]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.3-201209101830.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.3-201209101830.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..7530459 100644
228 --- a/Documentation/kernel-parameters.txt
229 +++ b/Documentation/kernel-parameters.txt
230 @@ -2051,6 +2051,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 the specified number of seconds. This is to be used if
232 your oopses keep scrolling off the screen.
233
234 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
235 + virtualization environments that don't cope well with the
236 + expand down segment used by UDEREF on X86-32 or the frequent
237 + page table updates on X86-64.
238 +
239 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
240 +
241 pcbit= [HW,ISDN]
242
243 pcd. [PARIDE]
244 diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
245 index 13d6166..8c235b6 100644
246 --- a/Documentation/sysctl/fs.txt
247 +++ b/Documentation/sysctl/fs.txt
248 @@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
249 or otherwise protected/tainted binaries. The modes are
250
251 0 - (default) - traditional behaviour. Any process which has changed
252 - privilege levels or is execute only will not be dumped
253 + privilege levels or is execute only will not be dumped.
254 1 - (debug) - all processes dump core when possible. The core dump is
255 owned by the current user and no security is applied. This is
256 intended for system debugging situations only. Ptrace is unchecked.
257 + This is insecure as it allows regular users to examine the memory
258 + contents of privileged processes.
259 2 - (suidsafe) - any binary which normally would not be dumped is dumped
260 - readable by root only. This allows the end user to remove
261 - such a dump but not access it directly. For security reasons
262 - core dumps in this mode will not overwrite one another or
263 - other files. This mode is appropriate when administrators are
264 - attempting to debug problems in a normal environment.
265 + anyway, but only if the "core_pattern" kernel sysctl is set to
266 + either a pipe handler or a fully qualified path. (For more details
267 + on this limitation, see CVE-2006-2451.) This mode is appropriate
268 + when administrators are attempting to debug problems in a normal
269 + environment, and either have a core dump pipe handler that knows
270 + to treat privileged core dumps with care, or specific directory
271 + defined for catching core dumps. If a core dump happens without
272 + a pipe handler or fully qualifid path, a message will be emitted
273 + to syslog warning about the lack of a correct setting.
274
275 ==============================================================
276
277 diff --git a/Makefile b/Makefile
278 index c901aae..0f96503 100644
279 --- a/Makefile
280 +++ b/Makefile
281 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
282
283 HOSTCC = gcc
284 HOSTCXX = g++
285 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
286 -HOSTCXXFLAGS = -O2
287 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
288 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
289 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
290
291 # Decide whether to build built-in, modular, or both.
292 # Normally, just do built-in.
293 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
294 # Rules shared between *config targets and build targets
295
296 # Basic helpers built in scripts/
297 -PHONY += scripts_basic
298 -scripts_basic:
299 +PHONY += scripts_basic gcc-plugins
300 +scripts_basic: gcc-plugins
301 $(Q)$(MAKE) $(build)=scripts/basic
302 $(Q)rm -f .tmp_quiet_recordmcount
303
304 @@ -561,6 +562,60 @@ else
305 KBUILD_CFLAGS += -O2
306 endif
307
308 +ifndef DISABLE_PAX_PLUGINS
309 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
310 +ifneq ($(PLUGINCC),)
311 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
312 +ifndef CONFIG_UML
313 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
314 +endif
315 +endif
316 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
317 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
318 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
319 +endif
320 +ifdef CONFIG_KALLOCSTAT_PLUGIN
321 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
322 +endif
323 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
324 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
325 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
326 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
327 +endif
328 +ifdef CONFIG_CHECKER_PLUGIN
329 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
330 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
331 +endif
332 +endif
333 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
334 +ifdef CONFIG_PAX_SIZE_OVERFLOW
335 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
336 +endif
337 +ifdef CONFIG_PAX_LATENT_ENTROPY
338 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
339 +endif
340 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
341 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
342 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
343 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
344 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
345 +ifeq ($(KBUILD_EXTMOD),)
346 +gcc-plugins:
347 + $(Q)$(MAKE) $(build)=tools/gcc
348 +else
349 +gcc-plugins: ;
350 +endif
351 +else
352 +gcc-plugins:
353 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
354 + $(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.))
355 +else
356 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
357 +endif
358 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
359 +endif
360 +endif
361 +
362 include $(srctree)/arch/$(SRCARCH)/Makefile
363
364 ifdef CONFIG_READABLE_ASM
365 @@ -715,7 +770,7 @@ export mod_strip_cmd
366
367
368 ifeq ($(KBUILD_EXTMOD),)
369 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
370 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
371
372 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
373 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
374 @@ -762,6 +817,8 @@ endif
375
376 # The actual objects are generated when descending,
377 # make sure no implicit rule kicks in
378 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
380 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
381
382 # Handle descending into subdirectories listed in $(vmlinux-dirs)
383 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
384 # Error messages still appears in the original language
385
386 PHONY += $(vmlinux-dirs)
387 -$(vmlinux-dirs): prepare scripts
388 +$(vmlinux-dirs): gcc-plugins prepare scripts
389 $(Q)$(MAKE) $(build)=$@
390
391 # Store (new) KERNELRELASE string in include/config/kernel.release
392 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
393 $(Q)$(MAKE) $(build)=.
394
395 # All the preparing..
396 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
397 prepare: prepare0
398
399 # Generate some files
400 @@ -922,6 +980,8 @@ all: modules
401 # using awk while concatenating to the final file.
402
403 PHONY += modules
404 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
405 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
406 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
407 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
408 @$(kecho) ' Building modules, stage 2.';
409 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
410
411 # Target to prepare building external modules
412 PHONY += modules_prepare
413 -modules_prepare: prepare scripts
414 +modules_prepare: gcc-plugins prepare scripts
415
416 # Target to install modules
417 PHONY += modules_install
418 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
419 MRPROPER_DIRS += include/config usr/include include/generated \
420 arch/*/include/generated
421 MRPROPER_FILES += .config .config.old .version .old_version \
422 - include/linux/version.h \
423 + include/linux/version.h tools/gcc/size_overflow_hash.h\
424 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
425
426 # clean - Delete most, but leave enough to build external modules
427 @@ -1032,6 +1092,7 @@ distclean: mrproper
428 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
429 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
430 -o -name '.*.rej' \
431 + -o -name '.*.rej' -o -name '*.so' \
432 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
433 -type f -print | xargs rm -f
434
435 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
436 $(module-dirs): crmodverdir $(objtree)/Module.symvers
437 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
438
439 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
440 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
441 modules: $(module-dirs)
442 @$(kecho) ' Building modules, stage 2.';
443 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
444 @@ -1326,17 +1389,21 @@ else
445 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
446 endif
447
448 -%.s: %.c prepare scripts FORCE
449 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451 +%.s: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.i: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455 -%.o: %.c prepare scripts FORCE
456 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%.o: %.c gcc-plugins prepare scripts FORCE
459 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
460 %.lst: %.c prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462 -%.s: %.S prepare scripts FORCE
463 +%.s: %.S gcc-plugins prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465 -%.o: %.S prepare scripts FORCE
466 +%.o: %.S gcc-plugins prepare scripts FORCE
467 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
468 %.symtypes: %.c prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470 @@ -1346,11 +1413,15 @@ endif
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474 -%/: prepare scripts FORCE
475 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477 +%/: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir)
481 -%.ko: prepare scripts FORCE
482 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484 +%.ko: gcc-plugins prepare scripts FORCE
485 $(cmd_crmodverdir)
486 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
487 $(build)=$(build-dir) $(@:.ko=.o)
488 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
489 index 3bb7ffe..347a54c 100644
490 --- a/arch/alpha/include/asm/atomic.h
491 +++ b/arch/alpha/include/asm/atomic.h
492 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
493 #define atomic_dec(v) atomic_sub(1,(v))
494 #define atomic64_dec(v) atomic64_sub(1,(v))
495
496 +#define atomic64_read_unchecked(v) atomic64_read(v)
497 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
498 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
499 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
500 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
501 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
502 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
503 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
504 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
505 +
506 #define smp_mb__before_atomic_dec() smp_mb()
507 #define smp_mb__after_atomic_dec() smp_mb()
508 #define smp_mb__before_atomic_inc() smp_mb()
509 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
510 index ad368a9..fbe0f25 100644
511 --- a/arch/alpha/include/asm/cache.h
512 +++ b/arch/alpha/include/asm/cache.h
513 @@ -4,19 +4,19 @@
514 #ifndef __ARCH_ALPHA_CACHE_H
515 #define __ARCH_ALPHA_CACHE_H
516
517 +#include <linux/const.h>
518
519 /* Bytes per L1 (data) cache line. */
520 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
521 -# define L1_CACHE_BYTES 64
522 # define L1_CACHE_SHIFT 6
523 #else
524 /* Both EV4 and EV5 are write-through, read-allocate,
525 direct-mapped, physical.
526 */
527 -# define L1_CACHE_BYTES 32
528 # define L1_CACHE_SHIFT 5
529 #endif
530
531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
532 #define SMP_CACHE_BYTES L1_CACHE_BYTES
533
534 #endif
535 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
536 index 968d999..d36b2df 100644
537 --- a/arch/alpha/include/asm/elf.h
538 +++ b/arch/alpha/include/asm/elf.h
539 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
540
541 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
542
543 +#ifdef CONFIG_PAX_ASLR
544 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
545 +
546 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
547 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
548 +#endif
549 +
550 /* $0 is set by ld.so to a pointer to a function which might be
551 registered using atexit. This provides a mean for the dynamic
552 linker to call DT_FINI functions for shared libraries that have
553 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
554 index bc2a0da..8ad11ee 100644
555 --- a/arch/alpha/include/asm/pgalloc.h
556 +++ b/arch/alpha/include/asm/pgalloc.h
557 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
558 pgd_set(pgd, pmd);
559 }
560
561 +static inline void
562 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
563 +{
564 + pgd_populate(mm, pgd, pmd);
565 +}
566 +
567 extern pgd_t *pgd_alloc(struct mm_struct *mm);
568
569 static inline void
570 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
571 index 81a4342..348b927 100644
572 --- a/arch/alpha/include/asm/pgtable.h
573 +++ b/arch/alpha/include/asm/pgtable.h
574 @@ -102,6 +102,17 @@ struct vm_area_struct;
575 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
576 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
577 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
578 +
579 +#ifdef CONFIG_PAX_PAGEEXEC
580 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
581 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
582 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
583 +#else
584 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
585 +# define PAGE_COPY_NOEXEC PAGE_COPY
586 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
587 +#endif
588 +
589 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
590
591 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
592 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
593 index 2fd00b7..cfd5069 100644
594 --- a/arch/alpha/kernel/module.c
595 +++ b/arch/alpha/kernel/module.c
596 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
597
598 /* The small sections were sorted to the end of the segment.
599 The following should definitely cover them. */
600 - gp = (u64)me->module_core + me->core_size - 0x8000;
601 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
602 got = sechdrs[me->arch.gotsecindex].sh_addr;
603
604 for (i = 0; i < n; i++) {
605 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
606 index 98a1036..fb54ccf 100644
607 --- a/arch/alpha/kernel/osf_sys.c
608 +++ b/arch/alpha/kernel/osf_sys.c
609 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
610 /* At this point: (!vma || addr < vma->vm_end). */
611 if (limit - len < addr)
612 return -ENOMEM;
613 - if (!vma || addr + len <= vma->vm_start)
614 + if (check_heap_stack_gap(vma, addr, len))
615 return addr;
616 addr = vma->vm_end;
617 vma = vma->vm_next;
618 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
619 merely specific addresses, but regions of memory -- perhaps
620 this feature should be incorporated into all ports? */
621
622 +#ifdef CONFIG_PAX_RANDMMAP
623 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
624 +#endif
625 +
626 if (addr) {
627 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
628 if (addr != (unsigned long) -ENOMEM)
629 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
630 }
631
632 /* Next, try allocating at TASK_UNMAPPED_BASE. */
633 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
634 - len, limit);
635 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
636 +
637 if (addr != (unsigned long) -ENOMEM)
638 return addr;
639
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 5eecab1..609abc0 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
801 index c79f61f..9ac0642 100644
802 --- a/arch/arm/include/asm/atomic.h
803 +++ b/arch/arm/include/asm/atomic.h
804 @@ -17,17 +17,35 @@
805 #include <asm/barrier.h>
806 #include <asm/cmpxchg.h>
807
808 +#ifdef CONFIG_GENERIC_ATOMIC64
809 +#include <asm-generic/atomic64.h>
810 +#endif
811 +
812 #define ATOMIC_INIT(i) { (i) }
813
814 #ifdef __KERNEL__
815
816 +#define _ASM_EXTABLE(from, to) \
817 +" .pushsection __ex_table,\"a\"\n"\
818 +" .align 3\n" \
819 +" .long " #from ", " #to"\n" \
820 +" .popsection"
821 +
822 /*
823 * On ARM, ordinary assignment (str instruction) doesn't clear the local
824 * strex/ldrex monitor on some implementations. The reason we can use it for
825 * atomic_set() is the clrex or dummy strex done on every exception return.
826 */
827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
828 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
829 +{
830 + return v->counter;
831 +}
832 #define atomic_set(v,i) (((v)->counter) = (i))
833 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
834 +{
835 + v->counter = i;
836 +}
837
838 #if __LINUX_ARM_ARCH__ >= 6
839
840 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
841 int result;
842
843 __asm__ __volatile__("@ atomic_add\n"
844 +"1: ldrex %1, [%3]\n"
845 +" adds %0, %1, %4\n"
846 +
847 +#ifdef CONFIG_PAX_REFCOUNT
848 +" bvc 3f\n"
849 +"2: bkpt 0xf103\n"
850 +"3:\n"
851 +#endif
852 +
853 +" strex %1, %0, [%3]\n"
854 +" teq %1, #0\n"
855 +" bne 1b"
856 +
857 +#ifdef CONFIG_PAX_REFCOUNT
858 +"\n4:\n"
859 + _ASM_EXTABLE(2b, 4b)
860 +#endif
861 +
862 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
863 + : "r" (&v->counter), "Ir" (i)
864 + : "cc");
865 +}
866 +
867 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
868 +{
869 + unsigned long tmp;
870 + int result;
871 +
872 + __asm__ __volatile__("@ atomic_add_unchecked\n"
873 "1: ldrex %0, [%3]\n"
874 " add %0, %0, %4\n"
875 " strex %1, %0, [%3]\n"
876 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
877 smp_mb();
878
879 __asm__ __volatile__("@ atomic_add_return\n"
880 +"1: ldrex %1, [%3]\n"
881 +" adds %0, %1, %4\n"
882 +
883 +#ifdef CONFIG_PAX_REFCOUNT
884 +" bvc 3f\n"
885 +" mov %0, %1\n"
886 +"2: bkpt 0xf103\n"
887 +"3:\n"
888 +#endif
889 +
890 +" strex %1, %0, [%3]\n"
891 +" teq %1, #0\n"
892 +" bne 1b"
893 +
894 +#ifdef CONFIG_PAX_REFCOUNT
895 +"\n4:\n"
896 + _ASM_EXTABLE(2b, 4b)
897 +#endif
898 +
899 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
900 + : "r" (&v->counter), "Ir" (i)
901 + : "cc");
902 +
903 + smp_mb();
904 +
905 + return result;
906 +}
907 +
908 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
909 +{
910 + unsigned long tmp;
911 + int result;
912 +
913 + smp_mb();
914 +
915 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
920 int result;
921
922 __asm__ __volatile__("@ atomic_sub\n"
923 +"1: ldrex %1, [%3]\n"
924 +" subs %0, %1, %4\n"
925 +
926 +#ifdef CONFIG_PAX_REFCOUNT
927 +" bvc 3f\n"
928 +"2: bkpt 0xf103\n"
929 +"3:\n"
930 +#endif
931 +
932 +" strex %1, %0, [%3]\n"
933 +" teq %1, #0\n"
934 +" bne 1b"
935 +
936 +#ifdef CONFIG_PAX_REFCOUNT
937 +"\n4:\n"
938 + _ASM_EXTABLE(2b, 4b)
939 +#endif
940 +
941 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
942 + : "r" (&v->counter), "Ir" (i)
943 + : "cc");
944 +}
945 +
946 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
947 +{
948 + unsigned long tmp;
949 + int result;
950 +
951 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " sub %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
956 smp_mb();
957
958 __asm__ __volatile__("@ atomic_sub_return\n"
959 -"1: ldrex %0, [%3]\n"
960 -" sub %0, %0, %4\n"
961 +"1: ldrex %1, [%3]\n"
962 +" subs %0, %1, %4\n"
963 +
964 +#ifdef CONFIG_PAX_REFCOUNT
965 +" bvc 3f\n"
966 +" mov %0, %1\n"
967 +"2: bkpt 0xf103\n"
968 +"3:\n"
969 +#endif
970 +
971 " strex %1, %0, [%3]\n"
972 " teq %1, #0\n"
973 " bne 1b"
974 +
975 +#ifdef CONFIG_PAX_REFCOUNT
976 +"\n4:\n"
977 + _ASM_EXTABLE(2b, 4b)
978 +#endif
979 +
980 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
981 : "r" (&v->counter), "Ir" (i)
982 : "cc");
983 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
984 return oldval;
985 }
986
987 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
988 +{
989 + unsigned long oldval, res;
990 +
991 + smp_mb();
992 +
993 + do {
994 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
995 + "ldrex %1, [%3]\n"
996 + "mov %0, #0\n"
997 + "teq %1, %4\n"
998 + "strexeq %0, %5, [%3]\n"
999 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1000 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1001 + : "cc");
1002 + } while (res);
1003 +
1004 + smp_mb();
1005 +
1006 + return oldval;
1007 +}
1008 +
1009 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1010 {
1011 unsigned long tmp, tmp2;
1012 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1013
1014 return val;
1015 }
1016 +
1017 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1018 +{
1019 + return atomic_add_return(i, v);
1020 +}
1021 +
1022 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1023 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + (void) atomic_add_return(i, v);
1026 +}
1027
1028 static inline int atomic_sub_return(int i, atomic_t *v)
1029 {
1030 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1031 return val;
1032 }
1033 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1034 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1035 +{
1036 + (void) atomic_sub_return(i, v);
1037 +}
1038
1039 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1040 {
1041 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1042 return ret;
1043 }
1044
1045 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1046 +{
1047 + return atomic_cmpxchg(v, old, new);
1048 +}
1049 +
1050 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1051 {
1052 unsigned long flags;
1053 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 #endif /* __LINUX_ARM_ARCH__ */
1055
1056 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1057 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1058 +{
1059 + return xchg(&v->counter, new);
1060 +}
1061
1062 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1063 {
1064 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 }
1066
1067 #define atomic_inc(v) atomic_add(1, v)
1068 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_add_unchecked(1, v);
1071 +}
1072 #define atomic_dec(v) atomic_sub(1, v)
1073 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1074 +{
1075 + atomic_sub_unchecked(1, v);
1076 +}
1077
1078 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1079 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1080 +{
1081 + return atomic_add_return_unchecked(1, v) == 0;
1082 +}
1083 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1084 #define atomic_inc_return(v) (atomic_add_return(1, v))
1085 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1086 +{
1087 + return atomic_add_return_unchecked(1, v);
1088 +}
1089 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1090 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1091
1092 @@ -241,6 +428,14 @@ typedef struct {
1093 u64 __aligned(8) counter;
1094 } atomic64_t;
1095
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +typedef struct {
1098 + u64 __aligned(8) counter;
1099 +} atomic64_unchecked_t;
1100 +#else
1101 +typedef atomic64_t atomic64_unchecked_t;
1102 +#endif
1103 +
1104 #define ATOMIC64_INIT(i) { (i) }
1105
1106 static inline u64 atomic64_read(const atomic64_t *v)
1107 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1108 return result;
1109 }
1110
1111 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1112 +{
1113 + u64 result;
1114 +
1115 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1116 +" ldrexd %0, %H0, [%1]"
1117 + : "=&r" (result)
1118 + : "r" (&v->counter), "Qo" (v->counter)
1119 + );
1120 +
1121 + return result;
1122 +}
1123 +
1124 static inline void atomic64_set(atomic64_t *v, u64 i)
1125 {
1126 u64 tmp;
1127 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1128 : "cc");
1129 }
1130
1131 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1132 +{
1133 + u64 tmp;
1134 +
1135 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1136 +"1: ldrexd %0, %H0, [%2]\n"
1137 +" strexd %0, %3, %H3, [%2]\n"
1138 +" teq %0, #0\n"
1139 +" bne 1b"
1140 + : "=&r" (tmp), "=Qo" (v->counter)
1141 + : "r" (&v->counter), "r" (i)
1142 + : "cc");
1143 +}
1144 +
1145 static inline void atomic64_add(u64 i, atomic64_t *v)
1146 {
1147 u64 result;
1148 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149 __asm__ __volatile__("@ atomic64_add\n"
1150 "1: ldrexd %0, %H0, [%3]\n"
1151 " adds %0, %0, %4\n"
1152 +" adcs %H0, %H0, %H4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +"2: bkpt 0xf103\n"
1157 +"3:\n"
1158 +#endif
1159 +
1160 +" strexd %1, %0, %H0, [%3]\n"
1161 +" teq %1, #0\n"
1162 +" bne 1b"
1163 +
1164 +#ifdef CONFIG_PAX_REFCOUNT
1165 +"\n4:\n"
1166 + _ASM_EXTABLE(2b, 4b)
1167 +#endif
1168 +
1169 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1170 + : "r" (&v->counter), "r" (i)
1171 + : "cc");
1172 +}
1173 +
1174 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1175 +{
1176 + u64 result;
1177 + unsigned long tmp;
1178 +
1179 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1180 +"1: ldrexd %0, %H0, [%3]\n"
1181 +" adds %0, %0, %4\n"
1182 " adc %H0, %H0, %H4\n"
1183 " strexd %1, %0, %H0, [%3]\n"
1184 " teq %1, #0\n"
1185 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1186
1187 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1188 {
1189 - u64 result;
1190 - unsigned long tmp;
1191 + u64 result, tmp;
1192
1193 smp_mb();
1194
1195 __asm__ __volatile__("@ atomic64_add_return\n"
1196 +"1: ldrexd %1, %H1, [%3]\n"
1197 +" adds %0, %1, %4\n"
1198 +" adcs %H0, %H1, %H4\n"
1199 +
1200 +#ifdef CONFIG_PAX_REFCOUNT
1201 +" bvc 3f\n"
1202 +" mov %0, %1\n"
1203 +" mov %H0, %H1\n"
1204 +"2: bkpt 0xf103\n"
1205 +"3:\n"
1206 +#endif
1207 +
1208 +" strexd %1, %0, %H0, [%3]\n"
1209 +" teq %1, #0\n"
1210 +" bne 1b"
1211 +
1212 +#ifdef CONFIG_PAX_REFCOUNT
1213 +"\n4:\n"
1214 + _ASM_EXTABLE(2b, 4b)
1215 +#endif
1216 +
1217 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1218 + : "r" (&v->counter), "r" (i)
1219 + : "cc");
1220 +
1221 + smp_mb();
1222 +
1223 + return result;
1224 +}
1225 +
1226 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1227 +{
1228 + u64 result;
1229 + unsigned long tmp;
1230 +
1231 + smp_mb();
1232 +
1233 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " adds %0, %0, %4\n"
1236 " adc %H0, %H0, %H4\n"
1237 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_sub\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " subs %0, %0, %4\n"
1241 +" sbcs %H0, %H0, %H4\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 +" bvc 3f\n"
1245 +"2: bkpt 0xf103\n"
1246 +"3:\n"
1247 +#endif
1248 +
1249 +" strexd %1, %0, %H0, [%3]\n"
1250 +" teq %1, #0\n"
1251 +" bne 1b"
1252 +
1253 +#ifdef CONFIG_PAX_REFCOUNT
1254 +"\n4:\n"
1255 + _ASM_EXTABLE(2b, 4b)
1256 +#endif
1257 +
1258 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259 + : "r" (&v->counter), "r" (i)
1260 + : "cc");
1261 +}
1262 +
1263 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1264 +{
1265 + u64 result;
1266 + unsigned long tmp;
1267 +
1268 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%3]\n"
1270 +" subs %0, %0, %4\n"
1271 " sbc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1277 {
1278 - u64 result;
1279 - unsigned long tmp;
1280 + u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_sub_return\n"
1285 -"1: ldrexd %0, %H0, [%3]\n"
1286 -" subs %0, %0, %4\n"
1287 -" sbc %H0, %H0, %H4\n"
1288 +"1: ldrexd %1, %H1, [%3]\n"
1289 +" subs %0, %1, %4\n"
1290 +" sbcs %H0, %H1, %H4\n"
1291 +
1292 +#ifdef CONFIG_PAX_REFCOUNT
1293 +" bvc 3f\n"
1294 +" mov %0, %1\n"
1295 +" mov %H0, %H1\n"
1296 +"2: bkpt 0xf103\n"
1297 +"3:\n"
1298 +#endif
1299 +
1300 " strexd %1, %0, %H0, [%3]\n"
1301 " teq %1, #0\n"
1302 " bne 1b"
1303 +
1304 +#ifdef CONFIG_PAX_REFCOUNT
1305 +"\n4:\n"
1306 + _ASM_EXTABLE(2b, 4b)
1307 +#endif
1308 +
1309 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1310 : "r" (&v->counter), "r" (i)
1311 : "cc");
1312 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1313 return oldval;
1314 }
1315
1316 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1317 +{
1318 + u64 oldval;
1319 + unsigned long res;
1320 +
1321 + smp_mb();
1322 +
1323 + do {
1324 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1325 + "ldrexd %1, %H1, [%3]\n"
1326 + "mov %0, #0\n"
1327 + "teq %1, %4\n"
1328 + "teqeq %H1, %H4\n"
1329 + "strexdeq %0, %5, %H5, [%3]"
1330 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1331 + : "r" (&ptr->counter), "r" (old), "r" (new)
1332 + : "cc");
1333 + } while (res);
1334 +
1335 + smp_mb();
1336 +
1337 + return oldval;
1338 +}
1339 +
1340 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1341 {
1342 u64 result;
1343 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1344
1345 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1346 {
1347 - u64 result;
1348 - unsigned long tmp;
1349 + u64 result, tmp;
1350
1351 smp_mb();
1352
1353 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1354 -"1: ldrexd %0, %H0, [%3]\n"
1355 -" subs %0, %0, #1\n"
1356 -" sbc %H0, %H0, #0\n"
1357 +"1: ldrexd %1, %H1, [%3]\n"
1358 +" subs %0, %1, #1\n"
1359 +" sbcs %H0, %H1, #0\n"
1360 +
1361 +#ifdef CONFIG_PAX_REFCOUNT
1362 +" bvc 3f\n"
1363 +" mov %0, %1\n"
1364 +" mov %H0, %H1\n"
1365 +"2: bkpt 0xf103\n"
1366 +"3:\n"
1367 +#endif
1368 +
1369 " teq %H0, #0\n"
1370 -" bmi 2f\n"
1371 +" bmi 4f\n"
1372 " strexd %1, %0, %H0, [%3]\n"
1373 " teq %1, #0\n"
1374 " bne 1b\n"
1375 -"2:"
1376 +"4:\n"
1377 +
1378 +#ifdef CONFIG_PAX_REFCOUNT
1379 + _ASM_EXTABLE(2b, 4b)
1380 +#endif
1381 +
1382 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1383 : "r" (&v->counter)
1384 : "cc");
1385 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1386 " teq %0, %5\n"
1387 " teqeq %H0, %H5\n"
1388 " moveq %1, #0\n"
1389 -" beq 2f\n"
1390 +" beq 4f\n"
1391 " adds %0, %0, %6\n"
1392 -" adc %H0, %H0, %H6\n"
1393 +" adcs %H0, %H0, %H6\n"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +" bvc 3f\n"
1397 +"2: bkpt 0xf103\n"
1398 +"3:\n"
1399 +#endif
1400 +
1401 " strexd %2, %0, %H0, [%4]\n"
1402 " teq %2, #0\n"
1403 " bne 1b\n"
1404 -"2:"
1405 +"4:\n"
1406 +
1407 +#ifdef CONFIG_PAX_REFCOUNT
1408 + _ASM_EXTABLE(2b, 4b)
1409 +#endif
1410 +
1411 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1412 : "r" (&v->counter), "r" (u), "r" (a)
1413 : "cc");
1414 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1415
1416 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1417 #define atomic64_inc(v) atomic64_add(1LL, (v))
1418 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1419 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1420 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1421 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1422 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1423 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1424 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1425 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1426 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1427 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1428 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1429 index 75fe66b..2255c86 100644
1430 --- a/arch/arm/include/asm/cache.h
1431 +++ b/arch/arm/include/asm/cache.h
1432 @@ -4,8 +4,10 @@
1433 #ifndef __ASMARM_CACHE_H
1434 #define __ASMARM_CACHE_H
1435
1436 +#include <linux/const.h>
1437 +
1438 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1439 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1440 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1441
1442 /*
1443 * Memory returned by kmalloc() may be used for DMA, so we must make
1444 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1445 index e4448e1..7bc86b7 100644
1446 --- a/arch/arm/include/asm/cacheflush.h
1447 +++ b/arch/arm/include/asm/cacheflush.h
1448 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1449 void (*dma_unmap_area)(const void *, size_t, int);
1450
1451 void (*dma_flush_range)(const void *, const void *);
1452 -};
1453 +} __no_const;
1454
1455 /*
1456 * Select the calling method
1457 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1458 index 7eb18c1..e38b6d2 100644
1459 --- a/arch/arm/include/asm/cmpxchg.h
1460 +++ b/arch/arm/include/asm/cmpxchg.h
1461 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1462
1463 #define xchg(ptr,x) \
1464 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1465 +#define xchg_unchecked(ptr,x) \
1466 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467
1468 #include <asm-generic/cmpxchg-local.h>
1469
1470 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1471 index 38050b1..9d90e8b 100644
1472 --- a/arch/arm/include/asm/elf.h
1473 +++ b/arch/arm/include/asm/elf.h
1474 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1475 the loader. We need to make sure that it is out of the way of the program
1476 that it will "exec", and that there is sufficient room for the brk. */
1477
1478 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1479 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1480 +
1481 +#ifdef CONFIG_PAX_ASLR
1482 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1483 +
1484 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1486 +#endif
1487
1488 /* When the program starts, a1 contains a pointer to a function to be
1489 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1490 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1491 extern void elf_set_personality(const struct elf32_hdr *);
1492 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1493
1494 -struct mm_struct;
1495 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1496 -#define arch_randomize_brk arch_randomize_brk
1497 -
1498 #endif
1499 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1500 index e51b1e8..32a3113 100644
1501 --- a/arch/arm/include/asm/kmap_types.h
1502 +++ b/arch/arm/include/asm/kmap_types.h
1503 @@ -21,6 +21,7 @@ enum km_type {
1504 KM_L1_CACHE,
1505 KM_L2_CACHE,
1506 KM_KDB,
1507 + KM_CLEARPAGE,
1508 KM_TYPE_NR
1509 };
1510
1511 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1512 index 53426c6..c7baff3 100644
1513 --- a/arch/arm/include/asm/outercache.h
1514 +++ b/arch/arm/include/asm/outercache.h
1515 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1516 #endif
1517 void (*set_debug)(unsigned long);
1518 void (*resume)(void);
1519 -};
1520 +} __no_const;
1521
1522 #ifdef CONFIG_OUTER_CACHE
1523
1524 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1525 index ecf9019..b71d9a1 100644
1526 --- a/arch/arm/include/asm/page.h
1527 +++ b/arch/arm/include/asm/page.h
1528 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1529 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1530 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1531 unsigned long vaddr, struct vm_area_struct *vma);
1532 -};
1533 +} __no_const;
1534
1535 #ifdef MULTI_USER
1536 extern struct cpu_user_fns cpu_user;
1537 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1538 index 943504f..bf8d667 100644
1539 --- a/arch/arm/include/asm/pgalloc.h
1540 +++ b/arch/arm/include/asm/pgalloc.h
1541 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1542 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1543 }
1544
1545 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1546 +{
1547 + pud_populate(mm, pud, pmd);
1548 +}
1549 +
1550 #else /* !CONFIG_ARM_LPAE */
1551
1552 /*
1553 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1554 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1555 #define pmd_free(mm, pmd) do { } while (0)
1556 #define pud_populate(mm,pmd,pte) BUG()
1557 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1558
1559 #endif /* CONFIG_ARM_LPAE */
1560
1561 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1562 index af7b0bd..6750a8c 100644
1563 --- a/arch/arm/include/asm/thread_info.h
1564 +++ b/arch/arm/include/asm/thread_info.h
1565 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1566 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1567 #define TIF_SYSCALL_TRACE 8
1568 #define TIF_SYSCALL_AUDIT 9
1569 +
1570 +/* within 8 bits of TIF_SYSCALL_TRACE
1571 + to meet flexible second operand requirements
1572 +*/
1573 +#define TIF_GRSEC_SETXID 10
1574 +
1575 #define TIF_POLLING_NRFLAG 16
1576 #define TIF_USING_IWMMXT 17
1577 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1578 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1579 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1580 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1581 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1582 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1583
1584 /* Checks for any syscall work in entry-common.S */
1585 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1586 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1587 + _TIF_GRSEC_SETXID)
1588
1589 /*
1590 * Change these and you break ASM code in entry-common.S
1591 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1592 index 71f6536..602f279 100644
1593 --- a/arch/arm/include/asm/uaccess.h
1594 +++ b/arch/arm/include/asm/uaccess.h
1595 @@ -22,6 +22,8 @@
1596 #define VERIFY_READ 0
1597 #define VERIFY_WRITE 1
1598
1599 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1600 +
1601 /*
1602 * The exception table consists of pairs of addresses: the first is the
1603 * address of an instruction that is allowed to fault, and the second is
1604 @@ -387,8 +389,23 @@ do { \
1605
1606
1607 #ifdef CONFIG_MMU
1608 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1609 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1610 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1611 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1612 +
1613 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1614 +{
1615 + if (!__builtin_constant_p(n))
1616 + check_object_size(to, n, false);
1617 + return ___copy_from_user(to, from, n);
1618 +}
1619 +
1620 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1621 +{
1622 + if (!__builtin_constant_p(n))
1623 + check_object_size(from, n, true);
1624 + return ___copy_to_user(to, from, n);
1625 +}
1626 +
1627 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1628 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1629 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1630 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1631
1632 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1633 {
1634 + if ((long)n < 0)
1635 + return n;
1636 +
1637 if (access_ok(VERIFY_READ, from, n))
1638 n = __copy_from_user(to, from, n);
1639 else /* security hole - plug it */
1640 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1641
1642 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1643 {
1644 + if ((long)n < 0)
1645 + return n;
1646 +
1647 if (access_ok(VERIFY_WRITE, to, n))
1648 n = __copy_to_user(to, from, n);
1649 return n;
1650 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1651 index b57c75e..ed2d6b2 100644
1652 --- a/arch/arm/kernel/armksyms.c
1653 +++ b/arch/arm/kernel/armksyms.c
1654 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1655 #ifdef CONFIG_MMU
1656 EXPORT_SYMBOL(copy_page);
1657
1658 -EXPORT_SYMBOL(__copy_from_user);
1659 -EXPORT_SYMBOL(__copy_to_user);
1660 +EXPORT_SYMBOL(___copy_from_user);
1661 +EXPORT_SYMBOL(___copy_to_user);
1662 EXPORT_SYMBOL(__clear_user);
1663
1664 EXPORT_SYMBOL(__get_user_1);
1665 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1666 index 693b744..e684262 100644
1667 --- a/arch/arm/kernel/process.c
1668 +++ b/arch/arm/kernel/process.c
1669 @@ -28,7 +28,6 @@
1670 #include <linux/tick.h>
1671 #include <linux/utsname.h>
1672 #include <linux/uaccess.h>
1673 -#include <linux/random.h>
1674 #include <linux/hw_breakpoint.h>
1675 #include <linux/cpuidle.h>
1676
1677 @@ -256,9 +255,10 @@ void machine_power_off(void)
1678 machine_shutdown();
1679 if (pm_power_off)
1680 pm_power_off();
1681 + BUG();
1682 }
1683
1684 -void machine_restart(char *cmd)
1685 +__noreturn void machine_restart(char *cmd)
1686 {
1687 machine_shutdown();
1688
1689 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1690 return 0;
1691 }
1692
1693 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1694 -{
1695 - unsigned long range_end = mm->brk + 0x02000000;
1696 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1697 -}
1698 -
1699 #ifdef CONFIG_MMU
1700 /*
1701 * The vectors page is always readable from user space for the
1702 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1703 index 14e3826..d832d89 100644
1704 --- a/arch/arm/kernel/ptrace.c
1705 +++ b/arch/arm/kernel/ptrace.c
1706 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1707 return ret;
1708 }
1709
1710 +#ifdef CONFIG_GRKERNSEC_SETXID
1711 +extern void gr_delayed_cred_worker(void);
1712 +#endif
1713 +
1714 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1715 {
1716 unsigned long ip;
1717
1718 +#ifdef CONFIG_GRKERNSEC_SETXID
1719 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1720 + gr_delayed_cred_worker();
1721 +#endif
1722 +
1723 if (why)
1724 audit_syscall_exit(regs);
1725 else
1726 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1727 index e15d83b..8c466dd 100644
1728 --- a/arch/arm/kernel/setup.c
1729 +++ b/arch/arm/kernel/setup.c
1730 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1731 struct cpu_tlb_fns cpu_tlb __read_mostly;
1732 #endif
1733 #ifdef MULTI_USER
1734 -struct cpu_user_fns cpu_user __read_mostly;
1735 +struct cpu_user_fns cpu_user __read_only;
1736 #endif
1737 #ifdef MULTI_CACHE
1738 -struct cpu_cache_fns cpu_cache __read_mostly;
1739 +struct cpu_cache_fns cpu_cache __read_only;
1740 #endif
1741 #ifdef CONFIG_OUTER_CACHE
1742 -struct outer_cache_fns outer_cache __read_mostly;
1743 +struct outer_cache_fns outer_cache __read_only;
1744 EXPORT_SYMBOL(outer_cache);
1745 #endif
1746
1747 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1748 index c7cae6b..e1e523c 100644
1749 --- a/arch/arm/kernel/traps.c
1750 +++ b/arch/arm/kernel/traps.c
1751 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1752
1753 static DEFINE_RAW_SPINLOCK(die_lock);
1754
1755 +extern void gr_handle_kernel_exploit(void);
1756 +
1757 /*
1758 * This function is protected against re-entrancy.
1759 */
1760 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1761 panic("Fatal exception in interrupt");
1762 if (panic_on_oops)
1763 panic("Fatal exception");
1764 +
1765 + gr_handle_kernel_exploit();
1766 +
1767 if (ret != NOTIFY_STOP)
1768 do_exit(SIGSEGV);
1769 }
1770 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1771 index 66a477a..bee61d3 100644
1772 --- a/arch/arm/lib/copy_from_user.S
1773 +++ b/arch/arm/lib/copy_from_user.S
1774 @@ -16,7 +16,7 @@
1775 /*
1776 * Prototype:
1777 *
1778 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1779 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1780 *
1781 * Purpose:
1782 *
1783 @@ -84,11 +84,11 @@
1784
1785 .text
1786
1787 -ENTRY(__copy_from_user)
1788 +ENTRY(___copy_from_user)
1789
1790 #include "copy_template.S"
1791
1792 -ENDPROC(__copy_from_user)
1793 +ENDPROC(___copy_from_user)
1794
1795 .pushsection .fixup,"ax"
1796 .align 0
1797 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1798 index 6ee2f67..d1cce76 100644
1799 --- a/arch/arm/lib/copy_page.S
1800 +++ b/arch/arm/lib/copy_page.S
1801 @@ -10,6 +10,7 @@
1802 * ASM optimised string functions
1803 */
1804 #include <linux/linkage.h>
1805 +#include <linux/const.h>
1806 #include <asm/assembler.h>
1807 #include <asm/asm-offsets.h>
1808 #include <asm/cache.h>
1809 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1810 index d066df6..df28194 100644
1811 --- a/arch/arm/lib/copy_to_user.S
1812 +++ b/arch/arm/lib/copy_to_user.S
1813 @@ -16,7 +16,7 @@
1814 /*
1815 * Prototype:
1816 *
1817 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1818 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1819 *
1820 * Purpose:
1821 *
1822 @@ -88,11 +88,11 @@
1823 .text
1824
1825 ENTRY(__copy_to_user_std)
1826 -WEAK(__copy_to_user)
1827 +WEAK(___copy_to_user)
1828
1829 #include "copy_template.S"
1830
1831 -ENDPROC(__copy_to_user)
1832 +ENDPROC(___copy_to_user)
1833 ENDPROC(__copy_to_user_std)
1834
1835 .pushsection .fixup,"ax"
1836 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1837 index 025f742..8432b08 100644
1838 --- a/arch/arm/lib/uaccess_with_memcpy.c
1839 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1840 @@ -104,7 +104,7 @@ out:
1841 }
1842
1843 unsigned long
1844 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1845 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1846 {
1847 /*
1848 * This test is stubbed out of the main function above to keep
1849 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1850 index f261cd2..4ae63fb 100644
1851 --- a/arch/arm/mach-kirkwood/common.c
1852 +++ b/arch/arm/mach-kirkwood/common.c
1853 @@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1854 clk_gate_ops.disable(hw);
1855 }
1856
1857 -static struct clk_ops clk_gate_fn_ops;
1858 +static clk_ops_no_const clk_gate_fn_ops;
1859
1860 static struct clk __init *clk_register_gate_fn(struct device *dev,
1861 const char *name,
1862 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1863 index 2c5d0ed..7d9099c 100644
1864 --- a/arch/arm/mach-omap2/board-n8x0.c
1865 +++ b/arch/arm/mach-omap2/board-n8x0.c
1866 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1867 }
1868 #endif
1869
1870 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1871 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1872 .late_init = n8x0_menelaus_late_init,
1873 };
1874
1875 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1876 index c3bd834..e81ef02 100644
1877 --- a/arch/arm/mm/fault.c
1878 +++ b/arch/arm/mm/fault.c
1879 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1880 }
1881 #endif
1882
1883 +#ifdef CONFIG_PAX_PAGEEXEC
1884 + if (fsr & FSR_LNX_PF) {
1885 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1886 + do_group_exit(SIGKILL);
1887 + }
1888 +#endif
1889 +
1890 tsk->thread.address = addr;
1891 tsk->thread.error_code = fsr;
1892 tsk->thread.trap_no = 14;
1893 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1894 }
1895 #endif /* CONFIG_MMU */
1896
1897 +#ifdef CONFIG_PAX_PAGEEXEC
1898 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1899 +{
1900 + long i;
1901 +
1902 + printk(KERN_ERR "PAX: bytes at PC: ");
1903 + for (i = 0; i < 20; i++) {
1904 + unsigned char c;
1905 + if (get_user(c, (__force unsigned char __user *)pc+i))
1906 + printk(KERN_CONT "?? ");
1907 + else
1908 + printk(KERN_CONT "%02x ", c);
1909 + }
1910 + printk("\n");
1911 +
1912 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1913 + for (i = -1; i < 20; i++) {
1914 + unsigned long c;
1915 + if (get_user(c, (__force unsigned long __user *)sp+i))
1916 + printk(KERN_CONT "???????? ");
1917 + else
1918 + printk(KERN_CONT "%08lx ", c);
1919 + }
1920 + printk("\n");
1921 +}
1922 +#endif
1923 +
1924 /*
1925 * First Level Translation Fault Handler
1926 *
1927 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1928 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1929 struct siginfo info;
1930
1931 +#ifdef CONFIG_PAX_REFCOUNT
1932 + if (fsr_fs(ifsr) == 2) {
1933 + unsigned int bkpt;
1934 +
1935 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1936 + current->thread.error_code = ifsr;
1937 + current->thread.trap_no = 0;
1938 + pax_report_refcount_overflow(regs);
1939 + fixup_exception(regs);
1940 + return;
1941 + }
1942 + }
1943 +#endif
1944 +
1945 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1946 return;
1947
1948 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1949 index ce8cb19..3ec539d 100644
1950 --- a/arch/arm/mm/mmap.c
1951 +++ b/arch/arm/mm/mmap.c
1952 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1953 if (len > TASK_SIZE)
1954 return -ENOMEM;
1955
1956 +#ifdef CONFIG_PAX_RANDMMAP
1957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1958 +#endif
1959 +
1960 if (addr) {
1961 if (do_align)
1962 addr = COLOUR_ALIGN(addr, pgoff);
1963 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1964 addr = PAGE_ALIGN(addr);
1965
1966 vma = find_vma(mm, addr);
1967 - if (TASK_SIZE - len >= addr &&
1968 - (!vma || addr + len <= vma->vm_start))
1969 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1970 return addr;
1971 }
1972 if (len > mm->cached_hole_size) {
1973 - start_addr = addr = mm->free_area_cache;
1974 + start_addr = addr = mm->free_area_cache;
1975 } else {
1976 - start_addr = addr = mm->mmap_base;
1977 - mm->cached_hole_size = 0;
1978 + start_addr = addr = mm->mmap_base;
1979 + mm->cached_hole_size = 0;
1980 }
1981
1982 full_search:
1983 @@ -124,14 +127,14 @@ full_search:
1984 * Start a new search - just in case we missed
1985 * some holes.
1986 */
1987 - if (start_addr != TASK_UNMAPPED_BASE) {
1988 - start_addr = addr = TASK_UNMAPPED_BASE;
1989 + if (start_addr != mm->mmap_base) {
1990 + start_addr = addr = mm->mmap_base;
1991 mm->cached_hole_size = 0;
1992 goto full_search;
1993 }
1994 return -ENOMEM;
1995 }
1996 - if (!vma || addr + len <= vma->vm_start) {
1997 + if (check_heap_stack_gap(vma, addr, len)) {
1998 /*
1999 * Remember the place where we stopped the search:
2000 */
2001 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2002
2003 if (mmap_is_legacy()) {
2004 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2005 +
2006 +#ifdef CONFIG_PAX_RANDMMAP
2007 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2008 + mm->mmap_base += mm->delta_mmap;
2009 +#endif
2010 +
2011 mm->get_unmapped_area = arch_get_unmapped_area;
2012 mm->unmap_area = arch_unmap_area;
2013 } else {
2014 mm->mmap_base = mmap_base(random_factor);
2015 +
2016 +#ifdef CONFIG_PAX_RANDMMAP
2017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2018 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2019 +#endif
2020 +
2021 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2022 mm->unmap_area = arch_unmap_area_topdown;
2023 }
2024 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2025 index fd556f7..af2e7d2 100644
2026 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2027 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2028 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2029 value in bridge_virt_base */
2030 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2031 const int win);
2032 -};
2033 +} __no_const;
2034
2035 /*
2036 * Information needed to setup one address mapping.
2037 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2038 index 71a6827..e7fbc23 100644
2039 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2040 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2041 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2042 int (*started)(unsigned ch);
2043 int (*flush)(unsigned ch);
2044 int (*stop)(unsigned ch);
2045 -};
2046 +} __no_const;
2047
2048 extern void *samsung_dmadev_get_ops(void);
2049 extern void *s3c_dma_get_ops(void);
2050 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2051 index 5f28cae..3d23723 100644
2052 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2053 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2054 @@ -14,7 +14,7 @@
2055 struct s5p_ehci_platdata {
2056 int (*phy_init)(struct platform_device *pdev, int type);
2057 int (*phy_exit)(struct platform_device *pdev, int type);
2058 -};
2059 +} __no_const;
2060
2061 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2062
2063 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2064 index c3a58a1..78fbf54 100644
2065 --- a/arch/avr32/include/asm/cache.h
2066 +++ b/arch/avr32/include/asm/cache.h
2067 @@ -1,8 +1,10 @@
2068 #ifndef __ASM_AVR32_CACHE_H
2069 #define __ASM_AVR32_CACHE_H
2070
2071 +#include <linux/const.h>
2072 +
2073 #define L1_CACHE_SHIFT 5
2074 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2075 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2076
2077 /*
2078 * Memory returned by kmalloc() may be used for DMA, so we must make
2079 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2080 index 3b3159b..425ea94 100644
2081 --- a/arch/avr32/include/asm/elf.h
2082 +++ b/arch/avr32/include/asm/elf.h
2083 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2084 the loader. We need to make sure that it is out of the way of the program
2085 that it will "exec", and that there is sufficient room for the brk. */
2086
2087 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2088 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2089
2090 +#ifdef CONFIG_PAX_ASLR
2091 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2092 +
2093 +#define PAX_DELTA_MMAP_LEN 15
2094 +#define PAX_DELTA_STACK_LEN 15
2095 +#endif
2096
2097 /* This yields a mask that user programs can use to figure out what
2098 instruction set this CPU supports. This could be done in user space,
2099 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2100 index b7f5c68..556135c 100644
2101 --- a/arch/avr32/include/asm/kmap_types.h
2102 +++ b/arch/avr32/include/asm/kmap_types.h
2103 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2104 D(11) KM_IRQ1,
2105 D(12) KM_SOFTIRQ0,
2106 D(13) KM_SOFTIRQ1,
2107 -D(14) KM_TYPE_NR
2108 +D(14) KM_CLEARPAGE,
2109 +D(15) KM_TYPE_NR
2110 };
2111
2112 #undef D
2113 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2114 index f7040a1..db9f300 100644
2115 --- a/arch/avr32/mm/fault.c
2116 +++ b/arch/avr32/mm/fault.c
2117 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2118
2119 int exception_trace = 1;
2120
2121 +#ifdef CONFIG_PAX_PAGEEXEC
2122 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2123 +{
2124 + unsigned long i;
2125 +
2126 + printk(KERN_ERR "PAX: bytes at PC: ");
2127 + for (i = 0; i < 20; i++) {
2128 + unsigned char c;
2129 + if (get_user(c, (unsigned char *)pc+i))
2130 + printk(KERN_CONT "???????? ");
2131 + else
2132 + printk(KERN_CONT "%02x ", c);
2133 + }
2134 + printk("\n");
2135 +}
2136 +#endif
2137 +
2138 /*
2139 * This routine handles page faults. It determines the address and the
2140 * problem, and then passes it off to one of the appropriate routines.
2141 @@ -156,6 +173,16 @@ bad_area:
2142 up_read(&mm->mmap_sem);
2143
2144 if (user_mode(regs)) {
2145 +
2146 +#ifdef CONFIG_PAX_PAGEEXEC
2147 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2148 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2149 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2150 + do_group_exit(SIGKILL);
2151 + }
2152 + }
2153 +#endif
2154 +
2155 if (exception_trace && printk_ratelimit())
2156 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2157 "sp %08lx ecr %lu\n",
2158 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2159 index 568885a..f8008df 100644
2160 --- a/arch/blackfin/include/asm/cache.h
2161 +++ b/arch/blackfin/include/asm/cache.h
2162 @@ -7,6 +7,7 @@
2163 #ifndef __ARCH_BLACKFIN_CACHE_H
2164 #define __ARCH_BLACKFIN_CACHE_H
2165
2166 +#include <linux/const.h>
2167 #include <linux/linkage.h> /* for asmlinkage */
2168
2169 /*
2170 @@ -14,7 +15,7 @@
2171 * Blackfin loads 32 bytes for cache
2172 */
2173 #define L1_CACHE_SHIFT 5
2174 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2175 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2176 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2177
2178 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2179 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2180 index aea2718..3639a60 100644
2181 --- a/arch/cris/include/arch-v10/arch/cache.h
2182 +++ b/arch/cris/include/arch-v10/arch/cache.h
2183 @@ -1,8 +1,9 @@
2184 #ifndef _ASM_ARCH_CACHE_H
2185 #define _ASM_ARCH_CACHE_H
2186
2187 +#include <linux/const.h>
2188 /* Etrax 100LX have 32-byte cache-lines. */
2189 -#define L1_CACHE_BYTES 32
2190 #define L1_CACHE_SHIFT 5
2191 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2192
2193 #endif /* _ASM_ARCH_CACHE_H */
2194 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2195 index 7caf25d..ee65ac5 100644
2196 --- a/arch/cris/include/arch-v32/arch/cache.h
2197 +++ b/arch/cris/include/arch-v32/arch/cache.h
2198 @@ -1,11 +1,12 @@
2199 #ifndef _ASM_CRIS_ARCH_CACHE_H
2200 #define _ASM_CRIS_ARCH_CACHE_H
2201
2202 +#include <linux/const.h>
2203 #include <arch/hwregs/dma.h>
2204
2205 /* A cache-line is 32 bytes. */
2206 -#define L1_CACHE_BYTES 32
2207 #define L1_CACHE_SHIFT 5
2208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2209
2210 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2211
2212 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2213 index b86329d..6709906 100644
2214 --- a/arch/frv/include/asm/atomic.h
2215 +++ b/arch/frv/include/asm/atomic.h
2216 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2217 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2218 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2219
2220 +#define atomic64_read_unchecked(v) atomic64_read(v)
2221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2229 +
2230 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2231 {
2232 int c, old;
2233 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2234 index 2797163..c2a401d 100644
2235 --- a/arch/frv/include/asm/cache.h
2236 +++ b/arch/frv/include/asm/cache.h
2237 @@ -12,10 +12,11 @@
2238 #ifndef __ASM_CACHE_H
2239 #define __ASM_CACHE_H
2240
2241 +#include <linux/const.h>
2242
2243 /* bytes per L1 cache line */
2244 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2245 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2246 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2247
2248 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2249 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2250 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2251 index f8e16b2..c73ff79 100644
2252 --- a/arch/frv/include/asm/kmap_types.h
2253 +++ b/arch/frv/include/asm/kmap_types.h
2254 @@ -23,6 +23,7 @@ enum km_type {
2255 KM_IRQ1,
2256 KM_SOFTIRQ0,
2257 KM_SOFTIRQ1,
2258 + KM_CLEARPAGE,
2259 KM_TYPE_NR
2260 };
2261
2262 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2263 index 385fd30..6c3d97e 100644
2264 --- a/arch/frv/mm/elf-fdpic.c
2265 +++ b/arch/frv/mm/elf-fdpic.c
2266 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2267 if (addr) {
2268 addr = PAGE_ALIGN(addr);
2269 vma = find_vma(current->mm, addr);
2270 - if (TASK_SIZE - len >= addr &&
2271 - (!vma || addr + len <= vma->vm_start))
2272 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2273 goto success;
2274 }
2275
2276 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 for (; vma; vma = vma->vm_next) {
2278 if (addr > limit)
2279 break;
2280 - if (addr + len <= vma->vm_start)
2281 + if (check_heap_stack_gap(vma, addr, len))
2282 goto success;
2283 addr = vma->vm_end;
2284 }
2285 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2286 for (; vma; vma = vma->vm_next) {
2287 if (addr > limit)
2288 break;
2289 - if (addr + len <= vma->vm_start)
2290 + if (check_heap_stack_gap(vma, addr, len))
2291 goto success;
2292 addr = vma->vm_end;
2293 }
2294 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2295 index c635028..6d9445a 100644
2296 --- a/arch/h8300/include/asm/cache.h
2297 +++ b/arch/h8300/include/asm/cache.h
2298 @@ -1,8 +1,10 @@
2299 #ifndef __ARCH_H8300_CACHE_H
2300 #define __ARCH_H8300_CACHE_H
2301
2302 +#include <linux/const.h>
2303 +
2304 /* bytes per L1 cache line */
2305 -#define L1_CACHE_BYTES 4
2306 +#define L1_CACHE_BYTES _AC(4,UL)
2307
2308 /* m68k-elf-gcc 2.95.2 doesn't like these */
2309
2310 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2311 index 0f01de2..d37d309 100644
2312 --- a/arch/hexagon/include/asm/cache.h
2313 +++ b/arch/hexagon/include/asm/cache.h
2314 @@ -21,9 +21,11 @@
2315 #ifndef __ASM_CACHE_H
2316 #define __ASM_CACHE_H
2317
2318 +#include <linux/const.h>
2319 +
2320 /* Bytes per L1 cache line */
2321 -#define L1_CACHE_SHIFT (5)
2322 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2323 +#define L1_CACHE_SHIFT 5
2324 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2325
2326 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2327 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2328 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2329 index 6e6fe18..a6ae668 100644
2330 --- a/arch/ia64/include/asm/atomic.h
2331 +++ b/arch/ia64/include/asm/atomic.h
2332 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2333 #define atomic64_inc(v) atomic64_add(1, (v))
2334 #define atomic64_dec(v) atomic64_sub(1, (v))
2335
2336 +#define atomic64_read_unchecked(v) atomic64_read(v)
2337 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2338 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2339 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2340 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2341 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2342 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2343 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2344 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2345 +
2346 /* Atomic operations are already serializing */
2347 #define smp_mb__before_atomic_dec() barrier()
2348 #define smp_mb__after_atomic_dec() barrier()
2349 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2350 index 988254a..e1ee885 100644
2351 --- a/arch/ia64/include/asm/cache.h
2352 +++ b/arch/ia64/include/asm/cache.h
2353 @@ -1,6 +1,7 @@
2354 #ifndef _ASM_IA64_CACHE_H
2355 #define _ASM_IA64_CACHE_H
2356
2357 +#include <linux/const.h>
2358
2359 /*
2360 * Copyright (C) 1998-2000 Hewlett-Packard Co
2361 @@ -9,7 +10,7 @@
2362
2363 /* Bytes per L1 (data) cache line. */
2364 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2365 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2366 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2367
2368 #ifdef CONFIG_SMP
2369 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2370 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2371 index b5298eb..67c6e62 100644
2372 --- a/arch/ia64/include/asm/elf.h
2373 +++ b/arch/ia64/include/asm/elf.h
2374 @@ -42,6 +42,13 @@
2375 */
2376 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2377
2378 +#ifdef CONFIG_PAX_ASLR
2379 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2380 +
2381 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2382 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2383 +#endif
2384 +
2385 #define PT_IA_64_UNWIND 0x70000001
2386
2387 /* IA-64 relocations: */
2388 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2389 index 96a8d92..617a1cf 100644
2390 --- a/arch/ia64/include/asm/pgalloc.h
2391 +++ b/arch/ia64/include/asm/pgalloc.h
2392 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2393 pgd_val(*pgd_entry) = __pa(pud);
2394 }
2395
2396 +static inline void
2397 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2398 +{
2399 + pgd_populate(mm, pgd_entry, pud);
2400 +}
2401 +
2402 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2403 {
2404 return quicklist_alloc(0, GFP_KERNEL, NULL);
2405 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2406 pud_val(*pud_entry) = __pa(pmd);
2407 }
2408
2409 +static inline void
2410 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2411 +{
2412 + pud_populate(mm, pud_entry, pmd);
2413 +}
2414 +
2415 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2416 {
2417 return quicklist_alloc(0, GFP_KERNEL, NULL);
2418 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2419 index 815810c..d60bd4c 100644
2420 --- a/arch/ia64/include/asm/pgtable.h
2421 +++ b/arch/ia64/include/asm/pgtable.h
2422 @@ -12,7 +12,7 @@
2423 * David Mosberger-Tang <davidm@hpl.hp.com>
2424 */
2425
2426 -
2427 +#include <linux/const.h>
2428 #include <asm/mman.h>
2429 #include <asm/page.h>
2430 #include <asm/processor.h>
2431 @@ -142,6 +142,17 @@
2432 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2434 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2435 +
2436 +#ifdef CONFIG_PAX_PAGEEXEC
2437 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2438 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2439 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2440 +#else
2441 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2442 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2443 +# define PAGE_COPY_NOEXEC PAGE_COPY
2444 +#endif
2445 +
2446 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2447 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2448 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2449 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2450 index 54ff557..70c88b7 100644
2451 --- a/arch/ia64/include/asm/spinlock.h
2452 +++ b/arch/ia64/include/asm/spinlock.h
2453 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2454 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2455
2456 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2457 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2458 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2459 }
2460
2461 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2462 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2463 index 449c8c0..432a3d2 100644
2464 --- a/arch/ia64/include/asm/uaccess.h
2465 +++ b/arch/ia64/include/asm/uaccess.h
2466 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2467 const void *__cu_from = (from); \
2468 long __cu_len = (n); \
2469 \
2470 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2471 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2472 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2473 __cu_len; \
2474 })
2475 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2476 long __cu_len = (n); \
2477 \
2478 __chk_user_ptr(__cu_from); \
2479 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2480 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2481 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2482 __cu_len; \
2483 })
2484 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2485 index 24603be..948052d 100644
2486 --- a/arch/ia64/kernel/module.c
2487 +++ b/arch/ia64/kernel/module.c
2488 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2489 void
2490 module_free (struct module *mod, void *module_region)
2491 {
2492 - if (mod && mod->arch.init_unw_table &&
2493 - module_region == mod->module_init) {
2494 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2495 unw_remove_unwind_table(mod->arch.init_unw_table);
2496 mod->arch.init_unw_table = NULL;
2497 }
2498 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2499 }
2500
2501 static inline int
2502 +in_init_rx (const struct module *mod, uint64_t addr)
2503 +{
2504 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2505 +}
2506 +
2507 +static inline int
2508 +in_init_rw (const struct module *mod, uint64_t addr)
2509 +{
2510 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2511 +}
2512 +
2513 +static inline int
2514 in_init (const struct module *mod, uint64_t addr)
2515 {
2516 - return addr - (uint64_t) mod->module_init < mod->init_size;
2517 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2518 +}
2519 +
2520 +static inline int
2521 +in_core_rx (const struct module *mod, uint64_t addr)
2522 +{
2523 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2524 +}
2525 +
2526 +static inline int
2527 +in_core_rw (const struct module *mod, uint64_t addr)
2528 +{
2529 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2530 }
2531
2532 static inline int
2533 in_core (const struct module *mod, uint64_t addr)
2534 {
2535 - return addr - (uint64_t) mod->module_core < mod->core_size;
2536 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2537 }
2538
2539 static inline int
2540 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2541 break;
2542
2543 case RV_BDREL:
2544 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2545 + if (in_init_rx(mod, val))
2546 + val -= (uint64_t) mod->module_init_rx;
2547 + else if (in_init_rw(mod, val))
2548 + val -= (uint64_t) mod->module_init_rw;
2549 + else if (in_core_rx(mod, val))
2550 + val -= (uint64_t) mod->module_core_rx;
2551 + else if (in_core_rw(mod, val))
2552 + val -= (uint64_t) mod->module_core_rw;
2553 break;
2554
2555 case RV_LTV:
2556 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2557 * addresses have been selected...
2558 */
2559 uint64_t gp;
2560 - if (mod->core_size > MAX_LTOFF)
2561 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2562 /*
2563 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2564 * at the end of the module.
2565 */
2566 - gp = mod->core_size - MAX_LTOFF / 2;
2567 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2568 else
2569 - gp = mod->core_size / 2;
2570 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2571 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2572 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2573 mod->arch.gp = gp;
2574 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2575 }
2576 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2577 index d9439ef..b9a4303 100644
2578 --- a/arch/ia64/kernel/sys_ia64.c
2579 +++ b/arch/ia64/kernel/sys_ia64.c
2580 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 if (REGION_NUMBER(addr) == RGN_HPAGE)
2582 addr = 0;
2583 #endif
2584 +
2585 +#ifdef CONFIG_PAX_RANDMMAP
2586 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2587 + addr = mm->free_area_cache;
2588 + else
2589 +#endif
2590 +
2591 if (!addr)
2592 addr = mm->free_area_cache;
2593
2594 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2595 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2596 /* At this point: (!vma || addr < vma->vm_end). */
2597 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2598 - if (start_addr != TASK_UNMAPPED_BASE) {
2599 + if (start_addr != mm->mmap_base) {
2600 /* Start a new search --- just in case we missed some holes. */
2601 - addr = TASK_UNMAPPED_BASE;
2602 + addr = mm->mmap_base;
2603 goto full_search;
2604 }
2605 return -ENOMEM;
2606 }
2607 - if (!vma || addr + len <= vma->vm_start) {
2608 + if (check_heap_stack_gap(vma, addr, len)) {
2609 /* Remember the address where we stopped this search: */
2610 mm->free_area_cache = addr + len;
2611 return addr;
2612 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2613 index 0ccb28f..8992469 100644
2614 --- a/arch/ia64/kernel/vmlinux.lds.S
2615 +++ b/arch/ia64/kernel/vmlinux.lds.S
2616 @@ -198,7 +198,7 @@ SECTIONS {
2617 /* Per-cpu data: */
2618 . = ALIGN(PERCPU_PAGE_SIZE);
2619 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2620 - __phys_per_cpu_start = __per_cpu_load;
2621 + __phys_per_cpu_start = per_cpu_load;
2622 /*
2623 * ensure percpu data fits
2624 * into percpu page size
2625 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2626 index 02d29c2..ea893df 100644
2627 --- a/arch/ia64/mm/fault.c
2628 +++ b/arch/ia64/mm/fault.c
2629 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2630 return pte_present(pte);
2631 }
2632
2633 +#ifdef CONFIG_PAX_PAGEEXEC
2634 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2635 +{
2636 + unsigned long i;
2637 +
2638 + printk(KERN_ERR "PAX: bytes at PC: ");
2639 + for (i = 0; i < 8; i++) {
2640 + unsigned int c;
2641 + if (get_user(c, (unsigned int *)pc+i))
2642 + printk(KERN_CONT "???????? ");
2643 + else
2644 + printk(KERN_CONT "%08x ", c);
2645 + }
2646 + printk("\n");
2647 +}
2648 +#endif
2649 +
2650 void __kprobes
2651 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2652 {
2653 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2654 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2655 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2656
2657 - if ((vma->vm_flags & mask) != mask)
2658 + if ((vma->vm_flags & mask) != mask) {
2659 +
2660 +#ifdef CONFIG_PAX_PAGEEXEC
2661 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2662 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2663 + goto bad_area;
2664 +
2665 + up_read(&mm->mmap_sem);
2666 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2667 + do_group_exit(SIGKILL);
2668 + }
2669 +#endif
2670 +
2671 goto bad_area;
2672
2673 + }
2674 +
2675 /*
2676 * If for any reason at all we couldn't handle the fault, make
2677 * sure we exit gracefully rather than endlessly redo the
2678 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2679 index 5ca674b..e0e1b70 100644
2680 --- a/arch/ia64/mm/hugetlbpage.c
2681 +++ b/arch/ia64/mm/hugetlbpage.c
2682 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2683 /* At this point: (!vmm || addr < vmm->vm_end). */
2684 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2685 return -ENOMEM;
2686 - if (!vmm || (addr + len) <= vmm->vm_start)
2687 + if (check_heap_stack_gap(vmm, addr, len))
2688 return addr;
2689 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2690 }
2691 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2692 index 0eab454..bd794f2 100644
2693 --- a/arch/ia64/mm/init.c
2694 +++ b/arch/ia64/mm/init.c
2695 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2696 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2697 vma->vm_end = vma->vm_start + PAGE_SIZE;
2698 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2699 +
2700 +#ifdef CONFIG_PAX_PAGEEXEC
2701 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2702 + vma->vm_flags &= ~VM_EXEC;
2703 +
2704 +#ifdef CONFIG_PAX_MPROTECT
2705 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2706 + vma->vm_flags &= ~VM_MAYEXEC;
2707 +#endif
2708 +
2709 + }
2710 +#endif
2711 +
2712 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2713 down_write(&current->mm->mmap_sem);
2714 if (insert_vm_struct(current->mm, vma)) {
2715 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2716 index 40b3ee9..8c2c112 100644
2717 --- a/arch/m32r/include/asm/cache.h
2718 +++ b/arch/m32r/include/asm/cache.h
2719 @@ -1,8 +1,10 @@
2720 #ifndef _ASM_M32R_CACHE_H
2721 #define _ASM_M32R_CACHE_H
2722
2723 +#include <linux/const.h>
2724 +
2725 /* L1 cache line size */
2726 #define L1_CACHE_SHIFT 4
2727 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2729
2730 #endif /* _ASM_M32R_CACHE_H */
2731 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2732 index 82abd15..d95ae5d 100644
2733 --- a/arch/m32r/lib/usercopy.c
2734 +++ b/arch/m32r/lib/usercopy.c
2735 @@ -14,6 +14,9 @@
2736 unsigned long
2737 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2738 {
2739 + if ((long)n < 0)
2740 + return n;
2741 +
2742 prefetch(from);
2743 if (access_ok(VERIFY_WRITE, to, n))
2744 __copy_user(to,from,n);
2745 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2746 unsigned long
2747 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2748 {
2749 + if ((long)n < 0)
2750 + return n;
2751 +
2752 prefetchw(to);
2753 if (access_ok(VERIFY_READ, from, n))
2754 __copy_user_zeroing(to,from,n);
2755 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2756 index 0395c51..5f26031 100644
2757 --- a/arch/m68k/include/asm/cache.h
2758 +++ b/arch/m68k/include/asm/cache.h
2759 @@ -4,9 +4,11 @@
2760 #ifndef __ARCH_M68K_CACHE_H
2761 #define __ARCH_M68K_CACHE_H
2762
2763 +#include <linux/const.h>
2764 +
2765 /* bytes per L1 cache line */
2766 #define L1_CACHE_SHIFT 4
2767 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2768 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2769
2770 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2771
2772 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2773 index 4efe96a..60e8699 100644
2774 --- a/arch/microblaze/include/asm/cache.h
2775 +++ b/arch/microblaze/include/asm/cache.h
2776 @@ -13,11 +13,12 @@
2777 #ifndef _ASM_MICROBLAZE_CACHE_H
2778 #define _ASM_MICROBLAZE_CACHE_H
2779
2780 +#include <linux/const.h>
2781 #include <asm/registers.h>
2782
2783 #define L1_CACHE_SHIFT 5
2784 /* word-granular cache in microblaze */
2785 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2786 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2787
2788 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2789
2790 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2791 index 3f4c5cb..3439c6e 100644
2792 --- a/arch/mips/include/asm/atomic.h
2793 +++ b/arch/mips/include/asm/atomic.h
2794 @@ -21,6 +21,10 @@
2795 #include <asm/cmpxchg.h>
2796 #include <asm/war.h>
2797
2798 +#ifdef CONFIG_GENERIC_ATOMIC64
2799 +#include <asm-generic/atomic64.h>
2800 +#endif
2801 +
2802 #define ATOMIC_INIT(i) { (i) }
2803
2804 /*
2805 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2806 */
2807 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2808
2809 +#define atomic64_read_unchecked(v) atomic64_read(v)
2810 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2811 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2812 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2813 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2814 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2815 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2816 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2817 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2818 +
2819 #endif /* CONFIG_64BIT */
2820
2821 /*
2822 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2823 index b4db69f..8f3b093 100644
2824 --- a/arch/mips/include/asm/cache.h
2825 +++ b/arch/mips/include/asm/cache.h
2826 @@ -9,10 +9,11 @@
2827 #ifndef _ASM_CACHE_H
2828 #define _ASM_CACHE_H
2829
2830 +#include <linux/const.h>
2831 #include <kmalloc.h>
2832
2833 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2834 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2835 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2836
2837 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2838 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2839 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2840 index 455c0ac..ad65fbe 100644
2841 --- a/arch/mips/include/asm/elf.h
2842 +++ b/arch/mips/include/asm/elf.h
2843 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2844 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2845 #endif
2846
2847 +#ifdef CONFIG_PAX_ASLR
2848 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2849 +
2850 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2851 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2852 +#endif
2853 +
2854 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2855 struct linux_binprm;
2856 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2857 int uses_interp);
2858
2859 -struct mm_struct;
2860 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2861 -#define arch_randomize_brk arch_randomize_brk
2862 -
2863 #endif /* _ASM_ELF_H */
2864 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2865 index c1f6afa..38cc6e9 100644
2866 --- a/arch/mips/include/asm/exec.h
2867 +++ b/arch/mips/include/asm/exec.h
2868 @@ -12,6 +12,6 @@
2869 #ifndef _ASM_EXEC_H
2870 #define _ASM_EXEC_H
2871
2872 -extern unsigned long arch_align_stack(unsigned long sp);
2873 +#define arch_align_stack(x) ((x) & ~0xfUL)
2874
2875 #endif /* _ASM_EXEC_H */
2876 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2877 index da9bd7d..91aa7ab 100644
2878 --- a/arch/mips/include/asm/page.h
2879 +++ b/arch/mips/include/asm/page.h
2880 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2881 #ifdef CONFIG_CPU_MIPS32
2882 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2883 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2884 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2885 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2886 #else
2887 typedef struct { unsigned long long pte; } pte_t;
2888 #define pte_val(x) ((x).pte)
2889 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2890 index 881d18b..cea38bc 100644
2891 --- a/arch/mips/include/asm/pgalloc.h
2892 +++ b/arch/mips/include/asm/pgalloc.h
2893 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2894 {
2895 set_pud(pud, __pud((unsigned long)pmd));
2896 }
2897 +
2898 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2899 +{
2900 + pud_populate(mm, pud, pmd);
2901 +}
2902 #endif
2903
2904 /*
2905 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2906 index ca97e0e..cd08920 100644
2907 --- a/arch/mips/include/asm/thread_info.h
2908 +++ b/arch/mips/include/asm/thread_info.h
2909 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2910 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2911 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2912 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2913 +/* li takes a 32bit immediate */
2914 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2915 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2916
2917 #ifdef CONFIG_MIPS32_O32
2918 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2919 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2920 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2921 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2922 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2923 +
2924 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2925
2926 /* work to do in syscall_trace_leave() */
2927 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2928 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2929
2930 /* work to do on interrupt/exception return */
2931 #define _TIF_WORK_MASK (0x0000ffef & \
2932 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2933 /* work to do on any return to u-space */
2934 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2935 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2936
2937 #endif /* __KERNEL__ */
2938
2939 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2940 index 9fdd8bc..4bd7f1a 100644
2941 --- a/arch/mips/kernel/binfmt_elfn32.c
2942 +++ b/arch/mips/kernel/binfmt_elfn32.c
2943 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2944 #undef ELF_ET_DYN_BASE
2945 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2946
2947 +#ifdef CONFIG_PAX_ASLR
2948 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2949 +
2950 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2951 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2952 +#endif
2953 +
2954 #include <asm/processor.h>
2955 #include <linux/module.h>
2956 #include <linux/elfcore.h>
2957 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2958 index ff44823..97f8906 100644
2959 --- a/arch/mips/kernel/binfmt_elfo32.c
2960 +++ b/arch/mips/kernel/binfmt_elfo32.c
2961 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2962 #undef ELF_ET_DYN_BASE
2963 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2964
2965 +#ifdef CONFIG_PAX_ASLR
2966 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2967 +
2968 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2969 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2970 +#endif
2971 +
2972 #include <asm/processor.h>
2973
2974 /*
2975 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2976 index e9a5fd7..378809a 100644
2977 --- a/arch/mips/kernel/process.c
2978 +++ b/arch/mips/kernel/process.c
2979 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2980 out:
2981 return pc;
2982 }
2983 -
2984 -/*
2985 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2986 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2987 - */
2988 -unsigned long arch_align_stack(unsigned long sp)
2989 -{
2990 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2991 - sp -= get_random_int() & ~PAGE_MASK;
2992 -
2993 - return sp & ALMASK;
2994 -}
2995 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2996 index 4812c6d..2069554 100644
2997 --- a/arch/mips/kernel/ptrace.c
2998 +++ b/arch/mips/kernel/ptrace.c
2999 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3000 return arch;
3001 }
3002
3003 +#ifdef CONFIG_GRKERNSEC_SETXID
3004 +extern void gr_delayed_cred_worker(void);
3005 +#endif
3006 +
3007 /*
3008 * Notification of system call entry/exit
3009 * - triggered by current->work.syscall_trace
3010 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3011 /* do the secure computing check first */
3012 secure_computing_strict(regs->regs[2]);
3013
3014 +#ifdef CONFIG_GRKERNSEC_SETXID
3015 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016 + gr_delayed_cred_worker();
3017 +#endif
3018 +
3019 if (!(current->ptrace & PT_PTRACED))
3020 goto out;
3021
3022 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3023 index a632bc1..0b77c7c 100644
3024 --- a/arch/mips/kernel/scall32-o32.S
3025 +++ b/arch/mips/kernel/scall32-o32.S
3026 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3027
3028 stack_done:
3029 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3030 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3031 + li t1, _TIF_SYSCALL_WORK
3032 and t0, t1
3033 bnez t0, syscall_trace_entry # -> yes
3034
3035 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3036 index 3b5a5e9..e1ee86d 100644
3037 --- a/arch/mips/kernel/scall64-64.S
3038 +++ b/arch/mips/kernel/scall64-64.S
3039 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3040
3041 sd a3, PT_R26(sp) # save a3 for syscall restarting
3042
3043 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3044 + li t1, _TIF_SYSCALL_WORK
3045 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3046 and t0, t1, t0
3047 bnez t0, syscall_trace_entry
3048 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3049 index 6be6f70..1859577 100644
3050 --- a/arch/mips/kernel/scall64-n32.S
3051 +++ b/arch/mips/kernel/scall64-n32.S
3052 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3053
3054 sd a3, PT_R26(sp) # save a3 for syscall restarting
3055
3056 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3057 + li t1, _TIF_SYSCALL_WORK
3058 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3059 and t0, t1, t0
3060 bnez t0, n32_syscall_trace_entry
3061 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3062 index 5422855..74e63a3 100644
3063 --- a/arch/mips/kernel/scall64-o32.S
3064 +++ b/arch/mips/kernel/scall64-o32.S
3065 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3066 PTR 4b, bad_stack
3067 .previous
3068
3069 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3070 + li t1, _TIF_SYSCALL_WORK
3071 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3072 and t0, t1, t0
3073 bnez t0, trace_a_syscall
3074 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3075 index c14f6df..537e729 100644
3076 --- a/arch/mips/mm/fault.c
3077 +++ b/arch/mips/mm/fault.c
3078 @@ -27,6 +27,23 @@
3079 #include <asm/highmem.h> /* For VMALLOC_END */
3080 #include <linux/kdebug.h>
3081
3082 +#ifdef CONFIG_PAX_PAGEEXEC
3083 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3084 +{
3085 + unsigned long i;
3086 +
3087 + printk(KERN_ERR "PAX: bytes at PC: ");
3088 + for (i = 0; i < 5; i++) {
3089 + unsigned int c;
3090 + if (get_user(c, (unsigned int *)pc+i))
3091 + printk(KERN_CONT "???????? ");
3092 + else
3093 + printk(KERN_CONT "%08x ", c);
3094 + }
3095 + printk("\n");
3096 +}
3097 +#endif
3098 +
3099 /*
3100 * This routine handles page faults. It determines the address,
3101 * and the problem, and then passes it off to one of the appropriate
3102 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3103 index 302d779..7d35bf8 100644
3104 --- a/arch/mips/mm/mmap.c
3105 +++ b/arch/mips/mm/mmap.c
3106 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3107 do_color_align = 1;
3108
3109 /* requesting a specific address */
3110 +
3111 +#ifdef CONFIG_PAX_RANDMMAP
3112 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3113 +#endif
3114 +
3115 if (addr) {
3116 if (do_color_align)
3117 addr = COLOUR_ALIGN(addr, pgoff);
3118 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3119 addr = PAGE_ALIGN(addr);
3120
3121 vma = find_vma(mm, addr);
3122 - if (TASK_SIZE - len >= addr &&
3123 - (!vma || addr + len <= vma->vm_start))
3124 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3125 return addr;
3126 }
3127
3128 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 /* At this point: (!vma || addr < vma->vm_end). */
3130 if (TASK_SIZE - len < addr)
3131 return -ENOMEM;
3132 - if (!vma || addr + len <= vma->vm_start)
3133 + if (check_heap_stack_gap(vmm, addr, len))
3134 return addr;
3135 addr = vma->vm_end;
3136 if (do_color_align)
3137 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3138 /* make sure it can fit in the remaining address space */
3139 if (likely(addr > len)) {
3140 vma = find_vma(mm, addr - len);
3141 - if (!vma || addr <= vma->vm_start) {
3142 + if (check_heap_stack_gap(vmm, addr - len, len))
3143 /* cache the address as a hint for next time */
3144 return mm->free_area_cache = addr - len;
3145 }
3146 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3147 * return with success:
3148 */
3149 vma = find_vma(mm, addr);
3150 - if (likely(!vma || addr + len <= vma->vm_start)) {
3151 + if (check_heap_stack_gap(vmm, addr, len)) {
3152 /* cache the address as a hint for next time */
3153 return mm->free_area_cache = addr;
3154 }
3155 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3156 mm->unmap_area = arch_unmap_area_topdown;
3157 }
3158 }
3159 -
3160 -static inline unsigned long brk_rnd(void)
3161 -{
3162 - unsigned long rnd = get_random_int();
3163 -
3164 - rnd = rnd << PAGE_SHIFT;
3165 - /* 8MB for 32bit, 256MB for 64bit */
3166 - if (TASK_IS_32BIT_ADDR)
3167 - rnd = rnd & 0x7ffffful;
3168 - else
3169 - rnd = rnd & 0xffffffful;
3170 -
3171 - return rnd;
3172 -}
3173 -
3174 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3175 -{
3176 - unsigned long base = mm->brk;
3177 - unsigned long ret;
3178 -
3179 - ret = PAGE_ALIGN(base + brk_rnd());
3180 -
3181 - if (ret < mm->brk)
3182 - return mm->brk;
3183 -
3184 - return ret;
3185 -}
3186 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3187 index 967d144..db12197 100644
3188 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3189 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3190 @@ -11,12 +11,14 @@
3191 #ifndef _ASM_PROC_CACHE_H
3192 #define _ASM_PROC_CACHE_H
3193
3194 +#include <linux/const.h>
3195 +
3196 /* L1 cache */
3197
3198 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3199 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3200 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3201 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3202 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3203 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3204
3205 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3206 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3207 index bcb5df2..84fabd2 100644
3208 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3209 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3210 @@ -16,13 +16,15 @@
3211 #ifndef _ASM_PROC_CACHE_H
3212 #define _ASM_PROC_CACHE_H
3213
3214 +#include <linux/const.h>
3215 +
3216 /*
3217 * L1 cache
3218 */
3219 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3220 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3221 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3222 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3223 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3224 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3225
3226 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3227 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3228 index 4ce7a01..449202a 100644
3229 --- a/arch/openrisc/include/asm/cache.h
3230 +++ b/arch/openrisc/include/asm/cache.h
3231 @@ -19,11 +19,13 @@
3232 #ifndef __ASM_OPENRISC_CACHE_H
3233 #define __ASM_OPENRISC_CACHE_H
3234
3235 +#include <linux/const.h>
3236 +
3237 /* FIXME: How can we replace these with values from the CPU...
3238 * they shouldn't be hard-coded!
3239 */
3240
3241 -#define L1_CACHE_BYTES 16
3242 #define L1_CACHE_SHIFT 4
3243 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3244
3245 #endif /* __ASM_OPENRISC_CACHE_H */
3246 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3247 index 6c6defc..d30653d 100644
3248 --- a/arch/parisc/include/asm/atomic.h
3249 +++ b/arch/parisc/include/asm/atomic.h
3250 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3251
3252 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3253
3254 +#define atomic64_read_unchecked(v) atomic64_read(v)
3255 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3256 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3257 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3258 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3259 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3260 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3261 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3262 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3263 +
3264 #endif /* !CONFIG_64BIT */
3265
3266
3267 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3268 index 47f11c7..3420df2 100644
3269 --- a/arch/parisc/include/asm/cache.h
3270 +++ b/arch/parisc/include/asm/cache.h
3271 @@ -5,6 +5,7 @@
3272 #ifndef __ARCH_PARISC_CACHE_H
3273 #define __ARCH_PARISC_CACHE_H
3274
3275 +#include <linux/const.h>
3276
3277 /*
3278 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3279 @@ -15,13 +16,13 @@
3280 * just ruin performance.
3281 */
3282 #ifdef CONFIG_PA20
3283 -#define L1_CACHE_BYTES 64
3284 #define L1_CACHE_SHIFT 6
3285 #else
3286 -#define L1_CACHE_BYTES 32
3287 #define L1_CACHE_SHIFT 5
3288 #endif
3289
3290 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3291 +
3292 #ifndef __ASSEMBLY__
3293
3294 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3295 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3296 index 19f6cb1..6c78cf2 100644
3297 --- a/arch/parisc/include/asm/elf.h
3298 +++ b/arch/parisc/include/asm/elf.h
3299 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3300
3301 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3302
3303 +#ifdef CONFIG_PAX_ASLR
3304 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3305 +
3306 +#define PAX_DELTA_MMAP_LEN 16
3307 +#define PAX_DELTA_STACK_LEN 16
3308 +#endif
3309 +
3310 /* This yields a mask that user programs can use to figure out what
3311 instruction set this CPU supports. This could be done in user space,
3312 but it's not easy, and we've already done it here. */
3313 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3314 index fc987a1..6e068ef 100644
3315 --- a/arch/parisc/include/asm/pgalloc.h
3316 +++ b/arch/parisc/include/asm/pgalloc.h
3317 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3318 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3319 }
3320
3321 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3322 +{
3323 + pgd_populate(mm, pgd, pmd);
3324 +}
3325 +
3326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3327 {
3328 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3329 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3330 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3331 #define pmd_free(mm, x) do { } while (0)
3332 #define pgd_populate(mm, pmd, pte) BUG()
3333 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3334
3335 #endif
3336
3337 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3338 index ee99f23..802b0a1 100644
3339 --- a/arch/parisc/include/asm/pgtable.h
3340 +++ b/arch/parisc/include/asm/pgtable.h
3341 @@ -212,6 +212,17 @@ struct vm_area_struct;
3342 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3343 #define PAGE_COPY PAGE_EXECREAD
3344 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3345 +
3346 +#ifdef CONFIG_PAX_PAGEEXEC
3347 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3348 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3349 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3350 +#else
3351 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3352 +# define PAGE_COPY_NOEXEC PAGE_COPY
3353 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3354 +#endif
3355 +
3356 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3357 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3358 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3359 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3360 index 4ba2c93..f5e3974 100644
3361 --- a/arch/parisc/include/asm/uaccess.h
3362 +++ b/arch/parisc/include/asm/uaccess.h
3363 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3364 const void __user *from,
3365 unsigned long n)
3366 {
3367 - int sz = __compiletime_object_size(to);
3368 + size_t sz = __compiletime_object_size(to);
3369 int ret = -EFAULT;
3370
3371 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3372 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3373 ret = __copy_from_user(to, from, n);
3374 else
3375 copy_from_user_overflow();
3376 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3377 index 5e34ccf..672bc9c 100644
3378 --- a/arch/parisc/kernel/module.c
3379 +++ b/arch/parisc/kernel/module.c
3380 @@ -98,16 +98,38 @@
3381
3382 /* three functions to determine where in the module core
3383 * or init pieces the location is */
3384 +static inline int in_init_rx(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rx &&
3387 + loc < (me->module_init_rx + me->init_size_rx));
3388 +}
3389 +
3390 +static inline int in_init_rw(struct module *me, void *loc)
3391 +{
3392 + return (loc >= me->module_init_rw &&
3393 + loc < (me->module_init_rw + me->init_size_rw));
3394 +}
3395 +
3396 static inline int in_init(struct module *me, void *loc)
3397 {
3398 - return (loc >= me->module_init &&
3399 - loc <= (me->module_init + me->init_size));
3400 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3401 +}
3402 +
3403 +static inline int in_core_rx(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rx &&
3406 + loc < (me->module_core_rx + me->core_size_rx));
3407 +}
3408 +
3409 +static inline int in_core_rw(struct module *me, void *loc)
3410 +{
3411 + return (loc >= me->module_core_rw &&
3412 + loc < (me->module_core_rw + me->core_size_rw));
3413 }
3414
3415 static inline int in_core(struct module *me, void *loc)
3416 {
3417 - return (loc >= me->module_core &&
3418 - loc <= (me->module_core + me->core_size));
3419 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3420 }
3421
3422 static inline int in_local(struct module *me, void *loc)
3423 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3424 }
3425
3426 /* align things a bit */
3427 - me->core_size = ALIGN(me->core_size, 16);
3428 - me->arch.got_offset = me->core_size;
3429 - me->core_size += gots * sizeof(struct got_entry);
3430 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431 + me->arch.got_offset = me->core_size_rw;
3432 + me->core_size_rw += gots * sizeof(struct got_entry);
3433
3434 - me->core_size = ALIGN(me->core_size, 16);
3435 - me->arch.fdesc_offset = me->core_size;
3436 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3437 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3438 + me->arch.fdesc_offset = me->core_size_rw;
3439 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3440
3441 me->arch.got_max = gots;
3442 me->arch.fdesc_max = fdescs;
3443 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3444
3445 BUG_ON(value == 0);
3446
3447 - got = me->module_core + me->arch.got_offset;
3448 + got = me->module_core_rw + me->arch.got_offset;
3449 for (i = 0; got[i].addr; i++)
3450 if (got[i].addr == value)
3451 goto out;
3452 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3453 #ifdef CONFIG_64BIT
3454 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455 {
3456 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3457 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3458
3459 if (!value) {
3460 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3461 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3462
3463 /* Create new one */
3464 fdesc->addr = value;
3465 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3466 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3467 return (Elf_Addr)fdesc;
3468 }
3469 #endif /* CONFIG_64BIT */
3470 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3471
3472 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3473 end = table + sechdrs[me->arch.unwind_section].sh_size;
3474 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3475 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3476
3477 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3478 me->arch.unwind_section, table, end, gp);
3479 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3480 index c9b9322..02d8940 100644
3481 --- a/arch/parisc/kernel/sys_parisc.c
3482 +++ b/arch/parisc/kernel/sys_parisc.c
3483 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3484 /* At this point: (!vma || addr < vma->vm_end). */
3485 if (TASK_SIZE - len < addr)
3486 return -ENOMEM;
3487 - if (!vma || addr + len <= vma->vm_start)
3488 + if (check_heap_stack_gap(vma, addr, len))
3489 return addr;
3490 addr = vma->vm_end;
3491 }
3492 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3493 /* At this point: (!vma || addr < vma->vm_end). */
3494 if (TASK_SIZE - len < addr)
3495 return -ENOMEM;
3496 - if (!vma || addr + len <= vma->vm_start)
3497 + if (check_heap_stack_gap(vma, addr, len))
3498 return addr;
3499 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3500 if (addr < vma->vm_end) /* handle wraparound */
3501 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3502 if (flags & MAP_FIXED)
3503 return addr;
3504 if (!addr)
3505 - addr = TASK_UNMAPPED_BASE;
3506 + addr = current->mm->mmap_base;
3507
3508 if (filp) {
3509 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3510 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3511 index 45ba99f..8e22c33 100644
3512 --- a/arch/parisc/kernel/traps.c
3513 +++ b/arch/parisc/kernel/traps.c
3514 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3515
3516 down_read(&current->mm->mmap_sem);
3517 vma = find_vma(current->mm,regs->iaoq[0]);
3518 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3519 - && (vma->vm_flags & VM_EXEC)) {
3520 -
3521 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3522 fault_address = regs->iaoq[0];
3523 fault_space = regs->iasq[0];
3524
3525 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3526 index 18162ce..94de376 100644
3527 --- a/arch/parisc/mm/fault.c
3528 +++ b/arch/parisc/mm/fault.c
3529 @@ -15,6 +15,7 @@
3530 #include <linux/sched.h>
3531 #include <linux/interrupt.h>
3532 #include <linux/module.h>
3533 +#include <linux/unistd.h>
3534
3535 #include <asm/uaccess.h>
3536 #include <asm/traps.h>
3537 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3538 static unsigned long
3539 parisc_acctyp(unsigned long code, unsigned int inst)
3540 {
3541 - if (code == 6 || code == 16)
3542 + if (code == 6 || code == 7 || code == 16)
3543 return VM_EXEC;
3544
3545 switch (inst & 0xf0000000) {
3546 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3547 }
3548 #endif
3549
3550 +#ifdef CONFIG_PAX_PAGEEXEC
3551 +/*
3552 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3553 + *
3554 + * returns 1 when task should be killed
3555 + * 2 when rt_sigreturn trampoline was detected
3556 + * 3 when unpatched PLT trampoline was detected
3557 + */
3558 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3559 +{
3560 +
3561 +#ifdef CONFIG_PAX_EMUPLT
3562 + int err;
3563 +
3564 + do { /* PaX: unpatched PLT emulation */
3565 + unsigned int bl, depwi;
3566 +
3567 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3568 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3569 +
3570 + if (err)
3571 + break;
3572 +
3573 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3574 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3575 +
3576 + err = get_user(ldw, (unsigned int *)addr);
3577 + err |= get_user(bv, (unsigned int *)(addr+4));
3578 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3579 +
3580 + if (err)
3581 + break;
3582 +
3583 + if (ldw == 0x0E801096U &&
3584 + bv == 0xEAC0C000U &&
3585 + ldw2 == 0x0E881095U)
3586 + {
3587 + unsigned int resolver, map;
3588 +
3589 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3590 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3591 + if (err)
3592 + break;
3593 +
3594 + regs->gr[20] = instruction_pointer(regs)+8;
3595 + regs->gr[21] = map;
3596 + regs->gr[22] = resolver;
3597 + regs->iaoq[0] = resolver | 3UL;
3598 + regs->iaoq[1] = regs->iaoq[0] + 4;
3599 + return 3;
3600 + }
3601 + }
3602 + } while (0);
3603 +#endif
3604 +
3605 +#ifdef CONFIG_PAX_EMUTRAMP
3606 +
3607 +#ifndef CONFIG_PAX_EMUSIGRT
3608 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3609 + return 1;
3610 +#endif
3611 +
3612 + do { /* PaX: rt_sigreturn emulation */
3613 + unsigned int ldi1, ldi2, bel, nop;
3614 +
3615 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3616 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3617 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3618 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3619 +
3620 + if (err)
3621 + break;
3622 +
3623 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3624 + ldi2 == 0x3414015AU &&
3625 + bel == 0xE4008200U &&
3626 + nop == 0x08000240U)
3627 + {
3628 + regs->gr[25] = (ldi1 & 2) >> 1;
3629 + regs->gr[20] = __NR_rt_sigreturn;
3630 + regs->gr[31] = regs->iaoq[1] + 16;
3631 + regs->sr[0] = regs->iasq[1];
3632 + regs->iaoq[0] = 0x100UL;
3633 + regs->iaoq[1] = regs->iaoq[0] + 4;
3634 + regs->iasq[0] = regs->sr[2];
3635 + regs->iasq[1] = regs->sr[2];
3636 + return 2;
3637 + }
3638 + } while (0);
3639 +#endif
3640 +
3641 + return 1;
3642 +}
3643 +
3644 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3645 +{
3646 + unsigned long i;
3647 +
3648 + printk(KERN_ERR "PAX: bytes at PC: ");
3649 + for (i = 0; i < 5; i++) {
3650 + unsigned int c;
3651 + if (get_user(c, (unsigned int *)pc+i))
3652 + printk(KERN_CONT "???????? ");
3653 + else
3654 + printk(KERN_CONT "%08x ", c);
3655 + }
3656 + printk("\n");
3657 +}
3658 +#endif
3659 +
3660 int fixup_exception(struct pt_regs *regs)
3661 {
3662 const struct exception_table_entry *fix;
3663 @@ -192,8 +303,33 @@ good_area:
3664
3665 acc_type = parisc_acctyp(code,regs->iir);
3666
3667 - if ((vma->vm_flags & acc_type) != acc_type)
3668 + if ((vma->vm_flags & acc_type) != acc_type) {
3669 +
3670 +#ifdef CONFIG_PAX_PAGEEXEC
3671 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3672 + (address & ~3UL) == instruction_pointer(regs))
3673 + {
3674 + up_read(&mm->mmap_sem);
3675 + switch (pax_handle_fetch_fault(regs)) {
3676 +
3677 +#ifdef CONFIG_PAX_EMUPLT
3678 + case 3:
3679 + return;
3680 +#endif
3681 +
3682 +#ifdef CONFIG_PAX_EMUTRAMP
3683 + case 2:
3684 + return;
3685 +#endif
3686 +
3687 + }
3688 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3689 + do_group_exit(SIGKILL);
3690 + }
3691 +#endif
3692 +
3693 goto bad_area;
3694 + }
3695
3696 /*
3697 * If for any reason at all we couldn't handle the fault, make
3698 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3699 index da29032..f76c24c 100644
3700 --- a/arch/powerpc/include/asm/atomic.h
3701 +++ b/arch/powerpc/include/asm/atomic.h
3702 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3703 return t1;
3704 }
3705
3706 +#define atomic64_read_unchecked(v) atomic64_read(v)
3707 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3708 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3709 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3710 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3711 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3712 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3713 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3714 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3715 +
3716 #endif /* __powerpc64__ */
3717
3718 #endif /* __KERNEL__ */
3719 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3720 index 9e495c9..b6878e5 100644
3721 --- a/arch/powerpc/include/asm/cache.h
3722 +++ b/arch/powerpc/include/asm/cache.h
3723 @@ -3,6 +3,7 @@
3724
3725 #ifdef __KERNEL__
3726
3727 +#include <linux/const.h>
3728
3729 /* bytes per L1 cache line */
3730 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3731 @@ -22,7 +23,7 @@
3732 #define L1_CACHE_SHIFT 7
3733 #endif
3734
3735 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3736 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3737
3738 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3739
3740 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3741 index 3bf9cca..e7457d0 100644
3742 --- a/arch/powerpc/include/asm/elf.h
3743 +++ b/arch/powerpc/include/asm/elf.h
3744 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3745 the loader. We need to make sure that it is out of the way of the program
3746 that it will "exec", and that there is sufficient room for the brk. */
3747
3748 -extern unsigned long randomize_et_dyn(unsigned long base);
3749 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3750 +#define ELF_ET_DYN_BASE (0x20000000)
3751 +
3752 +#ifdef CONFIG_PAX_ASLR
3753 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3754 +
3755 +#ifdef __powerpc64__
3756 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3757 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3758 +#else
3759 +#define PAX_DELTA_MMAP_LEN 15
3760 +#define PAX_DELTA_STACK_LEN 15
3761 +#endif
3762 +#endif
3763
3764 /*
3765 * Our registers are always unsigned longs, whether we're a 32 bit
3766 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3767 (0x7ff >> (PAGE_SHIFT - 12)) : \
3768 (0x3ffff >> (PAGE_SHIFT - 12)))
3769
3770 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3771 -#define arch_randomize_brk arch_randomize_brk
3772 -
3773 #endif /* __KERNEL__ */
3774
3775 /*
3776 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3777 index 8196e9c..d83a9f3 100644
3778 --- a/arch/powerpc/include/asm/exec.h
3779 +++ b/arch/powerpc/include/asm/exec.h
3780 @@ -4,6 +4,6 @@
3781 #ifndef _ASM_POWERPC_EXEC_H
3782 #define _ASM_POWERPC_EXEC_H
3783
3784 -extern unsigned long arch_align_stack(unsigned long sp);
3785 +#define arch_align_stack(x) ((x) & ~0xfUL)
3786
3787 #endif /* _ASM_POWERPC_EXEC_H */
3788 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3789 index bca8fdc..61e9580 100644
3790 --- a/arch/powerpc/include/asm/kmap_types.h
3791 +++ b/arch/powerpc/include/asm/kmap_types.h
3792 @@ -27,6 +27,7 @@ enum km_type {
3793 KM_PPC_SYNC_PAGE,
3794 KM_PPC_SYNC_ICACHE,
3795 KM_KDB,
3796 + KM_CLEARPAGE,
3797 KM_TYPE_NR
3798 };
3799
3800 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3801 index d4a7f64..451de1c 100644
3802 --- a/arch/powerpc/include/asm/mman.h
3803 +++ b/arch/powerpc/include/asm/mman.h
3804 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3805 }
3806 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3807
3808 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3809 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3810 {
3811 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3812 }
3813 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3814 index f072e97..b436dee 100644
3815 --- a/arch/powerpc/include/asm/page.h
3816 +++ b/arch/powerpc/include/asm/page.h
3817 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3818 * and needs to be executable. This means the whole heap ends
3819 * up being executable.
3820 */
3821 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3822 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3823 +#define VM_DATA_DEFAULT_FLAGS32 \
3824 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3825 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3826
3827 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3828 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3829 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3830 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3831 #endif
3832
3833 +#define ktla_ktva(addr) (addr)
3834 +#define ktva_ktla(addr) (addr)
3835 +
3836 /*
3837 * Use the top bit of the higher-level page table entries to indicate whether
3838 * the entries we point to contain hugepages. This works because we know that
3839 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3840 index fed85e6..da5c71b 100644
3841 --- a/arch/powerpc/include/asm/page_64.h
3842 +++ b/arch/powerpc/include/asm/page_64.h
3843 @@ -146,15 +146,18 @@ do { \
3844 * stack by default, so in the absence of a PT_GNU_STACK program header
3845 * we turn execute permission off.
3846 */
3847 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3848 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3849 +#define VM_STACK_DEFAULT_FLAGS32 \
3850 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3851 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3852
3853 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3854 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3855
3856 +#ifndef CONFIG_PAX_PAGEEXEC
3857 #define VM_STACK_DEFAULT_FLAGS \
3858 (is_32bit_task() ? \
3859 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3860 +#endif
3861
3862 #include <asm-generic/getorder.h>
3863
3864 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3865 index 292725c..f87ae14 100644
3866 --- a/arch/powerpc/include/asm/pgalloc-64.h
3867 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3868 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3869 #ifndef CONFIG_PPC_64K_PAGES
3870
3871 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3872 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3873
3874 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3875 {
3876 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3877 pud_set(pud, (unsigned long)pmd);
3878 }
3879
3880 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3881 +{
3882 + pud_populate(mm, pud, pmd);
3883 +}
3884 +
3885 #define pmd_populate(mm, pmd, pte_page) \
3886 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3887 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3888 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3889 #else /* CONFIG_PPC_64K_PAGES */
3890
3891 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3892 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3893
3894 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3895 pte_t *pte)
3896 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3897 index 2e0e411..7899c68 100644
3898 --- a/arch/powerpc/include/asm/pgtable.h
3899 +++ b/arch/powerpc/include/asm/pgtable.h
3900 @@ -2,6 +2,7 @@
3901 #define _ASM_POWERPC_PGTABLE_H
3902 #ifdef __KERNEL__
3903
3904 +#include <linux/const.h>
3905 #ifndef __ASSEMBLY__
3906 #include <asm/processor.h> /* For TASK_SIZE */
3907 #include <asm/mmu.h>
3908 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3909 index 4aad413..85d86bf 100644
3910 --- a/arch/powerpc/include/asm/pte-hash32.h
3911 +++ b/arch/powerpc/include/asm/pte-hash32.h
3912 @@ -21,6 +21,7 @@
3913 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3914 #define _PAGE_USER 0x004 /* usermode access allowed */
3915 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3916 +#define _PAGE_EXEC _PAGE_GUARDED
3917 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3918 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3919 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3920 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3921 index 360585d..c3930ef 100644
3922 --- a/arch/powerpc/include/asm/reg.h
3923 +++ b/arch/powerpc/include/asm/reg.h
3924 @@ -212,6 +212,7 @@
3925 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3926 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3927 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3928 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3929 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3930 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3931 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3932 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3933 index 68831e9..379c695 100644
3934 --- a/arch/powerpc/include/asm/thread_info.h
3935 +++ b/arch/powerpc/include/asm/thread_info.h
3936 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3937 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3938 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3939 #define TIF_SINGLESTEP 8 /* singlestepping active */
3940 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3941 #define TIF_SECCOMP 10 /* secure computing */
3942 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3943 #define TIF_NOERROR 12 /* Force successful syscall return */
3944 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3945 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3946 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3947 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3948 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3949
3950 /* as above, but as bit values */
3951 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3952 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3953 #define _TIF_NOERROR (1<<TIF_NOERROR)
3954 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3955 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3956 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3957 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3958 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3959 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3960 + _TIF_GRSEC_SETXID)
3961
3962 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3963 _TIF_NOTIFY_RESUME)
3964 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3965 index 17bb40c..353c98b 100644
3966 --- a/arch/powerpc/include/asm/uaccess.h
3967 +++ b/arch/powerpc/include/asm/uaccess.h
3968 @@ -13,6 +13,8 @@
3969 #define VERIFY_READ 0
3970 #define VERIFY_WRITE 1
3971
3972 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3973 +
3974 /*
3975 * The fs value determines whether argument validity checking should be
3976 * performed or not. If get_fs() == USER_DS, checking is performed, with
3977 @@ -329,52 +331,6 @@ do { \
3978 extern unsigned long __copy_tofrom_user(void __user *to,
3979 const void __user *from, unsigned long size);
3980
3981 -#ifndef __powerpc64__
3982 -
3983 -static inline unsigned long copy_from_user(void *to,
3984 - const void __user *from, unsigned long n)
3985 -{
3986 - unsigned long over;
3987 -
3988 - if (access_ok(VERIFY_READ, from, n))
3989 - return __copy_tofrom_user((__force void __user *)to, from, n);
3990 - if ((unsigned long)from < TASK_SIZE) {
3991 - over = (unsigned long)from + n - TASK_SIZE;
3992 - return __copy_tofrom_user((__force void __user *)to, from,
3993 - n - over) + over;
3994 - }
3995 - return n;
3996 -}
3997 -
3998 -static inline unsigned long copy_to_user(void __user *to,
3999 - const void *from, unsigned long n)
4000 -{
4001 - unsigned long over;
4002 -
4003 - if (access_ok(VERIFY_WRITE, to, n))
4004 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4005 - if ((unsigned long)to < TASK_SIZE) {
4006 - over = (unsigned long)to + n - TASK_SIZE;
4007 - return __copy_tofrom_user(to, (__force void __user *)from,
4008 - n - over) + over;
4009 - }
4010 - return n;
4011 -}
4012 -
4013 -#else /* __powerpc64__ */
4014 -
4015 -#define __copy_in_user(to, from, size) \
4016 - __copy_tofrom_user((to), (from), (size))
4017 -
4018 -extern unsigned long copy_from_user(void *to, const void __user *from,
4019 - unsigned long n);
4020 -extern unsigned long copy_to_user(void __user *to, const void *from,
4021 - unsigned long n);
4022 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4023 - unsigned long n);
4024 -
4025 -#endif /* __powerpc64__ */
4026 -
4027 static inline unsigned long __copy_from_user_inatomic(void *to,
4028 const void __user *from, unsigned long n)
4029 {
4030 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4031 if (ret == 0)
4032 return 0;
4033 }
4034 +
4035 + if (!__builtin_constant_p(n))
4036 + check_object_size(to, n, false);
4037 +
4038 return __copy_tofrom_user((__force void __user *)to, from, n);
4039 }
4040
4041 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4042 if (ret == 0)
4043 return 0;
4044 }
4045 +
4046 + if (!__builtin_constant_p(n))
4047 + check_object_size(from, n, true);
4048 +
4049 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4050 }
4051
4052 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4053 return __copy_to_user_inatomic(to, from, size);
4054 }
4055
4056 +#ifndef __powerpc64__
4057 +
4058 +static inline unsigned long __must_check copy_from_user(void *to,
4059 + const void __user *from, unsigned long n)
4060 +{
4061 + unsigned long over;
4062 +
4063 + if ((long)n < 0)
4064 + return n;
4065 +
4066 + if (access_ok(VERIFY_READ, from, n)) {
4067 + if (!__builtin_constant_p(n))
4068 + check_object_size(to, n, false);
4069 + return __copy_tofrom_user((__force void __user *)to, from, n);
4070 + }
4071 + if ((unsigned long)from < TASK_SIZE) {
4072 + over = (unsigned long)from + n - TASK_SIZE;
4073 + if (!__builtin_constant_p(n - over))
4074 + check_object_size(to, n - over, false);
4075 + return __copy_tofrom_user((__force void __user *)to, from,
4076 + n - over) + over;
4077 + }
4078 + return n;
4079 +}
4080 +
4081 +static inline unsigned long __must_check copy_to_user(void __user *to,
4082 + const void *from, unsigned long n)
4083 +{
4084 + unsigned long over;
4085 +
4086 + if ((long)n < 0)
4087 + return n;
4088 +
4089 + if (access_ok(VERIFY_WRITE, to, n)) {
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n, true);
4092 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4093 + }
4094 + if ((unsigned long)to < TASK_SIZE) {
4095 + over = (unsigned long)to + n - TASK_SIZE;
4096 + if (!__builtin_constant_p(n))
4097 + check_object_size(from, n - over, true);
4098 + return __copy_tofrom_user(to, (__force void __user *)from,
4099 + n - over) + over;
4100 + }
4101 + return n;
4102 +}
4103 +
4104 +#else /* __powerpc64__ */
4105 +
4106 +#define __copy_in_user(to, from, size) \
4107 + __copy_tofrom_user((to), (from), (size))
4108 +
4109 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4110 +{
4111 + if ((long)n < 0 || n > INT_MAX)
4112 + return n;
4113 +
4114 + if (!__builtin_constant_p(n))
4115 + check_object_size(to, n, false);
4116 +
4117 + if (likely(access_ok(VERIFY_READ, from, n)))
4118 + n = __copy_from_user(to, from, n);
4119 + else
4120 + memset(to, 0, n);
4121 + return n;
4122 +}
4123 +
4124 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4125 +{
4126 + if ((long)n < 0 || n > INT_MAX)
4127 + return n;
4128 +
4129 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4130 + if (!__builtin_constant_p(n))
4131 + check_object_size(from, n, true);
4132 + n = __copy_to_user(to, from, n);
4133 + }
4134 + return n;
4135 +}
4136 +
4137 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4138 + unsigned long n);
4139 +
4140 +#endif /* __powerpc64__ */
4141 +
4142 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4143
4144 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4145 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4146 index 7215cc2..a9730c1 100644
4147 --- a/arch/powerpc/kernel/exceptions-64e.S
4148 +++ b/arch/powerpc/kernel/exceptions-64e.S
4149 @@ -661,6 +661,7 @@ storage_fault_common:
4150 std r14,_DAR(r1)
4151 std r15,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 mr r4,r14
4155 mr r5,r15
4156 ld r14,PACA_EXGEN+EX_R14(r13)
4157 @@ -669,8 +670,7 @@ storage_fault_common:
4158 cmpdi r3,0
4159 bne- 1f
4160 b .ret_from_except_lite
4161 -1: bl .save_nvgprs
4162 - mr r5,r3
4163 +1: mr r5,r3
4164 addi r3,r1,STACK_FRAME_OVERHEAD
4165 ld r4,_DAR(r1)
4166 bl .bad_page_fault
4167 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4168 index 1c06d29..c2a339b 100644
4169 --- a/arch/powerpc/kernel/exceptions-64s.S
4170 +++ b/arch/powerpc/kernel/exceptions-64s.S
4171 @@ -888,10 +888,10 @@ handle_page_fault:
4172 11: ld r4,_DAR(r1)
4173 ld r5,_DSISR(r1)
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175 + bl .save_nvgprs
4176 bl .do_page_fault
4177 cmpdi r3,0
4178 beq+ 12f
4179 - bl .save_nvgprs
4180 mr r5,r3
4181 addi r3,r1,STACK_FRAME_OVERHEAD
4182 lwz r4,_DAR(r1)
4183 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4184 index 2e3200c..72095ce 100644
4185 --- a/arch/powerpc/kernel/module_32.c
4186 +++ b/arch/powerpc/kernel/module_32.c
4187 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4188 me->arch.core_plt_section = i;
4189 }
4190 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4191 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4192 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4193 return -ENOEXEC;
4194 }
4195
4196 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4197
4198 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4199 /* Init, or core PLT? */
4200 - if (location >= mod->module_core
4201 - && location < mod->module_core + mod->core_size)
4202 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4203 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4204 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4205 - else
4206 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4207 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4208 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4209 + else {
4210 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4211 + return ~0UL;
4212 + }
4213
4214 /* Find this entry, or if that fails, the next avail. entry */
4215 while (entry->jump[0]) {
4216 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4217 index 710f400..d00ebe6 100644
4218 --- a/arch/powerpc/kernel/process.c
4219 +++ b/arch/powerpc/kernel/process.c
4220 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4221 * Lookup NIP late so we have the best change of getting the
4222 * above info out without failing
4223 */
4224 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4225 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4226 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4227 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4228 #endif
4229 show_stack(current, (unsigned long *) regs->gpr[1]);
4230 if (!user_mode(regs))
4231 @@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4232 newsp = stack[0];
4233 ip = stack[STACK_FRAME_LR_SAVE];
4234 if (!firstframe || ip != lr) {
4235 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4236 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4237 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4238 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4239 - printk(" (%pS)",
4240 + printk(" (%pA)",
4241 (void *)current->ret_stack[curr_frame].ret);
4242 curr_frame--;
4243 }
4244 @@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4245 struct pt_regs *regs = (struct pt_regs *)
4246 (sp + STACK_FRAME_OVERHEAD);
4247 lr = regs->link;
4248 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4249 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4250 regs->trap, (void *)regs->nip, (void *)lr);
4251 firstframe = 1;
4252 }
4253 @@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4254 mtspr(SPRN_CTRLT, ctrl);
4255 }
4256 #endif /* CONFIG_PPC64 */
4257 -
4258 -unsigned long arch_align_stack(unsigned long sp)
4259 -{
4260 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4261 - sp -= get_random_int() & ~PAGE_MASK;
4262 - return sp & ~0xf;
4263 -}
4264 -
4265 -static inline unsigned long brk_rnd(void)
4266 -{
4267 - unsigned long rnd = 0;
4268 -
4269 - /* 8MB for 32bit, 1GB for 64bit */
4270 - if (is_32bit_task())
4271 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4272 - else
4273 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4274 -
4275 - return rnd << PAGE_SHIFT;
4276 -}
4277 -
4278 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4279 -{
4280 - unsigned long base = mm->brk;
4281 - unsigned long ret;
4282 -
4283 -#ifdef CONFIG_PPC_STD_MMU_64
4284 - /*
4285 - * If we are using 1TB segments and we are allowed to randomise
4286 - * the heap, we can put it above 1TB so it is backed by a 1TB
4287 - * segment. Otherwise the heap will be in the bottom 1TB
4288 - * which always uses 256MB segments and this may result in a
4289 - * performance penalty.
4290 - */
4291 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4292 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4293 -#endif
4294 -
4295 - ret = PAGE_ALIGN(base + brk_rnd());
4296 -
4297 - if (ret < mm->brk)
4298 - return mm->brk;
4299 -
4300 - return ret;
4301 -}
4302 -
4303 -unsigned long randomize_et_dyn(unsigned long base)
4304 -{
4305 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4306 -
4307 - if (ret < base)
4308 - return base;
4309 -
4310 - return ret;
4311 -}
4312 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4313 index c10fc28..c4ef063 100644
4314 --- a/arch/powerpc/kernel/ptrace.c
4315 +++ b/arch/powerpc/kernel/ptrace.c
4316 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4317 return ret;
4318 }
4319
4320 +#ifdef CONFIG_GRKERNSEC_SETXID
4321 +extern void gr_delayed_cred_worker(void);
4322 +#endif
4323 +
4324 /*
4325 * We must return the syscall number to actually look up in the table.
4326 * This can be -1L to skip running any syscall at all.
4327 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4328
4329 secure_computing_strict(regs->gpr[0]);
4330
4331 +#ifdef CONFIG_GRKERNSEC_SETXID
4332 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4333 + gr_delayed_cred_worker();
4334 +#endif
4335 +
4336 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4337 tracehook_report_syscall_entry(regs))
4338 /*
4339 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4340 {
4341 int step;
4342
4343 +#ifdef CONFIG_GRKERNSEC_SETXID
4344 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4345 + gr_delayed_cred_worker();
4346 +#endif
4347 +
4348 audit_syscall_exit(regs);
4349
4350 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4351 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4352 index 8b4c049..dcd6ef3 100644
4353 --- a/arch/powerpc/kernel/signal_32.c
4354 +++ b/arch/powerpc/kernel/signal_32.c
4355 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4356 /* Save user registers on the stack */
4357 frame = &rt_sf->uc.uc_mcontext;
4358 addr = frame;
4359 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4360 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4361 if (save_user_regs(regs, frame, 0, 1))
4362 goto badframe;
4363 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4364 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4365 index d183f87..1867f1a 100644
4366 --- a/arch/powerpc/kernel/signal_64.c
4367 +++ b/arch/powerpc/kernel/signal_64.c
4368 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4369 current->thread.fpscr.val = 0;
4370
4371 /* Set up to return from userspace. */
4372 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4373 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4374 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4375 } else {
4376 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4377 diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
4378 index f2496f2..4e3cc47 100644
4379 --- a/arch/powerpc/kernel/syscalls.c
4380 +++ b/arch/powerpc/kernel/syscalls.c
4381 @@ -107,11 +107,11 @@ long ppc64_personality(unsigned long personality)
4382 long ret;
4383
4384 if (personality(current->personality) == PER_LINUX32
4385 - && personality == PER_LINUX)
4386 - personality = PER_LINUX32;
4387 + && personality(personality) == PER_LINUX)
4388 + personality = (personality & ~PER_MASK) | PER_LINUX32;
4389 ret = sys_personality(personality);
4390 - if (ret == PER_LINUX32)
4391 - ret = PER_LINUX;
4392 + if (personality(ret) == PER_LINUX32)
4393 + ret = (ret & ~PER_MASK) | PER_LINUX;
4394 return ret;
4395 }
4396 #endif
4397 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4398 index 1589723..cefe690 100644
4399 --- a/arch/powerpc/kernel/traps.c
4400 +++ b/arch/powerpc/kernel/traps.c
4401 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4402 return flags;
4403 }
4404
4405 +extern void gr_handle_kernel_exploit(void);
4406 +
4407 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4408 int signr)
4409 {
4410 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4411 panic("Fatal exception in interrupt");
4412 if (panic_on_oops)
4413 panic("Fatal exception");
4414 +
4415 + gr_handle_kernel_exploit();
4416 +
4417 do_exit(signr);
4418 }
4419
4420 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4421 index 9eb5b9b..e45498a 100644
4422 --- a/arch/powerpc/kernel/vdso.c
4423 +++ b/arch/powerpc/kernel/vdso.c
4424 @@ -34,6 +34,7 @@
4425 #include <asm/firmware.h>
4426 #include <asm/vdso.h>
4427 #include <asm/vdso_datapage.h>
4428 +#include <asm/mman.h>
4429
4430 #include "setup.h"
4431
4432 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4433 vdso_base = VDSO32_MBASE;
4434 #endif
4435
4436 - current->mm->context.vdso_base = 0;
4437 + current->mm->context.vdso_base = ~0UL;
4438
4439 /* vDSO has a problem and was disabled, just don't "enable" it for the
4440 * process
4441 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4442 vdso_base = get_unmapped_area(NULL, vdso_base,
4443 (vdso_pages << PAGE_SHIFT) +
4444 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4445 - 0, 0);
4446 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4447 if (IS_ERR_VALUE(vdso_base)) {
4448 rc = vdso_base;
4449 goto fail_mmapsem;
4450 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4451 index 5eea6f3..5d10396 100644
4452 --- a/arch/powerpc/lib/usercopy_64.c
4453 +++ b/arch/powerpc/lib/usercopy_64.c
4454 @@ -9,22 +9,6 @@
4455 #include <linux/module.h>
4456 #include <asm/uaccess.h>
4457
4458 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4459 -{
4460 - if (likely(access_ok(VERIFY_READ, from, n)))
4461 - n = __copy_from_user(to, from, n);
4462 - else
4463 - memset(to, 0, n);
4464 - return n;
4465 -}
4466 -
4467 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4468 -{
4469 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4470 - n = __copy_to_user(to, from, n);
4471 - return n;
4472 -}
4473 -
4474 unsigned long copy_in_user(void __user *to, const void __user *from,
4475 unsigned long n)
4476 {
4477 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4478 return n;
4479 }
4480
4481 -EXPORT_SYMBOL(copy_from_user);
4482 -EXPORT_SYMBOL(copy_to_user);
4483 EXPORT_SYMBOL(copy_in_user);
4484
4485 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4486 index 08ffcf5..a0ab912 100644
4487 --- a/arch/powerpc/mm/fault.c
4488 +++ b/arch/powerpc/mm/fault.c
4489 @@ -32,6 +32,10 @@
4490 #include <linux/perf_event.h>
4491 #include <linux/magic.h>
4492 #include <linux/ratelimit.h>
4493 +#include <linux/slab.h>
4494 +#include <linux/pagemap.h>
4495 +#include <linux/compiler.h>
4496 +#include <linux/unistd.h>
4497
4498 #include <asm/firmware.h>
4499 #include <asm/page.h>
4500 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4501 }
4502 #endif
4503
4504 +#ifdef CONFIG_PAX_PAGEEXEC
4505 +/*
4506 + * PaX: decide what to do with offenders (regs->nip = fault address)
4507 + *
4508 + * returns 1 when task should be killed
4509 + */
4510 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4511 +{
4512 + return 1;
4513 +}
4514 +
4515 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4516 +{
4517 + unsigned long i;
4518 +
4519 + printk(KERN_ERR "PAX: bytes at PC: ");
4520 + for (i = 0; i < 5; i++) {
4521 + unsigned int c;
4522 + if (get_user(c, (unsigned int __user *)pc+i))
4523 + printk(KERN_CONT "???????? ");
4524 + else
4525 + printk(KERN_CONT "%08x ", c);
4526 + }
4527 + printk("\n");
4528 +}
4529 +#endif
4530 +
4531 /*
4532 * Check whether the instruction at regs->nip is a store using
4533 * an update addressing form which will update r1.
4534 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4535 * indicate errors in DSISR but can validly be set in SRR1.
4536 */
4537 if (trap == 0x400)
4538 - error_code &= 0x48200000;
4539 + error_code &= 0x58200000;
4540 else
4541 is_write = error_code & DSISR_ISSTORE;
4542 #else
4543 @@ -366,7 +397,7 @@ good_area:
4544 * "undefined". Of those that can be set, this is the only
4545 * one which seems bad.
4546 */
4547 - if (error_code & 0x10000000)
4548 + if (error_code & DSISR_GUARDED)
4549 /* Guarded storage error. */
4550 goto bad_area;
4551 #endif /* CONFIG_8xx */
4552 @@ -381,7 +412,7 @@ good_area:
4553 * processors use the same I/D cache coherency mechanism
4554 * as embedded.
4555 */
4556 - if (error_code & DSISR_PROTFAULT)
4557 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4558 goto bad_area;
4559 #endif /* CONFIG_PPC_STD_MMU */
4560
4561 @@ -463,6 +494,23 @@ bad_area:
4562 bad_area_nosemaphore:
4563 /* User mode accesses cause a SIGSEGV */
4564 if (user_mode(regs)) {
4565 +
4566 +#ifdef CONFIG_PAX_PAGEEXEC
4567 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4568 +#ifdef CONFIG_PPC_STD_MMU
4569 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4570 +#else
4571 + if (is_exec && regs->nip == address) {
4572 +#endif
4573 + switch (pax_handle_fetch_fault(regs)) {
4574 + }
4575 +
4576 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4577 + do_group_exit(SIGKILL);
4578 + }
4579 + }
4580 +#endif
4581 +
4582 _exception(SIGSEGV, regs, code, address);
4583 return 0;
4584 }
4585 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4586 index 67a42ed..1c7210c 100644
4587 --- a/arch/powerpc/mm/mmap_64.c
4588 +++ b/arch/powerpc/mm/mmap_64.c
4589 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4590 */
4591 if (mmap_is_legacy()) {
4592 mm->mmap_base = TASK_UNMAPPED_BASE;
4593 +
4594 +#ifdef CONFIG_PAX_RANDMMAP
4595 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4596 + mm->mmap_base += mm->delta_mmap;
4597 +#endif
4598 +
4599 mm->get_unmapped_area = arch_get_unmapped_area;
4600 mm->unmap_area = arch_unmap_area;
4601 } else {
4602 mm->mmap_base = mmap_base();
4603 +
4604 +#ifdef CONFIG_PAX_RANDMMAP
4605 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4606 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4607 +#endif
4608 +
4609 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4610 mm->unmap_area = arch_unmap_area_topdown;
4611 }
4612 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4613 index 73709f7..6b90313 100644
4614 --- a/arch/powerpc/mm/slice.c
4615 +++ b/arch/powerpc/mm/slice.c
4616 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4617 if ((mm->task_size - len) < addr)
4618 return 0;
4619 vma = find_vma(mm, addr);
4620 - return (!vma || (addr + len) <= vma->vm_start);
4621 + return check_heap_stack_gap(vma, addr, len);
4622 }
4623
4624 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4625 @@ -256,7 +256,7 @@ full_search:
4626 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4627 continue;
4628 }
4629 - if (!vma || addr + len <= vma->vm_start) {
4630 + if (check_heap_stack_gap(vma, addr, len)) {
4631 /*
4632 * Remember the place where we stopped the search:
4633 */
4634 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4635 }
4636 }
4637
4638 - addr = mm->mmap_base;
4639 - while (addr > len) {
4640 + if (mm->mmap_base < len)
4641 + addr = -ENOMEM;
4642 + else
4643 + addr = mm->mmap_base - len;
4644 +
4645 + while (!IS_ERR_VALUE(addr)) {
4646 /* Go down by chunk size */
4647 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4648 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4649
4650 /* Check for hit with different page size */
4651 mask = slice_range_to_mask(addr, len);
4652 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4653 * return with success:
4654 */
4655 vma = find_vma(mm, addr);
4656 - if (!vma || (addr + len) <= vma->vm_start) {
4657 + if (check_heap_stack_gap(vma, addr, len)) {
4658 /* remember the address as a hint for next time */
4659 if (use_cache)
4660 mm->free_area_cache = addr;
4661 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4662 mm->cached_hole_size = vma->vm_start - addr;
4663
4664 /* try just below the current vma->vm_start */
4665 - addr = vma->vm_start;
4666 + addr = skip_heap_stack_gap(vma, len);
4667 }
4668
4669 /*
4670 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4671 if (fixed && addr > (mm->task_size - len))
4672 return -EINVAL;
4673
4674 +#ifdef CONFIG_PAX_RANDMMAP
4675 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4676 + addr = 0;
4677 +#endif
4678 +
4679 /* If hint, make sure it matches our alignment restrictions */
4680 if (!fixed && addr) {
4681 addr = _ALIGN_UP(addr, 1ul << pshift);
4682 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4683 index 748347b..81bc6c7 100644
4684 --- a/arch/s390/include/asm/atomic.h
4685 +++ b/arch/s390/include/asm/atomic.h
4686 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4687 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4688 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4689
4690 +#define atomic64_read_unchecked(v) atomic64_read(v)
4691 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4692 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4693 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4694 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4695 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4696 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4697 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4698 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4699 +
4700 #define smp_mb__before_atomic_dec() smp_mb()
4701 #define smp_mb__after_atomic_dec() smp_mb()
4702 #define smp_mb__before_atomic_inc() smp_mb()
4703 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4704 index 2a30d5a..5e5586f 100644
4705 --- a/arch/s390/include/asm/cache.h
4706 +++ b/arch/s390/include/asm/cache.h
4707 @@ -11,8 +11,10 @@
4708 #ifndef __ARCH_S390_CACHE_H
4709 #define __ARCH_S390_CACHE_H
4710
4711 -#define L1_CACHE_BYTES 256
4712 +#include <linux/const.h>
4713 +
4714 #define L1_CACHE_SHIFT 8
4715 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4716 #define NET_SKB_PAD 32
4717
4718 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4719 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4720 index 06151e6..598f9a5 100644
4721 --- a/arch/s390/include/asm/elf.h
4722 +++ b/arch/s390/include/asm/elf.h
4723 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4724 the loader. We need to make sure that it is out of the way of the program
4725 that it will "exec", and that there is sufficient room for the brk. */
4726
4727 -extern unsigned long randomize_et_dyn(unsigned long base);
4728 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4729 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4730 +
4731 +#ifdef CONFIG_PAX_ASLR
4732 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4733 +
4734 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4735 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4736 +#endif
4737
4738 /* This yields a mask that user programs can use to figure out what
4739 instruction set this CPU supports. */
4740 @@ -182,7 +188,8 @@ extern char elf_platform[];
4741 #define ELF_PLATFORM (elf_platform)
4742
4743 #ifndef CONFIG_64BIT
4744 -#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
4745 +#define SET_PERSONALITY(ex) \
4746 + set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
4747 #else /* CONFIG_64BIT */
4748 #define SET_PERSONALITY(ex) \
4749 do { \
4750 @@ -210,7 +217,4 @@ struct linux_binprm;
4751 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4752 int arch_setup_additional_pages(struct linux_binprm *, int);
4753
4754 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4755 -#define arch_randomize_brk arch_randomize_brk
4756 -
4757 #endif
4758 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4759 index c4a93d6..4d2a9b4 100644
4760 --- a/arch/s390/include/asm/exec.h
4761 +++ b/arch/s390/include/asm/exec.h
4762 @@ -7,6 +7,6 @@
4763 #ifndef __ASM_EXEC_H
4764 #define __ASM_EXEC_H
4765
4766 -extern unsigned long arch_align_stack(unsigned long sp);
4767 +#define arch_align_stack(x) ((x) & ~0xfUL)
4768
4769 #endif /* __ASM_EXEC_H */
4770 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4771 index 1f3a79b..44d7f9c 100644
4772 --- a/arch/s390/include/asm/uaccess.h
4773 +++ b/arch/s390/include/asm/uaccess.h
4774 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4775 copy_to_user(void __user *to, const void *from, unsigned long n)
4776 {
4777 might_fault();
4778 +
4779 + if ((long)n < 0)
4780 + return n;
4781 +
4782 if (access_ok(VERIFY_WRITE, to, n))
4783 n = __copy_to_user(to, from, n);
4784 return n;
4785 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4786 static inline unsigned long __must_check
4787 __copy_from_user(void *to, const void __user *from, unsigned long n)
4788 {
4789 + if ((long)n < 0)
4790 + return n;
4791 +
4792 if (__builtin_constant_p(n) && (n <= 256))
4793 return uaccess.copy_from_user_small(n, from, to);
4794 else
4795 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4796 static inline unsigned long __must_check
4797 copy_from_user(void *to, const void __user *from, unsigned long n)
4798 {
4799 - unsigned int sz = __compiletime_object_size(to);
4800 + size_t sz = __compiletime_object_size(to);
4801
4802 might_fault();
4803 - if (unlikely(sz != -1 && sz < n)) {
4804 +
4805 + if ((long)n < 0)
4806 + return n;
4807 +
4808 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4809 copy_from_user_overflow();
4810 return n;
4811 }
4812 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4813 index dfcb343..eda788a 100644
4814 --- a/arch/s390/kernel/module.c
4815 +++ b/arch/s390/kernel/module.c
4816 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4817
4818 /* Increase core size by size of got & plt and set start
4819 offsets for got and plt. */
4820 - me->core_size = ALIGN(me->core_size, 4);
4821 - me->arch.got_offset = me->core_size;
4822 - me->core_size += me->arch.got_size;
4823 - me->arch.plt_offset = me->core_size;
4824 - me->core_size += me->arch.plt_size;
4825 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4826 + me->arch.got_offset = me->core_size_rw;
4827 + me->core_size_rw += me->arch.got_size;
4828 + me->arch.plt_offset = me->core_size_rx;
4829 + me->core_size_rx += me->arch.plt_size;
4830 return 0;
4831 }
4832
4833 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 if (info->got_initialized == 0) {
4835 Elf_Addr *gotent;
4836
4837 - gotent = me->module_core + me->arch.got_offset +
4838 + gotent = me->module_core_rw + me->arch.got_offset +
4839 info->got_offset;
4840 *gotent = val;
4841 info->got_initialized = 1;
4842 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 else if (r_type == R_390_GOTENT ||
4844 r_type == R_390_GOTPLTENT)
4845 *(unsigned int *) loc =
4846 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4847 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4848 else if (r_type == R_390_GOT64 ||
4849 r_type == R_390_GOTPLT64)
4850 *(unsigned long *) loc = val;
4851 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4852 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4853 if (info->plt_initialized == 0) {
4854 unsigned int *ip;
4855 - ip = me->module_core + me->arch.plt_offset +
4856 + ip = me->module_core_rx + me->arch.plt_offset +
4857 info->plt_offset;
4858 #ifndef CONFIG_64BIT
4859 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4860 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4861 val - loc + 0xffffUL < 0x1ffffeUL) ||
4862 (r_type == R_390_PLT32DBL &&
4863 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4864 - val = (Elf_Addr) me->module_core +
4865 + val = (Elf_Addr) me->module_core_rx +
4866 me->arch.plt_offset +
4867 info->plt_offset;
4868 val += rela->r_addend - loc;
4869 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4870 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4871 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4872 val = val + rela->r_addend -
4873 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4874 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4875 if (r_type == R_390_GOTOFF16)
4876 *(unsigned short *) loc = val;
4877 else if (r_type == R_390_GOTOFF32)
4878 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4879 break;
4880 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4881 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4882 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4883 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4884 rela->r_addend - loc;
4885 if (r_type == R_390_GOTPC)
4886 *(unsigned int *) loc = val;
4887 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4888 index 60055ce..ee4b252 100644
4889 --- a/arch/s390/kernel/process.c
4890 +++ b/arch/s390/kernel/process.c
4891 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4892 }
4893 return 0;
4894 }
4895 -
4896 -unsigned long arch_align_stack(unsigned long sp)
4897 -{
4898 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4899 - sp -= get_random_int() & ~PAGE_MASK;
4900 - return sp & ~0xf;
4901 -}
4902 -
4903 -static inline unsigned long brk_rnd(void)
4904 -{
4905 - /* 8MB for 32bit, 1GB for 64bit */
4906 - if (is_32bit_task())
4907 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4908 - else
4909 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4910 -}
4911 -
4912 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4913 -{
4914 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4915 -
4916 - if (ret < mm->brk)
4917 - return mm->brk;
4918 - return ret;
4919 -}
4920 -
4921 -unsigned long randomize_et_dyn(unsigned long base)
4922 -{
4923 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4924 -
4925 - if (!(current->flags & PF_RANDOMIZE))
4926 - return base;
4927 - if (ret < base)
4928 - return base;
4929 - return ret;
4930 -}
4931 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4932 index a64fe53..5c66963 100644
4933 --- a/arch/s390/mm/mmap.c
4934 +++ b/arch/s390/mm/mmap.c
4935 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4936 */
4937 if (mmap_is_legacy()) {
4938 mm->mmap_base = TASK_UNMAPPED_BASE;
4939 +
4940 +#ifdef CONFIG_PAX_RANDMMAP
4941 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4942 + mm->mmap_base += mm->delta_mmap;
4943 +#endif
4944 +
4945 mm->get_unmapped_area = arch_get_unmapped_area;
4946 mm->unmap_area = arch_unmap_area;
4947 } else {
4948 mm->mmap_base = mmap_base();
4949 +
4950 +#ifdef CONFIG_PAX_RANDMMAP
4951 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4952 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4953 +#endif
4954 +
4955 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4956 mm->unmap_area = arch_unmap_area_topdown;
4957 }
4958 @@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4959 */
4960 if (mmap_is_legacy()) {
4961 mm->mmap_base = TASK_UNMAPPED_BASE;
4962 +
4963 +#ifdef CONFIG_PAX_RANDMMAP
4964 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4965 + mm->mmap_base += mm->delta_mmap;
4966 +#endif
4967 +
4968 mm->get_unmapped_area = s390_get_unmapped_area;
4969 mm->unmap_area = arch_unmap_area;
4970 } else {
4971 mm->mmap_base = mmap_base();
4972 +
4973 +#ifdef CONFIG_PAX_RANDMMAP
4974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4975 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4976 +#endif
4977 +
4978 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4979 mm->unmap_area = arch_unmap_area_topdown;
4980 }
4981 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4982 index ae3d59f..f65f075 100644
4983 --- a/arch/score/include/asm/cache.h
4984 +++ b/arch/score/include/asm/cache.h
4985 @@ -1,7 +1,9 @@
4986 #ifndef _ASM_SCORE_CACHE_H
4987 #define _ASM_SCORE_CACHE_H
4988
4989 +#include <linux/const.h>
4990 +
4991 #define L1_CACHE_SHIFT 4
4992 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4993 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4994
4995 #endif /* _ASM_SCORE_CACHE_H */
4996 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4997 index f9f3cd5..58ff438 100644
4998 --- a/arch/score/include/asm/exec.h
4999 +++ b/arch/score/include/asm/exec.h
5000 @@ -1,6 +1,6 @@
5001 #ifndef _ASM_SCORE_EXEC_H
5002 #define _ASM_SCORE_EXEC_H
5003
5004 -extern unsigned long arch_align_stack(unsigned long sp);
5005 +#define arch_align_stack(x) (x)
5006
5007 #endif /* _ASM_SCORE_EXEC_H */
5008 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5009 index 2707023..1c2a3b7 100644
5010 --- a/arch/score/kernel/process.c
5011 +++ b/arch/score/kernel/process.c
5012 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5013
5014 return task_pt_regs(task)->cp0_epc;
5015 }
5016 -
5017 -unsigned long arch_align_stack(unsigned long sp)
5018 -{
5019 - return sp;
5020 -}
5021 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5022 index ef9e555..331bd29 100644
5023 --- a/arch/sh/include/asm/cache.h
5024 +++ b/arch/sh/include/asm/cache.h
5025 @@ -9,10 +9,11 @@
5026 #define __ASM_SH_CACHE_H
5027 #ifdef __KERNEL__
5028
5029 +#include <linux/const.h>
5030 #include <linux/init.h>
5031 #include <cpu/cache.h>
5032
5033 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5034 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5035
5036 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5037
5038 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5039 index afeb710..d1d1289 100644
5040 --- a/arch/sh/mm/mmap.c
5041 +++ b/arch/sh/mm/mmap.c
5042 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5043 addr = PAGE_ALIGN(addr);
5044
5045 vma = find_vma(mm, addr);
5046 - if (TASK_SIZE - len >= addr &&
5047 - (!vma || addr + len <= vma->vm_start))
5048 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5049 return addr;
5050 }
5051
5052 @@ -106,7 +105,7 @@ full_search:
5053 }
5054 return -ENOMEM;
5055 }
5056 - if (likely(!vma || addr + len <= vma->vm_start)) {
5057 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5058 /*
5059 * Remember the place where we stopped the search:
5060 */
5061 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5062 addr = PAGE_ALIGN(addr);
5063
5064 vma = find_vma(mm, addr);
5065 - if (TASK_SIZE - len >= addr &&
5066 - (!vma || addr + len <= vma->vm_start))
5067 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5068 return addr;
5069 }
5070
5071 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5072 /* make sure it can fit in the remaining address space */
5073 if (likely(addr > len)) {
5074 vma = find_vma(mm, addr-len);
5075 - if (!vma || addr <= vma->vm_start) {
5076 + if (check_heap_stack_gap(vma, addr - len, len)) {
5077 /* remember the address as a hint for next time */
5078 return (mm->free_area_cache = addr-len);
5079 }
5080 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5081 if (unlikely(mm->mmap_base < len))
5082 goto bottomup;
5083
5084 - addr = mm->mmap_base-len;
5085 - if (do_colour_align)
5086 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5087 + addr = mm->mmap_base - len;
5088
5089 do {
5090 + if (do_colour_align)
5091 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5092 /*
5093 * Lookup failure means no vma is above this address,
5094 * else if new region fits below vma->vm_start,
5095 * return with success:
5096 */
5097 vma = find_vma(mm, addr);
5098 - if (likely(!vma || addr+len <= vma->vm_start)) {
5099 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5100 /* remember the address as a hint for next time */
5101 return (mm->free_area_cache = addr);
5102 }
5103 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5104 mm->cached_hole_size = vma->vm_start - addr;
5105
5106 /* try just below the current vma->vm_start */
5107 - addr = vma->vm_start-len;
5108 - if (do_colour_align)
5109 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5110 - } while (likely(len < vma->vm_start));
5111 + addr = skip_heap_stack_gap(vma, len);
5112 + } while (!IS_ERR_VALUE(addr));
5113
5114 bottomup:
5115 /*
5116 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5117 index ce35a1c..2e7b8f9 100644
5118 --- a/arch/sparc/include/asm/atomic_64.h
5119 +++ b/arch/sparc/include/asm/atomic_64.h
5120 @@ -14,18 +14,40 @@
5121 #define ATOMIC64_INIT(i) { (i) }
5122
5123 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5124 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5125 +{
5126 + return v->counter;
5127 +}
5128 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5129 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5130 +{
5131 + return v->counter;
5132 +}
5133
5134 #define atomic_set(v, i) (((v)->counter) = i)
5135 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5136 +{
5137 + v->counter = i;
5138 +}
5139 #define atomic64_set(v, i) (((v)->counter) = i)
5140 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5141 +{
5142 + v->counter = i;
5143 +}
5144
5145 extern void atomic_add(int, atomic_t *);
5146 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5147 extern void atomic64_add(long, atomic64_t *);
5148 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5149 extern void atomic_sub(int, atomic_t *);
5150 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5151 extern void atomic64_sub(long, atomic64_t *);
5152 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5153
5154 extern int atomic_add_ret(int, atomic_t *);
5155 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5156 extern long atomic64_add_ret(long, atomic64_t *);
5157 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5158 extern int atomic_sub_ret(int, atomic_t *);
5159 extern long atomic64_sub_ret(long, atomic64_t *);
5160
5161 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5162 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5163
5164 #define atomic_inc_return(v) atomic_add_ret(1, v)
5165 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + return atomic_add_ret_unchecked(1, v);
5168 +}
5169 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5170 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5171 +{
5172 + return atomic64_add_ret_unchecked(1, v);
5173 +}
5174
5175 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5176 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5177
5178 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5179 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5180 +{
5181 + return atomic_add_ret_unchecked(i, v);
5182 +}
5183 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5184 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5185 +{
5186 + return atomic64_add_ret_unchecked(i, v);
5187 +}
5188
5189 /*
5190 * atomic_inc_and_test - increment and test
5191 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5192 * other cases.
5193 */
5194 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5195 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5196 +{
5197 + return atomic_inc_return_unchecked(v) == 0;
5198 +}
5199 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5200
5201 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5202 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5203 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5204
5205 #define atomic_inc(v) atomic_add(1, v)
5206 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5207 +{
5208 + atomic_add_unchecked(1, v);
5209 +}
5210 #define atomic64_inc(v) atomic64_add(1, v)
5211 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5212 +{
5213 + atomic64_add_unchecked(1, v);
5214 +}
5215
5216 #define atomic_dec(v) atomic_sub(1, v)
5217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5218 +{
5219 + atomic_sub_unchecked(1, v);
5220 +}
5221 #define atomic64_dec(v) atomic64_sub(1, v)
5222 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5223 +{
5224 + atomic64_sub_unchecked(1, v);
5225 +}
5226
5227 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5228 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5229
5230 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5231 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5232 +{
5233 + return cmpxchg(&v->counter, old, new);
5234 +}
5235 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5236 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5237 +{
5238 + return xchg(&v->counter, new);
5239 +}
5240
5241 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5242 {
5243 - int c, old;
5244 + int c, old, new;
5245 c = atomic_read(v);
5246 for (;;) {
5247 - if (unlikely(c == (u)))
5248 + if (unlikely(c == u))
5249 break;
5250 - old = atomic_cmpxchg((v), c, c + (a));
5251 +
5252 + asm volatile("addcc %2, %0, %0\n"
5253 +
5254 +#ifdef CONFIG_PAX_REFCOUNT
5255 + "tvs %%icc, 6\n"
5256 +#endif
5257 +
5258 + : "=r" (new)
5259 + : "0" (c), "ir" (a)
5260 + : "cc");
5261 +
5262 + old = atomic_cmpxchg(v, c, new);
5263 if (likely(old == c))
5264 break;
5265 c = old;
5266 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5267 #define atomic64_cmpxchg(v, o, n) \
5268 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5269 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5270 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5271 +{
5272 + return xchg(&v->counter, new);
5273 +}
5274
5275 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5276 {
5277 - long c, old;
5278 + long c, old, new;
5279 c = atomic64_read(v);
5280 for (;;) {
5281 - if (unlikely(c == (u)))
5282 + if (unlikely(c == u))
5283 break;
5284 - old = atomic64_cmpxchg((v), c, c + (a));
5285 +
5286 + asm volatile("addcc %2, %0, %0\n"
5287 +
5288 +#ifdef CONFIG_PAX_REFCOUNT
5289 + "tvs %%xcc, 6\n"
5290 +#endif
5291 +
5292 + : "=r" (new)
5293 + : "0" (c), "ir" (a)
5294 + : "cc");
5295 +
5296 + old = atomic64_cmpxchg(v, c, new);
5297 if (likely(old == c))
5298 break;
5299 c = old;
5300 }
5301 - return c != (u);
5302 + return c != u;
5303 }
5304
5305 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5306 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5307 index 5bb6991..5c2132e 100644
5308 --- a/arch/sparc/include/asm/cache.h
5309 +++ b/arch/sparc/include/asm/cache.h
5310 @@ -7,10 +7,12 @@
5311 #ifndef _SPARC_CACHE_H
5312 #define _SPARC_CACHE_H
5313
5314 +#include <linux/const.h>
5315 +
5316 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5317
5318 #define L1_CACHE_SHIFT 5
5319 -#define L1_CACHE_BYTES 32
5320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5321
5322 #ifdef CONFIG_SPARC32
5323 #define SMP_CACHE_BYTES_SHIFT 5
5324 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5325 index 2d4d755..81b6662 100644
5326 --- a/arch/sparc/include/asm/elf_32.h
5327 +++ b/arch/sparc/include/asm/elf_32.h
5328 @@ -114,6 +114,13 @@ typedef struct {
5329
5330 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5331
5332 +#ifdef CONFIG_PAX_ASLR
5333 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5334 +
5335 +#define PAX_DELTA_MMAP_LEN 16
5336 +#define PAX_DELTA_STACK_LEN 16
5337 +#endif
5338 +
5339 /* This yields a mask that user programs can use to figure out what
5340 instruction set this cpu supports. This can NOT be done in userspace
5341 on Sparc. */
5342 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5343 index 7df8b7f..4946269 100644
5344 --- a/arch/sparc/include/asm/elf_64.h
5345 +++ b/arch/sparc/include/asm/elf_64.h
5346 @@ -180,6 +180,13 @@ typedef struct {
5347 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5348 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5349
5350 +#ifdef CONFIG_PAX_ASLR
5351 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5352 +
5353 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5354 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5355 +#endif
5356 +
5357 extern unsigned long sparc64_elf_hwcap;
5358 #define ELF_HWCAP sparc64_elf_hwcap
5359
5360 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5361 index e5b169b46..e90b4fa 100644
5362 --- a/arch/sparc/include/asm/pgalloc_32.h
5363 +++ b/arch/sparc/include/asm/pgalloc_32.h
5364 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5365 }
5366
5367 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5368 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5369
5370 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5371 unsigned long address)
5372 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5373 index 40b2d7a..22a665b 100644
5374 --- a/arch/sparc/include/asm/pgalloc_64.h
5375 +++ b/arch/sparc/include/asm/pgalloc_64.h
5376 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5377 }
5378
5379 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5380 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5381
5382 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5383 {
5384 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5385 index cbbbed5..0983069 100644
5386 --- a/arch/sparc/include/asm/pgtable_32.h
5387 +++ b/arch/sparc/include/asm/pgtable_32.h
5388 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5389 #define PAGE_SHARED SRMMU_PAGE_SHARED
5390 #define PAGE_COPY SRMMU_PAGE_COPY
5391 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5392 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5393 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5394 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5395 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5396
5397 /* Top-level page directory */
5398 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5399
5400 /* xwr */
5401 #define __P000 PAGE_NONE
5402 -#define __P001 PAGE_READONLY
5403 -#define __P010 PAGE_COPY
5404 -#define __P011 PAGE_COPY
5405 +#define __P001 PAGE_READONLY_NOEXEC
5406 +#define __P010 PAGE_COPY_NOEXEC
5407 +#define __P011 PAGE_COPY_NOEXEC
5408 #define __P100 PAGE_READONLY
5409 #define __P101 PAGE_READONLY
5410 #define __P110 PAGE_COPY
5411 #define __P111 PAGE_COPY
5412
5413 #define __S000 PAGE_NONE
5414 -#define __S001 PAGE_READONLY
5415 -#define __S010 PAGE_SHARED
5416 -#define __S011 PAGE_SHARED
5417 +#define __S001 PAGE_READONLY_NOEXEC
5418 +#define __S010 PAGE_SHARE_NOEXEC
5419 +#define __S011 PAGE_SHARE_NOEXEC
5420 #define __S100 PAGE_READONLY
5421 #define __S101 PAGE_READONLY
5422 #define __S110 PAGE_SHARED
5423 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5424 index 79da178..c2eede8 100644
5425 --- a/arch/sparc/include/asm/pgtsrmmu.h
5426 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5427 @@ -115,6 +115,11 @@
5428 SRMMU_EXEC | SRMMU_REF)
5429 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5430 SRMMU_EXEC | SRMMU_REF)
5431 +
5432 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5433 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5434 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5435 +
5436 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5437 SRMMU_DIRTY | SRMMU_REF)
5438
5439 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5440 index 9689176..63c18ea 100644
5441 --- a/arch/sparc/include/asm/spinlock_64.h
5442 +++ b/arch/sparc/include/asm/spinlock_64.h
5443 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5444
5445 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5446
5447 -static void inline arch_read_lock(arch_rwlock_t *lock)
5448 +static inline void arch_read_lock(arch_rwlock_t *lock)
5449 {
5450 unsigned long tmp1, tmp2;
5451
5452 __asm__ __volatile__ (
5453 "1: ldsw [%2], %0\n"
5454 " brlz,pn %0, 2f\n"
5455 -"4: add %0, 1, %1\n"
5456 +"4: addcc %0, 1, %1\n"
5457 +
5458 +#ifdef CONFIG_PAX_REFCOUNT
5459 +" tvs %%icc, 6\n"
5460 +#endif
5461 +
5462 " cas [%2], %0, %1\n"
5463 " cmp %0, %1\n"
5464 " bne,pn %%icc, 1b\n"
5465 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5466 " .previous"
5467 : "=&r" (tmp1), "=&r" (tmp2)
5468 : "r" (lock)
5469 - : "memory");
5470 + : "memory", "cc");
5471 }
5472
5473 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5474 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5475 {
5476 int tmp1, tmp2;
5477
5478 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5479 "1: ldsw [%2], %0\n"
5480 " brlz,a,pn %0, 2f\n"
5481 " mov 0, %0\n"
5482 -" add %0, 1, %1\n"
5483 +" addcc %0, 1, %1\n"
5484 +
5485 +#ifdef CONFIG_PAX_REFCOUNT
5486 +" tvs %%icc, 6\n"
5487 +#endif
5488 +
5489 " cas [%2], %0, %1\n"
5490 " cmp %0, %1\n"
5491 " bne,pn %%icc, 1b\n"
5492 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5493 return tmp1;
5494 }
5495
5496 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5497 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5498 {
5499 unsigned long tmp1, tmp2;
5500
5501 __asm__ __volatile__(
5502 "1: lduw [%2], %0\n"
5503 -" sub %0, 1, %1\n"
5504 +" subcc %0, 1, %1\n"
5505 +
5506 +#ifdef CONFIG_PAX_REFCOUNT
5507 +" tvs %%icc, 6\n"
5508 +#endif
5509 +
5510 " cas [%2], %0, %1\n"
5511 " cmp %0, %1\n"
5512 " bne,pn %%xcc, 1b\n"
5513 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5514 : "memory");
5515 }
5516
5517 -static void inline arch_write_lock(arch_rwlock_t *lock)
5518 +static inline void arch_write_lock(arch_rwlock_t *lock)
5519 {
5520 unsigned long mask, tmp1, tmp2;
5521
5522 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5523 : "memory");
5524 }
5525
5526 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5527 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5528 {
5529 __asm__ __volatile__(
5530 " stw %%g0, [%0]"
5531 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5532 : "memory");
5533 }
5534
5535 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5536 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5537 {
5538 unsigned long mask, tmp1, tmp2, result;
5539
5540 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5541 index e6cd224..3a71793 100644
5542 --- a/arch/sparc/include/asm/thread_info_32.h
5543 +++ b/arch/sparc/include/asm/thread_info_32.h
5544 @@ -49,6 +49,8 @@ struct thread_info {
5545 unsigned long w_saved;
5546
5547 struct restart_block restart_block;
5548 +
5549 + unsigned long lowest_stack;
5550 };
5551
5552 /*
5553 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5554 index cfa8c38..13f30d3 100644
5555 --- a/arch/sparc/include/asm/thread_info_64.h
5556 +++ b/arch/sparc/include/asm/thread_info_64.h
5557 @@ -63,6 +63,8 @@ struct thread_info {
5558 struct pt_regs *kern_una_regs;
5559 unsigned int kern_una_insn;
5560
5561 + unsigned long lowest_stack;
5562 +
5563 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5564 };
5565
5566 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5567 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5568 /* flag bit 6 is available */
5569 #define TIF_32BIT 7 /* 32-bit binary */
5570 -/* flag bit 8 is available */
5571 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5572 #define TIF_SECCOMP 9 /* secure computing */
5573 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5574 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5575 +
5576 /* NOTE: Thread flags >= 12 should be ones we have no interest
5577 * in using in assembly, else we can't use the mask as
5578 * an immediate value in instructions such as andcc.
5579 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5580 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5581 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5582 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5583 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5584
5585 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5586 _TIF_DO_NOTIFY_RESUME_MASK | \
5587 _TIF_NEED_RESCHED)
5588 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5589
5590 +#define _TIF_WORK_SYSCALL \
5591 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5592 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5593 +
5594 +
5595 /*
5596 * Thread-synchronous status.
5597 *
5598 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5599 index 0167d26..9acd8ed 100644
5600 --- a/arch/sparc/include/asm/uaccess.h
5601 +++ b/arch/sparc/include/asm/uaccess.h
5602 @@ -1,5 +1,13 @@
5603 #ifndef ___ASM_SPARC_UACCESS_H
5604 #define ___ASM_SPARC_UACCESS_H
5605 +
5606 +#ifdef __KERNEL__
5607 +#ifndef __ASSEMBLY__
5608 +#include <linux/types.h>
5609 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5610 +#endif
5611 +#endif
5612 +
5613 #if defined(__sparc__) && defined(__arch64__)
5614 #include <asm/uaccess_64.h>
5615 #else
5616 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5617 index 53a28dd..50c38c3 100644
5618 --- a/arch/sparc/include/asm/uaccess_32.h
5619 +++ b/arch/sparc/include/asm/uaccess_32.h
5620 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5621
5622 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5623 {
5624 - if (n && __access_ok((unsigned long) to, n))
5625 + if ((long)n < 0)
5626 + return n;
5627 +
5628 + if (n && __access_ok((unsigned long) to, n)) {
5629 + if (!__builtin_constant_p(n))
5630 + check_object_size(from, n, true);
5631 return __copy_user(to, (__force void __user *) from, n);
5632 - else
5633 + } else
5634 return n;
5635 }
5636
5637 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5638 {
5639 + if ((long)n < 0)
5640 + return n;
5641 +
5642 + if (!__builtin_constant_p(n))
5643 + check_object_size(from, n, true);
5644 +
5645 return __copy_user(to, (__force void __user *) from, n);
5646 }
5647
5648 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5649 {
5650 - if (n && __access_ok((unsigned long) from, n))
5651 + if ((long)n < 0)
5652 + return n;
5653 +
5654 + if (n && __access_ok((unsigned long) from, n)) {
5655 + if (!__builtin_constant_p(n))
5656 + check_object_size(to, n, false);
5657 return __copy_user((__force void __user *) to, from, n);
5658 - else
5659 + } else
5660 return n;
5661 }
5662
5663 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5664 {
5665 + if ((long)n < 0)
5666 + return n;
5667 +
5668 return __copy_user((__force void __user *) to, from, n);
5669 }
5670
5671 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5672 index 7c831d8..d440ca7 100644
5673 --- a/arch/sparc/include/asm/uaccess_64.h
5674 +++ b/arch/sparc/include/asm/uaccess_64.h
5675 @@ -10,6 +10,7 @@
5676 #include <linux/compiler.h>
5677 #include <linux/string.h>
5678 #include <linux/thread_info.h>
5679 +#include <linux/kernel.h>
5680 #include <asm/asi.h>
5681 #include <asm/spitfire.h>
5682 #include <asm-generic/uaccess-unaligned.h>
5683 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5684 static inline unsigned long __must_check
5685 copy_from_user(void *to, const void __user *from, unsigned long size)
5686 {
5687 - unsigned long ret = ___copy_from_user(to, from, size);
5688 + unsigned long ret;
5689
5690 + if ((long)size < 0 || size > INT_MAX)
5691 + return size;
5692 +
5693 + if (!__builtin_constant_p(size))
5694 + check_object_size(to, size, false);
5695 +
5696 + ret = ___copy_from_user(to, from, size);
5697 if (unlikely(ret))
5698 ret = copy_from_user_fixup(to, from, size);
5699
5700 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5701 static inline unsigned long __must_check
5702 copy_to_user(void __user *to, const void *from, unsigned long size)
5703 {
5704 - unsigned long ret = ___copy_to_user(to, from, size);
5705 + unsigned long ret;
5706
5707 + if ((long)size < 0 || size > INT_MAX)
5708 + return size;
5709 +
5710 + if (!__builtin_constant_p(size))
5711 + check_object_size(from, size, true);
5712 +
5713 + ret = ___copy_to_user(to, from, size);
5714 if (unlikely(ret))
5715 ret = copy_to_user_fixup(to, from, size);
5716 return ret;
5717 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5718 index 6cf591b..b49e65a 100644
5719 --- a/arch/sparc/kernel/Makefile
5720 +++ b/arch/sparc/kernel/Makefile
5721 @@ -3,7 +3,7 @@
5722 #
5723
5724 asflags-y := -ansi
5725 -ccflags-y := -Werror
5726 +#ccflags-y := -Werror
5727
5728 extra-y := head_$(BITS).o
5729
5730 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5731 index cb36e82..1c1462f 100644
5732 --- a/arch/sparc/kernel/process_32.c
5733 +++ b/arch/sparc/kernel/process_32.c
5734 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5735
5736 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5737 r->psr, r->pc, r->npc, r->y, print_tainted());
5738 - printk("PC: <%pS>\n", (void *) r->pc);
5739 + printk("PC: <%pA>\n", (void *) r->pc);
5740 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5741 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5742 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5743 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5744 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5745 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5746 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5747 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5748
5749 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5750 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5751 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5752 rw = (struct reg_window32 *) fp;
5753 pc = rw->ins[7];
5754 printk("[%08lx : ", pc);
5755 - printk("%pS ] ", (void *) pc);
5756 + printk("%pA ] ", (void *) pc);
5757 fp = rw->ins[6];
5758 } while (++count < 16);
5759 printk("\n");
5760 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5761 index aff0c72..9067b39 100644
5762 --- a/arch/sparc/kernel/process_64.c
5763 +++ b/arch/sparc/kernel/process_64.c
5764 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5765 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5766 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5767 if (regs->tstate & TSTATE_PRIV)
5768 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5769 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5770 }
5771
5772 void show_regs(struct pt_regs *regs)
5773 {
5774 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5775 regs->tpc, regs->tnpc, regs->y, print_tainted());
5776 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5777 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5778 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5779 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5780 regs->u_regs[3]);
5781 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5782 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5783 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5784 regs->u_regs[15]);
5785 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5786 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5787 show_regwindow(regs);
5788 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5789 }
5790 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5791 ((tp && tp->task) ? tp->task->pid : -1));
5792
5793 if (gp->tstate & TSTATE_PRIV) {
5794 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5795 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5796 (void *) gp->tpc,
5797 (void *) gp->o7,
5798 (void *) gp->i7,
5799 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5800 index 484daba..0674139 100644
5801 --- a/arch/sparc/kernel/ptrace_64.c
5802 +++ b/arch/sparc/kernel/ptrace_64.c
5803 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5804 return ret;
5805 }
5806
5807 +#ifdef CONFIG_GRKERNSEC_SETXID
5808 +extern void gr_delayed_cred_worker(void);
5809 +#endif
5810 +
5811 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812 {
5813 int ret = 0;
5814 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5815 /* do the secure computing check first */
5816 secure_computing_strict(regs->u_regs[UREG_G1]);
5817
5818 +#ifdef CONFIG_GRKERNSEC_SETXID
5819 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5820 + gr_delayed_cred_worker();
5821 +#endif
5822 +
5823 if (test_thread_flag(TIF_SYSCALL_TRACE))
5824 ret = tracehook_report_syscall_entry(regs);
5825
5826 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5827
5828 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5829 {
5830 +#ifdef CONFIG_GRKERNSEC_SETXID
5831 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5832 + gr_delayed_cred_worker();
5833 +#endif
5834 +
5835 audit_syscall_exit(regs);
5836
5837 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5838 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5839 index 0c9b31b..7cb7aee 100644
5840 --- a/arch/sparc/kernel/sys_sparc_32.c
5841 +++ b/arch/sparc/kernel/sys_sparc_32.c
5842 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5843 if (len > TASK_SIZE - PAGE_SIZE)
5844 return -ENOMEM;
5845 if (!addr)
5846 - addr = TASK_UNMAPPED_BASE;
5847 + addr = current->mm->mmap_base;
5848
5849 if (flags & MAP_SHARED)
5850 addr = COLOUR_ALIGN(addr);
5851 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5852 /* At this point: (!vmm || addr < vmm->vm_end). */
5853 if (TASK_SIZE - PAGE_SIZE - len < addr)
5854 return -ENOMEM;
5855 - if (!vmm || addr + len <= vmm->vm_start)
5856 + if (check_heap_stack_gap(vmm, addr, len))
5857 return addr;
5858 addr = vmm->vm_end;
5859 if (flags & MAP_SHARED)
5860 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5861 index 275f74f..81bf5b8 100644
5862 --- a/arch/sparc/kernel/sys_sparc_64.c
5863 +++ b/arch/sparc/kernel/sys_sparc_64.c
5864 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5865 /* We do not accept a shared mapping if it would violate
5866 * cache aliasing constraints.
5867 */
5868 - if ((flags & MAP_SHARED) &&
5869 + if ((filp || (flags & MAP_SHARED)) &&
5870 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5871 return -EINVAL;
5872 return addr;
5873 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5874 if (filp || (flags & MAP_SHARED))
5875 do_color_align = 1;
5876
5877 +#ifdef CONFIG_PAX_RANDMMAP
5878 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5879 +#endif
5880 +
5881 if (addr) {
5882 if (do_color_align)
5883 addr = COLOUR_ALIGN(addr, pgoff);
5884 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5885 addr = PAGE_ALIGN(addr);
5886
5887 vma = find_vma(mm, addr);
5888 - if (task_size - len >= addr &&
5889 - (!vma || addr + len <= vma->vm_start))
5890 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5891 return addr;
5892 }
5893
5894 if (len > mm->cached_hole_size) {
5895 - start_addr = addr = mm->free_area_cache;
5896 + start_addr = addr = mm->free_area_cache;
5897 } else {
5898 - start_addr = addr = TASK_UNMAPPED_BASE;
5899 + start_addr = addr = mm->mmap_base;
5900 mm->cached_hole_size = 0;
5901 }
5902
5903 @@ -174,14 +177,14 @@ full_search:
5904 vma = find_vma(mm, VA_EXCLUDE_END);
5905 }
5906 if (unlikely(task_size < addr)) {
5907 - if (start_addr != TASK_UNMAPPED_BASE) {
5908 - start_addr = addr = TASK_UNMAPPED_BASE;
5909 + if (start_addr != mm->mmap_base) {
5910 + start_addr = addr = mm->mmap_base;
5911 mm->cached_hole_size = 0;
5912 goto full_search;
5913 }
5914 return -ENOMEM;
5915 }
5916 - if (likely(!vma || addr + len <= vma->vm_start)) {
5917 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5918 /*
5919 * Remember the place where we stopped the search:
5920 */
5921 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5922 /* We do not accept a shared mapping if it would violate
5923 * cache aliasing constraints.
5924 */
5925 - if ((flags & MAP_SHARED) &&
5926 + if ((filp || (flags & MAP_SHARED)) &&
5927 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5928 return -EINVAL;
5929 return addr;
5930 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5931 addr = PAGE_ALIGN(addr);
5932
5933 vma = find_vma(mm, addr);
5934 - if (task_size - len >= addr &&
5935 - (!vma || addr + len <= vma->vm_start))
5936 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5937 return addr;
5938 }
5939
5940 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5941 /* make sure it can fit in the remaining address space */
5942 if (likely(addr > len)) {
5943 vma = find_vma(mm, addr-len);
5944 - if (!vma || addr <= vma->vm_start) {
5945 + if (check_heap_stack_gap(vma, addr - len, len)) {
5946 /* remember the address as a hint for next time */
5947 return (mm->free_area_cache = addr-len);
5948 }
5949 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5950 if (unlikely(mm->mmap_base < len))
5951 goto bottomup;
5952
5953 - addr = mm->mmap_base-len;
5954 - if (do_color_align)
5955 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5956 + addr = mm->mmap_base - len;
5957
5958 do {
5959 + if (do_color_align)
5960 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5961 /*
5962 * Lookup failure means no vma is above this address,
5963 * else if new region fits below vma->vm_start,
5964 * return with success:
5965 */
5966 vma = find_vma(mm, addr);
5967 - if (likely(!vma || addr+len <= vma->vm_start)) {
5968 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5969 /* remember the address as a hint for next time */
5970 return (mm->free_area_cache = addr);
5971 }
5972 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5973 mm->cached_hole_size = vma->vm_start - addr;
5974
5975 /* try just below the current vma->vm_start */
5976 - addr = vma->vm_start-len;
5977 - if (do_color_align)
5978 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5979 - } while (likely(len < vma->vm_start));
5980 + addr = skip_heap_stack_gap(vma, len);
5981 + } while (!IS_ERR_VALUE(addr));
5982
5983 bottomup:
5984 /*
5985 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5986 gap == RLIM_INFINITY ||
5987 sysctl_legacy_va_layout) {
5988 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5989 +
5990 +#ifdef CONFIG_PAX_RANDMMAP
5991 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5992 + mm->mmap_base += mm->delta_mmap;
5993 +#endif
5994 +
5995 mm->get_unmapped_area = arch_get_unmapped_area;
5996 mm->unmap_area = arch_unmap_area;
5997 } else {
5998 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5999 gap = (task_size / 6 * 5);
6000
6001 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6002 +
6003 +#ifdef CONFIG_PAX_RANDMMAP
6004 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6005 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6006 +#endif
6007 +
6008 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6009 mm->unmap_area = arch_unmap_area_topdown;
6010 }
6011 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6012 index 1d7e274..b39c527 100644
6013 --- a/arch/sparc/kernel/syscalls.S
6014 +++ b/arch/sparc/kernel/syscalls.S
6015 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6016 #endif
6017 .align 32
6018 1: ldx [%g6 + TI_FLAGS], %l5
6019 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6020 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6021 be,pt %icc, rtrap
6022 nop
6023 call syscall_trace_leave
6024 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6025
6026 srl %i5, 0, %o5 ! IEU1
6027 srl %i2, 0, %o2 ! IEU0 Group
6028 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6029 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6030 bne,pn %icc, linux_syscall_trace32 ! CTI
6031 mov %i0, %l5 ! IEU1
6032 call %l7 ! CTI Group brk forced
6033 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6034
6035 mov %i3, %o3 ! IEU1
6036 mov %i4, %o4 ! IEU0 Group
6037 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6038 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6039 bne,pn %icc, linux_syscall_trace ! CTI Group
6040 mov %i0, %l5 ! IEU0
6041 2: call %l7 ! CTI Group brk forced
6042 @@ -226,7 +226,7 @@ ret_sys_call:
6043
6044 cmp %o0, -ERESTART_RESTARTBLOCK
6045 bgeu,pn %xcc, 1f
6046 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6047 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6048 80:
6049 /* System call success, clear Carry condition code. */
6050 andn %g3, %g2, %g3
6051 @@ -241,7 +241,7 @@ ret_sys_call:
6052 /* System call failure, set Carry condition code.
6053 * Also, get abs(errno) to return to the process.
6054 */
6055 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6056 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6057 sub %g0, %o0, %o0
6058 or %g3, %g2, %g3
6059 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6060 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6061 index a5785ea..405c5f7 100644
6062 --- a/arch/sparc/kernel/traps_32.c
6063 +++ b/arch/sparc/kernel/traps_32.c
6064 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6065 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6066 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6067
6068 +extern void gr_handle_kernel_exploit(void);
6069 +
6070 void die_if_kernel(char *str, struct pt_regs *regs)
6071 {
6072 static int die_counter;
6073 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6074 count++ < 30 &&
6075 (((unsigned long) rw) >= PAGE_OFFSET) &&
6076 !(((unsigned long) rw) & 0x7)) {
6077 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6078 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6079 (void *) rw->ins[7]);
6080 rw = (struct reg_window32 *)rw->ins[6];
6081 }
6082 }
6083 printk("Instruction DUMP:");
6084 instruction_dump ((unsigned long *) regs->pc);
6085 - if(regs->psr & PSR_PS)
6086 + if(regs->psr & PSR_PS) {
6087 + gr_handle_kernel_exploit();
6088 do_exit(SIGKILL);
6089 + }
6090 do_exit(SIGSEGV);
6091 }
6092
6093 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6094 index 3b05e66..6ea2917 100644
6095 --- a/arch/sparc/kernel/traps_64.c
6096 +++ b/arch/sparc/kernel/traps_64.c
6097 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6098 i + 1,
6099 p->trapstack[i].tstate, p->trapstack[i].tpc,
6100 p->trapstack[i].tnpc, p->trapstack[i].tt);
6101 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6102 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6103 }
6104 }
6105
6106 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6107
6108 lvl -= 0x100;
6109 if (regs->tstate & TSTATE_PRIV) {
6110 +
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + if (lvl == 6)
6113 + pax_report_refcount_overflow(regs);
6114 +#endif
6115 +
6116 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6117 die_if_kernel(buffer, regs);
6118 }
6119 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6120 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6121 {
6122 char buffer[32];
6123 -
6124 +
6125 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6126 0, lvl, SIGTRAP) == NOTIFY_STOP)
6127 return;
6128
6129 +#ifdef CONFIG_PAX_REFCOUNT
6130 + if (lvl == 6)
6131 + pax_report_refcount_overflow(regs);
6132 +#endif
6133 +
6134 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6135
6136 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6137 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6138 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6139 printk("%s" "ERROR(%d): ",
6140 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6141 - printk("TPC<%pS>\n", (void *) regs->tpc);
6142 + printk("TPC<%pA>\n", (void *) regs->tpc);
6143 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6144 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6145 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6146 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6147 smp_processor_id(),
6148 (type & 0x1) ? 'I' : 'D',
6149 regs->tpc);
6150 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6151 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6152 panic("Irrecoverable Cheetah+ parity error.");
6153 }
6154
6155 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6156 smp_processor_id(),
6157 (type & 0x1) ? 'I' : 'D',
6158 regs->tpc);
6159 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6160 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6161 }
6162
6163 struct sun4v_error_entry {
6164 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6165
6166 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6167 regs->tpc, tl);
6168 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6169 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6170 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6171 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6172 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6173 (void *) regs->u_regs[UREG_I7]);
6174 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6175 "pte[%lx] error[%lx]\n",
6176 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6177
6178 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6179 regs->tpc, tl);
6180 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6181 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6182 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6183 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6184 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6185 (void *) regs->u_regs[UREG_I7]);
6186 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6187 "pte[%lx] error[%lx]\n",
6188 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6189 fp = (unsigned long)sf->fp + STACK_BIAS;
6190 }
6191
6192 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6193 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6195 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6196 int index = tsk->curr_ret_stack;
6197 if (tsk->ret_stack && index >= graph) {
6198 pc = tsk->ret_stack[index - graph].ret;
6199 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6200 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6201 graph++;
6202 }
6203 }
6204 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6205 return (struct reg_window *) (fp + STACK_BIAS);
6206 }
6207
6208 +extern void gr_handle_kernel_exploit(void);
6209 +
6210 void die_if_kernel(char *str, struct pt_regs *regs)
6211 {
6212 static int die_counter;
6213 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6214 while (rw &&
6215 count++ < 30 &&
6216 kstack_valid(tp, (unsigned long) rw)) {
6217 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6218 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6219 (void *) rw->ins[7]);
6220
6221 rw = kernel_stack_up(rw);
6222 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6223 }
6224 user_instruction_dump ((unsigned int __user *) regs->tpc);
6225 }
6226 - if (regs->tstate & TSTATE_PRIV)
6227 + if (regs->tstate & TSTATE_PRIV) {
6228 + gr_handle_kernel_exploit();
6229 do_exit(SIGKILL);
6230 + }
6231 do_exit(SIGSEGV);
6232 }
6233 EXPORT_SYMBOL(die_if_kernel);
6234 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6235 index f81d038..e7a4680 100644
6236 --- a/arch/sparc/kernel/unaligned_64.c
6237 +++ b/arch/sparc/kernel/unaligned_64.c
6238 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6239 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6240
6241 if (__ratelimit(&ratelimit)) {
6242 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6243 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6244 regs->tpc, (void *) regs->tpc);
6245 }
6246 }
6247 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6248 index dff4096..bd9a388 100644
6249 --- a/arch/sparc/lib/Makefile
6250 +++ b/arch/sparc/lib/Makefile
6251 @@ -2,7 +2,7 @@
6252 #
6253
6254 asflags-y := -ansi -DST_DIV0=0x02
6255 -ccflags-y := -Werror
6256 +#ccflags-y := -Werror
6257
6258 lib-$(CONFIG_SPARC32) += ashrdi3.o
6259 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6260 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6261 index 4d502da..527c48d 100644
6262 --- a/arch/sparc/lib/atomic_64.S
6263 +++ b/arch/sparc/lib/atomic_64.S
6264 @@ -17,7 +17,12 @@
6265 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268 - add %g1, %o0, %g7
6269 + addcc %g1, %o0, %g7
6270 +
6271 +#ifdef CONFIG_PAX_REFCOUNT
6272 + tvs %icc, 6
6273 +#endif
6274 +
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_add)
6281
6282 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6283 + BACKOFF_SETUP(%o2)
6284 +1: lduw [%o1], %g1
6285 + add %g1, %o0, %g7
6286 + cas [%o1], %g1, %g7
6287 + cmp %g1, %g7
6288 + bne,pn %icc, 2f
6289 + nop
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_add_unchecked)
6294 +
6295 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - sub %g1, %o0, %g7
6299 + subcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_sub)
6311
6312 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6313 + BACKOFF_SETUP(%o2)
6314 +1: lduw [%o1], %g1
6315 + sub %g1, %o0, %g7
6316 + cas [%o1], %g1, %g7
6317 + cmp %g1, %g7
6318 + bne,pn %icc, 2f
6319 + nop
6320 + retl
6321 + nop
6322 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 +ENDPROC(atomic_sub_unchecked)
6324 +
6325 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6326 BACKOFF_SETUP(%o2)
6327 1: lduw [%o1], %g1
6328 - add %g1, %o0, %g7
6329 + addcc %g1, %o0, %g7
6330 +
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + tvs %icc, 6
6333 +#endif
6334 +
6335 cas [%o1], %g1, %g7
6336 cmp %g1, %g7
6337 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6338 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6339 2: BACKOFF_SPIN(%o2, %o3, 1b)
6340 ENDPROC(atomic_add_ret)
6341
6342 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6343 + BACKOFF_SETUP(%o2)
6344 +1: lduw [%o1], %g1
6345 + addcc %g1, %o0, %g7
6346 + cas [%o1], %g1, %g7
6347 + cmp %g1, %g7
6348 + bne,pn %icc, 2f
6349 + add %g7, %o0, %g7
6350 + sra %g7, 0, %o0
6351 + retl
6352 + nop
6353 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 +ENDPROC(atomic_add_ret_unchecked)
6355 +
6356 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: lduw [%o1], %g1
6359 - sub %g1, %o0, %g7
6360 + subcc %g1, %o0, %g7
6361 +
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + tvs %icc, 6
6364 +#endif
6365 +
6366 cas [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6369 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6370 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373 - add %g1, %o0, %g7
6374 + addcc %g1, %o0, %g7
6375 +
6376 +#ifdef CONFIG_PAX_REFCOUNT
6377 + tvs %xcc, 6
6378 +#endif
6379 +
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_add)
6386
6387 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6388 + BACKOFF_SETUP(%o2)
6389 +1: ldx [%o1], %g1
6390 + addcc %g1, %o0, %g7
6391 + casx [%o1], %g1, %g7
6392 + cmp %g1, %g7
6393 + bne,pn %xcc, 2f
6394 + nop
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_add_unchecked)
6399 +
6400 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_sub)
6416
6417 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6418 + BACKOFF_SETUP(%o2)
6419 +1: ldx [%o1], %g1
6420 + subcc %g1, %o0, %g7
6421 + casx [%o1], %g1, %g7
6422 + cmp %g1, %g7
6423 + bne,pn %xcc, 2f
6424 + nop
6425 + retl
6426 + nop
6427 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6428 +ENDPROC(atomic64_sub_unchecked)
6429 +
6430 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6431 BACKOFF_SETUP(%o2)
6432 1: ldx [%o1], %g1
6433 - add %g1, %o0, %g7
6434 + addcc %g1, %o0, %g7
6435 +
6436 +#ifdef CONFIG_PAX_REFCOUNT
6437 + tvs %xcc, 6
6438 +#endif
6439 +
6440 casx [%o1], %g1, %g7
6441 cmp %g1, %g7
6442 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6443 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6444 2: BACKOFF_SPIN(%o2, %o3, 1b)
6445 ENDPROC(atomic64_add_ret)
6446
6447 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6448 + BACKOFF_SETUP(%o2)
6449 +1: ldx [%o1], %g1
6450 + addcc %g1, %o0, %g7
6451 + casx [%o1], %g1, %g7
6452 + cmp %g1, %g7
6453 + bne,pn %xcc, 2f
6454 + add %g7, %o0, %g7
6455 + mov %g7, %o0
6456 + retl
6457 + nop
6458 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6459 +ENDPROC(atomic64_add_ret_unchecked)
6460 +
6461 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6462 BACKOFF_SETUP(%o2)
6463 1: ldx [%o1], %g1
6464 - sub %g1, %o0, %g7
6465 + subcc %g1, %o0, %g7
6466 +
6467 +#ifdef CONFIG_PAX_REFCOUNT
6468 + tvs %xcc, 6
6469 +#endif
6470 +
6471 casx [%o1], %g1, %g7
6472 cmp %g1, %g7
6473 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6474 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6475 index 3b31218..345c609 100644
6476 --- a/arch/sparc/lib/ksyms.c
6477 +++ b/arch/sparc/lib/ksyms.c
6478 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6479
6480 /* Atomic counter implementation. */
6481 EXPORT_SYMBOL(atomic_add);
6482 +EXPORT_SYMBOL(atomic_add_unchecked);
6483 EXPORT_SYMBOL(atomic_add_ret);
6484 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6485 EXPORT_SYMBOL(atomic_sub);
6486 +EXPORT_SYMBOL(atomic_sub_unchecked);
6487 EXPORT_SYMBOL(atomic_sub_ret);
6488 EXPORT_SYMBOL(atomic64_add);
6489 +EXPORT_SYMBOL(atomic64_add_unchecked);
6490 EXPORT_SYMBOL(atomic64_add_ret);
6491 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6492 EXPORT_SYMBOL(atomic64_sub);
6493 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6494 EXPORT_SYMBOL(atomic64_sub_ret);
6495
6496 /* Atomic bit operations. */
6497 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6498 index 30c3ecc..736f015 100644
6499 --- a/arch/sparc/mm/Makefile
6500 +++ b/arch/sparc/mm/Makefile
6501 @@ -2,7 +2,7 @@
6502 #
6503
6504 asflags-y := -ansi
6505 -ccflags-y := -Werror
6506 +#ccflags-y := -Werror
6507
6508 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6509 obj-y += fault_$(BITS).o
6510 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6511 index f46cf6b..cc0666bae 100644
6512 --- a/arch/sparc/mm/fault_32.c
6513 +++ b/arch/sparc/mm/fault_32.c
6514 @@ -21,6 +21,9 @@
6515 #include <linux/perf_event.h>
6516 #include <linux/interrupt.h>
6517 #include <linux/kdebug.h>
6518 +#include <linux/slab.h>
6519 +#include <linux/pagemap.h>
6520 +#include <linux/compiler.h>
6521
6522 #include <asm/page.h>
6523 #include <asm/pgtable.h>
6524 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6525 return safe_compute_effective_address(regs, insn);
6526 }
6527
6528 +#ifdef CONFIG_PAX_PAGEEXEC
6529 +#ifdef CONFIG_PAX_DLRESOLVE
6530 +static void pax_emuplt_close(struct vm_area_struct *vma)
6531 +{
6532 + vma->vm_mm->call_dl_resolve = 0UL;
6533 +}
6534 +
6535 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6536 +{
6537 + unsigned int *kaddr;
6538 +
6539 + vmf->page = alloc_page(GFP_HIGHUSER);
6540 + if (!vmf->page)
6541 + return VM_FAULT_OOM;
6542 +
6543 + kaddr = kmap(vmf->page);
6544 + memset(kaddr, 0, PAGE_SIZE);
6545 + kaddr[0] = 0x9DE3BFA8U; /* save */
6546 + flush_dcache_page(vmf->page);
6547 + kunmap(vmf->page);
6548 + return VM_FAULT_MAJOR;
6549 +}
6550 +
6551 +static const struct vm_operations_struct pax_vm_ops = {
6552 + .close = pax_emuplt_close,
6553 + .fault = pax_emuplt_fault
6554 +};
6555 +
6556 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6557 +{
6558 + int ret;
6559 +
6560 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6561 + vma->vm_mm = current->mm;
6562 + vma->vm_start = addr;
6563 + vma->vm_end = addr + PAGE_SIZE;
6564 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6565 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6566 + vma->vm_ops = &pax_vm_ops;
6567 +
6568 + ret = insert_vm_struct(current->mm, vma);
6569 + if (ret)
6570 + return ret;
6571 +
6572 + ++current->mm->total_vm;
6573 + return 0;
6574 +}
6575 +#endif
6576 +
6577 +/*
6578 + * PaX: decide what to do with offenders (regs->pc = fault address)
6579 + *
6580 + * returns 1 when task should be killed
6581 + * 2 when patched PLT trampoline was detected
6582 + * 3 when unpatched PLT trampoline was detected
6583 + */
6584 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6585 +{
6586 +
6587 +#ifdef CONFIG_PAX_EMUPLT
6588 + int err;
6589 +
6590 + do { /* PaX: patched PLT emulation #1 */
6591 + unsigned int sethi1, sethi2, jmpl;
6592 +
6593 + err = get_user(sethi1, (unsigned int *)regs->pc);
6594 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6595 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6596 +
6597 + if (err)
6598 + break;
6599 +
6600 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6601 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6602 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + {
6604 + unsigned int addr;
6605 +
6606 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6607 + addr = regs->u_regs[UREG_G1];
6608 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6609 + regs->pc = addr;
6610 + regs->npc = addr+4;
6611 + return 2;
6612 + }
6613 + } while (0);
6614 +
6615 + do { /* PaX: patched PLT emulation #2 */
6616 + unsigned int ba;
6617 +
6618 + err = get_user(ba, (unsigned int *)regs->pc);
6619 +
6620 + if (err)
6621 + break;
6622 +
6623 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6624 + unsigned int addr;
6625 +
6626 + if ((ba & 0xFFC00000U) == 0x30800000U)
6627 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6628 + else
6629 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6630 + regs->pc = addr;
6631 + regs->npc = addr+4;
6632 + return 2;
6633 + }
6634 + } while (0);
6635 +
6636 + do { /* PaX: patched PLT emulation #3 */
6637 + unsigned int sethi, bajmpl, nop;
6638 +
6639 + err = get_user(sethi, (unsigned int *)regs->pc);
6640 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6641 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6642 +
6643 + if (err)
6644 + break;
6645 +
6646 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6647 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6648 + nop == 0x01000000U)
6649 + {
6650 + unsigned int addr;
6651 +
6652 + addr = (sethi & 0x003FFFFFU) << 10;
6653 + regs->u_regs[UREG_G1] = addr;
6654 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6655 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6656 + else
6657 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6658 + regs->pc = addr;
6659 + regs->npc = addr+4;
6660 + return 2;
6661 + }
6662 + } while (0);
6663 +
6664 + do { /* PaX: unpatched PLT emulation step 1 */
6665 + unsigned int sethi, ba, nop;
6666 +
6667 + err = get_user(sethi, (unsigned int *)regs->pc);
6668 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6669 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6670 +
6671 + if (err)
6672 + break;
6673 +
6674 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6675 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6676 + nop == 0x01000000U)
6677 + {
6678 + unsigned int addr, save, call;
6679 +
6680 + if ((ba & 0xFFC00000U) == 0x30800000U)
6681 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6682 + else
6683 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6684 +
6685 + err = get_user(save, (unsigned int *)addr);
6686 + err |= get_user(call, (unsigned int *)(addr+4));
6687 + err |= get_user(nop, (unsigned int *)(addr+8));
6688 + if (err)
6689 + break;
6690 +
6691 +#ifdef CONFIG_PAX_DLRESOLVE
6692 + if (save == 0x9DE3BFA8U &&
6693 + (call & 0xC0000000U) == 0x40000000U &&
6694 + nop == 0x01000000U)
6695 + {
6696 + struct vm_area_struct *vma;
6697 + unsigned long call_dl_resolve;
6698 +
6699 + down_read(&current->mm->mmap_sem);
6700 + call_dl_resolve = current->mm->call_dl_resolve;
6701 + up_read(&current->mm->mmap_sem);
6702 + if (likely(call_dl_resolve))
6703 + goto emulate;
6704 +
6705 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6706 +
6707 + down_write(&current->mm->mmap_sem);
6708 + if (current->mm->call_dl_resolve) {
6709 + call_dl_resolve = current->mm->call_dl_resolve;
6710 + up_write(&current->mm->mmap_sem);
6711 + if (vma)
6712 + kmem_cache_free(vm_area_cachep, vma);
6713 + goto emulate;
6714 + }
6715 +
6716 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6717 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6718 + up_write(&current->mm->mmap_sem);
6719 + if (vma)
6720 + kmem_cache_free(vm_area_cachep, vma);
6721 + return 1;
6722 + }
6723 +
6724 + if (pax_insert_vma(vma, call_dl_resolve)) {
6725 + up_write(&current->mm->mmap_sem);
6726 + kmem_cache_free(vm_area_cachep, vma);
6727 + return 1;
6728 + }
6729 +
6730 + current->mm->call_dl_resolve = call_dl_resolve;
6731 + up_write(&current->mm->mmap_sem);
6732 +
6733 +emulate:
6734 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6735 + regs->pc = call_dl_resolve;
6736 + regs->npc = addr+4;
6737 + return 3;
6738 + }
6739 +#endif
6740 +
6741 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6742 + if ((save & 0xFFC00000U) == 0x05000000U &&
6743 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6747 + regs->u_regs[UREG_G2] = addr + 4;
6748 + addr = (save & 0x003FFFFFU) << 10;
6749 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6750 + regs->pc = addr;
6751 + regs->npc = addr+4;
6752 + return 3;
6753 + }
6754 + }
6755 + } while (0);
6756 +
6757 + do { /* PaX: unpatched PLT emulation step 2 */
6758 + unsigned int save, call, nop;
6759 +
6760 + err = get_user(save, (unsigned int *)(regs->pc-4));
6761 + err |= get_user(call, (unsigned int *)regs->pc);
6762 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6763 + if (err)
6764 + break;
6765 +
6766 + if (save == 0x9DE3BFA8U &&
6767 + (call & 0xC0000000U) == 0x40000000U &&
6768 + nop == 0x01000000U)
6769 + {
6770 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6771 +
6772 + regs->u_regs[UREG_RETPC] = regs->pc;
6773 + regs->pc = dl_resolve;
6774 + regs->npc = dl_resolve+4;
6775 + return 3;
6776 + }
6777 + } while (0);
6778 +#endif
6779 +
6780 + return 1;
6781 +}
6782 +
6783 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6784 +{
6785 + unsigned long i;
6786 +
6787 + printk(KERN_ERR "PAX: bytes at PC: ");
6788 + for (i = 0; i < 8; i++) {
6789 + unsigned int c;
6790 + if (get_user(c, (unsigned int *)pc+i))
6791 + printk(KERN_CONT "???????? ");
6792 + else
6793 + printk(KERN_CONT "%08x ", c);
6794 + }
6795 + printk("\n");
6796 +}
6797 +#endif
6798 +
6799 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6800 int text_fault)
6801 {
6802 @@ -248,6 +522,24 @@ good_area:
6803 if (!(vma->vm_flags & VM_WRITE))
6804 goto bad_area;
6805 } else {
6806 +
6807 +#ifdef CONFIG_PAX_PAGEEXEC
6808 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6809 + up_read(&mm->mmap_sem);
6810 + switch (pax_handle_fetch_fault(regs)) {
6811 +
6812 +#ifdef CONFIG_PAX_EMUPLT
6813 + case 2:
6814 + case 3:
6815 + return;
6816 +#endif
6817 +
6818 + }
6819 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6820 + do_group_exit(SIGKILL);
6821 + }
6822 +#endif
6823 +
6824 /* Allow reads even for write-only mappings */
6825 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6826 goto bad_area;
6827 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6828 index 1fe0429..8dd5dd5 100644
6829 --- a/arch/sparc/mm/fault_64.c
6830 +++ b/arch/sparc/mm/fault_64.c
6831 @@ -21,6 +21,9 @@
6832 #include <linux/kprobes.h>
6833 #include <linux/kdebug.h>
6834 #include <linux/percpu.h>
6835 +#include <linux/slab.h>
6836 +#include <linux/pagemap.h>
6837 +#include <linux/compiler.h>
6838
6839 #include <asm/page.h>
6840 #include <asm/pgtable.h>
6841 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6842 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6843 regs->tpc);
6844 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6845 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6846 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6847 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6848 dump_stack();
6849 unhandled_fault(regs->tpc, current, regs);
6850 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6851 show_regs(regs);
6852 }
6853
6854 +#ifdef CONFIG_PAX_PAGEEXEC
6855 +#ifdef CONFIG_PAX_DLRESOLVE
6856 +static void pax_emuplt_close(struct vm_area_struct *vma)
6857 +{
6858 + vma->vm_mm->call_dl_resolve = 0UL;
6859 +}
6860 +
6861 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6862 +{
6863 + unsigned int *kaddr;
6864 +
6865 + vmf->page = alloc_page(GFP_HIGHUSER);
6866 + if (!vmf->page)
6867 + return VM_FAULT_OOM;
6868 +
6869 + kaddr = kmap(vmf->page);
6870 + memset(kaddr, 0, PAGE_SIZE);
6871 + kaddr[0] = 0x9DE3BFA8U; /* save */
6872 + flush_dcache_page(vmf->page);
6873 + kunmap(vmf->page);
6874 + return VM_FAULT_MAJOR;
6875 +}
6876 +
6877 +static const struct vm_operations_struct pax_vm_ops = {
6878 + .close = pax_emuplt_close,
6879 + .fault = pax_emuplt_fault
6880 +};
6881 +
6882 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6883 +{
6884 + int ret;
6885 +
6886 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6887 + vma->vm_mm = current->mm;
6888 + vma->vm_start = addr;
6889 + vma->vm_end = addr + PAGE_SIZE;
6890 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6891 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6892 + vma->vm_ops = &pax_vm_ops;
6893 +
6894 + ret = insert_vm_struct(current->mm, vma);
6895 + if (ret)
6896 + return ret;
6897 +
6898 + ++current->mm->total_vm;
6899 + return 0;
6900 +}
6901 +#endif
6902 +
6903 +/*
6904 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6905 + *
6906 + * returns 1 when task should be killed
6907 + * 2 when patched PLT trampoline was detected
6908 + * 3 when unpatched PLT trampoline was detected
6909 + */
6910 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6911 +{
6912 +
6913 +#ifdef CONFIG_PAX_EMUPLT
6914 + int err;
6915 +
6916 + do { /* PaX: patched PLT emulation #1 */
6917 + unsigned int sethi1, sethi2, jmpl;
6918 +
6919 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6920 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6921 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6922 +
6923 + if (err)
6924 + break;
6925 +
6926 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6927 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6928 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6929 + {
6930 + unsigned long addr;
6931 +
6932 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6933 + addr = regs->u_regs[UREG_G1];
6934 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6935 +
6936 + if (test_thread_flag(TIF_32BIT))
6937 + addr &= 0xFFFFFFFFUL;
6938 +
6939 + regs->tpc = addr;
6940 + regs->tnpc = addr+4;
6941 + return 2;
6942 + }
6943 + } while (0);
6944 +
6945 + do { /* PaX: patched PLT emulation #2 */
6946 + unsigned int ba;
6947 +
6948 + err = get_user(ba, (unsigned int *)regs->tpc);
6949 +
6950 + if (err)
6951 + break;
6952 +
6953 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6954 + unsigned long addr;
6955 +
6956 + if ((ba & 0xFFC00000U) == 0x30800000U)
6957 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6958 + else
6959 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6960 +
6961 + if (test_thread_flag(TIF_32BIT))
6962 + addr &= 0xFFFFFFFFUL;
6963 +
6964 + regs->tpc = addr;
6965 + regs->tnpc = addr+4;
6966 + return 2;
6967 + }
6968 + } while (0);
6969 +
6970 + do { /* PaX: patched PLT emulation #3 */
6971 + unsigned int sethi, bajmpl, nop;
6972 +
6973 + err = get_user(sethi, (unsigned int *)regs->tpc);
6974 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6975 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6976 +
6977 + if (err)
6978 + break;
6979 +
6980 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6981 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6982 + nop == 0x01000000U)
6983 + {
6984 + unsigned long addr;
6985 +
6986 + addr = (sethi & 0x003FFFFFU) << 10;
6987 + regs->u_regs[UREG_G1] = addr;
6988 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6989 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6990 + else
6991 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6992 +
6993 + if (test_thread_flag(TIF_32BIT))
6994 + addr &= 0xFFFFFFFFUL;
6995 +
6996 + regs->tpc = addr;
6997 + regs->tnpc = addr+4;
6998 + return 2;
6999 + }
7000 + } while (0);
7001 +
7002 + do { /* PaX: patched PLT emulation #4 */
7003 + unsigned int sethi, mov1, call, mov2;
7004 +
7005 + err = get_user(sethi, (unsigned int *)regs->tpc);
7006 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7007 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7008 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7009 +
7010 + if (err)
7011 + break;
7012 +
7013 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7014 + mov1 == 0x8210000FU &&
7015 + (call & 0xC0000000U) == 0x40000000U &&
7016 + mov2 == 0x9E100001U)
7017 + {
7018 + unsigned long addr;
7019 +
7020 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7021 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7022 +
7023 + if (test_thread_flag(TIF_32BIT))
7024 + addr &= 0xFFFFFFFFUL;
7025 +
7026 + regs->tpc = addr;
7027 + regs->tnpc = addr+4;
7028 + return 2;
7029 + }
7030 + } while (0);
7031 +
7032 + do { /* PaX: patched PLT emulation #5 */
7033 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7034 +
7035 + err = get_user(sethi, (unsigned int *)regs->tpc);
7036 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7037 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7038 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7039 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7040 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7041 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7042 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7043 +
7044 + if (err)
7045 + break;
7046 +
7047 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7048 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7049 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7050 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7051 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7052 + sllx == 0x83287020U &&
7053 + jmpl == 0x81C04005U &&
7054 + nop == 0x01000000U)
7055 + {
7056 + unsigned long addr;
7057 +
7058 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7059 + regs->u_regs[UREG_G1] <<= 32;
7060 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7061 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7062 + regs->tpc = addr;
7063 + regs->tnpc = addr+4;
7064 + return 2;
7065 + }
7066 + } while (0);
7067 +
7068 + do { /* PaX: patched PLT emulation #6 */
7069 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7070 +
7071 + err = get_user(sethi, (unsigned int *)regs->tpc);
7072 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7073 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7074 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7075 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7076 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7077 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7078 +
7079 + if (err)
7080 + break;
7081 +
7082 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7084 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7085 + sllx == 0x83287020U &&
7086 + (or & 0xFFFFE000U) == 0x8A116000U &&
7087 + jmpl == 0x81C04005U &&
7088 + nop == 0x01000000U)
7089 + {
7090 + unsigned long addr;
7091 +
7092 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7093 + regs->u_regs[UREG_G1] <<= 32;
7094 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7095 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7096 + regs->tpc = addr;
7097 + regs->tnpc = addr+4;
7098 + return 2;
7099 + }
7100 + } while (0);
7101 +
7102 + do { /* PaX: unpatched PLT emulation step 1 */
7103 + unsigned int sethi, ba, nop;
7104 +
7105 + err = get_user(sethi, (unsigned int *)regs->tpc);
7106 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7107 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7108 +
7109 + if (err)
7110 + break;
7111 +
7112 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7113 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7114 + nop == 0x01000000U)
7115 + {
7116 + unsigned long addr;
7117 + unsigned int save, call;
7118 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7119 +
7120 + if ((ba & 0xFFC00000U) == 0x30800000U)
7121 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7122 + else
7123 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7124 +
7125 + if (test_thread_flag(TIF_32BIT))
7126 + addr &= 0xFFFFFFFFUL;
7127 +
7128 + err = get_user(save, (unsigned int *)addr);
7129 + err |= get_user(call, (unsigned int *)(addr+4));
7130 + err |= get_user(nop, (unsigned int *)(addr+8));
7131 + if (err)
7132 + break;
7133 +
7134 +#ifdef CONFIG_PAX_DLRESOLVE
7135 + if (save == 0x9DE3BFA8U &&
7136 + (call & 0xC0000000U) == 0x40000000U &&
7137 + nop == 0x01000000U)
7138 + {
7139 + struct vm_area_struct *vma;
7140 + unsigned long call_dl_resolve;
7141 +
7142 + down_read(&current->mm->mmap_sem);
7143 + call_dl_resolve = current->mm->call_dl_resolve;
7144 + up_read(&current->mm->mmap_sem);
7145 + if (likely(call_dl_resolve))
7146 + goto emulate;
7147 +
7148 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7149 +
7150 + down_write(&current->mm->mmap_sem);
7151 + if (current->mm->call_dl_resolve) {
7152 + call_dl_resolve = current->mm->call_dl_resolve;
7153 + up_write(&current->mm->mmap_sem);
7154 + if (vma)
7155 + kmem_cache_free(vm_area_cachep, vma);
7156 + goto emulate;
7157 + }
7158 +
7159 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7160 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7161 + up_write(&current->mm->mmap_sem);
7162 + if (vma)
7163 + kmem_cache_free(vm_area_cachep, vma);
7164 + return 1;
7165 + }
7166 +
7167 + if (pax_insert_vma(vma, call_dl_resolve)) {
7168 + up_write(&current->mm->mmap_sem);
7169 + kmem_cache_free(vm_area_cachep, vma);
7170 + return 1;
7171 + }
7172 +
7173 + current->mm->call_dl_resolve = call_dl_resolve;
7174 + up_write(&current->mm->mmap_sem);
7175 +
7176 +emulate:
7177 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7178 + regs->tpc = call_dl_resolve;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 +#endif
7183 +
7184 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7185 + if ((save & 0xFFC00000U) == 0x05000000U &&
7186 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7187 + nop == 0x01000000U)
7188 + {
7189 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7190 + regs->u_regs[UREG_G2] = addr + 4;
7191 + addr = (save & 0x003FFFFFU) << 10;
7192 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7193 +
7194 + if (test_thread_flag(TIF_32BIT))
7195 + addr &= 0xFFFFFFFFUL;
7196 +
7197 + regs->tpc = addr;
7198 + regs->tnpc = addr+4;
7199 + return 3;
7200 + }
7201 +
7202 + /* PaX: 64-bit PLT stub */
7203 + err = get_user(sethi1, (unsigned int *)addr);
7204 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7205 + err |= get_user(or1, (unsigned int *)(addr+8));
7206 + err |= get_user(or2, (unsigned int *)(addr+12));
7207 + err |= get_user(sllx, (unsigned int *)(addr+16));
7208 + err |= get_user(add, (unsigned int *)(addr+20));
7209 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7210 + err |= get_user(nop, (unsigned int *)(addr+28));
7211 + if (err)
7212 + break;
7213 +
7214 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7215 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7216 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7217 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7218 + sllx == 0x89293020U &&
7219 + add == 0x8A010005U &&
7220 + jmpl == 0x89C14000U &&
7221 + nop == 0x01000000U)
7222 + {
7223 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7224 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7225 + regs->u_regs[UREG_G4] <<= 32;
7226 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7227 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7228 + regs->u_regs[UREG_G4] = addr + 24;
7229 + addr = regs->u_regs[UREG_G5];
7230 + regs->tpc = addr;
7231 + regs->tnpc = addr+4;
7232 + return 3;
7233 + }
7234 + }
7235 + } while (0);
7236 +
7237 +#ifdef CONFIG_PAX_DLRESOLVE
7238 + do { /* PaX: unpatched PLT emulation step 2 */
7239 + unsigned int save, call, nop;
7240 +
7241 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7242 + err |= get_user(call, (unsigned int *)regs->tpc);
7243 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7244 + if (err)
7245 + break;
7246 +
7247 + if (save == 0x9DE3BFA8U &&
7248 + (call & 0xC0000000U) == 0x40000000U &&
7249 + nop == 0x01000000U)
7250 + {
7251 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7252 +
7253 + if (test_thread_flag(TIF_32BIT))
7254 + dl_resolve &= 0xFFFFFFFFUL;
7255 +
7256 + regs->u_regs[UREG_RETPC] = regs->tpc;
7257 + regs->tpc = dl_resolve;
7258 + regs->tnpc = dl_resolve+4;
7259 + return 3;
7260 + }
7261 + } while (0);
7262 +#endif
7263 +
7264 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7265 + unsigned int sethi, ba, nop;
7266 +
7267 + err = get_user(sethi, (unsigned int *)regs->tpc);
7268 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7269 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7270 +
7271 + if (err)
7272 + break;
7273 +
7274 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7275 + (ba & 0xFFF00000U) == 0x30600000U &&
7276 + nop == 0x01000000U)
7277 + {
7278 + unsigned long addr;
7279 +
7280 + addr = (sethi & 0x003FFFFFU) << 10;
7281 + regs->u_regs[UREG_G1] = addr;
7282 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7283 +
7284 + if (test_thread_flag(TIF_32BIT))
7285 + addr &= 0xFFFFFFFFUL;
7286 +
7287 + regs->tpc = addr;
7288 + regs->tnpc = addr+4;
7289 + return 2;
7290 + }
7291 + } while (0);
7292 +
7293 +#endif
7294 +
7295 + return 1;
7296 +}
7297 +
7298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7299 +{
7300 + unsigned long i;
7301 +
7302 + printk(KERN_ERR "PAX: bytes at PC: ");
7303 + for (i = 0; i < 8; i++) {
7304 + unsigned int c;
7305 + if (get_user(c, (unsigned int *)pc+i))
7306 + printk(KERN_CONT "???????? ");
7307 + else
7308 + printk(KERN_CONT "%08x ", c);
7309 + }
7310 + printk("\n");
7311 +}
7312 +#endif
7313 +
7314 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7315 {
7316 struct mm_struct *mm = current->mm;
7317 @@ -343,6 +806,29 @@ retry:
7318 if (!vma)
7319 goto bad_area;
7320
7321 +#ifdef CONFIG_PAX_PAGEEXEC
7322 + /* PaX: detect ITLB misses on non-exec pages */
7323 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7324 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7325 + {
7326 + if (address != regs->tpc)
7327 + goto good_area;
7328 +
7329 + up_read(&mm->mmap_sem);
7330 + switch (pax_handle_fetch_fault(regs)) {
7331 +
7332 +#ifdef CONFIG_PAX_EMUPLT
7333 + case 2:
7334 + case 3:
7335 + return;
7336 +#endif
7337 +
7338 + }
7339 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7340 + do_group_exit(SIGKILL);
7341 + }
7342 +#endif
7343 +
7344 /* Pure DTLB misses do not tell us whether the fault causing
7345 * load/store/atomic was a write or not, it only says that there
7346 * was no match. So in such a case we (carefully) read the
7347 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7348 index 07e1453..0a7d9e9 100644
7349 --- a/arch/sparc/mm/hugetlbpage.c
7350 +++ b/arch/sparc/mm/hugetlbpage.c
7351 @@ -67,7 +67,7 @@ full_search:
7352 }
7353 return -ENOMEM;
7354 }
7355 - if (likely(!vma || addr + len <= vma->vm_start)) {
7356 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7357 /*
7358 * Remember the place where we stopped the search:
7359 */
7360 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7361 /* make sure it can fit in the remaining address space */
7362 if (likely(addr > len)) {
7363 vma = find_vma(mm, addr-len);
7364 - if (!vma || addr <= vma->vm_start) {
7365 + if (check_heap_stack_gap(vma, addr - len, len)) {
7366 /* remember the address as a hint for next time */
7367 return (mm->free_area_cache = addr-len);
7368 }
7369 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7370 if (unlikely(mm->mmap_base < len))
7371 goto bottomup;
7372
7373 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7374 + addr = mm->mmap_base - len;
7375
7376 do {
7377 + addr &= HPAGE_MASK;
7378 /*
7379 * Lookup failure means no vma is above this address,
7380 * else if new region fits below vma->vm_start,
7381 * return with success:
7382 */
7383 vma = find_vma(mm, addr);
7384 - if (likely(!vma || addr+len <= vma->vm_start)) {
7385 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7386 /* remember the address as a hint for next time */
7387 return (mm->free_area_cache = addr);
7388 }
7389 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7390 mm->cached_hole_size = vma->vm_start - addr;
7391
7392 /* try just below the current vma->vm_start */
7393 - addr = (vma->vm_start-len) & HPAGE_MASK;
7394 - } while (likely(len < vma->vm_start));
7395 + addr = skip_heap_stack_gap(vma, len);
7396 + } while (!IS_ERR_VALUE(addr));
7397
7398 bottomup:
7399 /*
7400 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7401 if (addr) {
7402 addr = ALIGN(addr, HPAGE_SIZE);
7403 vma = find_vma(mm, addr);
7404 - if (task_size - len >= addr &&
7405 - (!vma || addr + len <= vma->vm_start))
7406 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7407 return addr;
7408 }
7409 if (mm->get_unmapped_area == arch_get_unmapped_area)
7410 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7411 index f4500c6..889656c 100644
7412 --- a/arch/tile/include/asm/atomic_64.h
7413 +++ b/arch/tile/include/asm/atomic_64.h
7414 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7415
7416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7417
7418 +#define atomic64_read_unchecked(v) atomic64_read(v)
7419 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7420 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7421 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7422 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7423 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7424 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7425 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7426 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7427 +
7428 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7429 #define smp_mb__before_atomic_dec() smp_mb()
7430 #define smp_mb__after_atomic_dec() smp_mb()
7431 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7432 index 392e533..536b092 100644
7433 --- a/arch/tile/include/asm/cache.h
7434 +++ b/arch/tile/include/asm/cache.h
7435 @@ -15,11 +15,12 @@
7436 #ifndef _ASM_TILE_CACHE_H
7437 #define _ASM_TILE_CACHE_H
7438
7439 +#include <linux/const.h>
7440 #include <arch/chip.h>
7441
7442 /* bytes per L1 data cache line */
7443 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 /* bytes per L2 cache line */
7448 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7449 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7450 index 9ab078a..d6635c2 100644
7451 --- a/arch/tile/include/asm/uaccess.h
7452 +++ b/arch/tile/include/asm/uaccess.h
7453 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7454 const void __user *from,
7455 unsigned long n)
7456 {
7457 - int sz = __compiletime_object_size(to);
7458 + size_t sz = __compiletime_object_size(to);
7459
7460 - if (likely(sz == -1 || sz >= n))
7461 + if (likely(sz == (size_t)-1 || sz >= n))
7462 n = _copy_from_user(to, from, n);
7463 else
7464 copy_from_user_overflow();
7465 diff --git a/arch/um/Makefile b/arch/um/Makefile
7466 index 0970910..13adb57a 100644
7467 --- a/arch/um/Makefile
7468 +++ b/arch/um/Makefile
7469 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7470 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7471 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7472
7473 +ifdef CONSTIFY_PLUGIN
7474 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7475 +endif
7476 +
7477 #This will adjust *FLAGS accordingly to the platform.
7478 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7479
7480 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7481 index 19e1bdd..3665b77 100644
7482 --- a/arch/um/include/asm/cache.h
7483 +++ b/arch/um/include/asm/cache.h
7484 @@ -1,6 +1,7 @@
7485 #ifndef __UM_CACHE_H
7486 #define __UM_CACHE_H
7487
7488 +#include <linux/const.h>
7489
7490 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7491 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7492 @@ -12,6 +13,6 @@
7493 # define L1_CACHE_SHIFT 5
7494 #endif
7495
7496 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7497 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7498
7499 #endif
7500 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7501 index 6c03acd..a5e0215 100644
7502 --- a/arch/um/include/asm/kmap_types.h
7503 +++ b/arch/um/include/asm/kmap_types.h
7504 @@ -23,6 +23,7 @@ enum km_type {
7505 KM_IRQ1,
7506 KM_SOFTIRQ0,
7507 KM_SOFTIRQ1,
7508 + KM_CLEARPAGE,
7509 KM_TYPE_NR
7510 };
7511
7512 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7513 index 7cfc3ce..cbd1a58 100644
7514 --- a/arch/um/include/asm/page.h
7515 +++ b/arch/um/include/asm/page.h
7516 @@ -14,6 +14,9 @@
7517 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7518 #define PAGE_MASK (~(PAGE_SIZE-1))
7519
7520 +#define ktla_ktva(addr) (addr)
7521 +#define ktva_ktla(addr) (addr)
7522 +
7523 #ifndef __ASSEMBLY__
7524
7525 struct page;
7526 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7527 index 0032f92..cd151e0 100644
7528 --- a/arch/um/include/asm/pgtable-3level.h
7529 +++ b/arch/um/include/asm/pgtable-3level.h
7530 @@ -58,6 +58,7 @@
7531 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7532 #define pud_populate(mm, pud, pmd) \
7533 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7534 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7535
7536 #ifdef CONFIG_64BIT
7537 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7538 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7539 index ccb9a9d..cc425bb 100644
7540 --- a/arch/um/kernel/process.c
7541 +++ b/arch/um/kernel/process.c
7542 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7543 return 2;
7544 }
7545
7546 -/*
7547 - * Only x86 and x86_64 have an arch_align_stack().
7548 - * All other arches have "#define arch_align_stack(x) (x)"
7549 - * in their asm/system.h
7550 - * As this is included in UML from asm-um/system-generic.h,
7551 - * we can use it to behave as the subarch does.
7552 - */
7553 -#ifndef arch_align_stack
7554 -unsigned long arch_align_stack(unsigned long sp)
7555 -{
7556 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7557 - sp -= get_random_int() % 8192;
7558 - return sp & ~0xf;
7559 -}
7560 -#endif
7561 -
7562 unsigned long get_wchan(struct task_struct *p)
7563 {
7564 unsigned long stack_page, sp, ip;
7565 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7566 index ad8f795..2c7eec6 100644
7567 --- a/arch/unicore32/include/asm/cache.h
7568 +++ b/arch/unicore32/include/asm/cache.h
7569 @@ -12,8 +12,10 @@
7570 #ifndef __UNICORE_CACHE_H__
7571 #define __UNICORE_CACHE_H__
7572
7573 -#define L1_CACHE_SHIFT (5)
7574 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7575 +#include <linux/const.h>
7576 +
7577 +#define L1_CACHE_SHIFT 5
7578 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7579
7580 /*
7581 * Memory returned by kmalloc() may be used for DMA, so we must make
7582 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7583 index c70684f..698fa4b 100644
7584 --- a/arch/x86/Kconfig
7585 +++ b/arch/x86/Kconfig
7586 @@ -218,7 +218,7 @@ config X86_HT
7587
7588 config X86_32_LAZY_GS
7589 def_bool y
7590 - depends on X86_32 && !CC_STACKPROTECTOR
7591 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7592
7593 config ARCH_HWEIGHT_CFLAGS
7594 string
7595 @@ -1047,7 +1047,7 @@ choice
7596
7597 config NOHIGHMEM
7598 bool "off"
7599 - depends on !X86_NUMAQ
7600 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7601 ---help---
7602 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7603 However, the address space of 32-bit x86 processors is only 4
7604 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7605
7606 config HIGHMEM4G
7607 bool "4GB"
7608 - depends on !X86_NUMAQ
7609 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7610 ---help---
7611 Select this if you have a 32-bit processor and between 1 and 4
7612 gigabytes of physical RAM.
7613 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7614 hex
7615 default 0xB0000000 if VMSPLIT_3G_OPT
7616 default 0x80000000 if VMSPLIT_2G
7617 - default 0x78000000 if VMSPLIT_2G_OPT
7618 + default 0x70000000 if VMSPLIT_2G_OPT
7619 default 0x40000000 if VMSPLIT_1G
7620 default 0xC0000000
7621 depends on X86_32
7622 @@ -1526,6 +1526,7 @@ config SECCOMP
7623
7624 config CC_STACKPROTECTOR
7625 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7626 + depends on X86_64 || !PAX_MEMORY_UDEREF
7627 ---help---
7628 This option turns on the -fstack-protector GCC feature. This
7629 feature puts, at the beginning of functions, a canary value on
7630 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7631 config PHYSICAL_START
7632 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7633 default "0x1000000"
7634 + range 0x400000 0x40000000
7635 ---help---
7636 This gives the physical address where the kernel is loaded.
7637
7638 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7639 config PHYSICAL_ALIGN
7640 hex "Alignment value to which kernel should be aligned" if X86_32
7641 default "0x1000000"
7642 + range 0x400000 0x1000000 if PAX_KERNEXEC
7643 range 0x2000 0x1000000
7644 ---help---
7645 This value puts the alignment restrictions on physical address
7646 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7647 Say N if you want to disable CPU hotplug.
7648
7649 config COMPAT_VDSO
7650 - def_bool y
7651 + def_bool n
7652 prompt "Compat VDSO support"
7653 depends on X86_32 || IA32_EMULATION
7654 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7655 ---help---
7656 Map the 32-bit VDSO to the predictable old-style address too.
7657
7658 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7659 index 706e12e..62e4feb 100644
7660 --- a/arch/x86/Kconfig.cpu
7661 +++ b/arch/x86/Kconfig.cpu
7662 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7663
7664 config X86_F00F_BUG
7665 def_bool y
7666 - depends on M586MMX || M586TSC || M586 || M486 || M386
7667 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7668
7669 config X86_INVD_BUG
7670 def_bool y
7671 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7672
7673 config X86_ALIGNMENT_16
7674 def_bool y
7675 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7676 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7677
7678 config X86_INTEL_USERCOPY
7679 def_bool y
7680 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7681 # generates cmov.
7682 config X86_CMOV
7683 def_bool y
7684 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7685 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7686
7687 config X86_MINIMUM_CPU_FAMILY
7688 int
7689 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7690 index e46c214..ab62fd1 100644
7691 --- a/arch/x86/Kconfig.debug
7692 +++ b/arch/x86/Kconfig.debug
7693 @@ -84,7 +84,7 @@ config X86_PTDUMP
7694 config DEBUG_RODATA
7695 bool "Write protect kernel read-only data structures"
7696 default y
7697 - depends on DEBUG_KERNEL
7698 + depends on DEBUG_KERNEL && BROKEN
7699 ---help---
7700 Mark the kernel read-only data as write-protected in the pagetables,
7701 in order to catch accidental (and incorrect) writes to such const
7702 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7703
7704 config DEBUG_SET_MODULE_RONX
7705 bool "Set loadable kernel module data as NX and text as RO"
7706 - depends on MODULES
7707 + depends on MODULES && BROKEN
7708 ---help---
7709 This option helps catch unintended modifications to loadable
7710 kernel module's text and read-only data. It also prevents execution
7711 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7712
7713 config DEBUG_STRICT_USER_COPY_CHECKS
7714 bool "Strict copy size checks"
7715 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7716 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7717 ---help---
7718 Enabling this option turns a certain set of sanity checks for user
7719 copy operations into compile time failures.
7720 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7721 index 1f25214..39422b3 100644
7722 --- a/arch/x86/Makefile
7723 +++ b/arch/x86/Makefile
7724 @@ -46,6 +46,7 @@ else
7725 UTS_MACHINE := x86_64
7726 CHECKFLAGS += -D__x86_64__ -m64
7727
7728 + biarch := $(call cc-option,-m64)
7729 KBUILD_AFLAGS += -m64
7730 KBUILD_CFLAGS += -m64
7731
7732 @@ -222,3 +223,12 @@ define archhelp
7733 echo ' FDARGS="..." arguments for the booted kernel'
7734 echo ' FDINITRD=file initrd for the booted kernel'
7735 endef
7736 +
7737 +define OLD_LD
7738 +
7739 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7740 +*** Please upgrade your binutils to 2.18 or newer
7741 +endef
7742 +
7743 +archprepare:
7744 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7745 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7746 index 5a747dd..ff7b12c 100644
7747 --- a/arch/x86/boot/Makefile
7748 +++ b/arch/x86/boot/Makefile
7749 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7750 $(call cc-option, -fno-stack-protector) \
7751 $(call cc-option, -mpreferred-stack-boundary=2)
7752 KBUILD_CFLAGS += $(call cc-option, -m32)
7753 +ifdef CONSTIFY_PLUGIN
7754 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7755 +endif
7756 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7757 GCOV_PROFILE := n
7758
7759 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7760 index 878e4b9..20537ab 100644
7761 --- a/arch/x86/boot/bitops.h
7762 +++ b/arch/x86/boot/bitops.h
7763 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7764 u8 v;
7765 const u32 *p = (const u32 *)addr;
7766
7767 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7768 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7769 return v;
7770 }
7771
7772 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7773
7774 static inline void set_bit(int nr, void *addr)
7775 {
7776 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7777 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7778 }
7779
7780 #endif /* BOOT_BITOPS_H */
7781 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7782 index 18997e5..83d9c67 100644
7783 --- a/arch/x86/boot/boot.h
7784 +++ b/arch/x86/boot/boot.h
7785 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7786 static inline u16 ds(void)
7787 {
7788 u16 seg;
7789 - asm("movw %%ds,%0" : "=rm" (seg));
7790 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7791 return seg;
7792 }
7793
7794 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7795 static inline int memcmp(const void *s1, const void *s2, size_t len)
7796 {
7797 u8 diff;
7798 - asm("repe; cmpsb; setnz %0"
7799 + asm volatile("repe; cmpsb; setnz %0"
7800 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7801 return diff;
7802 }
7803 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7804 index e398bb5..3a382ca 100644
7805 --- a/arch/x86/boot/compressed/Makefile
7806 +++ b/arch/x86/boot/compressed/Makefile
7807 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7808 KBUILD_CFLAGS += $(cflags-y)
7809 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7810 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7811 +ifdef CONSTIFY_PLUGIN
7812 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7813 +endif
7814
7815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7816 GCOV_PROFILE := n
7817 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7818 index 4e85f5f..39fa641 100644
7819 --- a/arch/x86/boot/compressed/eboot.c
7820 +++ b/arch/x86/boot/compressed/eboot.c
7821 @@ -142,7 +142,6 @@ again:
7822 *addr = max_addr;
7823 }
7824
7825 -free_pool:
7826 efi_call_phys1(sys_table->boottime->free_pool, map);
7827
7828 fail:
7829 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7830 if (i == map_size / desc_size)
7831 status = EFI_NOT_FOUND;
7832
7833 -free_pool:
7834 efi_call_phys1(sys_table->boottime->free_pool, map);
7835 fail:
7836 return status;
7837 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7838 index c85e3ac..6f5aa80 100644
7839 --- a/arch/x86/boot/compressed/head_32.S
7840 +++ b/arch/x86/boot/compressed/head_32.S
7841 @@ -106,7 +106,7 @@ preferred_addr:
7842 notl %eax
7843 andl %eax, %ebx
7844 #else
7845 - movl $LOAD_PHYSICAL_ADDR, %ebx
7846 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7847 #endif
7848
7849 /* Target address to relocate to for decompression */
7850 @@ -192,7 +192,7 @@ relocated:
7851 * and where it was actually loaded.
7852 */
7853 movl %ebp, %ebx
7854 - subl $LOAD_PHYSICAL_ADDR, %ebx
7855 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7856 jz 2f /* Nothing to be done if loaded at compiled addr. */
7857 /*
7858 * Process relocations.
7859 @@ -200,8 +200,7 @@ relocated:
7860
7861 1: subl $4, %edi
7862 movl (%edi), %ecx
7863 - testl %ecx, %ecx
7864 - jz 2f
7865 + jecxz 2f
7866 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7867 jmp 1b
7868 2:
7869 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7870 index 87e03a1..0d94c76 100644
7871 --- a/arch/x86/boot/compressed/head_64.S
7872 +++ b/arch/x86/boot/compressed/head_64.S
7873 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7874 notl %eax
7875 andl %eax, %ebx
7876 #else
7877 - movl $LOAD_PHYSICAL_ADDR, %ebx
7878 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7879 #endif
7880
7881 /* Target address to relocate to for decompression */
7882 @@ -263,7 +263,7 @@ preferred_addr:
7883 notq %rax
7884 andq %rax, %rbp
7885 #else
7886 - movq $LOAD_PHYSICAL_ADDR, %rbp
7887 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7888 #endif
7889
7890 /* Target address to relocate to for decompression */
7891 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7892 index 7116dcb..d9ae1d7 100644
7893 --- a/arch/x86/boot/compressed/misc.c
7894 +++ b/arch/x86/boot/compressed/misc.c
7895 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7896 case PT_LOAD:
7897 #ifdef CONFIG_RELOCATABLE
7898 dest = output;
7899 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7900 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7901 #else
7902 dest = (void *)(phdr->p_paddr);
7903 #endif
7904 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7905 error("Destination address too large");
7906 #endif
7907 #ifndef CONFIG_RELOCATABLE
7908 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7909 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7910 error("Wrong destination address");
7911 #endif
7912
7913 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7914 index 4d3ff03..e4972ff 100644
7915 --- a/arch/x86/boot/cpucheck.c
7916 +++ b/arch/x86/boot/cpucheck.c
7917 @@ -74,7 +74,7 @@ static int has_fpu(void)
7918 u16 fcw = -1, fsw = -1;
7919 u32 cr0;
7920
7921 - asm("movl %%cr0,%0" : "=r" (cr0));
7922 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7923 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7924 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7925 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7926 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7927 {
7928 u32 f0, f1;
7929
7930 - asm("pushfl ; "
7931 + asm volatile("pushfl ; "
7932 "pushfl ; "
7933 "popl %0 ; "
7934 "movl %0,%1 ; "
7935 @@ -115,7 +115,7 @@ static void get_flags(void)
7936 set_bit(X86_FEATURE_FPU, cpu.flags);
7937
7938 if (has_eflag(X86_EFLAGS_ID)) {
7939 - asm("cpuid"
7940 + asm volatile("cpuid"
7941 : "=a" (max_intel_level),
7942 "=b" (cpu_vendor[0]),
7943 "=d" (cpu_vendor[1]),
7944 @@ -124,7 +124,7 @@ static void get_flags(void)
7945
7946 if (max_intel_level >= 0x00000001 &&
7947 max_intel_level <= 0x0000ffff) {
7948 - asm("cpuid"
7949 + asm volatile("cpuid"
7950 : "=a" (tfms),
7951 "=c" (cpu.flags[4]),
7952 "=d" (cpu.flags[0])
7953 @@ -136,7 +136,7 @@ static void get_flags(void)
7954 cpu.model += ((tfms >> 16) & 0xf) << 4;
7955 }
7956
7957 - asm("cpuid"
7958 + asm volatile("cpuid"
7959 : "=a" (max_amd_level)
7960 : "a" (0x80000000)
7961 : "ebx", "ecx", "edx");
7962 @@ -144,7 +144,7 @@ static void get_flags(void)
7963 if (max_amd_level >= 0x80000001 &&
7964 max_amd_level <= 0x8000ffff) {
7965 u32 eax = 0x80000001;
7966 - asm("cpuid"
7967 + asm volatile("cpuid"
7968 : "+a" (eax),
7969 "=c" (cpu.flags[6]),
7970 "=d" (cpu.flags[1])
7971 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 ecx = MSR_K7_HWCR;
7973 u32 eax, edx;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7977 eax &= ~(1 << 15);
7978 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7980
7981 get_flags(); /* Make sure it really did something */
7982 err = check_flags();
7983 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7984 u32 ecx = MSR_VIA_FCR;
7985 u32 eax, edx;
7986
7987 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7988 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7989 eax |= (1<<1)|(1<<7);
7990 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7991 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7992
7993 set_bit(X86_FEATURE_CX8, cpu.flags);
7994 err = check_flags();
7995 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7996 u32 eax, edx;
7997 u32 level = 1;
7998
7999 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8000 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8001 - asm("cpuid"
8002 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8003 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8004 + asm volatile("cpuid"
8005 : "+a" (level), "=d" (cpu.flags[0])
8006 : : "ecx", "ebx");
8007 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8008 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8009
8010 err = check_flags();
8011 }
8012 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8013 index efe5acf..22a3784 100644
8014 --- a/arch/x86/boot/header.S
8015 +++ b/arch/x86/boot/header.S
8016 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8017 # single linked list of
8018 # struct setup_data
8019
8020 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8021 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8022
8023 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8024 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8025 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8026 +#else
8027 #define VO_INIT_SIZE (VO__end - VO__text)
8028 +#endif
8029 #if ZO_INIT_SIZE > VO_INIT_SIZE
8030 #define INIT_SIZE ZO_INIT_SIZE
8031 #else
8032 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8033 index db75d07..8e6d0af 100644
8034 --- a/arch/x86/boot/memory.c
8035 +++ b/arch/x86/boot/memory.c
8036 @@ -19,7 +19,7 @@
8037
8038 static int detect_memory_e820(void)
8039 {
8040 - int count = 0;
8041 + unsigned int count = 0;
8042 struct biosregs ireg, oreg;
8043 struct e820entry *desc = boot_params.e820_map;
8044 static struct e820entry buf; /* static so it is zeroed */
8045 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8046 index 11e8c6e..fdbb1ed 100644
8047 --- a/arch/x86/boot/video-vesa.c
8048 +++ b/arch/x86/boot/video-vesa.c
8049 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8050
8051 boot_params.screen_info.vesapm_seg = oreg.es;
8052 boot_params.screen_info.vesapm_off = oreg.di;
8053 + boot_params.screen_info.vesapm_size = oreg.cx;
8054 }
8055
8056 /*
8057 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8058 index 43eda28..5ab5fdb 100644
8059 --- a/arch/x86/boot/video.c
8060 +++ b/arch/x86/boot/video.c
8061 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8062 static unsigned int get_entry(void)
8063 {
8064 char entry_buf[4];
8065 - int i, len = 0;
8066 + unsigned int i, len = 0;
8067 int key;
8068 unsigned int v;
8069
8070 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8071 index 5b577d5..3c1fed4 100644
8072 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8073 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8074 @@ -8,6 +8,8 @@
8075 * including this sentence is retained in full.
8076 */
8077
8078 +#include <asm/alternative-asm.h>
8079 +
8080 .extern crypto_ft_tab
8081 .extern crypto_it_tab
8082 .extern crypto_fl_tab
8083 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8084 je B192; \
8085 leaq 32(r9),r9;
8086
8087 +#define ret pax_force_retaddr 0, 1; ret
8088 +
8089 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8090 movq r1,r2; \
8091 movq r3,r4; \
8092 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8093 index 3470624..201259d 100644
8094 --- a/arch/x86/crypto/aesni-intel_asm.S
8095 +++ b/arch/x86/crypto/aesni-intel_asm.S
8096 @@ -31,6 +31,7 @@
8097
8098 #include <linux/linkage.h>
8099 #include <asm/inst.h>
8100 +#include <asm/alternative-asm.h>
8101
8102 #ifdef __x86_64__
8103 .data
8104 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_gcm_dec)
8111
8112
8113 /*****************************************************************************
8114 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_gcm_enc)
8121
8122 #endif
8123
8124 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8125 pxor %xmm1, %xmm0
8126 movaps %xmm0, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 .align 4
8132 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8133 shufps $0b01001110, %xmm2, %xmm1
8134 movaps %xmm1, 0x10(TKEYP)
8135 add $0x20, TKEYP
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 .align 4
8140 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8141
8142 movaps %xmm0, (TKEYP)
8143 add $0x10, TKEYP
8144 + pax_force_retaddr_bts
8145 ret
8146
8147 .align 4
8148 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8149 pxor %xmm1, %xmm2
8150 movaps %xmm2, (TKEYP)
8151 add $0x10, TKEYP
8152 + pax_force_retaddr_bts
8153 ret
8154
8155 /*
8156 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8157 #ifndef __x86_64__
8158 popl KEYP
8159 #endif
8160 + pax_force_retaddr 0, 1
8161 ret
8162 +ENDPROC(aesni_set_key)
8163
8164 /*
8165 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8166 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8167 popl KLEN
8168 popl KEYP
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_enc)
8173
8174 /*
8175 * _aesni_enc1: internal ABI
8176 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8177 AESENC KEY STATE
8178 movaps 0x70(TKEYP), KEY
8179 AESENCLAST KEY STATE
8180 + pax_force_retaddr_bts
8181 ret
8182
8183 /*
8184 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8185 AESENCLAST KEY STATE2
8186 AESENCLAST KEY STATE3
8187 AESENCLAST KEY STATE4
8188 + pax_force_retaddr_bts
8189 ret
8190
8191 /*
8192 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8193 popl KLEN
8194 popl KEYP
8195 #endif
8196 + pax_force_retaddr 0, 1
8197 ret
8198 +ENDPROC(aesni_dec)
8199
8200 /*
8201 * _aesni_dec1: internal ABI
8202 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8203 AESDEC KEY STATE
8204 movaps 0x70(TKEYP), KEY
8205 AESDECLAST KEY STATE
8206 + pax_force_retaddr_bts
8207 ret
8208
8209 /*
8210 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8211 AESDECLAST KEY STATE2
8212 AESDECLAST KEY STATE3
8213 AESDECLAST KEY STATE4
8214 + pax_force_retaddr_bts
8215 ret
8216
8217 /*
8218 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222 + pax_force_retaddr 0, 1
8223 ret
8224 +ENDPROC(aesni_ecb_enc)
8225
8226 /*
8227 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232 + pax_force_retaddr 0, 1
8233 ret
8234 +ENDPROC(aesni_ecb_dec)
8235
8236 /*
8237 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8239 popl LEN
8240 popl IVP
8241 #endif
8242 + pax_force_retaddr 0, 1
8243 ret
8244 +ENDPROC(aesni_cbc_enc)
8245
8246 /*
8247 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8249 popl LEN
8250 popl IVP
8251 #endif
8252 + pax_force_retaddr 0, 1
8253 ret
8254 +ENDPROC(aesni_cbc_dec)
8255
8256 #ifdef __x86_64__
8257 .align 16
8258 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8259 mov $1, TCTR_LOW
8260 MOVQ_R64_XMM TCTR_LOW INC
8261 MOVQ_R64_XMM CTR TCTR_LOW
8262 + pax_force_retaddr_bts
8263 ret
8264
8265 /*
8266 @@ -2554,6 +2582,7 @@ _aesni_inc:
8267 .Linc_low:
8268 movaps CTR, IV
8269 PSHUFB_XMM BSWAP_MASK IV
8270 + pax_force_retaddr_bts
8271 ret
8272
8273 /*
8274 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8275 .Lctr_enc_ret:
8276 movups IV, (IVP)
8277 .Lctr_enc_just_ret:
8278 + pax_force_retaddr 0, 1
8279 ret
8280 +ENDPROC(aesni_ctr_enc)
8281 #endif
8282 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8283 index 391d245..67f35c2 100644
8284 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8285 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8286 @@ -20,6 +20,8 @@
8287 *
8288 */
8289
8290 +#include <asm/alternative-asm.h>
8291 +
8292 .file "blowfish-x86_64-asm.S"
8293 .text
8294
8295 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8296 jnz __enc_xor;
8297
8298 write_block();
8299 + pax_force_retaddr 0, 1
8300 ret;
8301 __enc_xor:
8302 xor_block();
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8308
8309 movq %r11, %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 /**********************************************************************
8315 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8316
8317 popq %rbx;
8318 popq %rbp;
8319 + pax_force_retaddr 0, 1
8320 ret;
8321
8322 __enc_xor4:
8323 @@ -349,6 +355,7 @@ __enc_xor4:
8324
8325 popq %rbx;
8326 popq %rbp;
8327 + pax_force_retaddr 0, 1
8328 ret;
8329
8330 .align 8
8331 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8332 popq %rbx;
8333 popq %rbp;
8334
8335 + pax_force_retaddr 0, 1
8336 ret;
8337
8338 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8339 index 0b33743..7a56206 100644
8340 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8341 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8342 @@ -20,6 +20,8 @@
8343 *
8344 */
8345
8346 +#include <asm/alternative-asm.h>
8347 +
8348 .file "camellia-x86_64-asm_64.S"
8349 .text
8350
8351 @@ -229,12 +231,14 @@ __enc_done:
8352 enc_outunpack(mov, RT1);
8353
8354 movq RRBP, %rbp;
8355 + pax_force_retaddr 0, 1
8356 ret;
8357
8358 __enc_xor:
8359 enc_outunpack(xor, RT1);
8360
8361 movq RRBP, %rbp;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk;
8366 @@ -275,6 +279,7 @@ __dec_rounds16:
8367 dec_outunpack();
8368
8369 movq RRBP, %rbp;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372
8373 /**********************************************************************
8374 @@ -468,6 +473,7 @@ __enc2_done:
8375
8376 movq RRBP, %rbp;
8377 popq %rbx;
8378 + pax_force_retaddr 0, 1
8379 ret;
8380
8381 __enc2_xor:
8382 @@ -475,6 +481,7 @@ __enc2_xor:
8383
8384 movq RRBP, %rbp;
8385 popq %rbx;
8386 + pax_force_retaddr 0, 1
8387 ret;
8388
8389 .global camellia_dec_blk_2way;
8390 @@ -517,4 +524,5 @@ __dec2_rounds16:
8391
8392 movq RRBP, %rbp;
8393 movq RXOR, %rbx;
8394 + pax_force_retaddr 0, 1
8395 ret;
8396 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8397 index 6214a9b..1f4fc9a 100644
8398 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8399 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8400 @@ -1,3 +1,5 @@
8401 +#include <asm/alternative-asm.h>
8402 +
8403 # enter ECRYPT_encrypt_bytes
8404 .text
8405 .p2align 5
8406 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8407 add %r11,%rsp
8408 mov %rdi,%rax
8409 mov %rsi,%rdx
8410 + pax_force_retaddr 0, 1
8411 ret
8412 # bytesatleast65:
8413 ._bytesatleast65:
8414 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8415 add %r11,%rsp
8416 mov %rdi,%rax
8417 mov %rsi,%rdx
8418 + pax_force_retaddr
8419 ret
8420 # enter ECRYPT_ivsetup
8421 .text
8422 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8423 add %r11,%rsp
8424 mov %rdi,%rax
8425 mov %rsi,%rdx
8426 + pax_force_retaddr
8427 ret
8428 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8429 index 3ee1ff0..cbc568b 100644
8430 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8431 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8432 @@ -24,6 +24,8 @@
8433 *
8434 */
8435
8436 +#include <asm/alternative-asm.h>
8437 +
8438 .file "serpent-sse2-x86_64-asm_64.S"
8439 .text
8440
8441 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8442 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8443 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8444
8445 + pax_force_retaddr
8446 ret;
8447
8448 __enc_xor8:
8449 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8450 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8451
8452 + pax_force_retaddr
8453 ret;
8454
8455 .align 8
8456 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8457 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8458 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8459
8460 + pax_force_retaddr
8461 ret;
8462 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8463 index b2c2f57..8470cab 100644
8464 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8465 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8466 @@ -28,6 +28,8 @@
8467 * (at your option) any later version.
8468 */
8469
8470 +#include <asm/alternative-asm.h>
8471 +
8472 #define CTX %rdi // arg1
8473 #define BUF %rsi // arg2
8474 #define CNT %rdx // arg3
8475 @@ -104,6 +106,7 @@
8476 pop %r12
8477 pop %rbp
8478 pop %rbx
8479 + pax_force_retaddr 0, 1
8480 ret
8481
8482 .size \name, .-\name
8483 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8484 index 5b012a2..36d5364 100644
8485 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8486 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8487 @@ -20,6 +20,8 @@
8488 *
8489 */
8490
8491 +#include <asm/alternative-asm.h>
8492 +
8493 .file "twofish-x86_64-asm-3way.S"
8494 .text
8495
8496 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8497 popq %r13;
8498 popq %r14;
8499 popq %r15;
8500 + pax_force_retaddr 0, 1
8501 ret;
8502
8503 __enc_xor3:
8504 @@ -271,6 +274,7 @@ __enc_xor3:
8505 popq %r13;
8506 popq %r14;
8507 popq %r15;
8508 + pax_force_retaddr 0, 1
8509 ret;
8510
8511 .global twofish_dec_blk_3way
8512 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516 + pax_force_retaddr 0, 1
8517 ret;
8518
8519 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8520 index 7bcf3fc..f53832f 100644
8521 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8522 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8523 @@ -21,6 +21,7 @@
8524 .text
8525
8526 #include <asm/asm-offsets.h>
8527 +#include <asm/alternative-asm.h>
8528
8529 #define a_offset 0
8530 #define b_offset 4
8531 @@ -268,6 +269,7 @@ twofish_enc_blk:
8532
8533 popq R1
8534 movq $1,%rax
8535 + pax_force_retaddr 0, 1
8536 ret
8537
8538 twofish_dec_blk:
8539 @@ -319,4 +321,5 @@ twofish_dec_blk:
8540
8541 popq R1
8542 movq $1,%rax
8543 + pax_force_retaddr 0, 1
8544 ret
8545 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8546 index 07b3a68..bd2a388 100644
8547 --- a/arch/x86/ia32/ia32_aout.c
8548 +++ b/arch/x86/ia32/ia32_aout.c
8549 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8550 unsigned long dump_start, dump_size;
8551 struct user32 dump;
8552
8553 + memset(&dump, 0, sizeof(dump));
8554 +
8555 fs = get_fs();
8556 set_fs(KERNEL_DS);
8557 has_dumped = 1;
8558 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8559 index 673ac9b..7a8c5df 100644
8560 --- a/arch/x86/ia32/ia32_signal.c
8561 +++ b/arch/x86/ia32/ia32_signal.c
8562 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8563 }
8564 seg = get_fs();
8565 set_fs(KERNEL_DS);
8566 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8567 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8568 set_fs(seg);
8569 if (ret >= 0 && uoss_ptr) {
8570 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8571 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8572 */
8573 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8574 size_t frame_size,
8575 - void **fpstate)
8576 + void __user **fpstate)
8577 {
8578 unsigned long sp;
8579
8580 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8581
8582 if (used_math()) {
8583 sp = sp - sig_xstate_ia32_size;
8584 - *fpstate = (struct _fpstate_ia32 *) sp;
8585 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8586 if (save_i387_xstate_ia32(*fpstate) < 0)
8587 return (void __user *) -1L;
8588 }
8589 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 sp -= frame_size;
8591 /* Align the stack pointer according to the i386 ABI,
8592 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8593 - sp = ((sp + 4) & -16ul) - 4;
8594 + sp = ((sp - 12) & -16ul) - 4;
8595 return (void __user *) sp;
8596 }
8597
8598 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8599 * These are actually not used anymore, but left because some
8600 * gdb versions depend on them as a marker.
8601 */
8602 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8603 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8604 } put_user_catch(err);
8605
8606 if (err)
8607 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8608 0xb8,
8609 __NR_ia32_rt_sigreturn,
8610 0x80cd,
8611 - 0,
8612 + 0
8613 };
8614
8615 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8616 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8617
8618 if (ka->sa.sa_flags & SA_RESTORER)
8619 restorer = ka->sa.sa_restorer;
8620 + else if (current->mm->context.vdso)
8621 + /* Return stub is in 32bit vsyscall page */
8622 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8623 else
8624 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8625 - rt_sigreturn);
8626 + restorer = &frame->retcode;
8627 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8628
8629 /*
8630 * Not actually used anymore, but left because some gdb
8631 * versions need it.
8632 */
8633 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8634 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8635 } put_user_catch(err);
8636
8637 if (err)
8638 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8639 index 20e5f7b..f33c779 100644
8640 --- a/arch/x86/ia32/ia32entry.S
8641 +++ b/arch/x86/ia32/ia32entry.S
8642 @@ -14,8 +14,10 @@
8643 #include <asm/segment.h>
8644 #include <asm/irqflags.h>
8645 #include <asm/asm.h>
8646 +#include <asm/pgtable.h>
8647 #include <linux/linkage.h>
8648 #include <linux/err.h>
8649 +#include <asm/alternative-asm.h>
8650
8651 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8652 #include <linux/elf-em.h>
8653 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8654 ENDPROC(native_irq_enable_sysexit)
8655 #endif
8656
8657 + .macro pax_enter_kernel_user
8658 + pax_set_fptr_mask
8659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8660 + call pax_enter_kernel_user
8661 +#endif
8662 + .endm
8663 +
8664 + .macro pax_exit_kernel_user
8665 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8666 + call pax_exit_kernel_user
8667 +#endif
8668 +#ifdef CONFIG_PAX_RANDKSTACK
8669 + pushq %rax
8670 + pushq %r11
8671 + call pax_randomize_kstack
8672 + popq %r11
8673 + popq %rax
8674 +#endif
8675 + .endm
8676 +
8677 +.macro pax_erase_kstack
8678 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8679 + call pax_erase_kstack
8680 +#endif
8681 +.endm
8682 +
8683 /*
8684 * 32bit SYSENTER instruction entry.
8685 *
8686 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8687 CFI_REGISTER rsp,rbp
8688 SWAPGS_UNSAFE_STACK
8689 movq PER_CPU_VAR(kernel_stack), %rsp
8690 - addq $(KERNEL_STACK_OFFSET),%rsp
8691 - /*
8692 - * No need to follow this irqs on/off section: the syscall
8693 - * disabled irqs, here we enable it straight after entry:
8694 - */
8695 - ENABLE_INTERRUPTS(CLBR_NONE)
8696 movl %ebp,%ebp /* zero extension */
8697 pushq_cfi $__USER32_DS
8698 /*CFI_REL_OFFSET ss,0*/
8699 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8700 CFI_REL_OFFSET rsp,0
8701 pushfq_cfi
8702 /*CFI_REL_OFFSET rflags,0*/
8703 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8704 - CFI_REGISTER rip,r10
8705 + orl $X86_EFLAGS_IF,(%rsp)
8706 + GET_THREAD_INFO(%r11)
8707 + movl TI_sysenter_return(%r11), %r11d
8708 + CFI_REGISTER rip,r11
8709 pushq_cfi $__USER32_CS
8710 /*CFI_REL_OFFSET cs,0*/
8711 movl %eax, %eax
8712 - pushq_cfi %r10
8713 + pushq_cfi %r11
8714 CFI_REL_OFFSET rip,0
8715 pushq_cfi %rax
8716 cld
8717 SAVE_ARGS 0,1,0
8718 + pax_enter_kernel_user
8719 +
8720 +#ifdef CONFIG_PAX_RANDKSTACK
8721 + pax_erase_kstack
8722 +#endif
8723 +
8724 + /*
8725 + * No need to follow this irqs on/off section: the syscall
8726 + * disabled irqs, here we enable it straight after entry:
8727 + */
8728 + ENABLE_INTERRUPTS(CLBR_NONE)
8729 /* no need to do an access_ok check here because rbp has been
8730 32bit zero extended */
8731 +
8732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8733 + mov $PAX_USER_SHADOW_BASE,%r11
8734 + add %r11,%rbp
8735 +#endif
8736 +
8737 1: movl (%rbp),%ebp
8738 _ASM_EXTABLE(1b,ia32_badarg)
8739 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8740 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8741 + GET_THREAD_INFO(%r11)
8742 + orl $TS_COMPAT,TI_status(%r11)
8743 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8744 CFI_REMEMBER_STATE
8745 jnz sysenter_tracesys
8746 cmpq $(IA32_NR_syscalls-1),%rax
8747 @@ -159,12 +201,15 @@ sysenter_do_call:
8748 sysenter_dispatch:
8749 call *ia32_sys_call_table(,%rax,8)
8750 movq %rax,RAX-ARGOFFSET(%rsp)
8751 + GET_THREAD_INFO(%r11)
8752 DISABLE_INTERRUPTS(CLBR_NONE)
8753 TRACE_IRQS_OFF
8754 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8755 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8756 jnz sysexit_audit
8757 sysexit_from_sys_call:
8758 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8759 + pax_exit_kernel_user
8760 + pax_erase_kstack
8761 + andl $~TS_COMPAT,TI_status(%r11)
8762 /* clear IF, that popfq doesn't enable interrupts early */
8763 andl $~0x200,EFLAGS-R11(%rsp)
8764 movl RIP-R11(%rsp),%edx /* User %eip */
8765 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8766 movl %eax,%esi /* 2nd arg: syscall number */
8767 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8768 call __audit_syscall_entry
8769 +
8770 + pax_erase_kstack
8771 +
8772 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8773 cmpq $(IA32_NR_syscalls-1),%rax
8774 ja ia32_badsys
8775 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8776 .endm
8777
8778 .macro auditsys_exit exit
8779 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8780 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8781 jnz ia32_ret_from_sys_call
8782 TRACE_IRQS_ON
8783 sti
8784 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8785 1: setbe %al /* 1 if error, 0 if not */
8786 movzbl %al,%edi /* zero-extend that into %edi */
8787 call __audit_syscall_exit
8788 + GET_THREAD_INFO(%r11)
8789 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8790 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8791 cli
8792 TRACE_IRQS_OFF
8793 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8794 + testl %edi,TI_flags(%r11)
8795 jz \exit
8796 CLEAR_RREGS -ARGOFFSET
8797 jmp int_with_check
8798 @@ -234,7 +283,7 @@ sysexit_audit:
8799
8800 sysenter_tracesys:
8801 #ifdef CONFIG_AUDITSYSCALL
8802 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8804 jz sysenter_auditsys
8805 #endif
8806 SAVE_REST
8807 @@ -246,6 +295,9 @@ sysenter_tracesys:
8808 RESTORE_REST
8809 cmpq $(IA32_NR_syscalls-1),%rax
8810 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8811 +
8812 + pax_erase_kstack
8813 +
8814 jmp sysenter_do_call
8815 CFI_ENDPROC
8816 ENDPROC(ia32_sysenter_target)
8817 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8818 ENTRY(ia32_cstar_target)
8819 CFI_STARTPROC32 simple
8820 CFI_SIGNAL_FRAME
8821 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8822 + CFI_DEF_CFA rsp,0
8823 CFI_REGISTER rip,rcx
8824 /*CFI_REGISTER rflags,r11*/
8825 SWAPGS_UNSAFE_STACK
8826 movl %esp,%r8d
8827 CFI_REGISTER rsp,r8
8828 movq PER_CPU_VAR(kernel_stack),%rsp
8829 + SAVE_ARGS 8*6,0,0
8830 + pax_enter_kernel_user
8831 +
8832 +#ifdef CONFIG_PAX_RANDKSTACK
8833 + pax_erase_kstack
8834 +#endif
8835 +
8836 /*
8837 * No need to follow this irqs on/off section: the syscall
8838 * disabled irqs and here we enable it straight after entry:
8839 */
8840 ENABLE_INTERRUPTS(CLBR_NONE)
8841 - SAVE_ARGS 8,0,0
8842 movl %eax,%eax /* zero extension */
8843 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8844 movq %rcx,RIP-ARGOFFSET(%rsp)
8845 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8846 /* no need to do an access_ok check here because r8 has been
8847 32bit zero extended */
8848 /* hardware stack frame is complete now */
8849 +
8850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8851 + mov $PAX_USER_SHADOW_BASE,%r11
8852 + add %r11,%r8
8853 +#endif
8854 +
8855 1: movl (%r8),%r9d
8856 _ASM_EXTABLE(1b,ia32_badarg)
8857 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8858 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8859 + GET_THREAD_INFO(%r11)
8860 + orl $TS_COMPAT,TI_status(%r11)
8861 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8862 CFI_REMEMBER_STATE
8863 jnz cstar_tracesys
8864 cmpq $IA32_NR_syscalls-1,%rax
8865 @@ -314,12 +379,15 @@ cstar_do_call:
8866 cstar_dispatch:
8867 call *ia32_sys_call_table(,%rax,8)
8868 movq %rax,RAX-ARGOFFSET(%rsp)
8869 + GET_THREAD_INFO(%r11)
8870 DISABLE_INTERRUPTS(CLBR_NONE)
8871 TRACE_IRQS_OFF
8872 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8873 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8874 jnz sysretl_audit
8875 sysretl_from_sys_call:
8876 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8877 + pax_exit_kernel_user
8878 + pax_erase_kstack
8879 + andl $~TS_COMPAT,TI_status(%r11)
8880 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8881 movl RIP-ARGOFFSET(%rsp),%ecx
8882 CFI_REGISTER rip,rcx
8883 @@ -347,7 +415,7 @@ sysretl_audit:
8884
8885 cstar_tracesys:
8886 #ifdef CONFIG_AUDITSYSCALL
8887 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8888 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8889 jz cstar_auditsys
8890 #endif
8891 xchgl %r9d,%ebp
8892 @@ -361,6 +429,9 @@ cstar_tracesys:
8893 xchgl %ebp,%r9d
8894 cmpq $(IA32_NR_syscalls-1),%rax
8895 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8896 +
8897 + pax_erase_kstack
8898 +
8899 jmp cstar_do_call
8900 END(ia32_cstar_target)
8901
8902 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8903 CFI_REL_OFFSET rip,RIP-RIP
8904 PARAVIRT_ADJUST_EXCEPTION_FRAME
8905 SWAPGS
8906 - /*
8907 - * No need to follow this irqs on/off section: the syscall
8908 - * disabled irqs and here we enable it straight after entry:
8909 - */
8910 - ENABLE_INTERRUPTS(CLBR_NONE)
8911 movl %eax,%eax
8912 pushq_cfi %rax
8913 cld
8914 /* note the registers are not zero extended to the sf.
8915 this could be a problem. */
8916 SAVE_ARGS 0,1,0
8917 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8918 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8919 + pax_enter_kernel_user
8920 +
8921 +#ifdef CONFIG_PAX_RANDKSTACK
8922 + pax_erase_kstack
8923 +#endif
8924 +
8925 + /*
8926 + * No need to follow this irqs on/off section: the syscall
8927 + * disabled irqs and here we enable it straight after entry:
8928 + */
8929 + ENABLE_INTERRUPTS(CLBR_NONE)
8930 + GET_THREAD_INFO(%r11)
8931 + orl $TS_COMPAT,TI_status(%r11)
8932 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8933 jnz ia32_tracesys
8934 cmpq $(IA32_NR_syscalls-1),%rax
8935 ja ia32_badsys
8936 @@ -436,6 +514,9 @@ ia32_tracesys:
8937 RESTORE_REST
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8940 +
8941 + pax_erase_kstack
8942 +
8943 jmp ia32_do_call
8944 END(ia32_syscall)
8945
8946 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8947 index 4540bec..714d913 100644
8948 --- a/arch/x86/ia32/sys_ia32.c
8949 +++ b/arch/x86/ia32/sys_ia32.c
8950 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8951 */
8952 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8953 {
8954 - typeof(ubuf->st_uid) uid = 0;
8955 - typeof(ubuf->st_gid) gid = 0;
8956 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8957 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8958 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8959 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8960 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8961 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8962 return ret;
8963 }
8964
8965 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8966 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8967 int options)
8968 {
8969 return compat_sys_wait4(pid, stat_addr, options, NULL);
8970 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8971 mm_segment_t old_fs = get_fs();
8972
8973 set_fs(KERNEL_DS);
8974 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8975 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8976 set_fs(old_fs);
8977 if (put_compat_timespec(&t, interval))
8978 return -EFAULT;
8979 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8980 mm_segment_t old_fs = get_fs();
8981
8982 set_fs(KERNEL_DS);
8983 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8984 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8985 set_fs(old_fs);
8986 if (!ret) {
8987 switch (_NSIG_WORDS) {
8988 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8989 if (copy_siginfo_from_user32(&info, uinfo))
8990 return -EFAULT;
8991 set_fs(KERNEL_DS);
8992 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8993 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8994 set_fs(old_fs);
8995 return ret;
8996 }
8997 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8998 return -EFAULT;
8999
9000 set_fs(KERNEL_DS);
9001 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9002 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9003 count);
9004 set_fs(old_fs);
9005
9006 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9007 index 952bd01..7692c6f 100644
9008 --- a/arch/x86/include/asm/alternative-asm.h
9009 +++ b/arch/x86/include/asm/alternative-asm.h
9010 @@ -15,6 +15,45 @@
9011 .endm
9012 #endif
9013
9014 +#ifdef KERNEXEC_PLUGIN
9015 + .macro pax_force_retaddr_bts rip=0
9016 + btsq $63,\rip(%rsp)
9017 + .endm
9018 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9019 + .macro pax_force_retaddr rip=0, reload=0
9020 + btsq $63,\rip(%rsp)
9021 + .endm
9022 + .macro pax_force_fptr ptr
9023 + btsq $63,\ptr
9024 + .endm
9025 + .macro pax_set_fptr_mask
9026 + .endm
9027 +#endif
9028 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9029 + .macro pax_force_retaddr rip=0, reload=0
9030 + .if \reload
9031 + pax_set_fptr_mask
9032 + .endif
9033 + orq %r10,\rip(%rsp)
9034 + .endm
9035 + .macro pax_force_fptr ptr
9036 + orq %r10,\ptr
9037 + .endm
9038 + .macro pax_set_fptr_mask
9039 + movabs $0x8000000000000000,%r10
9040 + .endm
9041 +#endif
9042 +#else
9043 + .macro pax_force_retaddr rip=0, reload=0
9044 + .endm
9045 + .macro pax_force_fptr ptr
9046 + .endm
9047 + .macro pax_force_retaddr_bts rip=0
9048 + .endm
9049 + .macro pax_set_fptr_mask
9050 + .endm
9051 +#endif
9052 +
9053 .macro altinstruction_entry orig alt feature orig_len alt_len
9054 .long \orig - .
9055 .long \alt - .
9056 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9057 index 49331be..9706065 100644
9058 --- a/arch/x86/include/asm/alternative.h
9059 +++ b/arch/x86/include/asm/alternative.h
9060 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9061 ".section .discard,\"aw\",@progbits\n" \
9062 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9063 ".previous\n" \
9064 - ".section .altinstr_replacement, \"ax\"\n" \
9065 + ".section .altinstr_replacement, \"a\"\n" \
9066 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9067 ".previous"
9068
9069 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9070 index eaff479..3025a63 100644
9071 --- a/arch/x86/include/asm/apic.h
9072 +++ b/arch/x86/include/asm/apic.h
9073 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9074
9075 #ifdef CONFIG_X86_LOCAL_APIC
9076
9077 -extern unsigned int apic_verbosity;
9078 +extern int apic_verbosity;
9079 extern int local_apic_timer_c2_ok;
9080
9081 extern int disable_apic;
9082 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9083 index 20370c6..a2eb9b0 100644
9084 --- a/arch/x86/include/asm/apm.h
9085 +++ b/arch/x86/include/asm/apm.h
9086 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9087 __asm__ __volatile__(APM_DO_ZERO_SEGS
9088 "pushl %%edi\n\t"
9089 "pushl %%ebp\n\t"
9090 - "lcall *%%cs:apm_bios_entry\n\t"
9091 + "lcall *%%ss:apm_bios_entry\n\t"
9092 "setc %%al\n\t"
9093 "popl %%ebp\n\t"
9094 "popl %%edi\n\t"
9095 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9096 __asm__ __volatile__(APM_DO_ZERO_SEGS
9097 "pushl %%edi\n\t"
9098 "pushl %%ebp\n\t"
9099 - "lcall *%%cs:apm_bios_entry\n\t"
9100 + "lcall *%%ss:apm_bios_entry\n\t"
9101 "setc %%bl\n\t"
9102 "popl %%ebp\n\t"
9103 "popl %%edi\n\t"
9104 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9105 index 58cb6d4..a4b806c 100644
9106 --- a/arch/x86/include/asm/atomic.h
9107 +++ b/arch/x86/include/asm/atomic.h
9108 @@ -22,7 +22,18 @@
9109 */
9110 static inline int atomic_read(const atomic_t *v)
9111 {
9112 - return (*(volatile int *)&(v)->counter);
9113 + return (*(volatile const int *)&(v)->counter);
9114 +}
9115 +
9116 +/**
9117 + * atomic_read_unchecked - read atomic variable
9118 + * @v: pointer of type atomic_unchecked_t
9119 + *
9120 + * Atomically reads the value of @v.
9121 + */
9122 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9123 +{
9124 + return (*(volatile const int *)&(v)->counter);
9125 }
9126
9127 /**
9128 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9129 }
9130
9131 /**
9132 + * atomic_set_unchecked - set atomic variable
9133 + * @v: pointer of type atomic_unchecked_t
9134 + * @i: required value
9135 + *
9136 + * Atomically sets the value of @v to @i.
9137 + */
9138 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9139 +{
9140 + v->counter = i;
9141 +}
9142 +
9143 +/**
9144 * atomic_add - add integer to atomic variable
9145 * @i: integer value to add
9146 * @v: pointer of type atomic_t
9147 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9148 */
9149 static inline void atomic_add(int i, atomic_t *v)
9150 {
9151 - asm volatile(LOCK_PREFIX "addl %1,%0"
9152 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9153 +
9154 +#ifdef CONFIG_PAX_REFCOUNT
9155 + "jno 0f\n"
9156 + LOCK_PREFIX "subl %1,%0\n"
9157 + "int $4\n0:\n"
9158 + _ASM_EXTABLE(0b, 0b)
9159 +#endif
9160 +
9161 + : "+m" (v->counter)
9162 + : "ir" (i));
9163 +}
9164 +
9165 +/**
9166 + * atomic_add_unchecked - add integer to atomic variable
9167 + * @i: integer value to add
9168 + * @v: pointer of type atomic_unchecked_t
9169 + *
9170 + * Atomically adds @i to @v.
9171 + */
9172 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9173 +{
9174 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9175 : "+m" (v->counter)
9176 : "ir" (i));
9177 }
9178 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9179 */
9180 static inline void atomic_sub(int i, atomic_t *v)
9181 {
9182 - asm volatile(LOCK_PREFIX "subl %1,%0"
9183 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9184 +
9185 +#ifdef CONFIG_PAX_REFCOUNT
9186 + "jno 0f\n"
9187 + LOCK_PREFIX "addl %1,%0\n"
9188 + "int $4\n0:\n"
9189 + _ASM_EXTABLE(0b, 0b)
9190 +#endif
9191 +
9192 + : "+m" (v->counter)
9193 + : "ir" (i));
9194 +}
9195 +
9196 +/**
9197 + * atomic_sub_unchecked - subtract integer from atomic variable
9198 + * @i: integer value to subtract
9199 + * @v: pointer of type atomic_unchecked_t
9200 + *
9201 + * Atomically subtracts @i from @v.
9202 + */
9203 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9204 +{
9205 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9206 : "+m" (v->counter)
9207 : "ir" (i));
9208 }
9209 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9210 {
9211 unsigned char c;
9212
9213 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9214 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9215 +
9216 +#ifdef CONFIG_PAX_REFCOUNT
9217 + "jno 0f\n"
9218 + LOCK_PREFIX "addl %2,%0\n"
9219 + "int $4\n0:\n"
9220 + _ASM_EXTABLE(0b, 0b)
9221 +#endif
9222 +
9223 + "sete %1\n"
9224 : "+m" (v->counter), "=qm" (c)
9225 : "ir" (i) : "memory");
9226 return c;
9227 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9228 */
9229 static inline void atomic_inc(atomic_t *v)
9230 {
9231 - asm volatile(LOCK_PREFIX "incl %0"
9232 + asm volatile(LOCK_PREFIX "incl %0\n"
9233 +
9234 +#ifdef CONFIG_PAX_REFCOUNT
9235 + "jno 0f\n"
9236 + LOCK_PREFIX "decl %0\n"
9237 + "int $4\n0:\n"
9238 + _ASM_EXTABLE(0b, 0b)
9239 +#endif
9240 +
9241 + : "+m" (v->counter));
9242 +}
9243 +
9244 +/**
9245 + * atomic_inc_unchecked - increment atomic variable
9246 + * @v: pointer of type atomic_unchecked_t
9247 + *
9248 + * Atomically increments @v by 1.
9249 + */
9250 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9251 +{
9252 + asm volatile(LOCK_PREFIX "incl %0\n"
9253 : "+m" (v->counter));
9254 }
9255
9256 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9257 */
9258 static inline void atomic_dec(atomic_t *v)
9259 {
9260 - asm volatile(LOCK_PREFIX "decl %0"
9261 + asm volatile(LOCK_PREFIX "decl %0\n"
9262 +
9263 +#ifdef CONFIG_PAX_REFCOUNT
9264 + "jno 0f\n"
9265 + LOCK_PREFIX "incl %0\n"
9266 + "int $4\n0:\n"
9267 + _ASM_EXTABLE(0b, 0b)
9268 +#endif
9269 +
9270 + : "+m" (v->counter));
9271 +}
9272 +
9273 +/**
9274 + * atomic_dec_unchecked - decrement atomic variable
9275 + * @v: pointer of type atomic_unchecked_t
9276 + *
9277 + * Atomically decrements @v by 1.
9278 + */
9279 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9280 +{
9281 + asm volatile(LOCK_PREFIX "decl %0\n"
9282 : "+m" (v->counter));
9283 }
9284
9285 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9286 {
9287 unsigned char c;
9288
9289 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9290 + asm volatile(LOCK_PREFIX "decl %0\n"
9291 +
9292 +#ifdef CONFIG_PAX_REFCOUNT
9293 + "jno 0f\n"
9294 + LOCK_PREFIX "incl %0\n"
9295 + "int $4\n0:\n"
9296 + _ASM_EXTABLE(0b, 0b)
9297 +#endif
9298 +
9299 + "sete %1\n"
9300 : "+m" (v->counter), "=qm" (c)
9301 : : "memory");
9302 return c != 0;
9303 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9304 {
9305 unsigned char c;
9306
9307 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9308 + asm volatile(LOCK_PREFIX "incl %0\n"
9309 +
9310 +#ifdef CONFIG_PAX_REFCOUNT
9311 + "jno 0f\n"
9312 + LOCK_PREFIX "decl %0\n"
9313 + "int $4\n0:\n"
9314 + _ASM_EXTABLE(0b, 0b)
9315 +#endif
9316 +
9317 + "sete %1\n"
9318 + : "+m" (v->counter), "=qm" (c)
9319 + : : "memory");
9320 + return c != 0;
9321 +}
9322 +
9323 +/**
9324 + * atomic_inc_and_test_unchecked - increment and test
9325 + * @v: pointer of type atomic_unchecked_t
9326 + *
9327 + * Atomically increments @v by 1
9328 + * and returns true if the result is zero, or false for all
9329 + * other cases.
9330 + */
9331 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9332 +{
9333 + unsigned char c;
9334 +
9335 + asm volatile(LOCK_PREFIX "incl %0\n"
9336 + "sete %1\n"
9337 : "+m" (v->counter), "=qm" (c)
9338 : : "memory");
9339 return c != 0;
9340 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9341 {
9342 unsigned char c;
9343
9344 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9345 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9346 +
9347 +#ifdef CONFIG_PAX_REFCOUNT
9348 + "jno 0f\n"
9349 + LOCK_PREFIX "subl %2,%0\n"
9350 + "int $4\n0:\n"
9351 + _ASM_EXTABLE(0b, 0b)
9352 +#endif
9353 +
9354 + "sets %1\n"
9355 : "+m" (v->counter), "=qm" (c)
9356 : "ir" (i) : "memory");
9357 return c;
9358 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9359 goto no_xadd;
9360 #endif
9361 /* Modern 486+ processor */
9362 - return i + xadd(&v->counter, i);
9363 + return i + xadd_check_overflow(&v->counter, i);
9364
9365 #ifdef CONFIG_M386
9366 no_xadd: /* Legacy 386 processor */
9367 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9368 }
9369
9370 /**
9371 + * atomic_add_return_unchecked - add integer and return
9372 + * @i: integer value to add
9373 + * @v: pointer of type atomic_unchecked_t
9374 + *
9375 + * Atomically adds @i to @v and returns @i + @v
9376 + */
9377 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9378 +{
9379 +#ifdef CONFIG_M386
9380 + int __i;
9381 + unsigned long flags;
9382 + if (unlikely(boot_cpu_data.x86 <= 3))
9383 + goto no_xadd;
9384 +#endif
9385 + /* Modern 486+ processor */
9386 + return i + xadd(&v->counter, i);
9387 +
9388 +#ifdef CONFIG_M386
9389 +no_xadd: /* Legacy 386 processor */
9390 + raw_local_irq_save(flags);
9391 + __i = atomic_read_unchecked(v);
9392 + atomic_set_unchecked(v, i + __i);
9393 + raw_local_irq_restore(flags);
9394 + return i + __i;
9395 +#endif
9396 +}
9397 +
9398 +/**
9399 * atomic_sub_return - subtract integer and return
9400 * @v: pointer of type atomic_t
9401 * @i: integer value to subtract
9402 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9403 }
9404
9405 #define atomic_inc_return(v) (atomic_add_return(1, v))
9406 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9407 +{
9408 + return atomic_add_return_unchecked(1, v);
9409 +}
9410 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9411
9412 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9413 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9414 return cmpxchg(&v->counter, old, new);
9415 }
9416
9417 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9418 +{
9419 + return cmpxchg(&v->counter, old, new);
9420 +}
9421 +
9422 static inline int atomic_xchg(atomic_t *v, int new)
9423 {
9424 return xchg(&v->counter, new);
9425 }
9426
9427 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9428 +{
9429 + return xchg(&v->counter, new);
9430 +}
9431 +
9432 /**
9433 * __atomic_add_unless - add unless the number is already a given value
9434 * @v: pointer of type atomic_t
9435 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9436 */
9437 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9438 {
9439 - int c, old;
9440 + int c, old, new;
9441 c = atomic_read(v);
9442 for (;;) {
9443 - if (unlikely(c == (u)))
9444 + if (unlikely(c == u))
9445 break;
9446 - old = atomic_cmpxchg((v), c, c + (a));
9447 +
9448 + asm volatile("addl %2,%0\n"
9449 +
9450 +#ifdef CONFIG_PAX_REFCOUNT
9451 + "jno 0f\n"
9452 + "subl %2,%0\n"
9453 + "int $4\n0:\n"
9454 + _ASM_EXTABLE(0b, 0b)
9455 +#endif
9456 +
9457 + : "=r" (new)
9458 + : "0" (c), "ir" (a));
9459 +
9460 + old = atomic_cmpxchg(v, c, new);
9461 if (likely(old == c))
9462 break;
9463 c = old;
9464 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9465 return c;
9466 }
9467
9468 +/**
9469 + * atomic_inc_not_zero_hint - increment if not null
9470 + * @v: pointer of type atomic_t
9471 + * @hint: probable value of the atomic before the increment
9472 + *
9473 + * This version of atomic_inc_not_zero() gives a hint of probable
9474 + * value of the atomic. This helps processor to not read the memory
9475 + * before doing the atomic read/modify/write cycle, lowering
9476 + * number of bus transactions on some arches.
9477 + *
9478 + * Returns: 0 if increment was not done, 1 otherwise.
9479 + */
9480 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9481 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9482 +{
9483 + int val, c = hint, new;
9484 +
9485 + /* sanity test, should be removed by compiler if hint is a constant */
9486 + if (!hint)
9487 + return __atomic_add_unless(v, 1, 0);
9488 +
9489 + do {
9490 + asm volatile("incl %0\n"
9491 +
9492 +#ifdef CONFIG_PAX_REFCOUNT
9493 + "jno 0f\n"
9494 + "decl %0\n"
9495 + "int $4\n0:\n"
9496 + _ASM_EXTABLE(0b, 0b)
9497 +#endif
9498 +
9499 + : "=r" (new)
9500 + : "0" (c));
9501 +
9502 + val = atomic_cmpxchg(v, c, new);
9503 + if (val == c)
9504 + return 1;
9505 + c = val;
9506 + } while (c);
9507 +
9508 + return 0;
9509 +}
9510
9511 /*
9512 * atomic_dec_if_positive - decrement by 1 if old value positive
9513 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9514 #endif
9515
9516 /* These are x86-specific, used by some header files */
9517 -#define atomic_clear_mask(mask, addr) \
9518 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9519 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9520 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9521 +{
9522 + asm volatile(LOCK_PREFIX "andl %1,%0"
9523 + : "+m" (v->counter)
9524 + : "r" (~(mask))
9525 + : "memory");
9526 +}
9527
9528 -#define atomic_set_mask(mask, addr) \
9529 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9530 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9531 - : "memory")
9532 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9533 +{
9534 + asm volatile(LOCK_PREFIX "andl %1,%0"
9535 + : "+m" (v->counter)
9536 + : "r" (~(mask))
9537 + : "memory");
9538 +}
9539 +
9540 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9541 +{
9542 + asm volatile(LOCK_PREFIX "orl %1,%0"
9543 + : "+m" (v->counter)
9544 + : "r" (mask)
9545 + : "memory");
9546 +}
9547 +
9548 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9549 +{
9550 + asm volatile(LOCK_PREFIX "orl %1,%0"
9551 + : "+m" (v->counter)
9552 + : "r" (mask)
9553 + : "memory");
9554 +}
9555
9556 /* Atomic operations are already serializing on x86 */
9557 #define smp_mb__before_atomic_dec() barrier()
9558 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9559 index b154de7..aadebd8 100644
9560 --- a/arch/x86/include/asm/atomic64_32.h
9561 +++ b/arch/x86/include/asm/atomic64_32.h
9562 @@ -12,6 +12,14 @@ typedef struct {
9563 u64 __aligned(8) counter;
9564 } atomic64_t;
9565
9566 +#ifdef CONFIG_PAX_REFCOUNT
9567 +typedef struct {
9568 + u64 __aligned(8) counter;
9569 +} atomic64_unchecked_t;
9570 +#else
9571 +typedef atomic64_t atomic64_unchecked_t;
9572 +#endif
9573 +
9574 #define ATOMIC64_INIT(val) { (val) }
9575
9576 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9577 @@ -37,21 +45,31 @@ typedef struct {
9578 ATOMIC64_DECL_ONE(sym##_386)
9579
9580 ATOMIC64_DECL_ONE(add_386);
9581 +ATOMIC64_DECL_ONE(add_unchecked_386);
9582 ATOMIC64_DECL_ONE(sub_386);
9583 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9584 ATOMIC64_DECL_ONE(inc_386);
9585 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9586 ATOMIC64_DECL_ONE(dec_386);
9587 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9588 #endif
9589
9590 #define alternative_atomic64(f, out, in...) \
9591 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9592
9593 ATOMIC64_DECL(read);
9594 +ATOMIC64_DECL(read_unchecked);
9595 ATOMIC64_DECL(set);
9596 +ATOMIC64_DECL(set_unchecked);
9597 ATOMIC64_DECL(xchg);
9598 ATOMIC64_DECL(add_return);
9599 +ATOMIC64_DECL(add_return_unchecked);
9600 ATOMIC64_DECL(sub_return);
9601 +ATOMIC64_DECL(sub_return_unchecked);
9602 ATOMIC64_DECL(inc_return);
9603 +ATOMIC64_DECL(inc_return_unchecked);
9604 ATOMIC64_DECL(dec_return);
9605 +ATOMIC64_DECL(dec_return_unchecked);
9606 ATOMIC64_DECL(dec_if_positive);
9607 ATOMIC64_DECL(inc_not_zero);
9608 ATOMIC64_DECL(add_unless);
9609 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9610 }
9611
9612 /**
9613 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9614 + * @p: pointer to type atomic64_unchecked_t
9615 + * @o: expected value
9616 + * @n: new value
9617 + *
9618 + * Atomically sets @v to @n if it was equal to @o and returns
9619 + * the old value.
9620 + */
9621 +
9622 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9623 +{
9624 + return cmpxchg64(&v->counter, o, n);
9625 +}
9626 +
9627 +/**
9628 * atomic64_xchg - xchg atomic64 variable
9629 * @v: pointer to type atomic64_t
9630 * @n: value to assign
9631 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9632 }
9633
9634 /**
9635 + * atomic64_set_unchecked - set atomic64 variable
9636 + * @v: pointer to type atomic64_unchecked_t
9637 + * @n: value to assign
9638 + *
9639 + * Atomically sets the value of @v to @n.
9640 + */
9641 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9642 +{
9643 + unsigned high = (unsigned)(i >> 32);
9644 + unsigned low = (unsigned)i;
9645 + alternative_atomic64(set, /* no output */,
9646 + "S" (v), "b" (low), "c" (high)
9647 + : "eax", "edx", "memory");
9648 +}
9649 +
9650 +/**
9651 * atomic64_read - read atomic64 variable
9652 * @v: pointer to type atomic64_t
9653 *
9654 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9655 }
9656
9657 /**
9658 + * atomic64_read_unchecked - read atomic64 variable
9659 + * @v: pointer to type atomic64_unchecked_t
9660 + *
9661 + * Atomically reads the value of @v and returns it.
9662 + */
9663 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9664 +{
9665 + long long r;
9666 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9667 + return r;
9668 + }
9669 +
9670 +/**
9671 * atomic64_add_return - add and return
9672 * @i: integer value to add
9673 * @v: pointer to type atomic64_t
9674 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9675 return i;
9676 }
9677
9678 +/**
9679 + * atomic64_add_return_unchecked - add and return
9680 + * @i: integer value to add
9681 + * @v: pointer to type atomic64_unchecked_t
9682 + *
9683 + * Atomically adds @i to @v and returns @i + *@v
9684 + */
9685 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9686 +{
9687 + alternative_atomic64(add_return_unchecked,
9688 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9689 + ASM_NO_INPUT_CLOBBER("memory"));
9690 + return i;
9691 +}
9692 +
9693 /*
9694 * Other variants with different arithmetic operators:
9695 */
9696 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9697 return a;
9698 }
9699
9700 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9701 +{
9702 + long long a;
9703 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9704 + "S" (v) : "memory", "ecx");
9705 + return a;
9706 +}
9707 +
9708 static inline long long atomic64_dec_return(atomic64_t *v)
9709 {
9710 long long a;
9711 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9712 }
9713
9714 /**
9715 + * atomic64_add_unchecked - add integer to atomic64 variable
9716 + * @i: integer value to add
9717 + * @v: pointer to type atomic64_unchecked_t
9718 + *
9719 + * Atomically adds @i to @v.
9720 + */
9721 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9722 +{
9723 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9724 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9725 + ASM_NO_INPUT_CLOBBER("memory"));
9726 + return i;
9727 +}
9728 +
9729 +/**
9730 * atomic64_sub - subtract the atomic64 variable
9731 * @i: integer value to subtract
9732 * @v: pointer to type atomic64_t
9733 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9734 index 0e1cbfc..5623683 100644
9735 --- a/arch/x86/include/asm/atomic64_64.h
9736 +++ b/arch/x86/include/asm/atomic64_64.h
9737 @@ -18,7 +18,19 @@
9738 */
9739 static inline long atomic64_read(const atomic64_t *v)
9740 {
9741 - return (*(volatile long *)&(v)->counter);
9742 + return (*(volatile const long *)&(v)->counter);
9743 +}
9744 +
9745 +/**
9746 + * atomic64_read_unchecked - read atomic64 variable
9747 + * @v: pointer of type atomic64_unchecked_t
9748 + *
9749 + * Atomically reads the value of @v.
9750 + * Doesn't imply a read memory barrier.
9751 + */
9752 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9753 +{
9754 + return (*(volatile const long *)&(v)->counter);
9755 }
9756
9757 /**
9758 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9759 }
9760
9761 /**
9762 + * atomic64_set_unchecked - set atomic64 variable
9763 + * @v: pointer to type atomic64_unchecked_t
9764 + * @i: required value
9765 + *
9766 + * Atomically sets the value of @v to @i.
9767 + */
9768 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9769 +{
9770 + v->counter = i;
9771 +}
9772 +
9773 +/**
9774 * atomic64_add - add integer to atomic64 variable
9775 * @i: integer value to add
9776 * @v: pointer to type atomic64_t
9777 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9778 */
9779 static inline void atomic64_add(long i, atomic64_t *v)
9780 {
9781 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9782 +
9783 +#ifdef CONFIG_PAX_REFCOUNT
9784 + "jno 0f\n"
9785 + LOCK_PREFIX "subq %1,%0\n"
9786 + "int $4\n0:\n"
9787 + _ASM_EXTABLE(0b, 0b)
9788 +#endif
9789 +
9790 + : "=m" (v->counter)
9791 + : "er" (i), "m" (v->counter));
9792 +}
9793 +
9794 +/**
9795 + * atomic64_add_unchecked - add integer to atomic64 variable
9796 + * @i: integer value to add
9797 + * @v: pointer to type atomic64_unchecked_t
9798 + *
9799 + * Atomically adds @i to @v.
9800 + */
9801 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9802 +{
9803 asm volatile(LOCK_PREFIX "addq %1,%0"
9804 : "=m" (v->counter)
9805 : "er" (i), "m" (v->counter));
9806 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9807 */
9808 static inline void atomic64_sub(long i, atomic64_t *v)
9809 {
9810 - asm volatile(LOCK_PREFIX "subq %1,%0"
9811 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9812 +
9813 +#ifdef CONFIG_PAX_REFCOUNT
9814 + "jno 0f\n"
9815 + LOCK_PREFIX "addq %1,%0\n"
9816 + "int $4\n0:\n"
9817 + _ASM_EXTABLE(0b, 0b)
9818 +#endif
9819 +
9820 + : "=m" (v->counter)
9821 + : "er" (i), "m" (v->counter));
9822 +}
9823 +
9824 +/**
9825 + * atomic64_sub_unchecked - subtract the atomic64 variable
9826 + * @i: integer value to subtract
9827 + * @v: pointer to type atomic64_unchecked_t
9828 + *
9829 + * Atomically subtracts @i from @v.
9830 + */
9831 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9832 +{
9833 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9834 : "=m" (v->counter)
9835 : "er" (i), "m" (v->counter));
9836 }
9837 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9838 {
9839 unsigned char c;
9840
9841 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9842 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + LOCK_PREFIX "addq %2,%0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + "sete %1\n"
9852 : "=m" (v->counter), "=qm" (c)
9853 : "er" (i), "m" (v->counter) : "memory");
9854 return c;
9855 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9856 */
9857 static inline void atomic64_inc(atomic64_t *v)
9858 {
9859 + asm volatile(LOCK_PREFIX "incq %0\n"
9860 +
9861 +#ifdef CONFIG_PAX_REFCOUNT
9862 + "jno 0f\n"
9863 + LOCK_PREFIX "decq %0\n"
9864 + "int $4\n0:\n"
9865 + _ASM_EXTABLE(0b, 0b)
9866 +#endif
9867 +
9868 + : "=m" (v->counter)
9869 + : "m" (v->counter));
9870 +}
9871 +
9872 +/**
9873 + * atomic64_inc_unchecked - increment atomic64 variable
9874 + * @v: pointer to type atomic64_unchecked_t
9875 + *
9876 + * Atomically increments @v by 1.
9877 + */
9878 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9879 +{
9880 asm volatile(LOCK_PREFIX "incq %0"
9881 : "=m" (v->counter)
9882 : "m" (v->counter));
9883 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9884 */
9885 static inline void atomic64_dec(atomic64_t *v)
9886 {
9887 - asm volatile(LOCK_PREFIX "decq %0"
9888 + asm volatile(LOCK_PREFIX "decq %0\n"
9889 +
9890 +#ifdef CONFIG_PAX_REFCOUNT
9891 + "jno 0f\n"
9892 + LOCK_PREFIX "incq %0\n"
9893 + "int $4\n0:\n"
9894 + _ASM_EXTABLE(0b, 0b)
9895 +#endif
9896 +
9897 + : "=m" (v->counter)
9898 + : "m" (v->counter));
9899 +}
9900 +
9901 +/**
9902 + * atomic64_dec_unchecked - decrement atomic64 variable
9903 + * @v: pointer to type atomic64_t
9904 + *
9905 + * Atomically decrements @v by 1.
9906 + */
9907 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9908 +{
9909 + asm volatile(LOCK_PREFIX "decq %0\n"
9910 : "=m" (v->counter)
9911 : "m" (v->counter));
9912 }
9913 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9914 {
9915 unsigned char c;
9916
9917 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9918 + asm volatile(LOCK_PREFIX "decq %0\n"
9919 +
9920 +#ifdef CONFIG_PAX_REFCOUNT
9921 + "jno 0f\n"
9922 + LOCK_PREFIX "incq %0\n"
9923 + "int $4\n0:\n"
9924 + _ASM_EXTABLE(0b, 0b)
9925 +#endif
9926 +
9927 + "sete %1\n"
9928 : "=m" (v->counter), "=qm" (c)
9929 : "m" (v->counter) : "memory");
9930 return c != 0;
9931 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9932 {
9933 unsigned char c;
9934
9935 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9936 + asm volatile(LOCK_PREFIX "incq %0\n"
9937 +
9938 +#ifdef CONFIG_PAX_REFCOUNT
9939 + "jno 0f\n"
9940 + LOCK_PREFIX "decq %0\n"
9941 + "int $4\n0:\n"
9942 + _ASM_EXTABLE(0b, 0b)
9943 +#endif
9944 +
9945 + "sete %1\n"
9946 : "=m" (v->counter), "=qm" (c)
9947 : "m" (v->counter) : "memory");
9948 return c != 0;
9949 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9950 {
9951 unsigned char c;
9952
9953 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9954 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9955 +
9956 +#ifdef CONFIG_PAX_REFCOUNT
9957 + "jno 0f\n"
9958 + LOCK_PREFIX "subq %2,%0\n"
9959 + "int $4\n0:\n"
9960 + _ASM_EXTABLE(0b, 0b)
9961 +#endif
9962 +
9963 + "sets %1\n"
9964 : "=m" (v->counter), "=qm" (c)
9965 : "er" (i), "m" (v->counter) : "memory");
9966 return c;
9967 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9968 */
9969 static inline long atomic64_add_return(long i, atomic64_t *v)
9970 {
9971 + return i + xadd_check_overflow(&v->counter, i);
9972 +}
9973 +
9974 +/**
9975 + * atomic64_add_return_unchecked - add and return
9976 + * @i: integer value to add
9977 + * @v: pointer to type atomic64_unchecked_t
9978 + *
9979 + * Atomically adds @i to @v and returns @i + @v
9980 + */
9981 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9982 +{
9983 return i + xadd(&v->counter, i);
9984 }
9985
9986 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9987 }
9988
9989 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9990 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9991 +{
9992 + return atomic64_add_return_unchecked(1, v);
9993 +}
9994 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9995
9996 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9997 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9998 return cmpxchg(&v->counter, old, new);
9999 }
10000
10001 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10002 +{
10003 + return cmpxchg(&v->counter, old, new);
10004 +}
10005 +
10006 static inline long atomic64_xchg(atomic64_t *v, long new)
10007 {
10008 return xchg(&v->counter, new);
10009 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10010 */
10011 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10012 {
10013 - long c, old;
10014 + long c, old, new;
10015 c = atomic64_read(v);
10016 for (;;) {
10017 - if (unlikely(c == (u)))
10018 + if (unlikely(c == u))
10019 break;
10020 - old = atomic64_cmpxchg((v), c, c + (a));
10021 +
10022 + asm volatile("add %2,%0\n"
10023 +
10024 +#ifdef CONFIG_PAX_REFCOUNT
10025 + "jno 0f\n"
10026 + "sub %2,%0\n"
10027 + "int $4\n0:\n"
10028 + _ASM_EXTABLE(0b, 0b)
10029 +#endif
10030 +
10031 + : "=r" (new)
10032 + : "0" (c), "ir" (a));
10033 +
10034 + old = atomic64_cmpxchg(v, c, new);
10035 if (likely(old == c))
10036 break;
10037 c = old;
10038 }
10039 - return c != (u);
10040 + return c != u;
10041 }
10042
10043 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10044 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10045 index a6983b2..63f48a2 100644
10046 --- a/arch/x86/include/asm/bitops.h
10047 +++ b/arch/x86/include/asm/bitops.h
10048 @@ -40,7 +40,7 @@
10049 * a mask operation on a byte.
10050 */
10051 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10052 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10053 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10054 #define CONST_MASK(nr) (1 << ((nr) & 7))
10055
10056 /**
10057 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10058 index b13fe63..0dab13a 100644
10059 --- a/arch/x86/include/asm/boot.h
10060 +++ b/arch/x86/include/asm/boot.h
10061 @@ -11,10 +11,15 @@
10062 #include <asm/pgtable_types.h>
10063
10064 /* Physical address where kernel should be loaded. */
10065 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10066 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10067 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10068 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10069
10070 +#ifndef __ASSEMBLY__
10071 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10072 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10073 +#endif
10074 +
10075 /* Minimum kernel alignment, as a power of two */
10076 #ifdef CONFIG_X86_64
10077 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10078 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10079 index 48f99f1..d78ebf9 100644
10080 --- a/arch/x86/include/asm/cache.h
10081 +++ b/arch/x86/include/asm/cache.h
10082 @@ -5,12 +5,13 @@
10083
10084 /* L1 cache line size */
10085 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10086 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10087 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10088
10089 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10090 +#define __read_only __attribute__((__section__(".data..read_only")))
10091
10092 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10093 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10094 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10095
10096 #ifdef CONFIG_X86_VSMP
10097 #ifdef CONFIG_SMP
10098 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10099 index 9863ee3..4a1f8e1 100644
10100 --- a/arch/x86/include/asm/cacheflush.h
10101 +++ b/arch/x86/include/asm/cacheflush.h
10102 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10103 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10104
10105 if (pg_flags == _PGMT_DEFAULT)
10106 - return -1;
10107 + return ~0UL;
10108 else if (pg_flags == _PGMT_WC)
10109 return _PAGE_CACHE_WC;
10110 else if (pg_flags == _PGMT_UC_MINUS)
10111 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10112 index 46fc474..b02b0f9 100644
10113 --- a/arch/x86/include/asm/checksum_32.h
10114 +++ b/arch/x86/include/asm/checksum_32.h
10115 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10116 int len, __wsum sum,
10117 int *src_err_ptr, int *dst_err_ptr);
10118
10119 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10120 + int len, __wsum sum,
10121 + int *src_err_ptr, int *dst_err_ptr);
10122 +
10123 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10124 + int len, __wsum sum,
10125 + int *src_err_ptr, int *dst_err_ptr);
10126 +
10127 /*
10128 * Note: when you get a NULL pointer exception here this means someone
10129 * passed in an incorrect kernel address to one of these functions.
10130 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10131 int *err_ptr)
10132 {
10133 might_sleep();
10134 - return csum_partial_copy_generic((__force void *)src, dst,
10135 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10136 len, sum, err_ptr, NULL);
10137 }
10138
10139 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10140 {
10141 might_sleep();
10142 if (access_ok(VERIFY_WRITE, dst, len))
10143 - return csum_partial_copy_generic(src, (__force void *)dst,
10144 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10145 len, sum, NULL, err_ptr);
10146
10147 if (len)
10148 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10149 index 99480e5..d81165b 100644
10150 --- a/arch/x86/include/asm/cmpxchg.h
10151 +++ b/arch/x86/include/asm/cmpxchg.h
10152 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10153 __compiletime_error("Bad argument size for cmpxchg");
10154 extern void __xadd_wrong_size(void)
10155 __compiletime_error("Bad argument size for xadd");
10156 +extern void __xadd_check_overflow_wrong_size(void)
10157 + __compiletime_error("Bad argument size for xadd_check_overflow");
10158 extern void __add_wrong_size(void)
10159 __compiletime_error("Bad argument size for add");
10160 +extern void __add_check_overflow_wrong_size(void)
10161 + __compiletime_error("Bad argument size for add_check_overflow");
10162
10163 /*
10164 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10165 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10166 __ret; \
10167 })
10168
10169 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10170 + ({ \
10171 + __typeof__ (*(ptr)) __ret = (arg); \
10172 + switch (sizeof(*(ptr))) { \
10173 + case __X86_CASE_L: \
10174 + asm volatile (lock #op "l %0, %1\n" \
10175 + "jno 0f\n" \
10176 + "mov %0,%1\n" \
10177 + "int $4\n0:\n" \
10178 + _ASM_EXTABLE(0b, 0b) \
10179 + : "+r" (__ret), "+m" (*(ptr)) \
10180 + : : "memory", "cc"); \
10181 + break; \
10182 + case __X86_CASE_Q: \
10183 + asm volatile (lock #op "q %q0, %1\n" \
10184 + "jno 0f\n" \
10185 + "mov %0,%1\n" \
10186 + "int $4\n0:\n" \
10187 + _ASM_EXTABLE(0b, 0b) \
10188 + : "+r" (__ret), "+m" (*(ptr)) \
10189 + : : "memory", "cc"); \
10190 + break; \
10191 + default: \
10192 + __ ## op ## _check_overflow_wrong_size(); \
10193 + } \
10194 + __ret; \
10195 + })
10196 +
10197 /*
10198 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10199 * Since this is generally used to protect other memory information, we
10200 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10201 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10202 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10203
10204 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10205 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10206 +
10207 #define __add(ptr, inc, lock) \
10208 ({ \
10209 __typeof__ (*(ptr)) __ret = (inc); \
10210 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10211 index f91e80f..7f9bd27 100644
10212 --- a/arch/x86/include/asm/cpufeature.h
10213 +++ b/arch/x86/include/asm/cpufeature.h
10214 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10215 ".section .discard,\"aw\",@progbits\n"
10216 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10217 ".previous\n"
10218 - ".section .altinstr_replacement,\"ax\"\n"
10219 + ".section .altinstr_replacement,\"a\"\n"
10220 "3: movb $1,%0\n"
10221 "4:\n"
10222 ".previous\n"
10223 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10224 index 8bf1c06..f723dfd 100644
10225 --- a/arch/x86/include/asm/desc.h
10226 +++ b/arch/x86/include/asm/desc.h
10227 @@ -4,6 +4,7 @@
10228 #include <asm/desc_defs.h>
10229 #include <asm/ldt.h>
10230 #include <asm/mmu.h>
10231 +#include <asm/pgtable.h>
10232
10233 #include <linux/smp.h>
10234 #include <linux/percpu.h>
10235 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10236
10237 desc->type = (info->read_exec_only ^ 1) << 1;
10238 desc->type |= info->contents << 2;
10239 + desc->type |= info->seg_not_present ^ 1;
10240
10241 desc->s = 1;
10242 desc->dpl = 0x3;
10243 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10244 }
10245
10246 extern struct desc_ptr idt_descr;
10247 -extern gate_desc idt_table[];
10248 extern struct desc_ptr nmi_idt_descr;
10249 -extern gate_desc nmi_idt_table[];
10250 -
10251 -struct gdt_page {
10252 - struct desc_struct gdt[GDT_ENTRIES];
10253 -} __attribute__((aligned(PAGE_SIZE)));
10254 -
10255 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10256 +extern gate_desc idt_table[256];
10257 +extern gate_desc nmi_idt_table[256];
10258
10259 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10260 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10261 {
10262 - return per_cpu(gdt_page, cpu).gdt;
10263 + return cpu_gdt_table[cpu];
10264 }
10265
10266 #ifdef CONFIG_X86_64
10267 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10268 unsigned long base, unsigned dpl, unsigned flags,
10269 unsigned short seg)
10270 {
10271 - gate->a = (seg << 16) | (base & 0xffff);
10272 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10273 + gate->gate.offset_low = base;
10274 + gate->gate.seg = seg;
10275 + gate->gate.reserved = 0;
10276 + gate->gate.type = type;
10277 + gate->gate.s = 0;
10278 + gate->gate.dpl = dpl;
10279 + gate->gate.p = 1;
10280 + gate->gate.offset_high = base >> 16;
10281 }
10282
10283 #endif
10284 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10285
10286 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10287 {
10288 + pax_open_kernel();
10289 memcpy(&idt[entry], gate, sizeof(*gate));
10290 + pax_close_kernel();
10291 }
10292
10293 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10294 {
10295 + pax_open_kernel();
10296 memcpy(&ldt[entry], desc, 8);
10297 + pax_close_kernel();
10298 }
10299
10300 static inline void
10301 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10302 default: size = sizeof(*gdt); break;
10303 }
10304
10305 + pax_open_kernel();
10306 memcpy(&gdt[entry], desc, size);
10307 + pax_close_kernel();
10308 }
10309
10310 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10311 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10312
10313 static inline void native_load_tr_desc(void)
10314 {
10315 + pax_open_kernel();
10316 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10317 + pax_close_kernel();
10318 }
10319
10320 static inline void native_load_gdt(const struct desc_ptr *dtr)
10321 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10322 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10323 unsigned int i;
10324
10325 + pax_open_kernel();
10326 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10327 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10328 + pax_close_kernel();
10329 }
10330
10331 #define _LDT_empty(info) \
10332 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10333 }
10334
10335 #ifdef CONFIG_X86_64
10336 -static inline void set_nmi_gate(int gate, void *addr)
10337 +static inline void set_nmi_gate(int gate, const void *addr)
10338 {
10339 gate_desc s;
10340
10341 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10342 }
10343 #endif
10344
10345 -static inline void _set_gate(int gate, unsigned type, void *addr,
10346 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10347 unsigned dpl, unsigned ist, unsigned seg)
10348 {
10349 gate_desc s;
10350 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10351 * Pentium F0 0F bugfix can have resulted in the mapped
10352 * IDT being write-protected.
10353 */
10354 -static inline void set_intr_gate(unsigned int n, void *addr)
10355 +static inline void set_intr_gate(unsigned int n, const void *addr)
10356 {
10357 BUG_ON((unsigned)n > 0xFF);
10358 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10359 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10360 /*
10361 * This routine sets up an interrupt gate at directory privilege level 3.
10362 */
10363 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10364 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10365 {
10366 BUG_ON((unsigned)n > 0xFF);
10367 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10368 }
10369
10370 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10371 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10372 {
10373 BUG_ON((unsigned)n > 0xFF);
10374 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10375 }
10376
10377 -static inline void set_trap_gate(unsigned int n, void *addr)
10378 +static inline void set_trap_gate(unsigned int n, const void *addr)
10379 {
10380 BUG_ON((unsigned)n > 0xFF);
10381 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10382 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10383 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10384 {
10385 BUG_ON((unsigned)n > 0xFF);
10386 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10387 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10388 }
10389
10390 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10391 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10392 {
10393 BUG_ON((unsigned)n > 0xFF);
10394 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10395 }
10396
10397 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10398 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10399 {
10400 BUG_ON((unsigned)n > 0xFF);
10401 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10402 }
10403
10404 +#ifdef CONFIG_X86_32
10405 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10406 +{
10407 + struct desc_struct d;
10408 +
10409 + if (likely(limit))
10410 + limit = (limit - 1UL) >> PAGE_SHIFT;
10411 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10412 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10413 +}
10414 +#endif
10415 +
10416 #endif /* _ASM_X86_DESC_H */
10417 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10418 index 278441f..b95a174 100644
10419 --- a/arch/x86/include/asm/desc_defs.h
10420 +++ b/arch/x86/include/asm/desc_defs.h
10421 @@ -31,6 +31,12 @@ struct desc_struct {
10422 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10423 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10424 };
10425 + struct {
10426 + u16 offset_low;
10427 + u16 seg;
10428 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10429 + unsigned offset_high: 16;
10430 + } gate;
10431 };
10432 } __attribute__((packed));
10433
10434 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10435 index 3778256..c5d4fce 100644
10436 --- a/arch/x86/include/asm/e820.h
10437 +++ b/arch/x86/include/asm/e820.h
10438 @@ -69,7 +69,7 @@ struct e820map {
10439 #define ISA_START_ADDRESS 0xa0000
10440 #define ISA_END_ADDRESS 0x100000
10441
10442 -#define BIOS_BEGIN 0x000a0000
10443 +#define BIOS_BEGIN 0x000c0000
10444 #define BIOS_END 0x00100000
10445
10446 #define BIOS_ROM_BASE 0xffe00000
10447 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10448 index 5939f44..f8845f6 100644
10449 --- a/arch/x86/include/asm/elf.h
10450 +++ b/arch/x86/include/asm/elf.h
10451 @@ -243,7 +243,25 @@ extern int force_personality32;
10452 the loader. We need to make sure that it is out of the way of the program
10453 that it will "exec", and that there is sufficient room for the brk. */
10454
10455 +#ifdef CONFIG_PAX_SEGMEXEC
10456 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10457 +#else
10458 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10459 +#endif
10460 +
10461 +#ifdef CONFIG_PAX_ASLR
10462 +#ifdef CONFIG_X86_32
10463 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10464 +
10465 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10466 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10467 +#else
10468 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10469 +
10470 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10471 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10472 +#endif
10473 +#endif
10474
10475 /* This yields a mask that user programs can use to figure out what
10476 instruction set this CPU supports. This could be done in user space,
10477 @@ -296,16 +314,12 @@ do { \
10478
10479 #define ARCH_DLINFO \
10480 do { \
10481 - if (vdso_enabled) \
10482 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10483 - (unsigned long)current->mm->context.vdso); \
10484 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10485 } while (0)
10486
10487 #define ARCH_DLINFO_X32 \
10488 do { \
10489 - if (vdso_enabled) \
10490 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10491 - (unsigned long)current->mm->context.vdso); \
10492 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10493 } while (0)
10494
10495 #define AT_SYSINFO 32
10496 @@ -320,7 +334,7 @@ else \
10497
10498 #endif /* !CONFIG_X86_32 */
10499
10500 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10501 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10502
10503 #define VDSO_ENTRY \
10504 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10505 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10506 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10507 #define compat_arch_setup_additional_pages syscall32_setup_pages
10508
10509 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10510 -#define arch_randomize_brk arch_randomize_brk
10511 -
10512 /*
10513 * True on X86_32 or when emulating IA32 on X86_64
10514 */
10515 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10516 index cc70c1c..d96d011 100644
10517 --- a/arch/x86/include/asm/emergency-restart.h
10518 +++ b/arch/x86/include/asm/emergency-restart.h
10519 @@ -15,6 +15,6 @@ enum reboot_type {
10520
10521 extern enum reboot_type reboot_type;
10522
10523 -extern void machine_emergency_restart(void);
10524 +extern void machine_emergency_restart(void) __noreturn;
10525
10526 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10527 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10528 index 75f4c6d..ee3eb8f 100644
10529 --- a/arch/x86/include/asm/fpu-internal.h
10530 +++ b/arch/x86/include/asm/fpu-internal.h
10531 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10532 {
10533 int err;
10534
10535 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10536 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10537 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10538 +#endif
10539 +
10540 /* See comment in fxsave() below. */
10541 #ifdef CONFIG_AS_FXSAVEQ
10542 asm volatile("1: fxrstorq %[fx]\n\t"
10543 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10544 {
10545 int err;
10546
10547 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10548 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10549 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10550 +#endif
10551 +
10552 /*
10553 * Clear the bytes not touched by the fxsave and reserved
10554 * for the SW usage.
10555 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10556 "emms\n\t" /* clear stack tags */
10557 "fildl %P[addr]", /* set F?P to defined value */
10558 X86_FEATURE_FXSAVE_LEAK,
10559 - [addr] "m" (tsk->thread.fpu.has_fpu));
10560 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10561
10562 return fpu_restore_checking(&tsk->thread.fpu);
10563 }
10564 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10565 index 71ecbcb..bac10b7 100644
10566 --- a/arch/x86/include/asm/futex.h
10567 +++ b/arch/x86/include/asm/futex.h
10568 @@ -11,16 +11,18 @@
10569 #include <asm/processor.h>
10570
10571 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10572 + typecheck(u32 __user *, uaddr); \
10573 asm volatile("1:\t" insn "\n" \
10574 "2:\t.section .fixup,\"ax\"\n" \
10575 "3:\tmov\t%3, %1\n" \
10576 "\tjmp\t2b\n" \
10577 "\t.previous\n" \
10578 _ASM_EXTABLE(1b, 3b) \
10579 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10580 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10581 : "i" (-EFAULT), "0" (oparg), "1" (0))
10582
10583 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10584 + typecheck(u32 __user *, uaddr); \
10585 asm volatile("1:\tmovl %2, %0\n" \
10586 "\tmovl\t%0, %3\n" \
10587 "\t" insn "\n" \
10588 @@ -33,7 +35,7 @@
10589 _ASM_EXTABLE(1b, 4b) \
10590 _ASM_EXTABLE(2b, 4b) \
10591 : "=&a" (oldval), "=&r" (ret), \
10592 - "+m" (*uaddr), "=&r" (tem) \
10593 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10594 : "r" (oparg), "i" (-EFAULT), "1" (0))
10595
10596 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10597 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10598
10599 switch (op) {
10600 case FUTEX_OP_SET:
10601 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10602 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10603 break;
10604 case FUTEX_OP_ADD:
10605 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10606 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10607 uaddr, oparg);
10608 break;
10609 case FUTEX_OP_OR:
10610 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10611 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10612 return -EFAULT;
10613
10614 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10615 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10616 "2:\t.section .fixup, \"ax\"\n"
10617 "3:\tmov %3, %0\n"
10618 "\tjmp 2b\n"
10619 "\t.previous\n"
10620 _ASM_EXTABLE(1b, 3b)
10621 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10622 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10623 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10624 : "memory"
10625 );
10626 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10627 index eb92a6e..b98b2f4 100644
10628 --- a/arch/x86/include/asm/hw_irq.h
10629 +++ b/arch/x86/include/asm/hw_irq.h
10630 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10631 extern void enable_IO_APIC(void);
10632
10633 /* Statistics */
10634 -extern atomic_t irq_err_count;
10635 -extern atomic_t irq_mis_count;
10636 +extern atomic_unchecked_t irq_err_count;
10637 +extern atomic_unchecked_t irq_mis_count;
10638
10639 /* EISA */
10640 extern void eisa_set_level_irq(unsigned int irq);
10641 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10642 index d8e8eef..99f81ae 100644
10643 --- a/arch/x86/include/asm/io.h
10644 +++ b/arch/x86/include/asm/io.h
10645 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10646
10647 #include <linux/vmalloc.h>
10648
10649 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10650 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10651 +{
10652 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10653 +}
10654 +
10655 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10656 +{
10657 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10658 +}
10659 +
10660 /*
10661 * Convert a virtual cached pointer to an uncached pointer
10662 */
10663 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10664 index bba3cf8..06bc8da 100644
10665 --- a/arch/x86/include/asm/irqflags.h
10666 +++ b/arch/x86/include/asm/irqflags.h
10667 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10668 sti; \
10669 sysexit
10670
10671 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10672 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10673 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10674 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10675 +
10676 #else
10677 #define INTERRUPT_RETURN iret
10678 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10679 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10680 index 5478825..839e88c 100644
10681 --- a/arch/x86/include/asm/kprobes.h
10682 +++ b/arch/x86/include/asm/kprobes.h
10683 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10684 #define RELATIVEJUMP_SIZE 5
10685 #define RELATIVECALL_OPCODE 0xe8
10686 #define RELATIVE_ADDR_SIZE 4
10687 -#define MAX_STACK_SIZE 64
10688 -#define MIN_STACK_SIZE(ADDR) \
10689 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10690 - THREAD_SIZE - (unsigned long)(ADDR))) \
10691 - ? (MAX_STACK_SIZE) \
10692 - : (((unsigned long)current_thread_info()) + \
10693 - THREAD_SIZE - (unsigned long)(ADDR)))
10694 +#define MAX_STACK_SIZE 64UL
10695 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10696
10697 #define flush_insn_slot(p) do { } while (0)
10698
10699 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10700 index db7c1f2..92f130a 100644
10701 --- a/arch/x86/include/asm/kvm_host.h
10702 +++ b/arch/x86/include/asm/kvm_host.h
10703 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10704 int (*check_intercept)(struct kvm_vcpu *vcpu,
10705 struct x86_instruction_info *info,
10706 enum x86_intercept_stage stage);
10707 -};
10708 +} __do_const;
10709
10710 struct kvm_arch_async_pf {
10711 u32 token;
10712 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10713 index c8bed0d..e5721fa 100644
10714 --- a/arch/x86/include/asm/local.h
10715 +++ b/arch/x86/include/asm/local.h
10716 @@ -17,26 +17,58 @@ typedef struct {
10717
10718 static inline void local_inc(local_t *l)
10719 {
10720 - asm volatile(_ASM_INC "%0"
10721 + asm volatile(_ASM_INC "%0\n"
10722 +
10723 +#ifdef CONFIG_PAX_REFCOUNT
10724 + "jno 0f\n"
10725 + _ASM_DEC "%0\n"
10726 + "int $4\n0:\n"
10727 + _ASM_EXTABLE(0b, 0b)
10728 +#endif
10729 +
10730 : "+m" (l->a.counter));
10731 }
10732
10733 static inline void local_dec(local_t *l)
10734 {
10735 - asm volatile(_ASM_DEC "%0"
10736 + asm volatile(_ASM_DEC "%0\n"
10737 +
10738 +#ifdef CONFIG_PAX_REFCOUNT
10739 + "jno 0f\n"
10740 + _ASM_INC "%0\n"
10741 + "int $4\n0:\n"
10742 + _ASM_EXTABLE(0b, 0b)
10743 +#endif
10744 +
10745 : "+m" (l->a.counter));
10746 }
10747
10748 static inline void local_add(long i, local_t *l)
10749 {
10750 - asm volatile(_ASM_ADD "%1,%0"
10751 + asm volatile(_ASM_ADD "%1,%0\n"
10752 +
10753 +#ifdef CONFIG_PAX_REFCOUNT
10754 + "jno 0f\n"
10755 + _ASM_SUB "%1,%0\n"
10756 + "int $4\n0:\n"
10757 + _ASM_EXTABLE(0b, 0b)
10758 +#endif
10759 +
10760 : "+m" (l->a.counter)
10761 : "ir" (i));
10762 }
10763
10764 static inline void local_sub(long i, local_t *l)
10765 {
10766 - asm volatile(_ASM_SUB "%1,%0"
10767 + asm volatile(_ASM_SUB "%1,%0\n"
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + "jno 0f\n"
10771 + _ASM_ADD "%1,%0\n"
10772 + "int $4\n0:\n"
10773 + _ASM_EXTABLE(0b, 0b)
10774 +#endif
10775 +
10776 : "+m" (l->a.counter)
10777 : "ir" (i));
10778 }
10779 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10780 {
10781 unsigned char c;
10782
10783 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10784 + asm volatile(_ASM_SUB "%2,%0\n"
10785 +
10786 +#ifdef CONFIG_PAX_REFCOUNT
10787 + "jno 0f\n"
10788 + _ASM_ADD "%2,%0\n"
10789 + "int $4\n0:\n"
10790 + _ASM_EXTABLE(0b, 0b)
10791 +#endif
10792 +
10793 + "sete %1\n"
10794 : "+m" (l->a.counter), "=qm" (c)
10795 : "ir" (i) : "memory");
10796 return c;
10797 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10798 {
10799 unsigned char c;
10800
10801 - asm volatile(_ASM_DEC "%0; sete %1"
10802 + asm volatile(_ASM_DEC "%0\n"
10803 +
10804 +#ifdef CONFIG_PAX_REFCOUNT
10805 + "jno 0f\n"
10806 + _ASM_INC "%0\n"
10807 + "int $4\n0:\n"
10808 + _ASM_EXTABLE(0b, 0b)
10809 +#endif
10810 +
10811 + "sete %1\n"
10812 : "+m" (l->a.counter), "=qm" (c)
10813 : : "memory");
10814 return c != 0;
10815 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10816 {
10817 unsigned char c;
10818
10819 - asm volatile(_ASM_INC "%0; sete %1"
10820 + asm volatile(_ASM_INC "%0\n"
10821 +
10822 +#ifdef CONFIG_PAX_REFCOUNT
10823 + "jno 0f\n"
10824 + _ASM_DEC "%0\n"
10825 + "int $4\n0:\n"
10826 + _ASM_EXTABLE(0b, 0b)
10827 +#endif
10828 +
10829 + "sete %1\n"
10830 : "+m" (l->a.counter), "=qm" (c)
10831 : : "memory");
10832 return c != 0;
10833 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10834 {
10835 unsigned char c;
10836
10837 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10838 + asm volatile(_ASM_ADD "%2,%0\n"
10839 +
10840 +#ifdef CONFIG_PAX_REFCOUNT
10841 + "jno 0f\n"
10842 + _ASM_SUB "%2,%0\n"
10843 + "int $4\n0:\n"
10844 + _ASM_EXTABLE(0b, 0b)
10845 +#endif
10846 +
10847 + "sets %1\n"
10848 : "+m" (l->a.counter), "=qm" (c)
10849 : "ir" (i) : "memory");
10850 return c;
10851 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10852 #endif
10853 /* Modern 486+ processor */
10854 __i = i;
10855 - asm volatile(_ASM_XADD "%0, %1;"
10856 + asm volatile(_ASM_XADD "%0, %1\n"
10857 +
10858 +#ifdef CONFIG_PAX_REFCOUNT
10859 + "jno 0f\n"
10860 + _ASM_MOV "%0,%1\n"
10861 + "int $4\n0:\n"
10862 + _ASM_EXTABLE(0b, 0b)
10863 +#endif
10864 +
10865 : "+r" (i), "+m" (l->a.counter)
10866 : : "memory");
10867 return i + __i;
10868 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10869 index 593e51d..fa69c9a 100644
10870 --- a/arch/x86/include/asm/mman.h
10871 +++ b/arch/x86/include/asm/mman.h
10872 @@ -5,4 +5,14 @@
10873
10874 #include <asm-generic/mman.h>
10875
10876 +#ifdef __KERNEL__
10877 +#ifndef __ASSEMBLY__
10878 +#ifdef CONFIG_X86_32
10879 +#define arch_mmap_check i386_mmap_check
10880 +int i386_mmap_check(unsigned long addr, unsigned long len,
10881 + unsigned long flags);
10882 +#endif
10883 +#endif
10884 +#endif
10885 +
10886 #endif /* _ASM_X86_MMAN_H */
10887 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10888 index 5f55e69..e20bfb1 100644
10889 --- a/arch/x86/include/asm/mmu.h
10890 +++ b/arch/x86/include/asm/mmu.h
10891 @@ -9,7 +9,7 @@
10892 * we put the segment information here.
10893 */
10894 typedef struct {
10895 - void *ldt;
10896 + struct desc_struct *ldt;
10897 int size;
10898
10899 #ifdef CONFIG_X86_64
10900 @@ -18,7 +18,19 @@ typedef struct {
10901 #endif
10902
10903 struct mutex lock;
10904 - void *vdso;
10905 + unsigned long vdso;
10906 +
10907 +#ifdef CONFIG_X86_32
10908 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10909 + unsigned long user_cs_base;
10910 + unsigned long user_cs_limit;
10911 +
10912 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10913 + cpumask_t cpu_user_cs_mask;
10914 +#endif
10915 +
10916 +#endif
10917 +#endif
10918 } mm_context_t;
10919
10920 #ifdef CONFIG_SMP
10921 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10922 index cdbf367..adb37ac 100644
10923 --- a/arch/x86/include/asm/mmu_context.h
10924 +++ b/arch/x86/include/asm/mmu_context.h
10925 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10926
10927 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10928 {
10929 +
10930 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10931 + unsigned int i;
10932 + pgd_t *pgd;
10933 +
10934 + pax_open_kernel();
10935 + pgd = get_cpu_pgd(smp_processor_id());
10936 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10937 + set_pgd_batched(pgd+i, native_make_pgd(0));
10938 + pax_close_kernel();
10939 +#endif
10940 +
10941 #ifdef CONFIG_SMP
10942 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10943 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10944 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10945 struct task_struct *tsk)
10946 {
10947 unsigned cpu = smp_processor_id();
10948 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10949 + int tlbstate = TLBSTATE_OK;
10950 +#endif
10951
10952 if (likely(prev != next)) {
10953 #ifdef CONFIG_SMP
10954 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10955 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10956 +#endif
10957 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10958 this_cpu_write(cpu_tlbstate.active_mm, next);
10959 #endif
10960 cpumask_set_cpu(cpu, mm_cpumask(next));
10961
10962 /* Re-load page tables */
10963 +#ifdef CONFIG_PAX_PER_CPU_PGD
10964 + pax_open_kernel();
10965 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10966 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10967 + pax_close_kernel();
10968 + load_cr3(get_cpu_pgd(cpu));
10969 +#else
10970 load_cr3(next->pgd);
10971 +#endif
10972
10973 /* stop flush ipis for the previous mm */
10974 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10975 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10976 */
10977 if (unlikely(prev->context.ldt != next->context.ldt))
10978 load_LDT_nolock(&next->context);
10979 - }
10980 +
10981 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10982 + if (!(__supported_pte_mask & _PAGE_NX)) {
10983 + smp_mb__before_clear_bit();
10984 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10985 + smp_mb__after_clear_bit();
10986 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10987 + }
10988 +#endif
10989 +
10990 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10991 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10992 + prev->context.user_cs_limit != next->context.user_cs_limit))
10993 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10994 #ifdef CONFIG_SMP
10995 + else if (unlikely(tlbstate != TLBSTATE_OK))
10996 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10997 +#endif
10998 +#endif
10999 +
11000 + }
11001 else {
11002 +
11003 +#ifdef CONFIG_PAX_PER_CPU_PGD
11004 + pax_open_kernel();
11005 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11006 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11007 + pax_close_kernel();
11008 + load_cr3(get_cpu_pgd(cpu));
11009 +#endif
11010 +
11011 +#ifdef CONFIG_SMP
11012 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11013 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11014
11015 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11016 * tlb flush IPI delivery. We must reload CR3
11017 * to make sure to use no freed page tables.
11018 */
11019 +
11020 +#ifndef CONFIG_PAX_PER_CPU_PGD
11021 load_cr3(next->pgd);
11022 +#endif
11023 +
11024 load_LDT_nolock(&next->context);
11025 +
11026 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11027 + if (!(__supported_pte_mask & _PAGE_NX))
11028 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11029 +#endif
11030 +
11031 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11032 +#ifdef CONFIG_PAX_PAGEEXEC
11033 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11034 +#endif
11035 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11036 +#endif
11037 +
11038 }
11039 +#endif
11040 }
11041 -#endif
11042 }
11043
11044 #define activate_mm(prev, next) \
11045 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11046 index 9eae775..c914fea 100644
11047 --- a/arch/x86/include/asm/module.h
11048 +++ b/arch/x86/include/asm/module.h
11049 @@ -5,6 +5,7 @@
11050
11051 #ifdef CONFIG_X86_64
11052 /* X86_64 does not define MODULE_PROC_FAMILY */
11053 +#define MODULE_PROC_FAMILY ""
11054 #elif defined CONFIG_M386
11055 #define MODULE_PROC_FAMILY "386 "
11056 #elif defined CONFIG_M486
11057 @@ -59,8 +60,20 @@
11058 #error unknown processor family
11059 #endif
11060
11061 -#ifdef CONFIG_X86_32
11062 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11063 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11064 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11065 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11066 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11067 +#else
11068 +#define MODULE_PAX_KERNEXEC ""
11069 #endif
11070
11071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11072 +#define MODULE_PAX_UDEREF "UDEREF "
11073 +#else
11074 +#define MODULE_PAX_UDEREF ""
11075 +#endif
11076 +
11077 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11078 +
11079 #endif /* _ASM_X86_MODULE_H */
11080 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11081 index 320f7bb..e89f8f8 100644
11082 --- a/arch/x86/include/asm/page_64_types.h
11083 +++ b/arch/x86/include/asm/page_64_types.h
11084 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11085
11086 /* duplicated to the one in bootmem.h */
11087 extern unsigned long max_pfn;
11088 -extern unsigned long phys_base;
11089 +extern const unsigned long phys_base;
11090
11091 extern unsigned long __phys_addr(unsigned long);
11092 #define __phys_reloc_hide(x) (x)
11093 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11094 index 6cbbabf..11b3aed 100644
11095 --- a/arch/x86/include/asm/paravirt.h
11096 +++ b/arch/x86/include/asm/paravirt.h
11097 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11098 val);
11099 }
11100
11101 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11102 +{
11103 + pgdval_t val = native_pgd_val(pgd);
11104 +
11105 + if (sizeof(pgdval_t) > sizeof(long))
11106 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11107 + val, (u64)val >> 32);
11108 + else
11109 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11110 + val);
11111 +}
11112 +
11113 static inline void pgd_clear(pgd_t *pgdp)
11114 {
11115 set_pgd(pgdp, __pgd(0));
11116 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11117 pv_mmu_ops.set_fixmap(idx, phys, flags);
11118 }
11119
11120 +#ifdef CONFIG_PAX_KERNEXEC
11121 +static inline unsigned long pax_open_kernel(void)
11122 +{
11123 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11124 +}
11125 +
11126 +static inline unsigned long pax_close_kernel(void)
11127 +{
11128 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11129 +}
11130 +#else
11131 +static inline unsigned long pax_open_kernel(void) { return 0; }
11132 +static inline unsigned long pax_close_kernel(void) { return 0; }
11133 +#endif
11134 +
11135 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11136
11137 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11138 @@ -965,7 +992,7 @@ extern void default_banner(void);
11139
11140 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11141 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11142 -#define PARA_INDIRECT(addr) *%cs:addr
11143 +#define PARA_INDIRECT(addr) *%ss:addr
11144 #endif
11145
11146 #define INTERRUPT_RETURN \
11147 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11148 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11149 CLBR_NONE, \
11150 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11151 +
11152 +#define GET_CR0_INTO_RDI \
11153 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11154 + mov %rax,%rdi
11155 +
11156 +#define SET_RDI_INTO_CR0 \
11157 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11158 +
11159 +#define GET_CR3_INTO_RDI \
11160 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11161 + mov %rax,%rdi
11162 +
11163 +#define SET_RDI_INTO_CR3 \
11164 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11165 +
11166 #endif /* CONFIG_X86_32 */
11167
11168 #endif /* __ASSEMBLY__ */
11169 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11170 index 8e8b9a4..f07d725 100644
11171 --- a/arch/x86/include/asm/paravirt_types.h
11172 +++ b/arch/x86/include/asm/paravirt_types.h
11173 @@ -84,20 +84,20 @@ struct pv_init_ops {
11174 */
11175 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11176 unsigned long addr, unsigned len);
11177 -};
11178 +} __no_const;
11179
11180
11181 struct pv_lazy_ops {
11182 /* Set deferred update mode, used for batching operations. */
11183 void (*enter)(void);
11184 void (*leave)(void);
11185 -};
11186 +} __no_const;
11187
11188 struct pv_time_ops {
11189 unsigned long long (*sched_clock)(void);
11190 unsigned long long (*steal_clock)(int cpu);
11191 unsigned long (*get_tsc_khz)(void);
11192 -};
11193 +} __no_const;
11194
11195 struct pv_cpu_ops {
11196 /* hooks for various privileged instructions */
11197 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11198
11199 void (*start_context_switch)(struct task_struct *prev);
11200 void (*end_context_switch)(struct task_struct *next);
11201 -};
11202 +} __no_const;
11203
11204 struct pv_irq_ops {
11205 /*
11206 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11207 unsigned long start_eip,
11208 unsigned long start_esp);
11209 #endif
11210 -};
11211 +} __no_const;
11212
11213 struct pv_mmu_ops {
11214 unsigned long (*read_cr2)(void);
11215 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11216 struct paravirt_callee_save make_pud;
11217
11218 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11219 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11220 #endif /* PAGETABLE_LEVELS == 4 */
11221 #endif /* PAGETABLE_LEVELS >= 3 */
11222
11223 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11224 an mfn. We can tell which is which from the index. */
11225 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11226 phys_addr_t phys, pgprot_t flags);
11227 +
11228 +#ifdef CONFIG_PAX_KERNEXEC
11229 + unsigned long (*pax_open_kernel)(void);
11230 + unsigned long (*pax_close_kernel)(void);
11231 +#endif
11232 +
11233 };
11234
11235 struct arch_spinlock;
11236 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11237 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11238 int (*spin_trylock)(struct arch_spinlock *lock);
11239 void (*spin_unlock)(struct arch_spinlock *lock);
11240 -};
11241 +} __no_const;
11242
11243 /* This contains all the paravirt structures: we get a convenient
11244 * number for each function using the offset which we use to indicate
11245 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11246 index b4389a4..7024269 100644
11247 --- a/arch/x86/include/asm/pgalloc.h
11248 +++ b/arch/x86/include/asm/pgalloc.h
11249 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11250 pmd_t *pmd, pte_t *pte)
11251 {
11252 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11253 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11254 +}
11255 +
11256 +static inline void pmd_populate_user(struct mm_struct *mm,
11257 + pmd_t *pmd, pte_t *pte)
11258 +{
11259 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11260 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11261 }
11262
11263 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11264
11265 #ifdef CONFIG_X86_PAE
11266 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11267 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11268 +{
11269 + pud_populate(mm, pudp, pmd);
11270 +}
11271 #else /* !CONFIG_X86_PAE */
11272 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11273 {
11274 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11275 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11276 }
11277 +
11278 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11279 +{
11280 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11281 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11282 +}
11283 #endif /* CONFIG_X86_PAE */
11284
11285 #if PAGETABLE_LEVELS > 3
11286 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11287 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11288 }
11289
11290 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11291 +{
11292 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11293 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11294 +}
11295 +
11296 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11297 {
11298 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11299 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11300 index 98391db..8f6984e 100644
11301 --- a/arch/x86/include/asm/pgtable-2level.h
11302 +++ b/arch/x86/include/asm/pgtable-2level.h
11303 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11304
11305 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11306 {
11307 + pax_open_kernel();
11308 *pmdp = pmd;
11309 + pax_close_kernel();
11310 }
11311
11312 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11313 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11314 index cb00ccc..17e9054 100644
11315 --- a/arch/x86/include/asm/pgtable-3level.h
11316 +++ b/arch/x86/include/asm/pgtable-3level.h
11317 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11318
11319 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11320 {
11321 + pax_open_kernel();
11322 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11323 + pax_close_kernel();
11324 }
11325
11326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11327 {
11328 + pax_open_kernel();
11329 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11330 + pax_close_kernel();
11331 }
11332
11333 /*
11334 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11335 index 49afb3f..91a8c63 100644
11336 --- a/arch/x86/include/asm/pgtable.h
11337 +++ b/arch/x86/include/asm/pgtable.h
11338 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11339
11340 #ifndef __PAGETABLE_PUD_FOLDED
11341 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11342 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11343 #define pgd_clear(pgd) native_pgd_clear(pgd)
11344 #endif
11345
11346 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11347
11348 #define arch_end_context_switch(prev) do {} while(0)
11349
11350 +#define pax_open_kernel() native_pax_open_kernel()
11351 +#define pax_close_kernel() native_pax_close_kernel()
11352 #endif /* CONFIG_PARAVIRT */
11353
11354 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11355 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11356 +
11357 +#ifdef CONFIG_PAX_KERNEXEC
11358 +static inline unsigned long native_pax_open_kernel(void)
11359 +{
11360 + unsigned long cr0;
11361 +
11362 + preempt_disable();
11363 + barrier();
11364 + cr0 = read_cr0() ^ X86_CR0_WP;
11365 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11366 + write_cr0(cr0);
11367 + return cr0 ^ X86_CR0_WP;
11368 +}
11369 +
11370 +static inline unsigned long native_pax_close_kernel(void)
11371 +{
11372 + unsigned long cr0;
11373 +
11374 + cr0 = read_cr0() ^ X86_CR0_WP;
11375 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11376 + write_cr0(cr0);
11377 + barrier();
11378 + preempt_enable_no_resched();
11379 + return cr0 ^ X86_CR0_WP;
11380 +}
11381 +#else
11382 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11383 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11384 +#endif
11385 +
11386 /*
11387 * The following only work if pte_present() is true.
11388 * Undefined behaviour if not..
11389 */
11390 +static inline int pte_user(pte_t pte)
11391 +{
11392 + return pte_val(pte) & _PAGE_USER;
11393 +}
11394 +
11395 static inline int pte_dirty(pte_t pte)
11396 {
11397 return pte_flags(pte) & _PAGE_DIRTY;
11398 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11399 return pte_clear_flags(pte, _PAGE_RW);
11400 }
11401
11402 +static inline pte_t pte_mkread(pte_t pte)
11403 +{
11404 + return __pte(pte_val(pte) | _PAGE_USER);
11405 +}
11406 +
11407 static inline pte_t pte_mkexec(pte_t pte)
11408 {
11409 - return pte_clear_flags(pte, _PAGE_NX);
11410 +#ifdef CONFIG_X86_PAE
11411 + if (__supported_pte_mask & _PAGE_NX)
11412 + return pte_clear_flags(pte, _PAGE_NX);
11413 + else
11414 +#endif
11415 + return pte_set_flags(pte, _PAGE_USER);
11416 +}
11417 +
11418 +static inline pte_t pte_exprotect(pte_t pte)
11419 +{
11420 +#ifdef CONFIG_X86_PAE
11421 + if (__supported_pte_mask & _PAGE_NX)
11422 + return pte_set_flags(pte, _PAGE_NX);
11423 + else
11424 +#endif
11425 + return pte_clear_flags(pte, _PAGE_USER);
11426 }
11427
11428 static inline pte_t pte_mkdirty(pte_t pte)
11429 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11430 #endif
11431
11432 #ifndef __ASSEMBLY__
11433 +
11434 +#ifdef CONFIG_PAX_PER_CPU_PGD
11435 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11436 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11437 +{
11438 + return cpu_pgd[cpu];
11439 +}
11440 +#endif
11441 +
11442 #include <linux/mm_types.h>
11443
11444 static inline int pte_none(pte_t pte)
11445 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11446
11447 static inline int pgd_bad(pgd_t pgd)
11448 {
11449 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11450 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11451 }
11452
11453 static inline int pgd_none(pgd_t pgd)
11454 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11455 * pgd_offset() returns a (pgd_t *)
11456 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11457 */
11458 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11459 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11460 +
11461 +#ifdef CONFIG_PAX_PER_CPU_PGD
11462 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11463 +#endif
11464 +
11465 /*
11466 * a shortcut which implies the use of the kernel's pgd, instead
11467 * of a process's
11468 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11469 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11470 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11471
11472 +#ifdef CONFIG_X86_32
11473 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11474 +#else
11475 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11476 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11477 +
11478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11479 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11480 +#else
11481 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11482 +#endif
11483 +
11484 +#endif
11485 +
11486 #ifndef __ASSEMBLY__
11487
11488 extern int direct_gbpages;
11489 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11490 * dst and src can be on the same page, but the range must not overlap,
11491 * and must not cross a page boundary.
11492 */
11493 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11494 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11495 {
11496 - memcpy(dst, src, count * sizeof(pgd_t));
11497 + pax_open_kernel();
11498 + while (count--)
11499 + *dst++ = *src++;
11500 + pax_close_kernel();
11501 }
11502
11503 +#ifdef CONFIG_PAX_PER_CPU_PGD
11504 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11505 +#endif
11506 +
11507 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11508 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11509 +#else
11510 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11511 +#endif
11512
11513 #include <asm-generic/pgtable.h>
11514 #endif /* __ASSEMBLY__ */
11515 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11516 index 0c92113..34a77c6 100644
11517 --- a/arch/x86/include/asm/pgtable_32.h
11518 +++ b/arch/x86/include/asm/pgtable_32.h
11519 @@ -25,9 +25,6 @@
11520 struct mm_struct;
11521 struct vm_area_struct;
11522
11523 -extern pgd_t swapper_pg_dir[1024];
11524 -extern pgd_t initial_page_table[1024];
11525 -
11526 static inline void pgtable_cache_init(void) { }
11527 static inline void check_pgt_cache(void) { }
11528 void paging_init(void);
11529 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11530 # include <asm/pgtable-2level.h>
11531 #endif
11532
11533 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11534 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11535 +#ifdef CONFIG_X86_PAE
11536 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11537 +#endif
11538 +
11539 #if defined(CONFIG_HIGHPTE)
11540 #define pte_offset_map(dir, address) \
11541 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11542 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11543 /* Clear a kernel PTE and flush it from the TLB */
11544 #define kpte_clear_flush(ptep, vaddr) \
11545 do { \
11546 + pax_open_kernel(); \
11547 pte_clear(&init_mm, (vaddr), (ptep)); \
11548 + pax_close_kernel(); \
11549 __flush_tlb_one((vaddr)); \
11550 } while (0)
11551
11552 @@ -74,6 +79,9 @@ do { \
11553
11554 #endif /* !__ASSEMBLY__ */
11555
11556 +#define HAVE_ARCH_UNMAPPED_AREA
11557 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11558 +
11559 /*
11560 * kern_addr_valid() is (1) for FLATMEM and (0) for
11561 * SPARSEMEM and DISCONTIGMEM
11562 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11563 index ed5903b..c7fe163 100644
11564 --- a/arch/x86/include/asm/pgtable_32_types.h
11565 +++ b/arch/x86/include/asm/pgtable_32_types.h
11566 @@ -8,7 +8,7 @@
11567 */
11568 #ifdef CONFIG_X86_PAE
11569 # include <asm/pgtable-3level_types.h>
11570 -# define PMD_SIZE (1UL << PMD_SHIFT)
11571 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11572 # define PMD_MASK (~(PMD_SIZE - 1))
11573 #else
11574 # include <asm/pgtable-2level_types.h>
11575 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11576 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11577 #endif
11578
11579 +#ifdef CONFIG_PAX_KERNEXEC
11580 +#ifndef __ASSEMBLY__
11581 +extern unsigned char MODULES_EXEC_VADDR[];
11582 +extern unsigned char MODULES_EXEC_END[];
11583 +#endif
11584 +#include <asm/boot.h>
11585 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11586 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11587 +#else
11588 +#define ktla_ktva(addr) (addr)
11589 +#define ktva_ktla(addr) (addr)
11590 +#endif
11591 +
11592 #define MODULES_VADDR VMALLOC_START
11593 #define MODULES_END VMALLOC_END
11594 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11595 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11596 index 975f709..9f779c9 100644
11597 --- a/arch/x86/include/asm/pgtable_64.h
11598 +++ b/arch/x86/include/asm/pgtable_64.h
11599 @@ -16,10 +16,14 @@
11600
11601 extern pud_t level3_kernel_pgt[512];
11602 extern pud_t level3_ident_pgt[512];
11603 +extern pud_t level3_vmalloc_start_pgt[512];
11604 +extern pud_t level3_vmalloc_end_pgt[512];
11605 +extern pud_t level3_vmemmap_pgt[512];
11606 +extern pud_t level2_vmemmap_pgt[512];
11607 extern pmd_t level2_kernel_pgt[512];
11608 extern pmd_t level2_fixmap_pgt[512];
11609 -extern pmd_t level2_ident_pgt[512];
11610 -extern pgd_t init_level4_pgt[];
11611 +extern pmd_t level2_ident_pgt[512*2];
11612 +extern pgd_t init_level4_pgt[512];
11613
11614 #define swapper_pg_dir init_level4_pgt
11615
11616 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11617
11618 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11619 {
11620 + pax_open_kernel();
11621 *pmdp = pmd;
11622 + pax_close_kernel();
11623 }
11624
11625 static inline void native_pmd_clear(pmd_t *pmd)
11626 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11627
11628 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11629 {
11630 + pax_open_kernel();
11631 *pudp = pud;
11632 + pax_close_kernel();
11633 }
11634
11635 static inline void native_pud_clear(pud_t *pud)
11636 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11637
11638 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11639 {
11640 + pax_open_kernel();
11641 + *pgdp = pgd;
11642 + pax_close_kernel();
11643 +}
11644 +
11645 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11646 +{
11647 *pgdp = pgd;
11648 }
11649
11650 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11651 index 766ea16..5b96cb3 100644
11652 --- a/arch/x86/include/asm/pgtable_64_types.h
11653 +++ b/arch/x86/include/asm/pgtable_64_types.h
11654 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11655 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11656 #define MODULES_END _AC(0xffffffffff000000, UL)
11657 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11658 +#define MODULES_EXEC_VADDR MODULES_VADDR
11659 +#define MODULES_EXEC_END MODULES_END
11660 +
11661 +#define ktla_ktva(addr) (addr)
11662 +#define ktva_ktla(addr) (addr)
11663
11664 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11665 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11666 index 013286a..8b42f4f 100644
11667 --- a/arch/x86/include/asm/pgtable_types.h
11668 +++ b/arch/x86/include/asm/pgtable_types.h
11669 @@ -16,13 +16,12 @@
11670 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11671 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11672 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11673 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11674 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11675 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11676 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11677 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11678 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11679 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11680 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11681 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11682 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11683 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11684
11685 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11686 @@ -40,7 +39,6 @@
11687 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11688 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11689 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11690 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11691 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11692 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11693 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11694 @@ -57,8 +55,10 @@
11695
11696 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11697 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11698 -#else
11699 +#elif defined(CONFIG_KMEMCHECK)
11700 #define _PAGE_NX (_AT(pteval_t, 0))
11701 +#else
11702 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11703 #endif
11704
11705 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11706 @@ -96,6 +96,9 @@
11707 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11708 _PAGE_ACCESSED)
11709
11710 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11711 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11712 +
11713 #define __PAGE_KERNEL_EXEC \
11714 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11715 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11716 @@ -106,7 +109,7 @@
11717 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11718 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11719 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11720 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11721 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11722 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11723 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11724 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11725 @@ -168,8 +171,8 @@
11726 * bits are combined, this will alow user to access the high address mapped
11727 * VDSO in the presence of CONFIG_COMPAT_VDSO
11728 */
11729 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11730 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11731 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11732 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11733 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11734 #endif
11735
11736 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11737 {
11738 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11739 }
11740 +#endif
11741
11742 +#if PAGETABLE_LEVELS == 3
11743 +#include <asm-generic/pgtable-nopud.h>
11744 +#endif
11745 +
11746 +#if PAGETABLE_LEVELS == 2
11747 +#include <asm-generic/pgtable-nopmd.h>
11748 +#endif
11749 +
11750 +#ifndef __ASSEMBLY__
11751 #if PAGETABLE_LEVELS > 3
11752 typedef struct { pudval_t pud; } pud_t;
11753
11754 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11755 return pud.pud;
11756 }
11757 #else
11758 -#include <asm-generic/pgtable-nopud.h>
11759 -
11760 static inline pudval_t native_pud_val(pud_t pud)
11761 {
11762 return native_pgd_val(pud.pgd);
11763 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11764 return pmd.pmd;
11765 }
11766 #else
11767 -#include <asm-generic/pgtable-nopmd.h>
11768 -
11769 static inline pmdval_t native_pmd_val(pmd_t pmd)
11770 {
11771 return native_pgd_val(pmd.pud.pgd);
11772 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11773
11774 extern pteval_t __supported_pte_mask;
11775 extern void set_nx(void);
11776 -extern int nx_enabled;
11777
11778 #define pgprot_writecombine pgprot_writecombine
11779 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11780 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11781 index 39bc577..538233f 100644
11782 --- a/arch/x86/include/asm/processor.h
11783 +++ b/arch/x86/include/asm/processor.h
11784 @@ -276,7 +276,7 @@ struct tss_struct {
11785
11786 } ____cacheline_aligned;
11787
11788 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11789 +extern struct tss_struct init_tss[NR_CPUS];
11790
11791 /*
11792 * Save the original ist values for checking stack pointers during debugging
11793 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11794 */
11795 #define TASK_SIZE PAGE_OFFSET
11796 #define TASK_SIZE_MAX TASK_SIZE
11797 +
11798 +#ifdef CONFIG_PAX_SEGMEXEC
11799 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11800 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11801 +#else
11802 #define STACK_TOP TASK_SIZE
11803 -#define STACK_TOP_MAX STACK_TOP
11804 +#endif
11805 +
11806 +#define STACK_TOP_MAX TASK_SIZE
11807
11808 #define INIT_THREAD { \
11809 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11810 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11811 .vm86_info = NULL, \
11812 .sysenter_cs = __KERNEL_CS, \
11813 .io_bitmap_ptr = NULL, \
11814 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11815 */
11816 #define INIT_TSS { \
11817 .x86_tss = { \
11818 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11819 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11820 .ss0 = __KERNEL_DS, \
11821 .ss1 = __KERNEL_CS, \
11822 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11823 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11824 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11825
11826 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11827 -#define KSTK_TOP(info) \
11828 -({ \
11829 - unsigned long *__ptr = (unsigned long *)(info); \
11830 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11831 -})
11832 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11833
11834 /*
11835 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11836 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11837 #define task_pt_regs(task) \
11838 ({ \
11839 struct pt_regs *__regs__; \
11840 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11841 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11842 __regs__ - 1; \
11843 })
11844
11845 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11846 /*
11847 * User space process size. 47bits minus one guard page.
11848 */
11849 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11850 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11851
11852 /* This decides where the kernel will search for a free chunk of vm
11853 * space during mmap's.
11854 */
11855 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11856 - 0xc0000000 : 0xFFFFe000)
11857 + 0xc0000000 : 0xFFFFf000)
11858
11859 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11860 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11861 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11862 #define STACK_TOP_MAX TASK_SIZE_MAX
11863
11864 #define INIT_THREAD { \
11865 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11866 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11867 }
11868
11869 #define INIT_TSS { \
11870 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11871 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11872 }
11873
11874 /*
11875 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11876 */
11877 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11878
11879 +#ifdef CONFIG_PAX_SEGMEXEC
11880 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11881 +#endif
11882 +
11883 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11884
11885 /* Get/set a process' ability to use the timestamp counter instruction */
11886 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11887 #define cpu_has_amd_erratum(x) (false)
11888 #endif /* CONFIG_CPU_SUP_AMD */
11889
11890 -extern unsigned long arch_align_stack(unsigned long sp);
11891 +#define arch_align_stack(x) ((x) & ~0xfUL)
11892 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11893
11894 void default_idle(void);
11895 bool set_pm_idle_to_default(void);
11896
11897 -void stop_this_cpu(void *dummy);
11898 +void stop_this_cpu(void *dummy) __noreturn;
11899
11900 #endif /* _ASM_X86_PROCESSOR_H */
11901 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11902 index dcfde52..dbfea06 100644
11903 --- a/arch/x86/include/asm/ptrace.h
11904 +++ b/arch/x86/include/asm/ptrace.h
11905 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11906 }
11907
11908 /*
11909 - * user_mode_vm(regs) determines whether a register set came from user mode.
11910 + * user_mode(regs) determines whether a register set came from user mode.
11911 * This is true if V8086 mode was enabled OR if the register set was from
11912 * protected mode with RPL-3 CS value. This tricky test checks that with
11913 * one comparison. Many places in the kernel can bypass this full check
11914 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11915 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11916 + * be used.
11917 */
11918 -static inline int user_mode(struct pt_regs *regs)
11919 +static inline int user_mode_novm(struct pt_regs *regs)
11920 {
11921 #ifdef CONFIG_X86_32
11922 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11923 #else
11924 - return !!(regs->cs & 3);
11925 + return !!(regs->cs & SEGMENT_RPL_MASK);
11926 #endif
11927 }
11928
11929 -static inline int user_mode_vm(struct pt_regs *regs)
11930 +static inline int user_mode(struct pt_regs *regs)
11931 {
11932 #ifdef CONFIG_X86_32
11933 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11934 USER_RPL;
11935 #else
11936 - return user_mode(regs);
11937 + return user_mode_novm(regs);
11938 #endif
11939 }
11940
11941 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11942 #ifdef CONFIG_X86_64
11943 static inline bool user_64bit_mode(struct pt_regs *regs)
11944 {
11945 + unsigned long cs = regs->cs & 0xffff;
11946 #ifndef CONFIG_PARAVIRT
11947 /*
11948 * On non-paravirt systems, this is the only long mode CPL 3
11949 * selector. We do not allow long mode selectors in the LDT.
11950 */
11951 - return regs->cs == __USER_CS;
11952 + return cs == __USER_CS;
11953 #else
11954 /* Headers are too twisted for this to go in paravirt.h. */
11955 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11956 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11957 #endif
11958 }
11959 #endif
11960 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11961 index fce3f4a..3f69f2a 100644
11962 --- a/arch/x86/include/asm/realmode.h
11963 +++ b/arch/x86/include/asm/realmode.h
11964 @@ -30,7 +30,7 @@ struct real_mode_header {
11965 struct trampoline_header {
11966 #ifdef CONFIG_X86_32
11967 u32 start;
11968 - u16 gdt_pad;
11969 + u16 boot_cs;
11970 u16 gdt_limit;
11971 u32 gdt_base;
11972 #else
11973 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11974 index 92f29706..a79cbbb 100644
11975 --- a/arch/x86/include/asm/reboot.h
11976 +++ b/arch/x86/include/asm/reboot.h
11977 @@ -6,19 +6,19 @@
11978 struct pt_regs;
11979
11980 struct machine_ops {
11981 - void (*restart)(char *cmd);
11982 - void (*halt)(void);
11983 - void (*power_off)(void);
11984 + void (* __noreturn restart)(char *cmd);
11985 + void (* __noreturn halt)(void);
11986 + void (* __noreturn power_off)(void);
11987 void (*shutdown)(void);
11988 void (*crash_shutdown)(struct pt_regs *);
11989 - void (*emergency_restart)(void);
11990 -};
11991 + void (* __noreturn emergency_restart)(void);
11992 +} __no_const;
11993
11994 extern struct machine_ops machine_ops;
11995
11996 void native_machine_crash_shutdown(struct pt_regs *regs);
11997 void native_machine_shutdown(void);
11998 -void machine_real_restart(unsigned int type);
11999 +void machine_real_restart(unsigned int type) __noreturn;
12000 /* These must match dispatch_table in reboot_32.S */
12001 #define MRR_BIOS 0
12002 #define MRR_APM 1
12003 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12004 index 2dbe4a7..ce1db00 100644
12005 --- a/arch/x86/include/asm/rwsem.h
12006 +++ b/arch/x86/include/asm/rwsem.h
12007 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12008 {
12009 asm volatile("# beginning down_read\n\t"
12010 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12011 +
12012 +#ifdef CONFIG_PAX_REFCOUNT
12013 + "jno 0f\n"
12014 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12015 + "int $4\n0:\n"
12016 + _ASM_EXTABLE(0b, 0b)
12017 +#endif
12018 +
12019 /* adds 0x00000001 */
12020 " jns 1f\n"
12021 " call call_rwsem_down_read_failed\n"
12022 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12023 "1:\n\t"
12024 " mov %1,%2\n\t"
12025 " add %3,%2\n\t"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + "sub %3,%2\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 " jle 2f\n\t"
12035 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12036 " jnz 1b\n\t"
12037 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12038 long tmp;
12039 asm volatile("# beginning down_write\n\t"
12040 LOCK_PREFIX " xadd %1,(%2)\n\t"
12041 +
12042 +#ifdef CONFIG_PAX_REFCOUNT
12043 + "jno 0f\n"
12044 + "mov %1,(%2)\n"
12045 + "int $4\n0:\n"
12046 + _ASM_EXTABLE(0b, 0b)
12047 +#endif
12048 +
12049 /* adds 0xffff0001, returns the old value */
12050 " test %1,%1\n\t"
12051 /* was the count 0 before? */
12052 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12053 long tmp;
12054 asm volatile("# beginning __up_read\n\t"
12055 LOCK_PREFIX " xadd %1,(%2)\n\t"
12056 +
12057 +#ifdef CONFIG_PAX_REFCOUNT
12058 + "jno 0f\n"
12059 + "mov %1,(%2)\n"
12060 + "int $4\n0:\n"
12061 + _ASM_EXTABLE(0b, 0b)
12062 +#endif
12063 +
12064 /* subtracts 1, returns the old value */
12065 " jns 1f\n\t"
12066 " call call_rwsem_wake\n" /* expects old value in %edx */
12067 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12068 long tmp;
12069 asm volatile("# beginning __up_write\n\t"
12070 LOCK_PREFIX " xadd %1,(%2)\n\t"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + "mov %1,(%2)\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 /* subtracts 0xffff0001, returns the old value */
12080 " jns 1f\n\t"
12081 " call call_rwsem_wake\n" /* expects old value in %edx */
12082 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12083 {
12084 asm volatile("# beginning __downgrade_write\n\t"
12085 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12086 +
12087 +#ifdef CONFIG_PAX_REFCOUNT
12088 + "jno 0f\n"
12089 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12090 + "int $4\n0:\n"
12091 + _ASM_EXTABLE(0b, 0b)
12092 +#endif
12093 +
12094 /*
12095 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12096 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12097 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12098 */
12099 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12100 {
12101 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12102 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12103 +
12104 +#ifdef CONFIG_PAX_REFCOUNT
12105 + "jno 0f\n"
12106 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12107 + "int $4\n0:\n"
12108 + _ASM_EXTABLE(0b, 0b)
12109 +#endif
12110 +
12111 : "+m" (sem->count)
12112 : "er" (delta));
12113 }
12114 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12115 */
12116 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12117 {
12118 - return delta + xadd(&sem->count, delta);
12119 + return delta + xadd_check_overflow(&sem->count, delta);
12120 }
12121
12122 #endif /* __KERNEL__ */
12123 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12124 index c48a950..c6d7468 100644
12125 --- a/arch/x86/include/asm/segment.h
12126 +++ b/arch/x86/include/asm/segment.h
12127 @@ -64,10 +64,15 @@
12128 * 26 - ESPFIX small SS
12129 * 27 - per-cpu [ offset to per-cpu data area ]
12130 * 28 - stack_canary-20 [ for stack protector ]
12131 - * 29 - unused
12132 - * 30 - unused
12133 + * 29 - PCI BIOS CS
12134 + * 30 - PCI BIOS DS
12135 * 31 - TSS for double fault handler
12136 */
12137 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12138 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12139 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12140 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12141 +
12142 #define GDT_ENTRY_TLS_MIN 6
12143 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12144
12145 @@ -79,6 +84,8 @@
12146
12147 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12148
12149 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12150 +
12151 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12152
12153 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12154 @@ -104,6 +111,12 @@
12155 #define __KERNEL_STACK_CANARY 0
12156 #endif
12157
12158 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12159 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12160 +
12161 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12162 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12163 +
12164 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12165
12166 /*
12167 @@ -141,7 +154,7 @@
12168 */
12169
12170 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12171 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12172 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12173
12174
12175 #else
12176 @@ -165,6 +178,8 @@
12177 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12178 #define __USER32_DS __USER_DS
12179
12180 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12181 +
12182 #define GDT_ENTRY_TSS 8 /* needs two entries */
12183 #define GDT_ENTRY_LDT 10 /* needs two entries */
12184 #define GDT_ENTRY_TLS_MIN 12
12185 @@ -185,6 +200,7 @@
12186 #endif
12187
12188 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12189 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12190 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12191 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12192 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12193 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12194 {
12195 unsigned long __limit;
12196 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12197 - return __limit + 1;
12198 + return __limit;
12199 }
12200
12201 #endif /* !__ASSEMBLY__ */
12202 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12203 index f483945..64a7851 100644
12204 --- a/arch/x86/include/asm/smp.h
12205 +++ b/arch/x86/include/asm/smp.h
12206 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12207 /* cpus sharing the last level cache: */
12208 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12209 DECLARE_PER_CPU(u16, cpu_llc_id);
12210 -DECLARE_PER_CPU(int, cpu_number);
12211 +DECLARE_PER_CPU(unsigned int, cpu_number);
12212
12213 static inline struct cpumask *cpu_sibling_mask(int cpu)
12214 {
12215 @@ -79,7 +79,7 @@ struct smp_ops {
12216
12217 void (*send_call_func_ipi)(const struct cpumask *mask);
12218 void (*send_call_func_single_ipi)(int cpu);
12219 -};
12220 +} __no_const;
12221
12222 /* Globals due to paravirt */
12223 extern void set_cpu_sibling_map(int cpu);
12224 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12225 extern int safe_smp_processor_id(void);
12226
12227 #elif defined(CONFIG_X86_64_SMP)
12228 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12229 -
12230 -#define stack_smp_processor_id() \
12231 -({ \
12232 - struct thread_info *ti; \
12233 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12234 - ti->cpu; \
12235 -})
12236 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12237 +#define stack_smp_processor_id() raw_smp_processor_id()
12238 #define safe_smp_processor_id() smp_processor_id()
12239
12240 #endif
12241 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12242 index b315a33..8849ab0 100644
12243 --- a/arch/x86/include/asm/spinlock.h
12244 +++ b/arch/x86/include/asm/spinlock.h
12245 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12246 static inline void arch_read_lock(arch_rwlock_t *rw)
12247 {
12248 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12249 +
12250 +#ifdef CONFIG_PAX_REFCOUNT
12251 + "jno 0f\n"
12252 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12253 + "int $4\n0:\n"
12254 + _ASM_EXTABLE(0b, 0b)
12255 +#endif
12256 +
12257 "jns 1f\n"
12258 "call __read_lock_failed\n\t"
12259 "1:\n"
12260 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12261 static inline void arch_write_lock(arch_rwlock_t *rw)
12262 {
12263 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12264 +
12265 +#ifdef CONFIG_PAX_REFCOUNT
12266 + "jno 0f\n"
12267 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12268 + "int $4\n0:\n"
12269 + _ASM_EXTABLE(0b, 0b)
12270 +#endif
12271 +
12272 "jz 1f\n"
12273 "call __write_lock_failed\n\t"
12274 "1:\n"
12275 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12276
12277 static inline void arch_read_unlock(arch_rwlock_t *rw)
12278 {
12279 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12280 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12281 +
12282 +#ifdef CONFIG_PAX_REFCOUNT
12283 + "jno 0f\n"
12284 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12285 + "int $4\n0:\n"
12286 + _ASM_EXTABLE(0b, 0b)
12287 +#endif
12288 +
12289 :"+m" (rw->lock) : : "memory");
12290 }
12291
12292 static inline void arch_write_unlock(arch_rwlock_t *rw)
12293 {
12294 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12295 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12296 +
12297 +#ifdef CONFIG_PAX_REFCOUNT
12298 + "jno 0f\n"
12299 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12300 + "int $4\n0:\n"
12301 + _ASM_EXTABLE(0b, 0b)
12302 +#endif
12303 +
12304 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12305 }
12306
12307 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12308 index 6a99859..03cb807 100644
12309 --- a/arch/x86/include/asm/stackprotector.h
12310 +++ b/arch/x86/include/asm/stackprotector.h
12311 @@ -47,7 +47,7 @@
12312 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12313 */
12314 #define GDT_STACK_CANARY_INIT \
12315 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12316 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12317
12318 /*
12319 * Initialize the stackprotector canary value.
12320 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12321
12322 static inline void load_stack_canary_segment(void)
12323 {
12324 -#ifdef CONFIG_X86_32
12325 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12326 asm volatile ("mov %0, %%gs" : : "r" (0));
12327 #endif
12328 }
12329 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12330 index 70bbe39..4ae2bd4 100644
12331 --- a/arch/x86/include/asm/stacktrace.h
12332 +++ b/arch/x86/include/asm/stacktrace.h
12333 @@ -11,28 +11,20 @@
12334
12335 extern int kstack_depth_to_print;
12336
12337 -struct thread_info;
12338 +struct task_struct;
12339 struct stacktrace_ops;
12340
12341 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12342 - unsigned long *stack,
12343 - unsigned long bp,
12344 - const struct stacktrace_ops *ops,
12345 - void *data,
12346 - unsigned long *end,
12347 - int *graph);
12348 +typedef unsigned long walk_stack_t(struct task_struct *task,
12349 + void *stack_start,
12350 + unsigned long *stack,
12351 + unsigned long bp,
12352 + const struct stacktrace_ops *ops,
12353 + void *data,
12354 + unsigned long *end,
12355 + int *graph);
12356
12357 -extern unsigned long
12358 -print_context_stack(struct thread_info *tinfo,
12359 - unsigned long *stack, unsigned long bp,
12360 - const struct stacktrace_ops *ops, void *data,
12361 - unsigned long *end, int *graph);
12362 -
12363 -extern unsigned long
12364 -print_context_stack_bp(struct thread_info *tinfo,
12365 - unsigned long *stack, unsigned long bp,
12366 - const struct stacktrace_ops *ops, void *data,
12367 - unsigned long *end, int *graph);
12368 +extern walk_stack_t print_context_stack;
12369 +extern walk_stack_t print_context_stack_bp;
12370
12371 /* Generic stack tracer with callbacks */
12372
12373 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12374 void (*address)(void *data, unsigned long address, int reliable);
12375 /* On negative return stop dumping */
12376 int (*stack)(void *data, char *name);
12377 - walk_stack_t walk_stack;
12378 + walk_stack_t *walk_stack;
12379 };
12380
12381 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12382 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12383 index 4ec45b3..a4f0a8a 100644
12384 --- a/arch/x86/include/asm/switch_to.h
12385 +++ b/arch/x86/include/asm/switch_to.h
12386 @@ -108,7 +108,7 @@ do { \
12387 "call __switch_to\n\t" \
12388 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12389 __switch_canary \
12390 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12391 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12392 "movq %%rax,%%rdi\n\t" \
12393 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12394 "jnz ret_from_fork\n\t" \
12395 @@ -119,7 +119,7 @@ do { \
12396 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12397 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12398 [_tif_fork] "i" (_TIF_FORK), \
12399 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12400 + [thread_info] "m" (current_tinfo), \
12401 [current_task] "m" (current_task) \
12402 __switch_canary_iparam \
12403 : "memory", "cc" __EXTRA_CLOBBER)
12404 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12405 index 3fda9db4..4ca1c61 100644
12406 --- a/arch/x86/include/asm/sys_ia32.h
12407 +++ b/arch/x86/include/asm/sys_ia32.h
12408 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12409 struct old_sigaction32 __user *);
12410 asmlinkage long sys32_alarm(unsigned int);
12411
12412 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12413 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12414 asmlinkage long sys32_sysfs(int, u32, u32);
12415
12416 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12417 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12418 index 89f794f..1422765 100644
12419 --- a/arch/x86/include/asm/thread_info.h
12420 +++ b/arch/x86/include/asm/thread_info.h
12421 @@ -10,6 +10,7 @@
12422 #include <linux/compiler.h>
12423 #include <asm/page.h>
12424 #include <asm/types.h>
12425 +#include <asm/percpu.h>
12426
12427 /*
12428 * low level task data that entry.S needs immediate access to
12429 @@ -24,7 +25,6 @@ struct exec_domain;
12430 #include <linux/atomic.h>
12431
12432 struct thread_info {
12433 - struct task_struct *task; /* main task structure */
12434 struct exec_domain *exec_domain; /* execution domain */
12435 __u32 flags; /* low level flags */
12436 __u32 status; /* thread synchronous flags */
12437 @@ -34,19 +34,13 @@ struct thread_info {
12438 mm_segment_t addr_limit;
12439 struct restart_block restart_block;
12440 void __user *sysenter_return;
12441 -#ifdef CONFIG_X86_32
12442 - unsigned long previous_esp; /* ESP of the previous stack in
12443 - case of nested (IRQ) stacks
12444 - */
12445 - __u8 supervisor_stack[0];
12446 -#endif
12447 + unsigned long lowest_stack;
12448 unsigned int sig_on_uaccess_error:1;
12449 unsigned int uaccess_err:1; /* uaccess failed */
12450 };
12451
12452 -#define INIT_THREAD_INFO(tsk) \
12453 +#define INIT_THREAD_INFO \
12454 { \
12455 - .task = &tsk, \
12456 .exec_domain = &default_exec_domain, \
12457 .flags = 0, \
12458 .cpu = 0, \
12459 @@ -57,7 +51,7 @@ struct thread_info {
12460 }, \
12461 }
12462
12463 -#define init_thread_info (init_thread_union.thread_info)
12464 +#define init_thread_info (init_thread_union.stack)
12465 #define init_stack (init_thread_union.stack)
12466
12467 #else /* !__ASSEMBLY__ */
12468 @@ -98,6 +92,7 @@ struct thread_info {
12469 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12470 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12471 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12472 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12473
12474 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12475 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12476 @@ -122,16 +117,18 @@ struct thread_info {
12477 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12478 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12479 #define _TIF_X32 (1 << TIF_X32)
12480 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12481
12482 /* work to do in syscall_trace_enter() */
12483 #define _TIF_WORK_SYSCALL_ENTRY \
12484 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12485 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12486 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12487 + _TIF_GRSEC_SETXID)
12488
12489 /* work to do in syscall_trace_leave() */
12490 #define _TIF_WORK_SYSCALL_EXIT \
12491 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12492 - _TIF_SYSCALL_TRACEPOINT)
12493 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12494
12495 /* work to do on interrupt/exception return */
12496 #define _TIF_WORK_MASK \
12497 @@ -141,7 +138,8 @@ struct thread_info {
12498
12499 /* work to do on any return to user space */
12500 #define _TIF_ALLWORK_MASK \
12501 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12502 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12503 + _TIF_GRSEC_SETXID)
12504
12505 /* Only used for 64 bit */
12506 #define _TIF_DO_NOTIFY_MASK \
12507 @@ -157,45 +155,40 @@ struct thread_info {
12508
12509 #define PREEMPT_ACTIVE 0x10000000
12510
12511 -#ifdef CONFIG_X86_32
12512 -
12513 -#define STACK_WARN (THREAD_SIZE/8)
12514 -/*
12515 - * macros/functions for gaining access to the thread information structure
12516 - *
12517 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12518 - */
12519 -#ifndef __ASSEMBLY__
12520 -
12521 -
12522 -/* how to get the current stack pointer from C */
12523 -register unsigned long current_stack_pointer asm("esp") __used;
12524 -
12525 -/* how to get the thread information struct from C */
12526 -static inline struct thread_info *current_thread_info(void)
12527 -{
12528 - return (struct thread_info *)
12529 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12530 -}
12531 -
12532 -#else /* !__ASSEMBLY__ */
12533 -
12534 +#ifdef __ASSEMBLY__
12535 /* how to get the thread information struct from ASM */
12536 #define GET_THREAD_INFO(reg) \
12537 - movl $-THREAD_SIZE, reg; \
12538 - andl %esp, reg
12539 + mov PER_CPU_VAR(current_tinfo), reg
12540
12541 /* use this one if reg already contains %esp */
12542 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12543 - andl $-THREAD_SIZE, reg
12544 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12545 +#else
12546 +/* how to get the thread information struct from C */
12547 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12548 +
12549 +static __always_inline struct thread_info *current_thread_info(void)
12550 +{
12551 + return this_cpu_read_stable(current_tinfo);
12552 +}
12553 +#endif
12554 +
12555 +#ifdef CONFIG_X86_32
12556 +
12557 +#define STACK_WARN (THREAD_SIZE/8)
12558 +/*
12559 + * macros/functions for gaining access to the thread information structure
12560 + *
12561 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12562 + */
12563 +#ifndef __ASSEMBLY__
12564 +
12565 +/* how to get the current stack pointer from C */
12566 +register unsigned long current_stack_pointer asm("esp") __used;
12567
12568 #endif
12569
12570 #else /* X86_32 */
12571
12572 -#include <asm/percpu.h>
12573 -#define KERNEL_STACK_OFFSET (5*8)
12574 -
12575 /*
12576 * macros/functions for gaining access to the thread information structure
12577 * preempt_count needs to be 1 initially, until the scheduler is functional.
12578 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12579 #ifndef __ASSEMBLY__
12580 DECLARE_PER_CPU(unsigned long, kernel_stack);
12581
12582 -static inline struct thread_info *current_thread_info(void)
12583 -{
12584 - struct thread_info *ti;
12585 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12586 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12587 - return ti;
12588 -}
12589 -
12590 -#else /* !__ASSEMBLY__ */
12591 -
12592 -/* how to get the thread information struct from ASM */
12593 -#define GET_THREAD_INFO(reg) \
12594 - movq PER_CPU_VAR(kernel_stack),reg ; \
12595 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12596 -
12597 -/*
12598 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12599 - * a certain register (to be used in assembler memory operands).
12600 - */
12601 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12602 -
12603 +/* how to get the current stack pointer from C */
12604 +register unsigned long current_stack_pointer asm("rsp") __used;
12605 #endif
12606
12607 #endif /* !X86_32 */
12608 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12609 extern void arch_task_cache_init(void);
12610 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12611 extern void arch_release_task_struct(struct task_struct *tsk);
12612 +
12613 +#define __HAVE_THREAD_FUNCTIONS
12614 +#define task_thread_info(task) (&(task)->tinfo)
12615 +#define task_stack_page(task) ((task)->stack)
12616 +#define setup_thread_stack(p, org) do {} while (0)
12617 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12618 +
12619 #endif
12620 #endif /* _ASM_X86_THREAD_INFO_H */
12621 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12622 index e1f3a17..1ab364d 100644
12623 --- a/arch/x86/include/asm/uaccess.h
12624 +++ b/arch/x86/include/asm/uaccess.h
12625 @@ -7,12 +7,15 @@
12626 #include <linux/compiler.h>
12627 #include <linux/thread_info.h>
12628 #include <linux/string.h>
12629 +#include <linux/sched.h>
12630 #include <asm/asm.h>
12631 #include <asm/page.h>
12632
12633 #define VERIFY_READ 0
12634 #define VERIFY_WRITE 1
12635
12636 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12637 +
12638 /*
12639 * The fs value determines whether argument validity checking should be
12640 * performed or not. If get_fs() == USER_DS, checking is performed, with
12641 @@ -28,7 +31,12 @@
12642
12643 #define get_ds() (KERNEL_DS)
12644 #define get_fs() (current_thread_info()->addr_limit)
12645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12646 +void __set_fs(mm_segment_t x);
12647 +void set_fs(mm_segment_t x);
12648 +#else
12649 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12650 +#endif
12651
12652 #define segment_eq(a, b) ((a).seg == (b).seg)
12653
12654 @@ -76,8 +84,33 @@
12655 * checks that the pointer is in the user space range - after calling
12656 * this function, memory access functions may still return -EFAULT.
12657 */
12658 -#define access_ok(type, addr, size) \
12659 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12660 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12661 +#define access_ok(type, addr, size) \
12662 +({ \
12663 + long __size = size; \
12664 + unsigned long __addr = (unsigned long)addr; \
12665 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12666 + unsigned long __end_ao = __addr + __size - 1; \
12667 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12668 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12669 + while(__addr_ao <= __end_ao) { \
12670 + char __c_ao; \
12671 + __addr_ao += PAGE_SIZE; \
12672 + if (__size > PAGE_SIZE) \
12673 + cond_resched(); \
12674 + if (__get_user(__c_ao, (char __user *)__addr)) \
12675 + break; \
12676 + if (type != VERIFY_WRITE) { \
12677 + __addr = __addr_ao; \
12678 + continue; \
12679 + } \
12680 + if (__put_user(__c_ao, (char __user *)__addr)) \
12681 + break; \
12682 + __addr = __addr_ao; \
12683 + } \
12684 + } \
12685 + __ret_ao; \
12686 +})
12687
12688 /*
12689 * The exception table consists of pairs of addresses relative to the
12690 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12691 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12692 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12693
12694 -
12695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12696 +#define __copyuser_seg "gs;"
12697 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12698 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12699 +#else
12700 +#define __copyuser_seg
12701 +#define __COPYUSER_SET_ES
12702 +#define __COPYUSER_RESTORE_ES
12703 +#endif
12704
12705 #ifdef CONFIG_X86_32
12706 #define __put_user_asm_u64(x, addr, err, errret) \
12707 - asm volatile("1: movl %%eax,0(%2)\n" \
12708 - "2: movl %%edx,4(%2)\n" \
12709 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12710 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12711 "3:\n" \
12712 ".section .fixup,\"ax\"\n" \
12713 "4: movl %3,%0\n" \
12714 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12715 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12716
12717 #define __put_user_asm_ex_u64(x, addr) \
12718 - asm volatile("1: movl %%eax,0(%1)\n" \
12719 - "2: movl %%edx,4(%1)\n" \
12720 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12721 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12722 "3:\n" \
12723 _ASM_EXTABLE_EX(1b, 2b) \
12724 _ASM_EXTABLE_EX(2b, 3b) \
12725 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12726 __typeof__(*(ptr)) __pu_val; \
12727 __chk_user_ptr(ptr); \
12728 might_fault(); \
12729 - __pu_val = x; \
12730 + __pu_val = (x); \
12731 switch (sizeof(*(ptr))) { \
12732 case 1: \
12733 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12734 @@ -379,7 +420,7 @@ do { \
12735 } while (0)
12736
12737 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12738 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12739 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12740 "2:\n" \
12741 ".section .fixup,\"ax\"\n" \
12742 "3: mov %3,%0\n" \
12743 @@ -387,7 +428,7 @@ do { \
12744 " jmp 2b\n" \
12745 ".previous\n" \
12746 _ASM_EXTABLE(1b, 3b) \
12747 - : "=r" (err), ltype(x) \
12748 + : "=r" (err), ltype (x) \
12749 : "m" (__m(addr)), "i" (errret), "0" (err))
12750
12751 #define __get_user_size_ex(x, ptr, size) \
12752 @@ -412,7 +453,7 @@ do { \
12753 } while (0)
12754
12755 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12756 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12757 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12758 "2:\n" \
12759 _ASM_EXTABLE_EX(1b, 2b) \
12760 : ltype(x) : "m" (__m(addr)))
12761 @@ -429,13 +470,24 @@ do { \
12762 int __gu_err; \
12763 unsigned long __gu_val; \
12764 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12765 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12766 + (x) = (__typeof__(*(ptr)))__gu_val; \
12767 __gu_err; \
12768 })
12769
12770 /* FIXME: this hack is definitely wrong -AK */
12771 struct __large_struct { unsigned long buf[100]; };
12772 -#define __m(x) (*(struct __large_struct __user *)(x))
12773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12774 +#define ____m(x) \
12775 +({ \
12776 + unsigned long ____x = (unsigned long)(x); \
12777 + if (____x < PAX_USER_SHADOW_BASE) \
12778 + ____x += PAX_USER_SHADOW_BASE; \
12779 + (void __user *)____x; \
12780 +})
12781 +#else
12782 +#define ____m(x) (x)
12783 +#endif
12784 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12785
12786 /*
12787 * Tell gcc we read from memory instead of writing: this is because
12788 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12789 * aliasing issues.
12790 */
12791 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12792 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12793 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12794 "2:\n" \
12795 ".section .fixup,\"ax\"\n" \
12796 "3: mov %3,%0\n" \
12797 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12798 ".previous\n" \
12799 _ASM_EXTABLE(1b, 3b) \
12800 : "=r"(err) \
12801 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12802 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12803
12804 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12805 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12806 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12807 "2:\n" \
12808 _ASM_EXTABLE_EX(1b, 2b) \
12809 : : ltype(x), "m" (__m(addr)))
12810 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12811 * On error, the variable @x is set to zero.
12812 */
12813
12814 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12815 +#define __get_user(x, ptr) get_user((x), (ptr))
12816 +#else
12817 #define __get_user(x, ptr) \
12818 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12819 +#endif
12820
12821 /**
12822 * __put_user: - Write a simple value into user space, with less checking.
12823 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12824 * Returns zero on success, or -EFAULT on error.
12825 */
12826
12827 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12828 +#define __put_user(x, ptr) put_user((x), (ptr))
12829 +#else
12830 #define __put_user(x, ptr) \
12831 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12832 +#endif
12833
12834 #define __get_user_unaligned __get_user
12835 #define __put_user_unaligned __put_user
12836 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12837 #define get_user_ex(x, ptr) do { \
12838 unsigned long __gue_val; \
12839 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12840 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12841 + (x) = (__typeof__(*(ptr)))__gue_val; \
12842 } while (0)
12843
12844 #ifdef CONFIG_X86_WP_WORKS_OK
12845 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12846 index 576e39b..ccd0a39 100644
12847 --- a/arch/x86/include/asm/uaccess_32.h
12848 +++ b/arch/x86/include/asm/uaccess_32.h
12849 @@ -11,15 +11,15 @@
12850 #include <asm/page.h>
12851
12852 unsigned long __must_check __copy_to_user_ll
12853 - (void __user *to, const void *from, unsigned long n);
12854 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12855 unsigned long __must_check __copy_from_user_ll
12856 - (void *to, const void __user *from, unsigned long n);
12857 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12858 unsigned long __must_check __copy_from_user_ll_nozero
12859 - (void *to, const void __user *from, unsigned long n);
12860 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12861 unsigned long __must_check __copy_from_user_ll_nocache
12862 - (void *to, const void __user *from, unsigned long n);
12863 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12864 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12865 - (void *to, const void __user *from, unsigned long n);
12866 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12867
12868 /**
12869 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12870 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12871 static __always_inline unsigned long __must_check
12872 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12873 {
12874 + if ((long)n < 0)
12875 + return n;
12876 +
12877 if (__builtin_constant_p(n)) {
12878 unsigned long ret;
12879
12880 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12881 return ret;
12882 }
12883 }
12884 + if (!__builtin_constant_p(n))
12885 + check_object_size(from, n, true);
12886 return __copy_to_user_ll(to, from, n);
12887 }
12888
12889 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12890 __copy_to_user(void __user *to, const void *from, unsigned long n)
12891 {
12892 might_fault();
12893 +
12894 return __copy_to_user_inatomic(to, from, n);
12895 }
12896
12897 static __always_inline unsigned long
12898 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12899 {
12900 + if ((long)n < 0)
12901 + return n;
12902 +
12903 /* Avoid zeroing the tail if the copy fails..
12904 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12905 * but as the zeroing behaviour is only significant when n is not
12906 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12907 __copy_from_user(void *to, const void __user *from, unsigned long n)
12908 {
12909 might_fault();
12910 +
12911 + if ((long)n < 0)
12912 + return n;
12913 +
12914 if (__builtin_constant_p(n)) {
12915 unsigned long ret;
12916
12917 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12918 return ret;
12919 }
12920 }
12921 + if (!__builtin_constant_p(n))
12922 + check_object_size(to, n, false);
12923 return __copy_from_user_ll(to, from, n);
12924 }
12925
12926 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12927 const void __user *from, unsigned long n)
12928 {
12929 might_fault();
12930 +
12931 + if ((long)n < 0)
12932 + return n;
12933 +
12934 if (__builtin_constant_p(n)) {
12935 unsigned long ret;
12936
12937 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12938 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12939 unsigned long n)
12940 {
12941 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12942 + if ((long)n < 0)
12943 + return n;
12944 +
12945 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12946 }
12947
12948 -unsigned long __must_check copy_to_user(void __user *to,
12949 - const void *from, unsigned long n);
12950 -unsigned long __must_check _copy_from_user(void *to,
12951 - const void __user *from,
12952 - unsigned long n);
12953 -
12954 +extern void copy_to_user_overflow(void)
12955 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12956 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12957 +#else
12958 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12959 +#endif
12960 +;
12961
12962 extern void copy_from_user_overflow(void)
12963 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12964 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12965 #endif
12966 ;
12967
12968 -static inline unsigned long __must_check copy_from_user(void *to,
12969 - const void __user *from,
12970 - unsigned long n)
12971 +/**
12972 + * copy_to_user: - Copy a block of data into user space.
12973 + * @to: Destination address, in user space.
12974 + * @from: Source address, in kernel space.
12975 + * @n: Number of bytes to copy.
12976 + *
12977 + * Context: User context only. This function may sleep.
12978 + *
12979 + * Copy data from kernel space to user space.
12980 + *
12981 + * Returns number of bytes that could not be copied.
12982 + * On success, this will be zero.
12983 + */
12984 +static inline unsigned long __must_check
12985 +copy_to_user(void __user *to, const void *from, unsigned long n)
12986 {
12987 - int sz = __compiletime_object_size(to);
12988 + size_t sz = __compiletime_object_size(from);
12989
12990 - if (likely(sz == -1 || sz >= n))
12991 - n = _copy_from_user(to, from, n);
12992 - else
12993 + if (unlikely(sz != (size_t)-1 && sz < n))
12994 + copy_to_user_overflow();
12995 + else if (access_ok(VERIFY_WRITE, to, n))
12996 + n = __copy_to_user(to, from, n);
12997 + return n;
12998 +}
12999 +
13000 +/**
13001 + * copy_from_user: - Copy a block of data from user space.
13002 + * @to: Destination address, in kernel space.
13003 + * @from: Source address, in user space.
13004 + * @n: Number of bytes to copy.
13005 + *
13006 + * Context: User context only. This function may sleep.
13007 + *
13008 + * Copy data from user space to kernel space.
13009 + *
13010 + * Returns number of bytes that could not be copied.
13011 + * On success, this will be zero.
13012 + *
13013 + * If some data could not be copied, this function will pad the copied
13014 + * data to the requested size using zero bytes.
13015 + */
13016 +static inline unsigned long __must_check
13017 +copy_from_user(void *to, const void __user *from, unsigned long n)
13018 +{
13019 + size_t sz = __compiletime_object_size(to);
13020 +
13021 + if (unlikely(sz != (size_t)-1 && sz < n))
13022 copy_from_user_overflow();
13023 -
13024 + else if (access_ok(VERIFY_READ, from, n))
13025 + n = __copy_from_user(to, from, n);
13026 + else if ((long)n > 0) {
13027 + if (!__builtin_constant_p(n))
13028 + check_object_size(to, n, false);
13029 + memset(to, 0, n);
13030 + }
13031 return n;
13032 }
13033
13034 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13035 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13036 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13037 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13038
13039 #endif /* _ASM_X86_UACCESS_32_H */
13040 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13041 index 8e796fb..72fd934 100644
13042 --- a/arch/x86/include/asm/uaccess_64.h
13043 +++ b/arch/x86/include/asm/uaccess_64.h
13044 @@ -10,6 +10,9 @@
13045 #include <asm/alternative.h>
13046 #include <asm/cpufeature.h>
13047 #include <asm/page.h>
13048 +#include <asm/pgtable.h>
13049 +
13050 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13051
13052 /*
13053 * Copy To/From Userspace
13054 @@ -17,12 +20,14 @@
13055
13056 /* Handles exceptions in both to and from, but doesn't do access_ok */
13057 __must_check unsigned long
13058 -copy_user_generic_string(void *to, const void *from, unsigned len);
13059 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13060 __must_check unsigned long
13061 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13062 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13063
13064 static __always_inline __must_check unsigned long
13065 -copy_user_generic(void *to, const void *from, unsigned len)
13066 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13067 +static __always_inline __must_check unsigned long
13068 +copy_user_generic(void *to, const void *from, unsigned long len)
13069 {
13070 unsigned ret;
13071
13072 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13073 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13074 "=d" (len)),
13075 "1" (to), "2" (from), "3" (len)
13076 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13077 + : "memory", "rcx", "r8", "r9", "r11");
13078 return ret;
13079 }
13080
13081 +static __always_inline __must_check unsigned long
13082 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13083 +static __always_inline __must_check unsigned long
13084 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13085 __must_check unsigned long
13086 -_copy_to_user(void __user *to, const void *from, unsigned len);
13087 -__must_check unsigned long
13088 -_copy_from_user(void *to, const void __user *from, unsigned len);
13089 -__must_check unsigned long
13090 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13091 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13092 +
13093 +extern void copy_to_user_overflow(void)
13094 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13095 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13096 +#else
13097 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13098 +#endif
13099 +;
13100 +
13101 +extern void copy_from_user_overflow(void)
13102 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13103 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13104 +#else
13105 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13106 +#endif
13107 +;
13108
13109 static inline unsigned long __must_check copy_from_user(void *to,
13110 const void __user *from,
13111 unsigned long n)
13112 {
13113 - int sz = __compiletime_object_size(to);
13114 -
13115 might_fault();
13116 - if (likely(sz == -1 || sz >= n))
13117 - n = _copy_from_user(to, from, n);
13118 -#ifdef CONFIG_DEBUG_VM
13119 - else
13120 - WARN(1, "Buffer overflow detected!\n");
13121 -#endif
13122 +
13123 + if (access_ok(VERIFY_READ, from, n))
13124 + n = __copy_from_user(to, from, n);
13125 + else if (n < INT_MAX) {
13126 + if (!__builtin_constant_p(n))
13127 + check_object_size(to, n, false);
13128 + memset(to, 0, n);
13129 + }
13130 return n;
13131 }
13132
13133 static __always_inline __must_check
13134 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13135 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13136 {
13137 might_fault();
13138
13139 - return _copy_to_user(dst, src, size);
13140 + if (access_ok(VERIFY_WRITE, dst, size))
13141 + size = __copy_to_user(dst, src, size);
13142 + return size;
13143 }
13144
13145 static __always_inline __must_check
13146 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13147 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13148 {
13149 - int ret = 0;
13150 + size_t sz = __compiletime_object_size(dst);
13151 + unsigned ret = 0;
13152
13153 might_fault();
13154 - if (!__builtin_constant_p(size))
13155 - return copy_user_generic(dst, (__force void *)src, size);
13156 +
13157 + if (size > INT_MAX)
13158 + return size;
13159 +
13160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13161 + if (!__access_ok(VERIFY_READ, src, size))
13162 + return size;
13163 +#endif
13164 +
13165 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13166 + copy_from_user_overflow();
13167 + return size;
13168 + }
13169 +
13170 + if (!__builtin_constant_p(size)) {
13171 + check_object_size(dst, size, false);
13172 +
13173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13174 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13175 + src += PAX_USER_SHADOW_BASE;
13176 +#endif
13177 +
13178 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13179 + }
13180 switch (size) {
13181 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13182 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13183 ret, "b", "b", "=q", 1);
13184 return ret;
13185 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13186 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13187 ret, "w", "w", "=r", 2);
13188 return ret;
13189 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13190 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13191 ret, "l", "k", "=r", 4);
13192 return ret;
13193 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13194 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13195 ret, "q", "", "=r", 8);
13196 return ret;
13197 case 10:
13198 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13199 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13200 ret, "q", "", "=r", 10);
13201 if (unlikely(ret))
13202 return ret;
13203 __get_user_asm(*(u16 *)(8 + (char *)dst),
13204 - (u16 __user *)(8 + (char __user *)src),
13205 + (const u16 __user *)(8 + (const char __user *)src),
13206 ret, "w", "w", "=r", 2);
13207 return ret;
13208 case 16:
13209 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13210 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13211 ret, "q", "", "=r", 16);
13212 if (unlikely(ret))
13213 return ret;
13214 __get_user_asm(*(u64 *)(8 + (char *)dst),
13215 - (u64 __user *)(8 + (char __user *)src),
13216 + (const u64 __user *)(8 + (const char __user *)src),
13217 ret, "q", "", "=r", 8);
13218 return ret;
13219 default:
13220 - return copy_user_generic(dst, (__force void *)src, size);
13221 +
13222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13223 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13224 + src += PAX_USER_SHADOW_BASE;
13225 +#endif
13226 +
13227 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13228 }
13229 }
13230
13231 static __always_inline __must_check
13232 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13233 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13234 {
13235 - int ret = 0;
13236 + size_t sz = __compiletime_object_size(src);
13237 + unsigned ret = 0;
13238
13239 might_fault();
13240 - if (!__builtin_constant_p(size))
13241 - return copy_user_generic((__force void *)dst, src, size);
13242 +
13243 + if (size > INT_MAX)
13244 + return size;
13245 +
13246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13247 + if (!__access_ok(VERIFY_WRITE, dst, size))
13248 + return size;
13249 +#endif
13250 +
13251 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13252 + copy_to_user_overflow();
13253 + return size;
13254 + }
13255 +
13256 + if (!__builtin_constant_p(size)) {
13257 + check_object_size(src, size, true);
13258 +
13259 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13260 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13261 + dst += PAX_USER_SHADOW_BASE;
13262 +#endif
13263 +
13264 + return copy_user_generic((__force_kernel void *)dst, src, size);
13265 + }
13266 switch (size) {
13267 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13268 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13269 ret, "b", "b", "iq", 1);
13270 return ret;
13271 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13272 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13273 ret, "w", "w", "ir", 2);
13274 return ret;
13275 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13276 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13277 ret, "l", "k", "ir", 4);
13278 return ret;
13279 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13280 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13281 ret, "q", "", "er", 8);
13282 return ret;
13283 case 10:
13284 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13285 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13286 ret, "q", "", "er", 10);
13287 if (unlikely(ret))
13288 return ret;
13289 asm("":::"memory");
13290 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13291 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13292 ret, "w", "w", "ir", 2);
13293 return ret;
13294 case 16:
13295 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13296 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13297 ret, "q", "", "er", 16);
13298 if (unlikely(ret))
13299 return ret;
13300 asm("":::"memory");
13301 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13302 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13303 ret, "q", "", "er", 8);
13304 return ret;
13305 default:
13306 - return copy_user_generic((__force void *)dst, src, size);
13307 +
13308 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13309 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13310 + dst += PAX_USER_SHADOW_BASE;
13311 +#endif
13312 +
13313 + return copy_user_generic((__force_kernel void *)dst, src, size);
13314 }
13315 }
13316
13317 static __always_inline __must_check
13318 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13319 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13320 {
13321 - int ret = 0;
13322 + unsigned ret = 0;
13323
13324 might_fault();
13325 - if (!__builtin_constant_p(size))
13326 - return copy_user_generic((__force void *)dst,
13327 - (__force void *)src, size);
13328 +
13329 + if (size > INT_MAX)
13330 + return size;
13331 +
13332 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13333 + if (!__access_ok(VERIFY_READ, src, size))
13334 + return size;
13335 + if (!__access_ok(VERIFY_WRITE, dst, size))
13336 + return size;
13337 +#endif
13338 +
13339 + if (!__builtin_constant_p(size)) {
13340 +
13341 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13342 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13343 + src += PAX_USER_SHADOW_BASE;
13344 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13345 + dst += PAX_USER_SHADOW_BASE;
13346 +#endif
13347 +
13348 + return copy_user_generic((__force_kernel void *)dst,
13349 + (__force_kernel const void *)src, size);
13350 + }
13351 switch (size) {
13352 case 1: {
13353 u8 tmp;
13354 - __get_user_asm(tmp, (u8 __user *)src,
13355 + __get_user_asm(tmp, (const u8 __user *)src,
13356 ret, "b", "b", "=q", 1);
13357 if (likely(!ret))
13358 __put_user_asm(tmp, (u8 __user *)dst,
13359 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13360 }
13361 case 2: {
13362 u16 tmp;
13363 - __get_user_asm(tmp, (u16 __user *)src,
13364 + __get_user_asm(tmp, (const u16 __user *)src,
13365 ret, "w", "w", "=r", 2);
13366 if (likely(!ret))
13367 __put_user_asm(tmp, (u16 __user *)dst,
13368 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13369
13370 case 4: {
13371 u32 tmp;
13372 - __get_user_asm(tmp, (u32 __user *)src,
13373 + __get_user_asm(tmp, (const u32 __user *)src,
13374 ret, "l", "k", "=r", 4);
13375 if (likely(!ret))
13376 __put_user_asm(tmp, (u32 __user *)dst,
13377 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13378 }
13379 case 8: {
13380 u64 tmp;
13381 - __get_user_asm(tmp, (u64 __user *)src,
13382 + __get_user_asm(tmp, (const u64 __user *)src,
13383 ret, "q", "", "=r", 8);
13384 if (likely(!ret))
13385 __put_user_asm(tmp, (u64 __user *)dst,
13386 @@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13387 return ret;
13388 }
13389 default:
13390 - return copy_user_generic((__force void *)dst,
13391 - (__force void *)src, size);
13392 +
13393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13394 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13395 + src += PAX_USER_SHADOW_BASE;
13396 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13397 + dst += PAX_USER_SHADOW_BASE;
13398 +#endif
13399 +
13400 + return copy_user_generic((__force_kernel void *)dst,
13401 + (__force_kernel const void *)src, size);
13402 }
13403 }
13404
13405 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13406 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13407 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13408 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13409
13410 static __must_check __always_inline int
13411 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13412 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13413 {
13414 - return copy_user_generic(dst, (__force const void *)src, size);
13415 + if (size > INT_MAX)
13416 + return size;
13417 +
13418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13419 + if (!__access_ok(VERIFY_READ, src, size))
13420 + return size;
13421 +
13422 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13423 + src += PAX_USER_SHADOW_BASE;
13424 +#endif
13425 +
13426 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13427 }
13428
13429 -static __must_check __always_inline int
13430 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13431 +static __must_check __always_inline unsigned long
13432 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13433 {
13434 - return copy_user_generic((__force void *)dst, src, size);
13435 + if (size > INT_MAX)
13436 + return size;
13437 +
13438 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13439 + if (!__access_ok(VERIFY_WRITE, dst, size))
13440 + return size;
13441 +
13442 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13443 + dst += PAX_USER_SHADOW_BASE;
13444 +#endif
13445 +
13446 + return copy_user_generic((__force_kernel void *)dst, src, size);
13447 }
13448
13449 -extern long __copy_user_nocache(void *dst, const void __user *src,
13450 - unsigned size, int zerorest);
13451 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13452 + unsigned long size, int zerorest) __size_overflow(3);
13453
13454 -static inline int
13455 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13456 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13457 {
13458 might_sleep();
13459 +
13460 + if (size > INT_MAX)
13461 + return size;
13462 +
13463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13464 + if (!__access_ok(VERIFY_READ, src, size))
13465 + return size;
13466 +#endif
13467 +
13468 return __copy_user_nocache(dst, src, size, 1);
13469 }
13470
13471 -static inline int
13472 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13473 - unsigned size)
13474 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13475 + unsigned long size)
13476 {
13477 + if (size > INT_MAX)
13478 + return size;
13479 +
13480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13481 + if (!__access_ok(VERIFY_READ, src, size))
13482 + return size;
13483 +#endif
13484 +
13485 return __copy_user_nocache(dst, src, size, 0);
13486 }
13487
13488 -unsigned long
13489 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13490 +extern unsigned long
13491 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13492
13493 #endif /* _ASM_X86_UACCESS_64_H */
13494 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13495 index bb05228..d763d5b 100644
13496 --- a/arch/x86/include/asm/vdso.h
13497 +++ b/arch/x86/include/asm/vdso.h
13498 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13499 #define VDSO32_SYMBOL(base, name) \
13500 ({ \
13501 extern const char VDSO32_##name[]; \
13502 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13503 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13504 })
13505 #endif
13506
13507 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13508 index 5b238981..77fdd78 100644
13509 --- a/arch/x86/include/asm/word-at-a-time.h
13510 +++ b/arch/x86/include/asm/word-at-a-time.h
13511 @@ -11,7 +11,7 @@
13512 * and shift, for example.
13513 */
13514 struct word_at_a_time {
13515 - const unsigned long one_bits, high_bits;
13516 + unsigned long one_bits, high_bits;
13517 };
13518
13519 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13520 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13521 index c090af1..7e7bf16 100644
13522 --- a/arch/x86/include/asm/x86_init.h
13523 +++ b/arch/x86/include/asm/x86_init.h
13524 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13525 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13526 void (*find_smp_config)(void);
13527 void (*get_smp_config)(unsigned int early);
13528 -};
13529 +} __no_const;
13530
13531 /**
13532 * struct x86_init_resources - platform specific resource related ops
13533 @@ -43,7 +43,7 @@ struct x86_init_resources {
13534 void (*probe_roms)(void);
13535 void (*reserve_resources)(void);
13536 char *(*memory_setup)(void);
13537 -};
13538 +} __no_const;
13539
13540 /**
13541 * struct x86_init_irqs - platform specific interrupt setup
13542 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13543 void (*pre_vector_init)(void);
13544 void (*intr_init)(void);
13545 void (*trap_init)(void);
13546 -};
13547 +} __no_const;
13548
13549 /**
13550 * struct x86_init_oem - oem platform specific customizing functions
13551 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13552 struct x86_init_oem {
13553 void (*arch_setup)(void);
13554 void (*banner)(void);
13555 -};
13556 +} __no_const;
13557
13558 /**
13559 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13560 @@ -77,7 +77,7 @@ struct x86_init_oem {
13561 */
13562 struct x86_init_mapping {
13563 void (*pagetable_reserve)(u64 start, u64 end);
13564 -};
13565 +} __no_const;
13566
13567 /**
13568 * struct x86_init_paging - platform specific paging functions
13569 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13570 struct x86_init_paging {
13571 void (*pagetable_setup_start)(pgd_t *base);
13572 void (*pagetable_setup_done)(pgd_t *base);
13573 -};
13574 +} __no_const;
13575
13576 /**
13577 * struct x86_init_timers - platform specific timer setup
13578 @@ -102,7 +102,7 @@ struct x86_init_timers {
13579 void (*tsc_pre_init)(void);
13580 void (*timer_init)(void);
13581 void (*wallclock_init)(void);
13582 -};
13583 +} __no_const;
13584
13585 /**
13586 * struct x86_init_iommu - platform specific iommu setup
13587 @@ -110,7 +110,7 @@ struct x86_init_timers {
13588 */
13589 struct x86_init_iommu {
13590 int (*iommu_init)(void);
13591 -};
13592 +} __no_const;
13593
13594 /**
13595 * struct x86_init_pci - platform specific pci init functions
13596 @@ -124,7 +124,7 @@ struct x86_init_pci {
13597 int (*init)(void);
13598 void (*init_irq)(void);
13599 void (*fixup_irqs)(void);
13600 -};
13601 +} __no_const;
13602
13603 /**
13604 * struct x86_init_ops - functions for platform specific setup
13605 @@ -140,7 +140,7 @@ struct x86_init_ops {
13606 struct x86_init_timers timers;
13607 struct x86_init_iommu iommu;
13608 struct x86_init_pci pci;
13609 -};
13610 +} __no_const;
13611
13612 /**
13613 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13614 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13615 void (*setup_percpu_clockev)(void);
13616 void (*early_percpu_clock_init)(void);
13617 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13618 -};
13619 +} __no_const;
13620
13621 /**
13622 * struct x86_platform_ops - platform specific runtime functions
13623 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13624 int (*i8042_detect)(void);
13625 void (*save_sched_clock_state)(void);
13626 void (*restore_sched_clock_state)(void);
13627 -};
13628 +} __no_const;
13629
13630 struct pci_dev;
13631
13632 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13633 void (*teardown_msi_irq)(unsigned int irq);
13634 void (*teardown_msi_irqs)(struct pci_dev *dev);
13635 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13636 -};
13637 +} __no_const;
13638
13639 struct x86_io_apic_ops {
13640 void (*init) (void);
13641 unsigned int (*read) (unsigned int apic, unsigned int reg);
13642 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13643 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13644 -};
13645 +} __no_const;
13646
13647 extern struct x86_init_ops x86_init;
13648 extern struct x86_cpuinit_ops x86_cpuinit;
13649 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13650 index 8a1b6f9..a29c4e4 100644
13651 --- a/arch/x86/include/asm/xsave.h
13652 +++ b/arch/x86/include/asm/xsave.h
13653 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13654 {
13655 int err;
13656
13657 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13658 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13659 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13660 +#endif
13661 +
13662 /*
13663 * Clear the xsave header first, so that reserved fields are
13664 * initialized to zero.
13665 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13666 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13667 {
13668 int err;
13669 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13670 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13671 u32 lmask = mask;
13672 u32 hmask = mask >> 32;
13673
13674 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13675 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13676 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13677 +#endif
13678 +
13679 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13680 "2:\n"
13681 ".section .fixup,\"ax\"\n"
13682 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13683 index 95bf99de..de9235c 100644
13684 --- a/arch/x86/kernel/acpi/sleep.c
13685 +++ b/arch/x86/kernel/acpi/sleep.c
13686 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13687 #else /* CONFIG_64BIT */
13688 #ifdef CONFIG_SMP
13689 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13690 +
13691 + pax_open_kernel();
13692 early_gdt_descr.address =
13693 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13694 + pax_close_kernel();
13695 +
13696 initial_gs = per_cpu_offset(smp_processor_id());
13697 #endif
13698 initial_code = (unsigned long)wakeup_long64;
13699 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13700 index 7261083..5c12053 100644
13701 --- a/arch/x86/kernel/acpi/wakeup_32.S
13702 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13703 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13704 # and restore the stack ... but you need gdt for this to work
13705 movl saved_context_esp, %esp
13706
13707 - movl %cs:saved_magic, %eax
13708 - cmpl $0x12345678, %eax
13709 + cmpl $0x12345678, saved_magic
13710 jne bogus_magic
13711
13712 # jump to place where we left off
13713 - movl saved_eip, %eax
13714 - jmp *%eax
13715 + jmp *(saved_eip)
13716
13717 bogus_magic:
13718 jmp bogus_magic
13719 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13720 index 73ef56c..0238021 100644
13721 --- a/arch/x86/kernel/alternative.c
13722 +++ b/arch/x86/kernel/alternative.c
13723 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13724 */
13725 for (a = start; a < end; a++) {
13726 instr = (u8 *)&a->instr_offset + a->instr_offset;
13727 +
13728 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13729 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13730 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13731 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13732 +#endif
13733 +
13734 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13735 BUG_ON(a->replacementlen > a->instrlen);
13736 BUG_ON(a->instrlen > sizeof(insnbuf));
13737 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13738 for (poff = start; poff < end; poff++) {
13739 u8 *ptr = (u8 *)poff + *poff;
13740
13741 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13742 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13743 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13744 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13745 +#endif
13746 +
13747 if (!*poff || ptr < text || ptr >= text_end)
13748 continue;
13749 /* turn DS segment override prefix into lock prefix */
13750 - if (*ptr == 0x3e)
13751 + if (*ktla_ktva(ptr) == 0x3e)
13752 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13753 };
13754 mutex_unlock(&text_mutex);
13755 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13756 for (poff = start; poff < end; poff++) {
13757 u8 *ptr = (u8 *)poff + *poff;
13758
13759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13760 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13761 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13762 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13763 +#endif
13764 +
13765 if (!*poff || ptr < text || ptr >= text_end)
13766 continue;
13767 /* turn lock prefix into DS segment override prefix */
13768 - if (*ptr == 0xf0)
13769 + if (*ktla_ktva(ptr) == 0xf0)
13770 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13771 };
13772 mutex_unlock(&text_mutex);
13773 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13774
13775 BUG_ON(p->len > MAX_PATCH_LEN);
13776 /* prep the buffer with the original instructions */
13777 - memcpy(insnbuf, p->instr, p->len);
13778 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13779 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13780 (unsigned long)p->instr, p->len);
13781
13782 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13783 if (smp_alt_once)
13784 free_init_pages("SMP alternatives",
13785 (unsigned long)__smp_locks,
13786 - (unsigned long)__smp_locks_end);
13787 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13788
13789 restart_nmi();
13790 }
13791 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13792 * instructions. And on the local CPU you need to be protected again NMI or MCE
13793 * handlers seeing an inconsistent instruction while you patch.
13794 */
13795 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13796 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13797 size_t len)
13798 {
13799 unsigned long flags;
13800 local_irq_save(flags);
13801 - memcpy(addr, opcode, len);
13802 +
13803 + pax_open_kernel();
13804 + memcpy(ktla_ktva(addr), opcode, len);
13805 sync_core();
13806 + pax_close_kernel();
13807 +
13808 local_irq_restore(flags);
13809 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13810 that causes hangs on some VIA CPUs. */
13811 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13812 */
13813 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13814 {
13815 - unsigned long flags;
13816 - char *vaddr;
13817 + unsigned char *vaddr = ktla_ktva(addr);
13818 struct page *pages[2];
13819 - int i;
13820 + size_t i;
13821
13822 if (!core_kernel_text((unsigned long)addr)) {
13823 - pages[0] = vmalloc_to_page(addr);
13824 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13825 + pages[0] = vmalloc_to_page(vaddr);
13826 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13827 } else {
13828 - pages[0] = virt_to_page(addr);
13829 + pages[0] = virt_to_page(vaddr);
13830 WARN_ON(!PageReserved(pages[0]));
13831 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13832 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13833 }
13834 BUG_ON(!pages[0]);
13835 - local_irq_save(flags);
13836 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13837 - if (pages[1])
13838 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13839 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13840 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13841 - clear_fixmap(FIX_TEXT_POKE0);
13842 - if (pages[1])
13843 - clear_fixmap(FIX_TEXT_POKE1);
13844 - local_flush_tlb();
13845 - sync_core();
13846 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13847 - that causes hangs on some VIA CPUs. */
13848 + text_poke_early(addr, opcode, len);
13849 for (i = 0; i < len; i++)
13850 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13851 - local_irq_restore(flags);
13852 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13853 return addr;
13854 }
13855
13856 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13857 index 39a222e..85a7767 100644
13858 --- a/arch/x86/kernel/apic/apic.c
13859 +++ b/arch/x86/kernel/apic/apic.c
13860 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13861 /*
13862 * Debug level, exported for io_apic.c
13863 */
13864 -unsigned int apic_verbosity;
13865 +int apic_verbosity;
13866
13867 int pic_mode;
13868
13869 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13870 apic_write(APIC_ESR, 0);
13871 v1 = apic_read(APIC_ESR);
13872 ack_APIC_irq();
13873 - atomic_inc(&irq_err_count);
13874 + atomic_inc_unchecked(&irq_err_count);
13875
13876 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13877 smp_processor_id(), v0 , v1);
13878 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13879 index 5f0ff59..f9e01bc 100644
13880 --- a/arch/x86/kernel/apic/io_apic.c
13881 +++ b/arch/x86/kernel/apic/io_apic.c
13882 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13883 }
13884 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13885
13886 -void lock_vector_lock(void)
13887 +void lock_vector_lock(void) __acquires(vector_lock)
13888 {
13889 /* Used to the online set of cpus does not change
13890 * during assign_irq_vector.
13891 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13892 raw_spin_lock(&vector_lock);
13893 }
13894
13895 -void unlock_vector_lock(void)
13896 +void unlock_vector_lock(void) __releases(vector_lock)
13897 {
13898 raw_spin_unlock(&vector_lock);
13899 }
13900 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13901 ack_APIC_irq();
13902 }
13903
13904 -atomic_t irq_mis_count;
13905 +atomic_unchecked_t irq_mis_count;
13906
13907 #ifdef CONFIG_GENERIC_PENDING_IRQ
13908 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13909 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13910 * at the cpu.
13911 */
13912 if (!(v & (1 << (i & 0x1f)))) {
13913 - atomic_inc(&irq_mis_count);
13914 + atomic_inc_unchecked(&irq_mis_count);
13915
13916 eoi_ioapic_irq(irq, cfg);
13917 }
13918 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13919 index 07b0c0d..1df6f42 100644
13920 --- a/arch/x86/kernel/apm_32.c
13921 +++ b/arch/x86/kernel/apm_32.c
13922 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13923 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13924 * even though they are called in protected mode.
13925 */
13926 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13927 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13928 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13929
13930 static const char driver_version[] = "1.16ac"; /* no spaces */
13931 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13932 BUG_ON(cpu != 0);
13933 gdt = get_cpu_gdt_table(cpu);
13934 save_desc_40 = gdt[0x40 / 8];
13935 +
13936 + pax_open_kernel();
13937 gdt[0x40 / 8] = bad_bios_desc;
13938 + pax_close_kernel();
13939
13940 apm_irq_save(flags);
13941 APM_DO_SAVE_SEGS;
13942 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13943 &call->esi);
13944 APM_DO_RESTORE_SEGS;
13945 apm_irq_restore(flags);
13946 +
13947 + pax_open_kernel();
13948 gdt[0x40 / 8] = save_desc_40;
13949 + pax_close_kernel();
13950 +
13951 put_cpu();
13952
13953 return call->eax & 0xff;
13954 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13955 BUG_ON(cpu != 0);
13956 gdt = get_cpu_gdt_table(cpu);
13957 save_desc_40 = gdt[0x40 / 8];
13958 +
13959 + pax_open_kernel();
13960 gdt[0x40 / 8] = bad_bios_desc;
13961 + pax_close_kernel();
13962
13963 apm_irq_save(flags);
13964 APM_DO_SAVE_SEGS;
13965 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13966 &call->eax);
13967 APM_DO_RESTORE_SEGS;
13968 apm_irq_restore(flags);
13969 +
13970 + pax_open_kernel();
13971 gdt[0x40 / 8] = save_desc_40;
13972 + pax_close_kernel();
13973 +
13974 put_cpu();
13975 return error;
13976 }
13977 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13978 * code to that CPU.
13979 */
13980 gdt = get_cpu_gdt_table(0);
13981 +
13982 + pax_open_kernel();
13983 set_desc_base(&gdt[APM_CS >> 3],
13984 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13985 set_desc_base(&gdt[APM_CS_16 >> 3],
13986 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13987 set_desc_base(&gdt[APM_DS >> 3],
13988 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13989 + pax_close_kernel();
13990
13991 proc_create("apm", 0, NULL, &apm_file_ops);
13992
13993 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13994 index 68de2dc..1f3c720 100644
13995 --- a/arch/x86/kernel/asm-offsets.c
13996 +++ b/arch/x86/kernel/asm-offsets.c
13997 @@ -33,6 +33,8 @@ void common(void) {
13998 OFFSET(TI_status, thread_info, status);
13999 OFFSET(TI_addr_limit, thread_info, addr_limit);
14000 OFFSET(TI_preempt_count, thread_info, preempt_count);
14001 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14002 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14003
14004 BLANK();
14005 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14006 @@ -53,8 +55,26 @@ void common(void) {
14007 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14008 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14009 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14010 +
14011 +#ifdef CONFIG_PAX_KERNEXEC
14012 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14013 #endif
14014
14015 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14016 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14017 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14018 +#ifdef CONFIG_X86_64
14019 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14020 +#endif
14021 +#endif
14022 +
14023 +#endif
14024 +
14025 + BLANK();
14026 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14027 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14028 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14029 +
14030 #ifdef CONFIG_XEN
14031 BLANK();
14032 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14033 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14034 index 1b4754f..fbb4227 100644
14035 --- a/arch/x86/kernel/asm-offsets_64.c
14036 +++ b/arch/x86/kernel/asm-offsets_64.c
14037 @@ -76,6 +76,7 @@ int main(void)
14038 BLANK();
14039 #undef ENTRY
14040
14041 + DEFINE(TSS_size, sizeof(struct tss_struct));
14042 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14043 BLANK();
14044
14045 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14046 index 6ab6aa2..8f71507 100644
14047 --- a/arch/x86/kernel/cpu/Makefile
14048 +++ b/arch/x86/kernel/cpu/Makefile
14049 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14050 CFLAGS_REMOVE_perf_event.o = -pg
14051 endif
14052
14053 -# Make sure load_percpu_segment has no stackprotector
14054 -nostackp := $(call cc-option, -fno-stack-protector)
14055 -CFLAGS_common.o := $(nostackp)
14056 -
14057 obj-y := intel_cacheinfo.o scattered.o topology.o
14058 obj-y += proc.o capflags.o powerflags.o common.o
14059 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14060 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14061 index 146bb62..ac9c74a 100644
14062 --- a/arch/x86/kernel/cpu/amd.c
14063 +++ b/arch/x86/kernel/cpu/amd.c
14064 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14065 unsigned int size)
14066 {
14067 /* AMD errata T13 (order #21922) */
14068 - if ((c->x86 == 6)) {
14069 + if (c->x86 == 6) {
14070 /* Duron Rev A0 */
14071 if (c->x86_model == 3 && c->x86_mask == 0)
14072 size = 64;
14073 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14074 index 6b9333b..4c3083a 100644
14075 --- a/arch/x86/kernel/cpu/common.c
14076 +++ b/arch/x86/kernel/cpu/common.c
14077 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14078
14079 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14080
14081 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14082 -#ifdef CONFIG_X86_64
14083 - /*
14084 - * We need valid kernel segments for data and code in long mode too
14085 - * IRET will check the segment types kkeil 2000/10/28
14086 - * Also sysret mandates a special GDT layout
14087 - *
14088 - * TLS descriptors are currently at a different place compared to i386.
14089 - * Hopefully nobody expects them at a fixed place (Wine?)
14090 - */
14091 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14092 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14093 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14094 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14095 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14096 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14097 -#else
14098 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14099 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14100 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14101 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14102 - /*
14103 - * Segments used for calling PnP BIOS have byte granularity.
14104 - * They code segments and data segments have fixed 64k limits,
14105 - * the transfer segment sizes are set at run time.
14106 - */
14107 - /* 32-bit code */
14108 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14109 - /* 16-bit code */
14110 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14111 - /* 16-bit data */
14112 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14113 - /* 16-bit data */
14114 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14115 - /* 16-bit data */
14116 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14117 - /*
14118 - * The APM segments have byte granularity and their bases
14119 - * are set at run time. All have 64k limits.
14120 - */
14121 - /* 32-bit code */
14122 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14123 - /* 16-bit code */
14124 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14125 - /* data */
14126 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14127 -
14128 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14129 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14130 - GDT_STACK_CANARY_INIT
14131 -#endif
14132 -} };
14133 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14134 -
14135 static int __init x86_xsave_setup(char *s)
14136 {
14137 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14138 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14139 {
14140 struct desc_ptr gdt_descr;
14141
14142 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14143 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14144 gdt_descr.size = GDT_SIZE - 1;
14145 load_gdt(&gdt_descr);
14146 /* Reload the per-cpu base */
14147 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14148 /* Filter out anything that depends on CPUID levels we don't have */
14149 filter_cpuid_features(c, true);
14150
14151 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14152 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14153 +#endif
14154 +
14155 /* If the model name is still unset, do table lookup. */
14156 if (!c->x86_model_id[0]) {
14157 const char *p;
14158 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14159 }
14160 __setup("clearcpuid=", setup_disablecpuid);
14161
14162 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14163 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14164 +
14165 #ifdef CONFIG_X86_64
14166 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14167 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14168 - (unsigned long) nmi_idt_table };
14169 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14170
14171 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14172 irq_stack_union) __aligned(PAGE_SIZE);
14173 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14174 EXPORT_PER_CPU_SYMBOL(current_task);
14175
14176 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14177 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14178 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14179 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14180
14181 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14182 @@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14183 {
14184 memset(regs, 0, sizeof(struct pt_regs));
14185 regs->fs = __KERNEL_PERCPU;
14186 - regs->gs = __KERNEL_STACK_CANARY;
14187 + savesegment(gs, regs->gs);
14188
14189 return regs;
14190 }
14191 @@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14192 int i;
14193
14194 cpu = stack_smp_processor_id();
14195 - t = &per_cpu(init_tss, cpu);
14196 + t = init_tss + cpu;
14197 oist = &per_cpu(orig_ist, cpu);
14198
14199 #ifdef CONFIG_NUMA
14200 @@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14201 switch_to_new_gdt(cpu);
14202 loadsegment(fs, 0);
14203
14204 - load_idt((const struct desc_ptr *)&idt_descr);
14205 + load_idt(&idt_descr);
14206
14207 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14208 syscall_init();
14209 @@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14210 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14211 barrier();
14212
14213 - x86_configure_nx();
14214 if (cpu != 0)
14215 enable_x2apic();
14216
14217 @@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14218 {
14219 int cpu = smp_processor_id();
14220 struct task_struct *curr = current;
14221 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14222 + struct tss_struct *t = init_tss + cpu;
14223 struct thread_struct *thread = &curr->thread;
14224
14225 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14226 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14227 index 3e6ff6c..54b4992 100644
14228 --- a/arch/x86/kernel/cpu/intel.c
14229 +++ b/arch/x86/kernel/cpu/intel.c
14230 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14231 * Update the IDT descriptor and reload the IDT so that
14232 * it uses the read-only mapped virtual address.
14233 */
14234 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14235 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14236 load_idt(&idt_descr);
14237 }
14238 #endif
14239 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14240 index c46ed49..5dc0a53 100644
14241 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14242 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14243 @@ -42,6 +42,7 @@
14244 #include <asm/processor.h>
14245 #include <asm/mce.h>
14246 #include <asm/msr.h>
14247 +#include <asm/local.h>
14248
14249 #include "mce-internal.h"
14250
14251 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14252 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14253 m->cs, m->ip);
14254
14255 - if (m->cs == __KERNEL_CS)
14256 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14257 print_symbol("{%s}", m->ip);
14258 pr_cont("\n");
14259 }
14260 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14261
14262 #define PANIC_TIMEOUT 5 /* 5 seconds */
14263
14264 -static atomic_t mce_paniced;
14265 +static atomic_unchecked_t mce_paniced;
14266
14267 static int fake_panic;
14268 -static atomic_t mce_fake_paniced;
14269 +static atomic_unchecked_t mce_fake_paniced;
14270
14271 /* Panic in progress. Enable interrupts and wait for final IPI */
14272 static void wait_for_panic(void)
14273 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14274 /*
14275 * Make sure only one CPU runs in machine check panic
14276 */
14277 - if (atomic_inc_return(&mce_paniced) > 1)
14278 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14279 wait_for_panic();
14280 barrier();
14281
14282 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14283 console_verbose();
14284 } else {
14285 /* Don't log too much for fake panic */
14286 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14287 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14288 return;
14289 }
14290 /* First print corrected ones that are still unlogged */
14291 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14292 * might have been modified by someone else.
14293 */
14294 rmb();
14295 - if (atomic_read(&mce_paniced))
14296 + if (atomic_read_unchecked(&mce_paniced))
14297 wait_for_panic();
14298 if (!monarch_timeout)
14299 goto out;
14300 @@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14301 }
14302
14303 /* Call the installed machine check handler for this CPU setup. */
14304 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14305 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14306 unexpected_machine_check;
14307
14308 /*
14309 @@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14310 return;
14311 }
14312
14313 + pax_open_kernel();
14314 machine_check_vector = do_machine_check;
14315 + pax_close_kernel();
14316
14317 __mcheck_cpu_init_generic();
14318 __mcheck_cpu_init_vendor(c);
14319 @@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14320 */
14321
14322 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14323 -static int mce_chrdev_open_count; /* #times opened */
14324 +static local_t mce_chrdev_open_count; /* #times opened */
14325 static int mce_chrdev_open_exclu; /* already open exclusive? */
14326
14327 static int mce_chrdev_open(struct inode *inode, struct file *file)
14328 @@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14329 spin_lock(&mce_chrdev_state_lock);
14330
14331 if (mce_chrdev_open_exclu ||
14332 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14333 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14334 spin_unlock(&mce_chrdev_state_lock);
14335
14336 return -EBUSY;
14337 @@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14338
14339 if (file->f_flags & O_EXCL)
14340 mce_chrdev_open_exclu = 1;
14341 - mce_chrdev_open_count++;
14342 + local_inc(&mce_chrdev_open_count);
14343
14344 spin_unlock(&mce_chrdev_state_lock);
14345
14346 @@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14347 {
14348 spin_lock(&mce_chrdev_state_lock);
14349
14350 - mce_chrdev_open_count--;
14351 + local_dec(&mce_chrdev_open_count);
14352 mce_chrdev_open_exclu = 0;
14353
14354 spin_unlock(&mce_chrdev_state_lock);
14355 @@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14356 static void mce_reset(void)
14357 {
14358 cpu_missing = 0;
14359 - atomic_set(&mce_fake_paniced, 0);
14360 + atomic_set_unchecked(&mce_fake_paniced, 0);
14361 atomic_set(&mce_executing, 0);
14362 atomic_set(&mce_callin, 0);
14363 atomic_set(&global_nwo, 0);
14364 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14365 index 2d5454c..51987eb 100644
14366 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14367 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14368 @@ -11,6 +11,7 @@
14369 #include <asm/processor.h>
14370 #include <asm/mce.h>
14371 #include <asm/msr.h>
14372 +#include <asm/pgtable.h>
14373
14374 /* By default disabled */
14375 int mce_p5_enabled __read_mostly;
14376 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14377 if (!cpu_has(c, X86_FEATURE_MCE))
14378 return;
14379
14380 + pax_open_kernel();
14381 machine_check_vector = pentium_machine_check;
14382 + pax_close_kernel();
14383 /* Make sure the vector pointer is visible before we enable MCEs: */
14384 wmb();
14385
14386 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14387 index 2d7998f..17c9de1 100644
14388 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14389 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14390 @@ -10,6 +10,7 @@
14391 #include <asm/processor.h>
14392 #include <asm/mce.h>
14393 #include <asm/msr.h>
14394 +#include <asm/pgtable.h>
14395
14396 /* Machine check handler for WinChip C6: */
14397 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14398 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14399 {
14400 u32 lo, hi;
14401
14402 + pax_open_kernel();
14403 machine_check_vector = winchip_machine_check;
14404 + pax_close_kernel();
14405 /* Make sure the vector pointer is visible before we enable MCEs: */
14406 wmb();
14407
14408 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14409 index 6b96110..0da73eb 100644
14410 --- a/arch/x86/kernel/cpu/mtrr/main.c
14411 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14412 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14413 u64 size_or_mask, size_and_mask;
14414 static bool mtrr_aps_delayed_init;
14415
14416 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14417 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14418
14419 const struct mtrr_ops *mtrr_if;
14420
14421 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14422 index df5e41f..816c719 100644
14423 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14424 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14425 @@ -25,7 +25,7 @@ struct mtrr_ops {
14426 int (*validate_add_page)(unsigned long base, unsigned long size,
14427 unsigned int type);
14428 int (*have_wrcomb)(void);
14429 -};
14430 +} __do_const;
14431
14432 extern int generic_get_free_region(unsigned long base, unsigned long size,
14433 int replace_reg);
14434 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14435 index c4706cf..264b0f7 100644
14436 --- a/arch/x86/kernel/cpu/perf_event.c
14437 +++ b/arch/x86/kernel/cpu/perf_event.c
14438 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14439 break;
14440
14441 perf_callchain_store(entry, frame.return_address);
14442 - fp = frame.next_frame;
14443 + fp = (const void __force_user *)frame.next_frame;
14444 }
14445 }
14446
14447 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14448 index 13ad899..f642b9a 100644
14449 --- a/arch/x86/kernel/crash.c
14450 +++ b/arch/x86/kernel/crash.c
14451 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14452 {
14453 #ifdef CONFIG_X86_32
14454 struct pt_regs fixed_regs;
14455 -#endif
14456
14457 -#ifdef CONFIG_X86_32
14458 - if (!user_mode_vm(regs)) {
14459 + if (!user_mode(regs)) {
14460 crash_fixup_ss_esp(&fixed_regs, regs);
14461 regs = &fixed_regs;
14462 }
14463 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14464 index 37250fe..bf2ec74 100644
14465 --- a/arch/x86/kernel/doublefault_32.c
14466 +++ b/arch/x86/kernel/doublefault_32.c
14467 @@ -11,7 +11,7 @@
14468
14469 #define DOUBLEFAULT_STACKSIZE (1024)
14470 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14471 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14472 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14473
14474 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14475
14476 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14477 unsigned long gdt, tss;
14478
14479 store_gdt(&gdt_desc);
14480 - gdt = gdt_desc.address;
14481 + gdt = (unsigned long)gdt_desc.address;
14482
14483 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14484
14485 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14486 /* 0x2 bit is always set */
14487 .flags = X86_EFLAGS_SF | 0x2,
14488 .sp = STACK_START,
14489 - .es = __USER_DS,
14490 + .es = __KERNEL_DS,
14491 .cs = __KERNEL_CS,
14492 .ss = __KERNEL_DS,
14493 - .ds = __USER_DS,
14494 + .ds = __KERNEL_DS,
14495 .fs = __KERNEL_PERCPU,
14496
14497 .__cr3 = __pa_nodebug(swapper_pg_dir),
14498 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14499 index 571246d..81f335c 100644
14500 --- a/arch/x86/kernel/dumpstack.c
14501 +++ b/arch/x86/kernel/dumpstack.c
14502 @@ -2,6 +2,9 @@
14503 * Copyright (C) 1991, 1992 Linus Torvalds
14504 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14505 */
14506 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14507 +#define __INCLUDED_BY_HIDESYM 1
14508 +#endif
14509 #include <linux/kallsyms.h>
14510 #include <linux/kprobes.h>
14511 #include <linux/uaccess.h>
14512 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14513 static void
14514 print_ftrace_graph_addr(unsigned long addr, void *data,
14515 const struct stacktrace_ops *ops,
14516 - struct thread_info *tinfo, int *graph)
14517 + struct task_struct *task, int *graph)
14518 {
14519 - struct task_struct *task;
14520 unsigned long ret_addr;
14521 int index;
14522
14523 if (addr != (unsigned long)return_to_handler)
14524 return;
14525
14526 - task = tinfo->task;
14527 index = task->curr_ret_stack;
14528
14529 if (!task->ret_stack || index < *graph)
14530 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14531 static inline void
14532 print_ftrace_graph_addr(unsigned long addr, void *data,
14533 const struct stacktrace_ops *ops,
14534 - struct thread_info *tinfo, int *graph)
14535 + struct task_struct *task, int *graph)
14536 { }
14537 #endif
14538
14539 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14540 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14541 */
14542
14543 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14544 - void *p, unsigned int size, void *end)
14545 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14546 {
14547 - void *t = tinfo;
14548 if (end) {
14549 if (p < end && p >= (end-THREAD_SIZE))
14550 return 1;
14551 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14552 }
14553
14554 unsigned long
14555 -print_context_stack(struct thread_info *tinfo,
14556 +print_context_stack(struct task_struct *task, void *stack_start,
14557 unsigned long *stack, unsigned long bp,
14558 const struct stacktrace_ops *ops, void *data,
14559 unsigned long *end, int *graph)
14560 {
14561 struct stack_frame *frame = (struct stack_frame *)bp;
14562
14563 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14564 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14565 unsigned long addr;
14566
14567 addr = *stack;
14568 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14569 } else {
14570 ops->address(data, addr, 0);
14571 }
14572 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14573 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14574 }
14575 stack++;
14576 }
14577 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14578 EXPORT_SYMBOL_GPL(print_context_stack);
14579
14580 unsigned long
14581 -print_context_stack_bp(struct thread_info *tinfo,
14582 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14583 unsigned long *stack, unsigned long bp,
14584 const struct stacktrace_ops *ops, void *data,
14585 unsigned long *end, int *graph)
14586 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14587 struct stack_frame *frame = (struct stack_frame *)bp;
14588 unsigned long *ret_addr = &frame->return_address;
14589
14590 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14591 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14592 unsigned long addr = *ret_addr;
14593
14594 if (!__kernel_text_address(addr))
14595 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14596 ops->address(data, addr, 1);
14597 frame = frame->next_frame;
14598 ret_addr = &frame->return_address;
14599 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14600 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14601 }
14602
14603 return (unsigned long)frame;
14604 @@ -189,7 +188,7 @@ void dump_stack(void)
14605
14606 bp = stack_frame(current, NULL);
14607 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14608 - current->pid, current->comm, print_tainted(),
14609 + task_pid_nr(current), current->comm, print_tainted(),
14610 init_utsname()->release,
14611 (int)strcspn(init_utsname()->version, " "),
14612 init_utsname()->version);
14613 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14614 }
14615 EXPORT_SYMBOL_GPL(oops_begin);
14616
14617 +extern void gr_handle_kernel_exploit(void);
14618 +
14619 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14620 {
14621 if (regs && kexec_should_crash(current))
14622 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14623 panic("Fatal exception in interrupt");
14624 if (panic_on_oops)
14625 panic("Fatal exception");
14626 - do_exit(signr);
14627 +
14628 + gr_handle_kernel_exploit();
14629 +
14630 + do_group_exit(signr);
14631 }
14632
14633 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14634 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14635
14636 show_regs(regs);
14637 #ifdef CONFIG_X86_32
14638 - if (user_mode_vm(regs)) {
14639 + if (user_mode(regs)) {
14640 sp = regs->sp;
14641 ss = regs->ss & 0xffff;
14642 } else {
14643 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14644 unsigned long flags = oops_begin();
14645 int sig = SIGSEGV;
14646
14647 - if (!user_mode_vm(regs))
14648 + if (!user_mode(regs))
14649 report_bug(regs->ip, regs);
14650
14651 if (__die(str, regs, err))
14652 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14653 index e0b1d78..a8ade5e 100644
14654 --- a/arch/x86/kernel/dumpstack_32.c
14655 +++ b/arch/x86/kernel/dumpstack_32.c
14656 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14657 bp = stack_frame(task, regs);
14658
14659 for (;;) {
14660 - struct thread_info *context;
14661 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14662
14663 - context = (struct thread_info *)
14664 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14665 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14666 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14667
14668 - stack = (unsigned long *)context->previous_esp;
14669 - if (!stack)
14670 + if (stack_start == task_stack_page(task))
14671 break;
14672 + stack = *(unsigned long **)stack_start;
14673 if (ops->stack(data, "IRQ") < 0)
14674 break;
14675 touch_nmi_watchdog();
14676 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14677 int i;
14678
14679 print_modules();
14680 - __show_regs(regs, !user_mode_vm(regs));
14681 + __show_regs(regs, !user_mode(regs));
14682
14683 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14684 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14685 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14686 * When in-kernel, we also print out the stack and code at the
14687 * time of the fault..
14688 */
14689 - if (!user_mode_vm(regs)) {
14690 + if (!user_mode(regs)) {
14691 unsigned int code_prologue = code_bytes * 43 / 64;
14692 unsigned int code_len = code_bytes;
14693 unsigned char c;
14694 u8 *ip;
14695 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14696
14697 printk(KERN_EMERG "Stack:\n");
14698 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14699
14700 printk(KERN_EMERG "Code: ");
14701
14702 - ip = (u8 *)regs->ip - code_prologue;
14703 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14704 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14705 /* try starting at IP */
14706 - ip = (u8 *)regs->ip;
14707 + ip = (u8 *)regs->ip + cs_base;
14708 code_len = code_len - code_prologue + 1;
14709 }
14710 for (i = 0; i < code_len; i++, ip++) {
14711 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14712 printk(KERN_CONT " Bad EIP value.");
14713 break;
14714 }
14715 - if (ip == (u8 *)regs->ip)
14716 + if (ip == (u8 *)regs->ip + cs_base)
14717 printk(KERN_CONT "<%02x> ", c);
14718 else
14719 printk(KERN_CONT "%02x ", c);
14720 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14721 {
14722 unsigned short ud2;
14723
14724 + ip = ktla_ktva(ip);
14725 if (ip < PAGE_OFFSET)
14726 return 0;
14727 if (probe_kernel_address((unsigned short *)ip, ud2))
14728 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14729
14730 return ud2 == 0x0b0f;
14731 }
14732 +
14733 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14734 +void pax_check_alloca(unsigned long size)
14735 +{
14736 + unsigned long sp = (unsigned long)&sp, stack_left;
14737 +
14738 + /* all kernel stacks are of the same size */
14739 + stack_left = sp & (THREAD_SIZE - 1);
14740 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14741 +}
14742 +EXPORT_SYMBOL(pax_check_alloca);
14743 +#endif
14744 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14745 index 791b761..2ab6e33 100644
14746 --- a/arch/x86/kernel/dumpstack_64.c
14747 +++ b/arch/x86/kernel/dumpstack_64.c
14748 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14749 unsigned long *irq_stack_end =
14750 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14751 unsigned used = 0;
14752 - struct thread_info *tinfo;
14753 int graph = 0;
14754 unsigned long dummy;
14755 + void *stack_start;
14756
14757 if (!task)
14758 task = current;
14759 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14760 * current stack address. If the stacks consist of nested
14761 * exceptions
14762 */
14763 - tinfo = task_thread_info(task);
14764 for (;;) {
14765 char *id;
14766 unsigned long *estack_end;
14767 +
14768 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14769 &used, &id);
14770
14771 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14772 if (ops->stack(data, id) < 0)
14773 break;
14774
14775 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14776 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14777 data, estack_end, &graph);
14778 ops->stack(data, "<EOE>");
14779 /*
14780 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14781 * second-to-last pointer (index -2 to end) in the
14782 * exception stack:
14783 */
14784 + if ((u16)estack_end[-1] != __KERNEL_DS)
14785 + goto out;
14786 stack = (unsigned long *) estack_end[-2];
14787 continue;
14788 }
14789 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14790 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14791 if (ops->stack(data, "IRQ") < 0)
14792 break;
14793 - bp = ops->walk_stack(tinfo, stack, bp,
14794 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14795 ops, data, irq_stack_end, &graph);
14796 /*
14797 * We link to the next stack (which would be
14798 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14799 /*
14800 * This handles the process stack:
14801 */
14802 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14803 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14804 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14805 +out:
14806 put_cpu();
14807 }
14808 EXPORT_SYMBOL(dump_trace);
14809 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14810
14811 return ud2 == 0x0b0f;
14812 }
14813 +
14814 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14815 +void pax_check_alloca(unsigned long size)
14816 +{
14817 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14818 + unsigned cpu, used;
14819 + char *id;
14820 +
14821 + /* check the process stack first */
14822 + stack_start = (unsigned long)task_stack_page(current);
14823 + stack_end = stack_start + THREAD_SIZE;
14824 + if (likely(stack_start <= sp && sp < stack_end)) {
14825 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14826 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14827 + return;
14828 + }
14829 +
14830 + cpu = get_cpu();
14831 +
14832 + /* check the irq stacks */
14833 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14834 + stack_start = stack_end - IRQ_STACK_SIZE;
14835 + if (stack_start <= sp && sp < stack_end) {
14836 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14837 + put_cpu();
14838 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14839 + return;
14840 + }
14841 +
14842 + /* check the exception stacks */
14843 + used = 0;
14844 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14845 + stack_start = stack_end - EXCEPTION_STKSZ;
14846 + if (stack_end && stack_start <= sp && sp < stack_end) {
14847 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14848 + put_cpu();
14849 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14850 + return;
14851 + }
14852 +
14853 + put_cpu();
14854 +
14855 + /* unknown stack */
14856 + BUG();
14857 +}
14858 +EXPORT_SYMBOL(pax_check_alloca);
14859 +#endif
14860 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14861 index 9b9f18b..9fcaa04 100644
14862 --- a/arch/x86/kernel/early_printk.c
14863 +++ b/arch/x86/kernel/early_printk.c
14864 @@ -7,6 +7,7 @@
14865 #include <linux/pci_regs.h>
14866 #include <linux/pci_ids.h>
14867 #include <linux/errno.h>
14868 +#include <linux/sched.h>
14869 #include <asm/io.h>
14870 #include <asm/processor.h>
14871 #include <asm/fcntl.h>
14872 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14873 index 623f288..8bdd78a 100644
14874 --- a/arch/x86/kernel/entry_32.S
14875 +++ b/arch/x86/kernel/entry_32.S
14876 @@ -176,13 +176,153 @@
14877 /*CFI_REL_OFFSET gs, PT_GS*/
14878 .endm
14879 .macro SET_KERNEL_GS reg
14880 +
14881 +#ifdef CONFIG_CC_STACKPROTECTOR
14882 movl $(__KERNEL_STACK_CANARY), \reg
14883 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14884 + movl $(__USER_DS), \reg
14885 +#else
14886 + xorl \reg, \reg
14887 +#endif
14888 +
14889 movl \reg, %gs
14890 .endm
14891
14892 #endif /* CONFIG_X86_32_LAZY_GS */
14893
14894 -.macro SAVE_ALL
14895 +.macro pax_enter_kernel
14896 +#ifdef CONFIG_PAX_KERNEXEC
14897 + call pax_enter_kernel
14898 +#endif
14899 +.endm
14900 +
14901 +.macro pax_exit_kernel
14902 +#ifdef CONFIG_PAX_KERNEXEC
14903 + call pax_exit_kernel
14904 +#endif
14905 +.endm
14906 +
14907 +#ifdef CONFIG_PAX_KERNEXEC
14908 +ENTRY(pax_enter_kernel)
14909 +#ifdef CONFIG_PARAVIRT
14910 + pushl %eax
14911 + pushl %ecx
14912 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14913 + mov %eax, %esi
14914 +#else
14915 + mov %cr0, %esi
14916 +#endif
14917 + bts $16, %esi
14918 + jnc 1f
14919 + mov %cs, %esi
14920 + cmp $__KERNEL_CS, %esi
14921 + jz 3f
14922 + ljmp $__KERNEL_CS, $3f
14923 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14924 +2:
14925 +#ifdef CONFIG_PARAVIRT
14926 + mov %esi, %eax
14927 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14928 +#else
14929 + mov %esi, %cr0
14930 +#endif
14931 +3:
14932 +#ifdef CONFIG_PARAVIRT
14933 + popl %ecx
14934 + popl %eax
14935 +#endif
14936 + ret
14937 +ENDPROC(pax_enter_kernel)
14938 +
14939 +ENTRY(pax_exit_kernel)
14940 +#ifdef CONFIG_PARAVIRT
14941 + pushl %eax
14942 + pushl %ecx
14943 +#endif
14944 + mov %cs, %esi
14945 + cmp $__KERNEXEC_KERNEL_CS, %esi
14946 + jnz 2f
14947 +#ifdef CONFIG_PARAVIRT
14948 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14949 + mov %eax, %esi
14950 +#else
14951 + mov %cr0, %esi
14952 +#endif
14953 + btr $16, %esi
14954 + ljmp $__KERNEL_CS, $1f
14955 +1:
14956 +#ifdef CONFIG_PARAVIRT
14957 + mov %esi, %eax
14958 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14959 +#else
14960 + mov %esi, %cr0
14961 +#endif
14962 +2:
14963 +#ifdef CONFIG_PARAVIRT
14964 + popl %ecx
14965 + popl %eax
14966 +#endif
14967 + ret
14968 +ENDPROC(pax_exit_kernel)
14969 +#endif
14970 +
14971 +.macro pax_erase_kstack
14972 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14973 + call pax_erase_kstack
14974 +#endif
14975 +.endm
14976 +
14977 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14978 +/*
14979 + * ebp: thread_info
14980 + */
14981 +ENTRY(pax_erase_kstack)
14982 + pushl %edi
14983 + pushl %ecx
14984 + pushl %eax
14985 +
14986 + mov TI_lowest_stack(%ebp), %edi
14987 + mov $-0xBEEF, %eax
14988 + std
14989 +
14990 +1: mov %edi, %ecx
14991 + and $THREAD_SIZE_asm - 1, %ecx
14992 + shr $2, %ecx
14993 + repne scasl
14994 + jecxz 2f
14995 +
14996 + cmp $2*16, %ecx
14997 + jc 2f
14998 +
14999 + mov $2*16, %ecx
15000 + repe scasl
15001 + jecxz 2f
15002 + jne 1b
15003 +
15004 +2: cld
15005 + mov %esp, %ecx
15006 + sub %edi, %ecx
15007 +
15008 + cmp $THREAD_SIZE_asm, %ecx
15009 + jb 3f
15010 + ud2
15011 +3:
15012 +
15013 + shr $2, %ecx
15014 + rep stosl
15015 +
15016 + mov TI_task_thread_sp0(%ebp), %edi
15017 + sub $128, %edi
15018 + mov %edi, TI_lowest_stack(%ebp)
15019 +
15020 + popl %eax
15021 + popl %ecx
15022 + popl %edi
15023 + ret
15024 +ENDPROC(pax_erase_kstack)
15025 +#endif
15026 +
15027 +.macro __SAVE_ALL _DS
15028 cld
15029 PUSH_GS
15030 pushl_cfi %fs
15031 @@ -205,7 +345,7 @@
15032 CFI_REL_OFFSET ecx, 0
15033 pushl_cfi %ebx
15034 CFI_REL_OFFSET ebx, 0
15035 - movl $(__USER_DS), %edx
15036 + movl $\_DS, %edx
15037 movl %edx, %ds
15038 movl %edx, %es
15039 movl $(__KERNEL_PERCPU), %edx
15040 @@ -213,6 +353,15 @@
15041 SET_KERNEL_GS %edx
15042 .endm
15043
15044 +.macro SAVE_ALL
15045 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15046 + __SAVE_ALL __KERNEL_DS
15047 + pax_enter_kernel
15048 +#else
15049 + __SAVE_ALL __USER_DS
15050 +#endif
15051 +.endm
15052 +
15053 .macro RESTORE_INT_REGS
15054 popl_cfi %ebx
15055 CFI_RESTORE ebx
15056 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15057 popfl_cfi
15058 jmp syscall_exit
15059 CFI_ENDPROC
15060 -END(ret_from_fork)
15061 +ENDPROC(ret_from_fork)
15062
15063 /*
15064 * Interrupt exit functions should be protected against kprobes
15065 @@ -329,7 +478,15 @@ ret_from_intr:
15066 andl $SEGMENT_RPL_MASK, %eax
15067 #endif
15068 cmpl $USER_RPL, %eax
15069 +
15070 +#ifdef CONFIG_PAX_KERNEXEC
15071 + jae resume_userspace
15072 +
15073 + pax_exit_kernel
15074 + jmp resume_kernel
15075 +#else
15076 jb resume_kernel # not returning to v8086 or userspace
15077 +#endif
15078
15079 ENTRY(resume_userspace)
15080 LOCKDEP_SYS_EXIT
15081 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15082 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15083 # int/exception return?
15084 jne work_pending
15085 - jmp restore_all
15086 -END(ret_from_exception)
15087 + jmp restore_all_pax
15088 +ENDPROC(ret_from_exception)
15089
15090 #ifdef CONFIG_PREEMPT
15091 ENTRY(resume_kernel)
15092 @@ -357,7 +514,7 @@ need_resched:
15093 jz restore_all
15094 call preempt_schedule_irq
15095 jmp need_resched
15096 -END(resume_kernel)
15097 +ENDPROC(resume_kernel)
15098 #endif
15099 CFI_ENDPROC
15100 /*
15101 @@ -391,28 +548,43 @@ sysenter_past_esp:
15102 /*CFI_REL_OFFSET cs, 0*/
15103 /*
15104 * Push current_thread_info()->sysenter_return to the stack.
15105 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15106 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15107 */
15108 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15109 + pushl_cfi $0
15110 CFI_REL_OFFSET eip, 0
15111
15112 pushl_cfi %eax
15113 SAVE_ALL
15114 + GET_THREAD_INFO(%ebp)
15115 + movl TI_sysenter_return(%ebp),%ebp
15116 + movl %ebp,PT_EIP(%esp)
15117 ENABLE_INTERRUPTS(CLBR_NONE)
15118
15119 /*
15120 * Load the potential sixth argument from user stack.
15121 * Careful about security.
15122 */
15123 + movl PT_OLDESP(%esp),%ebp
15124 +
15125 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15126 + mov PT_OLDSS(%esp),%ds
15127 +1: movl %ds:(%ebp),%ebp
15128 + push %ss
15129 + pop %ds
15130 +#else
15131 cmpl $__PAGE_OFFSET-3,%ebp
15132 jae syscall_fault
15133 1: movl (%ebp),%ebp
15134 +#endif
15135 +
15136 movl %ebp,PT_EBP(%esp)
15137 _ASM_EXTABLE(1b,syscall_fault)
15138
15139 GET_THREAD_INFO(%ebp)
15140
15141 +#ifdef CONFIG_PAX_RANDKSTACK
15142 + pax_erase_kstack
15143 +#endif
15144 +
15145 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15146 jnz sysenter_audit
15147 sysenter_do_call:
15148 @@ -427,12 +599,24 @@ sysenter_do_call:
15149 testl $_TIF_ALLWORK_MASK, %ecx
15150 jne sysexit_audit
15151 sysenter_exit:
15152 +
15153 +#ifdef CONFIG_PAX_RANDKSTACK
15154 + pushl_cfi %eax
15155 + movl %esp, %eax
15156 + call pax_randomize_kstack
15157 + popl_cfi %eax
15158 +#endif
15159 +
15160 + pax_erase_kstack
15161 +
15162 /* if something modifies registers it must also disable sysexit */
15163 movl PT_EIP(%esp), %edx
15164 movl PT_OLDESP(%esp), %ecx
15165 xorl %ebp,%ebp
15166 TRACE_IRQS_ON
15167 1: mov PT_FS(%esp), %fs
15168 +2: mov PT_DS(%esp), %ds
15169 +3: mov PT_ES(%esp), %es
15170 PTGS_TO_GS
15171 ENABLE_INTERRUPTS_SYSEXIT
15172
15173 @@ -449,6 +633,9 @@ sysenter_audit:
15174 movl %eax,%edx /* 2nd arg: syscall number */
15175 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15176 call __audit_syscall_entry
15177 +
15178 + pax_erase_kstack
15179 +
15180 pushl_cfi %ebx
15181 movl PT_EAX(%esp),%eax /* reload syscall number */
15182 jmp sysenter_do_call
15183 @@ -474,10 +661,16 @@ sysexit_audit:
15184
15185 CFI_ENDPROC
15186 .pushsection .fixup,"ax"
15187 -2: movl $0,PT_FS(%esp)
15188 +4: movl $0,PT_FS(%esp)
15189 + jmp 1b
15190 +5: movl $0,PT_DS(%esp)
15191 + jmp 1b
15192 +6: movl $0,PT_ES(%esp)
15193 jmp 1b
15194 .popsection
15195 - _ASM_EXTABLE(1b,2b)
15196 + _ASM_EXTABLE(1b,4b)
15197 + _ASM_EXTABLE(2b,5b)
15198 + _ASM_EXTABLE(3b,6b)
15199 PTGS_TO_GS_EX
15200 ENDPROC(ia32_sysenter_target)
15201
15202 @@ -491,6 +684,11 @@ ENTRY(system_call)
15203 pushl_cfi %eax # save orig_eax
15204 SAVE_ALL
15205 GET_THREAD_INFO(%ebp)
15206 +
15207 +#ifdef CONFIG_PAX_RANDKSTACK
15208 + pax_erase_kstack
15209 +#endif
15210 +
15211 # system call tracing in operation / emulation
15212 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15213 jnz syscall_trace_entry
15214 @@ -509,6 +707,15 @@ syscall_exit:
15215 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15216 jne syscall_exit_work
15217
15218 +restore_all_pax:
15219 +
15220 +#ifdef CONFIG_PAX_RANDKSTACK
15221 + movl %esp, %eax
15222 + call pax_randomize_kstack
15223 +#endif
15224 +
15225 + pax_erase_kstack
15226 +
15227 restore_all:
15228 TRACE_IRQS_IRET
15229 restore_all_notrace:
15230 @@ -565,14 +772,34 @@ ldt_ss:
15231 * compensating for the offset by changing to the ESPFIX segment with
15232 * a base address that matches for the difference.
15233 */
15234 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15235 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15236 mov %esp, %edx /* load kernel esp */
15237 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15238 mov %dx, %ax /* eax: new kernel esp */
15239 sub %eax, %edx /* offset (low word is 0) */
15240 +#ifdef CONFIG_SMP
15241 + movl PER_CPU_VAR(cpu_number), %ebx
15242 + shll $PAGE_SHIFT_asm, %ebx
15243 + addl $cpu_gdt_table, %ebx
15244 +#else
15245 + movl $cpu_gdt_table, %ebx
15246 +#endif
15247 shr $16, %edx
15248 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15249 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15250 +
15251 +#ifdef CONFIG_PAX_KERNEXEC
15252 + mov %cr0, %esi
15253 + btr $16, %esi
15254 + mov %esi, %cr0
15255 +#endif
15256 +
15257 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15258 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15259 +
15260 +#ifdef CONFIG_PAX_KERNEXEC
15261 + bts $16, %esi
15262 + mov %esi, %cr0
15263 +#endif
15264 +
15265 pushl_cfi $__ESPFIX_SS
15266 pushl_cfi %eax /* new kernel esp */
15267 /* Disable interrupts, but do not irqtrace this section: we
15268 @@ -601,35 +828,23 @@ work_resched:
15269 movl TI_flags(%ebp), %ecx
15270 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15271 # than syscall tracing?
15272 - jz restore_all
15273 + jz restore_all_pax
15274 testb $_TIF_NEED_RESCHED, %cl
15275 jnz work_resched
15276
15277 work_notifysig: # deal with pending signals and
15278 # notify-resume requests
15279 + movl %esp, %eax
15280 #ifdef CONFIG_VM86
15281 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15282 - movl %esp, %eax
15283 - jne work_notifysig_v86 # returning to kernel-space or
15284 + jz 1f # returning to kernel-space or
15285 # vm86-space
15286 - TRACE_IRQS_ON
15287 - ENABLE_INTERRUPTS(CLBR_NONE)
15288 - movb PT_CS(%esp), %bl
15289 - andb $SEGMENT_RPL_MASK, %bl
15290 - cmpb $USER_RPL, %bl
15291 - jb resume_kernel
15292 - xorl %edx, %edx
15293 - call do_notify_resume
15294 - jmp resume_userspace
15295
15296 - ALIGN
15297 -work_notifysig_v86:
15298 pushl_cfi %ecx # save ti_flags for do_notify_resume
15299 call save_v86_state # %eax contains pt_regs pointer
15300 popl_cfi %ecx
15301 movl %eax, %esp
15302 -#else
15303 - movl %esp, %eax
15304 +1:
15305 #endif
15306 TRACE_IRQS_ON
15307 ENABLE_INTERRUPTS(CLBR_NONE)
15308 @@ -640,7 +855,7 @@ work_notifysig_v86:
15309 xorl %edx, %edx
15310 call do_notify_resume
15311 jmp resume_userspace
15312 -END(work_pending)
15313 +ENDPROC(work_pending)
15314
15315 # perform syscall exit tracing
15316 ALIGN
15317 @@ -648,11 +863,14 @@ syscall_trace_entry:
15318 movl $-ENOSYS,PT_EAX(%esp)
15319 movl %esp, %eax
15320 call syscall_trace_enter
15321 +
15322 + pax_erase_kstack
15323 +
15324 /* What it returned is what we'll actually use. */
15325 cmpl $(NR_syscalls), %eax
15326 jnae syscall_call
15327 jmp syscall_exit
15328 -END(syscall_trace_entry)
15329 +ENDPROC(syscall_trace_entry)
15330
15331 # perform syscall exit tracing
15332 ALIGN
15333 @@ -665,20 +883,24 @@ syscall_exit_work:
15334 movl %esp, %eax
15335 call syscall_trace_leave
15336 jmp resume_userspace
15337 -END(syscall_exit_work)
15338 +ENDPROC(syscall_exit_work)
15339 CFI_ENDPROC
15340
15341 RING0_INT_FRAME # can't unwind into user space anyway
15342 syscall_fault:
15343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15344 + push %ss
15345 + pop %ds
15346 +#endif
15347 GET_THREAD_INFO(%ebp)
15348 movl $-EFAULT,PT_EAX(%esp)
15349 jmp resume_userspace
15350 -END(syscall_fault)
15351 +ENDPROC(syscall_fault)
15352
15353 syscall_badsys:
15354 movl $-ENOSYS,PT_EAX(%esp)
15355 jmp resume_userspace
15356 -END(syscall_badsys)
15357 +ENDPROC(syscall_badsys)
15358 CFI_ENDPROC
15359 /*
15360 * End of kprobes section
15361 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15362 CFI_ENDPROC
15363 ENDPROC(ptregs_clone)
15364
15365 + ALIGN;
15366 +ENTRY(kernel_execve)
15367 + CFI_STARTPROC
15368 + pushl_cfi %ebp
15369 + sub $PT_OLDSS+4,%esp
15370 + pushl_cfi %edi
15371 + pushl_cfi %ecx
15372 + pushl_cfi %eax
15373 + lea 3*4(%esp),%edi
15374 + mov $PT_OLDSS/4+1,%ecx
15375 + xorl %eax,%eax
15376 + rep stosl
15377 + popl_cfi %eax
15378 + popl_cfi %ecx
15379 + popl_cfi %edi
15380 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15381 + pushl_cfi %esp
15382 + call sys_execve
15383 + add $4,%esp
15384 + CFI_ADJUST_CFA_OFFSET -4
15385 + GET_THREAD_INFO(%ebp)
15386 + test %eax,%eax
15387 + jz syscall_exit
15388 + add $PT_OLDSS+4,%esp
15389 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15390 + popl_cfi %ebp
15391 + ret
15392 + CFI_ENDPROC
15393 +ENDPROC(kernel_execve)
15394 +
15395 .macro FIXUP_ESPFIX_STACK
15396 /*
15397 * Switch back for ESPFIX stack to the normal zerobased stack
15398 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15399 * normal stack and adjusts ESP with the matching offset.
15400 */
15401 /* fixup the stack */
15402 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15403 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15404 +#ifdef CONFIG_SMP
15405 + movl PER_CPU_VAR(cpu_number), %ebx
15406 + shll $PAGE_SHIFT_asm, %ebx
15407 + addl $cpu_gdt_table, %ebx
15408 +#else
15409 + movl $cpu_gdt_table, %ebx
15410 +#endif
15411 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15412 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15413 shl $16, %eax
15414 addl %esp, %eax /* the adjusted stack pointer */
15415 pushl_cfi $__KERNEL_DS
15416 @@ -813,7 +1072,7 @@ vector=vector+1
15417 .endr
15418 2: jmp common_interrupt
15419 .endr
15420 -END(irq_entries_start)
15421 +ENDPROC(irq_entries_start)
15422
15423 .previous
15424 END(interrupt)
15425 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15426 pushl_cfi $do_coprocessor_error
15427 jmp error_code
15428 CFI_ENDPROC
15429 -END(coprocessor_error)
15430 +ENDPROC(coprocessor_error)
15431
15432 ENTRY(simd_coprocessor_error)
15433 RING0_INT_FRAME
15434 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15435 #endif
15436 jmp error_code
15437 CFI_ENDPROC
15438 -END(simd_coprocessor_error)
15439 +ENDPROC(simd_coprocessor_error)
15440
15441 ENTRY(device_not_available)
15442 RING0_INT_FRAME
15443 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15444 pushl_cfi $do_device_not_available
15445 jmp error_code
15446 CFI_ENDPROC
15447 -END(device_not_available)
15448 +ENDPROC(device_not_available)
15449
15450 #ifdef CONFIG_PARAVIRT
15451 ENTRY(native_iret)
15452 iret
15453 _ASM_EXTABLE(native_iret, iret_exc)
15454 -END(native_iret)
15455 +ENDPROC(native_iret)
15456
15457 ENTRY(native_irq_enable_sysexit)
15458 sti
15459 sysexit
15460 -END(native_irq_enable_sysexit)
15461 +ENDPROC(native_irq_enable_sysexit)
15462 #endif
15463
15464 ENTRY(overflow)
15465 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15466 pushl_cfi $do_overflow
15467 jmp error_code
15468 CFI_ENDPROC
15469 -END(overflow)
15470 +ENDPROC(overflow)
15471
15472 ENTRY(bounds)
15473 RING0_INT_FRAME
15474 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15475 pushl_cfi $do_bounds
15476 jmp error_code
15477 CFI_ENDPROC
15478 -END(bounds)
15479 +ENDPROC(bounds)
15480
15481 ENTRY(invalid_op)
15482 RING0_INT_FRAME
15483 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15484 pushl_cfi $do_invalid_op
15485 jmp error_code
15486 CFI_ENDPROC
15487 -END(invalid_op)
15488 +ENDPROC(invalid_op)
15489
15490 ENTRY(coprocessor_segment_overrun)
15491 RING0_INT_FRAME
15492 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15493 pushl_cfi $do_coprocessor_segment_overrun
15494 jmp error_code
15495 CFI_ENDPROC
15496 -END(coprocessor_segment_overrun)
15497 +ENDPROC(coprocessor_segment_overrun)
15498
15499 ENTRY(invalid_TSS)
15500 RING0_EC_FRAME
15501 pushl_cfi $do_invalid_TSS
15502 jmp error_code
15503 CFI_ENDPROC
15504 -END(invalid_TSS)
15505 +ENDPROC(invalid_TSS)
15506
15507 ENTRY(segment_not_present)
15508 RING0_EC_FRAME
15509 pushl_cfi $do_segment_not_present
15510 jmp error_code
15511 CFI_ENDPROC
15512 -END(segment_not_present)
15513 +ENDPROC(segment_not_present)
15514
15515 ENTRY(stack_segment)
15516 RING0_EC_FRAME
15517 pushl_cfi $do_stack_segment
15518 jmp error_code
15519 CFI_ENDPROC
15520 -END(stack_segment)
15521 +ENDPROC(stack_segment)
15522
15523 ENTRY(alignment_check)
15524 RING0_EC_FRAME
15525 pushl_cfi $do_alignment_check
15526 jmp error_code
15527 CFI_ENDPROC
15528 -END(alignment_check)
15529 +ENDPROC(alignment_check)
15530
15531 ENTRY(divide_error)
15532 RING0_INT_FRAME
15533 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15534 pushl_cfi $do_divide_error
15535 jmp error_code
15536 CFI_ENDPROC
15537 -END(divide_error)
15538 +ENDPROC(divide_error)
15539
15540 #ifdef CONFIG_X86_MCE
15541 ENTRY(machine_check)
15542 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15543 pushl_cfi machine_check_vector
15544 jmp error_code
15545 CFI_ENDPROC
15546 -END(machine_check)
15547 +ENDPROC(machine_check)
15548 #endif
15549
15550 ENTRY(spurious_interrupt_bug)
15551 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15552 pushl_cfi $do_spurious_interrupt_bug
15553 jmp error_code
15554 CFI_ENDPROC
15555 -END(spurious_interrupt_bug)
15556 +ENDPROC(spurious_interrupt_bug)
15557 /*
15558 * End of kprobes section
15559 */
15560 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15561
15562 ENTRY(mcount)
15563 ret
15564 -END(mcount)
15565 +ENDPROC(mcount)
15566
15567 ENTRY(ftrace_caller)
15568 cmpl $0, function_trace_stop
15569 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15570 .globl ftrace_stub
15571 ftrace_stub:
15572 ret
15573 -END(ftrace_caller)
15574 +ENDPROC(ftrace_caller)
15575
15576 #else /* ! CONFIG_DYNAMIC_FTRACE */
15577
15578 @@ -1165,7 +1424,7 @@ trace:
15579 popl %ecx
15580 popl %eax
15581 jmp ftrace_stub
15582 -END(mcount)
15583 +ENDPROC(mcount)
15584 #endif /* CONFIG_DYNAMIC_FTRACE */
15585 #endif /* CONFIG_FUNCTION_TRACER */
15586
15587 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15588 popl %ecx
15589 popl %eax
15590 ret
15591 -END(ftrace_graph_caller)
15592 +ENDPROC(ftrace_graph_caller)
15593
15594 .globl return_to_handler
15595 return_to_handler:
15596 @@ -1241,15 +1500,18 @@ error_code:
15597 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15598 REG_TO_PTGS %ecx
15599 SET_KERNEL_GS %ecx
15600 - movl $(__USER_DS), %ecx
15601 + movl $(__KERNEL_DS), %ecx
15602 movl %ecx, %ds
15603 movl %ecx, %es
15604 +
15605 + pax_enter_kernel
15606 +
15607 TRACE_IRQS_OFF
15608 movl %esp,%eax # pt_regs pointer
15609 call *%edi
15610 jmp ret_from_exception
15611 CFI_ENDPROC
15612 -END(page_fault)
15613 +ENDPROC(page_fault)
15614
15615 /*
15616 * Debug traps and NMI can happen at the one SYSENTER instruction
15617 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15618 call do_debug
15619 jmp ret_from_exception
15620 CFI_ENDPROC
15621 -END(debug)
15622 +ENDPROC(debug)
15623
15624 /*
15625 * NMI is doubly nasty. It can happen _while_ we're handling
15626 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15627 xorl %edx,%edx # zero error code
15628 movl %esp,%eax # pt_regs pointer
15629 call do_nmi
15630 +
15631 + pax_exit_kernel
15632 +
15633 jmp restore_all_notrace
15634 CFI_ENDPROC
15635
15636 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15637 FIXUP_ESPFIX_STACK # %eax == %esp
15638 xorl %edx,%edx # zero error code
15639 call do_nmi
15640 +
15641 + pax_exit_kernel
15642 +
15643 RESTORE_REGS
15644 lss 12+4(%esp), %esp # back to espfix stack
15645 CFI_ADJUST_CFA_OFFSET -24
15646 jmp irq_return
15647 CFI_ENDPROC
15648 -END(nmi)
15649 +ENDPROC(nmi)
15650
15651 ENTRY(int3)
15652 RING0_INT_FRAME
15653 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15654 call do_int3
15655 jmp ret_from_exception
15656 CFI_ENDPROC
15657 -END(int3)
15658 +ENDPROC(int3)
15659
15660 ENTRY(general_protection)
15661 RING0_EC_FRAME
15662 pushl_cfi $do_general_protection
15663 jmp error_code
15664 CFI_ENDPROC
15665 -END(general_protection)
15666 +ENDPROC(general_protection)
15667
15668 #ifdef CONFIG_KVM_GUEST
15669 ENTRY(async_page_fault)
15670 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15671 pushl_cfi $do_async_page_fault
15672 jmp error_code
15673 CFI_ENDPROC
15674 -END(async_page_fault)
15675 +ENDPROC(async_page_fault)
15676 #endif
15677
15678 /*
15679 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15680 index 7d65133..c888d5f 100644
15681 --- a/arch/x86/kernel/entry_64.S
15682 +++ b/arch/x86/kernel/entry_64.S
15683 @@ -57,6 +57,8 @@
15684 #include <asm/percpu.h>
15685 #include <asm/asm.h>
15686 #include <linux/err.h>
15687 +#include <asm/pgtable.h>
15688 +#include <asm/alternative-asm.h>
15689
15690 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15691 #include <linux/elf-em.h>
15692 @@ -70,8 +72,9 @@
15693 #ifdef CONFIG_FUNCTION_TRACER
15694 #ifdef CONFIG_DYNAMIC_FTRACE
15695 ENTRY(mcount)
15696 + pax_force_retaddr
15697 retq
15698 -END(mcount)
15699 +ENDPROC(mcount)
15700
15701 ENTRY(ftrace_caller)
15702 cmpl $0, function_trace_stop
15703 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15704 #endif
15705
15706 GLOBAL(ftrace_stub)
15707 + pax_force_retaddr
15708 retq
15709 -END(ftrace_caller)
15710 +ENDPROC(ftrace_caller)
15711
15712 #else /* ! CONFIG_DYNAMIC_FTRACE */
15713 ENTRY(mcount)
15714 @@ -114,6 +118,7 @@ ENTRY(mcount)
15715 #endif
15716
15717 GLOBAL(ftrace_stub)
15718 + pax_force_retaddr
15719 retq
15720
15721 trace:
15722 @@ -123,12 +128,13 @@ trace:
15723 movq 8(%rbp), %rsi
15724 subq $MCOUNT_INSN_SIZE, %rdi
15725
15726 + pax_force_fptr ftrace_trace_function
15727 call *ftrace_trace_function
15728
15729 MCOUNT_RESTORE_FRAME
15730
15731 jmp ftrace_stub
15732 -END(mcount)
15733 +ENDPROC(mcount)
15734 #endif /* CONFIG_DYNAMIC_FTRACE */
15735 #endif /* CONFIG_FUNCTION_TRACER */
15736
15737 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15738
15739 MCOUNT_RESTORE_FRAME
15740
15741 + pax_force_retaddr
15742 retq
15743 -END(ftrace_graph_caller)
15744 +ENDPROC(ftrace_graph_caller)
15745
15746 GLOBAL(return_to_handler)
15747 subq $24, %rsp
15748 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15749 movq 8(%rsp), %rdx
15750 movq (%rsp), %rax
15751 addq $24, %rsp
15752 + pax_force_fptr %rdi
15753 jmp *%rdi
15754 #endif
15755
15756 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15757 ENDPROC(native_usergs_sysret64)
15758 #endif /* CONFIG_PARAVIRT */
15759
15760 + .macro ljmpq sel, off
15761 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15762 + .byte 0x48; ljmp *1234f(%rip)
15763 + .pushsection .rodata
15764 + .align 16
15765 + 1234: .quad \off; .word \sel
15766 + .popsection
15767 +#else
15768 + pushq $\sel
15769 + pushq $\off
15770 + lretq
15771 +#endif
15772 + .endm
15773 +
15774 + .macro pax_enter_kernel
15775 + pax_set_fptr_mask
15776 +#ifdef CONFIG_PAX_KERNEXEC
15777 + call pax_enter_kernel
15778 +#endif
15779 + .endm
15780 +
15781 + .macro pax_exit_kernel
15782 +#ifdef CONFIG_PAX_KERNEXEC
15783 + call pax_exit_kernel
15784 +#endif
15785 + .endm
15786 +
15787 +#ifdef CONFIG_PAX_KERNEXEC
15788 +ENTRY(pax_enter_kernel)
15789 + pushq %rdi
15790 +
15791 +#ifdef CONFIG_PARAVIRT
15792 + PV_SAVE_REGS(CLBR_RDI)
15793 +#endif
15794 +
15795 + GET_CR0_INTO_RDI
15796 + bts $16,%rdi
15797 + jnc 3f
15798 + mov %cs,%edi
15799 + cmp $__KERNEL_CS,%edi
15800 + jnz 2f
15801 +1:
15802 +
15803 +#ifdef CONFIG_PARAVIRT
15804 + PV_RESTORE_REGS(CLBR_RDI)
15805 +#endif
15806 +
15807 + popq %rdi
15808 + pax_force_retaddr
15809 + retq
15810 +
15811 +2: ljmpq __KERNEL_CS,1f
15812 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15813 +4: SET_RDI_INTO_CR0
15814 + jmp 1b
15815 +ENDPROC(pax_enter_kernel)
15816 +
15817 +ENTRY(pax_exit_kernel)
15818 + pushq %rdi
15819 +
15820 +#ifdef CONFIG_PARAVIRT
15821 + PV_SAVE_REGS(CLBR_RDI)
15822 +#endif
15823 +
15824 + mov %cs,%rdi
15825 + cmp $__KERNEXEC_KERNEL_CS,%edi
15826 + jz 2f
15827 +1:
15828 +
15829 +#ifdef CONFIG_PARAVIRT
15830 + PV_RESTORE_REGS(CLBR_RDI);
15831 +#endif
15832 +
15833 + popq %rdi
15834 + pax_force_retaddr
15835 + retq
15836 +
15837 +2: GET_CR0_INTO_RDI
15838 + btr $16,%rdi
15839 + ljmpq __KERNEL_CS,3f
15840 +3: SET_RDI_INTO_CR0
15841 + jmp 1b
15842 +#ifdef CONFIG_PARAVIRT
15843 + PV_RESTORE_REGS(CLBR_RDI);
15844 +#endif
15845 +
15846 + popq %rdi
15847 + pax_force_retaddr
15848 + retq
15849 +ENDPROC(pax_exit_kernel)
15850 +#endif
15851 +
15852 + .macro pax_enter_kernel_user
15853 + pax_set_fptr_mask
15854 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15855 + call pax_enter_kernel_user
15856 +#endif
15857 + .endm
15858 +
15859 + .macro pax_exit_kernel_user
15860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15861 + call pax_exit_kernel_user
15862 +#endif
15863 +#ifdef CONFIG_PAX_RANDKSTACK
15864 + pushq %rax
15865 + call pax_randomize_kstack
15866 + popq %rax
15867 +#endif
15868 + .endm
15869 +
15870 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15871 +ENTRY(pax_enter_kernel_user)
15872 + pushq %rdi
15873 + pushq %rbx
15874 +
15875 +#ifdef CONFIG_PARAVIRT
15876 + PV_SAVE_REGS(CLBR_RDI)
15877 +#endif
15878 +
15879 + GET_CR3_INTO_RDI
15880 + mov %rdi,%rbx
15881 + add $__START_KERNEL_map,%rbx
15882 + sub phys_base(%rip),%rbx
15883 +
15884 +#ifdef CONFIG_PARAVIRT
15885 + pushq %rdi
15886 + cmpl $0, pv_info+PARAVIRT_enabled
15887 + jz 1f
15888 + i = 0
15889 + .rept USER_PGD_PTRS
15890 + mov i*8(%rbx),%rsi
15891 + mov $0,%sil
15892 + lea i*8(%rbx),%rdi
15893 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15894 + i = i + 1
15895 + .endr
15896 + jmp 2f
15897 +1:
15898 +#endif
15899 +
15900 + i = 0
15901 + .rept USER_PGD_PTRS
15902 + movb $0,i*8(%rbx)
15903 + i = i + 1
15904 + .endr
15905 +
15906 +#ifdef CONFIG_PARAVIRT
15907 +2: popq %rdi
15908 +#endif
15909 + SET_RDI_INTO_CR3
15910 +
15911 +#ifdef CONFIG_PAX_KERNEXEC
15912 + GET_CR0_INTO_RDI
15913 + bts $16,%rdi
15914 + SET_RDI_INTO_CR0
15915 +#endif
15916 +
15917 +#ifdef CONFIG_PARAVIRT
15918 + PV_RESTORE_REGS(CLBR_RDI)
15919 +#endif
15920 +
15921 + popq %rbx
15922 + popq %rdi
15923 + pax_force_retaddr
15924 + retq
15925 +ENDPROC(pax_enter_kernel_user)
15926 +
15927 +ENTRY(pax_exit_kernel_user)
15928 + push %rdi
15929 +
15930 +#ifdef CONFIG_PARAVIRT
15931 + pushq %rbx
15932 + PV_SAVE_REGS(CLBR_RDI)
15933 +#endif
15934 +
15935 +#ifdef CONFIG_PAX_KERNEXEC
15936 + GET_CR0_INTO_RDI
15937 + btr $16,%rdi
15938 + SET_RDI_INTO_CR0
15939 +#endif
15940 +
15941 + GET_CR3_INTO_RDI
15942 + add $__START_KERNEL_map,%rdi
15943 + sub phys_base(%rip),%rdi
15944 +
15945 +#ifdef CONFIG_PARAVIRT
15946 + cmpl $0, pv_info+PARAVIRT_enabled
15947 + jz 1f
15948 + mov %rdi,%rbx
15949 + i = 0
15950 + .rept USER_PGD_PTRS
15951 + mov i*8(%rbx),%rsi
15952 + mov $0x67,%sil
15953 + lea i*8(%rbx),%rdi
15954 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15955 + i = i + 1
15956 + .endr
15957 + jmp 2f
15958 +1:
15959 +#endif
15960 +
15961 + i = 0
15962 + .rept USER_PGD_PTRS
15963 + movb $0x67,i*8(%rdi)
15964 + i = i + 1
15965 + .endr
15966 +
15967 +#ifdef CONFIG_PARAVIRT
15968 +2: PV_RESTORE_REGS(CLBR_RDI)
15969 + popq %rbx
15970 +#endif
15971 +
15972 + popq %rdi
15973 + pax_force_retaddr
15974 + retq
15975 +ENDPROC(pax_exit_kernel_user)
15976 +#endif
15977 +
15978 +.macro pax_erase_kstack
15979 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15980 + call pax_erase_kstack
15981 +#endif
15982 +.endm
15983 +
15984 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15985 +ENTRY(pax_erase_kstack)
15986 + pushq %rdi
15987 + pushq %rcx
15988 + pushq %rax
15989 + pushq %r11
15990 +
15991 + GET_THREAD_INFO(%r11)
15992 + mov TI_lowest_stack(%r11), %rdi
15993 + mov $-0xBEEF, %rax
15994 + std
15995 +
15996 +1: mov %edi, %ecx
15997 + and $THREAD_SIZE_asm - 1, %ecx
15998 + shr $3, %ecx
15999 + repne scasq
16000 + jecxz 2f
16001 +
16002 + cmp $2*8, %ecx
16003 + jc 2f
16004 +
16005 + mov $2*8, %ecx
16006 + repe scasq
16007 + jecxz 2f
16008 + jne 1b
16009 +
16010 +2: cld
16011 + mov %esp, %ecx
16012 + sub %edi, %ecx
16013 +
16014 + cmp $THREAD_SIZE_asm, %rcx
16015 + jb 3f
16016 + ud2
16017 +3:
16018 +
16019 + shr $3, %ecx
16020 + rep stosq
16021 +
16022 + mov TI_task_thread_sp0(%r11), %rdi
16023 + sub $256, %rdi
16024 + mov %rdi, TI_lowest_stack(%r11)
16025 +
16026 + popq %r11
16027 + popq %rax
16028 + popq %rcx
16029 + popq %rdi
16030 + pax_force_retaddr
16031 + ret
16032 +ENDPROC(pax_erase_kstack)
16033 +#endif
16034
16035 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16036 #ifdef CONFIG_TRACE_IRQFLAGS
16037 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16038 .endm
16039
16040 .macro UNFAKE_STACK_FRAME
16041 - addq $8*6, %rsp
16042 - CFI_ADJUST_CFA_OFFSET -(6*8)
16043 + addq $8*6 + ARG_SKIP, %rsp
16044 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16045 .endm
16046
16047 /*
16048 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16049 movq %rsp, %rsi
16050
16051 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16052 - testl $3, CS-RBP(%rsi)
16053 + testb $3, CS-RBP(%rsi)
16054 je 1f
16055 SWAPGS
16056 /*
16057 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16058 movq_cfi r15, R15+16
16059 movq %r11, 8(%rsp) /* return address */
16060 FIXUP_TOP_OF_STACK %r11, 16
16061 + pax_force_retaddr
16062 ret
16063 CFI_ENDPROC
16064 -END(save_rest)
16065 +ENDPROC(save_rest)
16066
16067 /* save complete stack frame */
16068 .pushsection .kprobes.text, "ax"
16069 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16070 js 1f /* negative -> in kernel */
16071 SWAPGS
16072 xorl %ebx,%ebx
16073 -1: ret
16074 +1: pax_force_retaddr_bts
16075 + ret
16076 CFI_ENDPROC
16077 -END(save_paranoid)
16078 +ENDPROC(save_paranoid)
16079 .popsection
16080
16081 /*
16082 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16083
16084 RESTORE_REST
16085
16086 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16087 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16088 jz retint_restore_args
16089
16090 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16091 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16092 jmp ret_from_sys_call # go to the SYSRET fastpath
16093
16094 CFI_ENDPROC
16095 -END(ret_from_fork)
16096 +ENDPROC(ret_from_fork)
16097
16098 /*
16099 * System call entry. Up to 6 arguments in registers are supported.
16100 @@ -495,7 +779,7 @@ END(ret_from_fork)
16101 ENTRY(system_call)
16102 CFI_STARTPROC simple
16103 CFI_SIGNAL_FRAME
16104 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16105 + CFI_DEF_CFA rsp,0
16106 CFI_REGISTER rip,rcx
16107 /*CFI_REGISTER rflags,r11*/
16108 SWAPGS_UNSAFE_STACK
16109 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16110
16111 movq %rsp,PER_CPU_VAR(old_rsp)
16112 movq PER_CPU_VAR(kernel_stack),%rsp
16113 + SAVE_ARGS 8*6,0
16114 + pax_enter_kernel_user
16115 +
16116 +#ifdef CONFIG_PAX_RANDKSTACK
16117 + pax_erase_kstack
16118 +#endif
16119 +
16120 /*
16121 * No need to follow this irqs off/on section - it's straight
16122 * and short:
16123 */
16124 ENABLE_INTERRUPTS(CLBR_NONE)
16125 - SAVE_ARGS 8,0
16126 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16127 movq %rcx,RIP-ARGOFFSET(%rsp)
16128 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16129 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16130 + GET_THREAD_INFO(%rcx)
16131 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16132 jnz tracesys
16133 system_call_fastpath:
16134 #if __SYSCALL_MASK == ~0
16135 @@ -527,7 +818,7 @@ system_call_fastpath:
16136 cmpl $__NR_syscall_max,%eax
16137 #endif
16138 ja badsys
16139 - movq %r10,%rcx
16140 + movq R10-ARGOFFSET(%rsp),%rcx
16141 call *sys_call_table(,%rax,8) # XXX: rip relative
16142 movq %rax,RAX-ARGOFFSET(%rsp)
16143 /*
16144 @@ -541,10 +832,13 @@ sysret_check:
16145 LOCKDEP_SYS_EXIT
16146 DISABLE_INTERRUPTS(CLBR_NONE)
16147 TRACE_IRQS_OFF
16148 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16149 + GET_THREAD_INFO(%rcx)
16150 + movl TI_flags(%rcx),%edx
16151 andl %edi,%edx
16152 jnz sysret_careful
16153 CFI_REMEMBER_STATE
16154 + pax_exit_kernel_user
16155 + pax_erase_kstack
16156 /*
16157 * sysretq will re-enable interrupts:
16158 */
16159 @@ -596,14 +890,18 @@ badsys:
16160 * jump back to the normal fast path.
16161 */
16162 auditsys:
16163 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16164 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16165 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16166 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16167 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16168 movq %rax,%rsi /* 2nd arg: syscall number */
16169 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16170 call __audit_syscall_entry
16171 +
16172 + pax_erase_kstack
16173 +
16174 LOAD_ARGS 0 /* reload call-clobbered registers */
16175 + pax_set_fptr_mask
16176 jmp system_call_fastpath
16177
16178 /*
16179 @@ -624,7 +922,7 @@ sysret_audit:
16180 /* Do syscall tracing */
16181 tracesys:
16182 #ifdef CONFIG_AUDITSYSCALL
16183 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16184 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16185 jz auditsys
16186 #endif
16187 SAVE_REST
16188 @@ -632,12 +930,16 @@ tracesys:
16189 FIXUP_TOP_OF_STACK %rdi
16190 movq %rsp,%rdi
16191 call syscall_trace_enter
16192 +
16193 + pax_erase_kstack
16194 +
16195 /*
16196 * Reload arg registers from stack in case ptrace changed them.
16197 * We don't reload %rax because syscall_trace_enter() returned
16198 * the value it wants us to use in the table lookup.
16199 */
16200 LOAD_ARGS ARGOFFSET, 1
16201 + pax_set_fptr_mask
16202 RESTORE_REST
16203 #if __SYSCALL_MASK == ~0
16204 cmpq $__NR_syscall_max,%rax
16205 @@ -646,7 +948,7 @@ tracesys:
16206 cmpl $__NR_syscall_max,%eax
16207 #endif
16208 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16209 - movq %r10,%rcx /* fixup for C */
16210 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16211 call *sys_call_table(,%rax,8)
16212 movq %rax,RAX-ARGOFFSET(%rsp)
16213 /* Use IRET because user could have changed frame */
16214 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16215 andl %edi,%edx
16216 jnz int_careful
16217 andl $~TS_COMPAT,TI_status(%rcx)
16218 - jmp retint_swapgs
16219 + pax_exit_kernel_user
16220 + pax_erase_kstack
16221 + jmp retint_swapgs_pax
16222
16223 /* Either reschedule or signal or syscall exit tracking needed. */
16224 /* First do a reschedule test. */
16225 @@ -713,7 +1017,7 @@ int_restore_rest:
16226 TRACE_IRQS_OFF
16227 jmp int_with_check
16228 CFI_ENDPROC
16229 -END(system_call)
16230 +ENDPROC(system_call)
16231
16232 /*
16233 * Certain special system calls that need to save a complete full stack frame.
16234 @@ -729,7 +1033,7 @@ ENTRY(\label)
16235 call \func
16236 jmp ptregscall_common
16237 CFI_ENDPROC
16238 -END(\label)
16239 +ENDPROC(\label)
16240 .endm
16241
16242 PTREGSCALL stub_clone, sys_clone, %r8
16243 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16244 movq_cfi_restore R12+8, r12
16245 movq_cfi_restore RBP+8, rbp
16246 movq_cfi_restore RBX+8, rbx
16247 + pax_force_retaddr
16248 ret $REST_SKIP /* pop extended registers */
16249 CFI_ENDPROC
16250 -END(ptregscall_common)
16251 +ENDPROC(ptregscall_common)
16252
16253 ENTRY(stub_execve)
16254 CFI_STARTPROC
16255 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16256 RESTORE_REST
16257 jmp int_ret_from_sys_call
16258 CFI_ENDPROC
16259 -END(stub_execve)
16260 +ENDPROC(stub_execve)
16261
16262 /*
16263 * sigreturn is special because it needs to restore all registers on return.
16264 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16265 RESTORE_REST
16266 jmp int_ret_from_sys_call
16267 CFI_ENDPROC
16268 -END(stub_rt_sigreturn)
16269 +ENDPROC(stub_rt_sigreturn)
16270
16271 #ifdef CONFIG_X86_X32_ABI
16272 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16273 @@ -851,7 +1156,7 @@ vector=vector+1
16274 2: jmp common_interrupt
16275 .endr
16276 CFI_ENDPROC
16277 -END(irq_entries_start)
16278 +ENDPROC(irq_entries_start)
16279
16280 .previous
16281 END(interrupt)
16282 @@ -871,6 +1176,16 @@ END(interrupt)
16283 subq $ORIG_RAX-RBP, %rsp
16284 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16285 SAVE_ARGS_IRQ
16286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16287 + testb $3, CS(%rdi)
16288 + jnz 1f
16289 + pax_enter_kernel
16290 + jmp 2f
16291 +1: pax_enter_kernel_user
16292 +2:
16293 +#else
16294 + pax_enter_kernel
16295 +#endif
16296 call \func
16297 .endm
16298
16299 @@ -902,7 +1217,7 @@ ret_from_intr:
16300
16301 exit_intr:
16302 GET_THREAD_INFO(%rcx)
16303 - testl $3,CS-ARGOFFSET(%rsp)
16304 + testb $3,CS-ARGOFFSET(%rsp)
16305 je retint_kernel
16306
16307 /* Interrupt came from user space */
16308 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16309 * The iretq could re-enable interrupts:
16310 */
16311 DISABLE_INTERRUPTS(CLBR_ANY)
16312 + pax_exit_kernel_user
16313 +retint_swapgs_pax:
16314 TRACE_IRQS_IRETQ
16315 SWAPGS
16316 jmp restore_args
16317
16318 retint_restore_args: /* return to kernel space */
16319 DISABLE_INTERRUPTS(CLBR_ANY)
16320 + pax_exit_kernel
16321 + pax_force_retaddr RIP-ARGOFFSET
16322 /*
16323 * The iretq could re-enable interrupts:
16324 */
16325 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16326 #endif
16327
16328 CFI_ENDPROC
16329 -END(common_interrupt)
16330 +ENDPROC(common_interrupt)
16331 /*
16332 * End of kprobes section
16333 */
16334 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16335 interrupt \do_sym
16336 jmp ret_from_intr
16337 CFI_ENDPROC
16338 -END(\sym)
16339 +ENDPROC(\sym)
16340 .endm
16341
16342 #ifdef CONFIG_SMP
16343 @@ -1102,12 +1421,22 @@ ENTRY(\sym)
16344 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16345 call error_entry
16346 DEFAULT_FRAME 0
16347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16348 + testb $3, CS(%rsp)
16349 + jnz 1f
16350 + pax_enter_kernel
16351 + jmp 2f
16352 +1: pax_enter_kernel_user
16353 +2:
16354 +#else
16355 + pax_enter_kernel
16356 +#endif
16357 movq %rsp,%rdi /* pt_regs pointer */
16358 xorl %esi,%esi /* no error code */
16359 call \do_sym
16360 jmp error_exit /* %ebx: no swapgs flag */
16361 CFI_ENDPROC
16362 -END(\sym)
16363 +ENDPROC(\sym)
16364 .endm
16365
16366 .macro paranoidzeroentry sym do_sym
16367 @@ -1119,15 +1448,25 @@ ENTRY(\sym)
16368 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16369 call save_paranoid
16370 TRACE_IRQS_OFF
16371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16372 + testb $3, CS(%rsp)
16373 + jnz 1f
16374 + pax_enter_kernel
16375 + jmp 2f
16376 +1: pax_enter_kernel_user
16377 +2:
16378 +#else
16379 + pax_enter_kernel
16380 +#endif
16381 movq %rsp,%rdi /* pt_regs pointer */
16382 xorl %esi,%esi /* no error code */
16383 call \do_sym
16384 jmp paranoid_exit /* %ebx: no swapgs flag */
16385 CFI_ENDPROC
16386 -END(\sym)
16387 +ENDPROC(\sym)
16388 .endm
16389
16390 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16391 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16392 .macro paranoidzeroentry_ist sym do_sym ist
16393 ENTRY(\sym)
16394 INTR_FRAME
16395 @@ -1137,14 +1476,30 @@ ENTRY(\sym)
16396 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16397 call save_paranoid
16398 TRACE_IRQS_OFF_DEBUG
16399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16400 + testb $3, CS(%rsp)
16401 + jnz 1f
16402 + pax_enter_kernel
16403 + jmp 2f
16404 +1: pax_enter_kernel_user
16405 +2:
16406 +#else
16407 + pax_enter_kernel
16408 +#endif
16409 movq %rsp,%rdi /* pt_regs pointer */
16410 xorl %esi,%esi /* no error code */
16411 +#ifdef CONFIG_SMP
16412 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16413 + lea init_tss(%r12), %r12
16414 +#else
16415 + lea init_tss(%rip), %r12
16416 +#endif
16417 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16418 call \do_sym
16419 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16420 jmp paranoid_exit /* %ebx: no swapgs flag */
16421 CFI_ENDPROC
16422 -END(\sym)
16423 +ENDPROC(\sym)
16424 .endm
16425
16426 .macro errorentry sym do_sym
16427 @@ -1155,13 +1510,23 @@ ENTRY(\sym)
16428 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16429 call error_entry
16430 DEFAULT_FRAME 0
16431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16432 + testb $3, CS(%rsp)
16433 + jnz 1f
16434 + pax_enter_kernel
16435 + jmp 2f
16436 +1: pax_enter_kernel_user
16437 +2:
16438 +#else
16439 + pax_enter_kernel
16440 +#endif
16441 movq %rsp,%rdi /* pt_regs pointer */
16442 movq ORIG_RAX(%rsp),%rsi /* get error code */
16443 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16444 call \do_sym
16445 jmp error_exit /* %ebx: no swapgs flag */
16446 CFI_ENDPROC
16447 -END(\sym)
16448 +ENDPROC(\sym)
16449 .endm
16450
16451 /* error code is on the stack already */
16452 @@ -1174,13 +1539,23 @@ ENTRY(\sym)
16453 call save_paranoid
16454 DEFAULT_FRAME 0
16455 TRACE_IRQS_OFF
16456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16457 + testb $3, CS(%rsp)
16458 + jnz 1f
16459 + pax_enter_kernel
16460 + jmp 2f
16461 +1: pax_enter_kernel_user
16462 +2:
16463 +#else
16464 + pax_enter_kernel
16465 +#endif
16466 movq %rsp,%rdi /* pt_regs pointer */
16467 movq ORIG_RAX(%rsp),%rsi /* get error code */
16468 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16469 call \do_sym
16470 jmp paranoid_exit /* %ebx: no swapgs flag */
16471 CFI_ENDPROC
16472 -END(\sym)
16473 +ENDPROC(\sym)
16474 .endm
16475
16476 zeroentry divide_error do_divide_error
16477 @@ -1210,9 +1585,10 @@ gs_change:
16478 2: mfence /* workaround */
16479 SWAPGS
16480 popfq_cfi
16481 + pax_force_retaddr
16482 ret
16483 CFI_ENDPROC
16484 -END(native_load_gs_index)
16485 +ENDPROC(native_load_gs_index)
16486
16487 _ASM_EXTABLE(gs_change,bad_gs)
16488 .section .fixup,"ax"
16489 @@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16490 * Here we are in the child and the registers are set as they were
16491 * at kernel_thread() invocation in the parent.
16492 */
16493 + pax_force_fptr %rsi
16494 call *%rsi
16495 # exit
16496 mov %eax, %edi
16497 call do_exit
16498 ud2 # padding for call trace
16499 CFI_ENDPROC
16500 -END(kernel_thread_helper)
16501 +ENDPROC(kernel_thread_helper)
16502
16503 /*
16504 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16505 @@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16506 RESTORE_REST
16507 testq %rax,%rax
16508 je int_ret_from_sys_call
16509 - RESTORE_ARGS
16510 UNFAKE_STACK_FRAME
16511 + pax_force_retaddr
16512 ret
16513 CFI_ENDPROC
16514 -END(kernel_execve)
16515 +ENDPROC(kernel_execve)
16516
16517 /* Call softirq on interrupt stack. Interrupts are off. */
16518 ENTRY(call_softirq)
16519 @@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16520 CFI_DEF_CFA_REGISTER rsp
16521 CFI_ADJUST_CFA_OFFSET -8
16522 decl PER_CPU_VAR(irq_count)
16523 + pax_force_retaddr
16524 ret
16525 CFI_ENDPROC
16526 -END(call_softirq)
16527 +ENDPROC(call_softirq)
16528
16529 #ifdef CONFIG_XEN
16530 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16531 @@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16532 decl PER_CPU_VAR(irq_count)
16533 jmp error_exit
16534 CFI_ENDPROC
16535 -END(xen_do_hypervisor_callback)
16536 +ENDPROC(xen_do_hypervisor_callback)
16537
16538 /*
16539 * Hypervisor uses this for application faults while it executes.
16540 @@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16541 SAVE_ALL
16542 jmp error_exit
16543 CFI_ENDPROC
16544 -END(xen_failsafe_callback)
16545 +ENDPROC(xen_failsafe_callback)
16546
16547 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16548 xen_hvm_callback_vector xen_evtchn_do_upcall
16549 @@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16550 TRACE_IRQS_OFF_DEBUG
16551 testl %ebx,%ebx /* swapgs needed? */
16552 jnz paranoid_restore
16553 - testl $3,CS(%rsp)
16554 + testb $3,CS(%rsp)
16555 jnz paranoid_userspace
16556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16557 + pax_exit_kernel
16558 + TRACE_IRQS_IRETQ 0
16559 + SWAPGS_UNSAFE_STACK
16560 + RESTORE_ALL 8
16561 + pax_force_retaddr_bts
16562 + jmp irq_return
16563 +#endif
16564 paranoid_swapgs:
16565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16566 + pax_exit_kernel_user
16567 +#else
16568 + pax_exit_kernel
16569 +#endif
16570 TRACE_IRQS_IRETQ 0
16571 SWAPGS_UNSAFE_STACK
16572 RESTORE_ALL 8
16573 jmp irq_return
16574 paranoid_restore:
16575 + pax_exit_kernel
16576 TRACE_IRQS_IRETQ_DEBUG 0
16577 RESTORE_ALL 8
16578 + pax_force_retaddr_bts
16579 jmp irq_return
16580 paranoid_userspace:
16581 GET_THREAD_INFO(%rcx)
16582 @@ -1472,7 +1865,7 @@ paranoid_schedule:
16583 TRACE_IRQS_OFF
16584 jmp paranoid_userspace
16585 CFI_ENDPROC
16586 -END(paranoid_exit)
16587 +ENDPROC(paranoid_exit)
16588
16589 /*
16590 * Exception entry point. This expects an error code/orig_rax on the stack.
16591 @@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16592 movq_cfi r14, R14+8
16593 movq_cfi r15, R15+8
16594 xorl %ebx,%ebx
16595 - testl $3,CS+8(%rsp)
16596 + testb $3,CS+8(%rsp)
16597 je error_kernelspace
16598 error_swapgs:
16599 SWAPGS
16600 error_sti:
16601 TRACE_IRQS_OFF
16602 + pax_force_retaddr_bts
16603 ret
16604
16605 /*
16606 @@ -1531,7 +1925,7 @@ bstep_iret:
16607 movq %rcx,RIP+8(%rsp)
16608 jmp error_swapgs
16609 CFI_ENDPROC
16610 -END(error_entry)
16611 +ENDPROC(error_entry)
16612
16613
16614 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16615 @@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16616 jnz retint_careful
16617 jmp retint_swapgs
16618 CFI_ENDPROC
16619 -END(error_exit)
16620 +ENDPROC(error_exit)
16621
16622 /*
16623 * Test if a given stack is an NMI stack or not.
16624 @@ -1609,9 +2003,11 @@ ENTRY(nmi)
16625 * If %cs was not the kernel segment, then the NMI triggered in user
16626 * space, which means it is definitely not nested.
16627 */
16628 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16629 + je 1f
16630 cmpl $__KERNEL_CS, 16(%rsp)
16631 jne first_nmi
16632 -
16633 +1:
16634 /*
16635 * Check the special variable on the stack to see if NMIs are
16636 * executing.
16637 @@ -1758,6 +2154,16 @@ end_repeat_nmi:
16638 */
16639 call save_paranoid
16640 DEFAULT_FRAME 0
16641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16642 + testb $3, CS(%rsp)
16643 + jnz 1f
16644 + pax_enter_kernel
16645 + jmp 2f
16646 +1: pax_enter_kernel_user
16647 +2:
16648 +#else
16649 + pax_enter_kernel
16650 +#endif
16651 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16652 movq %rsp,%rdi
16653 movq $-1,%rsi
16654 @@ -1765,21 +2171,32 @@ end_repeat_nmi:
16655 testl %ebx,%ebx /* swapgs needed? */
16656 jnz nmi_restore
16657 nmi_swapgs:
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel_user
16660 +#else
16661 + pax_exit_kernel
16662 +#endif
16663 SWAPGS_UNSAFE_STACK
16664 + RESTORE_ALL 8
16665 + /* Clear the NMI executing stack variable */
16666 + movq $0, 10*8(%rsp)
16667 + jmp irq_return
16668 nmi_restore:
16669 + pax_exit_kernel
16670 RESTORE_ALL 8
16671 + pax_force_retaddr_bts
16672 /* Clear the NMI executing stack variable */
16673 movq $0, 10*8(%rsp)
16674 jmp irq_return
16675 CFI_ENDPROC
16676 -END(nmi)
16677 +ENDPROC(nmi)
16678
16679 ENTRY(ignore_sysret)
16680 CFI_STARTPROC
16681 mov $-ENOSYS,%eax
16682 sysret
16683 CFI_ENDPROC
16684 -END(ignore_sysret)
16685 +ENDPROC(ignore_sysret)
16686
16687 /*
16688 * End of kprobes section
16689 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16690 index c3a7cb4..3ad00dc 100644
16691 --- a/arch/x86/kernel/ftrace.c
16692 +++ b/arch/x86/kernel/ftrace.c
16693 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16694 {
16695 unsigned char replaced[MCOUNT_INSN_SIZE];
16696
16697 + ip = ktla_ktva(ip);
16698 +
16699 /*
16700 * Note: Due to modules and __init, code can
16701 * disappear and change, we need to protect against faulting
16702 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16703 unsigned char old[MCOUNT_INSN_SIZE], *new;
16704 int ret;
16705
16706 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16707 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16708 new = ftrace_call_replace(ip, (unsigned long)func);
16709
16710 /* See comment above by declaration of modifying_ftrace_code */
16711 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16712 {
16713 unsigned char code[MCOUNT_INSN_SIZE];
16714
16715 + ip = ktla_ktva(ip);
16716 +
16717 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16718 return -EFAULT;
16719
16720 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16721 index c18f59d..9c0c9f6 100644
16722 --- a/arch/x86/kernel/head32.c
16723 +++ b/arch/x86/kernel/head32.c
16724 @@ -18,6 +18,7 @@
16725 #include <asm/io_apic.h>
16726 #include <asm/bios_ebda.h>
16727 #include <asm/tlbflush.h>
16728 +#include <asm/boot.h>
16729
16730 static void __init i386_default_early_setup(void)
16731 {
16732 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16733
16734 void __init i386_start_kernel(void)
16735 {
16736 - memblock_reserve(__pa_symbol(&_text),
16737 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16738 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16739
16740 #ifdef CONFIG_BLK_DEV_INITRD
16741 /* Reserve INITRD */
16742 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16743 index d42ab17..cb1b997 100644
16744 --- a/arch/x86/kernel/head_32.S
16745 +++ b/arch/x86/kernel/head_32.S
16746 @@ -26,6 +26,12 @@
16747 /* Physical address */
16748 #define pa(X) ((X) - __PAGE_OFFSET)
16749
16750 +#ifdef CONFIG_PAX_KERNEXEC
16751 +#define ta(X) (X)
16752 +#else
16753 +#define ta(X) ((X) - __PAGE_OFFSET)
16754 +#endif
16755 +
16756 /*
16757 * References to members of the new_cpu_data structure.
16758 */
16759 @@ -55,11 +61,7 @@
16760 * and small than max_low_pfn, otherwise will waste some page table entries
16761 */
16762
16763 -#if PTRS_PER_PMD > 1
16764 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16765 -#else
16766 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16767 -#endif
16768 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16769
16770 /* Number of possible pages in the lowmem region */
16771 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16772 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16773 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16774
16775 /*
16776 + * Real beginning of normal "text" segment
16777 + */
16778 +ENTRY(stext)
16779 +ENTRY(_stext)
16780 +
16781 +/*
16782 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16783 * %esi points to the real-mode code as a 32-bit pointer.
16784 * CS and DS must be 4 GB flat segments, but we don't depend on
16785 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16786 * can.
16787 */
16788 __HEAD
16789 +
16790 +#ifdef CONFIG_PAX_KERNEXEC
16791 + jmp startup_32
16792 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16793 +.fill PAGE_SIZE-5,1,0xcc
16794 +#endif
16795 +
16796 ENTRY(startup_32)
16797 movl pa(stack_start),%ecx
16798
16799 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16800 2:
16801 leal -__PAGE_OFFSET(%ecx),%esp
16802
16803 +#ifdef CONFIG_SMP
16804 + movl $pa(cpu_gdt_table),%edi
16805 + movl $__per_cpu_load,%eax
16806 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16807 + rorl $16,%eax
16808 + movb %al,__KERNEL_PERCPU + 4(%edi)
16809 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16810 + movl $__per_cpu_end - 1,%eax
16811 + subl $__per_cpu_start,%eax
16812 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16813 +#endif
16814 +
16815 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16816 + movl $NR_CPUS,%ecx
16817 + movl $pa(cpu_gdt_table),%edi
16818 +1:
16819 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16820 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16821 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16822 + addl $PAGE_SIZE_asm,%edi
16823 + loop 1b
16824 +#endif
16825 +
16826 +#ifdef CONFIG_PAX_KERNEXEC
16827 + movl $pa(boot_gdt),%edi
16828 + movl $__LOAD_PHYSICAL_ADDR,%eax
16829 + movw %ax,__BOOT_CS + 2(%edi)
16830 + rorl $16,%eax
16831 + movb %al,__BOOT_CS + 4(%edi)
16832 + movb %ah,__BOOT_CS + 7(%edi)
16833 + rorl $16,%eax
16834 +
16835 + ljmp $(__BOOT_CS),$1f
16836 +1:
16837 +
16838 + movl $NR_CPUS,%ecx
16839 + movl $pa(cpu_gdt_table),%edi
16840 + addl $__PAGE_OFFSET,%eax
16841 +1:
16842 + movw %ax,__KERNEL_CS + 2(%edi)
16843 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16844 + rorl $16,%eax
16845 + movb %al,__KERNEL_CS + 4(%edi)
16846 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16847 + movb %ah,__KERNEL_CS + 7(%edi)
16848 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16849 + rorl $16,%eax
16850 + addl $PAGE_SIZE_asm,%edi
16851 + loop 1b
16852 +#endif
16853 +
16854 /*
16855 * Clear BSS first so that there are no surprises...
16856 */
16857 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16858 movl %eax, pa(max_pfn_mapped)
16859
16860 /* Do early initialization of the fixmap area */
16861 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16862 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16863 +#ifdef CONFIG_COMPAT_VDSO
16864 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16865 +#else
16866 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16867 +#endif
16868 #else /* Not PAE */
16869
16870 page_pde_offset = (__PAGE_OFFSET >> 20);
16871 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16872 movl %eax, pa(max_pfn_mapped)
16873
16874 /* Do early initialization of the fixmap area */
16875 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16876 - movl %eax,pa(initial_page_table+0xffc)
16877 +#ifdef CONFIG_COMPAT_VDSO
16878 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16879 +#else
16880 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16881 +#endif
16882 #endif
16883
16884 #ifdef CONFIG_PARAVIRT
16885 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16886 cmpl $num_subarch_entries, %eax
16887 jae bad_subarch
16888
16889 - movl pa(subarch_entries)(,%eax,4), %eax
16890 - subl $__PAGE_OFFSET, %eax
16891 - jmp *%eax
16892 + jmp *pa(subarch_entries)(,%eax,4)
16893
16894 bad_subarch:
16895 WEAK(lguest_entry)
16896 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16897 __INITDATA
16898
16899 subarch_entries:
16900 - .long default_entry /* normal x86/PC */
16901 - .long lguest_entry /* lguest hypervisor */
16902 - .long xen_entry /* Xen hypervisor */
16903 - .long default_entry /* Moorestown MID */
16904 + .long ta(default_entry) /* normal x86/PC */
16905 + .long ta(lguest_entry) /* lguest hypervisor */
16906 + .long ta(xen_entry) /* Xen hypervisor */
16907 + .long ta(default_entry) /* Moorestown MID */
16908 num_subarch_entries = (. - subarch_entries) / 4
16909 .previous
16910 #else
16911 @@ -310,6 +380,7 @@ default_entry:
16912 orl %edx,%eax
16913 movl %eax,%cr4
16914
16915 +#ifdef CONFIG_X86_PAE
16916 testb $X86_CR4_PAE, %al # check if PAE is enabled
16917 jz 6f
16918
16919 @@ -338,6 +409,9 @@ default_entry:
16920 /* Make changes effective */
16921 wrmsr
16922
16923 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16924 +#endif
16925 +
16926 6:
16927
16928 /*
16929 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16930 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16931 movl %eax,%ss # after changing gdt.
16932
16933 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16934 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16935 movl %eax,%ds
16936 movl %eax,%es
16937
16938 movl $(__KERNEL_PERCPU), %eax
16939 movl %eax,%fs # set this cpu's percpu
16940
16941 +#ifdef CONFIG_CC_STACKPROTECTOR
16942 movl $(__KERNEL_STACK_CANARY),%eax
16943 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16944 + movl $(__USER_DS),%eax
16945 +#else
16946 + xorl %eax,%eax
16947 +#endif
16948 movl %eax,%gs
16949
16950 xorl %eax,%eax # Clear LDT
16951 @@ -520,8 +600,11 @@ setup_once:
16952 * relocation. Manually set base address in stack canary
16953 * segment descriptor.
16954 */
16955 - movl $gdt_page,%eax
16956 + movl $cpu_gdt_table,%eax
16957 movl $stack_canary,%ecx
16958 +#ifdef CONFIG_SMP
16959 + addl $__per_cpu_load,%ecx
16960 +#endif
16961 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16962 shrl $16, %ecx
16963 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16964 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16965 /* This is global to keep gas from relaxing the jumps */
16966 ENTRY(early_idt_handler)
16967 cld
16968 - cmpl $2,%ss:early_recursion_flag
16969 + cmpl $1,%ss:early_recursion_flag
16970 je hlt_loop
16971 incl %ss:early_recursion_flag
16972
16973 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16974 pushl (20+6*4)(%esp) /* trapno */
16975 pushl $fault_msg
16976 call printk
16977 -#endif
16978 call dump_stack
16979 +#endif
16980 hlt_loop:
16981 hlt
16982 jmp hlt_loop
16983 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16984 /* This is the default interrupt "handler" :-) */
16985 ALIGN
16986 ignore_int:
16987 - cld
16988 #ifdef CONFIG_PRINTK
16989 + cmpl $2,%ss:early_recursion_flag
16990 + je hlt_loop
16991 + incl %ss:early_recursion_flag
16992 + cld
16993 pushl %eax
16994 pushl %ecx
16995 pushl %edx
16996 @@ -620,9 +706,6 @@ ignore_int:
16997 movl $(__KERNEL_DS),%eax
16998 movl %eax,%ds
16999 movl %eax,%es
17000 - cmpl $2,early_recursion_flag
17001 - je hlt_loop
17002 - incl early_recursion_flag
17003 pushl 16(%esp)
17004 pushl 24(%esp)
17005 pushl 32(%esp)
17006 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17007 /*
17008 * BSS section
17009 */
17010 -__PAGE_ALIGNED_BSS
17011 - .align PAGE_SIZE
17012 #ifdef CONFIG_X86_PAE
17013 +.section .initial_pg_pmd,"a",@progbits
17014 initial_pg_pmd:
17015 .fill 1024*KPMDS,4,0
17016 #else
17017 +.section .initial_page_table,"a",@progbits
17018 ENTRY(initial_page_table)
17019 .fill 1024,4,0
17020 #endif
17021 +.section .initial_pg_fixmap,"a",@progbits
17022 initial_pg_fixmap:
17023 .fill 1024,4,0
17024 +.section .empty_zero_page,"a",@progbits
17025 ENTRY(empty_zero_page)
17026 .fill 4096,1,0
17027 +.section .swapper_pg_dir,"a",@progbits
17028 ENTRY(swapper_pg_dir)
17029 +#ifdef CONFIG_X86_PAE
17030 + .fill 4,8,0
17031 +#else
17032 .fill 1024,4,0
17033 +#endif
17034 +
17035 +/*
17036 + * The IDT has to be page-aligned to simplify the Pentium
17037 + * F0 0F bug workaround.. We have a special link segment
17038 + * for this.
17039 + */
17040 +.section .idt,"a",@progbits
17041 +ENTRY(idt_table)
17042 + .fill 256,8,0
17043
17044 /*
17045 * This starts the data section.
17046 */
17047 #ifdef CONFIG_X86_PAE
17048 -__PAGE_ALIGNED_DATA
17049 - /* Page-aligned for the benefit of paravirt? */
17050 - .align PAGE_SIZE
17051 +.section .initial_page_table,"a",@progbits
17052 ENTRY(initial_page_table)
17053 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17054 # if KPMDS == 3
17055 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17056 # error "Kernel PMDs should be 1, 2 or 3"
17057 # endif
17058 .align PAGE_SIZE /* needs to be page-sized too */
17059 +
17060 +#ifdef CONFIG_PAX_PER_CPU_PGD
17061 +ENTRY(cpu_pgd)
17062 + .rept NR_CPUS
17063 + .fill 4,8,0
17064 + .endr
17065 +#endif
17066 +
17067 #endif
17068
17069 .data
17070 .balign 4
17071 ENTRY(stack_start)
17072 - .long init_thread_union+THREAD_SIZE
17073 + .long init_thread_union+THREAD_SIZE-8
17074
17075 __INITRODATA
17076 int_msg:
17077 @@ -730,7 +835,7 @@ fault_msg:
17078 * segment size, and 32-bit linear address value:
17079 */
17080
17081 - .data
17082 +.section .rodata,"a",@progbits
17083 .globl boot_gdt_descr
17084 .globl idt_descr
17085
17086 @@ -739,7 +844,7 @@ fault_msg:
17087 .word 0 # 32 bit align gdt_desc.address
17088 boot_gdt_descr:
17089 .word __BOOT_DS+7
17090 - .long boot_gdt - __PAGE_OFFSET
17091 + .long pa(boot_gdt)
17092
17093 .word 0 # 32-bit align idt_desc.address
17094 idt_descr:
17095 @@ -750,7 +855,7 @@ idt_descr:
17096 .word 0 # 32 bit align gdt_desc.address
17097 ENTRY(early_gdt_descr)
17098 .word GDT_ENTRIES*8-1
17099 - .long gdt_page /* Overwritten for secondary CPUs */
17100 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17101
17102 /*
17103 * The boot_gdt must mirror the equivalent in setup.S and is
17104 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17105 .align L1_CACHE_BYTES
17106 ENTRY(boot_gdt)
17107 .fill GDT_ENTRY_BOOT_CS,8,0
17108 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17109 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17110 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17111 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17112 +
17113 + .align PAGE_SIZE_asm
17114 +ENTRY(cpu_gdt_table)
17115 + .rept NR_CPUS
17116 + .quad 0x0000000000000000 /* NULL descriptor */
17117 + .quad 0x0000000000000000 /* 0x0b reserved */
17118 + .quad 0x0000000000000000 /* 0x13 reserved */
17119 + .quad 0x0000000000000000 /* 0x1b reserved */
17120 +
17121 +#ifdef CONFIG_PAX_KERNEXEC
17122 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17123 +#else
17124 + .quad 0x0000000000000000 /* 0x20 unused */
17125 +#endif
17126 +
17127 + .quad 0x0000000000000000 /* 0x28 unused */
17128 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17129 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17130 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17131 + .quad 0x0000000000000000 /* 0x4b reserved */
17132 + .quad 0x0000000000000000 /* 0x53 reserved */
17133 + .quad 0x0000000000000000 /* 0x5b reserved */
17134 +
17135 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17136 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17137 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17138 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17139 +
17140 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17141 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17142 +
17143 + /*
17144 + * Segments used for calling PnP BIOS have byte granularity.
17145 + * The code segments and data segments have fixed 64k limits,
17146 + * the transfer segment sizes are set at run time.
17147 + */
17148 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17149 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17150 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17151 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17152 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17153 +
17154 + /*
17155 + * The APM segments have byte granularity and their bases
17156 + * are set at run time. All have 64k limits.
17157 + */
17158 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17159 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17160 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17161 +
17162 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17163 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17164 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17165 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17166 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17167 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17168 +
17169 + /* Be sure this is zeroed to avoid false validations in Xen */
17170 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17171 + .endr
17172 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17173 index 94bf9cc..400455a 100644
17174 --- a/arch/x86/kernel/head_64.S
17175 +++ b/arch/x86/kernel/head_64.S
17176 @@ -20,6 +20,8 @@
17177 #include <asm/processor-flags.h>
17178 #include <asm/percpu.h>
17179 #include <asm/nops.h>
17180 +#include <asm/cpufeature.h>
17181 +#include <asm/alternative-asm.h>
17182
17183 #ifdef CONFIG_PARAVIRT
17184 #include <asm/asm-offsets.h>
17185 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17186 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17187 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17188 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17189 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17190 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17191 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17192 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17193 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17194 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17195
17196 .text
17197 __HEAD
17198 @@ -88,35 +96,23 @@ startup_64:
17199 */
17200 addq %rbp, init_level4_pgt + 0(%rip)
17201 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17202 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17203 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17204 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17205 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17206
17207 addq %rbp, level3_ident_pgt + 0(%rip)
17208 +#ifndef CONFIG_XEN
17209 + addq %rbp, level3_ident_pgt + 8(%rip)
17210 +#endif
17211
17212 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17213 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17214 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17215 +
17216 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17217 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17218
17219 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17220 -
17221 - /* Add an Identity mapping if I am above 1G */
17222 - leaq _text(%rip), %rdi
17223 - andq $PMD_PAGE_MASK, %rdi
17224 -
17225 - movq %rdi, %rax
17226 - shrq $PUD_SHIFT, %rax
17227 - andq $(PTRS_PER_PUD - 1), %rax
17228 - jz ident_complete
17229 -
17230 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17231 - leaq level3_ident_pgt(%rip), %rbx
17232 - movq %rdx, 0(%rbx, %rax, 8)
17233 -
17234 - movq %rdi, %rax
17235 - shrq $PMD_SHIFT, %rax
17236 - andq $(PTRS_PER_PMD - 1), %rax
17237 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17238 - leaq level2_spare_pgt(%rip), %rbx
17239 - movq %rdx, 0(%rbx, %rax, 8)
17240 -ident_complete:
17241 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17242
17243 /*
17244 * Fixup the kernel text+data virtual addresses. Note that
17245 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17246 * after the boot processor executes this code.
17247 */
17248
17249 - /* Enable PAE mode and PGE */
17250 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17251 + /* Enable PAE mode and PSE/PGE */
17252 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17253 movq %rax, %cr4
17254
17255 /* Setup early boot stage 4 level pagetables. */
17256 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17257 movl $MSR_EFER, %ecx
17258 rdmsr
17259 btsl $_EFER_SCE, %eax /* Enable System Call */
17260 - btl $20,%edi /* No Execute supported? */
17261 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17262 jnc 1f
17263 btsl $_EFER_NX, %eax
17264 + leaq init_level4_pgt(%rip), %rdi
17265 +#ifndef CONFIG_EFI
17266 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17267 +#endif
17268 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17269 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17270 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17271 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17272 1: wrmsr /* Make changes effective */
17273
17274 /* Setup cr0 */
17275 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17276 * jump. In addition we need to ensure %cs is set so we make this
17277 * a far return.
17278 */
17279 + pax_set_fptr_mask
17280 movq initial_code(%rip),%rax
17281 pushq $0 # fake return address to stop unwinder
17282 pushq $__KERNEL_CS # set correct cs
17283 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17284 bad_address:
17285 jmp bad_address
17286
17287 - .section ".init.text","ax"
17288 + __INIT
17289 .globl early_idt_handlers
17290 early_idt_handlers:
17291 # 104(%rsp) %rflags
17292 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17293 addq $16,%rsp # drop vector number and error code
17294 decl early_recursion_flag(%rip)
17295 INTERRUPT_RETURN
17296 + .previous
17297
17298 + __INITDATA
17299 .balign 4
17300 early_recursion_flag:
17301 .long 0
17302 + .previous
17303
17304 + .section .rodata,"a",@progbits
17305 #ifdef CONFIG_EARLY_PRINTK
17306 early_idt_msg:
17307 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17308 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17309 #endif /* CONFIG_EARLY_PRINTK */
17310 .previous
17311
17312 + .section .rodata,"a",@progbits
17313 #define NEXT_PAGE(name) \
17314 .balign PAGE_SIZE; \
17315 ENTRY(name)
17316 @@ -372,7 +382,6 @@ ENTRY(name)
17317 i = i + 1 ; \
17318 .endr
17319
17320 - .data
17321 /*
17322 * This default setting generates an ident mapping at address 0x100000
17323 * and a mapping for the kernel that precisely maps virtual address
17324 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17325 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17326 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17327 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17328 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17329 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17330 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17331 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17332 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17333 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17334 .org init_level4_pgt + L4_START_KERNEL*8, 0
17335 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17336 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17337
17338 +#ifdef CONFIG_PAX_PER_CPU_PGD
17339 +NEXT_PAGE(cpu_pgd)
17340 + .rept NR_CPUS
17341 + .fill 512,8,0
17342 + .endr
17343 +#endif
17344 +
17345 NEXT_PAGE(level3_ident_pgt)
17346 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17347 +#ifdef CONFIG_XEN
17348 .fill 511,8,0
17349 +#else
17350 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17351 + .fill 510,8,0
17352 +#endif
17353 +
17354 +NEXT_PAGE(level3_vmalloc_start_pgt)
17355 + .fill 512,8,0
17356 +
17357 +NEXT_PAGE(level3_vmalloc_end_pgt)
17358 + .fill 512,8,0
17359 +
17360 +NEXT_PAGE(level3_vmemmap_pgt)
17361 + .fill L3_VMEMMAP_START,8,0
17362 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17363
17364 NEXT_PAGE(level3_kernel_pgt)
17365 .fill L3_START_KERNEL,8,0
17366 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17367 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17368 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17369
17370 +NEXT_PAGE(level2_vmemmap_pgt)
17371 + .fill 512,8,0
17372 +
17373 NEXT_PAGE(level2_fixmap_pgt)
17374 - .fill 506,8,0
17375 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17376 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17377 - .fill 5,8,0
17378 + .fill 507,8,0
17379 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17380 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17381 + .fill 4,8,0
17382
17383 -NEXT_PAGE(level1_fixmap_pgt)
17384 +NEXT_PAGE(level1_vsyscall_pgt)
17385 .fill 512,8,0
17386
17387 -NEXT_PAGE(level2_ident_pgt)
17388 - /* Since I easily can, map the first 1G.
17389 + /* Since I easily can, map the first 2G.
17390 * Don't set NX because code runs from these pages.
17391 */
17392 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17393 +NEXT_PAGE(level2_ident_pgt)
17394 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17395
17396 NEXT_PAGE(level2_kernel_pgt)
17397 /*
17398 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17399 * If you want to increase this then increase MODULES_VADDR
17400 * too.)
17401 */
17402 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17403 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17404 -
17405 -NEXT_PAGE(level2_spare_pgt)
17406 - .fill 512, 8, 0
17407 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17408
17409 #undef PMDS
17410 #undef NEXT_PAGE
17411
17412 - .data
17413 + .align PAGE_SIZE
17414 +ENTRY(cpu_gdt_table)
17415 + .rept NR_CPUS
17416 + .quad 0x0000000000000000 /* NULL descriptor */
17417 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17418 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17419 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17420 + .quad 0x00cffb000000ffff /* __USER32_CS */
17421 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17422 + .quad 0x00affb000000ffff /* __USER_CS */
17423 +
17424 +#ifdef CONFIG_PAX_KERNEXEC
17425 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17426 +#else
17427 + .quad 0x0 /* unused */
17428 +#endif
17429 +
17430 + .quad 0,0 /* TSS */
17431 + .quad 0,0 /* LDT */
17432 + .quad 0,0,0 /* three TLS descriptors */
17433 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17434 + /* asm/segment.h:GDT_ENTRIES must match this */
17435 +
17436 + /* zero the remaining page */
17437 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17438 + .endr
17439 +
17440 .align 16
17441 .globl early_gdt_descr
17442 early_gdt_descr:
17443 .word GDT_ENTRIES*8-1
17444 early_gdt_descr_base:
17445 - .quad INIT_PER_CPU_VAR(gdt_page)
17446 + .quad cpu_gdt_table
17447
17448 ENTRY(phys_base)
17449 /* This must match the first entry in level2_kernel_pgt */
17450 .quad 0x0000000000000000
17451
17452 #include "../../x86/xen/xen-head.S"
17453 -
17454 - .section .bss, "aw", @nobits
17455 +
17456 + .section .rodata,"a",@progbits
17457 .align L1_CACHE_BYTES
17458 ENTRY(idt_table)
17459 - .skip IDT_ENTRIES * 16
17460 + .fill 512,8,0
17461
17462 .align L1_CACHE_BYTES
17463 ENTRY(nmi_idt_table)
17464 - .skip IDT_ENTRIES * 16
17465 + .fill 512,8,0
17466
17467 __PAGE_ALIGNED_BSS
17468 .align PAGE_SIZE
17469 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17470 index 9c3bd4a..e1d9b35 100644
17471 --- a/arch/x86/kernel/i386_ksyms_32.c
17472 +++ b/arch/x86/kernel/i386_ksyms_32.c
17473 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17474 EXPORT_SYMBOL(cmpxchg8b_emu);
17475 #endif
17476
17477 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17478 +
17479 /* Networking helper routines. */
17480 EXPORT_SYMBOL(csum_partial_copy_generic);
17481 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17482 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17483
17484 EXPORT_SYMBOL(__get_user_1);
17485 EXPORT_SYMBOL(__get_user_2);
17486 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17487
17488 EXPORT_SYMBOL(csum_partial);
17489 EXPORT_SYMBOL(empty_zero_page);
17490 +
17491 +#ifdef CONFIG_PAX_KERNEXEC
17492 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17493 +#endif
17494 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17495 index f250431..54097e7 100644
17496 --- a/arch/x86/kernel/i387.c
17497 +++ b/arch/x86/kernel/i387.c
17498 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17499 static inline bool interrupted_user_mode(void)
17500 {
17501 struct pt_regs *regs = get_irq_regs();
17502 - return regs && user_mode_vm(regs);
17503 + return regs && user_mode(regs);
17504 }
17505
17506 /*
17507 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17508 index 36d1853..bf25736 100644
17509 --- a/arch/x86/kernel/i8259.c
17510 +++ b/arch/x86/kernel/i8259.c
17511 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17512 "spurious 8259A interrupt: IRQ%d.\n", irq);
17513 spurious_irq_mask |= irqmask;
17514 }
17515 - atomic_inc(&irq_err_count);
17516 + atomic_inc_unchecked(&irq_err_count);
17517 /*
17518 * Theoretically we do not have to handle this IRQ,
17519 * but in Linux this does not cause problems and is
17520 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17521 index 8c96897..be66bfa 100644
17522 --- a/arch/x86/kernel/ioport.c
17523 +++ b/arch/x86/kernel/ioport.c
17524 @@ -6,6 +6,7 @@
17525 #include <linux/sched.h>
17526 #include <linux/kernel.h>
17527 #include <linux/capability.h>
17528 +#include <linux/security.h>
17529 #include <linux/errno.h>
17530 #include <linux/types.h>
17531 #include <linux/ioport.h>
17532 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17533
17534 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17535 return -EINVAL;
17536 +#ifdef CONFIG_GRKERNSEC_IO
17537 + if (turn_on && grsec_disable_privio) {
17538 + gr_handle_ioperm();
17539 + return -EPERM;
17540 + }
17541 +#endif
17542 if (turn_on && !capable(CAP_SYS_RAWIO))
17543 return -EPERM;
17544
17545 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17546 * because the ->io_bitmap_max value must match the bitmap
17547 * contents:
17548 */
17549 - tss = &per_cpu(init_tss, get_cpu());
17550 + tss = init_tss + get_cpu();
17551
17552 if (turn_on)
17553 bitmap_clear(t->io_bitmap_ptr, from, num);
17554 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17555 return -EINVAL;
17556 /* Trying to gain more privileges? */
17557 if (level > old) {
17558 +#ifdef CONFIG_GRKERNSEC_IO
17559 + if (grsec_disable_privio) {
17560 + gr_handle_iopl();
17561 + return -EPERM;
17562 + }
17563 +#endif
17564 if (!capable(CAP_SYS_RAWIO))
17565 return -EPERM;
17566 }
17567 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17568 index 3dafc60..aa8e9c4 100644
17569 --- a/arch/x86/kernel/irq.c
17570 +++ b/arch/x86/kernel/irq.c
17571 @@ -18,7 +18,7 @@
17572 #include <asm/mce.h>
17573 #include <asm/hw_irq.h>
17574
17575 -atomic_t irq_err_count;
17576 +atomic_unchecked_t irq_err_count;
17577
17578 /* Function pointer for generic interrupt vector handling */
17579 void (*x86_platform_ipi_callback)(void) = NULL;
17580 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17581 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17582 seq_printf(p, " Machine check polls\n");
17583 #endif
17584 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17585 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17586 #if defined(CONFIG_X86_IO_APIC)
17587 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17588 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17589 #endif
17590 return 0;
17591 }
17592 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17593
17594 u64 arch_irq_stat(void)
17595 {
17596 - u64 sum = atomic_read(&irq_err_count);
17597 + u64 sum = atomic_read_unchecked(&irq_err_count);
17598
17599 #ifdef CONFIG_X86_IO_APIC
17600 - sum += atomic_read(&irq_mis_count);
17601 + sum += atomic_read_unchecked(&irq_mis_count);
17602 #endif
17603 return sum;
17604 }
17605 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17606 index 344faf8..355f60d 100644
17607 --- a/arch/x86/kernel/irq_32.c
17608 +++ b/arch/x86/kernel/irq_32.c
17609 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17610 __asm__ __volatile__("andl %%esp,%0" :
17611 "=r" (sp) : "0" (THREAD_SIZE - 1));
17612
17613 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17614 + return sp < STACK_WARN;
17615 }
17616
17617 static void print_stack_overflow(void)
17618 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17619 * per-CPU IRQ handling contexts (thread information and stack)
17620 */
17621 union irq_ctx {
17622 - struct thread_info tinfo;
17623 - u32 stack[THREAD_SIZE/sizeof(u32)];
17624 + unsigned long previous_esp;
17625 + u32 stack[THREAD_SIZE/sizeof(u32)];
17626 } __attribute__((aligned(THREAD_SIZE)));
17627
17628 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17629 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17630 static inline int
17631 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17632 {
17633 - union irq_ctx *curctx, *irqctx;
17634 + union irq_ctx *irqctx;
17635 u32 *isp, arg1, arg2;
17636
17637 - curctx = (union irq_ctx *) current_thread_info();
17638 irqctx = __this_cpu_read(hardirq_ctx);
17639
17640 /*
17641 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17642 * handler) we can't do that and just have to keep using the
17643 * current stack (which is the irq stack already after all)
17644 */
17645 - if (unlikely(curctx == irqctx))
17646 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17647 return 0;
17648
17649 /* build the stack frame on the IRQ stack */
17650 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17651 - irqctx->tinfo.task = curctx->tinfo.task;
17652 - irqctx->tinfo.previous_esp = current_stack_pointer;
17653 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17654 + irqctx->previous_esp = current_stack_pointer;
17655
17656 - /* Copy the preempt_count so that the [soft]irq checks work. */
17657 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17659 + __set_fs(MAKE_MM_SEG(0));
17660 +#endif
17661
17662 if (unlikely(overflow))
17663 call_on_stack(print_stack_overflow, isp);
17664 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17665 : "0" (irq), "1" (desc), "2" (isp),
17666 "D" (desc->handle_irq)
17667 : "memory", "cc", "ecx");
17668 +
17669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17670 + __set_fs(current_thread_info()->addr_limit);
17671 +#endif
17672 +
17673 return 1;
17674 }
17675
17676 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17677 */
17678 void __cpuinit irq_ctx_init(int cpu)
17679 {
17680 - union irq_ctx *irqctx;
17681 -
17682 if (per_cpu(hardirq_ctx, cpu))
17683 return;
17684
17685 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17686 - THREADINFO_GFP,
17687 - THREAD_SIZE_ORDER));
17688 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17689 - irqctx->tinfo.cpu = cpu;
17690 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17691 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17692 -
17693 - per_cpu(hardirq_ctx, cpu) = irqctx;
17694 -
17695 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17696 - THREADINFO_GFP,
17697 - THREAD_SIZE_ORDER));
17698 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17699 - irqctx->tinfo.cpu = cpu;
17700 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17701 -
17702 - per_cpu(softirq_ctx, cpu) = irqctx;
17703 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17704 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17705 +
17706 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17707 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17708
17709 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17710 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17711 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17712 asmlinkage void do_softirq(void)
17713 {
17714 unsigned long flags;
17715 - struct thread_info *curctx;
17716 union irq_ctx *irqctx;
17717 u32 *isp;
17718
17719 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17720 local_irq_save(flags);
17721
17722 if (local_softirq_pending()) {
17723 - curctx = current_thread_info();
17724 irqctx = __this_cpu_read(softirq_ctx);
17725 - irqctx->tinfo.task = curctx->task;
17726 - irqctx->tinfo.previous_esp = current_stack_pointer;
17727 + irqctx->previous_esp = current_stack_pointer;
17728
17729 /* build the stack frame on the softirq stack */
17730 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17731 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17732 +
17733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17734 + __set_fs(MAKE_MM_SEG(0));
17735 +#endif
17736
17737 call_on_stack(__do_softirq, isp);
17738 +
17739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17740 + __set_fs(current_thread_info()->addr_limit);
17741 +#endif
17742 +
17743 /*
17744 * Shouldn't happen, we returned above if in_interrupt():
17745 */
17746 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17747 if (unlikely(!desc))
17748 return false;
17749
17750 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17751 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17752 if (unlikely(overflow))
17753 print_stack_overflow();
17754 desc->handle_irq(irq, desc);
17755 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17756 index d04d3ec..ea4b374 100644
17757 --- a/arch/x86/kernel/irq_64.c
17758 +++ b/arch/x86/kernel/irq_64.c
17759 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17760 u64 estack_top, estack_bottom;
17761 u64 curbase = (u64)task_stack_page(current);
17762
17763 - if (user_mode_vm(regs))
17764 + if (user_mode(regs))
17765 return;
17766
17767 if (regs->sp >= curbase + sizeof(struct thread_info) +
17768 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17769 index 1d5d31e..72731d4 100644
17770 --- a/arch/x86/kernel/kdebugfs.c
17771 +++ b/arch/x86/kernel/kdebugfs.c
17772 @@ -27,7 +27,7 @@ struct setup_data_node {
17773 u32 len;
17774 };
17775
17776 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17777 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17778 size_t count, loff_t *ppos)
17779 {
17780 struct setup_data_node *node = file->private_data;
17781 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17782 index 3f61904..873cea9 100644
17783 --- a/arch/x86/kernel/kgdb.c
17784 +++ b/arch/x86/kernel/kgdb.c
17785 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17786 #ifdef CONFIG_X86_32
17787 switch (regno) {
17788 case GDB_SS:
17789 - if (!user_mode_vm(regs))
17790 + if (!user_mode(regs))
17791 *(unsigned long *)mem = __KERNEL_DS;
17792 break;
17793 case GDB_SP:
17794 - if (!user_mode_vm(regs))
17795 + if (!user_mode(regs))
17796 *(unsigned long *)mem = kernel_stack_pointer(regs);
17797 break;
17798 case GDB_GS:
17799 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17800 case 'k':
17801 /* clear the trace bit */
17802 linux_regs->flags &= ~X86_EFLAGS_TF;
17803 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17804 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17805
17806 /* set the trace bit if we're stepping */
17807 if (remcomInBuffer[0] == 's') {
17808 linux_regs->flags |= X86_EFLAGS_TF;
17809 - atomic_set(&kgdb_cpu_doing_single_step,
17810 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17811 raw_smp_processor_id());
17812 }
17813
17814 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17815
17816 switch (cmd) {
17817 case DIE_DEBUG:
17818 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17819 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17820 if (user_mode(regs))
17821 return single_step_cont(regs, args);
17822 break;
17823 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17824 index c5e410e..da6aaf9 100644
17825 --- a/arch/x86/kernel/kprobes-opt.c
17826 +++ b/arch/x86/kernel/kprobes-opt.c
17827 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17828 * Verify if the address gap is in 2GB range, because this uses
17829 * a relative jump.
17830 */
17831 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17832 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17833 if (abs(rel) > 0x7fffffff)
17834 return -ERANGE;
17835
17836 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17837 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17838
17839 /* Set probe function call */
17840 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17841 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17842
17843 /* Set returning jmp instruction at the tail of out-of-line buffer */
17844 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17845 - (u8 *)op->kp.addr + op->optinsn.size);
17846 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17847
17848 flush_icache_range((unsigned long) buf,
17849 (unsigned long) buf + TMPL_END_IDX +
17850 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17851 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17852
17853 /* Backup instructions which will be replaced by jump address */
17854 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17855 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17856 RELATIVE_ADDR_SIZE);
17857
17858 insn_buf[0] = RELATIVEJUMP_OPCODE;
17859 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17860 index e2f751e..dffa2a0 100644
17861 --- a/arch/x86/kernel/kprobes.c
17862 +++ b/arch/x86/kernel/kprobes.c
17863 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17864 } __attribute__((packed)) *insn;
17865
17866 insn = (struct __arch_relative_insn *)from;
17867 +
17868 + pax_open_kernel();
17869 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17870 insn->op = op;
17871 + pax_close_kernel();
17872 }
17873
17874 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17875 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17876 kprobe_opcode_t opcode;
17877 kprobe_opcode_t *orig_opcodes = opcodes;
17878
17879 - if (search_exception_tables((unsigned long)opcodes))
17880 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17881 return 0; /* Page fault may occur on this address. */
17882
17883 retry:
17884 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17885 /* Another subsystem puts a breakpoint, failed to recover */
17886 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17887 return 0;
17888 + pax_open_kernel();
17889 memcpy(dest, insn.kaddr, insn.length);
17890 + pax_close_kernel();
17891
17892 #ifdef CONFIG_X86_64
17893 if (insn_rip_relative(&insn)) {
17894 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17895 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17896 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17897 disp = (u8 *) dest + insn_offset_displacement(&insn);
17898 + pax_open_kernel();
17899 *(s32 *) disp = (s32) newdisp;
17900 + pax_close_kernel();
17901 }
17902 #endif
17903 return insn.length;
17904 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17905 * nor set current_kprobe, because it doesn't use single
17906 * stepping.
17907 */
17908 - regs->ip = (unsigned long)p->ainsn.insn;
17909 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17910 preempt_enable_no_resched();
17911 return;
17912 }
17913 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17914 if (p->opcode == BREAKPOINT_INSTRUCTION)
17915 regs->ip = (unsigned long)p->addr;
17916 else
17917 - regs->ip = (unsigned long)p->ainsn.insn;
17918 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17919 }
17920
17921 /*
17922 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17923 setup_singlestep(p, regs, kcb, 0);
17924 return 1;
17925 }
17926 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17927 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17928 /*
17929 * The breakpoint instruction was removed right
17930 * after we hit it. Another cpu has removed
17931 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17932 " movq %rax, 152(%rsp)\n"
17933 RESTORE_REGS_STRING
17934 " popfq\n"
17935 +#ifdef KERNEXEC_PLUGIN
17936 + " btsq $63,(%rsp)\n"
17937 +#endif
17938 #else
17939 " pushf\n"
17940 SAVE_REGS_STRING
17941 @@ -765,7 +775,7 @@ static void __kprobes
17942 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17943 {
17944 unsigned long *tos = stack_addr(regs);
17945 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17946 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17947 unsigned long orig_ip = (unsigned long)p->addr;
17948 kprobe_opcode_t *insn = p->ainsn.insn;
17949
17950 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17951 struct die_args *args = data;
17952 int ret = NOTIFY_DONE;
17953
17954 - if (args->regs && user_mode_vm(args->regs))
17955 + if (args->regs && user_mode(args->regs))
17956 return ret;
17957
17958 switch (val) {
17959 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17960 index ebc9873..1b9724b 100644
17961 --- a/arch/x86/kernel/ldt.c
17962 +++ b/arch/x86/kernel/ldt.c
17963 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17964 if (reload) {
17965 #ifdef CONFIG_SMP
17966 preempt_disable();
17967 - load_LDT(pc);
17968 + load_LDT_nolock(pc);
17969 if (!cpumask_equal(mm_cpumask(current->mm),
17970 cpumask_of(smp_processor_id())))
17971 smp_call_function(flush_ldt, current->mm, 1);
17972 preempt_enable();
17973 #else
17974 - load_LDT(pc);
17975 + load_LDT_nolock(pc);
17976 #endif
17977 }
17978 if (oldsize) {
17979 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17980 return err;
17981
17982 for (i = 0; i < old->size; i++)
17983 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17984 + write_ldt_entry(new->ldt, i, old->ldt + i);
17985 return 0;
17986 }
17987
17988 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17989 retval = copy_ldt(&mm->context, &old_mm->context);
17990 mutex_unlock(&old_mm->context.lock);
17991 }
17992 +
17993 + if (tsk == current) {
17994 + mm->context.vdso = 0;
17995 +
17996 +#ifdef CONFIG_X86_32
17997 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17998 + mm->context.user_cs_base = 0UL;
17999 + mm->context.user_cs_limit = ~0UL;
18000 +
18001 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18002 + cpus_clear(mm->context.cpu_user_cs_mask);
18003 +#endif
18004 +
18005 +#endif
18006 +#endif
18007 +
18008 + }
18009 +
18010 return retval;
18011 }
18012
18013 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18014 }
18015 }
18016
18017 +#ifdef CONFIG_PAX_SEGMEXEC
18018 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18019 + error = -EINVAL;
18020 + goto out_unlock;
18021 + }
18022 +#endif
18023 +
18024 fill_ldt(&ldt, &ldt_info);
18025 if (oldmode)
18026 ldt.avl = 0;
18027 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18028 index 5b19e4d..6476a76 100644
18029 --- a/arch/x86/kernel/machine_kexec_32.c
18030 +++ b/arch/x86/kernel/machine_kexec_32.c
18031 @@ -26,7 +26,7 @@
18032 #include <asm/cacheflush.h>
18033 #include <asm/debugreg.h>
18034
18035 -static void set_idt(void *newidt, __u16 limit)
18036 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18037 {
18038 struct desc_ptr curidt;
18039
18040 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18041 }
18042
18043
18044 -static void set_gdt(void *newgdt, __u16 limit)
18045 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18046 {
18047 struct desc_ptr curgdt;
18048
18049 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18050 }
18051
18052 control_page = page_address(image->control_code_page);
18053 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18054 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18055
18056 relocate_kernel_ptr = control_page;
18057 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18058 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18059 index 0327e2b..e43737b 100644
18060 --- a/arch/x86/kernel/microcode_intel.c
18061 +++ b/arch/x86/kernel/microcode_intel.c
18062 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18063
18064 static int get_ucode_user(void *to, const void *from, size_t n)
18065 {
18066 - return copy_from_user(to, from, n);
18067 + return copy_from_user(to, (const void __force_user *)from, n);
18068 }
18069
18070 static enum ucode_state
18071 request_microcode_user(int cpu, const void __user *buf, size_t size)
18072 {
18073 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18074 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18075 }
18076
18077 static void microcode_fini_cpu(int cpu)
18078 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18079 index f21fd94..61565cd 100644
18080 --- a/arch/x86/kernel/module.c
18081 +++ b/arch/x86/kernel/module.c
18082 @@ -35,15 +35,60 @@
18083 #define DEBUGP(fmt...)
18084 #endif
18085
18086 -void *module_alloc(unsigned long size)
18087 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18088 {
18089 - if (PAGE_ALIGN(size) > MODULES_LEN)
18090 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18091 return NULL;
18092 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18093 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18094 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18095 -1, __builtin_return_address(0));
18096 }
18097
18098 +void *module_alloc(unsigned long size)
18099 +{
18100 +
18101 +#ifdef CONFIG_PAX_KERNEXEC
18102 + return __module_alloc(size, PAGE_KERNEL);
18103 +#else
18104 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18105 +#endif
18106 +
18107 +}
18108 +
18109 +#ifdef CONFIG_PAX_KERNEXEC
18110 +#ifdef CONFIG_X86_32
18111 +void *module_alloc_exec(unsigned long size)
18112 +{
18113 + struct vm_struct *area;
18114 +
18115 + if (size == 0)
18116 + return NULL;
18117 +
18118 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18119 + return area ? area->addr : NULL;
18120 +}
18121 +EXPORT_SYMBOL(module_alloc_exec);
18122 +
18123 +void module_free_exec(struct module *mod, void *module_region)
18124 +{
18125 + vunmap(module_region);
18126 +}
18127 +EXPORT_SYMBOL(module_free_exec);
18128 +#else
18129 +void module_free_exec(struct module *mod, void *module_region)
18130 +{
18131 + module_free(mod, module_region);
18132 +}
18133 +EXPORT_SYMBOL(module_free_exec);
18134 +
18135 +void *module_alloc_exec(unsigned long size)
18136 +{
18137 + return __module_alloc(size, PAGE_KERNEL_RX);
18138 +}
18139 +EXPORT_SYMBOL(module_alloc_exec);
18140 +#endif
18141 +#endif
18142 +
18143 #ifdef CONFIG_X86_32
18144 int apply_relocate(Elf32_Shdr *sechdrs,
18145 const char *strtab,
18146 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18147 unsigned int i;
18148 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18149 Elf32_Sym *sym;
18150 - uint32_t *location;
18151 + uint32_t *plocation, location;
18152
18153 DEBUGP("Applying relocate section %u to %u\n", relsec,
18154 sechdrs[relsec].sh_info);
18155 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18156 /* This is where to make the change */
18157 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18158 - + rel[i].r_offset;
18159 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18160 + location = (uint32_t)plocation;
18161 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18162 + plocation = ktla_ktva((void *)plocation);
18163 /* This is the symbol it is referring to. Note that all
18164 undefined symbols have been resolved. */
18165 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18166 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18167 switch (ELF32_R_TYPE(rel[i].r_info)) {
18168 case R_386_32:
18169 /* We add the value into the location given */
18170 - *location += sym->st_value;
18171 + pax_open_kernel();
18172 + *plocation += sym->st_value;
18173 + pax_close_kernel();
18174 break;
18175 case R_386_PC32:
18176 /* Add the value, subtract its postition */
18177 - *location += sym->st_value - (uint32_t)location;
18178 + pax_open_kernel();
18179 + *plocation += sym->st_value - location;
18180 + pax_close_kernel();
18181 break;
18182 default:
18183 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18184 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18185 case R_X86_64_NONE:
18186 break;
18187 case R_X86_64_64:
18188 + pax_open_kernel();
18189 *(u64 *)loc = val;
18190 + pax_close_kernel();
18191 break;
18192 case R_X86_64_32:
18193 + pax_open_kernel();
18194 *(u32 *)loc = val;
18195 + pax_close_kernel();
18196 if (val != *(u32 *)loc)
18197 goto overflow;
18198 break;
18199 case R_X86_64_32S:
18200 + pax_open_kernel();
18201 *(s32 *)loc = val;
18202 + pax_close_kernel();
18203 if ((s64)val != *(s32 *)loc)
18204 goto overflow;
18205 break;
18206 case R_X86_64_PC32:
18207 val -= (u64)loc;
18208 + pax_open_kernel();
18209 *(u32 *)loc = val;
18210 + pax_close_kernel();
18211 +
18212 #if 0
18213 if ((s64)val != *(s32 *)loc)
18214 goto overflow;
18215 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18216 index a0b2f84..875ab81 100644
18217 --- a/arch/x86/kernel/nmi.c
18218 +++ b/arch/x86/kernel/nmi.c
18219 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18220 dotraplinkage notrace __kprobes void
18221 do_nmi(struct pt_regs *regs, long error_code)
18222 {
18223 +
18224 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18225 + if (!user_mode(regs)) {
18226 + unsigned long cs = regs->cs & 0xFFFF;
18227 + unsigned long ip = ktva_ktla(regs->ip);
18228 +
18229 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18230 + regs->ip = ip;
18231 + }
18232 +#endif
18233 +
18234 nmi_nesting_preprocess(regs);
18235
18236 nmi_enter();
18237 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18238 index 676b8c7..870ba04 100644
18239 --- a/arch/x86/kernel/paravirt-spinlocks.c
18240 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18241 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18242 arch_spin_lock(lock);
18243 }
18244
18245 -struct pv_lock_ops pv_lock_ops = {
18246 +struct pv_lock_ops pv_lock_ops __read_only = {
18247 #ifdef CONFIG_SMP
18248 .spin_is_locked = __ticket_spin_is_locked,
18249 .spin_is_contended = __ticket_spin_is_contended,
18250 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18251 index 9ce8859..b49bf51 100644
18252 --- a/arch/x86/kernel/paravirt.c
18253 +++ b/arch/x86/kernel/paravirt.c
18254 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18255 {
18256 return x;
18257 }
18258 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18259 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18260 +#endif
18261
18262 void __init default_banner(void)
18263 {
18264 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18265 if (opfunc == NULL)
18266 /* If there's no function, patch it with a ud2a (BUG) */
18267 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18268 - else if (opfunc == _paravirt_nop)
18269 + else if (opfunc == (void *)_paravirt_nop)
18270 /* If the operation is a nop, then nop the callsite */
18271 ret = paravirt_patch_nop();
18272
18273 /* identity functions just return their single argument */
18274 - else if (opfunc == _paravirt_ident_32)
18275 + else if (opfunc == (void *)_paravirt_ident_32)
18276 ret = paravirt_patch_ident_32(insnbuf, len);
18277 - else if (opfunc == _paravirt_ident_64)
18278 + else if (opfunc == (void *)_paravirt_ident_64)
18279 ret = paravirt_patch_ident_64(insnbuf, len);
18280 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18281 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18282 + ret = paravirt_patch_ident_64(insnbuf, len);
18283 +#endif
18284
18285 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18286 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18287 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18288 if (insn_len > len || start == NULL)
18289 insn_len = len;
18290 else
18291 - memcpy(insnbuf, start, insn_len);
18292 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18293
18294 return insn_len;
18295 }
18296 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18297 preempt_enable();
18298 }
18299
18300 -struct pv_info pv_info = {
18301 +struct pv_info pv_info __read_only = {
18302 .name = "bare hardware",
18303 .paravirt_enabled = 0,
18304 .kernel_rpl = 0,
18305 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18306 #endif
18307 };
18308
18309 -struct pv_init_ops pv_init_ops = {
18310 +struct pv_init_ops pv_init_ops __read_only = {
18311 .patch = native_patch,
18312 };
18313
18314 -struct pv_time_ops pv_time_ops = {
18315 +struct pv_time_ops pv_time_ops __read_only = {
18316 .sched_clock = native_sched_clock,
18317 .steal_clock = native_steal_clock,
18318 };
18319
18320 -struct pv_irq_ops pv_irq_ops = {
18321 +struct pv_irq_ops pv_irq_ops __read_only = {
18322 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18323 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18324 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18325 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18326 #endif
18327 };
18328
18329 -struct pv_cpu_ops pv_cpu_ops = {
18330 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18331 .cpuid = native_cpuid,
18332 .get_debugreg = native_get_debugreg,
18333 .set_debugreg = native_set_debugreg,
18334 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18335 .end_context_switch = paravirt_nop,
18336 };
18337
18338 -struct pv_apic_ops pv_apic_ops = {
18339 +struct pv_apic_ops pv_apic_ops __read_only = {
18340 #ifdef CONFIG_X86_LOCAL_APIC
18341 .startup_ipi_hook = paravirt_nop,
18342 #endif
18343 };
18344
18345 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18346 +#ifdef CONFIG_X86_32
18347 +#ifdef CONFIG_X86_PAE
18348 +/* 64-bit pagetable entries */
18349 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18350 +#else
18351 /* 32-bit pagetable entries */
18352 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18353 +#endif
18354 #else
18355 /* 64-bit pagetable entries */
18356 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18357 #endif
18358
18359 -struct pv_mmu_ops pv_mmu_ops = {
18360 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18361
18362 .read_cr2 = native_read_cr2,
18363 .write_cr2 = native_write_cr2,
18364 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18365 .make_pud = PTE_IDENT,
18366
18367 .set_pgd = native_set_pgd,
18368 + .set_pgd_batched = native_set_pgd_batched,
18369 #endif
18370 #endif /* PAGETABLE_LEVELS >= 3 */
18371
18372 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18373 },
18374
18375 .set_fixmap = native_set_fixmap,
18376 +
18377 +#ifdef CONFIG_PAX_KERNEXEC
18378 + .pax_open_kernel = native_pax_open_kernel,
18379 + .pax_close_kernel = native_pax_close_kernel,
18380 +#endif
18381 +
18382 };
18383
18384 EXPORT_SYMBOL_GPL(pv_time_ops);
18385 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18386 index 35ccf75..7a15747 100644
18387 --- a/arch/x86/kernel/pci-iommu_table.c
18388 +++ b/arch/x86/kernel/pci-iommu_table.c
18389 @@ -2,7 +2,7 @@
18390 #include <asm/iommu_table.h>
18391 #include <linux/string.h>
18392 #include <linux/kallsyms.h>
18393 -
18394 +#include <linux/sched.h>
18395
18396 #define DEBUG 1
18397
18398 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18399 index 735279e..5008677 100644
18400 --- a/arch/x86/kernel/process.c
18401 +++ b/arch/x86/kernel/process.c
18402 @@ -34,7 +34,8 @@
18403 * section. Since TSS's are completely CPU-local, we want them
18404 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18405 */
18406 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18407 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18408 +EXPORT_SYMBOL(init_tss);
18409
18410 #ifdef CONFIG_X86_64
18411 static DEFINE_PER_CPU(unsigned char, is_idle);
18412 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18413 task_xstate_cachep =
18414 kmem_cache_create("task_xstate", xstate_size,
18415 __alignof__(union thread_xstate),
18416 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18417 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18418 }
18419
18420 static inline void drop_fpu(struct task_struct *tsk)
18421 @@ -115,7 +116,7 @@ void exit_thread(void)
18422 unsigned long *bp = t->io_bitmap_ptr;
18423
18424 if (bp) {
18425 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18426 + struct tss_struct *tss = init_tss + get_cpu();
18427
18428 t->io_bitmap_ptr = NULL;
18429 clear_thread_flag(TIF_IO_BITMAP);
18430 @@ -147,7 +148,7 @@ void show_regs_common(void)
18431
18432 printk(KERN_CONT "\n");
18433 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18434 - current->pid, current->comm, print_tainted(),
18435 + task_pid_nr(current), current->comm, print_tainted(),
18436 init_utsname()->release,
18437 (int)strcspn(init_utsname()->version, " "),
18438 init_utsname()->version);
18439 @@ -161,6 +162,9 @@ void flush_thread(void)
18440 {
18441 struct task_struct *tsk = current;
18442
18443 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18444 + loadsegment(gs, 0);
18445 +#endif
18446 flush_ptrace_hw_breakpoint(tsk);
18447 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18448 drop_fpu(tsk);
18449 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18450 regs.di = (unsigned long) arg;
18451
18452 #ifdef CONFIG_X86_32
18453 - regs.ds = __USER_DS;
18454 - regs.es = __USER_DS;
18455 + regs.ds = __KERNEL_DS;
18456 + regs.es = __KERNEL_DS;
18457 regs.fs = __KERNEL_PERCPU;
18458 - regs.gs = __KERNEL_STACK_CANARY;
18459 + savesegment(gs, regs.gs);
18460 #else
18461 regs.ss = __KERNEL_DS;
18462 #endif
18463 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18464 void exit_idle(void)
18465 {
18466 /* idle loop has pid 0 */
18467 - if (current->pid)
18468 + if (task_pid_nr(current))
18469 return;
18470 __exit_idle();
18471 }
18472 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18473
18474 return ret;
18475 }
18476 -void stop_this_cpu(void *dummy)
18477 +__noreturn void stop_this_cpu(void *dummy)
18478 {
18479 local_irq_disable();
18480 /*
18481 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18482 }
18483 early_param("idle", idle_setup);
18484
18485 -unsigned long arch_align_stack(unsigned long sp)
18486 +#ifdef CONFIG_PAX_RANDKSTACK
18487 +void pax_randomize_kstack(struct pt_regs *regs)
18488 {
18489 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18490 - sp -= get_random_int() % 8192;
18491 - return sp & ~0xf;
18492 -}
18493 + struct thread_struct *thread = &current->thread;
18494 + unsigned long time;
18495
18496 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18497 -{
18498 - unsigned long range_end = mm->brk + 0x02000000;
18499 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18500 -}
18501 + if (!randomize_va_space)
18502 + return;
18503 +
18504 + if (v8086_mode(regs))
18505 + return;
18506
18507 + rdtscl(time);
18508 +
18509 + /* P4 seems to return a 0 LSB, ignore it */
18510 +#ifdef CONFIG_MPENTIUM4
18511 + time &= 0x3EUL;
18512 + time <<= 2;
18513 +#elif defined(CONFIG_X86_64)
18514 + time &= 0xFUL;
18515 + time <<= 4;
18516 +#else
18517 + time &= 0x1FUL;
18518 + time <<= 3;
18519 +#endif
18520 +
18521 + thread->sp0 ^= time;
18522 + load_sp0(init_tss + smp_processor_id(), thread);
18523 +
18524 +#ifdef CONFIG_X86_64
18525 + this_cpu_write(kernel_stack, thread->sp0);
18526 +#endif
18527 +}
18528 +#endif
18529 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18530 index 516fa18..80bd9e6 100644
18531 --- a/arch/x86/kernel/process_32.c
18532 +++ b/arch/x86/kernel/process_32.c
18533 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18534 unsigned long thread_saved_pc(struct task_struct *tsk)
18535 {
18536 return ((unsigned long *)tsk->thread.sp)[3];
18537 +//XXX return tsk->thread.eip;
18538 }
18539
18540 void __show_regs(struct pt_regs *regs, int all)
18541 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18542 unsigned long sp;
18543 unsigned short ss, gs;
18544
18545 - if (user_mode_vm(regs)) {
18546 + if (user_mode(regs)) {
18547 sp = regs->sp;
18548 ss = regs->ss & 0xffff;
18549 - gs = get_user_gs(regs);
18550 } else {
18551 sp = kernel_stack_pointer(regs);
18552 savesegment(ss, ss);
18553 - savesegment(gs, gs);
18554 }
18555 + gs = get_user_gs(regs);
18556
18557 show_regs_common();
18558
18559 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18560 struct task_struct *tsk;
18561 int err;
18562
18563 - childregs = task_pt_regs(p);
18564 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18565 *childregs = *regs;
18566 childregs->ax = 0;
18567 childregs->sp = sp;
18568
18569 p->thread.sp = (unsigned long) childregs;
18570 p->thread.sp0 = (unsigned long) (childregs+1);
18571 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18572
18573 p->thread.ip = (unsigned long) ret_from_fork;
18574
18575 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18576 struct thread_struct *prev = &prev_p->thread,
18577 *next = &next_p->thread;
18578 int cpu = smp_processor_id();
18579 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18580 + struct tss_struct *tss = init_tss + cpu;
18581 fpu_switch_t fpu;
18582
18583 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18584 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18585 */
18586 lazy_save_gs(prev->gs);
18587
18588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18589 + __set_fs(task_thread_info(next_p)->addr_limit);
18590 +#endif
18591 +
18592 /*
18593 * Load the per-thread Thread-Local Storage descriptor.
18594 */
18595 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18596 */
18597 arch_end_context_switch(next_p);
18598
18599 + this_cpu_write(current_task, next_p);
18600 + this_cpu_write(current_tinfo, &next_p->tinfo);
18601 +
18602 /*
18603 * Restore %gs if needed (which is common)
18604 */
18605 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18606
18607 switch_fpu_finish(next_p, fpu);
18608
18609 - this_cpu_write(current_task, next_p);
18610 -
18611 return prev_p;
18612 }
18613
18614 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18615 } while (count++ < 16);
18616 return 0;
18617 }
18618 -
18619 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18620 index 61cdf7f..797f06a 100644
18621 --- a/arch/x86/kernel/process_64.c
18622 +++ b/arch/x86/kernel/process_64.c
18623 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18624 struct pt_regs *childregs;
18625 struct task_struct *me = current;
18626
18627 - childregs = ((struct pt_regs *)
18628 - (THREAD_SIZE + task_stack_page(p))) - 1;
18629 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18630 *childregs = *regs;
18631
18632 childregs->ax = 0;
18633 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18634 p->thread.sp = (unsigned long) childregs;
18635 p->thread.sp0 = (unsigned long) (childregs+1);
18636 p->thread.usersp = me->thread.usersp;
18637 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18638
18639 set_tsk_thread_flag(p, TIF_FORK);
18640
18641 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18642 struct thread_struct *prev = &prev_p->thread;
18643 struct thread_struct *next = &next_p->thread;
18644 int cpu = smp_processor_id();
18645 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18646 + struct tss_struct *tss = init_tss + cpu;
18647 unsigned fsindex, gsindex;
18648 fpu_switch_t fpu;
18649
18650 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18651 prev->usersp = this_cpu_read(old_rsp);
18652 this_cpu_write(old_rsp, next->usersp);
18653 this_cpu_write(current_task, next_p);
18654 + this_cpu_write(current_tinfo, &next_p->tinfo);
18655
18656 - this_cpu_write(kernel_stack,
18657 - (unsigned long)task_stack_page(next_p) +
18658 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18659 + this_cpu_write(kernel_stack, next->sp0);
18660
18661 /*
18662 * Now maybe reload the debug registers and handle I/O bitmaps
18663 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18664 if (!p || p == current || p->state == TASK_RUNNING)
18665 return 0;
18666 stack = (unsigned long)task_stack_page(p);
18667 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18668 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18669 return 0;
18670 fp = *(u64 *)(p->thread.sp);
18671 do {
18672 - if (fp < (unsigned long)stack ||
18673 - fp >= (unsigned long)stack+THREAD_SIZE)
18674 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18675 return 0;
18676 ip = *(u64 *)(fp+8);
18677 if (!in_sched_functions(ip))
18678 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18679 index c4c6a5c..905f440 100644
18680 --- a/arch/x86/kernel/ptrace.c
18681 +++ b/arch/x86/kernel/ptrace.c
18682 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18683 unsigned long addr, unsigned long data)
18684 {
18685 int ret;
18686 - unsigned long __user *datap = (unsigned long __user *)data;
18687 + unsigned long __user *datap = (__force unsigned long __user *)data;
18688
18689 switch (request) {
18690 /* read the word at location addr in the USER area. */
18691 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18692 if ((int) addr < 0)
18693 return -EIO;
18694 ret = do_get_thread_area(child, addr,
18695 - (struct user_desc __user *)data);
18696 + (__force struct user_desc __user *) data);
18697 break;
18698
18699 case PTRACE_SET_THREAD_AREA:
18700 if ((int) addr < 0)
18701 return -EIO;
18702 ret = do_set_thread_area(child, addr,
18703 - (struct user_desc __user *)data, 0);
18704 + (__force struct user_desc __user *) data, 0);
18705 break;
18706 #endif
18707
18708 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18709 memset(info, 0, sizeof(*info));
18710 info->si_signo = SIGTRAP;
18711 info->si_code = si_code;
18712 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18713 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18714 }
18715
18716 void user_single_step_siginfo(struct task_struct *tsk,
18717 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18718 # define IS_IA32 0
18719 #endif
18720
18721 +#ifdef CONFIG_GRKERNSEC_SETXID
18722 +extern void gr_delayed_cred_worker(void);
18723 +#endif
18724 +
18725 /*
18726 * We must return the syscall number to actually look up in the table.
18727 * This can be -1L to skip running any syscall at all.
18728 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18729 {
18730 long ret = 0;
18731
18732 +#ifdef CONFIG_GRKERNSEC_SETXID
18733 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18734 + gr_delayed_cred_worker();
18735 +#endif
18736 +
18737 /*
18738 * If we stepped into a sysenter/syscall insn, it trapped in
18739 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18740 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18741 {
18742 bool step;
18743
18744 +#ifdef CONFIG_GRKERNSEC_SETXID
18745 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18746 + gr_delayed_cred_worker();
18747 +#endif
18748 +
18749 audit_syscall_exit(regs);
18750
18751 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18752 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18753 index 42eb330..139955c 100644
18754 --- a/arch/x86/kernel/pvclock.c
18755 +++ b/arch/x86/kernel/pvclock.c
18756 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18757 return pv_tsc_khz;
18758 }
18759
18760 -static atomic64_t last_value = ATOMIC64_INIT(0);
18761 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18762
18763 void pvclock_resume(void)
18764 {
18765 - atomic64_set(&last_value, 0);
18766 + atomic64_set_unchecked(&last_value, 0);
18767 }
18768
18769 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18770 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18771 * updating at the same time, and one of them could be slightly behind,
18772 * making the assumption that last_value always go forward fail to hold.
18773 */
18774 - last = atomic64_read(&last_value);
18775 + last = atomic64_read_unchecked(&last_value);
18776 do {
18777 if (ret < last)
18778 return last;
18779 - last = atomic64_cmpxchg(&last_value, last, ret);
18780 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18781 } while (unlikely(last != ret));
18782
18783 return ret;
18784 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18785 index 5de92f1..2732385 100644
18786 --- a/arch/x86/kernel/reboot.c
18787 +++ b/arch/x86/kernel/reboot.c
18788 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18789 EXPORT_SYMBOL(pm_power_off);
18790
18791 static const struct desc_ptr no_idt = {};
18792 -static int reboot_mode;
18793 +static unsigned short reboot_mode;
18794 enum reboot_type reboot_type = BOOT_ACPI;
18795 int reboot_force;
18796
18797 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18798 return 0;
18799 }
18800
18801 -void machine_real_restart(unsigned int type)
18802 +__noreturn void machine_real_restart(unsigned int type)
18803 {
18804 - void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18805 + void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18806 real_mode_header->machine_real_restart_asm;
18807
18808 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18809 + struct desc_struct *gdt;
18810 +#endif
18811 +
18812 local_irq_disable();
18813
18814 /*
18815 @@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18816 * boot)". This seems like a fairly standard thing that gets set by
18817 * REBOOT.COM programs, and the previous reset routine did this
18818 * too. */
18819 - *((unsigned short *)0x472) = reboot_mode;
18820 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18821
18822 /* Jump to the identity-mapped low memory code */
18823 +
18824 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18825 + gdt = get_cpu_gdt_table(smp_processor_id());
18826 + pax_open_kernel();
18827 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18828 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18829 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18830 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18831 +#endif
18832 +#ifdef CONFIG_PAX_KERNEXEC
18833 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18834 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18835 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18836 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18837 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18838 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18839 +#endif
18840 + pax_close_kernel();
18841 +#endif
18842 +
18843 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18844 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18845 + unreachable();
18846 +#else
18847 restart_lowmem(type);
18848 +#endif
18849 +
18850 }
18851 #ifdef CONFIG_APM_MODULE
18852 EXPORT_SYMBOL(machine_real_restart);
18853 @@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18854 * try to force a triple fault and then cycle between hitting the keyboard
18855 * controller and doing that
18856 */
18857 -static void native_machine_emergency_restart(void)
18858 +__noreturn static void native_machine_emergency_restart(void)
18859 {
18860 int i;
18861 int attempt = 0;
18862 @@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18863 #endif
18864 }
18865
18866 -static void __machine_emergency_restart(int emergency)
18867 +static __noreturn void __machine_emergency_restart(int emergency)
18868 {
18869 reboot_emergency = emergency;
18870 machine_ops.emergency_restart();
18871 }
18872
18873 -static void native_machine_restart(char *__unused)
18874 +static __noreturn void native_machine_restart(char *__unused)
18875 {
18876 printk("machine restart\n");
18877
18878 @@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18879 __machine_emergency_restart(0);
18880 }
18881
18882 -static void native_machine_halt(void)
18883 +static __noreturn void native_machine_halt(void)
18884 {
18885 /* Stop other cpus and apics */
18886 machine_shutdown();
18887 @@ -695,7 +725,7 @@ static void native_machine_halt(void)
18888 stop_this_cpu(NULL);
18889 }
18890
18891 -static void native_machine_power_off(void)
18892 +__noreturn static void native_machine_power_off(void)
18893 {
18894 if (pm_power_off) {
18895 if (!reboot_force)
18896 @@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18897 }
18898 /* A fallback in case there is no PM info available */
18899 tboot_shutdown(TB_SHUTDOWN_HALT);
18900 + unreachable();
18901 }
18902
18903 struct machine_ops machine_ops = {
18904 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18905 index 7a6f3b3..bed145d7 100644
18906 --- a/arch/x86/kernel/relocate_kernel_64.S
18907 +++ b/arch/x86/kernel/relocate_kernel_64.S
18908 @@ -11,6 +11,7 @@
18909 #include <asm/kexec.h>
18910 #include <asm/processor-flags.h>
18911 #include <asm/pgtable_types.h>
18912 +#include <asm/alternative-asm.h>
18913
18914 /*
18915 * Must be relocatable PIC code callable as a C function
18916 @@ -160,13 +161,14 @@ identity_mapped:
18917 xorq %rbp, %rbp
18918 xorq %r8, %r8
18919 xorq %r9, %r9
18920 - xorq %r10, %r9
18921 + xorq %r10, %r10
18922 xorq %r11, %r11
18923 xorq %r12, %r12
18924 xorq %r13, %r13
18925 xorq %r14, %r14
18926 xorq %r15, %r15
18927
18928 + pax_force_retaddr 0, 1
18929 ret
18930
18931 1:
18932 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18933 index 16be6dc..4686132 100644
18934 --- a/arch/x86/kernel/setup.c
18935 +++ b/arch/x86/kernel/setup.c
18936 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18937
18938 switch (data->type) {
18939 case SETUP_E820_EXT:
18940 - parse_e820_ext(data);
18941 + parse_e820_ext((struct setup_data __force_kernel *)data);
18942 break;
18943 case SETUP_DTB:
18944 add_dtb(pa_data);
18945 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18946 * area (640->1Mb) as ram even though it is not.
18947 * take them out.
18948 */
18949 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18950 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18951 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18952 }
18953
18954 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18955
18956 if (!boot_params.hdr.root_flags)
18957 root_mountflags &= ~MS_RDONLY;
18958 - init_mm.start_code = (unsigned long) _text;
18959 - init_mm.end_code = (unsigned long) _etext;
18960 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18961 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18962 init_mm.end_data = (unsigned long) _edata;
18963 init_mm.brk = _brk_end;
18964
18965 - code_resource.start = virt_to_phys(_text);
18966 - code_resource.end = virt_to_phys(_etext)-1;
18967 - data_resource.start = virt_to_phys(_etext);
18968 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18969 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18970 + data_resource.start = virt_to_phys(_sdata);
18971 data_resource.end = virt_to_phys(_edata)-1;
18972 bss_resource.start = virt_to_phys(&__bss_start);
18973 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18974 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18975 index 5a98aa2..2f9288d 100644
18976 --- a/arch/x86/kernel/setup_percpu.c
18977 +++ b/arch/x86/kernel/setup_percpu.c
18978 @@ -21,19 +21,17 @@
18979 #include <asm/cpu.h>
18980 #include <asm/stackprotector.h>
18981
18982 -DEFINE_PER_CPU(int, cpu_number);
18983 +#ifdef CONFIG_SMP
18984 +DEFINE_PER_CPU(unsigned int, cpu_number);
18985 EXPORT_PER_CPU_SYMBOL(cpu_number);
18986 +#endif
18987
18988 -#ifdef CONFIG_X86_64
18989 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18990 -#else
18991 -#define BOOT_PERCPU_OFFSET 0
18992 -#endif
18993
18994 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18995 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18996
18997 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18998 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18999 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19000 };
19001 EXPORT_SYMBOL(__per_cpu_offset);
19002 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19003 {
19004 #ifdef CONFIG_X86_32
19005 struct desc_struct gdt;
19006 + unsigned long base = per_cpu_offset(cpu);
19007
19008 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19009 - 0x2 | DESCTYPE_S, 0x8);
19010 - gdt.s = 1;
19011 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19012 + 0x83 | DESCTYPE_S, 0xC);
19013 write_gdt_entry(get_cpu_gdt_table(cpu),
19014 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19015 #endif
19016 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19017 /* alrighty, percpu areas up and running */
19018 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19019 for_each_possible_cpu(cpu) {
19020 +#ifdef CONFIG_CC_STACKPROTECTOR
19021 +#ifdef CONFIG_X86_32
19022 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19023 +#endif
19024 +#endif
19025 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19026 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19027 per_cpu(cpu_number, cpu) = cpu;
19028 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19029 */
19030 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19031 #endif
19032 +#ifdef CONFIG_CC_STACKPROTECTOR
19033 +#ifdef CONFIG_X86_32
19034 + if (!cpu)
19035 + per_cpu(stack_canary.canary, cpu) = canary;
19036 +#endif
19037 +#endif
19038 /*
19039 * Up to this point, the boot CPU has been using .init.data
19040 * area. Reload any changed state for the boot CPU.
19041 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19042 index 21af737..fb45e22 100644
19043 --- a/arch/x86/kernel/signal.c
19044 +++ b/arch/x86/kernel/signal.c
19045 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19046 * Align the stack pointer according to the i386 ABI,
19047 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19048 */
19049 - sp = ((sp + 4) & -16ul) - 4;
19050 + sp = ((sp - 12) & -16ul) - 4;
19051 #else /* !CONFIG_X86_32 */
19052 sp = round_down(sp, 16) - 8;
19053 #endif
19054 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19055 * Return an always-bogus address instead so we will die with SIGSEGV.
19056 */
19057 if (onsigstack && !likely(on_sig_stack(sp)))
19058 - return (void __user *)-1L;
19059 + return (__force void __user *)-1L;
19060
19061 /* save i387 state */
19062 if (used_math() && save_i387_xstate(*fpstate) < 0)
19063 - return (void __user *)-1L;
19064 + return (__force void __user *)-1L;
19065
19066 return (void __user *)sp;
19067 }
19068 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19069 }
19070
19071 if (current->mm->context.vdso)
19072 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19073 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19074 else
19075 - restorer = &frame->retcode;
19076 + restorer = (void __user *)&frame->retcode;
19077 if (ka->sa.sa_flags & SA_RESTORER)
19078 restorer = ka->sa.sa_restorer;
19079
19080 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19081 * reasons and because gdb uses it as a signature to notice
19082 * signal handler stack frames.
19083 */
19084 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19085 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19086
19087 if (err)
19088 return -EFAULT;
19089 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19090 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19091
19092 /* Set up to return from userspace. */
19093 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19094 + if (current->mm->context.vdso)
19095 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19096 + else
19097 + restorer = (void __user *)&frame->retcode;
19098 if (ka->sa.sa_flags & SA_RESTORER)
19099 restorer = ka->sa.sa_restorer;
19100 put_user_ex(restorer, &frame->pretcode);
19101 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19102 * reasons and because gdb uses it as a signature to notice
19103 * signal handler stack frames.
19104 */
19105 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19106 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19107 } put_user_catch(err);
19108
19109 if (err)
19110 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19111 index 7bd8a08..2659b5b 100644
19112 --- a/arch/x86/kernel/smpboot.c
19113 +++ b/arch/x86/kernel/smpboot.c
19114 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19115 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19116 (THREAD_SIZE + task_stack_page(idle))) - 1);
19117 per_cpu(current_task, cpu) = idle;
19118 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19119
19120 #ifdef CONFIG_X86_32
19121 /* Stack for startup_32 can be just as for start_secondary onwards */
19122 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19123 #else
19124 clear_tsk_thread_flag(idle, TIF_FORK);
19125 initial_gs = per_cpu_offset(cpu);
19126 - per_cpu(kernel_stack, cpu) =
19127 - (unsigned long)task_stack_page(idle) -
19128 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19129 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19130 #endif
19131 +
19132 + pax_open_kernel();
19133 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19134 + pax_close_kernel();
19135 +
19136 initial_code = (unsigned long)start_secondary;
19137 stack_start = idle->thread.sp;
19138
19139 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19140
19141 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19142
19143 +#ifdef CONFIG_PAX_PER_CPU_PGD
19144 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19145 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19146 + KERNEL_PGD_PTRS);
19147 +#endif
19148 +
19149 err = do_boot_cpu(apicid, cpu, tidle);
19150 if (err) {
19151 pr_debug("do_boot_cpu failed %d\n", err);
19152 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19153 index c346d11..d43b163 100644
19154 --- a/arch/x86/kernel/step.c
19155 +++ b/arch/x86/kernel/step.c
19156 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19157 struct desc_struct *desc;
19158 unsigned long base;
19159
19160 - seg &= ~7UL;
19161 + seg >>= 3;
19162
19163 mutex_lock(&child->mm->context.lock);
19164 - if (unlikely((seg >> 3) >= child->mm->context.size))
19165 + if (unlikely(seg >= child->mm->context.size))
19166 addr = -1L; /* bogus selector, access would fault */
19167 else {
19168 desc = child->mm->context.ldt + seg;
19169 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19170 addr += base;
19171 }
19172 mutex_unlock(&child->mm->context.lock);
19173 - }
19174 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19175 + addr = ktla_ktva(addr);
19176
19177 return addr;
19178 }
19179 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19180 unsigned char opcode[15];
19181 unsigned long addr = convert_ip_to_linear(child, regs);
19182
19183 + if (addr == -EINVAL)
19184 + return 0;
19185 +
19186 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19187 for (i = 0; i < copied; i++) {
19188 switch (opcode[i]) {
19189 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19190 index 0b0cb5f..db6b9ed 100644
19191 --- a/arch/x86/kernel/sys_i386_32.c
19192 +++ b/arch/x86/kernel/sys_i386_32.c
19193 @@ -24,17 +24,224 @@
19194
19195 #include <asm/syscalls.h>
19196
19197 -/*
19198 - * Do a system call from kernel instead of calling sys_execve so we
19199 - * end up with proper pt_regs.
19200 - */
19201 -int kernel_execve(const char *filename,
19202 - const char *const argv[],
19203 - const char *const envp[])
19204 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19205 {
19206 - long __res;
19207 - asm volatile ("int $0x80"
19208 - : "=a" (__res)
19209 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19210 - return __res;
19211 + unsigned long pax_task_size = TASK_SIZE;
19212 +
19213 +#ifdef CONFIG_PAX_SEGMEXEC
19214 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19215 + pax_task_size = SEGMEXEC_TASK_SIZE;
19216 +#endif
19217 +
19218 + if (len > pax_task_size || addr > pax_task_size - len)
19219 + return -EINVAL;
19220 +
19221 + return 0;
19222 +}
19223 +
19224 +unsigned long
19225 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19226 + unsigned long len, unsigned long pgoff, unsigned long flags)
19227 +{
19228 + struct mm_struct *mm = current->mm;
19229 + struct vm_area_struct *vma;
19230 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19231 +
19232 +#ifdef CONFIG_PAX_SEGMEXEC
19233 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19234 + pax_task_size = SEGMEXEC_TASK_SIZE;
19235 +#endif
19236 +
19237 + pax_task_size -= PAGE_SIZE;
19238 +
19239 + if (len > pax_task_size)
19240 + return -ENOMEM;
19241 +
19242 + if (flags & MAP_FIXED)
19243 + return addr;
19244 +
19245 +#ifdef CONFIG_PAX_RANDMMAP
19246 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19247 +#endif
19248 +
19249 + if (addr) {
19250 + addr = PAGE_ALIGN(addr);
19251 + if (pax_task_size - len >= addr) {
19252 + vma = find_vma(mm, addr);
19253 + if (check_heap_stack_gap(vma, addr, len))
19254 + return addr;
19255 + }
19256 + }
19257 + if (len > mm->cached_hole_size) {
19258 + start_addr = addr = mm->free_area_cache;
19259 + } else {
19260 + start_addr = addr = mm->mmap_base;
19261 + mm->cached_hole_size = 0;
19262 + }
19263 +
19264 +#ifdef CONFIG_PAX_PAGEEXEC
19265 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19266 + start_addr = 0x00110000UL;
19267 +
19268 +#ifdef CONFIG_PAX_RANDMMAP
19269 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19270 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19271 +#endif
19272 +
19273 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19274 + start_addr = addr = mm->mmap_base;
19275 + else
19276 + addr = start_addr;
19277 + }
19278 +#endif
19279 +
19280 +full_search:
19281 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19282 + /* At this point: (!vma || addr < vma->vm_end). */
19283 + if (pax_task_size - len < addr) {
19284 + /*
19285 + * Start a new search - just in case we missed
19286 + * some holes.
19287 + */
19288 + if (start_addr != mm->mmap_base) {
19289 + start_addr = addr = mm->mmap_base;
19290 + mm->cached_hole_size = 0;
19291 + goto full_search;
19292 + }
19293 + return -ENOMEM;
19294 + }
19295 + if (check_heap_stack_gap(vma, addr, len))
19296 + break;
19297 + if (addr + mm->cached_hole_size < vma->vm_start)
19298 + mm->cached_hole_size = vma->vm_start - addr;
19299 + addr = vma->vm_end;
19300 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19301 + start_addr = addr = mm->mmap_base;
19302 + mm->cached_hole_size = 0;
19303 + goto full_search;
19304 + }
19305 + }
19306 +
19307 + /*
19308 + * Remember the place where we stopped the search:
19309 + */
19310 + mm->free_area_cache = addr + len;
19311 + return addr;
19312 +}
19313 +
19314 +unsigned long
19315 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19316 + const unsigned long len, const unsigned long pgoff,
19317 + const unsigned long flags)
19318 +{
19319 + struct vm_area_struct *vma;
19320 + struct mm_struct *mm = current->mm;
19321 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19322 +
19323 +#ifdef CONFIG_PAX_SEGMEXEC
19324 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19325 + pax_task_size = SEGMEXEC_TASK_SIZE;
19326 +#endif
19327 +
19328 + pax_task_size -= PAGE_SIZE;
19329 +
19330 + /* requested length too big for entire address space */
19331 + if (len > pax_task_size)
19332 + return -ENOMEM;
19333 +
19334 + if (flags & MAP_FIXED)
19335 + return addr;
19336 +
19337 +#ifdef CONFIG_PAX_PAGEEXEC
19338 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19339 + goto bottomup;
19340 +#endif
19341 +
19342 +#ifdef CONFIG_PAX_RANDMMAP
19343 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19344 +#endif
19345 +
19346 + /* requesting a specific address */
19347 + if (addr) {
19348 + addr = PAGE_ALIGN(addr);
19349 + if (pax_task_size - len >= addr) {
19350 + vma = find_vma(mm, addr);
19351 + if (check_heap_stack_gap(vma, addr, len))
19352 + return addr;
19353 + }
19354 + }
19355 +
19356 + /* check if free_area_cache is useful for us */
19357 + if (len <= mm->cached_hole_size) {
19358 + mm->cached_hole_size = 0;
19359 + mm->free_area_cache = mm->mmap_base;
19360 + }
19361 +
19362 + /* either no address requested or can't fit in requested address hole */
19363 + addr = mm->free_area_cache;
19364 +
19365 + /* make sure it can fit in the remaining address space */
19366 + if (addr > len) {
19367 + vma = find_vma(mm, addr-len);
19368 + if (check_heap_stack_gap(vma, addr - len, len))
19369 + /* remember the address as a hint for next time */
19370 + return (mm->free_area_cache = addr-len);
19371 + }
19372 +
19373 + if (mm->mmap_base < len)
19374 + goto bottomup;
19375 +
19376 + addr = mm->mmap_base-len;
19377 +
19378 + do {
19379 + /*
19380 + * Lookup failure means no vma is above this address,
19381 + * else if new region fits below vma->vm_start,
19382 + * return with success:
19383 + */
19384 + vma = find_vma(mm, addr);
19385 + if (check_heap_stack_gap(vma, addr, len))
19386 + /* remember the address as a hint for next time */
19387 + return (mm->free_area_cache = addr);
19388 +
19389 + /* remember the largest hole we saw so far */
19390 + if (addr + mm->cached_hole_size < vma->vm_start)
19391 + mm->cached_hole_size = vma->vm_start - addr;
19392 +
19393 + /* try just below the current vma->vm_start */
19394 + addr = skip_heap_stack_gap(vma, len);
19395 + } while (!IS_ERR_VALUE(addr));
19396 +
19397 +bottomup:
19398 + /*
19399 + * A failed mmap() very likely causes application failure,
19400 + * so fall back to the bottom-up function here. This scenario
19401 + * can happen with large stack limits and large mmap()
19402 + * allocations.
19403 + */
19404 +
19405 +#ifdef CONFIG_PAX_SEGMEXEC
19406 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19407 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19408 + else
19409 +#endif
19410 +
19411 + mm->mmap_base = TASK_UNMAPPED_BASE;
19412 +
19413 +#ifdef CONFIG_PAX_RANDMMAP
19414 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19415 + mm->mmap_base += mm->delta_mmap;
19416 +#endif
19417 +
19418 + mm->free_area_cache = mm->mmap_base;
19419 + mm->cached_hole_size = ~0UL;
19420 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19421 + /*
19422 + * Restore the topdown base:
19423 + */
19424 + mm->mmap_base = base;
19425 + mm->free_area_cache = base;
19426 + mm->cached_hole_size = ~0UL;
19427 +
19428 + return addr;
19429 }
19430 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19431 index b4d3c39..82bb73b 100644
19432 --- a/arch/x86/kernel/sys_x86_64.c
19433 +++ b/arch/x86/kernel/sys_x86_64.c
19434 @@ -95,8 +95,8 @@ out:
19435 return error;
19436 }
19437
19438 -static void find_start_end(unsigned long flags, unsigned long *begin,
19439 - unsigned long *end)
19440 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19441 + unsigned long *begin, unsigned long *end)
19442 {
19443 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19444 unsigned long new_begin;
19445 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19446 *begin = new_begin;
19447 }
19448 } else {
19449 - *begin = TASK_UNMAPPED_BASE;
19450 + *begin = mm->mmap_base;
19451 *end = TASK_SIZE;
19452 }
19453 }
19454 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19455 if (flags & MAP_FIXED)
19456 return addr;
19457
19458 - find_start_end(flags, &begin, &end);
19459 + find_start_end(mm, flags, &begin, &end);
19460
19461 if (len > end)
19462 return -ENOMEM;
19463
19464 +#ifdef CONFIG_PAX_RANDMMAP
19465 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19466 +#endif
19467 +
19468 if (addr) {
19469 addr = PAGE_ALIGN(addr);
19470 vma = find_vma(mm, addr);
19471 - if (end - len >= addr &&
19472 - (!vma || addr + len <= vma->vm_start))
19473 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19474 return addr;
19475 }
19476 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19477 @@ -172,7 +175,7 @@ full_search:
19478 }
19479 return -ENOMEM;
19480 }
19481 - if (!vma || addr + len <= vma->vm_start) {
19482 + if (check_heap_stack_gap(vma, addr, len)) {
19483 /*
19484 * Remember the place where we stopped the search:
19485 */
19486 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19487 {
19488 struct vm_area_struct *vma;
19489 struct mm_struct *mm = current->mm;
19490 - unsigned long addr = addr0, start_addr;
19491 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19492
19493 /* requested length too big for entire address space */
19494 if (len > TASK_SIZE)
19495 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19496 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19497 goto bottomup;
19498
19499 +#ifdef CONFIG_PAX_RANDMMAP
19500 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19501 +#endif
19502 +
19503 /* requesting a specific address */
19504 if (addr) {
19505 addr = PAGE_ALIGN(addr);
19506 - vma = find_vma(mm, addr);
19507 - if (TASK_SIZE - len >= addr &&
19508 - (!vma || addr + len <= vma->vm_start))
19509 - return addr;
19510 + if (TASK_SIZE - len >= addr) {
19511 + vma = find_vma(mm, addr);
19512 + if (check_heap_stack_gap(vma, addr, len))
19513 + return addr;
19514 + }
19515 }
19516
19517 /* check if free_area_cache is useful for us */
19518 @@ -240,7 +248,7 @@ try_again:
19519 * return with success:
19520 */
19521 vma = find_vma(mm, addr);
19522 - if (!vma || addr+len <= vma->vm_start)
19523 + if (check_heap_stack_gap(vma, addr, len))
19524 /* remember the address as a hint for next time */
19525 return mm->free_area_cache = addr;
19526
19527 @@ -249,8 +257,8 @@ try_again:
19528 mm->cached_hole_size = vma->vm_start - addr;
19529
19530 /* try just below the current vma->vm_start */
19531 - addr = vma->vm_start-len;
19532 - } while (len < vma->vm_start);
19533 + addr = skip_heap_stack_gap(vma, len);
19534 + } while (!IS_ERR_VALUE(addr));
19535
19536 fail:
19537 /*
19538 @@ -270,13 +278,21 @@ bottomup:
19539 * can happen with large stack limits and large mmap()
19540 * allocations.
19541 */
19542 + mm->mmap_base = TASK_UNMAPPED_BASE;
19543 +
19544 +#ifdef CONFIG_PAX_RANDMMAP
19545 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19546 + mm->mmap_base += mm->delta_mmap;
19547 +#endif
19548 +
19549 + mm->free_area_cache = mm->mmap_base;
19550 mm->cached_hole_size = ~0UL;
19551 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19552 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19553 /*
19554 * Restore the topdown base:
19555 */
19556 - mm->free_area_cache = mm->mmap_base;
19557 + mm->mmap_base = base;
19558 + mm->free_area_cache = base;
19559 mm->cached_hole_size = ~0UL;
19560
19561 return addr;
19562 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19563 index f84fe00..93fe08f 100644
19564 --- a/arch/x86/kernel/tboot.c
19565 +++ b/arch/x86/kernel/tboot.c
19566 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19567
19568 void tboot_shutdown(u32 shutdown_type)
19569 {
19570 - void (*shutdown)(void);
19571 + void (* __noreturn shutdown)(void);
19572
19573 if (!tboot_enabled())
19574 return;
19575 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19576
19577 switch_to_tboot_pt();
19578
19579 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19580 + shutdown = (void *)tboot->shutdown_entry;
19581 shutdown();
19582
19583 /* should not reach here */
19584 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19585 return 0;
19586 }
19587
19588 -static atomic_t ap_wfs_count;
19589 +static atomic_unchecked_t ap_wfs_count;
19590
19591 static int tboot_wait_for_aps(int num_aps)
19592 {
19593 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19594 {
19595 switch (action) {
19596 case CPU_DYING:
19597 - atomic_inc(&ap_wfs_count);
19598 + atomic_inc_unchecked(&ap_wfs_count);
19599 if (num_online_cpus() == 1)
19600 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19601 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19602 return NOTIFY_BAD;
19603 break;
19604 }
19605 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19606
19607 tboot_create_trampoline();
19608
19609 - atomic_set(&ap_wfs_count, 0);
19610 + atomic_set_unchecked(&ap_wfs_count, 0);
19611 register_hotcpu_notifier(&tboot_cpu_notifier);
19612
19613 acpi_os_set_prepare_sleep(&tboot_sleep);
19614 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19615 index 24d3c91..d06b473 100644
19616 --- a/arch/x86/kernel/time.c
19617 +++ b/arch/x86/kernel/time.c
19618 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19619 {
19620 unsigned long pc = instruction_pointer(regs);
19621
19622 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19623 + if (!user_mode(regs) && in_lock_functions(pc)) {
19624 #ifdef CONFIG_FRAME_POINTER
19625 - return *(unsigned long *)(regs->bp + sizeof(long));
19626 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19627 #else
19628 unsigned long *sp =
19629 (unsigned long *)kernel_stack_pointer(regs);
19630 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19631 * or above a saved flags. Eflags has bits 22-31 zero,
19632 * kernel addresses don't.
19633 */
19634 +
19635 +#ifdef CONFIG_PAX_KERNEXEC
19636 + return ktla_ktva(sp[0]);
19637 +#else
19638 if (sp[0] >> 22)
19639 return sp[0];
19640 if (sp[1] >> 22)
19641 return sp[1];
19642 #endif
19643 +
19644 +#endif
19645 }
19646 return pc;
19647 }
19648 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19649 index 9d9d2f9..ed344e4 100644
19650 --- a/arch/x86/kernel/tls.c
19651 +++ b/arch/x86/kernel/tls.c
19652 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19653 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19654 return -EINVAL;
19655
19656 +#ifdef CONFIG_PAX_SEGMEXEC
19657 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19658 + return -EINVAL;
19659 +#endif
19660 +
19661 set_tls_desc(p, idx, &info, 1);
19662
19663 return 0;
19664 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19665 index 05b31d9..501d3ba 100644
19666 --- a/arch/x86/kernel/traps.c
19667 +++ b/arch/x86/kernel/traps.c
19668 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19669
19670 /* Do we ignore FPU interrupts ? */
19671 char ignore_fpu_irq;
19672 -
19673 -/*
19674 - * The IDT has to be page-aligned to simplify the Pentium
19675 - * F0 0F bug workaround.
19676 - */
19677 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19678 #endif
19679
19680 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19681 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19682 }
19683
19684 static void __kprobes
19685 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19686 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19687 long error_code, siginfo_t *info)
19688 {
19689 struct task_struct *tsk = current;
19690
19691 #ifdef CONFIG_X86_32
19692 - if (regs->flags & X86_VM_MASK) {
19693 + if (v8086_mode(regs)) {
19694 /*
19695 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19696 * On nmi (interrupt 2), do_trap should not be called.
19697 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19698 }
19699 #endif
19700
19701 - if (!user_mode(regs))
19702 + if (!user_mode_novm(regs))
19703 goto kernel_trap;
19704
19705 #ifdef CONFIG_X86_32
19706 @@ -145,7 +139,7 @@ trap_signal:
19707 printk_ratelimit()) {
19708 printk(KERN_INFO
19709 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19710 - tsk->comm, tsk->pid, str,
19711 + tsk->comm, task_pid_nr(tsk), str,
19712 regs->ip, regs->sp, error_code);
19713 print_vma_addr(" in ", regs->ip);
19714 printk("\n");
19715 @@ -162,8 +156,20 @@ kernel_trap:
19716 if (!fixup_exception(regs)) {
19717 tsk->thread.error_code = error_code;
19718 tsk->thread.trap_nr = trapnr;
19719 +
19720 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19721 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19722 + str = "PAX: suspicious stack segment fault";
19723 +#endif
19724 +
19725 die(str, regs, error_code);
19726 }
19727 +
19728 +#ifdef CONFIG_PAX_REFCOUNT
19729 + if (trapnr == 4)
19730 + pax_report_refcount_overflow(regs);
19731 +#endif
19732 +
19733 return;
19734
19735 #ifdef CONFIG_X86_32
19736 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19737 conditional_sti(regs);
19738
19739 #ifdef CONFIG_X86_32
19740 - if (regs->flags & X86_VM_MASK)
19741 + if (v8086_mode(regs))
19742 goto gp_in_vm86;
19743 #endif
19744
19745 tsk = current;
19746 - if (!user_mode(regs))
19747 + if (!user_mode_novm(regs))
19748 goto gp_in_kernel;
19749
19750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19751 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19752 + struct mm_struct *mm = tsk->mm;
19753 + unsigned long limit;
19754 +
19755 + down_write(&mm->mmap_sem);
19756 + limit = mm->context.user_cs_limit;
19757 + if (limit < TASK_SIZE) {
19758 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19759 + up_write(&mm->mmap_sem);
19760 + return;
19761 + }
19762 + up_write(&mm->mmap_sem);
19763 + }
19764 +#endif
19765 +
19766 tsk->thread.error_code = error_code;
19767 tsk->thread.trap_nr = X86_TRAP_GP;
19768
19769 @@ -296,6 +318,13 @@ gp_in_kernel:
19770 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19771 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19772 return;
19773 +
19774 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19775 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19776 + die("PAX: suspicious general protection fault", regs, error_code);
19777 + else
19778 +#endif
19779 +
19780 die("general protection fault", regs, error_code);
19781 }
19782
19783 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19784 /* It's safe to allow irq's after DR6 has been saved */
19785 preempt_conditional_sti(regs);
19786
19787 - if (regs->flags & X86_VM_MASK) {
19788 + if (v8086_mode(regs)) {
19789 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19790 X86_TRAP_DB);
19791 preempt_conditional_cli(regs);
19792 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19793 * We already checked v86 mode above, so we can check for kernel mode
19794 * by just checking the CPL of CS.
19795 */
19796 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19797 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19798 tsk->thread.debugreg6 &= ~DR_STEP;
19799 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19800 regs->flags &= ~X86_EFLAGS_TF;
19801 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19802 return;
19803 conditional_sti(regs);
19804
19805 - if (!user_mode_vm(regs))
19806 + if (!user_mode(regs))
19807 {
19808 if (!fixup_exception(regs)) {
19809 task->thread.error_code = error_code;
19810 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19811 index dc4e910..c9dedab 100644
19812 --- a/arch/x86/kernel/uprobes.c
19813 +++ b/arch/x86/kernel/uprobes.c
19814 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19815 int ret = NOTIFY_DONE;
19816
19817 /* We are only interested in userspace traps */
19818 - if (regs && !user_mode_vm(regs))
19819 + if (regs && !user_mode(regs))
19820 return NOTIFY_DONE;
19821
19822 switch (val) {
19823 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19824 index b9242ba..50c5edd 100644
19825 --- a/arch/x86/kernel/verify_cpu.S
19826 +++ b/arch/x86/kernel/verify_cpu.S
19827 @@ -20,6 +20,7 @@
19828 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19829 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19830 * arch/x86/kernel/head_32.S: processor startup
19831 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19832 *
19833 * verify_cpu, returns the status of longmode and SSE in register %eax.
19834 * 0: Success 1: Failure
19835 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19836 index 255f58a..5e91150 100644
19837 --- a/arch/x86/kernel/vm86_32.c
19838 +++ b/arch/x86/kernel/vm86_32.c
19839 @@ -41,6 +41,7 @@
19840 #include <linux/ptrace.h>
19841 #include <linux/audit.h>
19842 #include <linux/stddef.h>
19843 +#include <linux/grsecurity.h>
19844
19845 #include <asm/uaccess.h>
19846 #include <asm/io.h>
19847 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19848 do_exit(SIGSEGV);
19849 }
19850
19851 - tss = &per_cpu(init_tss, get_cpu());
19852 + tss = init_tss + get_cpu();
19853 current->thread.sp0 = current->thread.saved_sp0;
19854 current->thread.sysenter_cs = __KERNEL_CS;
19855 load_sp0(tss, &current->thread);
19856 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19857 struct task_struct *tsk;
19858 int tmp, ret = -EPERM;
19859
19860 +#ifdef CONFIG_GRKERNSEC_VM86
19861 + if (!capable(CAP_SYS_RAWIO)) {
19862 + gr_handle_vm86();
19863 + goto out;
19864 + }
19865 +#endif
19866 +
19867 tsk = current;
19868 if (tsk->thread.saved_sp0)
19869 goto out;
19870 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19871 int tmp, ret;
19872 struct vm86plus_struct __user *v86;
19873
19874 +#ifdef CONFIG_GRKERNSEC_VM86
19875 + if (!capable(CAP_SYS_RAWIO)) {
19876 + gr_handle_vm86();
19877 + ret = -EPERM;
19878 + goto out;
19879 + }
19880 +#endif
19881 +
19882 tsk = current;
19883 switch (cmd) {
19884 case VM86_REQUEST_IRQ:
19885 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19886 tsk->thread.saved_fs = info->regs32->fs;
19887 tsk->thread.saved_gs = get_user_gs(info->regs32);
19888
19889 - tss = &per_cpu(init_tss, get_cpu());
19890 + tss = init_tss + get_cpu();
19891 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19892 if (cpu_has_sep)
19893 tsk->thread.sysenter_cs = 0;
19894 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19895 goto cannot_handle;
19896 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19897 goto cannot_handle;
19898 - intr_ptr = (unsigned long __user *) (i << 2);
19899 + intr_ptr = (__force unsigned long __user *) (i << 2);
19900 if (get_user(segoffs, intr_ptr))
19901 goto cannot_handle;
19902 if ((segoffs >> 16) == BIOSSEG)
19903 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19904 index 22a1530..8fbaaad 100644
19905 --- a/arch/x86/kernel/vmlinux.lds.S
19906 +++ b/arch/x86/kernel/vmlinux.lds.S
19907 @@ -26,6 +26,13 @@
19908 #include <asm/page_types.h>
19909 #include <asm/cache.h>
19910 #include <asm/boot.h>
19911 +#include <asm/segment.h>
19912 +
19913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19914 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19915 +#else
19916 +#define __KERNEL_TEXT_OFFSET 0
19917 +#endif
19918
19919 #undef i386 /* in case the preprocessor is a 32bit one */
19920
19921 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19922
19923 PHDRS {
19924 text PT_LOAD FLAGS(5); /* R_E */
19925 +#ifdef CONFIG_X86_32
19926 + module PT_LOAD FLAGS(5); /* R_E */
19927 +#endif
19928 +#ifdef CONFIG_XEN
19929 + rodata PT_LOAD FLAGS(5); /* R_E */
19930 +#else
19931 + rodata PT_LOAD FLAGS(4); /* R__ */
19932 +#endif
19933 data PT_LOAD FLAGS(6); /* RW_ */
19934 -#ifdef CONFIG_X86_64
19935 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19936 #ifdef CONFIG_SMP
19937 percpu PT_LOAD FLAGS(6); /* RW_ */
19938 #endif
19939 + text.init PT_LOAD FLAGS(5); /* R_E */
19940 + text.exit PT_LOAD FLAGS(5); /* R_E */
19941 init PT_LOAD FLAGS(7); /* RWE */
19942 -#endif
19943 note PT_NOTE FLAGS(0); /* ___ */
19944 }
19945
19946 SECTIONS
19947 {
19948 #ifdef CONFIG_X86_32
19949 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19950 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19951 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19952 #else
19953 - . = __START_KERNEL;
19954 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19955 + . = __START_KERNEL;
19956 #endif
19957
19958 /* Text and read-only data */
19959 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19960 - _text = .;
19961 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19962 /* bootstrapping code */
19963 +#ifdef CONFIG_X86_32
19964 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19965 +#else
19966 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19967 +#endif
19968 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19969 + _text = .;
19970 HEAD_TEXT
19971 #ifdef CONFIG_X86_32
19972 . = ALIGN(PAGE_SIZE);
19973 @@ -108,13 +128,48 @@ SECTIONS
19974 IRQENTRY_TEXT
19975 *(.fixup)
19976 *(.gnu.warning)
19977 - /* End of text section */
19978 - _etext = .;
19979 } :text = 0x9090
19980
19981 - NOTES :text :note
19982 + . += __KERNEL_TEXT_OFFSET;
19983
19984 - EXCEPTION_TABLE(16) :text = 0x9090
19985 +#ifdef CONFIG_X86_32
19986 + . = ALIGN(PAGE_SIZE);
19987 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19988 +
19989 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19990 + MODULES_EXEC_VADDR = .;
19991 + BYTE(0)
19992 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19993 + . = ALIGN(HPAGE_SIZE) - 1;
19994 + MODULES_EXEC_END = .;
19995 +#endif
19996 +
19997 + } :module
19998 +#endif
19999 +
20000 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20001 + /* End of text section */
20002 + BYTE(0)
20003 + _etext = . - __KERNEL_TEXT_OFFSET;
20004 + }
20005 +
20006 +#ifdef CONFIG_X86_32
20007 + . = ALIGN(PAGE_SIZE);
20008 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20009 + *(.idt)
20010 + . = ALIGN(PAGE_SIZE);
20011 + *(.empty_zero_page)
20012 + *(.initial_pg_fixmap)
20013 + *(.initial_pg_pmd)
20014 + *(.initial_page_table)
20015 + *(.swapper_pg_dir)
20016 + } :rodata
20017 +#endif
20018 +
20019 + . = ALIGN(PAGE_SIZE);
20020 + NOTES :rodata :note
20021 +
20022 + EXCEPTION_TABLE(16) :rodata
20023
20024 #if defined(CONFIG_DEBUG_RODATA)
20025 /* .text should occupy whole number of pages */
20026 @@ -126,16 +181,20 @@ SECTIONS
20027
20028 /* Data */
20029 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20030 +
20031 +#ifdef CONFIG_PAX_KERNEXEC
20032 + . = ALIGN(HPAGE_SIZE);
20033 +#else
20034 + . = ALIGN(PAGE_SIZE);
20035 +#endif
20036 +
20037 /* Start of data section */
20038 _sdata = .;
20039
20040 /* init_task */
20041 INIT_TASK_DATA(THREAD_SIZE)
20042
20043 -#ifdef CONFIG_X86_32
20044 - /* 32 bit has nosave before _edata */
20045 NOSAVE_DATA
20046 -#endif
20047
20048 PAGE_ALIGNED_DATA(PAGE_SIZE)
20049
20050 @@ -176,12 +235,19 @@ SECTIONS
20051 #endif /* CONFIG_X86_64 */
20052
20053 /* Init code and data - will be freed after init */
20054 - . = ALIGN(PAGE_SIZE);
20055 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20056 + BYTE(0)
20057 +
20058 +#ifdef CONFIG_PAX_KERNEXEC
20059 + . = ALIGN(HPAGE_SIZE);
20060 +#else
20061 + . = ALIGN(PAGE_SIZE);
20062 +#endif
20063 +
20064 __init_begin = .; /* paired with __init_end */
20065 - }
20066 + } :init.begin
20067
20068 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20069 +#ifdef CONFIG_SMP
20070 /*
20071 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20072 * output PHDR, so the next output section - .init.text - should
20073 @@ -190,12 +256,27 @@ SECTIONS
20074 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20075 #endif
20076
20077 - INIT_TEXT_SECTION(PAGE_SIZE)
20078 -#ifdef CONFIG_X86_64
20079 - :init
20080 -#endif
20081 + . = ALIGN(PAGE_SIZE);
20082 + init_begin = .;
20083 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20084 + VMLINUX_SYMBOL(_sinittext) = .;
20085 + INIT_TEXT
20086 + VMLINUX_SYMBOL(_einittext) = .;
20087 + . = ALIGN(PAGE_SIZE);
20088 + } :text.init
20089
20090 - INIT_DATA_SECTION(16)
20091 + /*
20092 + * .exit.text is discard at runtime, not link time, to deal with
20093 + * references from .altinstructions and .eh_frame
20094 + */
20095 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20096 + EXIT_TEXT
20097 + . = ALIGN(16);
20098 + } :text.exit
20099 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20100 +
20101 + . = ALIGN(PAGE_SIZE);
20102 + INIT_DATA_SECTION(16) :init
20103
20104 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20105 __x86_cpu_dev_start = .;
20106 @@ -257,19 +338,12 @@ SECTIONS
20107 }
20108
20109 . = ALIGN(8);
20110 - /*
20111 - * .exit.text is discard at runtime, not link time, to deal with
20112 - * references from .altinstructions and .eh_frame
20113 - */
20114 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20115 - EXIT_TEXT
20116 - }
20117
20118 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20119 EXIT_DATA
20120 }
20121
20122 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20123 +#ifndef CONFIG_SMP
20124 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20125 #endif
20126
20127 @@ -288,16 +362,10 @@ SECTIONS
20128 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20129 __smp_locks = .;
20130 *(.smp_locks)
20131 - . = ALIGN(PAGE_SIZE);
20132 __smp_locks_end = .;
20133 + . = ALIGN(PAGE_SIZE);
20134 }
20135
20136 -#ifdef CONFIG_X86_64
20137 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20138 - NOSAVE_DATA
20139 - }
20140 -#endif
20141 -
20142 /* BSS */
20143 . = ALIGN(PAGE_SIZE);
20144 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20145 @@ -313,6 +381,7 @@ SECTIONS
20146 __brk_base = .;
20147 . += 64 * 1024; /* 64k alignment slop space */
20148 *(.brk_reservation) /* areas brk users have reserved */
20149 + . = ALIGN(HPAGE_SIZE);
20150 __brk_limit = .;
20151 }
20152
20153 @@ -339,13 +408,12 @@ SECTIONS
20154 * for the boot processor.
20155 */
20156 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20157 -INIT_PER_CPU(gdt_page);
20158 INIT_PER_CPU(irq_stack_union);
20159
20160 /*
20161 * Build-time check on the image size:
20162 */
20163 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20164 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20165 "kernel image bigger than KERNEL_IMAGE_SIZE");
20166
20167 #ifdef CONFIG_SMP
20168 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20169 index 5db36ca..2938af9 100644
20170 --- a/arch/x86/kernel/vsyscall_64.c
20171 +++ b/arch/x86/kernel/vsyscall_64.c
20172 @@ -54,15 +54,13 @@
20173 DEFINE_VVAR(int, vgetcpu_mode);
20174 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20175
20176 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20177 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20178
20179 static int __init vsyscall_setup(char *str)
20180 {
20181 if (str) {
20182 if (!strcmp("emulate", str))
20183 vsyscall_mode = EMULATE;
20184 - else if (!strcmp("native", str))
20185 - vsyscall_mode = NATIVE;
20186 else if (!strcmp("none", str))
20187 vsyscall_mode = NONE;
20188 else
20189 @@ -309,8 +307,7 @@ done:
20190 return true;
20191
20192 sigsegv:
20193 - force_sig(SIGSEGV, current);
20194 - return true;
20195 + do_group_exit(SIGKILL);
20196 }
20197
20198 /*
20199 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20200 extern char __vvar_page;
20201 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20202
20203 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20204 - vsyscall_mode == NATIVE
20205 - ? PAGE_KERNEL_VSYSCALL
20206 - : PAGE_KERNEL_VVAR);
20207 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20208 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20209 (unsigned long)VSYSCALL_START);
20210
20211 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20212 index 9796c2f..f686fbf 100644
20213 --- a/arch/x86/kernel/x8664_ksyms_64.c
20214 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20215 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20216 EXPORT_SYMBOL(copy_user_generic_string);
20217 EXPORT_SYMBOL(copy_user_generic_unrolled);
20218 EXPORT_SYMBOL(__copy_user_nocache);
20219 -EXPORT_SYMBOL(_copy_from_user);
20220 -EXPORT_SYMBOL(_copy_to_user);
20221
20222 EXPORT_SYMBOL(copy_page);
20223 EXPORT_SYMBOL(clear_page);
20224 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20225 index bd18149..2ea0183 100644
20226 --- a/arch/x86/kernel/xsave.c
20227 +++ b/arch/x86/kernel/xsave.c
20228 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20229 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20230 return -EINVAL;
20231
20232 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20233 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20234 fx_sw_user->extended_size -
20235 FP_XSTATE_MAGIC2_SIZE));
20236 if (err)
20237 @@ -265,7 +265,7 @@ fx_only:
20238 * the other extended state.
20239 */
20240 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20241 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20242 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20243 }
20244
20245 /*
20246 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20247 if (use_xsave())
20248 err = restore_user_xstate(buf);
20249 else
20250 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20251 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20252 buf);
20253 if (unlikely(err)) {
20254 /*
20255 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20256 index 7df1c6d..9ea7c79 100644
20257 --- a/arch/x86/kvm/cpuid.c
20258 +++ b/arch/x86/kvm/cpuid.c
20259 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20260 struct kvm_cpuid2 *cpuid,
20261 struct kvm_cpuid_entry2 __user *entries)
20262 {
20263 - int r;
20264 + int r, i;
20265
20266 r = -E2BIG;
20267 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20268 goto out;
20269 r = -EFAULT;
20270 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20271 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20272 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20273 goto out;
20274 + for (i = 0; i < cpuid->nent; ++i) {
20275 + struct kvm_cpuid_entry2 cpuid_entry;
20276 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20277 + goto out;
20278 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20279 + }
20280 vcpu->arch.cpuid_nent = cpuid->nent;
20281 kvm_apic_set_version(vcpu);
20282 kvm_x86_ops->cpuid_update(vcpu);
20283 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20284 struct kvm_cpuid2 *cpuid,
20285 struct kvm_cpuid_entry2 __user *entries)
20286 {
20287 - int r;
20288 + int r, i;
20289
20290 r = -E2BIG;
20291 if (cpuid->nent < vcpu->arch.cpuid_nent)
20292 goto out;
20293 r = -EFAULT;
20294 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20295 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20296 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20297 goto out;
20298 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20299 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20300 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20301 + goto out;
20302 + }
20303 return 0;
20304
20305 out:
20306 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20307 index 4837375..2cc9722 100644
20308 --- a/arch/x86/kvm/emulate.c
20309 +++ b/arch/x86/kvm/emulate.c
20310 @@ -256,6 +256,7 @@ struct gprefix {
20311
20312 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20313 do { \
20314 + unsigned long _tmp; \
20315 __asm__ __volatile__ ( \
20316 _PRE_EFLAGS("0", "4", "2") \
20317 _op _suffix " %"_x"3,%1; " \
20318 @@ -270,8 +271,6 @@ struct gprefix {
20319 /* Raw emulation: instruction has two explicit operands. */
20320 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20321 do { \
20322 - unsigned long _tmp; \
20323 - \
20324 switch ((ctxt)->dst.bytes) { \
20325 case 2: \
20326 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20327 @@ -287,7 +286,6 @@ struct gprefix {
20328
20329 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20330 do { \
20331 - unsigned long _tmp; \
20332 switch ((ctxt)->dst.bytes) { \
20333 case 1: \
20334 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20335 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20336 index 93c1574..d6097dc 100644
20337 --- a/arch/x86/kvm/lapic.c
20338 +++ b/arch/x86/kvm/lapic.c
20339 @@ -54,7 +54,7 @@
20340 #define APIC_BUS_CYCLE_NS 1
20341
20342 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20343 -#define apic_debug(fmt, arg...)
20344 +#define apic_debug(fmt, arg...) do {} while (0)
20345
20346 #define APIC_LVT_NUM 6
20347 /* 14 is the version for Xeon and Pentium 8.4.8*/
20348 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20349 index 34f9709..8eca2d5 100644
20350 --- a/arch/x86/kvm/paging_tmpl.h
20351 +++ b/arch/x86/kvm/paging_tmpl.h
20352 @@ -197,7 +197,7 @@ retry_walk:
20353 if (unlikely(kvm_is_error_hva(host_addr)))
20354 goto error;
20355
20356 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20357 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20358 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20359 goto error;
20360
20361 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20362 index f75af40..285b18f 100644
20363 --- a/arch/x86/kvm/svm.c
20364 +++ b/arch/x86/kvm/svm.c
20365 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20366 int cpu = raw_smp_processor_id();
20367
20368 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20369 +
20370 + pax_open_kernel();
20371 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20372 + pax_close_kernel();
20373 +
20374 load_TR_desc();
20375 }
20376
20377 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20378 #endif
20379 #endif
20380
20381 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20382 + __set_fs(current_thread_info()->addr_limit);
20383 +#endif
20384 +
20385 reload_tss(vcpu);
20386
20387 local_irq_disable();
20388 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20389 index 86c8704..e8ee2ac 100644
20390 --- a/arch/x86/kvm/vmx.c
20391 +++ b/arch/x86/kvm/vmx.c
20392 @@ -1317,7 +1317,11 @@ static void reload_tss(void)
20393 struct desc_struct *descs;
20394
20395 descs = (void *)gdt->address;
20396 +
20397 + pax_open_kernel();
20398 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20399 + pax_close_kernel();
20400 +
20401 load_TR_desc();
20402 }
20403
20404 @@ -2650,8 +2654,11 @@ static __init int hardware_setup(void)
20405 if (!cpu_has_vmx_flexpriority())
20406 flexpriority_enabled = 0;
20407
20408 - if (!cpu_has_vmx_tpr_shadow())
20409 - kvm_x86_ops->update_cr8_intercept = NULL;
20410 + if (!cpu_has_vmx_tpr_shadow()) {
20411 + pax_open_kernel();
20412 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20413 + pax_close_kernel();
20414 + }
20415
20416 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20417 kvm_disable_largepages();
20418 @@ -3719,7 +3726,7 @@ static void vmx_set_constant_host_state(void)
20419 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20420
20421 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20422 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20423 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20424
20425 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20426 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20427 @@ -6257,6 +6264,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20428 "jmp .Lkvm_vmx_return \n\t"
20429 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20430 ".Lkvm_vmx_return: "
20431 +
20432 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20433 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20434 + ".Lkvm_vmx_return2: "
20435 +#endif
20436 +
20437 /* Save guest registers, load host registers, keep flags */
20438 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20439 "pop %0 \n\t"
20440 @@ -6305,6 +6318,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20441 #endif
20442 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20443 [wordsize]"i"(sizeof(ulong))
20444 +
20445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20446 + ,[cs]"i"(__KERNEL_CS)
20447 +#endif
20448 +
20449 : "cc", "memory"
20450 , R"ax", R"bx", R"di", R"si"
20451 #ifdef CONFIG_X86_64
20452 @@ -6312,7 +6330,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20453 #endif
20454 );
20455
20456 -#ifndef CONFIG_X86_64
20457 +#ifdef CONFIG_X86_32
20458 /*
20459 * The sysexit path does not restore ds/es, so we must set them to
20460 * a reasonable value ourselves.
20461 @@ -6321,8 +6339,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20462 * may be executed in interrupt context, which saves and restore segments
20463 * around it, nullifying its effect.
20464 */
20465 - loadsegment(ds, __USER_DS);
20466 - loadsegment(es, __USER_DS);
20467 + loadsegment(ds, __KERNEL_DS);
20468 + loadsegment(es, __KERNEL_DS);
20469 + loadsegment(ss, __KERNEL_DS);
20470 +
20471 +#ifdef CONFIG_PAX_KERNEXEC
20472 + loadsegment(fs, __KERNEL_PERCPU);
20473 +#endif
20474 +
20475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20476 + __set_fs(current_thread_info()->addr_limit);
20477 +#endif
20478 +
20479 #endif
20480
20481 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20482 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20483 index 14c290d..0dae6e5 100644
20484 --- a/arch/x86/kvm/x86.c
20485 +++ b/arch/x86/kvm/x86.c
20486 @@ -1361,8 +1361,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20487 {
20488 struct kvm *kvm = vcpu->kvm;
20489 int lm = is_long_mode(vcpu);
20490 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20491 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20492 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20493 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20494 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20495 : kvm->arch.xen_hvm_config.blob_size_32;
20496 u32 page_num = data & ~PAGE_MASK;
20497 @@ -2218,6 +2218,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20498 if (n < msr_list.nmsrs)
20499 goto out;
20500 r = -EFAULT;
20501 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20502 + goto out;
20503 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20504 num_msrs_to_save * sizeof(u32)))
20505 goto out;
20506 @@ -2343,7 +2345,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20507 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20508 struct kvm_interrupt *irq)
20509 {
20510 - if (irq->irq < 0 || irq->irq >= 256)
20511 + if (irq->irq >= 256)
20512 return -EINVAL;
20513 if (irqchip_in_kernel(vcpu->kvm))
20514 return -ENXIO;
20515 @@ -4880,7 +4882,7 @@ static void kvm_set_mmio_spte_mask(void)
20516 kvm_mmu_set_mmio_spte_mask(mask);
20517 }
20518
20519 -int kvm_arch_init(void *opaque)
20520 +int kvm_arch_init(const void *opaque)
20521 {
20522 int r;
20523 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20524 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20525 index 642d880..44e0f3f 100644
20526 --- a/arch/x86/lguest/boot.c
20527 +++ b/arch/x86/lguest/boot.c
20528 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20529 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20530 * Launcher to reboot us.
20531 */
20532 -static void lguest_restart(char *reason)
20533 +static __noreturn void lguest_restart(char *reason)
20534 {
20535 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20536 + BUG();
20537 }
20538
20539 /*G:050
20540 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20541 index 00933d5..3a64af9 100644
20542 --- a/arch/x86/lib/atomic64_386_32.S
20543 +++ b/arch/x86/lib/atomic64_386_32.S
20544 @@ -48,6 +48,10 @@ BEGIN(read)
20545 movl (v), %eax
20546 movl 4(v), %edx
20547 RET_ENDP
20548 +BEGIN(read_unchecked)
20549 + movl (v), %eax
20550 + movl 4(v), %edx
20551 +RET_ENDP
20552 #undef v
20553
20554 #define v %esi
20555 @@ -55,6 +59,10 @@ BEGIN(set)
20556 movl %ebx, (v)
20557 movl %ecx, 4(v)
20558 RET_ENDP
20559 +BEGIN(set_unchecked)
20560 + movl %ebx, (v)
20561 + movl %ecx, 4(v)
20562 +RET_ENDP
20563 #undef v
20564
20565 #define v %esi
20566 @@ -70,6 +78,20 @@ RET_ENDP
20567 BEGIN(add)
20568 addl %eax, (v)
20569 adcl %edx, 4(v)
20570 +
20571 +#ifdef CONFIG_PAX_REFCOUNT
20572 + jno 0f
20573 + subl %eax, (v)
20574 + sbbl %edx, 4(v)
20575 + int $4
20576 +0:
20577 + _ASM_EXTABLE(0b, 0b)
20578 +#endif
20579 +
20580 +RET_ENDP
20581 +BEGIN(add_unchecked)
20582 + addl %eax, (v)
20583 + adcl %edx, 4(v)
20584 RET_ENDP
20585 #undef v
20586
20587 @@ -77,6 +99,24 @@ RET_ENDP
20588 BEGIN(add_return)
20589 addl (v), %eax
20590 adcl 4(v), %edx
20591 +
20592 +#ifdef CONFIG_PAX_REFCOUNT
20593 + into
20594 +1234:
20595 + _ASM_EXTABLE(1234b, 2f)
20596 +#endif
20597 +
20598 + movl %eax, (v)
20599 + movl %edx, 4(v)
20600 +
20601 +#ifdef CONFIG_PAX_REFCOUNT
20602 +2:
20603 +#endif
20604 +
20605 +RET_ENDP
20606 +BEGIN(add_return_unchecked)
20607 + addl (v), %eax
20608 + adcl 4(v), %edx
20609 movl %eax, (v)
20610 movl %edx, 4(v)
20611 RET_ENDP
20612 @@ -86,6 +126,20 @@ RET_ENDP
20613 BEGIN(sub)
20614 subl %eax, (v)
20615 sbbl %edx, 4(v)
20616 +
20617 +#ifdef CONFIG_PAX_REFCOUNT
20618 + jno 0f
20619 + addl %eax, (v)
20620 + adcl %edx, 4(v)
20621 + int $4
20622 +0:
20623 + _ASM_EXTABLE(0b, 0b)
20624 +#endif
20625 +
20626 +RET_ENDP
20627 +BEGIN(sub_unchecked)
20628 + subl %eax, (v)
20629 + sbbl %edx, 4(v)
20630 RET_ENDP
20631 #undef v
20632
20633 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20634 sbbl $0, %edx
20635 addl (v), %eax
20636 adcl 4(v), %edx
20637 +
20638 +#ifdef CONFIG_PAX_REFCOUNT
20639 + into
20640 +1234:
20641 + _ASM_EXTABLE(1234b, 2f)
20642 +#endif
20643 +
20644 + movl %eax, (v)
20645 + movl %edx, 4(v)
20646 +
20647 +#ifdef CONFIG_PAX_REFCOUNT
20648 +2:
20649 +#endif
20650 +
20651 +RET_ENDP
20652 +BEGIN(sub_return_unchecked)
20653 + negl %edx
20654 + negl %eax
20655 + sbbl $0, %edx
20656 + addl (v), %eax
20657 + adcl 4(v), %edx
20658 movl %eax, (v)
20659 movl %edx, 4(v)
20660 RET_ENDP
20661 @@ -105,6 +180,20 @@ RET_ENDP
20662 BEGIN(inc)
20663 addl $1, (v)
20664 adcl $0, 4(v)
20665 +
20666 +#ifdef CONFIG_PAX_REFCOUNT
20667 + jno 0f
20668 + subl $1, (v)
20669 + sbbl $0, 4(v)
20670 + int $4
20671 +0:
20672 + _ASM_EXTABLE(0b, 0b)
20673 +#endif
20674 +
20675 +RET_ENDP
20676 +BEGIN(inc_unchecked)
20677 + addl $1, (v)
20678 + adcl $0, 4(v)
20679 RET_ENDP
20680 #undef v
20681
20682 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20683 movl 4(v), %edx
20684 addl $1, %eax
20685 adcl $0, %edx
20686 +
20687 +#ifdef CONFIG_PAX_REFCOUNT
20688 + into
20689 +1234:
20690 + _ASM_EXTABLE(1234b, 2f)
20691 +#endif
20692 +
20693 + movl %eax, (v)
20694 + movl %edx, 4(v)
20695 +
20696 +#ifdef CONFIG_PAX_REFCOUNT
20697 +2:
20698 +#endif
20699 +
20700 +RET_ENDP
20701 +BEGIN(inc_return_unchecked)
20702 + movl (v), %eax
20703 + movl 4(v), %edx
20704 + addl $1, %eax
20705 + adcl $0, %edx
20706 movl %eax, (v)
20707 movl %edx, 4(v)
20708 RET_ENDP
20709 @@ -123,6 +232,20 @@ RET_ENDP
20710 BEGIN(dec)
20711 subl $1, (v)
20712 sbbl $0, 4(v)
20713 +
20714 +#ifdef CONFIG_PAX_REFCOUNT
20715 + jno 0f
20716 + addl $1, (v)
20717 + adcl $0, 4(v)
20718 + int $4
20719 +0:
20720 + _ASM_EXTABLE(0b, 0b)
20721 +#endif
20722 +
20723 +RET_ENDP
20724 +BEGIN(dec_unchecked)
20725 + subl $1, (v)
20726 + sbbl $0, 4(v)
20727 RET_ENDP
20728 #undef v
20729
20730 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20731 movl 4(v), %edx
20732 subl $1, %eax
20733 sbbl $0, %edx
20734 +
20735 +#ifdef CONFIG_PAX_REFCOUNT
20736 + into
20737 +1234:
20738 + _ASM_EXTABLE(1234b, 2f)
20739 +#endif
20740 +
20741 + movl %eax, (v)
20742 + movl %edx, 4(v)
20743 +
20744 +#ifdef CONFIG_PAX_REFCOUNT
20745 +2:
20746 +#endif
20747 +
20748 +RET_ENDP
20749 +BEGIN(dec_return_unchecked)
20750 + movl (v), %eax
20751 + movl 4(v), %edx
20752 + subl $1, %eax
20753 + sbbl $0, %edx
20754 movl %eax, (v)
20755 movl %edx, 4(v)
20756 RET_ENDP
20757 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20758 adcl %edx, %edi
20759 addl (v), %eax
20760 adcl 4(v), %edx
20761 +
20762 +#ifdef CONFIG_PAX_REFCOUNT
20763 + into
20764 +1234:
20765 + _ASM_EXTABLE(1234b, 2f)
20766 +#endif
20767 +
20768 cmpl %eax, %ecx
20769 je 3f
20770 1:
20771 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20772 1:
20773 addl $1, %eax
20774 adcl $0, %edx
20775 +
20776 +#ifdef CONFIG_PAX_REFCOUNT
20777 + into
20778 +1234:
20779 + _ASM_EXTABLE(1234b, 2f)
20780 +#endif
20781 +
20782 movl %eax, (v)
20783 movl %edx, 4(v)
20784 movl $1, %eax
20785 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20786 movl 4(v), %edx
20787 subl $1, %eax
20788 sbbl $0, %edx
20789 +
20790 +#ifdef CONFIG_PAX_REFCOUNT
20791 + into
20792 +1234:
20793 + _ASM_EXTABLE(1234b, 1f)
20794 +#endif
20795 +
20796 js 1f
20797 movl %eax, (v)
20798 movl %edx, 4(v)
20799 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20800 index f5cc9eb..51fa319 100644
20801 --- a/arch/x86/lib/atomic64_cx8_32.S
20802 +++ b/arch/x86/lib/atomic64_cx8_32.S
20803 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20804 CFI_STARTPROC
20805
20806 read64 %ecx
20807 + pax_force_retaddr
20808 ret
20809 CFI_ENDPROC
20810 ENDPROC(atomic64_read_cx8)
20811
20812 +ENTRY(atomic64_read_unchecked_cx8)
20813 + CFI_STARTPROC
20814 +
20815 + read64 %ecx
20816 + pax_force_retaddr
20817 + ret
20818 + CFI_ENDPROC
20819 +ENDPROC(atomic64_read_unchecked_cx8)
20820 +
20821 ENTRY(atomic64_set_cx8)
20822 CFI_STARTPROC
20823
20824 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20825 cmpxchg8b (%esi)
20826 jne 1b
20827
20828 + pax_force_retaddr
20829 ret
20830 CFI_ENDPROC
20831 ENDPROC(atomic64_set_cx8)
20832
20833 +ENTRY(atomic64_set_unchecked_cx8)
20834 + CFI_STARTPROC
20835 +
20836 +1:
20837 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20838 + * are atomic on 586 and newer */
20839 + cmpxchg8b (%esi)
20840 + jne 1b
20841 +
20842 + pax_force_retaddr
20843 + ret
20844 + CFI_ENDPROC
20845 +ENDPROC(atomic64_set_unchecked_cx8)
20846 +
20847 ENTRY(atomic64_xchg_cx8)
20848 CFI_STARTPROC
20849
20850 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20851 cmpxchg8b (%esi)
20852 jne 1b
20853
20854 + pax_force_retaddr
20855 ret
20856 CFI_ENDPROC
20857 ENDPROC(atomic64_xchg_cx8)
20858
20859 -.macro addsub_return func ins insc
20860 -ENTRY(atomic64_\func\()_return_cx8)
20861 +.macro addsub_return func ins insc unchecked=""
20862 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20863 CFI_STARTPROC
20864 SAVE ebp
20865 SAVE ebx
20866 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20867 movl %edx, %ecx
20868 \ins\()l %esi, %ebx
20869 \insc\()l %edi, %ecx
20870 +
20871 +.ifb \unchecked
20872 +#ifdef CONFIG_PAX_REFCOUNT
20873 + into
20874 +2:
20875 + _ASM_EXTABLE(2b, 3f)
20876 +#endif
20877 +.endif
20878 +
20879 LOCK_PREFIX
20880 cmpxchg8b (%ebp)
20881 jne 1b
20882 -
20883 -10:
20884 movl %ebx, %eax
20885 movl %ecx, %edx
20886 +
20887 +.ifb \unchecked
20888 +#ifdef CONFIG_PAX_REFCOUNT
20889 +3:
20890 +#endif
20891 +.endif
20892 +
20893 RESTORE edi
20894 RESTORE esi
20895 RESTORE ebx
20896 RESTORE ebp
20897 + pax_force_retaddr
20898 ret
20899 CFI_ENDPROC
20900 -ENDPROC(atomic64_\func\()_return_cx8)
20901 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20902 .endm
20903
20904 addsub_return add add adc
20905 addsub_return sub sub sbb
20906 +addsub_return add add adc _unchecked
20907 +addsub_return sub sub sbb _unchecked
20908
20909 -.macro incdec_return func ins insc
20910 -ENTRY(atomic64_\func\()_return_cx8)
20911 +.macro incdec_return func ins insc unchecked=""
20912 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20913 CFI_STARTPROC
20914 SAVE ebx
20915
20916 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20917 movl %edx, %ecx
20918 \ins\()l $1, %ebx
20919 \insc\()l $0, %ecx
20920 +
20921 +.ifb \unchecked
20922 +#ifdef CONFIG_PAX_REFCOUNT
20923 + into
20924 +2:
20925 + _ASM_EXTABLE(2b, 3f)
20926 +#endif
20927 +.endif
20928 +
20929 LOCK_PREFIX
20930 cmpxchg8b (%esi)
20931 jne 1b
20932
20933 -10:
20934 movl %ebx, %eax
20935 movl %ecx, %edx
20936 +
20937 +.ifb \unchecked
20938 +#ifdef CONFIG_PAX_REFCOUNT
20939 +3:
20940 +#endif
20941 +.endif
20942 +
20943 RESTORE ebx
20944 + pax_force_retaddr
20945 ret
20946 CFI_ENDPROC
20947 -ENDPROC(atomic64_\func\()_return_cx8)
20948 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20949 .endm
20950
20951 incdec_return inc add adc
20952 incdec_return dec sub sbb
20953 +incdec_return inc add adc _unchecked
20954 +incdec_return dec sub sbb _unchecked
20955
20956 ENTRY(atomic64_dec_if_positive_cx8)
20957 CFI_STARTPROC
20958 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20959 movl %edx, %ecx
20960 subl $1, %ebx
20961 sbb $0, %ecx
20962 +
20963 +#ifdef CONFIG_PAX_REFCOUNT
20964 + into
20965 +1234:
20966 + _ASM_EXTABLE(1234b, 2f)
20967 +#endif
20968 +
20969 js 2f
20970 LOCK_PREFIX
20971 cmpxchg8b (%esi)
20972 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20973 movl %ebx, %eax
20974 movl %ecx, %edx
20975 RESTORE ebx
20976 + pax_force_retaddr
20977 ret
20978 CFI_ENDPROC
20979 ENDPROC(atomic64_dec_if_positive_cx8)
20980 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20981 movl %edx, %ecx
20982 addl %ebp, %ebx
20983 adcl %edi, %ecx
20984 +
20985 +#ifdef CONFIG_PAX_REFCOUNT
20986 + into
20987 +1234:
20988 + _ASM_EXTABLE(1234b, 3f)
20989 +#endif
20990 +
20991 LOCK_PREFIX
20992 cmpxchg8b (%esi)
20993 jne 1b
20994 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20995 CFI_ADJUST_CFA_OFFSET -8
20996 RESTORE ebx
20997 RESTORE ebp
20998 + pax_force_retaddr
20999 ret
21000 4:
21001 cmpl %edx, 4(%esp)
21002 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21003 xorl %ecx, %ecx
21004 addl $1, %ebx
21005 adcl %edx, %ecx
21006 +
21007 +#ifdef CONFIG_PAX_REFCOUNT
21008 + into
21009 +1234:
21010 + _ASM_EXTABLE(1234b, 3f)
21011 +#endif
21012 +
21013 LOCK_PREFIX
21014 cmpxchg8b (%esi)
21015 jne 1b
21016 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21017 movl $1, %eax
21018 3:
21019 RESTORE ebx
21020 + pax_force_retaddr
21021 ret
21022 CFI_ENDPROC
21023 ENDPROC(atomic64_inc_not_zero_cx8)
21024 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21025 index 2af5df3..62b1a5a 100644
21026 --- a/arch/x86/lib/checksum_32.S
21027 +++ b/arch/x86/lib/checksum_32.S
21028 @@ -29,7 +29,8 @@
21029 #include <asm/dwarf2.h>
21030 #include <asm/errno.h>
21031 #include <asm/asm.h>
21032 -
21033 +#include <asm/segment.h>
21034 +
21035 /*
21036 * computes a partial checksum, e.g. for TCP/UDP fragments
21037 */
21038 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21039
21040 #define ARGBASE 16
21041 #define FP 12
21042 -
21043 -ENTRY(csum_partial_copy_generic)
21044 +
21045 +ENTRY(csum_partial_copy_generic_to_user)
21046 CFI_STARTPROC
21047 +
21048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21049 + pushl_cfi %gs
21050 + popl_cfi %es
21051 + jmp csum_partial_copy_generic
21052 +#endif
21053 +
21054 +ENTRY(csum_partial_copy_generic_from_user)
21055 +
21056 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21057 + pushl_cfi %gs
21058 + popl_cfi %ds
21059 +#endif
21060 +
21061 +ENTRY(csum_partial_copy_generic)
21062 subl $4,%esp
21063 CFI_ADJUST_CFA_OFFSET 4
21064 pushl_cfi %edi
21065 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21066 jmp 4f
21067 SRC(1: movw (%esi), %bx )
21068 addl $2, %esi
21069 -DST( movw %bx, (%edi) )
21070 +DST( movw %bx, %es:(%edi) )
21071 addl $2, %edi
21072 addw %bx, %ax
21073 adcl $0, %eax
21074 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21075 SRC(1: movl (%esi), %ebx )
21076 SRC( movl 4(%esi), %edx )
21077 adcl %ebx, %eax
21078 -DST( movl %ebx, (%edi) )
21079 +DST( movl %ebx, %es:(%edi) )
21080 adcl %edx, %eax
21081 -DST( movl %edx, 4(%edi) )
21082 +DST( movl %edx, %es:4(%edi) )
21083
21084 SRC( movl 8(%esi), %ebx )
21085 SRC( movl 12(%esi), %edx )
21086 adcl %ebx, %eax
21087 -DST( movl %ebx, 8(%edi) )
21088 +DST( movl %ebx, %es:8(%edi) )
21089 adcl %edx, %eax
21090 -DST( movl %edx, 12(%edi) )
21091 +DST( movl %edx, %es:12(%edi) )
21092
21093 SRC( movl 16(%esi), %ebx )
21094 SRC( movl 20(%esi), %edx )
21095 adcl %ebx, %eax
21096 -DST( movl %ebx, 16(%edi) )
21097 +DST( movl %ebx, %es:16(%edi) )
21098 adcl %edx, %eax
21099 -DST( movl %edx, 20(%edi) )
21100 +DST( movl %edx, %es:20(%edi) )
21101
21102 SRC( movl 24(%esi), %ebx )
21103 SRC( movl 28(%esi), %edx )
21104 adcl %ebx, %eax
21105 -DST( movl %ebx, 24(%edi) )
21106 +DST( movl %ebx, %es:24(%edi) )
21107 adcl %edx, %eax
21108 -DST( movl %edx, 28(%edi) )
21109 +DST( movl %edx, %es:28(%edi) )
21110
21111 lea 32(%esi), %esi
21112 lea 32(%edi), %edi
21113 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21114 shrl $2, %edx # This clears CF
21115 SRC(3: movl (%esi), %ebx )
21116 adcl %ebx, %eax
21117 -DST( movl %ebx, (%edi) )
21118 +DST( movl %ebx, %es:(%edi) )
21119 lea 4(%esi), %esi
21120 lea 4(%edi), %edi
21121 dec %edx
21122 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21123 jb 5f
21124 SRC( movw (%esi), %cx )
21125 leal 2(%esi), %esi
21126 -DST( movw %cx, (%edi) )
21127 +DST( movw %cx, %es:(%edi) )
21128 leal 2(%edi), %edi
21129 je 6f
21130 shll $16,%ecx
21131 SRC(5: movb (%esi), %cl )
21132 -DST( movb %cl, (%edi) )
21133 +DST( movb %cl, %es:(%edi) )
21134 6: addl %ecx, %eax
21135 adcl $0, %eax
21136 7:
21137 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21138
21139 6001:
21140 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21141 - movl $-EFAULT, (%ebx)
21142 + movl $-EFAULT, %ss:(%ebx)
21143
21144 # zero the complete destination - computing the rest
21145 # is too much work
21146 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21147
21148 6002:
21149 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21150 - movl $-EFAULT,(%ebx)
21151 + movl $-EFAULT,%ss:(%ebx)
21152 jmp 5000b
21153
21154 .previous
21155
21156 + pushl_cfi %ss
21157 + popl_cfi %ds
21158 + pushl_cfi %ss
21159 + popl_cfi %es
21160 popl_cfi %ebx
21161 CFI_RESTORE ebx
21162 popl_cfi %esi
21163 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21164 popl_cfi %ecx # equivalent to addl $4,%esp
21165 ret
21166 CFI_ENDPROC
21167 -ENDPROC(csum_partial_copy_generic)
21168 +ENDPROC(csum_partial_copy_generic_to_user)
21169
21170 #else
21171
21172 /* Version for PentiumII/PPro */
21173
21174 #define ROUND1(x) \
21175 + nop; nop; nop; \
21176 SRC(movl x(%esi), %ebx ) ; \
21177 addl %ebx, %eax ; \
21178 - DST(movl %ebx, x(%edi) ) ;
21179 + DST(movl %ebx, %es:x(%edi)) ;
21180
21181 #define ROUND(x) \
21182 + nop; nop; nop; \
21183 SRC(movl x(%esi), %ebx ) ; \
21184 adcl %ebx, %eax ; \
21185 - DST(movl %ebx, x(%edi) ) ;
21186 + DST(movl %ebx, %es:x(%edi)) ;
21187
21188 #define ARGBASE 12
21189 -
21190 -ENTRY(csum_partial_copy_generic)
21191 +
21192 +ENTRY(csum_partial_copy_generic_to_user)
21193 CFI_STARTPROC
21194 +
21195 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21196 + pushl_cfi %gs
21197 + popl_cfi %es
21198 + jmp csum_partial_copy_generic
21199 +#endif
21200 +
21201 +ENTRY(csum_partial_copy_generic_from_user)
21202 +
21203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21204 + pushl_cfi %gs
21205 + popl_cfi %ds
21206 +#endif
21207 +
21208 +ENTRY(csum_partial_copy_generic)
21209 pushl_cfi %ebx
21210 CFI_REL_OFFSET ebx, 0
21211 pushl_cfi %edi
21212 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21213 subl %ebx, %edi
21214 lea -1(%esi),%edx
21215 andl $-32,%edx
21216 - lea 3f(%ebx,%ebx), %ebx
21217 + lea 3f(%ebx,%ebx,2), %ebx
21218 testl %esi, %esi
21219 jmp *%ebx
21220 1: addl $64,%esi
21221 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21222 jb 5f
21223 SRC( movw (%esi), %dx )
21224 leal 2(%esi), %esi
21225 -DST( movw %dx, (%edi) )
21226 +DST( movw %dx, %es:(%edi) )
21227 leal 2(%edi), %edi
21228 je 6f
21229 shll $16,%edx
21230 5:
21231 SRC( movb (%esi), %dl )
21232 -DST( movb %dl, (%edi) )
21233 +DST( movb %dl, %es:(%edi) )
21234 6: addl %edx, %eax
21235 adcl $0, %eax
21236 7:
21237 .section .fixup, "ax"
21238 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21239 - movl $-EFAULT, (%ebx)
21240 + movl $-EFAULT, %ss:(%ebx)
21241 # zero the complete destination (computing the rest is too much work)
21242 movl ARGBASE+8(%esp),%edi # dst
21243 movl ARGBASE+12(%esp),%ecx # len
21244 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21245 rep; stosb
21246 jmp 7b
21247 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21248 - movl $-EFAULT, (%ebx)
21249 + movl $-EFAULT, %ss:(%ebx)
21250 jmp 7b
21251 .previous
21252
21253 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21254 + pushl_cfi %ss
21255 + popl_cfi %ds
21256 + pushl_cfi %ss
21257 + popl_cfi %es
21258 +#endif
21259 +
21260 popl_cfi %esi
21261 CFI_RESTORE esi
21262 popl_cfi %edi
21263 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21264 CFI_RESTORE ebx
21265 ret
21266 CFI_ENDPROC
21267 -ENDPROC(csum_partial_copy_generic)
21268 +ENDPROC(csum_partial_copy_generic_to_user)
21269
21270 #undef ROUND
21271 #undef ROUND1
21272 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21273 index f2145cf..cea889d 100644
21274 --- a/arch/x86/lib/clear_page_64.S
21275 +++ b/arch/x86/lib/clear_page_64.S
21276 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21277 movl $4096/8,%ecx
21278 xorl %eax,%eax
21279 rep stosq
21280 + pax_force_retaddr
21281 ret
21282 CFI_ENDPROC
21283 ENDPROC(clear_page_c)
21284 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21285 movl $4096,%ecx
21286 xorl %eax,%eax
21287 rep stosb
21288 + pax_force_retaddr
21289 ret
21290 CFI_ENDPROC
21291 ENDPROC(clear_page_c_e)
21292 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21293 leaq 64(%rdi),%rdi
21294 jnz .Lloop
21295 nop
21296 + pax_force_retaddr
21297 ret
21298 CFI_ENDPROC
21299 .Lclear_page_end:
21300 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21301
21302 #include <asm/cpufeature.h>
21303
21304 - .section .altinstr_replacement,"ax"
21305 + .section .altinstr_replacement,"a"
21306 1: .byte 0xeb /* jmp <disp8> */
21307 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21308 2: .byte 0xeb /* jmp <disp8> */
21309 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21310 index 1e572c5..2a162cd 100644
21311 --- a/arch/x86/lib/cmpxchg16b_emu.S
21312 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21313 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21314
21315 popf
21316 mov $1, %al
21317 + pax_force_retaddr
21318 ret
21319
21320 not_same:
21321 popf
21322 xor %al,%al
21323 + pax_force_retaddr
21324 ret
21325
21326 CFI_ENDPROC
21327 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21328 index 6b34d04..dccb07f 100644
21329 --- a/arch/x86/lib/copy_page_64.S
21330 +++ b/arch/x86/lib/copy_page_64.S
21331 @@ -9,6 +9,7 @@ copy_page_c:
21332 CFI_STARTPROC
21333 movl $4096/8,%ecx
21334 rep movsq
21335 + pax_force_retaddr
21336 ret
21337 CFI_ENDPROC
21338 ENDPROC(copy_page_c)
21339 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21340
21341 ENTRY(copy_page)
21342 CFI_STARTPROC
21343 - subq $2*8,%rsp
21344 - CFI_ADJUST_CFA_OFFSET 2*8
21345 + subq $3*8,%rsp
21346 + CFI_ADJUST_CFA_OFFSET 3*8
21347 movq %rbx,(%rsp)
21348 CFI_REL_OFFSET rbx, 0
21349 movq %r12,1*8(%rsp)
21350 CFI_REL_OFFSET r12, 1*8
21351 + movq %r13,2*8(%rsp)
21352 + CFI_REL_OFFSET r13, 2*8
21353
21354 movl $(4096/64)-5,%ecx
21355 .p2align 4
21356 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21357 movq 16 (%rsi), %rdx
21358 movq 24 (%rsi), %r8
21359 movq 32 (%rsi), %r9
21360 - movq 40 (%rsi), %r10
21361 + movq 40 (%rsi), %r13
21362 movq 48 (%rsi), %r11
21363 movq 56 (%rsi), %r12
21364
21365 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21366 movq %rdx, 16 (%rdi)
21367 movq %r8, 24 (%rdi)
21368 movq %r9, 32 (%rdi)
21369 - movq %r10, 40 (%rdi)
21370 + movq %r13, 40 (%rdi)
21371 movq %r11, 48 (%rdi)
21372 movq %r12, 56 (%rdi)
21373
21374 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21375 movq 16 (%rsi), %rdx
21376 movq 24 (%rsi), %r8
21377 movq 32 (%rsi), %r9
21378 - movq 40 (%rsi), %r10
21379 + movq 40 (%rsi), %r13
21380 movq 48 (%rsi), %r11
21381 movq 56 (%rsi), %r12
21382
21383 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21384 movq %rdx, 16 (%rdi)
21385 movq %r8, 24 (%rdi)
21386 movq %r9, 32 (%rdi)
21387 - movq %r10, 40 (%rdi)
21388 + movq %r13, 40 (%rdi)
21389 movq %r11, 48 (%rdi)
21390 movq %r12, 56 (%rdi)
21391
21392 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21393 CFI_RESTORE rbx
21394 movq 1*8(%rsp),%r12
21395 CFI_RESTORE r12
21396 - addq $2*8,%rsp
21397 - CFI_ADJUST_CFA_OFFSET -2*8
21398 + movq 2*8(%rsp),%r13
21399 + CFI_RESTORE r13
21400 + addq $3*8,%rsp
21401 + CFI_ADJUST_CFA_OFFSET -3*8
21402 + pax_force_retaddr
21403 ret
21404 .Lcopy_page_end:
21405 CFI_ENDPROC
21406 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21407
21408 #include <asm/cpufeature.h>
21409
21410 - .section .altinstr_replacement,"ax"
21411 + .section .altinstr_replacement,"a"
21412 1: .byte 0xeb /* jmp <disp8> */
21413 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21414 2:
21415 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21416 index 5b2995f..78e7644 100644
21417 --- a/arch/x86/lib/copy_user_64.S
21418 +++ b/arch/x86/lib/copy_user_64.S
21419 @@ -17,6 +17,7 @@
21420 #include <asm/cpufeature.h>
21421 #include <asm/alternative-asm.h>
21422 #include <asm/asm.h>
21423 +#include <asm/pgtable.h>
21424
21425 /*
21426 * By placing feature2 after feature1 in altinstructions section, we logically
21427 @@ -30,7 +31,7 @@
21428 .byte 0xe9 /* 32bit jump */
21429 .long \orig-1f /* by default jump to orig */
21430 1:
21431 - .section .altinstr_replacement,"ax"
21432 + .section .altinstr_replacement,"a"
21433 2: .byte 0xe9 /* near jump with 32bit immediate */
21434 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21435 3: .byte 0xe9 /* near jump with 32bit immediate */
21436 @@ -69,47 +70,20 @@
21437 #endif
21438 .endm
21439
21440 -/* Standard copy_to_user with segment limit checking */
21441 -ENTRY(_copy_to_user)
21442 - CFI_STARTPROC
21443 - GET_THREAD_INFO(%rax)
21444 - movq %rdi,%rcx
21445 - addq %rdx,%rcx
21446 - jc bad_to_user
21447 - cmpq TI_addr_limit(%rax),%rcx
21448 - ja bad_to_user
21449 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21450 - copy_user_generic_unrolled,copy_user_generic_string, \
21451 - copy_user_enhanced_fast_string
21452 - CFI_ENDPROC
21453 -ENDPROC(_copy_to_user)
21454 -
21455 -/* Standard copy_from_user with segment limit checking */
21456 -ENTRY(_copy_from_user)
21457 - CFI_STARTPROC
21458 - GET_THREAD_INFO(%rax)
21459 - movq %rsi,%rcx
21460 - addq %rdx,%rcx
21461 - jc bad_from_user
21462 - cmpq TI_addr_limit(%rax),%rcx
21463 - ja bad_from_user
21464 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21465 - copy_user_generic_unrolled,copy_user_generic_string, \
21466 - copy_user_enhanced_fast_string
21467 - CFI_ENDPROC
21468 -ENDPROC(_copy_from_user)
21469 -
21470 .section .fixup,"ax"
21471 /* must zero dest */
21472 ENTRY(bad_from_user)
21473 bad_from_user:
21474 CFI_STARTPROC
21475 + testl %edx,%edx
21476 + js bad_to_user
21477 movl %edx,%ecx
21478 xorl %eax,%eax
21479 rep
21480 stosb
21481 bad_to_user:
21482 movl %edx,%eax
21483 + pax_force_retaddr
21484 ret
21485 CFI_ENDPROC
21486 ENDPROC(bad_from_user)
21487 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21488 jz 17f
21489 1: movq (%rsi),%r8
21490 2: movq 1*8(%rsi),%r9
21491 -3: movq 2*8(%rsi),%r10
21492 +3: movq 2*8(%rsi),%rax
21493 4: movq 3*8(%rsi),%r11
21494 5: movq %r8,(%rdi)
21495 6: movq %r9,1*8(%rdi)
21496 -7: movq %r10,2*8(%rdi)
21497 +7: movq %rax,2*8(%rdi)
21498 8: movq %r11,3*8(%rdi)
21499 9: movq 4*8(%rsi),%r8
21500 10: movq 5*8(%rsi),%r9
21501 -11: movq 6*8(%rsi),%r10
21502 +11: movq 6*8(%rsi),%rax
21503 12: movq 7*8(%rsi),%r11
21504 13: movq %r8,4*8(%rdi)
21505 14: movq %r9,5*8(%rdi)
21506 -15: movq %r10,6*8(%rdi)
21507 +15: movq %rax,6*8(%rdi)
21508 16: movq %r11,7*8(%rdi)
21509 leaq 64(%rsi),%rsi
21510 leaq 64(%rdi),%rdi
21511 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21512 decl %ecx
21513 jnz 21b
21514 23: xor %eax,%eax
21515 + pax_force_retaddr
21516 ret
21517
21518 .section .fixup,"ax"
21519 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21520 3: rep
21521 movsb
21522 4: xorl %eax,%eax
21523 + pax_force_retaddr
21524 ret
21525
21526 .section .fixup,"ax"
21527 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21528 1: rep
21529 movsb
21530 2: xorl %eax,%eax
21531 + pax_force_retaddr
21532 ret
21533
21534 .section .fixup,"ax"
21535 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21536 index cacddc7..09d49e4 100644
21537 --- a/arch/x86/lib/copy_user_nocache_64.S
21538 +++ b/arch/x86/lib/copy_user_nocache_64.S
21539 @@ -8,6 +8,7 @@
21540
21541 #include <linux/linkage.h>
21542 #include <asm/dwarf2.h>
21543 +#include <asm/alternative-asm.h>
21544
21545 #define FIX_ALIGNMENT 1
21546
21547 @@ -15,6 +16,7 @@
21548 #include <asm/asm-offsets.h>
21549 #include <asm/thread_info.h>
21550 #include <asm/asm.h>
21551 +#include <asm/pgtable.h>
21552
21553 .macro ALIGN_DESTINATION
21554 #ifdef FIX_ALIGNMENT
21555 @@ -48,6 +50,15 @@
21556 */
21557 ENTRY(__copy_user_nocache)
21558 CFI_STARTPROC
21559 +
21560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21561 + mov $PAX_USER_SHADOW_BASE,%rcx
21562 + cmp %rcx,%rsi
21563 + jae 1f
21564 + add %rcx,%rsi
21565 +1:
21566 +#endif
21567 +
21568 cmpl $8,%edx
21569 jb 20f /* less then 8 bytes, go to byte copy loop */
21570 ALIGN_DESTINATION
21571 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21572 jz 17f
21573 1: movq (%rsi),%r8
21574 2: movq 1*8(%rsi),%r9
21575 -3: movq 2*8(%rsi),%r10
21576 +3: movq 2*8(%rsi),%rax
21577 4: movq 3*8(%rsi),%r11
21578 5: movnti %r8,(%rdi)
21579 6: movnti %r9,1*8(%rdi)
21580 -7: movnti %r10,2*8(%rdi)
21581 +7: movnti %rax,2*8(%rdi)
21582 8: movnti %r11,3*8(%rdi)
21583 9: movq 4*8(%rsi),%r8
21584 10: movq 5*8(%rsi),%r9
21585 -11: movq 6*8(%rsi),%r10
21586 +11: movq 6*8(%rsi),%rax
21587 12: movq 7*8(%rsi),%r11
21588 13: movnti %r8,4*8(%rdi)
21589 14: movnti %r9,5*8(%rdi)
21590 -15: movnti %r10,6*8(%rdi)
21591 +15: movnti %rax,6*8(%rdi)
21592 16: movnti %r11,7*8(%rdi)
21593 leaq 64(%rsi),%rsi
21594 leaq 64(%rdi),%rdi
21595 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21596 jnz 21b
21597 23: xorl %eax,%eax
21598 sfence
21599 + pax_force_retaddr
21600 ret
21601
21602 .section .fixup,"ax"
21603 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21604 index 2419d5f..953ee51 100644
21605 --- a/arch/x86/lib/csum-copy_64.S
21606 +++ b/arch/x86/lib/csum-copy_64.S
21607 @@ -9,6 +9,7 @@
21608 #include <asm/dwarf2.h>
21609 #include <asm/errno.h>
21610 #include <asm/asm.h>
21611 +#include <asm/alternative-asm.h>
21612
21613 /*
21614 * Checksum copy with exception handling.
21615 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21616 CFI_RESTORE rbp
21617 addq $7*8, %rsp
21618 CFI_ADJUST_CFA_OFFSET -7*8
21619 + pax_force_retaddr 0, 1
21620 ret
21621 CFI_RESTORE_STATE
21622
21623 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21624 index 25b7ae8..3b52ccd 100644
21625 --- a/arch/x86/lib/csum-wrappers_64.c
21626 +++ b/arch/x86/lib/csum-wrappers_64.c
21627 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21628 len -= 2;
21629 }
21630 }
21631 - isum = csum_partial_copy_generic((__force const void *)src,
21632 +
21633 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21634 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21635 + src += PAX_USER_SHADOW_BASE;
21636 +#endif
21637 +
21638 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21639 dst, len, isum, errp, NULL);
21640 if (unlikely(*errp))
21641 goto out_err;
21642 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21643 }
21644
21645 *errp = 0;
21646 - return csum_partial_copy_generic(src, (void __force *)dst,
21647 +
21648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21649 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21650 + dst += PAX_USER_SHADOW_BASE;
21651 +#endif
21652 +
21653 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21654 len, isum, NULL, errp);
21655 }
21656 EXPORT_SYMBOL(csum_partial_copy_to_user);
21657 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21658 index b33b1fb..219f389 100644
21659 --- a/arch/x86/lib/getuser.S
21660 +++ b/arch/x86/lib/getuser.S
21661 @@ -33,15 +33,38 @@
21662 #include <asm/asm-offsets.h>
21663 #include <asm/thread_info.h>
21664 #include <asm/asm.h>
21665 +#include <asm/segment.h>
21666 +#include <asm/pgtable.h>
21667 +#include <asm/alternative-asm.h>
21668 +
21669 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21670 +#define __copyuser_seg gs;
21671 +#else
21672 +#define __copyuser_seg
21673 +#endif
21674
21675 .text
21676 ENTRY(__get_user_1)
21677 CFI_STARTPROC
21678 +
21679 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21680 GET_THREAD_INFO(%_ASM_DX)
21681 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21682 jae bad_get_user
21683 -1: movzb (%_ASM_AX),%edx
21684 +
21685 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21686 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21687 + cmp %_ASM_DX,%_ASM_AX
21688 + jae 1234f
21689 + add %_ASM_DX,%_ASM_AX
21690 +1234:
21691 +#endif
21692 +
21693 +#endif
21694 +
21695 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21696 xor %eax,%eax
21697 + pax_force_retaddr
21698 ret
21699 CFI_ENDPROC
21700 ENDPROC(__get_user_1)
21701 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21702 ENTRY(__get_user_2)
21703 CFI_STARTPROC
21704 add $1,%_ASM_AX
21705 +
21706 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21707 jc bad_get_user
21708 GET_THREAD_INFO(%_ASM_DX)
21709 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21710 jae bad_get_user
21711 -2: movzwl -1(%_ASM_AX),%edx
21712 +
21713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21714 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21715 + cmp %_ASM_DX,%_ASM_AX
21716 + jae 1234f
21717 + add %_ASM_DX,%_ASM_AX
21718 +1234:
21719 +#endif
21720 +
21721 +#endif
21722 +
21723 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21724 xor %eax,%eax
21725 + pax_force_retaddr
21726 ret
21727 CFI_ENDPROC
21728 ENDPROC(__get_user_2)
21729 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21730 ENTRY(__get_user_4)
21731 CFI_STARTPROC
21732 add $3,%_ASM_AX
21733 +
21734 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21735 jc bad_get_user
21736 GET_THREAD_INFO(%_ASM_DX)
21737 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21738 jae bad_get_user
21739 -3: mov -3(%_ASM_AX),%edx
21740 +
21741 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21742 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21743 + cmp %_ASM_DX,%_ASM_AX
21744 + jae 1234f
21745 + add %_ASM_DX,%_ASM_AX
21746 +1234:
21747 +#endif
21748 +
21749 +#endif
21750 +
21751 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21752 xor %eax,%eax
21753 + pax_force_retaddr
21754 ret
21755 CFI_ENDPROC
21756 ENDPROC(__get_user_4)
21757 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21758 GET_THREAD_INFO(%_ASM_DX)
21759 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21760 jae bad_get_user
21761 +
21762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21763 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21764 + cmp %_ASM_DX,%_ASM_AX
21765 + jae 1234f
21766 + add %_ASM_DX,%_ASM_AX
21767 +1234:
21768 +#endif
21769 +
21770 4: movq -7(%_ASM_AX),%_ASM_DX
21771 xor %eax,%eax
21772 + pax_force_retaddr
21773 ret
21774 CFI_ENDPROC
21775 ENDPROC(__get_user_8)
21776 @@ -91,6 +152,7 @@ bad_get_user:
21777 CFI_STARTPROC
21778 xor %edx,%edx
21779 mov $(-EFAULT),%_ASM_AX
21780 + pax_force_retaddr
21781 ret
21782 CFI_ENDPROC
21783 END(bad_get_user)
21784 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21785 index b1e6c4b..21ae8fc 100644
21786 --- a/arch/x86/lib/insn.c
21787 +++ b/arch/x86/lib/insn.c
21788 @@ -21,6 +21,11 @@
21789 #include <linux/string.h>
21790 #include <asm/inat.h>
21791 #include <asm/insn.h>
21792 +#ifdef __KERNEL__
21793 +#include <asm/pgtable_types.h>
21794 +#else
21795 +#define ktla_ktva(addr) addr
21796 +#endif
21797
21798 /* Verify next sizeof(t) bytes can be on the same instruction */
21799 #define validate_next(t, insn, n) \
21800 @@ -49,8 +54,8 @@
21801 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21802 {
21803 memset(insn, 0, sizeof(*insn));
21804 - insn->kaddr = kaddr;
21805 - insn->next_byte = kaddr;
21806 + insn->kaddr = ktla_ktva(kaddr);
21807 + insn->next_byte = ktla_ktva(kaddr);
21808 insn->x86_64 = x86_64 ? 1 : 0;
21809 insn->opnd_bytes = 4;
21810 if (x86_64)
21811 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21812 index 05a95e7..326f2fa 100644
21813 --- a/arch/x86/lib/iomap_copy_64.S
21814 +++ b/arch/x86/lib/iomap_copy_64.S
21815 @@ -17,6 +17,7 @@
21816
21817 #include <linux/linkage.h>
21818 #include <asm/dwarf2.h>
21819 +#include <asm/alternative-asm.h>
21820
21821 /*
21822 * override generic version in lib/iomap_copy.c
21823 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21824 CFI_STARTPROC
21825 movl %edx,%ecx
21826 rep movsd
21827 + pax_force_retaddr
21828 ret
21829 CFI_ENDPROC
21830 ENDPROC(__iowrite32_copy)
21831 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21832 index 1c273be..da9cc0e 100644
21833 --- a/arch/x86/lib/memcpy_64.S
21834 +++ b/arch/x86/lib/memcpy_64.S
21835 @@ -33,6 +33,7 @@
21836 rep movsq
21837 movl %edx, %ecx
21838 rep movsb
21839 + pax_force_retaddr
21840 ret
21841 .Lmemcpy_e:
21842 .previous
21843 @@ -49,6 +50,7 @@
21844 movq %rdi, %rax
21845 movq %rdx, %rcx
21846 rep movsb
21847 + pax_force_retaddr
21848 ret
21849 .Lmemcpy_e_e:
21850 .previous
21851 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21852 */
21853 movq 0*8(%rsi), %r8
21854 movq 1*8(%rsi), %r9
21855 - movq 2*8(%rsi), %r10
21856 + movq 2*8(%rsi), %rcx
21857 movq 3*8(%rsi), %r11
21858 leaq 4*8(%rsi), %rsi
21859
21860 movq %r8, 0*8(%rdi)
21861 movq %r9, 1*8(%rdi)
21862 - movq %r10, 2*8(%rdi)
21863 + movq %rcx, 2*8(%rdi)
21864 movq %r11, 3*8(%rdi)
21865 leaq 4*8(%rdi), %rdi
21866 jae .Lcopy_forward_loop
21867 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21868 subq $0x20, %rdx
21869 movq -1*8(%rsi), %r8
21870 movq -2*8(%rsi), %r9
21871 - movq -3*8(%rsi), %r10
21872 + movq -3*8(%rsi), %rcx
21873 movq -4*8(%rsi), %r11
21874 leaq -4*8(%rsi), %rsi
21875 movq %r8, -1*8(%rdi)
21876 movq %r9, -2*8(%rdi)
21877 - movq %r10, -3*8(%rdi)
21878 + movq %rcx, -3*8(%rdi)
21879 movq %r11, -4*8(%rdi)
21880 leaq -4*8(%rdi), %rdi
21881 jae .Lcopy_backward_loop
21882 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21883 */
21884 movq 0*8(%rsi), %r8
21885 movq 1*8(%rsi), %r9
21886 - movq -2*8(%rsi, %rdx), %r10
21887 + movq -2*8(%rsi, %rdx), %rcx
21888 movq -1*8(%rsi, %rdx), %r11
21889 movq %r8, 0*8(%rdi)
21890 movq %r9, 1*8(%rdi)
21891 - movq %r10, -2*8(%rdi, %rdx)
21892 + movq %rcx, -2*8(%rdi, %rdx)
21893 movq %r11, -1*8(%rdi, %rdx)
21894 + pax_force_retaddr
21895 retq
21896 .p2align 4
21897 .Lless_16bytes:
21898 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21899 movq -1*8(%rsi, %rdx), %r9
21900 movq %r8, 0*8(%rdi)
21901 movq %r9, -1*8(%rdi, %rdx)
21902 + pax_force_retaddr
21903 retq
21904 .p2align 4
21905 .Lless_8bytes:
21906 @@ -161,6 +165,7 @@ ENTRY(memcpy)
21907 movl -4(%rsi, %rdx), %r8d
21908 movl %ecx, (%rdi)
21909 movl %r8d, -4(%rdi, %rdx)
21910 + pax_force_retaddr
21911 retq
21912 .p2align 4
21913 .Lless_3bytes:
21914 @@ -179,6 +184,7 @@ ENTRY(memcpy)
21915 movb %cl, (%rdi)
21916
21917 .Lend:
21918 + pax_force_retaddr
21919 retq
21920 CFI_ENDPROC
21921 ENDPROC(memcpy)
21922 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21923 index ee16461..c39c199 100644
21924 --- a/arch/x86/lib/memmove_64.S
21925 +++ b/arch/x86/lib/memmove_64.S
21926 @@ -61,13 +61,13 @@ ENTRY(memmove)
21927 5:
21928 sub $0x20, %rdx
21929 movq 0*8(%rsi), %r11
21930 - movq 1*8(%rsi), %r10
21931 + movq 1*8(%rsi), %rcx
21932 movq 2*8(%rsi), %r9
21933 movq 3*8(%rsi), %r8
21934 leaq 4*8(%rsi), %rsi
21935
21936 movq %r11, 0*8(%rdi)
21937 - movq %r10, 1*8(%rdi)
21938 + movq %rcx, 1*8(%rdi)
21939 movq %r9, 2*8(%rdi)
21940 movq %r8, 3*8(%rdi)
21941 leaq 4*8(%rdi), %rdi
21942 @@ -81,10 +81,10 @@ ENTRY(memmove)
21943 4:
21944 movq %rdx, %rcx
21945 movq -8(%rsi, %rdx), %r11
21946 - lea -8(%rdi, %rdx), %r10
21947 + lea -8(%rdi, %rdx), %r9
21948 shrq $3, %rcx
21949 rep movsq
21950 - movq %r11, (%r10)
21951 + movq %r11, (%r9)
21952 jmp 13f
21953 .Lmemmove_end_forward:
21954
21955 @@ -95,14 +95,14 @@ ENTRY(memmove)
21956 7:
21957 movq %rdx, %rcx
21958 movq (%rsi), %r11
21959 - movq %rdi, %r10
21960 + movq %rdi, %r9
21961 leaq -8(%rsi, %rdx), %rsi
21962 leaq -8(%rdi, %rdx), %rdi
21963 shrq $3, %rcx
21964 std
21965 rep movsq
21966 cld
21967 - movq %r11, (%r10)
21968 + movq %r11, (%r9)
21969 jmp 13f
21970
21971 /*
21972 @@ -127,13 +127,13 @@ ENTRY(memmove)
21973 8:
21974 subq $0x20, %rdx
21975 movq -1*8(%rsi), %r11
21976 - movq -2*8(%rsi), %r10
21977 + movq -2*8(%rsi), %rcx
21978 movq -3*8(%rsi), %r9
21979 movq -4*8(%rsi), %r8
21980 leaq -4*8(%rsi), %rsi
21981
21982 movq %r11, -1*8(%rdi)
21983 - movq %r10, -2*8(%rdi)
21984 + movq %rcx, -2*8(%rdi)
21985 movq %r9, -3*8(%rdi)
21986 movq %r8, -4*8(%rdi)
21987 leaq -4*8(%rdi), %rdi
21988 @@ -151,11 +151,11 @@ ENTRY(memmove)
21989 * Move data from 16 bytes to 31 bytes.
21990 */
21991 movq 0*8(%rsi), %r11
21992 - movq 1*8(%rsi), %r10
21993 + movq 1*8(%rsi), %rcx
21994 movq -2*8(%rsi, %rdx), %r9
21995 movq -1*8(%rsi, %rdx), %r8
21996 movq %r11, 0*8(%rdi)
21997 - movq %r10, 1*8(%rdi)
21998 + movq %rcx, 1*8(%rdi)
21999 movq %r9, -2*8(%rdi, %rdx)
22000 movq %r8, -1*8(%rdi, %rdx)
22001 jmp 13f
22002 @@ -167,9 +167,9 @@ ENTRY(memmove)
22003 * Move data from 8 bytes to 15 bytes.
22004 */
22005 movq 0*8(%rsi), %r11
22006 - movq -1*8(%rsi, %rdx), %r10
22007 + movq -1*8(%rsi, %rdx), %r9
22008 movq %r11, 0*8(%rdi)
22009 - movq %r10, -1*8(%rdi, %rdx)
22010 + movq %r9, -1*8(%rdi, %rdx)
22011 jmp 13f
22012 10:
22013 cmpq $4, %rdx
22014 @@ -178,9 +178,9 @@ ENTRY(memmove)
22015 * Move data from 4 bytes to 7 bytes.
22016 */
22017 movl (%rsi), %r11d
22018 - movl -4(%rsi, %rdx), %r10d
22019 + movl -4(%rsi, %rdx), %r9d
22020 movl %r11d, (%rdi)
22021 - movl %r10d, -4(%rdi, %rdx)
22022 + movl %r9d, -4(%rdi, %rdx)
22023 jmp 13f
22024 11:
22025 cmp $2, %rdx
22026 @@ -189,9 +189,9 @@ ENTRY(memmove)
22027 * Move data from 2 bytes to 3 bytes.
22028 */
22029 movw (%rsi), %r11w
22030 - movw -2(%rsi, %rdx), %r10w
22031 + movw -2(%rsi, %rdx), %r9w
22032 movw %r11w, (%rdi)
22033 - movw %r10w, -2(%rdi, %rdx)
22034 + movw %r9w, -2(%rdi, %rdx)
22035 jmp 13f
22036 12:
22037 cmp $1, %rdx
22038 @@ -202,6 +202,7 @@ ENTRY(memmove)
22039 movb (%rsi), %r11b
22040 movb %r11b, (%rdi)
22041 13:
22042 + pax_force_retaddr
22043 retq
22044 CFI_ENDPROC
22045
22046 @@ -210,6 +211,7 @@ ENTRY(memmove)
22047 /* Forward moving data. */
22048 movq %rdx, %rcx
22049 rep movsb
22050 + pax_force_retaddr
22051 retq
22052 .Lmemmove_end_forward_efs:
22053 .previous
22054 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22055 index 2dcb380..963660a 100644
22056 --- a/arch/x86/lib/memset_64.S
22057 +++ b/arch/x86/lib/memset_64.S
22058 @@ -30,6 +30,7 @@
22059 movl %edx,%ecx
22060 rep stosb
22061 movq %r9,%rax
22062 + pax_force_retaddr
22063 ret
22064 .Lmemset_e:
22065 .previous
22066 @@ -52,6 +53,7 @@
22067 movq %rdx,%rcx
22068 rep stosb
22069 movq %r9,%rax
22070 + pax_force_retaddr
22071 ret
22072 .Lmemset_e_e:
22073 .previous
22074 @@ -59,7 +61,7 @@
22075 ENTRY(memset)
22076 ENTRY(__memset)
22077 CFI_STARTPROC
22078 - movq %rdi,%r10
22079 + movq %rdi,%r11
22080
22081 /* expand byte value */
22082 movzbl %sil,%ecx
22083 @@ -117,7 +119,8 @@ ENTRY(__memset)
22084 jnz .Lloop_1
22085
22086 .Lende:
22087 - movq %r10,%rax
22088 + movq %r11,%rax
22089 + pax_force_retaddr
22090 ret
22091
22092 CFI_RESTORE_STATE
22093 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22094 index c9f2d9b..e7fd2c0 100644
22095 --- a/arch/x86/lib/mmx_32.c
22096 +++ b/arch/x86/lib/mmx_32.c
22097 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22098 {
22099 void *p;
22100 int i;
22101 + unsigned long cr0;
22102
22103 if (unlikely(in_interrupt()))
22104 return __memcpy(to, from, len);
22105 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22106 kernel_fpu_begin();
22107
22108 __asm__ __volatile__ (
22109 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22110 - " prefetch 64(%0)\n"
22111 - " prefetch 128(%0)\n"
22112 - " prefetch 192(%0)\n"
22113 - " prefetch 256(%0)\n"
22114 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22115 + " prefetch 64(%1)\n"
22116 + " prefetch 128(%1)\n"
22117 + " prefetch 192(%1)\n"
22118 + " prefetch 256(%1)\n"
22119 "2: \n"
22120 ".section .fixup, \"ax\"\n"
22121 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22122 + "3: \n"
22123 +
22124 +#ifdef CONFIG_PAX_KERNEXEC
22125 + " movl %%cr0, %0\n"
22126 + " movl %0, %%eax\n"
22127 + " andl $0xFFFEFFFF, %%eax\n"
22128 + " movl %%eax, %%cr0\n"
22129 +#endif
22130 +
22131 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22132 +
22133 +#ifdef CONFIG_PAX_KERNEXEC
22134 + " movl %0, %%cr0\n"
22135 +#endif
22136 +
22137 " jmp 2b\n"
22138 ".previous\n"
22139 _ASM_EXTABLE(1b, 3b)
22140 - : : "r" (from));
22141 + : "=&r" (cr0) : "r" (from) : "ax");
22142
22143 for ( ; i > 5; i--) {
22144 __asm__ __volatile__ (
22145 - "1: prefetch 320(%0)\n"
22146 - "2: movq (%0), %%mm0\n"
22147 - " movq 8(%0), %%mm1\n"
22148 - " movq 16(%0), %%mm2\n"
22149 - " movq 24(%0), %%mm3\n"
22150 - " movq %%mm0, (%1)\n"
22151 - " movq %%mm1, 8(%1)\n"
22152 - " movq %%mm2, 16(%1)\n"
22153 - " movq %%mm3, 24(%1)\n"
22154 - " movq 32(%0), %%mm0\n"
22155 - " movq 40(%0), %%mm1\n"
22156 - " movq 48(%0), %%mm2\n"
22157 - " movq 56(%0), %%mm3\n"
22158 - " movq %%mm0, 32(%1)\n"
22159 - " movq %%mm1, 40(%1)\n"
22160 - " movq %%mm2, 48(%1)\n"
22161 - " movq %%mm3, 56(%1)\n"
22162 + "1: prefetch 320(%1)\n"
22163 + "2: movq (%1), %%mm0\n"
22164 + " movq 8(%1), %%mm1\n"
22165 + " movq 16(%1), %%mm2\n"
22166 + " movq 24(%1), %%mm3\n"
22167 + " movq %%mm0, (%2)\n"
22168 + " movq %%mm1, 8(%2)\n"
22169 + " movq %%mm2, 16(%2)\n"
22170 + " movq %%mm3, 24(%2)\n"
22171 + " movq 32(%1), %%mm0\n"
22172 + " movq 40(%1), %%mm1\n"
22173 + " movq 48(%1), %%mm2\n"
22174 + " movq 56(%1), %%mm3\n"
22175 + " movq %%mm0, 32(%2)\n"
22176 + " movq %%mm1, 40(%2)\n"
22177 + " movq %%mm2, 48(%2)\n"
22178 + " movq %%mm3, 56(%2)\n"
22179 ".section .fixup, \"ax\"\n"
22180 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22181 + "3:\n"
22182 +
22183 +#ifdef CONFIG_PAX_KERNEXEC
22184 + " movl %%cr0, %0\n"
22185 + " movl %0, %%eax\n"
22186 + " andl $0xFFFEFFFF, %%eax\n"
22187 + " movl %%eax, %%cr0\n"
22188 +#endif
22189 +
22190 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22191 +
22192 +#ifdef CONFIG_PAX_KERNEXEC
22193 + " movl %0, %%cr0\n"
22194 +#endif
22195 +
22196 " jmp 2b\n"
22197 ".previous\n"
22198 _ASM_EXTABLE(1b, 3b)
22199 - : : "r" (from), "r" (to) : "memory");
22200 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22201
22202 from += 64;
22203 to += 64;
22204 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22205 static void fast_copy_page(void *to, void *from)
22206 {
22207 int i;
22208 + unsigned long cr0;
22209
22210 kernel_fpu_begin();
22211
22212 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22213 * but that is for later. -AV
22214 */
22215 __asm__ __volatile__(
22216 - "1: prefetch (%0)\n"
22217 - " prefetch 64(%0)\n"
22218 - " prefetch 128(%0)\n"
22219 - " prefetch 192(%0)\n"
22220 - " prefetch 256(%0)\n"
22221 + "1: prefetch (%1)\n"
22222 + " prefetch 64(%1)\n"
22223 + " prefetch 128(%1)\n"
22224 + " prefetch 192(%1)\n"
22225 + " prefetch 256(%1)\n"
22226 "2: \n"
22227 ".section .fixup, \"ax\"\n"
22228 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22229 + "3: \n"
22230 +
22231 +#ifdef CONFIG_PAX_KERNEXEC
22232 + " movl %%cr0, %0\n"
22233 + " movl %0, %%eax\n"
22234 + " andl $0xFFFEFFFF, %%eax\n"
22235 + " movl %%eax, %%cr0\n"
22236 +#endif
22237 +
22238 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22239 +
22240 +#ifdef CONFIG_PAX_KERNEXEC
22241 + " movl %0, %%cr0\n"
22242 +#endif
22243 +
22244 " jmp 2b\n"
22245 ".previous\n"
22246 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22247 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22248
22249 for (i = 0; i < (4096-320)/64; i++) {
22250 __asm__ __volatile__ (
22251 - "1: prefetch 320(%0)\n"
22252 - "2: movq (%0), %%mm0\n"
22253 - " movntq %%mm0, (%1)\n"
22254 - " movq 8(%0), %%mm1\n"
22255 - " movntq %%mm1, 8(%1)\n"
22256 - " movq 16(%0), %%mm2\n"
22257 - " movntq %%mm2, 16(%1)\n"
22258 - " movq 24(%0), %%mm3\n"
22259 - " movntq %%mm3, 24(%1)\n"
22260 - " movq 32(%0), %%mm4\n"
22261 - " movntq %%mm4, 32(%1)\n"
22262 - " movq 40(%0), %%mm5\n"
22263 - " movntq %%mm5, 40(%1)\n"
22264 - " movq 48(%0), %%mm6\n"
22265 - " movntq %%mm6, 48(%1)\n"
22266 - " movq 56(%0), %%mm7\n"
22267 - " movntq %%mm7, 56(%1)\n"
22268 + "1: prefetch 320(%1)\n"
22269 + "2: movq (%1), %%mm0\n"
22270 + " movntq %%mm0, (%2)\n"
22271 + " movq 8(%1), %%mm1\n"
22272 + " movntq %%mm1, 8(%2)\n"
22273 + " movq 16(%1), %%mm2\n"
22274 + " movntq %%mm2, 16(%2)\n"
22275 + " movq 24(%1), %%mm3\n"
22276 + " movntq %%mm3, 24(%2)\n"
22277 + " movq 32(%1), %%mm4\n"
22278 + " movntq %%mm4, 32(%2)\n"
22279 + " movq 40(%1), %%mm5\n"
22280 + " movntq %%mm5, 40(%2)\n"
22281 + " movq 48(%1), %%mm6\n"
22282 + " movntq %%mm6, 48(%2)\n"
22283 + " movq 56(%1), %%mm7\n"
22284 + " movntq %%mm7, 56(%2)\n"
22285 ".section .fixup, \"ax\"\n"
22286 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22287 + "3:\n"
22288 +
22289 +#ifdef CONFIG_PAX_KERNEXEC
22290 + " movl %%cr0, %0\n"
22291 + " movl %0, %%eax\n"
22292 + " andl $0xFFFEFFFF, %%eax\n"
22293 + " movl %%eax, %%cr0\n"
22294 +#endif
22295 +
22296 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22297 +
22298 +#ifdef CONFIG_PAX_KERNEXEC
22299 + " movl %0, %%cr0\n"
22300 +#endif
22301 +
22302 " jmp 2b\n"
22303 ".previous\n"
22304 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22305 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22306
22307 from += 64;
22308 to += 64;
22309 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22310 static void fast_copy_page(void *to, void *from)
22311 {
22312 int i;
22313 + unsigned long cr0;
22314
22315 kernel_fpu_begin();
22316
22317 __asm__ __volatile__ (
22318 - "1: prefetch (%0)\n"
22319 - " prefetch 64(%0)\n"
22320 - " prefetch 128(%0)\n"
22321 - " prefetch 192(%0)\n"
22322 - " prefetch 256(%0)\n"
22323 + "1: prefetch (%1)\n"
22324 + " prefetch 64(%1)\n"
22325 + " prefetch 128(%1)\n"
22326 + " prefetch 192(%1)\n"
22327 + " prefetch 256(%1)\n"
22328 "2: \n"
22329 ".section .fixup, \"ax\"\n"
22330 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22331 + "3: \n"
22332 +
22333 +#ifdef CONFIG_PAX_KERNEXEC
22334 + " movl %%cr0, %0\n"
22335 + " movl %0, %%eax\n"
22336 + " andl $0xFFFEFFFF, %%eax\n"
22337 + " movl %%eax, %%cr0\n"
22338 +#endif
22339 +
22340 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22341 +
22342 +#ifdef CONFIG_PAX_KERNEXEC
22343 + " movl %0, %%cr0\n"
22344 +#endif
22345 +
22346 " jmp 2b\n"
22347 ".previous\n"
22348 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22349 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22350
22351 for (i = 0; i < 4096/64; i++) {
22352 __asm__ __volatile__ (
22353 - "1: prefetch 320(%0)\n"
22354 - "2: movq (%0), %%mm0\n"
22355 - " movq 8(%0), %%mm1\n"
22356 - " movq 16(%0), %%mm2\n"
22357 - " movq 24(%0), %%mm3\n"
22358 - " movq %%mm0, (%1)\n"
22359 - " movq %%mm1, 8(%1)\n"
22360 - " movq %%mm2, 16(%1)\n"
22361 - " movq %%mm3, 24(%1)\n"
22362 - " movq 32(%0), %%mm0\n"
22363 - " movq 40(%0), %%mm1\n"
22364 - " movq 48(%0), %%mm2\n"
22365 - " movq 56(%0), %%mm3\n"
22366 - " movq %%mm0, 32(%1)\n"
22367 - " movq %%mm1, 40(%1)\n"
22368 - " movq %%mm2, 48(%1)\n"
22369 - " movq %%mm3, 56(%1)\n"
22370 + "1: prefetch 320(%1)\n"
22371 + "2: movq (%1), %%mm0\n"
22372 + " movq 8(%1), %%mm1\n"
22373 + " movq 16(%1), %%mm2\n"
22374 + " movq 24(%1), %%mm3\n"
22375 + " movq %%mm0, (%2)\n"
22376 + " movq %%mm1, 8(%2)\n"
22377 + " movq %%mm2, 16(%2)\n"
22378 + " movq %%mm3, 24(%2)\n"
22379 + " movq 32(%1), %%mm0\n"
22380 + " movq 40(%1), %%mm1\n"
22381 + " movq 48(%1), %%mm2\n"
22382 + " movq 56(%1), %%mm3\n"
22383 + " movq %%mm0, 32(%2)\n"
22384 + " movq %%mm1, 40(%2)\n"
22385 + " movq %%mm2, 48(%2)\n"
22386 + " movq %%mm3, 56(%2)\n"
22387 ".section .fixup, \"ax\"\n"
22388 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22389 + "3:\n"
22390 +
22391 +#ifdef CONFIG_PAX_KERNEXEC
22392 + " movl %%cr0, %0\n"
22393 + " movl %0, %%eax\n"
22394 + " andl $0xFFFEFFFF, %%eax\n"
22395 + " movl %%eax, %%cr0\n"
22396 +#endif
22397 +
22398 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22399 +
22400 +#ifdef CONFIG_PAX_KERNEXEC
22401 + " movl %0, %%cr0\n"
22402 +#endif
22403 +
22404 " jmp 2b\n"
22405 ".previous\n"
22406 _ASM_EXTABLE(1b, 3b)
22407 - : : "r" (from), "r" (to) : "memory");
22408 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22409
22410 from += 64;
22411 to += 64;
22412 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22413 index 69fa106..adda88b 100644
22414 --- a/arch/x86/lib/msr-reg.S
22415 +++ b/arch/x86/lib/msr-reg.S
22416 @@ -3,6 +3,7 @@
22417 #include <asm/dwarf2.h>
22418 #include <asm/asm.h>
22419 #include <asm/msr.h>
22420 +#include <asm/alternative-asm.h>
22421
22422 #ifdef CONFIG_X86_64
22423 /*
22424 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22425 CFI_STARTPROC
22426 pushq_cfi %rbx
22427 pushq_cfi %rbp
22428 - movq %rdi, %r10 /* Save pointer */
22429 + movq %rdi, %r9 /* Save pointer */
22430 xorl %r11d, %r11d /* Return value */
22431 movl (%rdi), %eax
22432 movl 4(%rdi), %ecx
22433 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22434 movl 28(%rdi), %edi
22435 CFI_REMEMBER_STATE
22436 1: \op
22437 -2: movl %eax, (%r10)
22438 +2: movl %eax, (%r9)
22439 movl %r11d, %eax /* Return value */
22440 - movl %ecx, 4(%r10)
22441 - movl %edx, 8(%r10)
22442 - movl %ebx, 12(%r10)
22443 - movl %ebp, 20(%r10)
22444 - movl %esi, 24(%r10)
22445 - movl %edi, 28(%r10)
22446 + movl %ecx, 4(%r9)
22447 + movl %edx, 8(%r9)
22448 + movl %ebx, 12(%r9)
22449 + movl %ebp, 20(%r9)
22450 + movl %esi, 24(%r9)
22451 + movl %edi, 28(%r9)
22452 popq_cfi %rbp
22453 popq_cfi %rbx
22454 + pax_force_retaddr
22455 ret
22456 3:
22457 CFI_RESTORE_STATE
22458 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22459 index 7f951c8..ebd573a 100644
22460 --- a/arch/x86/lib/putuser.S
22461 +++ b/arch/x86/lib/putuser.S
22462 @@ -15,7 +15,9 @@
22463 #include <asm/thread_info.h>
22464 #include <asm/errno.h>
22465 #include <asm/asm.h>
22466 -
22467 +#include <asm/segment.h>
22468 +#include <asm/pgtable.h>
22469 +#include <asm/alternative-asm.h>
22470
22471 /*
22472 * __put_user_X
22473 @@ -29,52 +31,119 @@
22474 * as they get called from within inline assembly.
22475 */
22476
22477 -#define ENTER CFI_STARTPROC ; \
22478 - GET_THREAD_INFO(%_ASM_BX)
22479 -#define EXIT ret ; \
22480 +#define ENTER CFI_STARTPROC
22481 +#define EXIT pax_force_retaddr; ret ; \
22482 CFI_ENDPROC
22483
22484 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22485 +#define _DEST %_ASM_CX,%_ASM_BX
22486 +#else
22487 +#define _DEST %_ASM_CX
22488 +#endif
22489 +
22490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22491 +#define __copyuser_seg gs;
22492 +#else
22493 +#define __copyuser_seg
22494 +#endif
22495 +
22496 .text
22497 ENTRY(__put_user_1)
22498 ENTER
22499 +
22500 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22501 + GET_THREAD_INFO(%_ASM_BX)
22502 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22503 jae bad_put_user
22504 -1: movb %al,(%_ASM_CX)
22505 +
22506 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22507 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22508 + cmp %_ASM_BX,%_ASM_CX
22509 + jb 1234f
22510 + xor %ebx,%ebx
22511 +1234:
22512 +#endif
22513 +
22514 +#endif
22515 +
22516 +1: __copyuser_seg movb %al,(_DEST)
22517 xor %eax,%eax
22518 EXIT
22519 ENDPROC(__put_user_1)
22520
22521 ENTRY(__put_user_2)
22522 ENTER
22523 +
22524 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22525 + GET_THREAD_INFO(%_ASM_BX)
22526 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22527 sub $1,%_ASM_BX
22528 cmp %_ASM_BX,%_ASM_CX
22529 jae bad_put_user
22530 -2: movw %ax,(%_ASM_CX)
22531 +
22532 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22533 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22534 + cmp %_ASM_BX,%_ASM_CX
22535 + jb 1234f
22536 + xor %ebx,%ebx
22537 +1234:
22538 +#endif
22539 +
22540 +#endif
22541 +
22542 +2: __copyuser_seg movw %ax,(_DEST)
22543 xor %eax,%eax
22544 EXIT
22545 ENDPROC(__put_user_2)
22546
22547 ENTRY(__put_user_4)
22548 ENTER
22549 +
22550 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22551 + GET_THREAD_INFO(%_ASM_BX)
22552 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22553 sub $3,%_ASM_BX
22554 cmp %_ASM_BX,%_ASM_CX
22555 jae bad_put_user
22556 -3: movl %eax,(%_ASM_CX)
22557 +
22558 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22559 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22560 + cmp %_ASM_BX,%_ASM_CX
22561 + jb 1234f
22562 + xor %ebx,%ebx
22563 +1234:
22564 +#endif
22565 +
22566 +#endif
22567 +
22568 +3: __copyuser_seg movl %eax,(_DEST)
22569 xor %eax,%eax
22570 EXIT
22571 ENDPROC(__put_user_4)
22572
22573 ENTRY(__put_user_8)
22574 ENTER
22575 +
22576 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22577 + GET_THREAD_INFO(%_ASM_BX)
22578 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22579 sub $7,%_ASM_BX
22580 cmp %_ASM_BX,%_ASM_CX
22581 jae bad_put_user
22582 -4: mov %_ASM_AX,(%_ASM_CX)
22583 +
22584 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22585 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22586 + cmp %_ASM_BX,%_ASM_CX
22587 + jb 1234f
22588 + xor %ebx,%ebx
22589 +1234:
22590 +#endif
22591 +
22592 +#endif
22593 +
22594 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22595 #ifdef CONFIG_X86_32
22596 -5: movl %edx,4(%_ASM_CX)
22597 +5: __copyuser_seg movl %edx,4(_DEST)
22598 #endif
22599 xor %eax,%eax
22600 EXIT
22601 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22602 index 1cad221..de671ee 100644
22603 --- a/arch/x86/lib/rwlock.S
22604 +++ b/arch/x86/lib/rwlock.S
22605 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22606 FRAME
22607 0: LOCK_PREFIX
22608 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22609 +
22610 +#ifdef CONFIG_PAX_REFCOUNT
22611 + jno 1234f
22612 + LOCK_PREFIX
22613 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22614 + int $4
22615 +1234:
22616 + _ASM_EXTABLE(1234b, 1234b)
22617 +#endif
22618 +
22619 1: rep; nop
22620 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22621 jne 1b
22622 LOCK_PREFIX
22623 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22624 +
22625 +#ifdef CONFIG_PAX_REFCOUNT
22626 + jno 1234f
22627 + LOCK_PREFIX
22628 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22629 + int $4
22630 +1234:
22631 + _ASM_EXTABLE(1234b, 1234b)
22632 +#endif
22633 +
22634 jnz 0b
22635 ENDFRAME
22636 + pax_force_retaddr
22637 ret
22638 CFI_ENDPROC
22639 END(__write_lock_failed)
22640 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22641 FRAME
22642 0: LOCK_PREFIX
22643 READ_LOCK_SIZE(inc) (%__lock_ptr)
22644 +
22645 +#ifdef CONFIG_PAX_REFCOUNT
22646 + jno 1234f
22647 + LOCK_PREFIX
22648 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22649 + int $4
22650 +1234:
22651 + _ASM_EXTABLE(1234b, 1234b)
22652 +#endif
22653 +
22654 1: rep; nop
22655 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22656 js 1b
22657 LOCK_PREFIX
22658 READ_LOCK_SIZE(dec) (%__lock_ptr)
22659 +
22660 +#ifdef CONFIG_PAX_REFCOUNT
22661 + jno 1234f
22662 + LOCK_PREFIX
22663 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22664 + int $4
22665 +1234:
22666 + _ASM_EXTABLE(1234b, 1234b)
22667 +#endif
22668 +
22669 js 0b
22670 ENDFRAME
22671 + pax_force_retaddr
22672 ret
22673 CFI_ENDPROC
22674 END(__read_lock_failed)
22675 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22676 index 5dff5f0..cadebf4 100644
22677 --- a/arch/x86/lib/rwsem.S
22678 +++ b/arch/x86/lib/rwsem.S
22679 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22680 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22681 CFI_RESTORE __ASM_REG(dx)
22682 restore_common_regs
22683 + pax_force_retaddr
22684 ret
22685 CFI_ENDPROC
22686 ENDPROC(call_rwsem_down_read_failed)
22687 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22688 movq %rax,%rdi
22689 call rwsem_down_write_failed
22690 restore_common_regs
22691 + pax_force_retaddr
22692 ret
22693 CFI_ENDPROC
22694 ENDPROC(call_rwsem_down_write_failed)
22695 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22696 movq %rax,%rdi
22697 call rwsem_wake
22698 restore_common_regs
22699 -1: ret
22700 +1: pax_force_retaddr
22701 + ret
22702 CFI_ENDPROC
22703 ENDPROC(call_rwsem_wake)
22704
22705 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22706 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22707 CFI_RESTORE __ASM_REG(dx)
22708 restore_common_regs
22709 + pax_force_retaddr
22710 ret
22711 CFI_ENDPROC
22712 ENDPROC(call_rwsem_downgrade_wake)
22713 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22714 index a63efd6..ccecad8 100644
22715 --- a/arch/x86/lib/thunk_64.S
22716 +++ b/arch/x86/lib/thunk_64.S
22717 @@ -8,6 +8,7 @@
22718 #include <linux/linkage.h>
22719 #include <asm/dwarf2.h>
22720 #include <asm/calling.h>
22721 +#include <asm/alternative-asm.h>
22722
22723 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22724 .macro THUNK name, func, put_ret_addr_in_rdi=0
22725 @@ -41,5 +42,6 @@
22726 SAVE_ARGS
22727 restore:
22728 RESTORE_ARGS
22729 + pax_force_retaddr
22730 ret
22731 CFI_ENDPROC
22732 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22733 index 1781b2f..90368dd 100644
22734 --- a/arch/x86/lib/usercopy_32.c
22735 +++ b/arch/x86/lib/usercopy_32.c
22736 @@ -42,10 +42,12 @@ do { \
22737 int __d0; \
22738 might_fault(); \
22739 __asm__ __volatile__( \
22740 + __COPYUSER_SET_ES \
22741 "0: rep; stosl\n" \
22742 " movl %2,%0\n" \
22743 "1: rep; stosb\n" \
22744 "2:\n" \
22745 + __COPYUSER_RESTORE_ES \
22746 ".section .fixup,\"ax\"\n" \
22747 "3: lea 0(%2,%0,4),%0\n" \
22748 " jmp 2b\n" \
22749 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22750
22751 #ifdef CONFIG_X86_INTEL_USERCOPY
22752 static unsigned long
22753 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22754 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22755 {
22756 int d0, d1;
22757 __asm__ __volatile__(
22758 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22759 " .align 2,0x90\n"
22760 "3: movl 0(%4), %%eax\n"
22761 "4: movl 4(%4), %%edx\n"
22762 - "5: movl %%eax, 0(%3)\n"
22763 - "6: movl %%edx, 4(%3)\n"
22764 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22765 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22766 "7: movl 8(%4), %%eax\n"
22767 "8: movl 12(%4),%%edx\n"
22768 - "9: movl %%eax, 8(%3)\n"
22769 - "10: movl %%edx, 12(%3)\n"
22770 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22771 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22772 "11: movl 16(%4), %%eax\n"
22773 "12: movl 20(%4), %%edx\n"
22774 - "13: movl %%eax, 16(%3)\n"
22775 - "14: movl %%edx, 20(%3)\n"
22776 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22777 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22778 "15: movl 24(%4), %%eax\n"
22779 "16: movl 28(%4), %%edx\n"
22780 - "17: movl %%eax, 24(%3)\n"
22781 - "18: movl %%edx, 28(%3)\n"
22782 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22783 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22784 "19: movl 32(%4), %%eax\n"
22785 "20: movl 36(%4), %%edx\n"
22786 - "21: movl %%eax, 32(%3)\n"
22787 - "22: movl %%edx, 36(%3)\n"
22788 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22789 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22790 "23: movl 40(%4), %%eax\n"
22791 "24: movl 44(%4), %%edx\n"
22792 - "25: movl %%eax, 40(%3)\n"
22793 - "26: movl %%edx, 44(%3)\n"
22794 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22795 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22796 "27: movl 48(%4), %%eax\n"
22797 "28: movl 52(%4), %%edx\n"
22798 - "29: movl %%eax, 48(%3)\n"
22799 - "30: movl %%edx, 52(%3)\n"
22800 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22801 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22802 "31: movl 56(%4), %%eax\n"
22803 "32: movl 60(%4), %%edx\n"
22804 - "33: movl %%eax, 56(%3)\n"
22805 - "34: movl %%edx, 60(%3)\n"
22806 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22807 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22808 " addl $-64, %0\n"
22809 " addl $64, %4\n"
22810 " addl $64, %3\n"
22811 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22812 " shrl $2, %0\n"
22813 " andl $3, %%eax\n"
22814 " cld\n"
22815 + __COPYUSER_SET_ES
22816 "99: rep; movsl\n"
22817 "36: movl %%eax, %0\n"
22818 "37: rep; movsb\n"
22819 "100:\n"
22820 + __COPYUSER_RESTORE_ES
22821 ".section .fixup,\"ax\"\n"
22822 "101: lea 0(%%eax,%0,4),%0\n"
22823 " jmp 100b\n"
22824 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22825 }
22826
22827 static unsigned long
22828 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22829 +{
22830 + int d0, d1;
22831 + __asm__ __volatile__(
22832 + " .align 2,0x90\n"
22833 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22834 + " cmpl $67, %0\n"
22835 + " jbe 3f\n"
22836 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22837 + " .align 2,0x90\n"
22838 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22839 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22840 + "5: movl %%eax, 0(%3)\n"
22841 + "6: movl %%edx, 4(%3)\n"
22842 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22843 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22844 + "9: movl %%eax, 8(%3)\n"
22845 + "10: movl %%edx, 12(%3)\n"
22846 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22847 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22848 + "13: movl %%eax, 16(%3)\n"
22849 + "14: movl %%edx, 20(%3)\n"
22850 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22851 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22852 + "17: movl %%eax, 24(%3)\n"
22853 + "18: movl %%edx, 28(%3)\n"
22854 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22855 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22856 + "21: movl %%eax, 32(%3)\n"
22857 + "22: movl %%edx, 36(%3)\n"
22858 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22859 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22860 + "25: movl %%eax, 40(%3)\n"
22861 + "26: movl %%edx, 44(%3)\n"
22862 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22863 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22864 + "29: movl %%eax, 48(%3)\n"
22865 + "30: movl %%edx, 52(%3)\n"
22866 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22867 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22868 + "33: movl %%eax, 56(%3)\n"
22869 + "34: movl %%edx, 60(%3)\n"
22870 + " addl $-64, %0\n"
22871 + " addl $64, %4\n"
22872 + " addl $64, %3\n"
22873 + " cmpl $63, %0\n"
22874 + " ja 1b\n"
22875 + "35: movl %0, %%eax\n"
22876 + " shrl $2, %0\n"
22877 + " andl $3, %%eax\n"
22878 + " cld\n"
22879 + "99: rep; "__copyuser_seg" movsl\n"
22880 + "36: movl %%eax, %0\n"
22881 + "37: rep; "__copyuser_seg" movsb\n"
22882 + "100:\n"
22883 + ".section .fixup,\"ax\"\n"
22884 + "101: lea 0(%%eax,%0,4),%0\n"
22885 + " jmp 100b\n"
22886 + ".previous\n"
22887 + _ASM_EXTABLE(1b,100b)
22888 + _ASM_EXTABLE(2b,100b)
22889 + _ASM_EXTABLE(3b,100b)
22890 + _ASM_EXTABLE(4b,100b)
22891 + _ASM_EXTABLE(5b,100b)
22892 + _ASM_EXTABLE(6b,100b)
22893 + _ASM_EXTABLE(7b,100b)
22894 + _ASM_EXTABLE(8b,100b)
22895 + _ASM_EXTABLE(9b,100b)
22896 + _ASM_EXTABLE(10b,100b)
22897 + _ASM_EXTABLE(11b,100b)
22898 + _ASM_EXTABLE(12b,100b)
22899 + _ASM_EXTABLE(13b,100b)
22900 + _ASM_EXTABLE(14b,100b)
22901 + _ASM_EXTABLE(15b,100b)
22902 + _ASM_EXTABLE(16b,100b)
22903 + _ASM_EXTABLE(17b,100b)
22904 + _ASM_EXTABLE(18b,100b)
22905 + _ASM_EXTABLE(19b,100b)
22906 + _ASM_EXTABLE(20b,100b)
22907 + _ASM_EXTABLE(21b,100b)
22908 + _ASM_EXTABLE(22b,100b)
22909 + _ASM_EXTABLE(23b,100b)
22910 + _ASM_EXTABLE(24b,100b)
22911 + _ASM_EXTABLE(25b,100b)
22912 + _ASM_EXTABLE(26b,100b)
22913 + _ASM_EXTABLE(27b,100b)
22914 + _ASM_EXTABLE(28b,100b)
22915 + _ASM_EXTABLE(29b,100b)
22916 + _ASM_EXTABLE(30b,100b)
22917 + _ASM_EXTABLE(31b,100b)
22918 + _ASM_EXTABLE(32b,100b)
22919 + _ASM_EXTABLE(33b,100b)
22920 + _ASM_EXTABLE(34b,100b)
22921 + _ASM_EXTABLE(35b,100b)
22922 + _ASM_EXTABLE(36b,100b)
22923 + _ASM_EXTABLE(37b,100b)
22924 + _ASM_EXTABLE(99b,101b)
22925 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22926 + : "1"(to), "2"(from), "0"(size)
22927 + : "eax", "edx", "memory");
22928 + return size;
22929 +}
22930 +
22931 +static unsigned long __size_overflow(3)
22932 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22933 {
22934 int d0, d1;
22935 __asm__ __volatile__(
22936 " .align 2,0x90\n"
22937 - "0: movl 32(%4), %%eax\n"
22938 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22939 " cmpl $67, %0\n"
22940 " jbe 2f\n"
22941 - "1: movl 64(%4), %%eax\n"
22942 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22943 " .align 2,0x90\n"
22944 - "2: movl 0(%4), %%eax\n"
22945 - "21: movl 4(%4), %%edx\n"
22946 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22947 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22948 " movl %%eax, 0(%3)\n"
22949 " movl %%edx, 4(%3)\n"
22950 - "3: movl 8(%4), %%eax\n"
22951 - "31: movl 12(%4),%%edx\n"
22952 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22953 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22954 " movl %%eax, 8(%3)\n"
22955 " movl %%edx, 12(%3)\n"
22956 - "4: movl 16(%4), %%eax\n"
22957 - "41: movl 20(%4), %%edx\n"
22958 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22959 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22960 " movl %%eax, 16(%3)\n"
22961 " movl %%edx, 20(%3)\n"
22962 - "10: movl 24(%4), %%eax\n"
22963 - "51: movl 28(%4), %%edx\n"
22964 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22965 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22966 " movl %%eax, 24(%3)\n"
22967 " movl %%edx, 28(%3)\n"
22968 - "11: movl 32(%4), %%eax\n"
22969 - "61: movl 36(%4), %%edx\n"
22970 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22971 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22972 " movl %%eax, 32(%3)\n"
22973 " movl %%edx, 36(%3)\n"
22974 - "12: movl 40(%4), %%eax\n"
22975 - "71: movl 44(%4), %%edx\n"
22976 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22977 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22978 " movl %%eax, 40(%3)\n"
22979 " movl %%edx, 44(%3)\n"
22980 - "13: movl 48(%4), %%eax\n"
22981 - "81: movl 52(%4), %%edx\n"
22982 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22983 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22984 " movl %%eax, 48(%3)\n"
22985 " movl %%edx, 52(%3)\n"
22986 - "14: movl 56(%4), %%eax\n"
22987 - "91: movl 60(%4), %%edx\n"
22988 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22989 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22990 " movl %%eax, 56(%3)\n"
22991 " movl %%edx, 60(%3)\n"
22992 " addl $-64, %0\n"
22993 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22994 " shrl $2, %0\n"
22995 " andl $3, %%eax\n"
22996 " cld\n"
22997 - "6: rep; movsl\n"
22998 + "6: rep; "__copyuser_seg" movsl\n"
22999 " movl %%eax,%0\n"
23000 - "7: rep; movsb\n"
23001 + "7: rep; "__copyuser_seg" movsb\n"
23002 "8:\n"
23003 ".section .fixup,\"ax\"\n"
23004 "9: lea 0(%%eax,%0,4),%0\n"
23005 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23006 * hyoshiok@miraclelinux.com
23007 */
23008
23009 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23010 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23011 const void __user *from, unsigned long size)
23012 {
23013 int d0, d1;
23014
23015 __asm__ __volatile__(
23016 " .align 2,0x90\n"
23017 - "0: movl 32(%4), %%eax\n"
23018 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23019 " cmpl $67, %0\n"
23020 " jbe 2f\n"
23021 - "1: movl 64(%4), %%eax\n"
23022 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23023 " .align 2,0x90\n"
23024 - "2: movl 0(%4), %%eax\n"
23025 - "21: movl 4(%4), %%edx\n"
23026 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23027 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23028 " movnti %%eax, 0(%3)\n"
23029 " movnti %%edx, 4(%3)\n"
23030 - "3: movl 8(%4), %%eax\n"
23031 - "31: movl 12(%4),%%edx\n"
23032 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23033 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23034 " movnti %%eax, 8(%3)\n"
23035 " movnti %%edx, 12(%3)\n"
23036 - "4: movl 16(%4), %%eax\n"
23037 - "41: movl 20(%4), %%edx\n"
23038 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23039 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23040 " movnti %%eax, 16(%3)\n"
23041 " movnti %%edx, 20(%3)\n"
23042 - "10: movl 24(%4), %%eax\n"
23043 - "51: movl 28(%4), %%edx\n"
23044 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23045 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23046 " movnti %%eax, 24(%3)\n"
23047 " movnti %%edx, 28(%3)\n"
23048 - "11: movl 32(%4), %%eax\n"
23049 - "61: movl 36(%4), %%edx\n"
23050 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23051 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23052 " movnti %%eax, 32(%3)\n"
23053 " movnti %%edx, 36(%3)\n"
23054 - "12: movl 40(%4), %%eax\n"
23055 - "71: movl 44(%4), %%edx\n"
23056 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23057 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23058 " movnti %%eax, 40(%3)\n"
23059 " movnti %%edx, 44(%3)\n"
23060 - "13: movl 48(%4), %%eax\n"
23061 - "81: movl 52(%4), %%edx\n"
23062 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23063 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23064 " movnti %%eax, 48(%3)\n"
23065 " movnti %%edx, 52(%3)\n"
23066 - "14: movl 56(%4), %%eax\n"
23067 - "91: movl 60(%4), %%edx\n"
23068 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23069 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23070 " movnti %%eax, 56(%3)\n"
23071 " movnti %%edx, 60(%3)\n"
23072 " addl $-64, %0\n"
23073 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23074 " shrl $2, %0\n"
23075 " andl $3, %%eax\n"
23076 " cld\n"
23077 - "6: rep; movsl\n"
23078 + "6: rep; "__copyuser_seg" movsl\n"
23079 " movl %%eax,%0\n"
23080 - "7: rep; movsb\n"
23081 + "7: rep; "__copyuser_seg" movsb\n"
23082 "8:\n"
23083 ".section .fixup,\"ax\"\n"
23084 "9: lea 0(%%eax,%0,4),%0\n"
23085 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23086 return size;
23087 }
23088
23089 -static unsigned long __copy_user_intel_nocache(void *to,
23090 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23091 const void __user *from, unsigned long size)
23092 {
23093 int d0, d1;
23094
23095 __asm__ __volatile__(
23096 " .align 2,0x90\n"
23097 - "0: movl 32(%4), %%eax\n"
23098 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23099 " cmpl $67, %0\n"
23100 " jbe 2f\n"
23101 - "1: movl 64(%4), %%eax\n"
23102 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23103 " .align 2,0x90\n"
23104 - "2: movl 0(%4), %%eax\n"
23105 - "21: movl 4(%4), %%edx\n"
23106 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23107 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23108 " movnti %%eax, 0(%3)\n"
23109 " movnti %%edx, 4(%3)\n"
23110 - "3: movl 8(%4), %%eax\n"
23111 - "31: movl 12(%4),%%edx\n"
23112 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23113 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23114 " movnti %%eax, 8(%3)\n"
23115 " movnti %%edx, 12(%3)\n"
23116 - "4: movl 16(%4), %%eax\n"
23117 - "41: movl 20(%4), %%edx\n"
23118 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23119 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23120 " movnti %%eax, 16(%3)\n"
23121 " movnti %%edx, 20(%3)\n"
23122 - "10: movl 24(%4), %%eax\n"
23123 - "51: movl 28(%4), %%edx\n"
23124 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23125 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23126 " movnti %%eax, 24(%3)\n"
23127 " movnti %%edx, 28(%3)\n"
23128 - "11: movl 32(%4), %%eax\n"
23129 - "61: movl 36(%4), %%edx\n"
23130 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23131 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23132 " movnti %%eax, 32(%3)\n"
23133 " movnti %%edx, 36(%3)\n"
23134 - "12: movl 40(%4), %%eax\n"
23135 - "71: movl 44(%4), %%edx\n"
23136 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23137 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23138 " movnti %%eax, 40(%3)\n"
23139 " movnti %%edx, 44(%3)\n"
23140 - "13: movl 48(%4), %%eax\n"
23141 - "81: movl 52(%4), %%edx\n"
23142 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23143 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23144 " movnti %%eax, 48(%3)\n"
23145 " movnti %%edx, 52(%3)\n"
23146 - "14: movl 56(%4), %%eax\n"
23147 - "91: movl 60(%4), %%edx\n"
23148 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23149 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23150 " movnti %%eax, 56(%3)\n"
23151 " movnti %%edx, 60(%3)\n"
23152 " addl $-64, %0\n"
23153 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23154 " shrl $2, %0\n"
23155 " andl $3, %%eax\n"
23156 " cld\n"
23157 - "6: rep; movsl\n"
23158 + "6: rep; "__copyuser_seg" movsl\n"
23159 " movl %%eax,%0\n"
23160 - "7: rep; movsb\n"
23161 + "7: rep; "__copyuser_seg" movsb\n"
23162 "8:\n"
23163 ".section .fixup,\"ax\"\n"
23164 "9: lea 0(%%eax,%0,4),%0\n"
23165 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23166 */
23167 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23168 unsigned long size);
23169 -unsigned long __copy_user_intel(void __user *to, const void *from,
23170 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23171 + unsigned long size);
23172 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23173 unsigned long size);
23174 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23175 const void __user *from, unsigned long size);
23176 #endif /* CONFIG_X86_INTEL_USERCOPY */
23177
23178 /* Generic arbitrary sized copy. */
23179 -#define __copy_user(to, from, size) \
23180 +#define __copy_user(to, from, size, prefix, set, restore) \
23181 do { \
23182 int __d0, __d1, __d2; \
23183 __asm__ __volatile__( \
23184 + set \
23185 " cmp $7,%0\n" \
23186 " jbe 1f\n" \
23187 " movl %1,%0\n" \
23188 " negl %0\n" \
23189 " andl $7,%0\n" \
23190 " subl %0,%3\n" \
23191 - "4: rep; movsb\n" \
23192 + "4: rep; "prefix"movsb\n" \
23193 " movl %3,%0\n" \
23194 " shrl $2,%0\n" \
23195 " andl $3,%3\n" \
23196 " .align 2,0x90\n" \
23197 - "0: rep; movsl\n" \
23198 + "0: rep; "prefix"movsl\n" \
23199 " movl %3,%0\n" \
23200 - "1: rep; movsb\n" \
23201 + "1: rep; "prefix"movsb\n" \
23202 "2:\n" \
23203 + restore \
23204 ".section .fixup,\"ax\"\n" \
23205 "5: addl %3,%0\n" \
23206 " jmp 2b\n" \
23207 @@ -537,14 +649,14 @@ do { \
23208 " negl %0\n" \
23209 " andl $7,%0\n" \
23210 " subl %0,%3\n" \
23211 - "4: rep; movsb\n" \
23212 + "4: rep; "__copyuser_seg"movsb\n" \
23213 " movl %3,%0\n" \
23214 " shrl $2,%0\n" \
23215 " andl $3,%3\n" \
23216 " .align 2,0x90\n" \
23217 - "0: rep; movsl\n" \
23218 + "0: rep; "__copyuser_seg"movsl\n" \
23219 " movl %3,%0\n" \
23220 - "1: rep; movsb\n" \
23221 + "1: rep; "__copyuser_seg"movsb\n" \
23222 "2:\n" \
23223 ".section .fixup,\"ax\"\n" \
23224 "5: addl %3,%0\n" \
23225 @@ -627,9 +739,9 @@ survive:
23226 }
23227 #endif
23228 if (movsl_is_ok(to, from, n))
23229 - __copy_user(to, from, n);
23230 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23231 else
23232 - n = __copy_user_intel(to, from, n);
23233 + n = __generic_copy_to_user_intel(to, from, n);
23234 return n;
23235 }
23236 EXPORT_SYMBOL(__copy_to_user_ll);
23237 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23238 unsigned long n)
23239 {
23240 if (movsl_is_ok(to, from, n))
23241 - __copy_user(to, from, n);
23242 + __copy_user(to, from, n, __copyuser_seg, "", "");
23243 else
23244 - n = __copy_user_intel((void __user *)to,
23245 - (const void *)from, n);
23246 + n = __generic_copy_from_user_intel(to, from, n);
23247 return n;
23248 }
23249 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23250 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23251 if (n > 64 && cpu_has_xmm2)
23252 n = __copy_user_intel_nocache(to, from, n);
23253 else
23254 - __copy_user(to, from, n);
23255 + __copy_user(to, from, n, __copyuser_seg, "", "");
23256 #else
23257 - __copy_user(to, from, n);
23258 + __copy_user(to, from, n, __copyuser_seg, "", "");
23259 #endif
23260 return n;
23261 }
23262 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23263
23264 -/**
23265 - * copy_to_user: - Copy a block of data into user space.
23266 - * @to: Destination address, in user space.
23267 - * @from: Source address, in kernel space.
23268 - * @n: Number of bytes to copy.
23269 - *
23270 - * Context: User context only. This function may sleep.
23271 - *
23272 - * Copy data from kernel space to user space.
23273 - *
23274 - * Returns number of bytes that could not be copied.
23275 - * On success, this will be zero.
23276 - */
23277 -unsigned long
23278 -copy_to_user(void __user *to, const void *from, unsigned long n)
23279 -{
23280 - if (access_ok(VERIFY_WRITE, to, n))
23281 - n = __copy_to_user(to, from, n);
23282 - return n;
23283 -}
23284 -EXPORT_SYMBOL(copy_to_user);
23285 -
23286 -/**
23287 - * copy_from_user: - Copy a block of data from user space.
23288 - * @to: Destination address, in kernel space.
23289 - * @from: Source address, in user space.
23290 - * @n: Number of bytes to copy.
23291 - *
23292 - * Context: User context only. This function may sleep.
23293 - *
23294 - * Copy data from user space to kernel space.
23295 - *
23296 - * Returns number of bytes that could not be copied.
23297 - * On success, this will be zero.
23298 - *
23299 - * If some data could not be copied, this function will pad the copied
23300 - * data to the requested size using zero bytes.
23301 - */
23302 -unsigned long
23303 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23304 -{
23305 - if (access_ok(VERIFY_READ, from, n))
23306 - n = __copy_from_user(to, from, n);
23307 - else
23308 - memset(to, 0, n);
23309 - return n;
23310 -}
23311 -EXPORT_SYMBOL(_copy_from_user);
23312 -
23313 void copy_from_user_overflow(void)
23314 {
23315 WARN(1, "Buffer overflow detected!\n");
23316 }
23317 EXPORT_SYMBOL(copy_from_user_overflow);
23318 +
23319 +void copy_to_user_overflow(void)
23320 +{
23321 + WARN(1, "Buffer overflow detected!\n");
23322 +}
23323 +EXPORT_SYMBOL(copy_to_user_overflow);
23324 +
23325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23326 +void __set_fs(mm_segment_t x)
23327 +{
23328 + switch (x.seg) {
23329 + case 0:
23330 + loadsegment(gs, 0);
23331 + break;
23332 + case TASK_SIZE_MAX:
23333 + loadsegment(gs, __USER_DS);
23334 + break;
23335 + case -1UL:
23336 + loadsegment(gs, __KERNEL_DS);
23337 + break;
23338 + default:
23339 + BUG();
23340 + }
23341 + return;
23342 +}
23343 +EXPORT_SYMBOL(__set_fs);
23344 +
23345 +void set_fs(mm_segment_t x)
23346 +{
23347 + current_thread_info()->addr_limit = x;
23348 + __set_fs(x);
23349 +}
23350 +EXPORT_SYMBOL(set_fs);
23351 +#endif
23352 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23353 index e5b130b..6690d31 100644
23354 --- a/arch/x86/lib/usercopy_64.c
23355 +++ b/arch/x86/lib/usercopy_64.c
23356 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23357 {
23358 long __d0;
23359 might_fault();
23360 +
23361 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23362 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23363 + addr += PAX_USER_SHADOW_BASE;
23364 +#endif
23365 +
23366 /* no memory constraint because it doesn't change any memory gcc knows
23367 about */
23368 asm volatile(
23369 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23370 }
23371 EXPORT_SYMBOL(clear_user);
23372
23373 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23374 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23375 {
23376 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23377 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23378 - }
23379 - return len;
23380 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23381 +
23382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23383 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23384 + to += PAX_USER_SHADOW_BASE;
23385 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23386 + from += PAX_USER_SHADOW_BASE;
23387 +#endif
23388 +
23389 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23390 + }
23391 + return len;
23392 }
23393 EXPORT_SYMBOL(copy_in_user);
23394
23395 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23396 * it is not necessary to optimize tail handling.
23397 */
23398 unsigned long
23399 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23400 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23401 {
23402 char c;
23403 unsigned zero_len;
23404 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23405 break;
23406 return len;
23407 }
23408 +
23409 +void copy_from_user_overflow(void)
23410 +{
23411 + WARN(1, "Buffer overflow detected!\n");
23412 +}
23413 +EXPORT_SYMBOL(copy_from_user_overflow);
23414 +
23415 +void copy_to_user_overflow(void)
23416 +{
23417 + WARN(1, "Buffer overflow detected!\n");
23418 +}
23419 +EXPORT_SYMBOL(copy_to_user_overflow);
23420 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23421 index 903ec1e..c4166b2 100644
23422 --- a/arch/x86/mm/extable.c
23423 +++ b/arch/x86/mm/extable.c
23424 @@ -6,12 +6,24 @@
23425 static inline unsigned long
23426 ex_insn_addr(const struct exception_table_entry *x)
23427 {
23428 - return (unsigned long)&x->insn + x->insn;
23429 + unsigned long reloc = 0;
23430 +
23431 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23432 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23433 +#endif
23434 +
23435 + return (unsigned long)&x->insn + x->insn + reloc;
23436 }
23437 static inline unsigned long
23438 ex_fixup_addr(const struct exception_table_entry *x)
23439 {
23440 - return (unsigned long)&x->fixup + x->fixup;
23441 + unsigned long reloc = 0;
23442 +
23443 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23444 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23445 +#endif
23446 +
23447 + return (unsigned long)&x->fixup + x->fixup + reloc;
23448 }
23449
23450 int fixup_exception(struct pt_regs *regs)
23451 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23452 unsigned long new_ip;
23453
23454 #ifdef CONFIG_PNPBIOS
23455 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23456 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23457 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23458 extern u32 pnp_bios_is_utter_crap;
23459 pnp_bios_is_utter_crap = 1;
23460 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23461 i += 4;
23462 p->fixup -= i;
23463 i += 4;
23464 +
23465 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23466 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23467 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23468 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23469 +#endif
23470 +
23471 }
23472 }
23473
23474 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23475 index 76dcd9d..e9dffde 100644
23476 --- a/arch/x86/mm/fault.c
23477 +++ b/arch/x86/mm/fault.c
23478 @@ -13,11 +13,18 @@
23479 #include <linux/perf_event.h> /* perf_sw_event */
23480 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23481 #include <linux/prefetch.h> /* prefetchw */
23482 +#include <linux/unistd.h>
23483 +#include <linux/compiler.h>
23484
23485 #include <asm/traps.h> /* dotraplinkage, ... */
23486 #include <asm/pgalloc.h> /* pgd_*(), ... */
23487 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23488 #include <asm/fixmap.h> /* VSYSCALL_START */
23489 +#include <asm/tlbflush.h>
23490 +
23491 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23492 +#include <asm/stacktrace.h>
23493 +#endif
23494
23495 /*
23496 * Page fault error code bits:
23497 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23498 int ret = 0;
23499
23500 /* kprobe_running() needs smp_processor_id() */
23501 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23502 + if (kprobes_built_in() && !user_mode(regs)) {
23503 preempt_disable();
23504 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23505 ret = 1;
23506 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23507 return !instr_lo || (instr_lo>>1) == 1;
23508 case 0x00:
23509 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23510 - if (probe_kernel_address(instr, opcode))
23511 + if (user_mode(regs)) {
23512 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23513 + return 0;
23514 + } else if (probe_kernel_address(instr, opcode))
23515 return 0;
23516
23517 *prefetch = (instr_lo == 0xF) &&
23518 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23519 while (instr < max_instr) {
23520 unsigned char opcode;
23521
23522 - if (probe_kernel_address(instr, opcode))
23523 + if (user_mode(regs)) {
23524 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23525 + break;
23526 + } else if (probe_kernel_address(instr, opcode))
23527 break;
23528
23529 instr++;
23530 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23531 force_sig_info(si_signo, &info, tsk);
23532 }
23533
23534 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23535 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23536 +#endif
23537 +
23538 +#ifdef CONFIG_PAX_EMUTRAMP
23539 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23540 +#endif
23541 +
23542 +#ifdef CONFIG_PAX_PAGEEXEC
23543 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23544 +{
23545 + pgd_t *pgd;
23546 + pud_t *pud;
23547 + pmd_t *pmd;
23548 +
23549 + pgd = pgd_offset(mm, address);
23550 + if (!pgd_present(*pgd))
23551 + return NULL;
23552 + pud = pud_offset(pgd, address);
23553 + if (!pud_present(*pud))
23554 + return NULL;
23555 + pmd = pmd_offset(pud, address);
23556 + if (!pmd_present(*pmd))
23557 + return NULL;
23558 + return pmd;
23559 +}
23560 +#endif
23561 +
23562 DEFINE_SPINLOCK(pgd_lock);
23563 LIST_HEAD(pgd_list);
23564
23565 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23566 for (address = VMALLOC_START & PMD_MASK;
23567 address >= TASK_SIZE && address < FIXADDR_TOP;
23568 address += PMD_SIZE) {
23569 +
23570 +#ifdef CONFIG_PAX_PER_CPU_PGD
23571 + unsigned long cpu;
23572 +#else
23573 struct page *page;
23574 +#endif
23575
23576 spin_lock(&pgd_lock);
23577 +
23578 +#ifdef CONFIG_PAX_PER_CPU_PGD
23579 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23580 + pgd_t *pgd = get_cpu_pgd(cpu);
23581 + pmd_t *ret;
23582 +#else
23583 list_for_each_entry(page, &pgd_list, lru) {
23584 + pgd_t *pgd = page_address(page);
23585 spinlock_t *pgt_lock;
23586 pmd_t *ret;
23587
23588 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23589 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23590
23591 spin_lock(pgt_lock);
23592 - ret = vmalloc_sync_one(page_address(page), address);
23593 +#endif
23594 +
23595 + ret = vmalloc_sync_one(pgd, address);
23596 +
23597 +#ifndef CONFIG_PAX_PER_CPU_PGD
23598 spin_unlock(pgt_lock);
23599 +#endif
23600
23601 if (!ret)
23602 break;
23603 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23604 * an interrupt in the middle of a task switch..
23605 */
23606 pgd_paddr = read_cr3();
23607 +
23608 +#ifdef CONFIG_PAX_PER_CPU_PGD
23609 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23610 +#endif
23611 +
23612 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23613 if (!pmd_k)
23614 return -1;
23615 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23616 * happen within a race in page table update. In the later
23617 * case just flush:
23618 */
23619 +
23620 +#ifdef CONFIG_PAX_PER_CPU_PGD
23621 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23622 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23623 +#else
23624 pgd = pgd_offset(current->active_mm, address);
23625 +#endif
23626 +
23627 pgd_ref = pgd_offset_k(address);
23628 if (pgd_none(*pgd_ref))
23629 return -1;
23630 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23631 static int is_errata100(struct pt_regs *regs, unsigned long address)
23632 {
23633 #ifdef CONFIG_X86_64
23634 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23635 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23636 return 1;
23637 #endif
23638 return 0;
23639 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23640 }
23641
23642 static const char nx_warning[] = KERN_CRIT
23643 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23644 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23645
23646 static void
23647 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23648 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23649 if (!oops_may_print())
23650 return;
23651
23652 - if (error_code & PF_INSTR) {
23653 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23654 unsigned int level;
23655
23656 pte_t *pte = lookup_address(address, &level);
23657
23658 if (pte && pte_present(*pte) && !pte_exec(*pte))
23659 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23660 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23661 }
23662
23663 +#ifdef CONFIG_PAX_KERNEXEC
23664 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23665 + if (current->signal->curr_ip)
23666 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23667 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23668 + else
23669 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23670 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23671 + }
23672 +#endif
23673 +
23674 printk(KERN_ALERT "BUG: unable to handle kernel ");
23675 if (address < PAGE_SIZE)
23676 printk(KERN_CONT "NULL pointer dereference");
23677 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23678 }
23679 #endif
23680
23681 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23682 + if (pax_is_fetch_fault(regs, error_code, address)) {
23683 +
23684 +#ifdef CONFIG_PAX_EMUTRAMP
23685 + switch (pax_handle_fetch_fault(regs)) {
23686 + case 2:
23687 + return;
23688 + }
23689 +#endif
23690 +
23691 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23692 + do_group_exit(SIGKILL);
23693 + }
23694 +#endif
23695 +
23696 if (unlikely(show_unhandled_signals))
23697 show_signal_msg(regs, error_code, address, tsk);
23698
23699 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23700 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23701 printk(KERN_ERR
23702 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23703 - tsk->comm, tsk->pid, address);
23704 + tsk->comm, task_pid_nr(tsk), address);
23705 code = BUS_MCEERR_AR;
23706 }
23707 #endif
23708 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23709 return 1;
23710 }
23711
23712 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23713 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23714 +{
23715 + pte_t *pte;
23716 + pmd_t *pmd;
23717 + spinlock_t *ptl;
23718 + unsigned char pte_mask;
23719 +
23720 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23721 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23722 + return 0;
23723 +
23724 + /* PaX: it's our fault, let's handle it if we can */
23725 +
23726 + /* PaX: take a look at read faults before acquiring any locks */
23727 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23728 + /* instruction fetch attempt from a protected page in user mode */
23729 + up_read(&mm->mmap_sem);
23730 +
23731 +#ifdef CONFIG_PAX_EMUTRAMP
23732 + switch (pax_handle_fetch_fault(regs)) {
23733 + case 2:
23734 + return 1;
23735 + }
23736 +#endif
23737 +
23738 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23739 + do_group_exit(SIGKILL);
23740 + }
23741 +
23742 + pmd = pax_get_pmd(mm, address);
23743 + if (unlikely(!pmd))
23744 + return 0;
23745 +
23746 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23747 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23748 + pte_unmap_unlock(pte, ptl);
23749 + return 0;
23750 + }
23751 +
23752 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23753 + /* write attempt to a protected page in user mode */
23754 + pte_unmap_unlock(pte, ptl);
23755 + return 0;
23756 + }
23757 +
23758 +#ifdef CONFIG_SMP
23759 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23760 +#else
23761 + if (likely(address > get_limit(regs->cs)))
23762 +#endif
23763 + {
23764 + set_pte(pte, pte_mkread(*pte));
23765 + __flush_tlb_one(address);
23766 + pte_unmap_unlock(pte, ptl);
23767 + up_read(&mm->mmap_sem);
23768 + return 1;
23769 + }
23770 +
23771 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23772 +
23773 + /*
23774 + * PaX: fill DTLB with user rights and retry
23775 + */
23776 + __asm__ __volatile__ (
23777 + "orb %2,(%1)\n"
23778 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23779 +/*
23780 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23781 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23782 + * page fault when examined during a TLB load attempt. this is true not only
23783 + * for PTEs holding a non-present entry but also present entries that will
23784 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23785 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23786 + * for our target pages since their PTEs are simply not in the TLBs at all.
23787 +
23788 + * the best thing in omitting it is that we gain around 15-20% speed in the
23789 + * fast path of the page fault handler and can get rid of tracing since we
23790 + * can no longer flush unintended entries.
23791 + */
23792 + "invlpg (%0)\n"
23793 +#endif
23794 + __copyuser_seg"testb $0,(%0)\n"
23795 + "xorb %3,(%1)\n"
23796 + :
23797 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23798 + : "memory", "cc");
23799 + pte_unmap_unlock(pte, ptl);
23800 + up_read(&mm->mmap_sem);
23801 + return 1;
23802 +}
23803 +#endif
23804 +
23805 /*
23806 * Handle a spurious fault caused by a stale TLB entry.
23807 *
23808 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23809 static inline int
23810 access_error(unsigned long error_code, struct vm_area_struct *vma)
23811 {
23812 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23813 + return 1;
23814 +
23815 if (error_code & PF_WRITE) {
23816 /* write, present and write, not present: */
23817 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23818 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23819 {
23820 struct vm_area_struct *vma;
23821 struct task_struct *tsk;
23822 - unsigned long address;
23823 struct mm_struct *mm;
23824 int fault;
23825 int write = error_code & PF_WRITE;
23826 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23827 (write ? FAULT_FLAG_WRITE : 0);
23828
23829 - tsk = current;
23830 - mm = tsk->mm;
23831 -
23832 /* Get the faulting address: */
23833 - address = read_cr2();
23834 + unsigned long address = read_cr2();
23835 +
23836 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23837 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23838 + if (!search_exception_tables(regs->ip)) {
23839 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23840 + bad_area_nosemaphore(regs, error_code, address);
23841 + return;
23842 + }
23843 + if (address < PAX_USER_SHADOW_BASE) {
23844 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23845 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23846 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23847 + } else
23848 + address -= PAX_USER_SHADOW_BASE;
23849 + }
23850 +#endif
23851 +
23852 + tsk = current;
23853 + mm = tsk->mm;
23854
23855 /*
23856 * Detect and handle instructions that would cause a page fault for
23857 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23858 * User-mode registers count as a user access even for any
23859 * potential system fault or CPU buglet:
23860 */
23861 - if (user_mode_vm(regs)) {
23862 + if (user_mode(regs)) {
23863 local_irq_enable();
23864 error_code |= PF_USER;
23865 } else {
23866 @@ -1132,6 +1339,11 @@ retry:
23867 might_sleep();
23868 }
23869
23870 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23871 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23872 + return;
23873 +#endif
23874 +
23875 vma = find_vma(mm, address);
23876 if (unlikely(!vma)) {
23877 bad_area(regs, error_code, address);
23878 @@ -1143,18 +1355,24 @@ retry:
23879 bad_area(regs, error_code, address);
23880 return;
23881 }
23882 - if (error_code & PF_USER) {
23883 - /*
23884 - * Accessing the stack below %sp is always a bug.
23885 - * The large cushion allows instructions like enter
23886 - * and pusha to work. ("enter $65535, $31" pushes
23887 - * 32 pointers and then decrements %sp by 65535.)
23888 - */
23889 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23890 - bad_area(regs, error_code, address);
23891 - return;
23892 - }
23893 + /*
23894 + * Accessing the stack below %sp is always a bug.
23895 + * The large cushion allows instructions like enter
23896 + * and pusha to work. ("enter $65535, $31" pushes
23897 + * 32 pointers and then decrements %sp by 65535.)
23898 + */
23899 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23900 + bad_area(regs, error_code, address);
23901 + return;
23902 }
23903 +
23904 +#ifdef CONFIG_PAX_SEGMEXEC
23905 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23906 + bad_area(regs, error_code, address);
23907 + return;
23908 + }
23909 +#endif
23910 +
23911 if (unlikely(expand_stack(vma, address))) {
23912 bad_area(regs, error_code, address);
23913 return;
23914 @@ -1209,3 +1427,292 @@ good_area:
23915
23916 up_read(&mm->mmap_sem);
23917 }
23918 +
23919 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23920 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23921 +{
23922 + struct mm_struct *mm = current->mm;
23923 + unsigned long ip = regs->ip;
23924 +
23925 + if (v8086_mode(regs))
23926 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23927 +
23928 +#ifdef CONFIG_PAX_PAGEEXEC
23929 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23930 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23931 + return true;
23932 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23933 + return true;
23934 + return false;
23935 + }
23936 +#endif
23937 +
23938 +#ifdef CONFIG_PAX_SEGMEXEC
23939 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23940 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23941 + return true;
23942 + return false;
23943 + }
23944 +#endif
23945 +
23946 + return false;
23947 +}
23948 +#endif
23949 +
23950 +#ifdef CONFIG_PAX_EMUTRAMP
23951 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23952 +{
23953 + int err;
23954 +
23955 + do { /* PaX: libffi trampoline emulation */
23956 + unsigned char mov, jmp;
23957 + unsigned int addr1, addr2;
23958 +
23959 +#ifdef CONFIG_X86_64
23960 + if ((regs->ip + 9) >> 32)
23961 + break;
23962 +#endif
23963 +
23964 + err = get_user(mov, (unsigned char __user *)regs->ip);
23965 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23966 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23967 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23968 +
23969 + if (err)
23970 + break;
23971 +
23972 + if (mov == 0xB8 && jmp == 0xE9) {
23973 + regs->ax = addr1;
23974 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23975 + return 2;
23976 + }
23977 + } while (0);
23978 +
23979 + do { /* PaX: gcc trampoline emulation #1 */
23980 + unsigned char mov1, mov2;
23981 + unsigned short jmp;
23982 + unsigned int addr1, addr2;
23983 +
23984 +#ifdef CONFIG_X86_64
23985 + if ((regs->ip + 11) >> 32)
23986 + break;
23987 +#endif
23988 +
23989 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23990 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23991 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23992 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23993 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23994 +
23995 + if (err)
23996 + break;
23997 +
23998 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23999 + regs->cx = addr1;
24000 + regs->ax = addr2;
24001 + regs->ip = addr2;
24002 + return 2;
24003 + }
24004 + } while (0);
24005 +
24006 + do { /* PaX: gcc trampoline emulation #2 */
24007 + unsigned char mov, jmp;
24008 + unsigned int addr1, addr2;
24009 +
24010 +#ifdef CONFIG_X86_64
24011 + if ((regs->ip + 9) >> 32)
24012 + break;
24013 +#endif
24014 +
24015 + err = get_user(mov, (unsigned char __user *)regs->ip);
24016 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24017 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24018 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24019 +
24020 + if (err)
24021 + break;
24022 +
24023 + if (mov == 0xB9 && jmp == 0xE9) {
24024 + regs->cx = addr1;
24025 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24026 + return 2;
24027 + }
24028 + } while (0);
24029 +
24030 + return 1; /* PaX in action */
24031 +}
24032 +
24033 +#ifdef CONFIG_X86_64
24034 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24035 +{
24036 + int err;
24037 +
24038 + do { /* PaX: libffi trampoline emulation */
24039 + unsigned short mov1, mov2, jmp1;
24040 + unsigned char stcclc, jmp2;
24041 + unsigned long addr1, addr2;
24042 +
24043 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24044 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24045 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24046 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24047 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24048 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24049 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24050 +
24051 + if (err)
24052 + break;
24053 +
24054 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24055 + regs->r11 = addr1;
24056 + regs->r10 = addr2;
24057 + if (stcclc == 0xF8)
24058 + regs->flags &= ~X86_EFLAGS_CF;
24059 + else
24060 + regs->flags |= X86_EFLAGS_CF;
24061 + regs->ip = addr1;
24062 + return 2;
24063 + }
24064 + } while (0);
24065 +
24066 + do { /* PaX: gcc trampoline emulation #1 */
24067 + unsigned short mov1, mov2, jmp1;
24068 + unsigned char jmp2;
24069 + unsigned int addr1;
24070 + unsigned long addr2;
24071 +
24072 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24073 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24074 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24075 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24076 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24077 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24078 +
24079 + if (err)
24080 + break;
24081 +
24082 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24083 + regs->r11 = addr1;
24084 + regs->r10 = addr2;
24085 + regs->ip = addr1;
24086 + return 2;
24087 + }
24088 + } while (0);
24089 +
24090 + do { /* PaX: gcc trampoline emulation #2 */
24091 + unsigned short mov1, mov2, jmp1;
24092 + unsigned char jmp2;
24093 + unsigned long addr1, addr2;
24094 +
24095 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24096 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24097 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24098 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24099 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24100 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24101 +
24102 + if (err)
24103 + break;
24104 +
24105 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24106 + regs->r11 = addr1;
24107 + regs->r10 = addr2;
24108 + regs->ip = addr1;
24109 + return 2;
24110 + }
24111 + } while (0);
24112 +
24113 + return 1; /* PaX in action */
24114 +}
24115 +#endif
24116 +
24117 +/*
24118 + * PaX: decide what to do with offenders (regs->ip = fault address)
24119 + *
24120 + * returns 1 when task should be killed
24121 + * 2 when gcc trampoline was detected
24122 + */
24123 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24124 +{
24125 + if (v8086_mode(regs))
24126 + return 1;
24127 +
24128 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24129 + return 1;
24130 +
24131 +#ifdef CONFIG_X86_32
24132 + return pax_handle_fetch_fault_32(regs);
24133 +#else
24134 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24135 + return pax_handle_fetch_fault_32(regs);
24136 + else
24137 + return pax_handle_fetch_fault_64(regs);
24138 +#endif
24139 +}
24140 +#endif
24141 +
24142 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24143 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24144 +{
24145 + long i;
24146 +
24147 + printk(KERN_ERR "PAX: bytes at PC: ");
24148 + for (i = 0; i < 20; i++) {
24149 + unsigned char c;
24150 + if (get_user(c, (unsigned char __force_user *)pc+i))
24151 + printk(KERN_CONT "?? ");
24152 + else
24153 + printk(KERN_CONT "%02x ", c);
24154 + }
24155 + printk("\n");
24156 +
24157 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24158 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24159 + unsigned long c;
24160 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24161 +#ifdef CONFIG_X86_32
24162 + printk(KERN_CONT "???????? ");
24163 +#else
24164 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24165 + printk(KERN_CONT "???????? ???????? ");
24166 + else
24167 + printk(KERN_CONT "???????????????? ");
24168 +#endif
24169 + } else {
24170 +#ifdef CONFIG_X86_64
24171 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24172 + printk(KERN_CONT "%08x ", (unsigned int)c);
24173 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24174 + } else
24175 +#endif
24176 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24177 + }
24178 + }
24179 + printk("\n");
24180 +}
24181 +#endif
24182 +
24183 +/**
24184 + * probe_kernel_write(): safely attempt to write to a location
24185 + * @dst: address to write to
24186 + * @src: pointer to the data that shall be written
24187 + * @size: size of the data chunk
24188 + *
24189 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24190 + * happens, handle that and return -EFAULT.
24191 + */
24192 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24193 +{
24194 + long ret;
24195 + mm_segment_t old_fs = get_fs();
24196 +
24197 + set_fs(KERNEL_DS);
24198 + pagefault_disable();
24199 + pax_open_kernel();
24200 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24201 + pax_close_kernel();
24202 + pagefault_enable();
24203 + set_fs(old_fs);
24204 +
24205 + return ret ? -EFAULT : 0;
24206 +}
24207 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24208 index dd74e46..7d26398 100644
24209 --- a/arch/x86/mm/gup.c
24210 +++ b/arch/x86/mm/gup.c
24211 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24212 addr = start;
24213 len = (unsigned long) nr_pages << PAGE_SHIFT;
24214 end = start + len;
24215 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24216 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24217 (void __user *)start, len)))
24218 return 0;
24219
24220 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24221 index 6f31ee5..8ee4164 100644
24222 --- a/arch/x86/mm/highmem_32.c
24223 +++ b/arch/x86/mm/highmem_32.c
24224 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24225 idx = type + KM_TYPE_NR*smp_processor_id();
24226 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24227 BUG_ON(!pte_none(*(kmap_pte-idx)));
24228 +
24229 + pax_open_kernel();
24230 set_pte(kmap_pte-idx, mk_pte(page, prot));
24231 + pax_close_kernel();
24232 +
24233 arch_flush_lazy_mmu_mode();
24234
24235 return (void *)vaddr;
24236 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24237 index f6679a7..8f795a3 100644
24238 --- a/arch/x86/mm/hugetlbpage.c
24239 +++ b/arch/x86/mm/hugetlbpage.c
24240 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24241 struct hstate *h = hstate_file(file);
24242 struct mm_struct *mm = current->mm;
24243 struct vm_area_struct *vma;
24244 - unsigned long start_addr;
24245 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24246 +
24247 +#ifdef CONFIG_PAX_SEGMEXEC
24248 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24249 + pax_task_size = SEGMEXEC_TASK_SIZE;
24250 +#endif
24251 +
24252 + pax_task_size -= PAGE_SIZE;
24253
24254 if (len > mm->cached_hole_size) {
24255 - start_addr = mm->free_area_cache;
24256 + start_addr = mm->free_area_cache;
24257 } else {
24258 - start_addr = TASK_UNMAPPED_BASE;
24259 - mm->cached_hole_size = 0;
24260 + start_addr = mm->mmap_base;
24261 + mm->cached_hole_size = 0;
24262 }
24263
24264 full_search:
24265 @@ -280,26 +287,27 @@ full_search:
24266
24267 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24268 /* At this point: (!vma || addr < vma->vm_end). */
24269 - if (TASK_SIZE - len < addr) {
24270 + if (pax_task_size - len < addr) {
24271 /*
24272 * Start a new search - just in case we missed
24273 * some holes.
24274 */
24275 - if (start_addr != TASK_UNMAPPED_BASE) {
24276 - start_addr = TASK_UNMAPPED_BASE;
24277 + if (start_addr != mm->mmap_base) {
24278 + start_addr = mm->mmap_base;
24279 mm->cached_hole_size = 0;
24280 goto full_search;
24281 }
24282 return -ENOMEM;
24283 }
24284 - if (!vma || addr + len <= vma->vm_start) {
24285 - mm->free_area_cache = addr + len;
24286 - return addr;
24287 - }
24288 + if (check_heap_stack_gap(vma, addr, len))
24289 + break;
24290 if (addr + mm->cached_hole_size < vma->vm_start)
24291 mm->cached_hole_size = vma->vm_start - addr;
24292 addr = ALIGN(vma->vm_end, huge_page_size(h));
24293 }
24294 +
24295 + mm->free_area_cache = addr + len;
24296 + return addr;
24297 }
24298
24299 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24300 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24301 struct mm_struct *mm = current->mm;
24302 struct vm_area_struct *vma;
24303 unsigned long base = mm->mmap_base;
24304 - unsigned long addr = addr0;
24305 + unsigned long addr;
24306 unsigned long largest_hole = mm->cached_hole_size;
24307 - unsigned long start_addr;
24308
24309 /* don't allow allocations above current base */
24310 if (mm->free_area_cache > base)
24311 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24312 largest_hole = 0;
24313 mm->free_area_cache = base;
24314 }
24315 -try_again:
24316 - start_addr = mm->free_area_cache;
24317
24318 /* make sure it can fit in the remaining address space */
24319 if (mm->free_area_cache < len)
24320 goto fail;
24321
24322 /* either no address requested or can't fit in requested address hole */
24323 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24324 + addr = mm->free_area_cache - len;
24325 do {
24326 + addr &= huge_page_mask(h);
24327 /*
24328 * Lookup failure means no vma is above this address,
24329 * i.e. return with success:
24330 @@ -340,10 +346,10 @@ try_again:
24331 if (!vma)
24332 return addr;
24333
24334 - if (addr + len <= vma->vm_start) {
24335 + if (check_heap_stack_gap(vma, addr, len)) {
24336 /* remember the address as a hint for next time */
24337 - mm->cached_hole_size = largest_hole;
24338 - return (mm->free_area_cache = addr);
24339 + mm->cached_hole_size = largest_hole;
24340 + return (mm->free_area_cache = addr);
24341 } else if (mm->free_area_cache == vma->vm_end) {
24342 /* pull free_area_cache down to the first hole */
24343 mm->free_area_cache = vma->vm_start;
24344 @@ -352,29 +358,34 @@ try_again:
24345
24346 /* remember the largest hole we saw so far */
24347 if (addr + largest_hole < vma->vm_start)
24348 - largest_hole = vma->vm_start - addr;
24349 + largest_hole = vma->vm_start - addr;
24350
24351 /* try just below the current vma->vm_start */
24352 - addr = (vma->vm_start - len) & huge_page_mask(h);
24353 - } while (len <= vma->vm_start);
24354 + addr = skip_heap_stack_gap(vma, len);
24355 + } while (!IS_ERR_VALUE(addr));
24356
24357 fail:
24358 /*
24359 - * if hint left us with no space for the requested
24360 - * mapping then try again:
24361 - */
24362 - if (start_addr != base) {
24363 - mm->free_area_cache = base;
24364 - largest_hole = 0;
24365 - goto try_again;
24366 - }
24367 - /*
24368 * A failed mmap() very likely causes application failure,
24369 * so fall back to the bottom-up function here. This scenario
24370 * can happen with large stack limits and large mmap()
24371 * allocations.
24372 */
24373 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24374 +
24375 +#ifdef CONFIG_PAX_SEGMEXEC
24376 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24377 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24378 + else
24379 +#endif
24380 +
24381 + mm->mmap_base = TASK_UNMAPPED_BASE;
24382 +
24383 +#ifdef CONFIG_PAX_RANDMMAP
24384 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24385 + mm->mmap_base += mm->delta_mmap;
24386 +#endif
24387 +
24388 + mm->free_area_cache = mm->mmap_base;
24389 mm->cached_hole_size = ~0UL;
24390 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24391 len, pgoff, flags);
24392 @@ -382,6 +393,7 @@ fail:
24393 /*
24394 * Restore the topdown base:
24395 */
24396 + mm->mmap_base = base;
24397 mm->free_area_cache = base;
24398 mm->cached_hole_size = ~0UL;
24399
24400 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24401 struct hstate *h = hstate_file(file);
24402 struct mm_struct *mm = current->mm;
24403 struct vm_area_struct *vma;
24404 + unsigned long pax_task_size = TASK_SIZE;
24405
24406 if (len & ~huge_page_mask(h))
24407 return -EINVAL;
24408 - if (len > TASK_SIZE)
24409 +
24410 +#ifdef CONFIG_PAX_SEGMEXEC
24411 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24412 + pax_task_size = SEGMEXEC_TASK_SIZE;
24413 +#endif
24414 +
24415 + pax_task_size -= PAGE_SIZE;
24416 +
24417 + if (len > pax_task_size)
24418 return -ENOMEM;
24419
24420 if (flags & MAP_FIXED) {
24421 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24422 if (addr) {
24423 addr = ALIGN(addr, huge_page_size(h));
24424 vma = find_vma(mm, addr);
24425 - if (TASK_SIZE - len >= addr &&
24426 - (!vma || addr + len <= vma->vm_start))
24427 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24428 return addr;
24429 }
24430 if (mm->get_unmapped_area == arch_get_unmapped_area)
24431 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24432 index bc4e9d8..ca4c14b 100644
24433 --- a/arch/x86/mm/init.c
24434 +++ b/arch/x86/mm/init.c
24435 @@ -16,6 +16,8 @@
24436 #include <asm/tlb.h>
24437 #include <asm/proto.h>
24438 #include <asm/dma.h> /* for MAX_DMA_PFN */
24439 +#include <asm/desc.h>
24440 +#include <asm/bios_ebda.h>
24441
24442 unsigned long __initdata pgt_buf_start;
24443 unsigned long __meminitdata pgt_buf_end;
24444 @@ -38,7 +40,7 @@ struct map_range {
24445 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24446 int use_pse, int use_gbpages)
24447 {
24448 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24449 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24450 phys_addr_t base;
24451
24452 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24453 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24454 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24455 * mmio resources as well as potential bios/acpi data regions.
24456 */
24457 +
24458 +#ifdef CONFIG_GRKERNSEC_KMEM
24459 +static unsigned int ebda_start __read_only;
24460 +static unsigned int ebda_end __read_only;
24461 +#endif
24462 +
24463 int devmem_is_allowed(unsigned long pagenr)
24464 {
24465 +#ifdef CONFIG_GRKERNSEC_KMEM
24466 + /* allow BDA */
24467 + if (!pagenr)
24468 + return 1;
24469 + /* allow EBDA */
24470 + if (pagenr >= ebda_start && pagenr < ebda_end)
24471 + return 1;
24472 +#else
24473 + if (!pagenr)
24474 + return 1;
24475 +#ifdef CONFIG_VM86
24476 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24477 + return 1;
24478 +#endif
24479 +#endif
24480 +
24481 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24482 + return 1;
24483 +#ifdef CONFIG_GRKERNSEC_KMEM
24484 + /* throw out everything else below 1MB */
24485 if (pagenr <= 256)
24486 - return 1;
24487 + return 0;
24488 +#endif
24489 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24490 return 0;
24491 if (!page_is_ram(pagenr))
24492 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24493 #endif
24494 }
24495
24496 +#ifdef CONFIG_GRKERNSEC_KMEM
24497 +static inline void gr_init_ebda(void)
24498 +{
24499 + unsigned int ebda_addr;
24500 + unsigned int ebda_size = 0;
24501 +
24502 + ebda_addr = get_bios_ebda();
24503 + if (ebda_addr) {
24504 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24505 + ebda_size <<= 10;
24506 + }
24507 + if (ebda_addr && ebda_size) {
24508 + ebda_start = ebda_addr >> PAGE_SHIFT;
24509 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24510 + } else {
24511 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24512 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24513 + }
24514 +}
24515 +#else
24516 +static inline void gr_init_ebda(void) { }
24517 +#endif
24518 +
24519 void free_initmem(void)
24520 {
24521 +#ifdef CONFIG_PAX_KERNEXEC
24522 +#ifdef CONFIG_X86_32
24523 + /* PaX: limit KERNEL_CS to actual size */
24524 + unsigned long addr, limit;
24525 + struct desc_struct d;
24526 + int cpu;
24527 +#else
24528 + pgd_t *pgd;
24529 + pud_t *pud;
24530 + pmd_t *pmd;
24531 + unsigned long addr, end;
24532 +#endif
24533 +#endif
24534 +
24535 + gr_init_ebda();
24536 +
24537 +#ifdef CONFIG_PAX_KERNEXEC
24538 +#ifdef CONFIG_X86_32
24539 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24540 + limit = (limit - 1UL) >> PAGE_SHIFT;
24541 +
24542 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24543 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24544 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24545 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24546 + }
24547 +
24548 + /* PaX: make KERNEL_CS read-only */
24549 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24550 + if (!paravirt_enabled())
24551 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24552 +/*
24553 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24554 + pgd = pgd_offset_k(addr);
24555 + pud = pud_offset(pgd, addr);
24556 + pmd = pmd_offset(pud, addr);
24557 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24558 + }
24559 +*/
24560 +#ifdef CONFIG_X86_PAE
24561 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24562 +/*
24563 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24564 + pgd = pgd_offset_k(addr);
24565 + pud = pud_offset(pgd, addr);
24566 + pmd = pmd_offset(pud, addr);
24567 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24568 + }
24569 +*/
24570 +#endif
24571 +
24572 +#ifdef CONFIG_MODULES
24573 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24574 +#endif
24575 +
24576 +#else
24577 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24578 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24579 + pgd = pgd_offset_k(addr);
24580 + pud = pud_offset(pgd, addr);
24581 + pmd = pmd_offset(pud, addr);
24582 + if (!pmd_present(*pmd))
24583 + continue;
24584 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24585 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24586 + else
24587 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24588 + }
24589 +
24590 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24591 + end = addr + KERNEL_IMAGE_SIZE;
24592 + for (; addr < end; addr += PMD_SIZE) {
24593 + pgd = pgd_offset_k(addr);
24594 + pud = pud_offset(pgd, addr);
24595 + pmd = pmd_offset(pud, addr);
24596 + if (!pmd_present(*pmd))
24597 + continue;
24598 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24599 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24600 + }
24601 +#endif
24602 +
24603 + flush_tlb_all();
24604 +#endif
24605 +
24606 free_init_pages("unused kernel memory",
24607 (unsigned long)(&__init_begin),
24608 (unsigned long)(&__init_end));
24609 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24610 index 575d86f..4987469 100644
24611 --- a/arch/x86/mm/init_32.c
24612 +++ b/arch/x86/mm/init_32.c
24613 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24614 }
24615
24616 /*
24617 - * Creates a middle page table and puts a pointer to it in the
24618 - * given global directory entry. This only returns the gd entry
24619 - * in non-PAE compilation mode, since the middle layer is folded.
24620 - */
24621 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24622 -{
24623 - pud_t *pud;
24624 - pmd_t *pmd_table;
24625 -
24626 -#ifdef CONFIG_X86_PAE
24627 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24628 - if (after_bootmem)
24629 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24630 - else
24631 - pmd_table = (pmd_t *)alloc_low_page();
24632 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24633 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24634 - pud = pud_offset(pgd, 0);
24635 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24636 -
24637 - return pmd_table;
24638 - }
24639 -#endif
24640 - pud = pud_offset(pgd, 0);
24641 - pmd_table = pmd_offset(pud, 0);
24642 -
24643 - return pmd_table;
24644 -}
24645 -
24646 -/*
24647 * Create a page table and place a pointer to it in a middle page
24648 * directory entry:
24649 */
24650 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24651 page_table = (pte_t *)alloc_low_page();
24652
24653 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24654 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24655 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24656 +#else
24657 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24658 +#endif
24659 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24660 }
24661
24662 return pte_offset_kernel(pmd, 0);
24663 }
24664
24665 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24666 +{
24667 + pud_t *pud;
24668 + pmd_t *pmd_table;
24669 +
24670 + pud = pud_offset(pgd, 0);
24671 + pmd_table = pmd_offset(pud, 0);
24672 +
24673 + return pmd_table;
24674 +}
24675 +
24676 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24677 {
24678 int pgd_idx = pgd_index(vaddr);
24679 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24680 int pgd_idx, pmd_idx;
24681 unsigned long vaddr;
24682 pgd_t *pgd;
24683 + pud_t *pud;
24684 pmd_t *pmd;
24685 pte_t *pte = NULL;
24686
24687 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24688 pgd = pgd_base + pgd_idx;
24689
24690 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24691 - pmd = one_md_table_init(pgd);
24692 - pmd = pmd + pmd_index(vaddr);
24693 + pud = pud_offset(pgd, vaddr);
24694 + pmd = pmd_offset(pud, vaddr);
24695 +
24696 +#ifdef CONFIG_X86_PAE
24697 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24698 +#endif
24699 +
24700 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24701 pmd++, pmd_idx++) {
24702 pte = page_table_kmap_check(one_page_table_init(pmd),
24703 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24704 }
24705 }
24706
24707 -static inline int is_kernel_text(unsigned long addr)
24708 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24709 {
24710 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24711 - return 1;
24712 - return 0;
24713 + if ((start > ktla_ktva((unsigned long)_etext) ||
24714 + end <= ktla_ktva((unsigned long)_stext)) &&
24715 + (start > ktla_ktva((unsigned long)_einittext) ||
24716 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24717 +
24718 +#ifdef CONFIG_ACPI_SLEEP
24719 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24720 +#endif
24721 +
24722 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24723 + return 0;
24724 + return 1;
24725 }
24726
24727 /*
24728 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24729 unsigned long last_map_addr = end;
24730 unsigned long start_pfn, end_pfn;
24731 pgd_t *pgd_base = swapper_pg_dir;
24732 - int pgd_idx, pmd_idx, pte_ofs;
24733 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24734 unsigned long pfn;
24735 pgd_t *pgd;
24736 + pud_t *pud;
24737 pmd_t *pmd;
24738 pte_t *pte;
24739 unsigned pages_2m, pages_4k;
24740 @@ -280,8 +281,13 @@ repeat:
24741 pfn = start_pfn;
24742 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24743 pgd = pgd_base + pgd_idx;
24744 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24745 - pmd = one_md_table_init(pgd);
24746 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24747 + pud = pud_offset(pgd, 0);
24748 + pmd = pmd_offset(pud, 0);
24749 +
24750 +#ifdef CONFIG_X86_PAE
24751 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24752 +#endif
24753
24754 if (pfn >= end_pfn)
24755 continue;
24756 @@ -293,14 +299,13 @@ repeat:
24757 #endif
24758 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24759 pmd++, pmd_idx++) {
24760 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24761 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24762
24763 /*
24764 * Map with big pages if possible, otherwise
24765 * create normal page tables:
24766 */
24767 if (use_pse) {
24768 - unsigned int addr2;
24769 pgprot_t prot = PAGE_KERNEL_LARGE;
24770 /*
24771 * first pass will use the same initial
24772 @@ -310,11 +315,7 @@ repeat:
24773 __pgprot(PTE_IDENT_ATTR |
24774 _PAGE_PSE);
24775
24776 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24777 - PAGE_OFFSET + PAGE_SIZE-1;
24778 -
24779 - if (is_kernel_text(addr) ||
24780 - is_kernel_text(addr2))
24781 + if (is_kernel_text(address, address + PMD_SIZE))
24782 prot = PAGE_KERNEL_LARGE_EXEC;
24783
24784 pages_2m++;
24785 @@ -331,7 +332,7 @@ repeat:
24786 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24787 pte += pte_ofs;
24788 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24789 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24790 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24791 pgprot_t prot = PAGE_KERNEL;
24792 /*
24793 * first pass will use the same initial
24794 @@ -339,7 +340,7 @@ repeat:
24795 */
24796 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24797
24798 - if (is_kernel_text(addr))
24799 + if (is_kernel_text(address, address + PAGE_SIZE))
24800 prot = PAGE_KERNEL_EXEC;
24801
24802 pages_4k++;
24803 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24804
24805 pud = pud_offset(pgd, va);
24806 pmd = pmd_offset(pud, va);
24807 - if (!pmd_present(*pmd))
24808 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24809 break;
24810
24811 pte = pte_offset_kernel(pmd, va);
24812 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24813
24814 static void __init pagetable_init(void)
24815 {
24816 - pgd_t *pgd_base = swapper_pg_dir;
24817 -
24818 - permanent_kmaps_init(pgd_base);
24819 + permanent_kmaps_init(swapper_pg_dir);
24820 }
24821
24822 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24823 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24824 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24825
24826 /* user-defined highmem size */
24827 @@ -734,6 +733,12 @@ void __init mem_init(void)
24828
24829 pci_iommu_alloc();
24830
24831 +#ifdef CONFIG_PAX_PER_CPU_PGD
24832 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24833 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24834 + KERNEL_PGD_PTRS);
24835 +#endif
24836 +
24837 #ifdef CONFIG_FLATMEM
24838 BUG_ON(!mem_map);
24839 #endif
24840 @@ -760,7 +765,7 @@ void __init mem_init(void)
24841 reservedpages++;
24842
24843 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24844 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24845 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24846 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24847
24848 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24849 @@ -801,10 +806,10 @@ void __init mem_init(void)
24850 ((unsigned long)&__init_end -
24851 (unsigned long)&__init_begin) >> 10,
24852
24853 - (unsigned long)&_etext, (unsigned long)&_edata,
24854 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24855 + (unsigned long)&_sdata, (unsigned long)&_edata,
24856 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24857
24858 - (unsigned long)&_text, (unsigned long)&_etext,
24859 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24860 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24861
24862 /*
24863 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24864 if (!kernel_set_to_readonly)
24865 return;
24866
24867 + start = ktla_ktva(start);
24868 pr_debug("Set kernel text: %lx - %lx for read write\n",
24869 start, start+size);
24870
24871 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24872 if (!kernel_set_to_readonly)
24873 return;
24874
24875 + start = ktla_ktva(start);
24876 pr_debug("Set kernel text: %lx - %lx for read only\n",
24877 start, start+size);
24878
24879 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24880 unsigned long start = PFN_ALIGN(_text);
24881 unsigned long size = PFN_ALIGN(_etext) - start;
24882
24883 + start = ktla_ktva(start);
24884 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24885 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24886 size >> 10);
24887 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24888 index 2b6b4a3..c17210d 100644
24889 --- a/arch/x86/mm/init_64.c
24890 +++ b/arch/x86/mm/init_64.c
24891 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24892 * around without checking the pgd every time.
24893 */
24894
24895 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24896 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24897 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24898
24899 int force_personality32;
24900 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24901
24902 for (address = start; address <= end; address += PGDIR_SIZE) {
24903 const pgd_t *pgd_ref = pgd_offset_k(address);
24904 +
24905 +#ifdef CONFIG_PAX_PER_CPU_PGD
24906 + unsigned long cpu;
24907 +#else
24908 struct page *page;
24909 +#endif
24910
24911 if (pgd_none(*pgd_ref))
24912 continue;
24913
24914 spin_lock(&pgd_lock);
24915 +
24916 +#ifdef CONFIG_PAX_PER_CPU_PGD
24917 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24918 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24919 +#else
24920 list_for_each_entry(page, &pgd_list, lru) {
24921 pgd_t *pgd;
24922 spinlock_t *pgt_lock;
24923 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24924 /* the pgt_lock only for Xen */
24925 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24926 spin_lock(pgt_lock);
24927 +#endif
24928
24929 if (pgd_none(*pgd))
24930 set_pgd(pgd, *pgd_ref);
24931 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24932 BUG_ON(pgd_page_vaddr(*pgd)
24933 != pgd_page_vaddr(*pgd_ref));
24934
24935 +#ifndef CONFIG_PAX_PER_CPU_PGD
24936 spin_unlock(pgt_lock);
24937 +#endif
24938 +
24939 }
24940 spin_unlock(&pgd_lock);
24941 }
24942 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24943 {
24944 if (pgd_none(*pgd)) {
24945 pud_t *pud = (pud_t *)spp_getpage();
24946 - pgd_populate(&init_mm, pgd, pud);
24947 + pgd_populate_kernel(&init_mm, pgd, pud);
24948 if (pud != pud_offset(pgd, 0))
24949 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24950 pud, pud_offset(pgd, 0));
24951 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24952 {
24953 if (pud_none(*pud)) {
24954 pmd_t *pmd = (pmd_t *) spp_getpage();
24955 - pud_populate(&init_mm, pud, pmd);
24956 + pud_populate_kernel(&init_mm, pud, pmd);
24957 if (pmd != pmd_offset(pud, 0))
24958 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24959 pmd, pmd_offset(pud, 0));
24960 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24961 pmd = fill_pmd(pud, vaddr);
24962 pte = fill_pte(pmd, vaddr);
24963
24964 + pax_open_kernel();
24965 set_pte(pte, new_pte);
24966 + pax_close_kernel();
24967
24968 /*
24969 * It's enough to flush this one mapping.
24970 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24971 pgd = pgd_offset_k((unsigned long)__va(phys));
24972 if (pgd_none(*pgd)) {
24973 pud = (pud_t *) spp_getpage();
24974 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24975 - _PAGE_USER));
24976 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24977 }
24978 pud = pud_offset(pgd, (unsigned long)__va(phys));
24979 if (pud_none(*pud)) {
24980 pmd = (pmd_t *) spp_getpage();
24981 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24982 - _PAGE_USER));
24983 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24984 }
24985 pmd = pmd_offset(pud, phys);
24986 BUG_ON(!pmd_none(*pmd));
24987 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24988 if (pfn >= pgt_buf_top)
24989 panic("alloc_low_page: ran out of memory");
24990
24991 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24992 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24993 clear_page(adr);
24994 *phys = pfn * PAGE_SIZE;
24995 return adr;
24996 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24997
24998 phys = __pa(virt);
24999 left = phys & (PAGE_SIZE - 1);
25000 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25001 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25002 adr = (void *)(((unsigned long)adr) | left);
25003
25004 return adr;
25005 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25006 unmap_low_page(pmd);
25007
25008 spin_lock(&init_mm.page_table_lock);
25009 - pud_populate(&init_mm, pud, __va(pmd_phys));
25010 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25011 spin_unlock(&init_mm.page_table_lock);
25012 }
25013 __flush_tlb_all();
25014 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25015 unmap_low_page(pud);
25016
25017 spin_lock(&init_mm.page_table_lock);
25018 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25019 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25020 spin_unlock(&init_mm.page_table_lock);
25021 pgd_changed = true;
25022 }
25023 @@ -686,6 +700,12 @@ void __init mem_init(void)
25024
25025 pci_iommu_alloc();
25026
25027 +#ifdef CONFIG_PAX_PER_CPU_PGD
25028 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25029 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25030 + KERNEL_PGD_PTRS);
25031 +#endif
25032 +
25033 /* clear_bss() already clear the empty_zero_page */
25034
25035 reservedpages = 0;
25036 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25037 static struct vm_area_struct gate_vma = {
25038 .vm_start = VSYSCALL_START,
25039 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25040 - .vm_page_prot = PAGE_READONLY_EXEC,
25041 - .vm_flags = VM_READ | VM_EXEC
25042 + .vm_page_prot = PAGE_READONLY,
25043 + .vm_flags = VM_READ
25044 };
25045
25046 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25047 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25048
25049 const char *arch_vma_name(struct vm_area_struct *vma)
25050 {
25051 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25052 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25053 return "[vdso]";
25054 if (vma == &gate_vma)
25055 return "[vsyscall]";
25056 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25057 index 7b179b4..6bd1777 100644
25058 --- a/arch/x86/mm/iomap_32.c
25059 +++ b/arch/x86/mm/iomap_32.c
25060 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25061 type = kmap_atomic_idx_push();
25062 idx = type + KM_TYPE_NR * smp_processor_id();
25063 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25064 +
25065 + pax_open_kernel();
25066 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25067 + pax_close_kernel();
25068 +
25069 arch_flush_lazy_mmu_mode();
25070
25071 return (void *)vaddr;
25072 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25073 index 78fe3f1..8293b6f 100644
25074 --- a/arch/x86/mm/ioremap.c
25075 +++ b/arch/x86/mm/ioremap.c
25076 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25077 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25078 int is_ram = page_is_ram(pfn);
25079
25080 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25081 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25082 return NULL;
25083 WARN_ON_ONCE(is_ram);
25084 }
25085 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25086
25087 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25088 if (page_is_ram(start >> PAGE_SHIFT))
25089 +#ifdef CONFIG_HIGHMEM
25090 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25091 +#endif
25092 return __va(phys);
25093
25094 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25095 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25096 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25097
25098 static __initdata int after_paging_init;
25099 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25100 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25101
25102 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25103 {
25104 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25105 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25106
25107 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25108 - memset(bm_pte, 0, sizeof(bm_pte));
25109 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25110 + pmd_populate_user(&init_mm, pmd, bm_pte);
25111
25112 /*
25113 * The boot-ioremap range spans multiple pmds, for which
25114 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25115 index d87dd6d..bf3fa66 100644
25116 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25117 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25118 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25119 * memory (e.g. tracked pages)? For now, we need this to avoid
25120 * invoking kmemcheck for PnP BIOS calls.
25121 */
25122 - if (regs->flags & X86_VM_MASK)
25123 + if (v8086_mode(regs))
25124 return false;
25125 - if (regs->cs != __KERNEL_CS)
25126 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25127 return false;
25128
25129 pte = kmemcheck_pte_lookup(address);
25130 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25131 index 845df68..1d8d29f 100644
25132 --- a/arch/x86/mm/mmap.c
25133 +++ b/arch/x86/mm/mmap.c
25134 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25135 * Leave an at least ~128 MB hole with possible stack randomization.
25136 */
25137 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25138 -#define MAX_GAP (TASK_SIZE/6*5)
25139 +#define MAX_GAP (pax_task_size/6*5)
25140
25141 static int mmap_is_legacy(void)
25142 {
25143 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25144 return rnd << PAGE_SHIFT;
25145 }
25146
25147 -static unsigned long mmap_base(void)
25148 +static unsigned long mmap_base(struct mm_struct *mm)
25149 {
25150 unsigned long gap = rlimit(RLIMIT_STACK);
25151 + unsigned long pax_task_size = TASK_SIZE;
25152 +
25153 +#ifdef CONFIG_PAX_SEGMEXEC
25154 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25155 + pax_task_size = SEGMEXEC_TASK_SIZE;
25156 +#endif
25157
25158 if (gap < MIN_GAP)
25159 gap = MIN_GAP;
25160 else if (gap > MAX_GAP)
25161 gap = MAX_GAP;
25162
25163 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25164 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25165 }
25166
25167 /*
25168 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25169 * does, but not when emulating X86_32
25170 */
25171 -static unsigned long mmap_legacy_base(void)
25172 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25173 {
25174 - if (mmap_is_ia32())
25175 + if (mmap_is_ia32()) {
25176 +
25177 +#ifdef CONFIG_PAX_SEGMEXEC
25178 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25179 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25180 + else
25181 +#endif
25182 +
25183 return TASK_UNMAPPED_BASE;
25184 - else
25185 + } else
25186 return TASK_UNMAPPED_BASE + mmap_rnd();
25187 }
25188
25189 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25190 void arch_pick_mmap_layout(struct mm_struct *mm)
25191 {
25192 if (mmap_is_legacy()) {
25193 - mm->mmap_base = mmap_legacy_base();
25194 + mm->mmap_base = mmap_legacy_base(mm);
25195 +
25196 +#ifdef CONFIG_PAX_RANDMMAP
25197 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25198 + mm->mmap_base += mm->delta_mmap;
25199 +#endif
25200 +
25201 mm->get_unmapped_area = arch_get_unmapped_area;
25202 mm->unmap_area = arch_unmap_area;
25203 } else {
25204 - mm->mmap_base = mmap_base();
25205 + mm->mmap_base = mmap_base(mm);
25206 +
25207 +#ifdef CONFIG_PAX_RANDMMAP
25208 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25209 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25210 +#endif
25211 +
25212 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25213 mm->unmap_area = arch_unmap_area_topdown;
25214 }
25215 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25216 index dc0b727..dc9d71a 100644
25217 --- a/arch/x86/mm/mmio-mod.c
25218 +++ b/arch/x86/mm/mmio-mod.c
25219 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25220 break;
25221 default:
25222 {
25223 - unsigned char *ip = (unsigned char *)instptr;
25224 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25225 my_trace->opcode = MMIO_UNKNOWN_OP;
25226 my_trace->width = 0;
25227 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25228 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25229 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25230 void __iomem *addr)
25231 {
25232 - static atomic_t next_id;
25233 + static atomic_unchecked_t next_id;
25234 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25235 /* These are page-unaligned. */
25236 struct mmiotrace_map map = {
25237 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25238 .private = trace
25239 },
25240 .phys = offset,
25241 - .id = atomic_inc_return(&next_id)
25242 + .id = atomic_inc_return_unchecked(&next_id)
25243 };
25244 map.map_id = trace->id;
25245
25246 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25247 index b008656..773eac2 100644
25248 --- a/arch/x86/mm/pageattr-test.c
25249 +++ b/arch/x86/mm/pageattr-test.c
25250 @@ -36,7 +36,7 @@ enum {
25251
25252 static int pte_testbit(pte_t pte)
25253 {
25254 - return pte_flags(pte) & _PAGE_UNUSED1;
25255 + return pte_flags(pte) & _PAGE_CPA_TEST;
25256 }
25257
25258 struct split_state {
25259 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25260 index a718e0d..45efc32 100644
25261 --- a/arch/x86/mm/pageattr.c
25262 +++ b/arch/x86/mm/pageattr.c
25263 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25264 */
25265 #ifdef CONFIG_PCI_BIOS
25266 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25267 - pgprot_val(forbidden) |= _PAGE_NX;
25268 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25269 #endif
25270
25271 /*
25272 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25273 * Does not cover __inittext since that is gone later on. On
25274 * 64bit we do not enforce !NX on the low mapping
25275 */
25276 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25277 - pgprot_val(forbidden) |= _PAGE_NX;
25278 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25279 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25280
25281 +#ifdef CONFIG_DEBUG_RODATA
25282 /*
25283 * The .rodata section needs to be read-only. Using the pfn
25284 * catches all aliases.
25285 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25286 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25287 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25288 pgprot_val(forbidden) |= _PAGE_RW;
25289 +#endif
25290
25291 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25292 /*
25293 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25294 }
25295 #endif
25296
25297 +#ifdef CONFIG_PAX_KERNEXEC
25298 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25299 + pgprot_val(forbidden) |= _PAGE_RW;
25300 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25301 + }
25302 +#endif
25303 +
25304 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25305
25306 return prot;
25307 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25308 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25309 {
25310 /* change init_mm */
25311 + pax_open_kernel();
25312 set_pte_atomic(kpte, pte);
25313 +
25314 #ifdef CONFIG_X86_32
25315 if (!SHARED_KERNEL_PMD) {
25316 +
25317 +#ifdef CONFIG_PAX_PER_CPU_PGD
25318 + unsigned long cpu;
25319 +#else
25320 struct page *page;
25321 +#endif
25322
25323 +#ifdef CONFIG_PAX_PER_CPU_PGD
25324 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25325 + pgd_t *pgd = get_cpu_pgd(cpu);
25326 +#else
25327 list_for_each_entry(page, &pgd_list, lru) {
25328 - pgd_t *pgd;
25329 + pgd_t *pgd = (pgd_t *)page_address(page);
25330 +#endif
25331 +
25332 pud_t *pud;
25333 pmd_t *pmd;
25334
25335 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25336 + pgd += pgd_index(address);
25337 pud = pud_offset(pgd, address);
25338 pmd = pmd_offset(pud, address);
25339 set_pte_atomic((pte_t *)pmd, pte);
25340 }
25341 }
25342 #endif
25343 + pax_close_kernel();
25344 }
25345
25346 static int
25347 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25348 index 3d68ef6..7f69136 100644
25349 --- a/arch/x86/mm/pat.c
25350 +++ b/arch/x86/mm/pat.c
25351 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25352
25353 if (!entry) {
25354 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25355 - current->comm, current->pid, start, end - 1);
25356 + current->comm, task_pid_nr(current), start, end - 1);
25357 return -EINVAL;
25358 }
25359
25360 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25361
25362 while (cursor < to) {
25363 if (!devmem_is_allowed(pfn)) {
25364 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25365 - current->comm, from, to - 1);
25366 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25367 + current->comm, from, to - 1, cursor);
25368 return 0;
25369 }
25370 cursor += PAGE_SIZE;
25371 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25372 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25373 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25374 "for [mem %#010Lx-%#010Lx]\n",
25375 - current->comm, current->pid,
25376 + current->comm, task_pid_nr(current),
25377 cattr_name(flags),
25378 base, (unsigned long long)(base + size-1));
25379 return -EINVAL;
25380 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25381 flags = lookup_memtype(paddr);
25382 if (want_flags != flags) {
25383 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25384 - current->comm, current->pid,
25385 + current->comm, task_pid_nr(current),
25386 cattr_name(want_flags),
25387 (unsigned long long)paddr,
25388 (unsigned long long)(paddr + size - 1),
25389 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25390 free_memtype(paddr, paddr + size);
25391 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25392 " for [mem %#010Lx-%#010Lx], got %s\n",
25393 - current->comm, current->pid,
25394 + current->comm, task_pid_nr(current),
25395 cattr_name(want_flags),
25396 (unsigned long long)paddr,
25397 (unsigned long long)(paddr + size - 1),
25398 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25399 index 9f0614d..92ae64a 100644
25400 --- a/arch/x86/mm/pf_in.c
25401 +++ b/arch/x86/mm/pf_in.c
25402 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25403 int i;
25404 enum reason_type rv = OTHERS;
25405
25406 - p = (unsigned char *)ins_addr;
25407 + p = (unsigned char *)ktla_ktva(ins_addr);
25408 p += skip_prefix(p, &prf);
25409 p += get_opcode(p, &opcode);
25410
25411 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25412 struct prefix_bits prf;
25413 int i;
25414
25415 - p = (unsigned char *)ins_addr;
25416 + p = (unsigned char *)ktla_ktva(ins_addr);
25417 p += skip_prefix(p, &prf);
25418 p += get_opcode(p, &opcode);
25419
25420 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25421 struct prefix_bits prf;
25422 int i;
25423
25424 - p = (unsigned char *)ins_addr;
25425 + p = (unsigned char *)ktla_ktva(ins_addr);
25426 p += skip_prefix(p, &prf);
25427 p += get_opcode(p, &opcode);
25428
25429 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25430 struct prefix_bits prf;
25431 int i;
25432
25433 - p = (unsigned char *)ins_addr;
25434 + p = (unsigned char *)ktla_ktva(ins_addr);
25435 p += skip_prefix(p, &prf);
25436 p += get_opcode(p, &opcode);
25437 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25438 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25439 struct prefix_bits prf;
25440 int i;
25441
25442 - p = (unsigned char *)ins_addr;
25443 + p = (unsigned char *)ktla_ktva(ins_addr);
25444 p += skip_prefix(p, &prf);
25445 p += get_opcode(p, &opcode);
25446 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25447 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25448 index 8573b83..4f3ed7e 100644
25449 --- a/arch/x86/mm/pgtable.c
25450 +++ b/arch/x86/mm/pgtable.c
25451 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25452 list_del(&page->lru);
25453 }
25454
25455 -#define UNSHARED_PTRS_PER_PGD \
25456 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25457 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25458 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25459
25460 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25461 +{
25462 + unsigned int count = USER_PGD_PTRS;
25463
25464 + while (count--)
25465 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25466 +}
25467 +#endif
25468 +
25469 +#ifdef CONFIG_PAX_PER_CPU_PGD
25470 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25471 +{
25472 + unsigned int count = USER_PGD_PTRS;
25473 +
25474 + while (count--) {
25475 + pgd_t pgd;
25476 +
25477 +#ifdef CONFIG_X86_64
25478 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25479 +#else
25480 + pgd = *src++;
25481 +#endif
25482 +
25483 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25484 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25485 +#endif
25486 +
25487 + *dst++ = pgd;
25488 + }
25489 +
25490 +}
25491 +#endif
25492 +
25493 +#ifdef CONFIG_X86_64
25494 +#define pxd_t pud_t
25495 +#define pyd_t pgd_t
25496 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25497 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25498 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25499 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25500 +#define PYD_SIZE PGDIR_SIZE
25501 +#else
25502 +#define pxd_t pmd_t
25503 +#define pyd_t pud_t
25504 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25505 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25506 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25507 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25508 +#define PYD_SIZE PUD_SIZE
25509 +#endif
25510 +
25511 +#ifdef CONFIG_PAX_PER_CPU_PGD
25512 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25513 +static inline void pgd_dtor(pgd_t *pgd) {}
25514 +#else
25515 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25516 {
25517 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25518 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25519 pgd_list_del(pgd);
25520 spin_unlock(&pgd_lock);
25521 }
25522 +#endif
25523
25524 /*
25525 * List of all pgd's needed for non-PAE so it can invalidate entries
25526 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25527 * -- wli
25528 */
25529
25530 -#ifdef CONFIG_X86_PAE
25531 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25532 /*
25533 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25534 * updating the top-level pagetable entries to guarantee the
25535 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25536 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25537 * and initialize the kernel pmds here.
25538 */
25539 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25540 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25541
25542 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25543 {
25544 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25545 */
25546 flush_tlb_mm(mm);
25547 }
25548 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25549 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25550 #else /* !CONFIG_X86_PAE */
25551
25552 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25553 -#define PREALLOCATED_PMDS 0
25554 +#define PREALLOCATED_PXDS 0
25555
25556 #endif /* CONFIG_X86_PAE */
25557
25558 -static void free_pmds(pmd_t *pmds[])
25559 +static void free_pxds(pxd_t *pxds[])
25560 {
25561 int i;
25562
25563 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25564 - if (pmds[i])
25565 - free_page((unsigned long)pmds[i]);
25566 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25567 + if (pxds[i])
25568 + free_page((unsigned long)pxds[i]);
25569 }
25570
25571 -static int preallocate_pmds(pmd_t *pmds[])
25572 +static int preallocate_pxds(pxd_t *pxds[])
25573 {
25574 int i;
25575 bool failed = false;
25576
25577 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25578 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25579 - if (pmd == NULL)
25580 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25581 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25582 + if (pxd == NULL)
25583 failed = true;
25584 - pmds[i] = pmd;
25585 + pxds[i] = pxd;
25586 }
25587
25588 if (failed) {
25589 - free_pmds(pmds);
25590 + free_pxds(pxds);
25591 return -ENOMEM;
25592 }
25593
25594 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25595 * preallocate which never got a corresponding vma will need to be
25596 * freed manually.
25597 */
25598 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25599 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25600 {
25601 int i;
25602
25603 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25604 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25605 pgd_t pgd = pgdp[i];
25606
25607 if (pgd_val(pgd) != 0) {
25608 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25609 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25610
25611 - pgdp[i] = native_make_pgd(0);
25612 + set_pgd(pgdp + i, native_make_pgd(0));
25613
25614 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25615 - pmd_free(mm, pmd);
25616 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25617 + pxd_free(mm, pxd);
25618 }
25619 }
25620 }
25621
25622 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25623 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25624 {
25625 - pud_t *pud;
25626 + pyd_t *pyd;
25627 unsigned long addr;
25628 int i;
25629
25630 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25631 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25632 return;
25633
25634 - pud = pud_offset(pgd, 0);
25635 +#ifdef CONFIG_X86_64
25636 + pyd = pyd_offset(mm, 0L);
25637 +#else
25638 + pyd = pyd_offset(pgd, 0L);
25639 +#endif
25640
25641 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25642 - i++, pud++, addr += PUD_SIZE) {
25643 - pmd_t *pmd = pmds[i];
25644 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25645 + i++, pyd++, addr += PYD_SIZE) {
25646 + pxd_t *pxd = pxds[i];
25647
25648 if (i >= KERNEL_PGD_BOUNDARY)
25649 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25650 - sizeof(pmd_t) * PTRS_PER_PMD);
25651 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25652 + sizeof(pxd_t) * PTRS_PER_PMD);
25653
25654 - pud_populate(mm, pud, pmd);
25655 + pyd_populate(mm, pyd, pxd);
25656 }
25657 }
25658
25659 pgd_t *pgd_alloc(struct mm_struct *mm)
25660 {
25661 pgd_t *pgd;
25662 - pmd_t *pmds[PREALLOCATED_PMDS];
25663 + pxd_t *pxds[PREALLOCATED_PXDS];
25664
25665 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25666
25667 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25668
25669 mm->pgd = pgd;
25670
25671 - if (preallocate_pmds(pmds) != 0)
25672 + if (preallocate_pxds(pxds) != 0)
25673 goto out_free_pgd;
25674
25675 if (paravirt_pgd_alloc(mm) != 0)
25676 - goto out_free_pmds;
25677 + goto out_free_pxds;
25678
25679 /*
25680 * Make sure that pre-populating the pmds is atomic with
25681 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25682 spin_lock(&pgd_lock);
25683
25684 pgd_ctor(mm, pgd);
25685 - pgd_prepopulate_pmd(mm, pgd, pmds);
25686 + pgd_prepopulate_pxd(mm, pgd, pxds);
25687
25688 spin_unlock(&pgd_lock);
25689
25690 return pgd;
25691
25692 -out_free_pmds:
25693 - free_pmds(pmds);
25694 +out_free_pxds:
25695 + free_pxds(pxds);
25696 out_free_pgd:
25697 free_page((unsigned long)pgd);
25698 out:
25699 @@ -295,7 +356,7 @@ out:
25700
25701 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25702 {
25703 - pgd_mop_up_pmds(mm, pgd);
25704 + pgd_mop_up_pxds(mm, pgd);
25705 pgd_dtor(pgd);
25706 paravirt_pgd_free(mm, pgd);
25707 free_page((unsigned long)pgd);
25708 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25709 index a69bcb8..19068ab 100644
25710 --- a/arch/x86/mm/pgtable_32.c
25711 +++ b/arch/x86/mm/pgtable_32.c
25712 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25713 return;
25714 }
25715 pte = pte_offset_kernel(pmd, vaddr);
25716 +
25717 + pax_open_kernel();
25718 if (pte_val(pteval))
25719 set_pte_at(&init_mm, vaddr, pte, pteval);
25720 else
25721 pte_clear(&init_mm, vaddr, pte);
25722 + pax_close_kernel();
25723
25724 /*
25725 * It's enough to flush this one mapping.
25726 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25727 index 410531d..0f16030 100644
25728 --- a/arch/x86/mm/setup_nx.c
25729 +++ b/arch/x86/mm/setup_nx.c
25730 @@ -5,8 +5,10 @@
25731 #include <asm/pgtable.h>
25732 #include <asm/proto.h>
25733
25734 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25735 static int disable_nx __cpuinitdata;
25736
25737 +#ifndef CONFIG_PAX_PAGEEXEC
25738 /*
25739 * noexec = on|off
25740 *
25741 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25742 return 0;
25743 }
25744 early_param("noexec", noexec_setup);
25745 +#endif
25746 +
25747 +#endif
25748
25749 void __cpuinit x86_configure_nx(void)
25750 {
25751 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25752 if (cpu_has_nx && !disable_nx)
25753 __supported_pte_mask |= _PAGE_NX;
25754 else
25755 +#endif
25756 __supported_pte_mask &= ~_PAGE_NX;
25757 }
25758
25759 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25760 index 5e57e11..64874249 100644
25761 --- a/arch/x86/mm/tlb.c
25762 +++ b/arch/x86/mm/tlb.c
25763 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25764 BUG();
25765 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25766 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25767 +
25768 +#ifndef CONFIG_PAX_PER_CPU_PGD
25769 load_cr3(swapper_pg_dir);
25770 +#endif
25771 +
25772 }
25773 }
25774 EXPORT_SYMBOL_GPL(leave_mm);
25775 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25776 index 877b9a1..a8ecf42 100644
25777 --- a/arch/x86/net/bpf_jit.S
25778 +++ b/arch/x86/net/bpf_jit.S
25779 @@ -9,6 +9,7 @@
25780 */
25781 #include <linux/linkage.h>
25782 #include <asm/dwarf2.h>
25783 +#include <asm/alternative-asm.h>
25784
25785 /*
25786 * Calling convention :
25787 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25788 jle bpf_slow_path_word
25789 mov (SKBDATA,%rsi),%eax
25790 bswap %eax /* ntohl() */
25791 + pax_force_retaddr
25792 ret
25793
25794 sk_load_half:
25795 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25796 jle bpf_slow_path_half
25797 movzwl (SKBDATA,%rsi),%eax
25798 rol $8,%ax # ntohs()
25799 + pax_force_retaddr
25800 ret
25801
25802 sk_load_byte:
25803 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25804 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25805 jle bpf_slow_path_byte
25806 movzbl (SKBDATA,%rsi),%eax
25807 + pax_force_retaddr
25808 ret
25809
25810 /**
25811 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25812 movzbl (SKBDATA,%rsi),%ebx
25813 and $15,%bl
25814 shl $2,%bl
25815 + pax_force_retaddr
25816 ret
25817
25818 /* rsi contains offset and can be scratched */
25819 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25820 js bpf_error
25821 mov -12(%rbp),%eax
25822 bswap %eax
25823 + pax_force_retaddr
25824 ret
25825
25826 bpf_slow_path_half:
25827 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25828 mov -12(%rbp),%ax
25829 rol $8,%ax
25830 movzwl %ax,%eax
25831 + pax_force_retaddr
25832 ret
25833
25834 bpf_slow_path_byte:
25835 bpf_slow_path_common(1)
25836 js bpf_error
25837 movzbl -12(%rbp),%eax
25838 + pax_force_retaddr
25839 ret
25840
25841 bpf_slow_path_byte_msh:
25842 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25843 and $15,%al
25844 shl $2,%al
25845 xchg %eax,%ebx
25846 + pax_force_retaddr
25847 ret
25848
25849 #define sk_negative_common(SIZE) \
25850 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25851 sk_negative_common(4)
25852 mov (%rax), %eax
25853 bswap %eax
25854 + pax_force_retaddr
25855 ret
25856
25857 bpf_slow_path_half_neg:
25858 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25859 mov (%rax),%ax
25860 rol $8,%ax
25861 movzwl %ax,%eax
25862 + pax_force_retaddr
25863 ret
25864
25865 bpf_slow_path_byte_neg:
25866 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25867 .globl sk_load_byte_negative_offset
25868 sk_negative_common(1)
25869 movzbl (%rax), %eax
25870 + pax_force_retaddr
25871 ret
25872
25873 bpf_slow_path_byte_msh_neg:
25874 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25875 and $15,%al
25876 shl $2,%al
25877 xchg %eax,%ebx
25878 + pax_force_retaddr
25879 ret
25880
25881 bpf_error:
25882 @@ -197,4 +210,5 @@ bpf_error:
25883 xor %eax,%eax
25884 mov -8(%rbp),%rbx
25885 leaveq
25886 + pax_force_retaddr
25887 ret
25888 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25889 index 0597f95..a12c36e 100644
25890 --- a/arch/x86/net/bpf_jit_comp.c
25891 +++ b/arch/x86/net/bpf_jit_comp.c
25892 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25893 set_fs(old_fs);
25894 }
25895
25896 +struct bpf_jit_work {
25897 + struct work_struct work;
25898 + void *image;
25899 +};
25900 +
25901 #define CHOOSE_LOAD_FUNC(K, func) \
25902 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25903
25904 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25905 if (addrs == NULL)
25906 return;
25907
25908 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25909 + if (!fp->work)
25910 + goto out;
25911 +
25912 /* Before first pass, make a rough estimation of addrs[]
25913 * each bpf instruction is translated to less than 64 bytes
25914 */
25915 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25916 break;
25917 default:
25918 /* hmm, too complex filter, give up with jit compiler */
25919 - goto out;
25920 + goto error;
25921 }
25922 ilen = prog - temp;
25923 if (image) {
25924 if (unlikely(proglen + ilen > oldproglen)) {
25925 pr_err("bpb_jit_compile fatal error\n");
25926 - kfree(addrs);
25927 - module_free(NULL, image);
25928 - return;
25929 + module_free_exec(NULL, image);
25930 + goto error;
25931 }
25932 + pax_open_kernel();
25933 memcpy(image + proglen, temp, ilen);
25934 + pax_close_kernel();
25935 }
25936 proglen += ilen;
25937 addrs[i] = proglen;
25938 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25939 break;
25940 }
25941 if (proglen == oldproglen) {
25942 - image = module_alloc(max_t(unsigned int,
25943 - proglen,
25944 - sizeof(struct work_struct)));
25945 + image = module_alloc_exec(proglen);
25946 if (!image)
25947 - goto out;
25948 + goto error;
25949 }
25950 oldproglen = proglen;
25951 }
25952 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25953 bpf_flush_icache(image, image + proglen);
25954
25955 fp->bpf_func = (void *)image;
25956 - }
25957 + } else
25958 +error:
25959 + kfree(fp->work);
25960 +
25961 out:
25962 kfree(addrs);
25963 return;
25964 @@ -648,18 +659,20 @@ out:
25965
25966 static void jit_free_defer(struct work_struct *arg)
25967 {
25968 - module_free(NULL, arg);
25969 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25970 + kfree(arg);
25971 }
25972
25973 /* run from softirq, we must use a work_struct to call
25974 - * module_free() from process context
25975 + * module_free_exec() from process context
25976 */
25977 void bpf_jit_free(struct sk_filter *fp)
25978 {
25979 if (fp->bpf_func != sk_run_filter) {
25980 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25981 + struct work_struct *work = &fp->work->work;
25982
25983 INIT_WORK(work, jit_free_defer);
25984 + fp->work->image = fp->bpf_func;
25985 schedule_work(work);
25986 }
25987 }
25988 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25989 index d6aa6e8..266395a 100644
25990 --- a/arch/x86/oprofile/backtrace.c
25991 +++ b/arch/x86/oprofile/backtrace.c
25992 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25993 struct stack_frame_ia32 *fp;
25994 unsigned long bytes;
25995
25996 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25997 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25998 if (bytes != sizeof(bufhead))
25999 return NULL;
26000
26001 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26002 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26003
26004 oprofile_add_trace(bufhead[0].return_address);
26005
26006 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26007 struct stack_frame bufhead[2];
26008 unsigned long bytes;
26009
26010 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26011 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26012 if (bytes != sizeof(bufhead))
26013 return NULL;
26014
26015 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26016 {
26017 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26018
26019 - if (!user_mode_vm(regs)) {
26020 + if (!user_mode(regs)) {
26021 unsigned long stack = kernel_stack_pointer(regs);
26022 if (depth)
26023 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26024 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26025 index 140942f..8a5cc55 100644
26026 --- a/arch/x86/pci/mrst.c
26027 +++ b/arch/x86/pci/mrst.c
26028 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26029 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26030 pci_mmcfg_late_init();
26031 pcibios_enable_irq = mrst_pci_irq_enable;
26032 - pci_root_ops = pci_mrst_ops;
26033 + pax_open_kernel();
26034 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26035 + pax_close_kernel();
26036 pci_soc_mode = 1;
26037 /* Continue with standard init */
26038 return 1;
26039 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26040 index da8fe05..7ee6704 100644
26041 --- a/arch/x86/pci/pcbios.c
26042 +++ b/arch/x86/pci/pcbios.c
26043 @@ -79,50 +79,93 @@ union bios32 {
26044 static struct {
26045 unsigned long address;
26046 unsigned short segment;
26047 -} bios32_indirect = { 0, __KERNEL_CS };
26048 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26049
26050 /*
26051 * Returns the entry point for the given service, NULL on error
26052 */
26053
26054 -static unsigned long bios32_service(unsigned long service)
26055 +static unsigned long __devinit bios32_service(unsigned long service)
26056 {
26057 unsigned char return_code; /* %al */
26058 unsigned long address; /* %ebx */
26059 unsigned long length; /* %ecx */
26060 unsigned long entry; /* %edx */
26061 unsigned long flags;
26062 + struct desc_struct d, *gdt;
26063
26064 local_irq_save(flags);
26065 - __asm__("lcall *(%%edi); cld"
26066 +
26067 + gdt = get_cpu_gdt_table(smp_processor_id());
26068 +
26069 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26070 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26071 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26072 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26073 +
26074 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26075 : "=a" (return_code),
26076 "=b" (address),
26077 "=c" (length),
26078 "=d" (entry)
26079 : "0" (service),
26080 "1" (0),
26081 - "D" (&bios32_indirect));
26082 + "D" (&bios32_indirect),
26083 + "r"(__PCIBIOS_DS)
26084 + : "memory");
26085 +
26086 + pax_open_kernel();
26087 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26088 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26089 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26090 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26091 + pax_close_kernel();
26092 +
26093 local_irq_restore(flags);
26094
26095 switch (return_code) {
26096 - case 0:
26097 - return address + entry;
26098 - case 0x80: /* Not present */
26099 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26100 - return 0;
26101 - default: /* Shouldn't happen */
26102 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26103 - service, return_code);
26104 + case 0: {
26105 + int cpu;
26106 + unsigned char flags;
26107 +
26108 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26109 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26110 + printk(KERN_WARNING "bios32_service: not valid\n");
26111 return 0;
26112 + }
26113 + address = address + PAGE_OFFSET;
26114 + length += 16UL; /* some BIOSs underreport this... */
26115 + flags = 4;
26116 + if (length >= 64*1024*1024) {
26117 + length >>= PAGE_SHIFT;
26118 + flags |= 8;
26119 + }
26120 +
26121 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26122 + gdt = get_cpu_gdt_table(cpu);
26123 + pack_descriptor(&d, address, length, 0x9b, flags);
26124 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26125 + pack_descriptor(&d, address, length, 0x93, flags);
26126 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26127 + }
26128 + return entry;
26129 + }
26130 + case 0x80: /* Not present */
26131 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26132 + return 0;
26133 + default: /* Shouldn't happen */
26134 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26135 + service, return_code);
26136 + return 0;
26137 }
26138 }
26139
26140 static struct {
26141 unsigned long address;
26142 unsigned short segment;
26143 -} pci_indirect = { 0, __KERNEL_CS };
26144 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26145
26146 -static int pci_bios_present;
26147 +static int pci_bios_present __read_only;
26148
26149 static int __devinit check_pcibios(void)
26150 {
26151 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26152 unsigned long flags, pcibios_entry;
26153
26154 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26155 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26156 + pci_indirect.address = pcibios_entry;
26157
26158 local_irq_save(flags);
26159 - __asm__(
26160 - "lcall *(%%edi); cld\n\t"
26161 + __asm__("movw %w6, %%ds\n\t"
26162 + "lcall *%%ss:(%%edi); cld\n\t"
26163 + "push %%ss\n\t"
26164 + "pop %%ds\n\t"
26165 "jc 1f\n\t"
26166 "xor %%ah, %%ah\n"
26167 "1:"
26168 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26169 "=b" (ebx),
26170 "=c" (ecx)
26171 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26172 - "D" (&pci_indirect)
26173 + "D" (&pci_indirect),
26174 + "r" (__PCIBIOS_DS)
26175 : "memory");
26176 local_irq_restore(flags);
26177
26178 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26179
26180 switch (len) {
26181 case 1:
26182 - __asm__("lcall *(%%esi); cld\n\t"
26183 + __asm__("movw %w6, %%ds\n\t"
26184 + "lcall *%%ss:(%%esi); cld\n\t"
26185 + "push %%ss\n\t"
26186 + "pop %%ds\n\t"
26187 "jc 1f\n\t"
26188 "xor %%ah, %%ah\n"
26189 "1:"
26190 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26191 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26192 "b" (bx),
26193 "D" ((long)reg),
26194 - "S" (&pci_indirect));
26195 + "S" (&pci_indirect),
26196 + "r" (__PCIBIOS_DS));
26197 /*
26198 * Zero-extend the result beyond 8 bits, do not trust the
26199 * BIOS having done it:
26200 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26201 *value &= 0xff;
26202 break;
26203 case 2:
26204 - __asm__("lcall *(%%esi); cld\n\t"
26205 + __asm__("movw %w6, %%ds\n\t"
26206 + "lcall *%%ss:(%%esi); cld\n\t"
26207 + "push %%ss\n\t"
26208 + "pop %%ds\n\t"
26209 "jc 1f\n\t"
26210 "xor %%ah, %%ah\n"
26211 "1:"
26212 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26213 : "1" (PCIBIOS_READ_CONFIG_WORD),
26214 "b" (bx),
26215 "D" ((long)reg),
26216 - "S" (&pci_indirect));
26217 + "S" (&pci_indirect),
26218 + "r" (__PCIBIOS_DS));
26219 /*
26220 * Zero-extend the result beyond 16 bits, do not trust the
26221 * BIOS having done it:
26222 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26223 *value &= 0xffff;
26224 break;
26225 case 4:
26226 - __asm__("lcall *(%%esi); cld\n\t"
26227 + __asm__("movw %w6, %%ds\n\t"
26228 + "lcall *%%ss:(%%esi); cld\n\t"
26229 + "push %%ss\n\t"
26230 + "pop %%ds\n\t"
26231 "jc 1f\n\t"
26232 "xor %%ah, %%ah\n"
26233 "1:"
26234 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26235 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26236 "b" (bx),
26237 "D" ((long)reg),
26238 - "S" (&pci_indirect));
26239 + "S" (&pci_indirect),
26240 + "r" (__PCIBIOS_DS));
26241 break;
26242 }
26243
26244 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26245
26246 switch (len) {
26247 case 1:
26248 - __asm__("lcall *(%%esi); cld\n\t"
26249 + __asm__("movw %w6, %%ds\n\t"
26250 + "lcall *%%ss:(%%esi); cld\n\t"
26251 + "push %%ss\n\t"
26252 + "pop %%ds\n\t"
26253 "jc 1f\n\t"
26254 "xor %%ah, %%ah\n"
26255 "1:"
26256 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26257 "c" (value),
26258 "b" (bx),
26259 "D" ((long)reg),
26260 - "S" (&pci_indirect));
26261 + "S" (&pci_indirect),
26262 + "r" (__PCIBIOS_DS));
26263 break;
26264 case 2:
26265 - __asm__("lcall *(%%esi); cld\n\t"
26266 + __asm__("movw %w6, %%ds\n\t"
26267 + "lcall *%%ss:(%%esi); cld\n\t"
26268 + "push %%ss\n\t"
26269 + "pop %%ds\n\t"
26270 "jc 1f\n\t"
26271 "xor %%ah, %%ah\n"
26272 "1:"
26273 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26274 "c" (value),
26275 "b" (bx),
26276 "D" ((long)reg),
26277 - "S" (&pci_indirect));
26278 + "S" (&pci_indirect),
26279 + "r" (__PCIBIOS_DS));
26280 break;
26281 case 4:
26282 - __asm__("lcall *(%%esi); cld\n\t"
26283 + __asm__("movw %w6, %%ds\n\t"
26284 + "lcall *%%ss:(%%esi); cld\n\t"
26285 + "push %%ss\n\t"
26286 + "pop %%ds\n\t"
26287 "jc 1f\n\t"
26288 "xor %%ah, %%ah\n"
26289 "1:"
26290 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26291 "c" (value),
26292 "b" (bx),
26293 "D" ((long)reg),
26294 - "S" (&pci_indirect));
26295 + "S" (&pci_indirect),
26296 + "r" (__PCIBIOS_DS));
26297 break;
26298 }
26299
26300 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26301
26302 DBG("PCI: Fetching IRQ routing table... ");
26303 __asm__("push %%es\n\t"
26304 + "movw %w8, %%ds\n\t"
26305 "push %%ds\n\t"
26306 "pop %%es\n\t"
26307 - "lcall *(%%esi); cld\n\t"
26308 + "lcall *%%ss:(%%esi); cld\n\t"
26309 "pop %%es\n\t"
26310 + "push %%ss\n\t"
26311 + "pop %%ds\n"
26312 "jc 1f\n\t"
26313 "xor %%ah, %%ah\n"
26314 "1:"
26315 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26316 "1" (0),
26317 "D" ((long) &opt),
26318 "S" (&pci_indirect),
26319 - "m" (opt)
26320 + "m" (opt),
26321 + "r" (__PCIBIOS_DS)
26322 : "memory");
26323 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26324 if (ret & 0xff00)
26325 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26326 {
26327 int ret;
26328
26329 - __asm__("lcall *(%%esi); cld\n\t"
26330 + __asm__("movw %w5, %%ds\n\t"
26331 + "lcall *%%ss:(%%esi); cld\n\t"
26332 + "push %%ss\n\t"
26333 + "pop %%ds\n"
26334 "jc 1f\n\t"
26335 "xor %%ah, %%ah\n"
26336 "1:"
26337 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26338 : "0" (PCIBIOS_SET_PCI_HW_INT),
26339 "b" ((dev->bus->number << 8) | dev->devfn),
26340 "c" ((irq << 8) | (pin + 10)),
26341 - "S" (&pci_indirect));
26342 + "S" (&pci_indirect),
26343 + "r" (__PCIBIOS_DS));
26344 return !(ret & 0xff00);
26345 }
26346 EXPORT_SYMBOL(pcibios_set_irq_routing);
26347 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26348 index 40e4469..1ab536e 100644
26349 --- a/arch/x86/platform/efi/efi_32.c
26350 +++ b/arch/x86/platform/efi/efi_32.c
26351 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26352 {
26353 struct desc_ptr gdt_descr;
26354
26355 +#ifdef CONFIG_PAX_KERNEXEC
26356 + struct desc_struct d;
26357 +#endif
26358 +
26359 local_irq_save(efi_rt_eflags);
26360
26361 load_cr3(initial_page_table);
26362 __flush_tlb_all();
26363
26364 +#ifdef CONFIG_PAX_KERNEXEC
26365 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26366 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26367 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26368 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26369 +#endif
26370 +
26371 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26372 gdt_descr.size = GDT_SIZE - 1;
26373 load_gdt(&gdt_descr);
26374 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26375 {
26376 struct desc_ptr gdt_descr;
26377
26378 +#ifdef CONFIG_PAX_KERNEXEC
26379 + struct desc_struct d;
26380 +
26381 + memset(&d, 0, sizeof d);
26382 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26383 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26384 +#endif
26385 +
26386 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26387 gdt_descr.size = GDT_SIZE - 1;
26388 load_gdt(&gdt_descr);
26389 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26390 index fbe66e6..eae5e38 100644
26391 --- a/arch/x86/platform/efi/efi_stub_32.S
26392 +++ b/arch/x86/platform/efi/efi_stub_32.S
26393 @@ -6,7 +6,9 @@
26394 */
26395
26396 #include <linux/linkage.h>
26397 +#include <linux/init.h>
26398 #include <asm/page_types.h>
26399 +#include <asm/segment.h>
26400
26401 /*
26402 * efi_call_phys(void *, ...) is a function with variable parameters.
26403 @@ -20,7 +22,7 @@
26404 * service functions will comply with gcc calling convention, too.
26405 */
26406
26407 -.text
26408 +__INIT
26409 ENTRY(efi_call_phys)
26410 /*
26411 * 0. The function can only be called in Linux kernel. So CS has been
26412 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26413 * The mapping of lower virtual memory has been created in prelog and
26414 * epilog.
26415 */
26416 - movl $1f, %edx
26417 - subl $__PAGE_OFFSET, %edx
26418 - jmp *%edx
26419 +#ifdef CONFIG_PAX_KERNEXEC
26420 + movl $(__KERNEXEC_EFI_DS), %edx
26421 + mov %edx, %ds
26422 + mov %edx, %es
26423 + mov %edx, %ss
26424 + addl $2f,(1f)
26425 + ljmp *(1f)
26426 +
26427 +__INITDATA
26428 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26429 +.previous
26430 +
26431 +2:
26432 + subl $2b,(1b)
26433 +#else
26434 + jmp 1f-__PAGE_OFFSET
26435 1:
26436 +#endif
26437
26438 /*
26439 * 2. Now on the top of stack is the return
26440 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26441 * parameter 2, ..., param n. To make things easy, we save the return
26442 * address of efi_call_phys in a global variable.
26443 */
26444 - popl %edx
26445 - movl %edx, saved_return_addr
26446 - /* get the function pointer into ECX*/
26447 - popl %ecx
26448 - movl %ecx, efi_rt_function_ptr
26449 - movl $2f, %edx
26450 - subl $__PAGE_OFFSET, %edx
26451 - pushl %edx
26452 + popl (saved_return_addr)
26453 + popl (efi_rt_function_ptr)
26454
26455 /*
26456 * 3. Clear PG bit in %CR0.
26457 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26458 /*
26459 * 5. Call the physical function.
26460 */
26461 - jmp *%ecx
26462 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26463
26464 -2:
26465 /*
26466 * 6. After EFI runtime service returns, control will return to
26467 * following instruction. We'd better readjust stack pointer first.
26468 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26469 movl %cr0, %edx
26470 orl $0x80000000, %edx
26471 movl %edx, %cr0
26472 - jmp 1f
26473 -1:
26474 +
26475 /*
26476 * 8. Now restore the virtual mode from flat mode by
26477 * adding EIP with PAGE_OFFSET.
26478 */
26479 - movl $1f, %edx
26480 - jmp *%edx
26481 +#ifdef CONFIG_PAX_KERNEXEC
26482 + movl $(__KERNEL_DS), %edx
26483 + mov %edx, %ds
26484 + mov %edx, %es
26485 + mov %edx, %ss
26486 + ljmp $(__KERNEL_CS),$1f
26487 +#else
26488 + jmp 1f+__PAGE_OFFSET
26489 +#endif
26490 1:
26491
26492 /*
26493 * 9. Balance the stack. And because EAX contain the return value,
26494 * we'd better not clobber it.
26495 */
26496 - leal efi_rt_function_ptr, %edx
26497 - movl (%edx), %ecx
26498 - pushl %ecx
26499 + pushl (efi_rt_function_ptr)
26500
26501 /*
26502 - * 10. Push the saved return address onto the stack and return.
26503 + * 10. Return to the saved return address.
26504 */
26505 - leal saved_return_addr, %edx
26506 - movl (%edx), %ecx
26507 - pushl %ecx
26508 - ret
26509 + jmpl *(saved_return_addr)
26510 ENDPROC(efi_call_phys)
26511 .previous
26512
26513 -.data
26514 +__INITDATA
26515 saved_return_addr:
26516 .long 0
26517 efi_rt_function_ptr:
26518 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26519 index 4c07cca..2c8427d 100644
26520 --- a/arch/x86/platform/efi/efi_stub_64.S
26521 +++ b/arch/x86/platform/efi/efi_stub_64.S
26522 @@ -7,6 +7,7 @@
26523 */
26524
26525 #include <linux/linkage.h>
26526 +#include <asm/alternative-asm.h>
26527
26528 #define SAVE_XMM \
26529 mov %rsp, %rax; \
26530 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26531 call *%rdi
26532 addq $32, %rsp
26533 RESTORE_XMM
26534 + pax_force_retaddr 0, 1
26535 ret
26536 ENDPROC(efi_call0)
26537
26538 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26539 call *%rdi
26540 addq $32, %rsp
26541 RESTORE_XMM
26542 + pax_force_retaddr 0, 1
26543 ret
26544 ENDPROC(efi_call1)
26545
26546 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26547 call *%rdi
26548 addq $32, %rsp
26549 RESTORE_XMM
26550 + pax_force_retaddr 0, 1
26551 ret
26552 ENDPROC(efi_call2)
26553
26554 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26555 call *%rdi
26556 addq $32, %rsp
26557 RESTORE_XMM
26558 + pax_force_retaddr 0, 1
26559 ret
26560 ENDPROC(efi_call3)
26561
26562 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26563 call *%rdi
26564 addq $32, %rsp
26565 RESTORE_XMM
26566 + pax_force_retaddr 0, 1
26567 ret
26568 ENDPROC(efi_call4)
26569
26570 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26571 call *%rdi
26572 addq $48, %rsp
26573 RESTORE_XMM
26574 + pax_force_retaddr 0, 1
26575 ret
26576 ENDPROC(efi_call5)
26577
26578 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26579 call *%rdi
26580 addq $48, %rsp
26581 RESTORE_XMM
26582 + pax_force_retaddr 0, 1
26583 ret
26584 ENDPROC(efi_call6)
26585 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26586 index fd41a92..9c33628 100644
26587 --- a/arch/x86/platform/mrst/mrst.c
26588 +++ b/arch/x86/platform/mrst/mrst.c
26589 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26590 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26591 int sfi_mrtc_num;
26592
26593 -static void mrst_power_off(void)
26594 +static __noreturn void mrst_power_off(void)
26595 {
26596 + BUG();
26597 }
26598
26599 -static void mrst_reboot(void)
26600 +static __noreturn void mrst_reboot(void)
26601 {
26602 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26603 + BUG();
26604 }
26605
26606 /* parse all the mtimer info to a static mtimer array */
26607 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26608 index 218cdb1..fd55c08 100644
26609 --- a/arch/x86/power/cpu.c
26610 +++ b/arch/x86/power/cpu.c
26611 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26612 static void fix_processor_context(void)
26613 {
26614 int cpu = smp_processor_id();
26615 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26616 + struct tss_struct *t = init_tss + cpu;
26617
26618 set_tss_desc(cpu, t); /*
26619 * This just modifies memory; should not be
26620 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26621 */
26622
26623 #ifdef CONFIG_X86_64
26624 + pax_open_kernel();
26625 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26626 + pax_close_kernel();
26627
26628 syscall_init(); /* This sets MSR_*STAR and related */
26629 #endif
26630 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26631 index cbca565..bae7133 100644
26632 --- a/arch/x86/realmode/init.c
26633 +++ b/arch/x86/realmode/init.c
26634 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26635 __va(real_mode_header->trampoline_header);
26636
26637 #ifdef CONFIG_X86_32
26638 - trampoline_header->start = __pa(startup_32_smp);
26639 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26640 +
26641 +#ifdef CONFIG_PAX_KERNEXEC
26642 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26643 +#endif
26644 +
26645 + trampoline_header->boot_cs = __BOOT_CS;
26646 trampoline_header->gdt_limit = __BOOT_DS + 7;
26647 trampoline_header->gdt_base = __pa(boot_gdt);
26648 #else
26649 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26650 index 5b84a2d..a004393 100644
26651 --- a/arch/x86/realmode/rm/Makefile
26652 +++ b/arch/x86/realmode/rm/Makefile
26653 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26654 $(call cc-option, -fno-unit-at-a-time)) \
26655 $(call cc-option, -fno-stack-protector) \
26656 $(call cc-option, -mpreferred-stack-boundary=2)
26657 +ifdef CONSTIFY_PLUGIN
26658 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26659 +endif
26660 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26661 GCOV_PROFILE := n
26662 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26663 index c1b2791..f9e31c7 100644
26664 --- a/arch/x86/realmode/rm/trampoline_32.S
26665 +++ b/arch/x86/realmode/rm/trampoline_32.S
26666 @@ -25,6 +25,12 @@
26667 #include <asm/page_types.h>
26668 #include "realmode.h"
26669
26670 +#ifdef CONFIG_PAX_KERNEXEC
26671 +#define ta(X) (X)
26672 +#else
26673 +#define ta(X) (pa_ ## X)
26674 +#endif
26675 +
26676 .text
26677 .code16
26678
26679 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26680
26681 cli # We should be safe anyway
26682
26683 - movl tr_start, %eax # where we need to go
26684 -
26685 movl $0xA5A5A5A5, trampoline_status
26686 # write marker for master knows we're running
26687
26688 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26689 movw $1, %dx # protected mode (PE) bit
26690 lmsw %dx # into protected mode
26691
26692 - ljmpl $__BOOT_CS, $pa_startup_32
26693 + ljmpl *(trampoline_header)
26694
26695 .section ".text32","ax"
26696 .code32
26697 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26698 .balign 8
26699 GLOBAL(trampoline_header)
26700 tr_start: .space 4
26701 - tr_gdt_pad: .space 2
26702 + tr_boot_cs: .space 2
26703 tr_gdt: .space 6
26704 END(trampoline_header)
26705
26706 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26707 index bb360dc..3e5945f 100644
26708 --- a/arch/x86/realmode/rm/trampoline_64.S
26709 +++ b/arch/x86/realmode/rm/trampoline_64.S
26710 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26711 wrmsr
26712
26713 # Enable paging and in turn activate Long Mode
26714 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26715 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26716 movl %eax, %cr0
26717
26718 /*
26719 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26720 index 5a1847d..deccb30 100644
26721 --- a/arch/x86/tools/relocs.c
26722 +++ b/arch/x86/tools/relocs.c
26723 @@ -12,10 +12,13 @@
26724 #include <regex.h>
26725 #include <tools/le_byteshift.h>
26726
26727 +#include "../../../include/generated/autoconf.h"
26728 +
26729 static void die(char *fmt, ...);
26730
26731 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26732 static Elf32_Ehdr ehdr;
26733 +static Elf32_Phdr *phdr;
26734 static unsigned long reloc_count, reloc_idx;
26735 static unsigned long *relocs;
26736 static unsigned long reloc16_count, reloc16_idx;
26737 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26738 }
26739 }
26740
26741 +static void read_phdrs(FILE *fp)
26742 +{
26743 + unsigned int i;
26744 +
26745 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26746 + if (!phdr) {
26747 + die("Unable to allocate %d program headers\n",
26748 + ehdr.e_phnum);
26749 + }
26750 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26751 + die("Seek to %d failed: %s\n",
26752 + ehdr.e_phoff, strerror(errno));
26753 + }
26754 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26755 + die("Cannot read ELF program headers: %s\n",
26756 + strerror(errno));
26757 + }
26758 + for(i = 0; i < ehdr.e_phnum; i++) {
26759 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26760 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26761 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26762 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26763 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26764 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26765 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26766 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26767 + }
26768 +
26769 +}
26770 +
26771 static void read_shdrs(FILE *fp)
26772 {
26773 - int i;
26774 + unsigned int i;
26775 Elf32_Shdr shdr;
26776
26777 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26778 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26779
26780 static void read_strtabs(FILE *fp)
26781 {
26782 - int i;
26783 + unsigned int i;
26784 for (i = 0; i < ehdr.e_shnum; i++) {
26785 struct section *sec = &secs[i];
26786 if (sec->shdr.sh_type != SHT_STRTAB) {
26787 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26788
26789 static void read_symtabs(FILE *fp)
26790 {
26791 - int i,j;
26792 + unsigned int i,j;
26793 for (i = 0; i < ehdr.e_shnum; i++) {
26794 struct section *sec = &secs[i];
26795 if (sec->shdr.sh_type != SHT_SYMTAB) {
26796 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26797 }
26798
26799
26800 -static void read_relocs(FILE *fp)
26801 +static void read_relocs(FILE *fp, int use_real_mode)
26802 {
26803 - int i,j;
26804 + unsigned int i,j;
26805 + uint32_t base;
26806 +
26807 for (i = 0; i < ehdr.e_shnum; i++) {
26808 struct section *sec = &secs[i];
26809 if (sec->shdr.sh_type != SHT_REL) {
26810 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26811 die("Cannot read symbol table: %s\n",
26812 strerror(errno));
26813 }
26814 + base = 0;
26815 +
26816 +#ifdef CONFIG_X86_32
26817 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26818 + if (phdr[j].p_type != PT_LOAD )
26819 + continue;
26820 + 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)
26821 + continue;
26822 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26823 + break;
26824 + }
26825 +#endif
26826 +
26827 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26828 Elf32_Rel *rel = &sec->reltab[j];
26829 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26830 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26831 rel->r_info = elf32_to_cpu(rel->r_info);
26832 }
26833 }
26834 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26835
26836 static void print_absolute_symbols(void)
26837 {
26838 - int i;
26839 + unsigned int i;
26840 printf("Absolute symbols\n");
26841 printf(" Num: Value Size Type Bind Visibility Name\n");
26842 for (i = 0; i < ehdr.e_shnum; i++) {
26843 struct section *sec = &secs[i];
26844 char *sym_strtab;
26845 - int j;
26846 + unsigned int j;
26847
26848 if (sec->shdr.sh_type != SHT_SYMTAB) {
26849 continue;
26850 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26851
26852 static void print_absolute_relocs(void)
26853 {
26854 - int i, printed = 0;
26855 + unsigned int i, printed = 0;
26856
26857 for (i = 0; i < ehdr.e_shnum; i++) {
26858 struct section *sec = &secs[i];
26859 struct section *sec_applies, *sec_symtab;
26860 char *sym_strtab;
26861 Elf32_Sym *sh_symtab;
26862 - int j;
26863 + unsigned int j;
26864 if (sec->shdr.sh_type != SHT_REL) {
26865 continue;
26866 }
26867 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26868 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26869 int use_real_mode)
26870 {
26871 - int i;
26872 + unsigned int i;
26873 /* Walk through the relocations */
26874 for (i = 0; i < ehdr.e_shnum; i++) {
26875 char *sym_strtab;
26876 Elf32_Sym *sh_symtab;
26877 struct section *sec_applies, *sec_symtab;
26878 - int j;
26879 + unsigned int j;
26880 struct section *sec = &secs[i];
26881
26882 if (sec->shdr.sh_type != SHT_REL) {
26883 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26884 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26885 r_type = ELF32_R_TYPE(rel->r_info);
26886
26887 + if (!use_real_mode) {
26888 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26889 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26890 + continue;
26891 +
26892 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26893 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26894 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26895 + continue;
26896 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26897 + continue;
26898 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26899 + continue;
26900 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26901 + continue;
26902 +#endif
26903 + }
26904 +
26905 shn_abs = sym->st_shndx == SHN_ABS;
26906
26907 switch (r_type) {
26908 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26909
26910 static void emit_relocs(int as_text, int use_real_mode)
26911 {
26912 - int i;
26913 + unsigned int i;
26914 /* Count how many relocations I have and allocate space for them. */
26915 reloc_count = 0;
26916 walk_relocs(count_reloc, use_real_mode);
26917 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
26918 fname, strerror(errno));
26919 }
26920 read_ehdr(fp);
26921 + read_phdrs(fp);
26922 read_shdrs(fp);
26923 read_strtabs(fp);
26924 read_symtabs(fp);
26925 - read_relocs(fp);
26926 + read_relocs(fp, use_real_mode);
26927 if (show_absolute_syms) {
26928 print_absolute_symbols();
26929 return 0;
26930 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26931 index fd14be1..e3c79c0 100644
26932 --- a/arch/x86/vdso/Makefile
26933 +++ b/arch/x86/vdso/Makefile
26934 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26935 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26936 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26937
26938 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26939 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26940 GCOV_PROFILE := n
26941
26942 #
26943 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26944 index 66e6d93..587f435 100644
26945 --- a/arch/x86/vdso/vdso32-setup.c
26946 +++ b/arch/x86/vdso/vdso32-setup.c
26947 @@ -25,6 +25,7 @@
26948 #include <asm/tlbflush.h>
26949 #include <asm/vdso.h>
26950 #include <asm/proto.h>
26951 +#include <asm/mman.h>
26952
26953 enum {
26954 VDSO_DISABLED = 0,
26955 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26956 void enable_sep_cpu(void)
26957 {
26958 int cpu = get_cpu();
26959 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26960 + struct tss_struct *tss = init_tss + cpu;
26961
26962 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26963 put_cpu();
26964 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26965 gate_vma.vm_start = FIXADDR_USER_START;
26966 gate_vma.vm_end = FIXADDR_USER_END;
26967 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26968 - gate_vma.vm_page_prot = __P101;
26969 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26970
26971 return 0;
26972 }
26973 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26974 if (compat)
26975 addr = VDSO_HIGH_BASE;
26976 else {
26977 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26978 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26979 if (IS_ERR_VALUE(addr)) {
26980 ret = addr;
26981 goto up_fail;
26982 }
26983 }
26984
26985 - current->mm->context.vdso = (void *)addr;
26986 + current->mm->context.vdso = addr;
26987
26988 if (compat_uses_vma || !compat) {
26989 /*
26990 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26991 }
26992
26993 current_thread_info()->sysenter_return =
26994 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26995 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26996
26997 up_fail:
26998 if (ret)
26999 - current->mm->context.vdso = NULL;
27000 + current->mm->context.vdso = 0;
27001
27002 up_write(&mm->mmap_sem);
27003
27004 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27005
27006 const char *arch_vma_name(struct vm_area_struct *vma)
27007 {
27008 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27009 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27010 return "[vdso]";
27011 +
27012 +#ifdef CONFIG_PAX_SEGMEXEC
27013 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27014 + return "[vdso]";
27015 +#endif
27016 +
27017 return NULL;
27018 }
27019
27020 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27021 * Check to see if the corresponding task was created in compat vdso
27022 * mode.
27023 */
27024 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27025 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27026 return &gate_vma;
27027 return NULL;
27028 }
27029 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27030 index 00aaf04..4a26505 100644
27031 --- a/arch/x86/vdso/vma.c
27032 +++ b/arch/x86/vdso/vma.c
27033 @@ -16,8 +16,6 @@
27034 #include <asm/vdso.h>
27035 #include <asm/page.h>
27036
27037 -unsigned int __read_mostly vdso_enabled = 1;
27038 -
27039 extern char vdso_start[], vdso_end[];
27040 extern unsigned short vdso_sync_cpuid;
27041
27042 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27043 * unaligned here as a result of stack start randomization.
27044 */
27045 addr = PAGE_ALIGN(addr);
27046 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27047
27048 return addr;
27049 }
27050 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27051 unsigned size)
27052 {
27053 struct mm_struct *mm = current->mm;
27054 - unsigned long addr;
27055 + unsigned long addr = 0;
27056 int ret;
27057
27058 - if (!vdso_enabled)
27059 - return 0;
27060 -
27061 down_write(&mm->mmap_sem);
27062 +
27063 +#ifdef CONFIG_PAX_RANDMMAP
27064 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27065 +#endif
27066 +
27067 addr = vdso_addr(mm->start_stack, size);
27068 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27069 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27070 if (IS_ERR_VALUE(addr)) {
27071 ret = addr;
27072 goto up_fail;
27073 }
27074
27075 - current->mm->context.vdso = (void *)addr;
27076 + mm->context.vdso = addr;
27077
27078 ret = install_special_mapping(mm, addr, size,
27079 VM_READ|VM_EXEC|
27080 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27081 pages);
27082 - if (ret) {
27083 - current->mm->context.vdso = NULL;
27084 - goto up_fail;
27085 - }
27086 + if (ret)
27087 + mm->context.vdso = 0;
27088
27089 up_fail:
27090 up_write(&mm->mmap_sem);
27091 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27092 vdsox32_size);
27093 }
27094 #endif
27095 -
27096 -static __init int vdso_setup(char *s)
27097 -{
27098 - vdso_enabled = simple_strtoul(s, NULL, 0);
27099 - return 0;
27100 -}
27101 -__setup("vdso=", vdso_setup);
27102 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27103 index ff962d4..2bb5e83 100644
27104 --- a/arch/x86/xen/enlighten.c
27105 +++ b/arch/x86/xen/enlighten.c
27106 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27107
27108 struct shared_info xen_dummy_shared_info;
27109
27110 -void *xen_initial_gdt;
27111 -
27112 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27113 __read_mostly int xen_have_vector_callback;
27114 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27115 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27116 #endif
27117 };
27118
27119 -static void xen_reboot(int reason)
27120 +static __noreturn void xen_reboot(int reason)
27121 {
27122 struct sched_shutdown r = { .reason = reason };
27123
27124 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27125 - BUG();
27126 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27127 + BUG();
27128 }
27129
27130 -static void xen_restart(char *msg)
27131 +static __noreturn void xen_restart(char *msg)
27132 {
27133 xen_reboot(SHUTDOWN_reboot);
27134 }
27135
27136 -static void xen_emergency_restart(void)
27137 +static __noreturn void xen_emergency_restart(void)
27138 {
27139 xen_reboot(SHUTDOWN_reboot);
27140 }
27141
27142 -static void xen_machine_halt(void)
27143 +static __noreturn void xen_machine_halt(void)
27144 {
27145 xen_reboot(SHUTDOWN_poweroff);
27146 }
27147
27148 -static void xen_machine_power_off(void)
27149 +static __noreturn void xen_machine_power_off(void)
27150 {
27151 if (pm_power_off)
27152 pm_power_off();
27153 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27154 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27155
27156 /* Work out if we support NX */
27157 - x86_configure_nx();
27158 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27159 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27160 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27161 + unsigned l, h;
27162 +
27163 + __supported_pte_mask |= _PAGE_NX;
27164 + rdmsr(MSR_EFER, l, h);
27165 + l |= EFER_NX;
27166 + wrmsr(MSR_EFER, l, h);
27167 + }
27168 +#endif
27169
27170 xen_setup_features();
27171
27172 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27173
27174 machine_ops = xen_machine_ops;
27175
27176 - /*
27177 - * The only reliable way to retain the initial address of the
27178 - * percpu gdt_page is to remember it here, so we can go and
27179 - * mark it RW later, when the initial percpu area is freed.
27180 - */
27181 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27182 -
27183 xen_smp_init();
27184
27185 #ifdef CONFIG_ACPI_NUMA
27186 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27187 index 3a73785..0d30df2 100644
27188 --- a/arch/x86/xen/mmu.c
27189 +++ b/arch/x86/xen/mmu.c
27190 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27191 convert_pfn_mfn(init_level4_pgt);
27192 convert_pfn_mfn(level3_ident_pgt);
27193 convert_pfn_mfn(level3_kernel_pgt);
27194 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27195 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27196 + convert_pfn_mfn(level3_vmemmap_pgt);
27197
27198 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27199 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27200 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27201 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27202 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27203 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27204 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27205 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27206 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27207 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27208 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27209 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27210 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27211
27212 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27213 pv_mmu_ops.set_pud = xen_set_pud;
27214 #if PAGETABLE_LEVELS == 4
27215 pv_mmu_ops.set_pgd = xen_set_pgd;
27216 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27217 #endif
27218
27219 /* This will work as long as patching hasn't happened yet
27220 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27221 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27222 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27223 .set_pgd = xen_set_pgd_hyper,
27224 + .set_pgd_batched = xen_set_pgd_hyper,
27225
27226 .alloc_pud = xen_alloc_pmd_init,
27227 .release_pud = xen_release_pmd_init,
27228 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27229 index afb250d..627075f 100644
27230 --- a/arch/x86/xen/smp.c
27231 +++ b/arch/x86/xen/smp.c
27232 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27233 {
27234 BUG_ON(smp_processor_id() != 0);
27235 native_smp_prepare_boot_cpu();
27236 -
27237 - /* We've switched to the "real" per-cpu gdt, so make sure the
27238 - old memory can be recycled */
27239 - make_lowmem_page_readwrite(xen_initial_gdt);
27240 -
27241 xen_filter_cpu_maps();
27242 xen_setup_vcpu_info_placement();
27243 }
27244 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27245 gdt = get_cpu_gdt_table(cpu);
27246
27247 ctxt->flags = VGCF_IN_KERNEL;
27248 - ctxt->user_regs.ds = __USER_DS;
27249 - ctxt->user_regs.es = __USER_DS;
27250 + ctxt->user_regs.ds = __KERNEL_DS;
27251 + ctxt->user_regs.es = __KERNEL_DS;
27252 ctxt->user_regs.ss = __KERNEL_DS;
27253 #ifdef CONFIG_X86_32
27254 ctxt->user_regs.fs = __KERNEL_PERCPU;
27255 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27256 + savesegment(gs, ctxt->user_regs.gs);
27257 #else
27258 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27259 #endif
27260 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27261 int rc;
27262
27263 per_cpu(current_task, cpu) = idle;
27264 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27265 #ifdef CONFIG_X86_32
27266 irq_ctx_init(cpu);
27267 #else
27268 clear_tsk_thread_flag(idle, TIF_FORK);
27269 - per_cpu(kernel_stack, cpu) =
27270 - (unsigned long)task_stack_page(idle) -
27271 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27272 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27273 #endif
27274 xen_setup_runstate_info(cpu);
27275 xen_setup_timer(cpu);
27276 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27277 index f9643fc..602e8af 100644
27278 --- a/arch/x86/xen/xen-asm_32.S
27279 +++ b/arch/x86/xen/xen-asm_32.S
27280 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27281 ESP_OFFSET=4 # bytes pushed onto stack
27282
27283 /*
27284 - * Store vcpu_info pointer for easy access. Do it this way to
27285 - * avoid having to reload %fs
27286 + * Store vcpu_info pointer for easy access.
27287 */
27288 #ifdef CONFIG_SMP
27289 - GET_THREAD_INFO(%eax)
27290 - movl TI_cpu(%eax), %eax
27291 - movl __per_cpu_offset(,%eax,4), %eax
27292 - mov xen_vcpu(%eax), %eax
27293 + push %fs
27294 + mov $(__KERNEL_PERCPU), %eax
27295 + mov %eax, %fs
27296 + mov PER_CPU_VAR(xen_vcpu), %eax
27297 + pop %fs
27298 #else
27299 movl xen_vcpu, %eax
27300 #endif
27301 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27302 index aaa7291..3f77960 100644
27303 --- a/arch/x86/xen/xen-head.S
27304 +++ b/arch/x86/xen/xen-head.S
27305 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27306 #ifdef CONFIG_X86_32
27307 mov %esi,xen_start_info
27308 mov $init_thread_union+THREAD_SIZE,%esp
27309 +#ifdef CONFIG_SMP
27310 + movl $cpu_gdt_table,%edi
27311 + movl $__per_cpu_load,%eax
27312 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27313 + rorl $16,%eax
27314 + movb %al,__KERNEL_PERCPU + 4(%edi)
27315 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27316 + movl $__per_cpu_end - 1,%eax
27317 + subl $__per_cpu_start,%eax
27318 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27319 +#endif
27320 #else
27321 mov %rsi,xen_start_info
27322 mov $init_thread_union+THREAD_SIZE,%rsp
27323 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27324 index 202d4c1..99b072a 100644
27325 --- a/arch/x86/xen/xen-ops.h
27326 +++ b/arch/x86/xen/xen-ops.h
27327 @@ -10,8 +10,6 @@
27328 extern const char xen_hypervisor_callback[];
27329 extern const char xen_failsafe_callback[];
27330
27331 -extern void *xen_initial_gdt;
27332 -
27333 struct trap_info;
27334 void xen_copy_trap_info(struct trap_info *traps);
27335
27336 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27337 index 525bd3d..ef888b1 100644
27338 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27339 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27340 @@ -119,9 +119,9 @@
27341 ----------------------------------------------------------------------*/
27342
27343 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27344 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27345 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27346 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27347 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27348
27349 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27350 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27351 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27352 index 2f33760..835e50a 100644
27353 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27354 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27355 @@ -11,6 +11,7 @@
27356 #ifndef _XTENSA_CORE_H
27357 #define _XTENSA_CORE_H
27358
27359 +#include <linux/const.h>
27360
27361 /****************************************************************************
27362 Parameters Useful for Any Code, USER or PRIVILEGED
27363 @@ -112,9 +113,9 @@
27364 ----------------------------------------------------------------------*/
27365
27366 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27367 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27368 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27369 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27370 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27371
27372 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27373 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27374 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27375 index af00795..2bb8105 100644
27376 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27377 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27378 @@ -11,6 +11,7 @@
27379 #ifndef _XTENSA_CORE_CONFIGURATION_H
27380 #define _XTENSA_CORE_CONFIGURATION_H
27381
27382 +#include <linux/const.h>
27383
27384 /****************************************************************************
27385 Parameters Useful for Any Code, USER or PRIVILEGED
27386 @@ -118,9 +119,9 @@
27387 ----------------------------------------------------------------------*/
27388
27389 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27390 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27391 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27392 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27393 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27394
27395 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27396 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27397 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27398 index 58916af..9cb880b 100644
27399 --- a/block/blk-iopoll.c
27400 +++ b/block/blk-iopoll.c
27401 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27402 }
27403 EXPORT_SYMBOL(blk_iopoll_complete);
27404
27405 -static void blk_iopoll_softirq(struct softirq_action *h)
27406 +static void blk_iopoll_softirq(void)
27407 {
27408 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27409 int rearm = 0, budget = blk_iopoll_budget;
27410 diff --git a/block/blk-map.c b/block/blk-map.c
27411 index 623e1cd..ca1e109 100644
27412 --- a/block/blk-map.c
27413 +++ b/block/blk-map.c
27414 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27415 if (!len || !kbuf)
27416 return -EINVAL;
27417
27418 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27419 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27420 if (do_copy)
27421 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27422 else
27423 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27424 index 467c8de..4bddc6d 100644
27425 --- a/block/blk-softirq.c
27426 +++ b/block/blk-softirq.c
27427 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27428 * Softirq action handler - move entries to local list and loop over them
27429 * while passing them to the queue registered handler.
27430 */
27431 -static void blk_done_softirq(struct softirq_action *h)
27432 +static void blk_done_softirq(void)
27433 {
27434 struct list_head *cpu_list, local_list;
27435
27436 diff --git a/block/bsg.c b/block/bsg.c
27437 index ff64ae3..593560c 100644
27438 --- a/block/bsg.c
27439 +++ b/block/bsg.c
27440 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27441 struct sg_io_v4 *hdr, struct bsg_device *bd,
27442 fmode_t has_write_perm)
27443 {
27444 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27445 + unsigned char *cmdptr;
27446 +
27447 if (hdr->request_len > BLK_MAX_CDB) {
27448 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27449 if (!rq->cmd)
27450 return -ENOMEM;
27451 - }
27452 + cmdptr = rq->cmd;
27453 + } else
27454 + cmdptr = tmpcmd;
27455
27456 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27457 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27458 hdr->request_len))
27459 return -EFAULT;
27460
27461 + if (cmdptr != rq->cmd)
27462 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27463 +
27464 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27465 if (blk_verify_command(rq->cmd, has_write_perm))
27466 return -EPERM;
27467 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27468 index 7c668c8..db3521c 100644
27469 --- a/block/compat_ioctl.c
27470 +++ b/block/compat_ioctl.c
27471 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27472 err |= __get_user(f->spec1, &uf->spec1);
27473 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27474 err |= __get_user(name, &uf->name);
27475 - f->name = compat_ptr(name);
27476 + f->name = (void __force_kernel *)compat_ptr(name);
27477 if (err) {
27478 err = -EFAULT;
27479 goto out;
27480 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27481 index 6296b40..417c00f 100644
27482 --- a/block/partitions/efi.c
27483 +++ b/block/partitions/efi.c
27484 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27485 if (!gpt)
27486 return NULL;
27487
27488 + if (!le32_to_cpu(gpt->num_partition_entries))
27489 + return NULL;
27490 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27491 + if (!pte)
27492 + return NULL;
27493 +
27494 count = le32_to_cpu(gpt->num_partition_entries) *
27495 le32_to_cpu(gpt->sizeof_partition_entry);
27496 - if (!count)
27497 - return NULL;
27498 - pte = kzalloc(count, GFP_KERNEL);
27499 - if (!pte)
27500 - return NULL;
27501 -
27502 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27503 (u8 *) pte,
27504 count) < count) {
27505 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27506 index 9a87daa..fb17486 100644
27507 --- a/block/scsi_ioctl.c
27508 +++ b/block/scsi_ioctl.c
27509 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27510 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27511 struct sg_io_hdr *hdr, fmode_t mode)
27512 {
27513 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27514 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27515 + unsigned char *cmdptr;
27516 +
27517 + if (rq->cmd != rq->__cmd)
27518 + cmdptr = rq->cmd;
27519 + else
27520 + cmdptr = tmpcmd;
27521 +
27522 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27523 return -EFAULT;
27524 +
27525 + if (cmdptr != rq->cmd)
27526 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27527 +
27528 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27529 return -EPERM;
27530
27531 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27532 int err;
27533 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27534 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27535 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27536 + unsigned char *cmdptr;
27537
27538 if (!sic)
27539 return -EINVAL;
27540 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27541 */
27542 err = -EFAULT;
27543 rq->cmd_len = cmdlen;
27544 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27545 +
27546 + if (rq->cmd != rq->__cmd)
27547 + cmdptr = rq->cmd;
27548 + else
27549 + cmdptr = tmpcmd;
27550 +
27551 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27552 goto error;
27553
27554 + if (rq->cmd != cmdptr)
27555 + memcpy(rq->cmd, cmdptr, cmdlen);
27556 +
27557 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27558 goto error;
27559
27560 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27561 index 671d4d6..5f24030 100644
27562 --- a/crypto/cryptd.c
27563 +++ b/crypto/cryptd.c
27564 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27565
27566 struct cryptd_blkcipher_request_ctx {
27567 crypto_completion_t complete;
27568 -};
27569 +} __no_const;
27570
27571 struct cryptd_hash_ctx {
27572 struct crypto_shash *child;
27573 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27574
27575 struct cryptd_aead_request_ctx {
27576 crypto_completion_t complete;
27577 -};
27578 +} __no_const;
27579
27580 static void cryptd_queue_worker(struct work_struct *work);
27581
27582 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27583 index e6defd8..c26a225 100644
27584 --- a/drivers/acpi/apei/cper.c
27585 +++ b/drivers/acpi/apei/cper.c
27586 @@ -38,12 +38,12 @@
27587 */
27588 u64 cper_next_record_id(void)
27589 {
27590 - static atomic64_t seq;
27591 + static atomic64_unchecked_t seq;
27592
27593 - if (!atomic64_read(&seq))
27594 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27595 + if (!atomic64_read_unchecked(&seq))
27596 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27597
27598 - return atomic64_inc_return(&seq);
27599 + return atomic64_inc_return_unchecked(&seq);
27600 }
27601 EXPORT_SYMBOL_GPL(cper_next_record_id);
27602
27603 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27604 index 7586544..636a2f0 100644
27605 --- a/drivers/acpi/ec_sys.c
27606 +++ b/drivers/acpi/ec_sys.c
27607 @@ -12,6 +12,7 @@
27608 #include <linux/acpi.h>
27609 #include <linux/debugfs.h>
27610 #include <linux/module.h>
27611 +#include <linux/uaccess.h>
27612 #include "internal.h"
27613
27614 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27615 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27616 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27617 */
27618 unsigned int size = EC_SPACE_SIZE;
27619 - u8 *data = (u8 *) buf;
27620 + u8 data;
27621 loff_t init_off = *off;
27622 int err = 0;
27623
27624 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27625 size = count;
27626
27627 while (size) {
27628 - err = ec_read(*off, &data[*off - init_off]);
27629 + err = ec_read(*off, &data);
27630 if (err)
27631 return err;
27632 + if (put_user(data, &buf[*off - init_off]))
27633 + return -EFAULT;
27634 *off += 1;
27635 size--;
27636 }
27637 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27638
27639 unsigned int size = count;
27640 loff_t init_off = *off;
27641 - u8 *data = (u8 *) buf;
27642 int err = 0;
27643
27644 if (*off >= EC_SPACE_SIZE)
27645 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27646 }
27647
27648 while (size) {
27649 - u8 byte_write = data[*off - init_off];
27650 + u8 byte_write;
27651 + if (get_user(byte_write, &buf[*off - init_off]))
27652 + return -EFAULT;
27653 err = ec_write(*off, byte_write);
27654 if (err)
27655 return err;
27656 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27657 index 251c7b62..000462d 100644
27658 --- a/drivers/acpi/proc.c
27659 +++ b/drivers/acpi/proc.c
27660 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27661 size_t count, loff_t * ppos)
27662 {
27663 struct list_head *node, *next;
27664 - char strbuf[5];
27665 - char str[5] = "";
27666 - unsigned int len = count;
27667 + char strbuf[5] = {0};
27668
27669 - if (len > 4)
27670 - len = 4;
27671 - if (len < 0)
27672 + if (count > 4)
27673 + count = 4;
27674 + if (copy_from_user(strbuf, buffer, count))
27675 return -EFAULT;
27676 -
27677 - if (copy_from_user(strbuf, buffer, len))
27678 - return -EFAULT;
27679 - strbuf[len] = '\0';
27680 - sscanf(strbuf, "%s", str);
27681 + strbuf[count] = '\0';
27682
27683 mutex_lock(&acpi_device_lock);
27684 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27685 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27686 if (!dev->wakeup.flags.valid)
27687 continue;
27688
27689 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27690 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27691 if (device_can_wakeup(&dev->dev)) {
27692 bool enable = !device_may_wakeup(&dev->dev);
27693 device_set_wakeup_enable(&dev->dev, enable);
27694 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27695 index bbac51e..4c094f9 100644
27696 --- a/drivers/acpi/processor_driver.c
27697 +++ b/drivers/acpi/processor_driver.c
27698 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27699 return 0;
27700 #endif
27701
27702 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27703 + BUG_ON(pr->id >= nr_cpu_ids);
27704
27705 /*
27706 * Buggy BIOS check
27707 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27708 index cece3a4..0845256 100644
27709 --- a/drivers/ata/libata-core.c
27710 +++ b/drivers/ata/libata-core.c
27711 @@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27712 struct ata_port *ap;
27713 unsigned int tag;
27714
27715 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27716 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27717 ap = qc->ap;
27718
27719 qc->flags = 0;
27720 @@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27721 struct ata_port *ap;
27722 struct ata_link *link;
27723
27724 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27725 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27726 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27727 ap = qc->ap;
27728 link = qc->dev->link;
27729 @@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27730 return;
27731
27732 spin_lock(&lock);
27733 + pax_open_kernel();
27734
27735 for (cur = ops->inherits; cur; cur = cur->inherits) {
27736 void **inherit = (void **)cur;
27737 @@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27738 if (IS_ERR(*pp))
27739 *pp = NULL;
27740
27741 - ops->inherits = NULL;
27742 + *(struct ata_port_operations **)&ops->inherits = NULL;
27743
27744 + pax_close_kernel();
27745 spin_unlock(&lock);
27746 }
27747
27748 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27749 index ac6a5be..c7176b1 100644
27750 --- a/drivers/ata/pata_arasan_cf.c
27751 +++ b/drivers/ata/pata_arasan_cf.c
27752 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27753 /* Handle platform specific quirks */
27754 if (pdata->quirk) {
27755 if (pdata->quirk & CF_BROKEN_PIO) {
27756 - ap->ops->set_piomode = NULL;
27757 + pax_open_kernel();
27758 + *(void **)&ap->ops->set_piomode = NULL;
27759 + pax_close_kernel();
27760 ap->pio_mask = 0;
27761 }
27762 if (pdata->quirk & CF_BROKEN_MWDMA)
27763 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27764 index f9b983a..887b9d8 100644
27765 --- a/drivers/atm/adummy.c
27766 +++ b/drivers/atm/adummy.c
27767 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27768 vcc->pop(vcc, skb);
27769 else
27770 dev_kfree_skb_any(skb);
27771 - atomic_inc(&vcc->stats->tx);
27772 + atomic_inc_unchecked(&vcc->stats->tx);
27773
27774 return 0;
27775 }
27776 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27777 index 89b30f3..7964211 100644
27778 --- a/drivers/atm/ambassador.c
27779 +++ b/drivers/atm/ambassador.c
27780 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27781 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27782
27783 // VC layer stats
27784 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27785 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27786
27787 // free the descriptor
27788 kfree (tx_descr);
27789 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27790 dump_skb ("<<<", vc, skb);
27791
27792 // VC layer stats
27793 - atomic_inc(&atm_vcc->stats->rx);
27794 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27795 __net_timestamp(skb);
27796 // end of our responsibility
27797 atm_vcc->push (atm_vcc, skb);
27798 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27799 } else {
27800 PRINTK (KERN_INFO, "dropped over-size frame");
27801 // should we count this?
27802 - atomic_inc(&atm_vcc->stats->rx_drop);
27803 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27804 }
27805
27806 } else {
27807 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27808 }
27809
27810 if (check_area (skb->data, skb->len)) {
27811 - atomic_inc(&atm_vcc->stats->tx_err);
27812 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27813 return -ENOMEM; // ?
27814 }
27815
27816 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27817 index b22d71c..d6e1049 100644
27818 --- a/drivers/atm/atmtcp.c
27819 +++ b/drivers/atm/atmtcp.c
27820 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27821 if (vcc->pop) vcc->pop(vcc,skb);
27822 else dev_kfree_skb(skb);
27823 if (dev_data) return 0;
27824 - atomic_inc(&vcc->stats->tx_err);
27825 + atomic_inc_unchecked(&vcc->stats->tx_err);
27826 return -ENOLINK;
27827 }
27828 size = skb->len+sizeof(struct atmtcp_hdr);
27829 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27830 if (!new_skb) {
27831 if (vcc->pop) vcc->pop(vcc,skb);
27832 else dev_kfree_skb(skb);
27833 - atomic_inc(&vcc->stats->tx_err);
27834 + atomic_inc_unchecked(&vcc->stats->tx_err);
27835 return -ENOBUFS;
27836 }
27837 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27838 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27839 if (vcc->pop) vcc->pop(vcc,skb);
27840 else dev_kfree_skb(skb);
27841 out_vcc->push(out_vcc,new_skb);
27842 - atomic_inc(&vcc->stats->tx);
27843 - atomic_inc(&out_vcc->stats->rx);
27844 + atomic_inc_unchecked(&vcc->stats->tx);
27845 + atomic_inc_unchecked(&out_vcc->stats->rx);
27846 return 0;
27847 }
27848
27849 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27850 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27851 read_unlock(&vcc_sklist_lock);
27852 if (!out_vcc) {
27853 - atomic_inc(&vcc->stats->tx_err);
27854 + atomic_inc_unchecked(&vcc->stats->tx_err);
27855 goto done;
27856 }
27857 skb_pull(skb,sizeof(struct atmtcp_hdr));
27858 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27859 __net_timestamp(new_skb);
27860 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27861 out_vcc->push(out_vcc,new_skb);
27862 - atomic_inc(&vcc->stats->tx);
27863 - atomic_inc(&out_vcc->stats->rx);
27864 + atomic_inc_unchecked(&vcc->stats->tx);
27865 + atomic_inc_unchecked(&out_vcc->stats->rx);
27866 done:
27867 if (vcc->pop) vcc->pop(vcc,skb);
27868 else dev_kfree_skb(skb);
27869 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27870 index 2059ee4..faf51c7 100644
27871 --- a/drivers/atm/eni.c
27872 +++ b/drivers/atm/eni.c
27873 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27874 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27875 vcc->dev->number);
27876 length = 0;
27877 - atomic_inc(&vcc->stats->rx_err);
27878 + atomic_inc_unchecked(&vcc->stats->rx_err);
27879 }
27880 else {
27881 length = ATM_CELL_SIZE-1; /* no HEC */
27882 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27883 size);
27884 }
27885 eff = length = 0;
27886 - atomic_inc(&vcc->stats->rx_err);
27887 + atomic_inc_unchecked(&vcc->stats->rx_err);
27888 }
27889 else {
27890 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27891 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27892 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27893 vcc->dev->number,vcc->vci,length,size << 2,descr);
27894 length = eff = 0;
27895 - atomic_inc(&vcc->stats->rx_err);
27896 + atomic_inc_unchecked(&vcc->stats->rx_err);
27897 }
27898 }
27899 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27900 @@ -767,7 +767,7 @@ rx_dequeued++;
27901 vcc->push(vcc,skb);
27902 pushed++;
27903 }
27904 - atomic_inc(&vcc->stats->rx);
27905 + atomic_inc_unchecked(&vcc->stats->rx);
27906 }
27907 wake_up(&eni_dev->rx_wait);
27908 }
27909 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27910 PCI_DMA_TODEVICE);
27911 if (vcc->pop) vcc->pop(vcc,skb);
27912 else dev_kfree_skb_irq(skb);
27913 - atomic_inc(&vcc->stats->tx);
27914 + atomic_inc_unchecked(&vcc->stats->tx);
27915 wake_up(&eni_dev->tx_wait);
27916 dma_complete++;
27917 }
27918 @@ -1567,7 +1567,7 @@ tx_complete++;
27919 /*--------------------------------- entries ---------------------------------*/
27920
27921
27922 -static const char *media_name[] __devinitdata = {
27923 +static const char *media_name[] __devinitconst = {
27924 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27925 "UTP", "05?", "06?", "07?", /* 4- 7 */
27926 "TAXI","09?", "10?", "11?", /* 8-11 */
27927 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27928 index 86fed1b..6dc4721 100644
27929 --- a/drivers/atm/firestream.c
27930 +++ b/drivers/atm/firestream.c
27931 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27932 }
27933 }
27934
27935 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27936 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27937
27938 fs_dprintk (FS_DEBUG_TXMEM, "i");
27939 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27940 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27941 #endif
27942 skb_put (skb, qe->p1 & 0xffff);
27943 ATM_SKB(skb)->vcc = atm_vcc;
27944 - atomic_inc(&atm_vcc->stats->rx);
27945 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27946 __net_timestamp(skb);
27947 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27948 atm_vcc->push (atm_vcc, skb);
27949 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27950 kfree (pe);
27951 }
27952 if (atm_vcc)
27953 - atomic_inc(&atm_vcc->stats->rx_drop);
27954 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27955 break;
27956 case 0x1f: /* Reassembly abort: no buffers. */
27957 /* Silently increment error counter. */
27958 if (atm_vcc)
27959 - atomic_inc(&atm_vcc->stats->rx_drop);
27960 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27961 break;
27962 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27963 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27964 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27965 index 361f5ae..7fc552d 100644
27966 --- a/drivers/atm/fore200e.c
27967 +++ b/drivers/atm/fore200e.c
27968 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27969 #endif
27970 /* check error condition */
27971 if (*entry->status & STATUS_ERROR)
27972 - atomic_inc(&vcc->stats->tx_err);
27973 + atomic_inc_unchecked(&vcc->stats->tx_err);
27974 else
27975 - atomic_inc(&vcc->stats->tx);
27976 + atomic_inc_unchecked(&vcc->stats->tx);
27977 }
27978 }
27979
27980 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27981 if (skb == NULL) {
27982 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27983
27984 - atomic_inc(&vcc->stats->rx_drop);
27985 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27986 return -ENOMEM;
27987 }
27988
27989 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27990
27991 dev_kfree_skb_any(skb);
27992
27993 - atomic_inc(&vcc->stats->rx_drop);
27994 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27995 return -ENOMEM;
27996 }
27997
27998 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27999
28000 vcc->push(vcc, skb);
28001 - atomic_inc(&vcc->stats->rx);
28002 + atomic_inc_unchecked(&vcc->stats->rx);
28003
28004 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28005
28006 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28007 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28008 fore200e->atm_dev->number,
28009 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28010 - atomic_inc(&vcc->stats->rx_err);
28011 + atomic_inc_unchecked(&vcc->stats->rx_err);
28012 }
28013 }
28014
28015 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28016 goto retry_here;
28017 }
28018
28019 - atomic_inc(&vcc->stats->tx_err);
28020 + atomic_inc_unchecked(&vcc->stats->tx_err);
28021
28022 fore200e->tx_sat++;
28023 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28024 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28025 index b182c2f..1c6fa8a 100644
28026 --- a/drivers/atm/he.c
28027 +++ b/drivers/atm/he.c
28028 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28029
28030 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28031 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28032 - atomic_inc(&vcc->stats->rx_drop);
28033 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28034 goto return_host_buffers;
28035 }
28036
28037 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28038 RBRQ_LEN_ERR(he_dev->rbrq_head)
28039 ? "LEN_ERR" : "",
28040 vcc->vpi, vcc->vci);
28041 - atomic_inc(&vcc->stats->rx_err);
28042 + atomic_inc_unchecked(&vcc->stats->rx_err);
28043 goto return_host_buffers;
28044 }
28045
28046 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28047 vcc->push(vcc, skb);
28048 spin_lock(&he_dev->global_lock);
28049
28050 - atomic_inc(&vcc->stats->rx);
28051 + atomic_inc_unchecked(&vcc->stats->rx);
28052
28053 return_host_buffers:
28054 ++pdus_assembled;
28055 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28056 tpd->vcc->pop(tpd->vcc, tpd->skb);
28057 else
28058 dev_kfree_skb_any(tpd->skb);
28059 - atomic_inc(&tpd->vcc->stats->tx_err);
28060 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28061 }
28062 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28063 return;
28064 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28065 vcc->pop(vcc, skb);
28066 else
28067 dev_kfree_skb_any(skb);
28068 - atomic_inc(&vcc->stats->tx_err);
28069 + atomic_inc_unchecked(&vcc->stats->tx_err);
28070 return -EINVAL;
28071 }
28072
28073 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28074 vcc->pop(vcc, skb);
28075 else
28076 dev_kfree_skb_any(skb);
28077 - atomic_inc(&vcc->stats->tx_err);
28078 + atomic_inc_unchecked(&vcc->stats->tx_err);
28079 return -EINVAL;
28080 }
28081 #endif
28082 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28083 vcc->pop(vcc, skb);
28084 else
28085 dev_kfree_skb_any(skb);
28086 - atomic_inc(&vcc->stats->tx_err);
28087 + atomic_inc_unchecked(&vcc->stats->tx_err);
28088 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28089 return -ENOMEM;
28090 }
28091 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28092 vcc->pop(vcc, skb);
28093 else
28094 dev_kfree_skb_any(skb);
28095 - atomic_inc(&vcc->stats->tx_err);
28096 + atomic_inc_unchecked(&vcc->stats->tx_err);
28097 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28098 return -ENOMEM;
28099 }
28100 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28101 __enqueue_tpd(he_dev, tpd, cid);
28102 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28103
28104 - atomic_inc(&vcc->stats->tx);
28105 + atomic_inc_unchecked(&vcc->stats->tx);
28106
28107 return 0;
28108 }
28109 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28110 index 7d01c2a..4e3ac01 100644
28111 --- a/drivers/atm/horizon.c
28112 +++ b/drivers/atm/horizon.c
28113 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28114 {
28115 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28116 // VC layer stats
28117 - atomic_inc(&vcc->stats->rx);
28118 + atomic_inc_unchecked(&vcc->stats->rx);
28119 __net_timestamp(skb);
28120 // end of our responsibility
28121 vcc->push (vcc, skb);
28122 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28123 dev->tx_iovec = NULL;
28124
28125 // VC layer stats
28126 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28127 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28128
28129 // free the skb
28130 hrz_kfree_skb (skb);
28131 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28132 index 8974bd2..b856f85 100644
28133 --- a/drivers/atm/idt77252.c
28134 +++ b/drivers/atm/idt77252.c
28135 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28136 else
28137 dev_kfree_skb(skb);
28138
28139 - atomic_inc(&vcc->stats->tx);
28140 + atomic_inc_unchecked(&vcc->stats->tx);
28141 }
28142
28143 atomic_dec(&scq->used);
28144 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28145 if ((sb = dev_alloc_skb(64)) == NULL) {
28146 printk("%s: Can't allocate buffers for aal0.\n",
28147 card->name);
28148 - atomic_add(i, &vcc->stats->rx_drop);
28149 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28150 break;
28151 }
28152 if (!atm_charge(vcc, sb->truesize)) {
28153 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28154 card->name);
28155 - atomic_add(i - 1, &vcc->stats->rx_drop);
28156 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28157 dev_kfree_skb(sb);
28158 break;
28159 }
28160 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28161 ATM_SKB(sb)->vcc = vcc;
28162 __net_timestamp(sb);
28163 vcc->push(vcc, sb);
28164 - atomic_inc(&vcc->stats->rx);
28165 + atomic_inc_unchecked(&vcc->stats->rx);
28166
28167 cell += ATM_CELL_PAYLOAD;
28168 }
28169 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28170 "(CDC: %08x)\n",
28171 card->name, len, rpp->len, readl(SAR_REG_CDC));
28172 recycle_rx_pool_skb(card, rpp);
28173 - atomic_inc(&vcc->stats->rx_err);
28174 + atomic_inc_unchecked(&vcc->stats->rx_err);
28175 return;
28176 }
28177 if (stat & SAR_RSQE_CRC) {
28178 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28179 recycle_rx_pool_skb(card, rpp);
28180 - atomic_inc(&vcc->stats->rx_err);
28181 + atomic_inc_unchecked(&vcc->stats->rx_err);
28182 return;
28183 }
28184 if (skb_queue_len(&rpp->queue) > 1) {
28185 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28186 RXPRINTK("%s: Can't alloc RX skb.\n",
28187 card->name);
28188 recycle_rx_pool_skb(card, rpp);
28189 - atomic_inc(&vcc->stats->rx_err);
28190 + atomic_inc_unchecked(&vcc->stats->rx_err);
28191 return;
28192 }
28193 if (!atm_charge(vcc, skb->truesize)) {
28194 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28195 __net_timestamp(skb);
28196
28197 vcc->push(vcc, skb);
28198 - atomic_inc(&vcc->stats->rx);
28199 + atomic_inc_unchecked(&vcc->stats->rx);
28200
28201 return;
28202 }
28203 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28204 __net_timestamp(skb);
28205
28206 vcc->push(vcc, skb);
28207 - atomic_inc(&vcc->stats->rx);
28208 + atomic_inc_unchecked(&vcc->stats->rx);
28209
28210 if (skb->truesize > SAR_FB_SIZE_3)
28211 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28212 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28213 if (vcc->qos.aal != ATM_AAL0) {
28214 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28215 card->name, vpi, vci);
28216 - atomic_inc(&vcc->stats->rx_drop);
28217 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28218 goto drop;
28219 }
28220
28221 if ((sb = dev_alloc_skb(64)) == NULL) {
28222 printk("%s: Can't allocate buffers for AAL0.\n",
28223 card->name);
28224 - atomic_inc(&vcc->stats->rx_err);
28225 + atomic_inc_unchecked(&vcc->stats->rx_err);
28226 goto drop;
28227 }
28228
28229 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28230 ATM_SKB(sb)->vcc = vcc;
28231 __net_timestamp(sb);
28232 vcc->push(vcc, sb);
28233 - atomic_inc(&vcc->stats->rx);
28234 + atomic_inc_unchecked(&vcc->stats->rx);
28235
28236 drop:
28237 skb_pull(queue, 64);
28238 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28239
28240 if (vc == NULL) {
28241 printk("%s: NULL connection in send().\n", card->name);
28242 - atomic_inc(&vcc->stats->tx_err);
28243 + atomic_inc_unchecked(&vcc->stats->tx_err);
28244 dev_kfree_skb(skb);
28245 return -EINVAL;
28246 }
28247 if (!test_bit(VCF_TX, &vc->flags)) {
28248 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28249 - atomic_inc(&vcc->stats->tx_err);
28250 + atomic_inc_unchecked(&vcc->stats->tx_err);
28251 dev_kfree_skb(skb);
28252 return -EINVAL;
28253 }
28254 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28255 break;
28256 default:
28257 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28258 - atomic_inc(&vcc->stats->tx_err);
28259 + atomic_inc_unchecked(&vcc->stats->tx_err);
28260 dev_kfree_skb(skb);
28261 return -EINVAL;
28262 }
28263
28264 if (skb_shinfo(skb)->nr_frags != 0) {
28265 printk("%s: No scatter-gather yet.\n", card->name);
28266 - atomic_inc(&vcc->stats->tx_err);
28267 + atomic_inc_unchecked(&vcc->stats->tx_err);
28268 dev_kfree_skb(skb);
28269 return -EINVAL;
28270 }
28271 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28272
28273 err = queue_skb(card, vc, skb, oam);
28274 if (err) {
28275 - atomic_inc(&vcc->stats->tx_err);
28276 + atomic_inc_unchecked(&vcc->stats->tx_err);
28277 dev_kfree_skb(skb);
28278 return err;
28279 }
28280 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28281 skb = dev_alloc_skb(64);
28282 if (!skb) {
28283 printk("%s: Out of memory in send_oam().\n", card->name);
28284 - atomic_inc(&vcc->stats->tx_err);
28285 + atomic_inc_unchecked(&vcc->stats->tx_err);
28286 return -ENOMEM;
28287 }
28288 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28289 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28290 index d438601..8b98495 100644
28291 --- a/drivers/atm/iphase.c
28292 +++ b/drivers/atm/iphase.c
28293 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28294 status = (u_short) (buf_desc_ptr->desc_mode);
28295 if (status & (RX_CER | RX_PTE | RX_OFL))
28296 {
28297 - atomic_inc(&vcc->stats->rx_err);
28298 + atomic_inc_unchecked(&vcc->stats->rx_err);
28299 IF_ERR(printk("IA: bad packet, dropping it");)
28300 if (status & RX_CER) {
28301 IF_ERR(printk(" cause: packet CRC error\n");)
28302 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28303 len = dma_addr - buf_addr;
28304 if (len > iadev->rx_buf_sz) {
28305 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28306 - atomic_inc(&vcc->stats->rx_err);
28307 + atomic_inc_unchecked(&vcc->stats->rx_err);
28308 goto out_free_desc;
28309 }
28310
28311 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28312 ia_vcc = INPH_IA_VCC(vcc);
28313 if (ia_vcc == NULL)
28314 {
28315 - atomic_inc(&vcc->stats->rx_err);
28316 + atomic_inc_unchecked(&vcc->stats->rx_err);
28317 atm_return(vcc, skb->truesize);
28318 dev_kfree_skb_any(skb);
28319 goto INCR_DLE;
28320 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28321 if ((length > iadev->rx_buf_sz) || (length >
28322 (skb->len - sizeof(struct cpcs_trailer))))
28323 {
28324 - atomic_inc(&vcc->stats->rx_err);
28325 + atomic_inc_unchecked(&vcc->stats->rx_err);
28326 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28327 length, skb->len);)
28328 atm_return(vcc, skb->truesize);
28329 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28330
28331 IF_RX(printk("rx_dle_intr: skb push");)
28332 vcc->push(vcc,skb);
28333 - atomic_inc(&vcc->stats->rx);
28334 + atomic_inc_unchecked(&vcc->stats->rx);
28335 iadev->rx_pkt_cnt++;
28336 }
28337 INCR_DLE:
28338 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28339 {
28340 struct k_sonet_stats *stats;
28341 stats = &PRIV(_ia_dev[board])->sonet_stats;
28342 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28343 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28344 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28345 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28346 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28347 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28348 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28349 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28350 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28351 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28352 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28353 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28354 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28355 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28356 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28357 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28358 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28359 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28360 }
28361 ia_cmds.status = 0;
28362 break;
28363 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28364 if ((desc == 0) || (desc > iadev->num_tx_desc))
28365 {
28366 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28367 - atomic_inc(&vcc->stats->tx);
28368 + atomic_inc_unchecked(&vcc->stats->tx);
28369 if (vcc->pop)
28370 vcc->pop(vcc, skb);
28371 else
28372 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28373 ATM_DESC(skb) = vcc->vci;
28374 skb_queue_tail(&iadev->tx_dma_q, skb);
28375
28376 - atomic_inc(&vcc->stats->tx);
28377 + atomic_inc_unchecked(&vcc->stats->tx);
28378 iadev->tx_pkt_cnt++;
28379 /* Increment transaction counter */
28380 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28381
28382 #if 0
28383 /* add flow control logic */
28384 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28385 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28386 if (iavcc->vc_desc_cnt > 10) {
28387 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28388 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28389 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28390 index 68c7588..7036683 100644
28391 --- a/drivers/atm/lanai.c
28392 +++ b/drivers/atm/lanai.c
28393 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28394 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28395 lanai_endtx(lanai, lvcc);
28396 lanai_free_skb(lvcc->tx.atmvcc, skb);
28397 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28398 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28399 }
28400
28401 /* Try to fill the buffer - don't call unless there is backlog */
28402 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28403 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28404 __net_timestamp(skb);
28405 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28406 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28407 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28408 out:
28409 lvcc->rx.buf.ptr = end;
28410 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28411 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28412 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28413 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28414 lanai->stats.service_rxnotaal5++;
28415 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28416 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28417 return 0;
28418 }
28419 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28420 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28421 int bytes;
28422 read_unlock(&vcc_sklist_lock);
28423 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28424 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28425 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28426 lvcc->stats.x.aal5.service_trash++;
28427 bytes = (SERVICE_GET_END(s) * 16) -
28428 (((unsigned long) lvcc->rx.buf.ptr) -
28429 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28430 }
28431 if (s & SERVICE_STREAM) {
28432 read_unlock(&vcc_sklist_lock);
28433 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28434 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28435 lvcc->stats.x.aal5.service_stream++;
28436 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28437 "PDU on VCI %d!\n", lanai->number, vci);
28438 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28439 return 0;
28440 }
28441 DPRINTK("got rx crc error on vci %d\n", vci);
28442 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28443 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28444 lvcc->stats.x.aal5.service_rxcrc++;
28445 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28446 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28447 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28448 index 1c70c45..300718d 100644
28449 --- a/drivers/atm/nicstar.c
28450 +++ b/drivers/atm/nicstar.c
28451 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28452 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28453 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28454 card->index);
28455 - atomic_inc(&vcc->stats->tx_err);
28456 + atomic_inc_unchecked(&vcc->stats->tx_err);
28457 dev_kfree_skb_any(skb);
28458 return -EINVAL;
28459 }
28460 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28461 if (!vc->tx) {
28462 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28463 card->index);
28464 - atomic_inc(&vcc->stats->tx_err);
28465 + atomic_inc_unchecked(&vcc->stats->tx_err);
28466 dev_kfree_skb_any(skb);
28467 return -EINVAL;
28468 }
28469 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28470 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28471 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28472 card->index);
28473 - atomic_inc(&vcc->stats->tx_err);
28474 + atomic_inc_unchecked(&vcc->stats->tx_err);
28475 dev_kfree_skb_any(skb);
28476 return -EINVAL;
28477 }
28478
28479 if (skb_shinfo(skb)->nr_frags != 0) {
28480 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28481 - atomic_inc(&vcc->stats->tx_err);
28482 + atomic_inc_unchecked(&vcc->stats->tx_err);
28483 dev_kfree_skb_any(skb);
28484 return -EINVAL;
28485 }
28486 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28487 }
28488
28489 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28490 - atomic_inc(&vcc->stats->tx_err);
28491 + atomic_inc_unchecked(&vcc->stats->tx_err);
28492 dev_kfree_skb_any(skb);
28493 return -EIO;
28494 }
28495 - atomic_inc(&vcc->stats->tx);
28496 + atomic_inc_unchecked(&vcc->stats->tx);
28497
28498 return 0;
28499 }
28500 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28501 printk
28502 ("nicstar%d: Can't allocate buffers for aal0.\n",
28503 card->index);
28504 - atomic_add(i, &vcc->stats->rx_drop);
28505 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28506 break;
28507 }
28508 if (!atm_charge(vcc, sb->truesize)) {
28509 RXPRINTK
28510 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28511 card->index);
28512 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28513 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28514 dev_kfree_skb_any(sb);
28515 break;
28516 }
28517 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28518 ATM_SKB(sb)->vcc = vcc;
28519 __net_timestamp(sb);
28520 vcc->push(vcc, sb);
28521 - atomic_inc(&vcc->stats->rx);
28522 + atomic_inc_unchecked(&vcc->stats->rx);
28523 cell += ATM_CELL_PAYLOAD;
28524 }
28525
28526 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28527 if (iovb == NULL) {
28528 printk("nicstar%d: Out of iovec buffers.\n",
28529 card->index);
28530 - atomic_inc(&vcc->stats->rx_drop);
28531 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28532 recycle_rx_buf(card, skb);
28533 return;
28534 }
28535 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28536 small or large buffer itself. */
28537 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28538 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28539 - atomic_inc(&vcc->stats->rx_err);
28540 + atomic_inc_unchecked(&vcc->stats->rx_err);
28541 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28542 NS_MAX_IOVECS);
28543 NS_PRV_IOVCNT(iovb) = 0;
28544 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28545 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28546 card->index);
28547 which_list(card, skb);
28548 - atomic_inc(&vcc->stats->rx_err);
28549 + atomic_inc_unchecked(&vcc->stats->rx_err);
28550 recycle_rx_buf(card, skb);
28551 vc->rx_iov = NULL;
28552 recycle_iov_buf(card, iovb);
28553 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28554 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28555 card->index);
28556 which_list(card, skb);
28557 - atomic_inc(&vcc->stats->rx_err);
28558 + atomic_inc_unchecked(&vcc->stats->rx_err);
28559 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28560 NS_PRV_IOVCNT(iovb));
28561 vc->rx_iov = NULL;
28562 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28563 printk(" - PDU size mismatch.\n");
28564 else
28565 printk(".\n");
28566 - atomic_inc(&vcc->stats->rx_err);
28567 + atomic_inc_unchecked(&vcc->stats->rx_err);
28568 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28569 NS_PRV_IOVCNT(iovb));
28570 vc->rx_iov = NULL;
28571 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28572 /* skb points to a small buffer */
28573 if (!atm_charge(vcc, skb->truesize)) {
28574 push_rxbufs(card, skb);
28575 - atomic_inc(&vcc->stats->rx_drop);
28576 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28577 } else {
28578 skb_put(skb, len);
28579 dequeue_sm_buf(card, skb);
28580 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28581 ATM_SKB(skb)->vcc = vcc;
28582 __net_timestamp(skb);
28583 vcc->push(vcc, skb);
28584 - atomic_inc(&vcc->stats->rx);
28585 + atomic_inc_unchecked(&vcc->stats->rx);
28586 }
28587 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28588 struct sk_buff *sb;
28589 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28590 if (len <= NS_SMBUFSIZE) {
28591 if (!atm_charge(vcc, sb->truesize)) {
28592 push_rxbufs(card, sb);
28593 - atomic_inc(&vcc->stats->rx_drop);
28594 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28595 } else {
28596 skb_put(sb, len);
28597 dequeue_sm_buf(card, sb);
28598 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28599 ATM_SKB(sb)->vcc = vcc;
28600 __net_timestamp(sb);
28601 vcc->push(vcc, sb);
28602 - atomic_inc(&vcc->stats->rx);
28603 + atomic_inc_unchecked(&vcc->stats->rx);
28604 }
28605
28606 push_rxbufs(card, skb);
28607 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28608
28609 if (!atm_charge(vcc, skb->truesize)) {
28610 push_rxbufs(card, skb);
28611 - atomic_inc(&vcc->stats->rx_drop);
28612 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28613 } else {
28614 dequeue_lg_buf(card, skb);
28615 #ifdef NS_USE_DESTRUCTORS
28616 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28617 ATM_SKB(skb)->vcc = vcc;
28618 __net_timestamp(skb);
28619 vcc->push(vcc, skb);
28620 - atomic_inc(&vcc->stats->rx);
28621 + atomic_inc_unchecked(&vcc->stats->rx);
28622 }
28623
28624 push_rxbufs(card, sb);
28625 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28626 printk
28627 ("nicstar%d: Out of huge buffers.\n",
28628 card->index);
28629 - atomic_inc(&vcc->stats->rx_drop);
28630 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28631 recycle_iovec_rx_bufs(card,
28632 (struct iovec *)
28633 iovb->data,
28634 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28635 card->hbpool.count++;
28636 } else
28637 dev_kfree_skb_any(hb);
28638 - atomic_inc(&vcc->stats->rx_drop);
28639 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28640 } else {
28641 /* Copy the small buffer to the huge buffer */
28642 sb = (struct sk_buff *)iov->iov_base;
28643 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28644 #endif /* NS_USE_DESTRUCTORS */
28645 __net_timestamp(hb);
28646 vcc->push(vcc, hb);
28647 - atomic_inc(&vcc->stats->rx);
28648 + atomic_inc_unchecked(&vcc->stats->rx);
28649 }
28650 }
28651
28652 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28653 index 9851093..adb2b1e 100644
28654 --- a/drivers/atm/solos-pci.c
28655 +++ b/drivers/atm/solos-pci.c
28656 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28657 }
28658 atm_charge(vcc, skb->truesize);
28659 vcc->push(vcc, skb);
28660 - atomic_inc(&vcc->stats->rx);
28661 + atomic_inc_unchecked(&vcc->stats->rx);
28662 break;
28663
28664 case PKT_STATUS:
28665 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28666 vcc = SKB_CB(oldskb)->vcc;
28667
28668 if (vcc) {
28669 - atomic_inc(&vcc->stats->tx);
28670 + atomic_inc_unchecked(&vcc->stats->tx);
28671 solos_pop(vcc, oldskb);
28672 } else
28673 dev_kfree_skb_irq(oldskb);
28674 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28675 index 0215934..ce9f5b1 100644
28676 --- a/drivers/atm/suni.c
28677 +++ b/drivers/atm/suni.c
28678 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28679
28680
28681 #define ADD_LIMITED(s,v) \
28682 - atomic_add((v),&stats->s); \
28683 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28684 + atomic_add_unchecked((v),&stats->s); \
28685 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28686
28687
28688 static void suni_hz(unsigned long from_timer)
28689 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28690 index 5120a96..e2572bd 100644
28691 --- a/drivers/atm/uPD98402.c
28692 +++ b/drivers/atm/uPD98402.c
28693 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28694 struct sonet_stats tmp;
28695 int error = 0;
28696
28697 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28698 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28699 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28700 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28701 if (zero && !error) {
28702 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28703
28704
28705 #define ADD_LIMITED(s,v) \
28706 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28707 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28708 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28709 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28710 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28711 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28712
28713
28714 static void stat_event(struct atm_dev *dev)
28715 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28716 if (reason & uPD98402_INT_PFM) stat_event(dev);
28717 if (reason & uPD98402_INT_PCO) {
28718 (void) GET(PCOCR); /* clear interrupt cause */
28719 - atomic_add(GET(HECCT),
28720 + atomic_add_unchecked(GET(HECCT),
28721 &PRIV(dev)->sonet_stats.uncorr_hcs);
28722 }
28723 if ((reason & uPD98402_INT_RFO) &&
28724 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28725 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28726 uPD98402_INT_LOS),PIMR); /* enable them */
28727 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28728 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28729 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28730 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28731 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28732 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28733 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28734 return 0;
28735 }
28736
28737 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28738 index abe4e20..83c4727 100644
28739 --- a/drivers/atm/zatm.c
28740 +++ b/drivers/atm/zatm.c
28741 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28742 }
28743 if (!size) {
28744 dev_kfree_skb_irq(skb);
28745 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28746 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28747 continue;
28748 }
28749 if (!atm_charge(vcc,skb->truesize)) {
28750 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28751 skb->len = size;
28752 ATM_SKB(skb)->vcc = vcc;
28753 vcc->push(vcc,skb);
28754 - atomic_inc(&vcc->stats->rx);
28755 + atomic_inc_unchecked(&vcc->stats->rx);
28756 }
28757 zout(pos & 0xffff,MTA(mbx));
28758 #if 0 /* probably a stupid idea */
28759 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28760 skb_queue_head(&zatm_vcc->backlog,skb);
28761 break;
28762 }
28763 - atomic_inc(&vcc->stats->tx);
28764 + atomic_inc_unchecked(&vcc->stats->tx);
28765 wake_up(&zatm_vcc->tx_wait);
28766 }
28767
28768 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28769 index 765c3a2..771ace6 100644
28770 --- a/drivers/base/devtmpfs.c
28771 +++ b/drivers/base/devtmpfs.c
28772 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28773 if (!thread)
28774 return 0;
28775
28776 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28777 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28778 if (err)
28779 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28780 else
28781 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28782 index cbb463b..babe2cf 100644
28783 --- a/drivers/base/power/wakeup.c
28784 +++ b/drivers/base/power/wakeup.c
28785 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28786 * They need to be modified together atomically, so it's better to use one
28787 * atomic variable to hold them both.
28788 */
28789 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28790 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28791
28792 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28793 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28794
28795 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28796 {
28797 - unsigned int comb = atomic_read(&combined_event_count);
28798 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28799
28800 *cnt = (comb >> IN_PROGRESS_BITS);
28801 *inpr = comb & MAX_IN_PROGRESS;
28802 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28803 ws->start_prevent_time = ws->last_time;
28804
28805 /* Increment the counter of events in progress. */
28806 - cec = atomic_inc_return(&combined_event_count);
28807 + cec = atomic_inc_return_unchecked(&combined_event_count);
28808
28809 trace_wakeup_source_activate(ws->name, cec);
28810 }
28811 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28812 * Increment the counter of registered wakeup events and decrement the
28813 * couter of wakeup events in progress simultaneously.
28814 */
28815 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28816 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28817 trace_wakeup_source_deactivate(ws->name, cec);
28818
28819 split_counters(&cnt, &inpr);
28820 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28821 index b0f553b..77b928b 100644
28822 --- a/drivers/block/cciss.c
28823 +++ b/drivers/block/cciss.c
28824 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28825 int err;
28826 u32 cp;
28827
28828 + memset(&arg64, 0, sizeof(arg64));
28829 +
28830 err = 0;
28831 err |=
28832 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28833 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28834 while (!list_empty(&h->reqQ)) {
28835 c = list_entry(h->reqQ.next, CommandList_struct, list);
28836 /* can't do anything if fifo is full */
28837 - if ((h->access.fifo_full(h))) {
28838 + if ((h->access->fifo_full(h))) {
28839 dev_warn(&h->pdev->dev, "fifo full\n");
28840 break;
28841 }
28842 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28843 h->Qdepth--;
28844
28845 /* Tell the controller execute command */
28846 - h->access.submit_command(h, c);
28847 + h->access->submit_command(h, c);
28848
28849 /* Put job onto the completed Q */
28850 addQ(&h->cmpQ, c);
28851 @@ -3443,17 +3445,17 @@ startio:
28852
28853 static inline unsigned long get_next_completion(ctlr_info_t *h)
28854 {
28855 - return h->access.command_completed(h);
28856 + return h->access->command_completed(h);
28857 }
28858
28859 static inline int interrupt_pending(ctlr_info_t *h)
28860 {
28861 - return h->access.intr_pending(h);
28862 + return h->access->intr_pending(h);
28863 }
28864
28865 static inline long interrupt_not_for_us(ctlr_info_t *h)
28866 {
28867 - return ((h->access.intr_pending(h) == 0) ||
28868 + return ((h->access->intr_pending(h) == 0) ||
28869 (h->interrupts_enabled == 0));
28870 }
28871
28872 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28873 u32 a;
28874
28875 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28876 - return h->access.command_completed(h);
28877 + return h->access->command_completed(h);
28878
28879 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28880 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28881 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28882 trans_support & CFGTBL_Trans_use_short_tags);
28883
28884 /* Change the access methods to the performant access methods */
28885 - h->access = SA5_performant_access;
28886 + h->access = &SA5_performant_access;
28887 h->transMethod = CFGTBL_Trans_Performant;
28888
28889 return;
28890 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28891 if (prod_index < 0)
28892 return -ENODEV;
28893 h->product_name = products[prod_index].product_name;
28894 - h->access = *(products[prod_index].access);
28895 + h->access = products[prod_index].access;
28896
28897 if (cciss_board_disabled(h)) {
28898 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28899 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28900 }
28901
28902 /* make sure the board interrupts are off */
28903 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28904 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28905 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28906 if (rc)
28907 goto clean2;
28908 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28909 * fake ones to scoop up any residual completions.
28910 */
28911 spin_lock_irqsave(&h->lock, flags);
28912 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28913 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28914 spin_unlock_irqrestore(&h->lock, flags);
28915 free_irq(h->intr[h->intr_mode], h);
28916 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28917 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28918 dev_info(&h->pdev->dev, "Board READY.\n");
28919 dev_info(&h->pdev->dev,
28920 "Waiting for stale completions to drain.\n");
28921 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28922 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28923 msleep(10000);
28924 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28925 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28926
28927 rc = controller_reset_failed(h->cfgtable);
28928 if (rc)
28929 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28930 cciss_scsi_setup(h);
28931
28932 /* Turn the interrupts on so we can service requests */
28933 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28934 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28935
28936 /* Get the firmware version */
28937 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28938 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28939 kfree(flush_buf);
28940 if (return_code != IO_OK)
28941 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28942 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28943 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28944 free_irq(h->intr[h->intr_mode], h);
28945 }
28946
28947 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28948 index 7fda30e..eb5dfe0 100644
28949 --- a/drivers/block/cciss.h
28950 +++ b/drivers/block/cciss.h
28951 @@ -101,7 +101,7 @@ struct ctlr_info
28952 /* information about each logical volume */
28953 drive_info_struct *drv[CISS_MAX_LUN];
28954
28955 - struct access_method access;
28956 + struct access_method *access;
28957
28958 /* queue and queue Info */
28959 struct list_head reqQ;
28960 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28961 index 9125bbe..eede5c8 100644
28962 --- a/drivers/block/cpqarray.c
28963 +++ b/drivers/block/cpqarray.c
28964 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28965 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28966 goto Enomem4;
28967 }
28968 - hba[i]->access.set_intr_mask(hba[i], 0);
28969 + hba[i]->access->set_intr_mask(hba[i], 0);
28970 if (request_irq(hba[i]->intr, do_ida_intr,
28971 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28972 {
28973 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28974 add_timer(&hba[i]->timer);
28975
28976 /* Enable IRQ now that spinlock and rate limit timer are set up */
28977 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28978 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28979
28980 for(j=0; j<NWD; j++) {
28981 struct gendisk *disk = ida_gendisk[i][j];
28982 @@ -694,7 +694,7 @@ DBGINFO(
28983 for(i=0; i<NR_PRODUCTS; i++) {
28984 if (board_id == products[i].board_id) {
28985 c->product_name = products[i].product_name;
28986 - c->access = *(products[i].access);
28987 + c->access = products[i].access;
28988 break;
28989 }
28990 }
28991 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28992 hba[ctlr]->intr = intr;
28993 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28994 hba[ctlr]->product_name = products[j].product_name;
28995 - hba[ctlr]->access = *(products[j].access);
28996 + hba[ctlr]->access = products[j].access;
28997 hba[ctlr]->ctlr = ctlr;
28998 hba[ctlr]->board_id = board_id;
28999 hba[ctlr]->pci_dev = NULL; /* not PCI */
29000 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29001
29002 while((c = h->reqQ) != NULL) {
29003 /* Can't do anything if we're busy */
29004 - if (h->access.fifo_full(h) == 0)
29005 + if (h->access->fifo_full(h) == 0)
29006 return;
29007
29008 /* Get the first entry from the request Q */
29009 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29010 h->Qdepth--;
29011
29012 /* Tell the controller to do our bidding */
29013 - h->access.submit_command(h, c);
29014 + h->access->submit_command(h, c);
29015
29016 /* Get onto the completion Q */
29017 addQ(&h->cmpQ, c);
29018 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29019 unsigned long flags;
29020 __u32 a,a1;
29021
29022 - istat = h->access.intr_pending(h);
29023 + istat = h->access->intr_pending(h);
29024 /* Is this interrupt for us? */
29025 if (istat == 0)
29026 return IRQ_NONE;
29027 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29028 */
29029 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29030 if (istat & FIFO_NOT_EMPTY) {
29031 - while((a = h->access.command_completed(h))) {
29032 + while((a = h->access->command_completed(h))) {
29033 a1 = a; a &= ~3;
29034 if ((c = h->cmpQ) == NULL)
29035 {
29036 @@ -1449,11 +1449,11 @@ static int sendcmd(
29037 /*
29038 * Disable interrupt
29039 */
29040 - info_p->access.set_intr_mask(info_p, 0);
29041 + info_p->access->set_intr_mask(info_p, 0);
29042 /* Make sure there is room in the command FIFO */
29043 /* Actually it should be completely empty at this time. */
29044 for (i = 200000; i > 0; i--) {
29045 - temp = info_p->access.fifo_full(info_p);
29046 + temp = info_p->access->fifo_full(info_p);
29047 if (temp != 0) {
29048 break;
29049 }
29050 @@ -1466,7 +1466,7 @@ DBG(
29051 /*
29052 * Send the cmd
29053 */
29054 - info_p->access.submit_command(info_p, c);
29055 + info_p->access->submit_command(info_p, c);
29056 complete = pollcomplete(ctlr);
29057
29058 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29059 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29060 * we check the new geometry. Then turn interrupts back on when
29061 * we're done.
29062 */
29063 - host->access.set_intr_mask(host, 0);
29064 + host->access->set_intr_mask(host, 0);
29065 getgeometry(ctlr);
29066 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29067 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29068
29069 for(i=0; i<NWD; i++) {
29070 struct gendisk *disk = ida_gendisk[ctlr][i];
29071 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29072 /* Wait (up to 2 seconds) for a command to complete */
29073
29074 for (i = 200000; i > 0; i--) {
29075 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29076 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29077 if (done == 0) {
29078 udelay(10); /* a short fixed delay */
29079 } else
29080 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29081 index be73e9d..7fbf140 100644
29082 --- a/drivers/block/cpqarray.h
29083 +++ b/drivers/block/cpqarray.h
29084 @@ -99,7 +99,7 @@ struct ctlr_info {
29085 drv_info_t drv[NWD];
29086 struct proc_dir_entry *proc;
29087
29088 - struct access_method access;
29089 + struct access_method *access;
29090
29091 cmdlist_t *reqQ;
29092 cmdlist_t *cmpQ;
29093 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29094 index 02f013a..afeba24 100644
29095 --- a/drivers/block/drbd/drbd_int.h
29096 +++ b/drivers/block/drbd/drbd_int.h
29097 @@ -735,7 +735,7 @@ struct drbd_request;
29098 struct drbd_epoch {
29099 struct list_head list;
29100 unsigned int barrier_nr;
29101 - atomic_t epoch_size; /* increased on every request added. */
29102 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29103 atomic_t active; /* increased on every req. added, and dec on every finished. */
29104 unsigned long flags;
29105 };
29106 @@ -1110,7 +1110,7 @@ struct drbd_conf {
29107 void *int_dig_in;
29108 void *int_dig_vv;
29109 wait_queue_head_t seq_wait;
29110 - atomic_t packet_seq;
29111 + atomic_unchecked_t packet_seq;
29112 unsigned int peer_seq;
29113 spinlock_t peer_seq_lock;
29114 unsigned int minor;
29115 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29116
29117 static inline void drbd_tcp_cork(struct socket *sock)
29118 {
29119 - int __user val = 1;
29120 + int val = 1;
29121 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29122 - (char __user *)&val, sizeof(val));
29123 + (char __force_user *)&val, sizeof(val));
29124 }
29125
29126 static inline void drbd_tcp_uncork(struct socket *sock)
29127 {
29128 - int __user val = 0;
29129 + int val = 0;
29130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29131 - (char __user *)&val, sizeof(val));
29132 + (char __force_user *)&val, sizeof(val));
29133 }
29134
29135 static inline void drbd_tcp_nodelay(struct socket *sock)
29136 {
29137 - int __user val = 1;
29138 + int val = 1;
29139 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29140 - (char __user *)&val, sizeof(val));
29141 + (char __force_user *)&val, sizeof(val));
29142 }
29143
29144 static inline void drbd_tcp_quickack(struct socket *sock)
29145 {
29146 - int __user val = 2;
29147 + int val = 2;
29148 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29149 - (char __user *)&val, sizeof(val));
29150 + (char __force_user *)&val, sizeof(val));
29151 }
29152
29153 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29154 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29155 index 920ede2..cb827ba 100644
29156 --- a/drivers/block/drbd/drbd_main.c
29157 +++ b/drivers/block/drbd/drbd_main.c
29158 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29159 p.sector = sector;
29160 p.block_id = block_id;
29161 p.blksize = blksize;
29162 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29163 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29164
29165 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29166 return false;
29167 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29168
29169 p.sector = cpu_to_be64(req->sector);
29170 p.block_id = (unsigned long)req;
29171 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29172 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29173
29174 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29175
29176 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29177 atomic_set(&mdev->unacked_cnt, 0);
29178 atomic_set(&mdev->local_cnt, 0);
29179 atomic_set(&mdev->net_cnt, 0);
29180 - atomic_set(&mdev->packet_seq, 0);
29181 + atomic_set_unchecked(&mdev->packet_seq, 0);
29182 atomic_set(&mdev->pp_in_use, 0);
29183 atomic_set(&mdev->pp_in_use_by_net, 0);
29184 atomic_set(&mdev->rs_sect_in, 0);
29185 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29186 mdev->receiver.t_state);
29187
29188 /* no need to lock it, I'm the only thread alive */
29189 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29190 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29191 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29192 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29193 mdev->al_writ_cnt =
29194 mdev->bm_writ_cnt =
29195 mdev->read_cnt =
29196 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29197 index 6d4de6a..7b7ad4b 100644
29198 --- a/drivers/block/drbd/drbd_nl.c
29199 +++ b/drivers/block/drbd/drbd_nl.c
29200 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29201 module_put(THIS_MODULE);
29202 }
29203
29204 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29205 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29206
29207 static unsigned short *
29208 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29209 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29210 cn_reply->id.idx = CN_IDX_DRBD;
29211 cn_reply->id.val = CN_VAL_DRBD;
29212
29213 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29214 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29215 cn_reply->ack = 0; /* not used here. */
29216 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29217 (int)((char *)tl - (char *)reply->tag_list);
29218 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29219 cn_reply->id.idx = CN_IDX_DRBD;
29220 cn_reply->id.val = CN_VAL_DRBD;
29221
29222 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29223 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29224 cn_reply->ack = 0; /* not used here. */
29225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29226 (int)((char *)tl - (char *)reply->tag_list);
29227 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29228 cn_reply->id.idx = CN_IDX_DRBD;
29229 cn_reply->id.val = CN_VAL_DRBD;
29230
29231 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29232 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29233 cn_reply->ack = 0; // not used here.
29234 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29235 (int)((char*)tl - (char*)reply->tag_list);
29236 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29237 cn_reply->id.idx = CN_IDX_DRBD;
29238 cn_reply->id.val = CN_VAL_DRBD;
29239
29240 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29241 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29242 cn_reply->ack = 0; /* not used here. */
29243 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29244 (int)((char *)tl - (char *)reply->tag_list);
29245 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29246 index ea4836e..272d72a 100644
29247 --- a/drivers/block/drbd/drbd_receiver.c
29248 +++ b/drivers/block/drbd/drbd_receiver.c
29249 @@ -893,7 +893,7 @@ retry:
29250 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29251 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29252
29253 - atomic_set(&mdev->packet_seq, 0);
29254 + atomic_set_unchecked(&mdev->packet_seq, 0);
29255 mdev->peer_seq = 0;
29256
29257 if (drbd_send_protocol(mdev) == -1)
29258 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29259 do {
29260 next_epoch = NULL;
29261
29262 - epoch_size = atomic_read(&epoch->epoch_size);
29263 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29264
29265 switch (ev & ~EV_CLEANUP) {
29266 case EV_PUT:
29267 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29268 rv = FE_DESTROYED;
29269 } else {
29270 epoch->flags = 0;
29271 - atomic_set(&epoch->epoch_size, 0);
29272 + atomic_set_unchecked(&epoch->epoch_size, 0);
29273 /* atomic_set(&epoch->active, 0); is already zero */
29274 if (rv == FE_STILL_LIVE)
29275 rv = FE_RECYCLED;
29276 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29277 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29278 drbd_flush(mdev);
29279
29280 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29281 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29282 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29283 if (epoch)
29284 break;
29285 }
29286
29287 epoch = mdev->current_epoch;
29288 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29289 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29290
29291 D_ASSERT(atomic_read(&epoch->active) == 0);
29292 D_ASSERT(epoch->flags == 0);
29293 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29294 }
29295
29296 epoch->flags = 0;
29297 - atomic_set(&epoch->epoch_size, 0);
29298 + atomic_set_unchecked(&epoch->epoch_size, 0);
29299 atomic_set(&epoch->active, 0);
29300
29301 spin_lock(&mdev->epoch_lock);
29302 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29303 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29304 list_add(&epoch->list, &mdev->current_epoch->list);
29305 mdev->current_epoch = epoch;
29306 mdev->epochs++;
29307 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29308 spin_unlock(&mdev->peer_seq_lock);
29309
29310 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29311 - atomic_inc(&mdev->current_epoch->epoch_size);
29312 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29313 return drbd_drain_block(mdev, data_size);
29314 }
29315
29316 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29317
29318 spin_lock(&mdev->epoch_lock);
29319 e->epoch = mdev->current_epoch;
29320 - atomic_inc(&e->epoch->epoch_size);
29321 + atomic_inc_unchecked(&e->epoch->epoch_size);
29322 atomic_inc(&e->epoch->active);
29323 spin_unlock(&mdev->epoch_lock);
29324
29325 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29326 D_ASSERT(list_empty(&mdev->done_ee));
29327
29328 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29329 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29330 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29331 D_ASSERT(list_empty(&mdev->current_epoch->list));
29332 }
29333
29334 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29335 index 3bba655..6151b66 100644
29336 --- a/drivers/block/loop.c
29337 +++ b/drivers/block/loop.c
29338 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29339 mm_segment_t old_fs = get_fs();
29340
29341 set_fs(get_ds());
29342 - bw = file->f_op->write(file, buf, len, &pos);
29343 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29344 set_fs(old_fs);
29345 if (likely(bw == len))
29346 return 0;
29347 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29348 index ea6f632..eafb192 100644
29349 --- a/drivers/char/Kconfig
29350 +++ b/drivers/char/Kconfig
29351 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29352
29353 config DEVKMEM
29354 bool "/dev/kmem virtual device support"
29355 - default y
29356 + default n
29357 + depends on !GRKERNSEC_KMEM
29358 help
29359 Say Y here if you want to support the /dev/kmem device. The
29360 /dev/kmem device is rarely used, but can be used for certain
29361 @@ -581,6 +582,7 @@ config DEVPORT
29362 bool
29363 depends on !M68K
29364 depends on ISA || PCI
29365 + depends on !GRKERNSEC_KMEM
29366 default y
29367
29368 source "drivers/s390/char/Kconfig"
29369 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29370 index 2e04433..22afc64 100644
29371 --- a/drivers/char/agp/frontend.c
29372 +++ b/drivers/char/agp/frontend.c
29373 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29374 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29375 return -EFAULT;
29376
29377 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29378 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29379 return -EFAULT;
29380
29381 client = agp_find_client_by_pid(reserve.pid);
29382 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29383 index 21cb980..f15107c 100644
29384 --- a/drivers/char/genrtc.c
29385 +++ b/drivers/char/genrtc.c
29386 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29387 switch (cmd) {
29388
29389 case RTC_PLL_GET:
29390 + memset(&pll, 0, sizeof(pll));
29391 if (get_rtc_pll(&pll))
29392 return -EINVAL;
29393 else
29394 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29395 index dfd7876..c0b0885 100644
29396 --- a/drivers/char/hpet.c
29397 +++ b/drivers/char/hpet.c
29398 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29399 }
29400
29401 static int
29402 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29403 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29404 struct hpet_info *info)
29405 {
29406 struct hpet_timer __iomem *timer;
29407 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29408 index 2c29942..604c5ba 100644
29409 --- a/drivers/char/ipmi/ipmi_msghandler.c
29410 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29411 @@ -420,7 +420,7 @@ struct ipmi_smi {
29412 struct proc_dir_entry *proc_dir;
29413 char proc_dir_name[10];
29414
29415 - atomic_t stats[IPMI_NUM_STATS];
29416 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29417
29418 /*
29419 * run_to_completion duplicate of smb_info, smi_info
29420 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29421
29422
29423 #define ipmi_inc_stat(intf, stat) \
29424 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29425 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29426 #define ipmi_get_stat(intf, stat) \
29427 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29428 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29429
29430 static int is_lan_addr(struct ipmi_addr *addr)
29431 {
29432 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29433 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29434 init_waitqueue_head(&intf->waitq);
29435 for (i = 0; i < IPMI_NUM_STATS; i++)
29436 - atomic_set(&intf->stats[i], 0);
29437 + atomic_set_unchecked(&intf->stats[i], 0);
29438
29439 intf->proc_dir = NULL;
29440
29441 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29442 index 1e638ff..a869ef5 100644
29443 --- a/drivers/char/ipmi/ipmi_si_intf.c
29444 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29445 @@ -275,7 +275,7 @@ struct smi_info {
29446 unsigned char slave_addr;
29447
29448 /* Counters and things for the proc filesystem. */
29449 - atomic_t stats[SI_NUM_STATS];
29450 + atomic_unchecked_t stats[SI_NUM_STATS];
29451
29452 struct task_struct *thread;
29453
29454 @@ -284,9 +284,9 @@ struct smi_info {
29455 };
29456
29457 #define smi_inc_stat(smi, stat) \
29458 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29459 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29460 #define smi_get_stat(smi, stat) \
29461 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29462 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29463
29464 #define SI_MAX_PARMS 4
29465
29466 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29467 atomic_set(&new_smi->req_events, 0);
29468 new_smi->run_to_completion = 0;
29469 for (i = 0; i < SI_NUM_STATS; i++)
29470 - atomic_set(&new_smi->stats[i], 0);
29471 + atomic_set_unchecked(&new_smi->stats[i], 0);
29472
29473 new_smi->interrupt_disabled = 1;
29474 atomic_set(&new_smi->stop_operation, 0);
29475 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29476 index 47ff7e4..0c7d340 100644
29477 --- a/drivers/char/mbcs.c
29478 +++ b/drivers/char/mbcs.c
29479 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29480 return 0;
29481 }
29482
29483 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29484 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29485 {
29486 .part_num = MBCS_PART_NUM,
29487 .mfg_num = MBCS_MFG_NUM,
29488 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29489 index 67c3371..ba8429d 100644
29490 --- a/drivers/char/mem.c
29491 +++ b/drivers/char/mem.c
29492 @@ -18,6 +18,7 @@
29493 #include <linux/raw.h>
29494 #include <linux/tty.h>
29495 #include <linux/capability.h>
29496 +#include <linux/security.h>
29497 #include <linux/ptrace.h>
29498 #include <linux/device.h>
29499 #include <linux/highmem.h>
29500 @@ -35,6 +36,10 @@
29501 # include <linux/efi.h>
29502 #endif
29503
29504 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29505 +extern const struct file_operations grsec_fops;
29506 +#endif
29507 +
29508 static inline unsigned long size_inside_page(unsigned long start,
29509 unsigned long size)
29510 {
29511 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29512
29513 while (cursor < to) {
29514 if (!devmem_is_allowed(pfn)) {
29515 +#ifdef CONFIG_GRKERNSEC_KMEM
29516 + gr_handle_mem_readwrite(from, to);
29517 +#else
29518 printk(KERN_INFO
29519 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29520 current->comm, from, to);
29521 +#endif
29522 return 0;
29523 }
29524 cursor += PAGE_SIZE;
29525 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29526 }
29527 return 1;
29528 }
29529 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29530 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29531 +{
29532 + return 0;
29533 +}
29534 #else
29535 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29536 {
29537 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29538
29539 while (count > 0) {
29540 unsigned long remaining;
29541 + char *temp;
29542
29543 sz = size_inside_page(p, count);
29544
29545 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29546 if (!ptr)
29547 return -EFAULT;
29548
29549 - remaining = copy_to_user(buf, ptr, sz);
29550 +#ifdef CONFIG_PAX_USERCOPY
29551 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29552 + if (!temp) {
29553 + unxlate_dev_mem_ptr(p, ptr);
29554 + return -ENOMEM;
29555 + }
29556 + memcpy(temp, ptr, sz);
29557 +#else
29558 + temp = ptr;
29559 +#endif
29560 +
29561 + remaining = copy_to_user(buf, temp, sz);
29562 +
29563 +#ifdef CONFIG_PAX_USERCOPY
29564 + kfree(temp);
29565 +#endif
29566 +
29567 unxlate_dev_mem_ptr(p, ptr);
29568 if (remaining)
29569 return -EFAULT;
29570 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29571 size_t count, loff_t *ppos)
29572 {
29573 unsigned long p = *ppos;
29574 - ssize_t low_count, read, sz;
29575 + ssize_t low_count, read, sz, err = 0;
29576 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29577 - int err = 0;
29578
29579 read = 0;
29580 if (p < (unsigned long) high_memory) {
29581 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29582 }
29583 #endif
29584 while (low_count > 0) {
29585 + char *temp;
29586 +
29587 sz = size_inside_page(p, low_count);
29588
29589 /*
29590 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29591 */
29592 kbuf = xlate_dev_kmem_ptr((char *)p);
29593
29594 - if (copy_to_user(buf, kbuf, sz))
29595 +#ifdef CONFIG_PAX_USERCOPY
29596 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29597 + if (!temp)
29598 + return -ENOMEM;
29599 + memcpy(temp, kbuf, sz);
29600 +#else
29601 + temp = kbuf;
29602 +#endif
29603 +
29604 + err = copy_to_user(buf, temp, sz);
29605 +
29606 +#ifdef CONFIG_PAX_USERCOPY
29607 + kfree(temp);
29608 +#endif
29609 +
29610 + if (err)
29611 return -EFAULT;
29612 buf += sz;
29613 p += sz;
29614 @@ -831,6 +878,9 @@ static const struct memdev {
29615 #ifdef CONFIG_CRASH_DUMP
29616 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29617 #endif
29618 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29619 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29620 +#endif
29621 };
29622
29623 static int memory_open(struct inode *inode, struct file *filp)
29624 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29625 index 9df78e2..01ba9ae 100644
29626 --- a/drivers/char/nvram.c
29627 +++ b/drivers/char/nvram.c
29628 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29629
29630 spin_unlock_irq(&rtc_lock);
29631
29632 - if (copy_to_user(buf, contents, tmp - contents))
29633 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29634 return -EFAULT;
29635
29636 *ppos = i;
29637 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29638 index 0a484b4..f48ccd1 100644
29639 --- a/drivers/char/pcmcia/synclink_cs.c
29640 +++ b/drivers/char/pcmcia/synclink_cs.c
29641 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29642
29643 if (debug_level >= DEBUG_LEVEL_INFO)
29644 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29645 - __FILE__,__LINE__, info->device_name, port->count);
29646 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29647
29648 - WARN_ON(!port->count);
29649 + WARN_ON(!atomic_read(&port->count));
29650
29651 if (tty_port_close_start(port, tty, filp) == 0)
29652 goto cleanup;
29653 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29654 cleanup:
29655 if (debug_level >= DEBUG_LEVEL_INFO)
29656 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29657 - tty->driver->name, port->count);
29658 + tty->driver->name, atomic_read(&port->count));
29659 }
29660
29661 /* Wait until the transmitter is empty.
29662 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29663
29664 if (debug_level >= DEBUG_LEVEL_INFO)
29665 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29666 - __FILE__,__LINE__,tty->driver->name, port->count);
29667 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29668
29669 /* If port is closing, signal caller to try again */
29670 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29671 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29672 goto cleanup;
29673 }
29674 spin_lock(&port->lock);
29675 - port->count++;
29676 + atomic_inc(&port->count);
29677 spin_unlock(&port->lock);
29678 spin_unlock_irqrestore(&info->netlock, flags);
29679
29680 - if (port->count == 1) {
29681 + if (atomic_read(&port->count) == 1) {
29682 /* 1st open on this device, init hardware */
29683 retval = startup(info, tty);
29684 if (retval < 0)
29685 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29686 unsigned short new_crctype;
29687
29688 /* return error if TTY interface open */
29689 - if (info->port.count)
29690 + if (atomic_read(&info->port.count))
29691 return -EBUSY;
29692
29693 switch (encoding)
29694 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29695
29696 /* arbitrate between network and tty opens */
29697 spin_lock_irqsave(&info->netlock, flags);
29698 - if (info->port.count != 0 || info->netcount != 0) {
29699 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29700 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29701 spin_unlock_irqrestore(&info->netlock, flags);
29702 return -EBUSY;
29703 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29704 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29705
29706 /* return error if TTY interface open */
29707 - if (info->port.count)
29708 + if (atomic_read(&info->port.count))
29709 return -EBUSY;
29710
29711 if (cmd != SIOCWANDEV)
29712 diff --git a/drivers/char/random.c b/drivers/char/random.c
29713 index d98b2a6..f0ceb97 100644
29714 --- a/drivers/char/random.c
29715 +++ b/drivers/char/random.c
29716 @@ -272,8 +272,13 @@
29717 /*
29718 * Configuration information
29719 */
29720 +#ifdef CONFIG_GRKERNSEC_RANDNET
29721 +#define INPUT_POOL_WORDS 512
29722 +#define OUTPUT_POOL_WORDS 128
29723 +#else
29724 #define INPUT_POOL_WORDS 128
29725 #define OUTPUT_POOL_WORDS 32
29726 +#endif
29727 #define SEC_XFER_SIZE 512
29728 #define EXTRACT_SIZE 10
29729
29730 @@ -313,10 +318,17 @@ static struct poolinfo {
29731 int poolwords;
29732 int tap1, tap2, tap3, tap4, tap5;
29733 } poolinfo_table[] = {
29734 +#ifdef CONFIG_GRKERNSEC_RANDNET
29735 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29736 + { 512, 411, 308, 208, 104, 1 },
29737 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29738 + { 128, 103, 76, 51, 25, 1 },
29739 +#else
29740 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29741 { 128, 103, 76, 51, 25, 1 },
29742 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29743 { 32, 26, 20, 14, 7, 1 },
29744 +#endif
29745 #if 0
29746 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29747 { 2048, 1638, 1231, 819, 411, 1 },
29748 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29749 input_rotate += i ? 7 : 14;
29750 }
29751
29752 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29753 - ACCESS_ONCE(r->add_ptr) = i;
29754 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29755 + ACCESS_ONCE_RW(r->add_ptr) = i;
29756 smp_wmb();
29757
29758 if (out)
29759 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29760 }
29761 #endif
29762
29763 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29764 +u64 latent_entropy;
29765 +
29766 +__init void transfer_latent_entropy(void)
29767 +{
29768 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29769 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29770 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29771 +}
29772 +#endif
29773 +
29774 /*********************************************************************
29775 *
29776 * Entropy extraction routines
29777 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29778
29779 extract_buf(r, tmp);
29780 i = min_t(int, nbytes, EXTRACT_SIZE);
29781 - if (copy_to_user(buf, tmp, i)) {
29782 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29783 ret = -EFAULT;
29784 break;
29785 }
29786 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29787 #include <linux/sysctl.h>
29788
29789 static int min_read_thresh = 8, min_write_thresh;
29790 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29791 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29792 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29793 static char sysctl_bootid[16];
29794
29795 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29796 index 45713f0..8286d21 100644
29797 --- a/drivers/char/sonypi.c
29798 +++ b/drivers/char/sonypi.c
29799 @@ -54,6 +54,7 @@
29800
29801 #include <asm/uaccess.h>
29802 #include <asm/io.h>
29803 +#include <asm/local.h>
29804
29805 #include <linux/sonypi.h>
29806
29807 @@ -490,7 +491,7 @@ static struct sonypi_device {
29808 spinlock_t fifo_lock;
29809 wait_queue_head_t fifo_proc_list;
29810 struct fasync_struct *fifo_async;
29811 - int open_count;
29812 + local_t open_count;
29813 int model;
29814 struct input_dev *input_jog_dev;
29815 struct input_dev *input_key_dev;
29816 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29817 static int sonypi_misc_release(struct inode *inode, struct file *file)
29818 {
29819 mutex_lock(&sonypi_device.lock);
29820 - sonypi_device.open_count--;
29821 + local_dec(&sonypi_device.open_count);
29822 mutex_unlock(&sonypi_device.lock);
29823 return 0;
29824 }
29825 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29826 {
29827 mutex_lock(&sonypi_device.lock);
29828 /* Flush input queue on first open */
29829 - if (!sonypi_device.open_count)
29830 + if (!local_read(&sonypi_device.open_count))
29831 kfifo_reset(&sonypi_device.fifo);
29832 - sonypi_device.open_count++;
29833 + local_inc(&sonypi_device.open_count);
29834 mutex_unlock(&sonypi_device.lock);
29835
29836 return 0;
29837 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29838 index 08427ab..1ab10b7 100644
29839 --- a/drivers/char/tpm/tpm.c
29840 +++ b/drivers/char/tpm/tpm.c
29841 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29842 chip->vendor.req_complete_val)
29843 goto out_recv;
29844
29845 - if ((status == chip->vendor.req_canceled)) {
29846 + if (status == chip->vendor.req_canceled) {
29847 dev_err(chip->dev, "Operation Canceled\n");
29848 rc = -ECANCELED;
29849 goto out;
29850 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29851 index 0636520..169c1d0 100644
29852 --- a/drivers/char/tpm/tpm_bios.c
29853 +++ b/drivers/char/tpm/tpm_bios.c
29854 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29855 event = addr;
29856
29857 if ((event->event_type == 0 && event->event_size == 0) ||
29858 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29859 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29860 return NULL;
29861
29862 return addr;
29863 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29864 return NULL;
29865
29866 if ((event->event_type == 0 && event->event_size == 0) ||
29867 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29868 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29869 return NULL;
29870
29871 (*pos)++;
29872 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29873 int i;
29874
29875 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29876 - seq_putc(m, data[i]);
29877 + if (!seq_putc(m, data[i]))
29878 + return -EFAULT;
29879
29880 return 0;
29881 }
29882 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29883 log->bios_event_log_end = log->bios_event_log + len;
29884
29885 virt = acpi_os_map_memory(start, len);
29886 + if (!virt) {
29887 + kfree(log->bios_event_log);
29888 + log->bios_event_log = NULL;
29889 + return -EFAULT;
29890 + }
29891
29892 - memcpy(log->bios_event_log, virt, len);
29893 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29894
29895 acpi_os_unmap_memory(virt, len);
29896 return 0;
29897 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29898 index cdf2f54..e55c197 100644
29899 --- a/drivers/char/virtio_console.c
29900 +++ b/drivers/char/virtio_console.c
29901 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29902 if (to_user) {
29903 ssize_t ret;
29904
29905 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29906 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29907 if (ret)
29908 return -EFAULT;
29909 } else {
29910 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29911 if (!port_has_data(port) && !port->host_connected)
29912 return 0;
29913
29914 - return fill_readbuf(port, ubuf, count, true);
29915 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29916 }
29917
29918 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29919 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29920 index 97f5064..202b6e6 100644
29921 --- a/drivers/edac/edac_pci_sysfs.c
29922 +++ b/drivers/edac/edac_pci_sysfs.c
29923 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29924 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29925 static int edac_pci_poll_msec = 1000; /* one second workq period */
29926
29927 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29928 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29929 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29930 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29931
29932 static struct kobject *edac_pci_top_main_kobj;
29933 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29934 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29935 edac_printk(KERN_CRIT, EDAC_PCI,
29936 "Signaled System Error on %s\n",
29937 pci_name(dev));
29938 - atomic_inc(&pci_nonparity_count);
29939 + atomic_inc_unchecked(&pci_nonparity_count);
29940 }
29941
29942 if (status & (PCI_STATUS_PARITY)) {
29943 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29944 "Master Data Parity Error on %s\n",
29945 pci_name(dev));
29946
29947 - atomic_inc(&pci_parity_count);
29948 + atomic_inc_unchecked(&pci_parity_count);
29949 }
29950
29951 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29952 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29953 "Detected Parity Error on %s\n",
29954 pci_name(dev));
29955
29956 - atomic_inc(&pci_parity_count);
29957 + atomic_inc_unchecked(&pci_parity_count);
29958 }
29959 }
29960
29961 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29962 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29963 "Signaled System Error on %s\n",
29964 pci_name(dev));
29965 - atomic_inc(&pci_nonparity_count);
29966 + atomic_inc_unchecked(&pci_nonparity_count);
29967 }
29968
29969 if (status & (PCI_STATUS_PARITY)) {
29970 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29971 "Master Data Parity Error on "
29972 "%s\n", pci_name(dev));
29973
29974 - atomic_inc(&pci_parity_count);
29975 + atomic_inc_unchecked(&pci_parity_count);
29976 }
29977
29978 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29979 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29980 "Detected Parity Error on %s\n",
29981 pci_name(dev));
29982
29983 - atomic_inc(&pci_parity_count);
29984 + atomic_inc_unchecked(&pci_parity_count);
29985 }
29986 }
29987 }
29988 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29989 if (!check_pci_errors)
29990 return;
29991
29992 - before_count = atomic_read(&pci_parity_count);
29993 + before_count = atomic_read_unchecked(&pci_parity_count);
29994
29995 /* scan all PCI devices looking for a Parity Error on devices and
29996 * bridges.
29997 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29998 /* Only if operator has selected panic on PCI Error */
29999 if (edac_pci_get_panic_on_pe()) {
30000 /* If the count is different 'after' from 'before' */
30001 - if (before_count != atomic_read(&pci_parity_count))
30002 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30003 panic("EDAC: PCI Parity Error");
30004 }
30005 }
30006 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30007 index 8c87a5e..a19cbd7 100644
30008 --- a/drivers/edac/mce_amd.h
30009 +++ b/drivers/edac/mce_amd.h
30010 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30011 struct amd_decoder_ops {
30012 bool (*dc_mce)(u16, u8);
30013 bool (*ic_mce)(u16, u8);
30014 -};
30015 +} __no_const;
30016
30017 void amd_report_gart_errors(bool);
30018 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30019 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30020 index 57ea7f4..789e3c3 100644
30021 --- a/drivers/firewire/core-card.c
30022 +++ b/drivers/firewire/core-card.c
30023 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30024
30025 void fw_core_remove_card(struct fw_card *card)
30026 {
30027 - struct fw_card_driver dummy_driver = dummy_driver_template;
30028 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30029
30030 card->driver->update_phy_reg(card, 4,
30031 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30032 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30033 index 2783f69..9f4b0cc 100644
30034 --- a/drivers/firewire/core-cdev.c
30035 +++ b/drivers/firewire/core-cdev.c
30036 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30037 int ret;
30038
30039 if ((request->channels == 0 && request->bandwidth == 0) ||
30040 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30041 - request->bandwidth < 0)
30042 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30043 return -EINVAL;
30044
30045 r = kmalloc(sizeof(*r), GFP_KERNEL);
30046 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30047 index 780708d..ad60a66 100644
30048 --- a/drivers/firewire/core-transaction.c
30049 +++ b/drivers/firewire/core-transaction.c
30050 @@ -37,6 +37,7 @@
30051 #include <linux/timer.h>
30052 #include <linux/types.h>
30053 #include <linux/workqueue.h>
30054 +#include <linux/sched.h>
30055
30056 #include <asm/byteorder.h>
30057
30058 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30059 index 515a42c..5ecf3ba 100644
30060 --- a/drivers/firewire/core.h
30061 +++ b/drivers/firewire/core.h
30062 @@ -111,6 +111,7 @@ struct fw_card_driver {
30063
30064 int (*stop_iso)(struct fw_iso_context *ctx);
30065 };
30066 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30067
30068 void fw_card_initialize(struct fw_card *card,
30069 const struct fw_card_driver *driver, struct device *device);
30070 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30071 index b298158..7ed8432 100644
30072 --- a/drivers/firmware/dmi_scan.c
30073 +++ b/drivers/firmware/dmi_scan.c
30074 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30075 }
30076 }
30077 else {
30078 - /*
30079 - * no iounmap() for that ioremap(); it would be a no-op, but
30080 - * it's so early in setup that sucker gets confused into doing
30081 - * what it shouldn't if we actually call it.
30082 - */
30083 p = dmi_ioremap(0xF0000, 0x10000);
30084 if (p == NULL)
30085 goto error;
30086 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30087 if (buf == NULL)
30088 return -1;
30089
30090 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30091 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30092
30093 iounmap(buf);
30094 return 0;
30095 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30096 index 82d5c20..44a7177 100644
30097 --- a/drivers/gpio/gpio-vr41xx.c
30098 +++ b/drivers/gpio/gpio-vr41xx.c
30099 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30100 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30101 maskl, pendl, maskh, pendh);
30102
30103 - atomic_inc(&irq_err_count);
30104 + atomic_inc_unchecked(&irq_err_count);
30105
30106 return -EINVAL;
30107 }
30108 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30109 index 3252e70..b5314ace 100644
30110 --- a/drivers/gpu/drm/drm_crtc_helper.c
30111 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30112 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30113 struct drm_crtc *tmp;
30114 int crtc_mask = 1;
30115
30116 - WARN(!crtc, "checking null crtc?\n");
30117 + BUG_ON(!crtc);
30118
30119 dev = crtc->dev;
30120
30121 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30122 index 8a9d079..606cdd5 100644
30123 --- a/drivers/gpu/drm/drm_drv.c
30124 +++ b/drivers/gpu/drm/drm_drv.c
30125 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30126 /**
30127 * Copy and IOCTL return string to user space
30128 */
30129 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30130 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30131 {
30132 int len;
30133
30134 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30135 return -ENODEV;
30136
30137 atomic_inc(&dev->ioctl_count);
30138 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30139 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30140 ++file_priv->ioctl_count;
30141
30142 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30143 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30144 index 123de28..43a0897 100644
30145 --- a/drivers/gpu/drm/drm_fops.c
30146 +++ b/drivers/gpu/drm/drm_fops.c
30147 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30148 }
30149
30150 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30151 - atomic_set(&dev->counts[i], 0);
30152 + atomic_set_unchecked(&dev->counts[i], 0);
30153
30154 dev->sigdata.lock = NULL;
30155
30156 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30157
30158 retcode = drm_open_helper(inode, filp, dev);
30159 if (!retcode) {
30160 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30161 - if (!dev->open_count++)
30162 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30163 + if (local_inc_return(&dev->open_count) == 1)
30164 retcode = drm_setup(dev);
30165 }
30166 if (!retcode) {
30167 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30168
30169 mutex_lock(&drm_global_mutex);
30170
30171 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30172 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30173
30174 if (dev->driver->preclose)
30175 dev->driver->preclose(dev, file_priv);
30176 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30177 * Begin inline drm_release
30178 */
30179
30180 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30181 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30182 task_pid_nr(current),
30183 (long)old_encode_dev(file_priv->minor->device),
30184 - dev->open_count);
30185 + local_read(&dev->open_count));
30186
30187 /* Release any auth tokens that might point to this file_priv,
30188 (do that under the drm_global_mutex) */
30189 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30190 * End inline drm_release
30191 */
30192
30193 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30194 - if (!--dev->open_count) {
30195 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30196 + if (local_dec_and_test(&dev->open_count)) {
30197 if (atomic_read(&dev->ioctl_count)) {
30198 DRM_ERROR("Device busy: %d\n",
30199 atomic_read(&dev->ioctl_count));
30200 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30201 index c87dc96..326055d 100644
30202 --- a/drivers/gpu/drm/drm_global.c
30203 +++ b/drivers/gpu/drm/drm_global.c
30204 @@ -36,7 +36,7 @@
30205 struct drm_global_item {
30206 struct mutex mutex;
30207 void *object;
30208 - int refcount;
30209 + atomic_t refcount;
30210 };
30211
30212 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30213 @@ -49,7 +49,7 @@ void drm_global_init(void)
30214 struct drm_global_item *item = &glob[i];
30215 mutex_init(&item->mutex);
30216 item->object = NULL;
30217 - item->refcount = 0;
30218 + atomic_set(&item->refcount, 0);
30219 }
30220 }
30221
30222 @@ -59,7 +59,7 @@ void drm_global_release(void)
30223 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30224 struct drm_global_item *item = &glob[i];
30225 BUG_ON(item->object != NULL);
30226 - BUG_ON(item->refcount != 0);
30227 + BUG_ON(atomic_read(&item->refcount) != 0);
30228 }
30229 }
30230
30231 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30232 void *object;
30233
30234 mutex_lock(&item->mutex);
30235 - if (item->refcount == 0) {
30236 + if (atomic_read(&item->refcount) == 0) {
30237 item->object = kzalloc(ref->size, GFP_KERNEL);
30238 if (unlikely(item->object == NULL)) {
30239 ret = -ENOMEM;
30240 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30241 goto out_err;
30242
30243 }
30244 - ++item->refcount;
30245 + atomic_inc(&item->refcount);
30246 ref->object = item->object;
30247 object = item->object;
30248 mutex_unlock(&item->mutex);
30249 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30250 struct drm_global_item *item = &glob[ref->global_type];
30251
30252 mutex_lock(&item->mutex);
30253 - BUG_ON(item->refcount == 0);
30254 + BUG_ON(atomic_read(&item->refcount) == 0);
30255 BUG_ON(ref->object != item->object);
30256 - if (--item->refcount == 0) {
30257 + if (atomic_dec_and_test(&item->refcount)) {
30258 ref->release(ref);
30259 item->object = NULL;
30260 }
30261 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30262 index ab1162d..42587b2 100644
30263 --- a/drivers/gpu/drm/drm_info.c
30264 +++ b/drivers/gpu/drm/drm_info.c
30265 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30266 struct drm_local_map *map;
30267 struct drm_map_list *r_list;
30268
30269 - /* Hardcoded from _DRM_FRAME_BUFFER,
30270 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30271 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30272 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30273 + static const char * const types[] = {
30274 + [_DRM_FRAME_BUFFER] = "FB",
30275 + [_DRM_REGISTERS] = "REG",
30276 + [_DRM_SHM] = "SHM",
30277 + [_DRM_AGP] = "AGP",
30278 + [_DRM_SCATTER_GATHER] = "SG",
30279 + [_DRM_CONSISTENT] = "PCI",
30280 + [_DRM_GEM] = "GEM" };
30281 const char *type;
30282 int i;
30283
30284 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30285 map = r_list->map;
30286 if (!map)
30287 continue;
30288 - if (map->type < 0 || map->type > 5)
30289 + if (map->type >= ARRAY_SIZE(types))
30290 type = "??";
30291 else
30292 type = types[map->type];
30293 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30294 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30295 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30296 vma->vm_flags & VM_IO ? 'i' : '-',
30297 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30298 + 0);
30299 +#else
30300 vma->vm_pgoff);
30301 +#endif
30302
30303 #if defined(__i386__)
30304 pgprot = pgprot_val(vma->vm_page_prot);
30305 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30306 index 637fcc3..e890b33 100644
30307 --- a/drivers/gpu/drm/drm_ioc32.c
30308 +++ b/drivers/gpu/drm/drm_ioc32.c
30309 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30310 request = compat_alloc_user_space(nbytes);
30311 if (!access_ok(VERIFY_WRITE, request, nbytes))
30312 return -EFAULT;
30313 - list = (struct drm_buf_desc *) (request + 1);
30314 + list = (struct drm_buf_desc __user *) (request + 1);
30315
30316 if (__put_user(count, &request->count)
30317 || __put_user(list, &request->list))
30318 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30319 request = compat_alloc_user_space(nbytes);
30320 if (!access_ok(VERIFY_WRITE, request, nbytes))
30321 return -EFAULT;
30322 - list = (struct drm_buf_pub *) (request + 1);
30323 + list = (struct drm_buf_pub __user *) (request + 1);
30324
30325 if (__put_user(count, &request->count)
30326 || __put_user(list, &request->list))
30327 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30328 index 64a62c6..ceab35e 100644
30329 --- a/drivers/gpu/drm/drm_ioctl.c
30330 +++ b/drivers/gpu/drm/drm_ioctl.c
30331 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30332 stats->data[i].value =
30333 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30334 else
30335 - stats->data[i].value = atomic_read(&dev->counts[i]);
30336 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30337 stats->data[i].type = dev->types[i];
30338 }
30339
30340 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30341 index 5211520..c744d85 100644
30342 --- a/drivers/gpu/drm/drm_lock.c
30343 +++ b/drivers/gpu/drm/drm_lock.c
30344 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30345 if (drm_lock_take(&master->lock, lock->context)) {
30346 master->lock.file_priv = file_priv;
30347 master->lock.lock_time = jiffies;
30348 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30349 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30350 break; /* Got lock */
30351 }
30352
30353 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30354 return -EINVAL;
30355 }
30356
30357 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30358 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30359
30360 if (drm_lock_free(&master->lock, lock->context)) {
30361 /* FIXME: Should really bail out here. */
30362 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30363 index 21bcd4a..8e074e0 100644
30364 --- a/drivers/gpu/drm/drm_stub.c
30365 +++ b/drivers/gpu/drm/drm_stub.c
30366 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30367
30368 drm_device_set_unplugged(dev);
30369
30370 - if (dev->open_count == 0) {
30371 + if (local_read(&dev->open_count) == 0) {
30372 drm_put_dev(dev);
30373 }
30374 mutex_unlock(&drm_global_mutex);
30375 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30376 index fa94391..ed26ec8 100644
30377 --- a/drivers/gpu/drm/i810/i810_dma.c
30378 +++ b/drivers/gpu/drm/i810/i810_dma.c
30379 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30380 dma->buflist[vertex->idx],
30381 vertex->discard, vertex->used);
30382
30383 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30384 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30385 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30386 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30387 sarea_priv->last_enqueue = dev_priv->counter - 1;
30388 sarea_priv->last_dispatch = (int)hw_status[5];
30389
30390 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30391 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30392 mc->last_render);
30393
30394 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30395 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30396 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30397 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30398 sarea_priv->last_enqueue = dev_priv->counter - 1;
30399 sarea_priv->last_dispatch = (int)hw_status[5];
30400
30401 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30402 index c9339f4..f5e1b9d 100644
30403 --- a/drivers/gpu/drm/i810/i810_drv.h
30404 +++ b/drivers/gpu/drm/i810/i810_drv.h
30405 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30406 int page_flipping;
30407
30408 wait_queue_head_t irq_queue;
30409 - atomic_t irq_received;
30410 - atomic_t irq_emitted;
30411 + atomic_unchecked_t irq_received;
30412 + atomic_unchecked_t irq_emitted;
30413
30414 int front_offset;
30415 } drm_i810_private_t;
30416 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30417 index 5363e9c..59360d1 100644
30418 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30419 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30420 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30421 I915_READ(GTIMR));
30422 }
30423 seq_printf(m, "Interrupts received: %d\n",
30424 - atomic_read(&dev_priv->irq_received));
30425 + atomic_read_unchecked(&dev_priv->irq_received));
30426 for (i = 0; i < I915_NUM_RINGS; i++) {
30427 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30428 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30429 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30430 index 36822b9..b725e1b 100644
30431 --- a/drivers/gpu/drm/i915/i915_dma.c
30432 +++ b/drivers/gpu/drm/i915/i915_dma.c
30433 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30434 bool can_switch;
30435
30436 spin_lock(&dev->count_lock);
30437 - can_switch = (dev->open_count == 0);
30438 + can_switch = (local_read(&dev->open_count) == 0);
30439 spin_unlock(&dev->count_lock);
30440 return can_switch;
30441 }
30442 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30443 index b0b676a..d107105 100644
30444 --- a/drivers/gpu/drm/i915/i915_drv.h
30445 +++ b/drivers/gpu/drm/i915/i915_drv.h
30446 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30447 /* render clock increase/decrease */
30448 /* display clock increase/decrease */
30449 /* pll clock increase/decrease */
30450 -};
30451 +} __no_const;
30452
30453 struct intel_device_info {
30454 u8 gen;
30455 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30456 int current_page;
30457 int page_flipping;
30458
30459 - atomic_t irq_received;
30460 + atomic_unchecked_t irq_received;
30461
30462 /* protects the irq masks */
30463 spinlock_t irq_lock;
30464 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30465 * will be page flipped away on the next vblank. When it
30466 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30467 */
30468 - atomic_t pending_flip;
30469 + atomic_unchecked_t pending_flip;
30470 };
30471
30472 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30473 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30474 struct drm_i915_private *dev_priv, unsigned port);
30475 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30476 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30477 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30478 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30479 {
30480 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30481 }
30482 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30483 index 974a9f1..b3ebd45 100644
30484 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30485 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30486 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30487 i915_gem_clflush_object(obj);
30488
30489 if (obj->base.pending_write_domain)
30490 - cd->flips |= atomic_read(&obj->pending_flip);
30491 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30492
30493 /* The actual obj->write_domain will be updated with
30494 * pending_write_domain after we emit the accumulated flush for all
30495 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30496
30497 static int
30498 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30499 - int count)
30500 + unsigned int count)
30501 {
30502 - int i;
30503 + unsigned int i;
30504
30505 for (i = 0; i < count; i++) {
30506 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30507 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30508 index ed3224c..6618589 100644
30509 --- a/drivers/gpu/drm/i915/i915_irq.c
30510 +++ b/drivers/gpu/drm/i915/i915_irq.c
30511 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30512 int vblank = 0;
30513 bool blc_event;
30514
30515 - atomic_inc(&dev_priv->irq_received);
30516 + atomic_inc_unchecked(&dev_priv->irq_received);
30517
30518 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30519 PIPE_VBLANK_INTERRUPT_STATUS;
30520 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30521 irqreturn_t ret = IRQ_NONE;
30522 int i;
30523
30524 - atomic_inc(&dev_priv->irq_received);
30525 + atomic_inc_unchecked(&dev_priv->irq_received);
30526
30527 /* disable master interrupt before clearing iir */
30528 de_ier = I915_READ(DEIER);
30529 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30530 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30531 u32 hotplug_mask;
30532
30533 - atomic_inc(&dev_priv->irq_received);
30534 + atomic_inc_unchecked(&dev_priv->irq_received);
30535
30536 /* disable master interrupt before clearing iir */
30537 de_ier = I915_READ(DEIER);
30538 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30539 {
30540 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30541
30542 - atomic_set(&dev_priv->irq_received, 0);
30543 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30544
30545
30546 I915_WRITE(HWSTAM, 0xeffe);
30547 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30548 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30549 int pipe;
30550
30551 - atomic_set(&dev_priv->irq_received, 0);
30552 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30553
30554 /* VLV magic */
30555 I915_WRITE(VLV_IMR, 0);
30556 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30557 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30558 int pipe;
30559
30560 - atomic_set(&dev_priv->irq_received, 0);
30561 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30562
30563 for_each_pipe(pipe)
30564 I915_WRITE(PIPESTAT(pipe), 0);
30565 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30566 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30567 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30568
30569 - atomic_inc(&dev_priv->irq_received);
30570 + atomic_inc_unchecked(&dev_priv->irq_received);
30571
30572 iir = I915_READ16(IIR);
30573 if (iir == 0)
30574 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30575 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30576 int pipe;
30577
30578 - atomic_set(&dev_priv->irq_received, 0);
30579 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30580
30581 if (I915_HAS_HOTPLUG(dev)) {
30582 I915_WRITE(PORT_HOTPLUG_EN, 0);
30583 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30584 };
30585 int pipe, ret = IRQ_NONE;
30586
30587 - atomic_inc(&dev_priv->irq_received);
30588 + atomic_inc_unchecked(&dev_priv->irq_received);
30589
30590 iir = I915_READ(IIR);
30591 do {
30592 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30593 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30594 int pipe;
30595
30596 - atomic_set(&dev_priv->irq_received, 0);
30597 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30598
30599 if (I915_HAS_HOTPLUG(dev)) {
30600 I915_WRITE(PORT_HOTPLUG_EN, 0);
30601 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30602 int irq_received;
30603 int ret = IRQ_NONE, pipe;
30604
30605 - atomic_inc(&dev_priv->irq_received);
30606 + atomic_inc_unchecked(&dev_priv->irq_received);
30607
30608 iir = I915_READ(IIR);
30609
30610 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30611 index 8a11131..46eeeaa 100644
30612 --- a/drivers/gpu/drm/i915/intel_display.c
30613 +++ b/drivers/gpu/drm/i915/intel_display.c
30614 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30615
30616 wait_event(dev_priv->pending_flip_queue,
30617 atomic_read(&dev_priv->mm.wedged) ||
30618 - atomic_read(&obj->pending_flip) == 0);
30619 + atomic_read_unchecked(&obj->pending_flip) == 0);
30620
30621 /* Big Hammer, we also need to ensure that any pending
30622 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30623 @@ -5914,9 +5914,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30624
30625 obj = work->old_fb_obj;
30626
30627 - atomic_clear_mask(1 << intel_crtc->plane,
30628 - &obj->pending_flip.counter);
30629 - if (atomic_read(&obj->pending_flip) == 0)
30630 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30631 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30632 wake_up(&dev_priv->pending_flip_queue);
30633
30634 schedule_work(&work->work);
30635 @@ -6253,7 +6252,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30636 /* Block clients from rendering to the new back buffer until
30637 * the flip occurs and the object is no longer visible.
30638 */
30639 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30640 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30641
30642 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30643 if (ret)
30644 @@ -6268,7 +6267,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30645 return 0;
30646
30647 cleanup_pending:
30648 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30649 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30650 drm_gem_object_unreference(&work->old_fb_obj->base);
30651 drm_gem_object_unreference(&obj->base);
30652 mutex_unlock(&dev->struct_mutex);
30653 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30654 index 54558a0..2d97005 100644
30655 --- a/drivers/gpu/drm/mga/mga_drv.h
30656 +++ b/drivers/gpu/drm/mga/mga_drv.h
30657 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30658 u32 clear_cmd;
30659 u32 maccess;
30660
30661 - atomic_t vbl_received; /**< Number of vblanks received. */
30662 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30663 wait_queue_head_t fence_queue;
30664 - atomic_t last_fence_retired;
30665 + atomic_unchecked_t last_fence_retired;
30666 u32 next_fence_to_post;
30667
30668 unsigned int fb_cpp;
30669 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30670 index 2581202..f230a8d9 100644
30671 --- a/drivers/gpu/drm/mga/mga_irq.c
30672 +++ b/drivers/gpu/drm/mga/mga_irq.c
30673 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30674 if (crtc != 0)
30675 return 0;
30676
30677 - return atomic_read(&dev_priv->vbl_received);
30678 + return atomic_read_unchecked(&dev_priv->vbl_received);
30679 }
30680
30681
30682 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30683 /* VBLANK interrupt */
30684 if (status & MGA_VLINEPEN) {
30685 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30686 - atomic_inc(&dev_priv->vbl_received);
30687 + atomic_inc_unchecked(&dev_priv->vbl_received);
30688 drm_handle_vblank(dev, 0);
30689 handled = 1;
30690 }
30691 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30692 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30693 MGA_WRITE(MGA_PRIMEND, prim_end);
30694
30695 - atomic_inc(&dev_priv->last_fence_retired);
30696 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30697 DRM_WAKEUP(&dev_priv->fence_queue);
30698 handled = 1;
30699 }
30700 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30701 * using fences.
30702 */
30703 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30704 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30705 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30706 - *sequence) <= (1 << 23)));
30707
30708 *sequence = cur_fence;
30709 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30710 index 2f11e16..191267e 100644
30711 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30712 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30713 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30714 struct bit_table {
30715 const char id;
30716 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30717 -};
30718 +} __no_const;
30719
30720 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30721
30722 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30723 index b863a3a..c55e0dc 100644
30724 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30725 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30726 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30727 u32 handle, u16 class);
30728 void (*set_tile_region)(struct drm_device *dev, int i);
30729 void (*tlb_flush)(struct drm_device *, int engine);
30730 -};
30731 +} __no_const;
30732
30733 struct nouveau_instmem_engine {
30734 void *priv;
30735 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30736 struct nouveau_mc_engine {
30737 int (*init)(struct drm_device *dev);
30738 void (*takedown)(struct drm_device *dev);
30739 -};
30740 +} __no_const;
30741
30742 struct nouveau_timer_engine {
30743 int (*init)(struct drm_device *dev);
30744 void (*takedown)(struct drm_device *dev);
30745 uint64_t (*read)(struct drm_device *dev);
30746 -};
30747 +} __no_const;
30748
30749 struct nouveau_fb_engine {
30750 int num_tiles;
30751 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30752 void (*put)(struct drm_device *, struct nouveau_mem **);
30753
30754 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30755 -};
30756 +} __no_const;
30757
30758 struct nouveau_engine {
30759 struct nouveau_instmem_engine instmem;
30760 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30761 struct drm_global_reference mem_global_ref;
30762 struct ttm_bo_global_ref bo_global_ref;
30763 struct ttm_bo_device bdev;
30764 - atomic_t validate_sequence;
30765 + atomic_unchecked_t validate_sequence;
30766 int (*move)(struct nouveau_channel *,
30767 struct ttm_buffer_object *,
30768 struct ttm_mem_reg *, struct ttm_mem_reg *);
30769 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30770 index 30f5423..abca136 100644
30771 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30772 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30773 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30774 int trycnt = 0;
30775 int ret, i;
30776
30777 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30778 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30779 retry:
30780 if (++trycnt > 100000) {
30781 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30782 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30783 index 19706f0..f257368 100644
30784 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30785 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30786 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30787 bool can_switch;
30788
30789 spin_lock(&dev->count_lock);
30790 - can_switch = (dev->open_count == 0);
30791 + can_switch = (local_read(&dev->open_count) == 0);
30792 spin_unlock(&dev->count_lock);
30793 return can_switch;
30794 }
30795 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30796 index a9514ea..369d511 100644
30797 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30798 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30799 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30800 }
30801
30802 if (nv_encoder->dcb->type == OUTPUT_DP) {
30803 - struct dp_train_func func = {
30804 + static struct dp_train_func func = {
30805 .link_set = nv50_sor_dp_link_set,
30806 .train_set = nv50_sor_dp_train_set,
30807 .train_adj = nv50_sor_dp_train_adj
30808 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30809 index c50b075..6b07dfc 100644
30810 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30811 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30812 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30813 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30814
30815 if (nv_encoder->dcb->type == OUTPUT_DP) {
30816 - struct dp_train_func func = {
30817 + static struct dp_train_func func = {
30818 .link_set = nvd0_sor_dp_link_set,
30819 .train_set = nvd0_sor_dp_train_set,
30820 .train_adj = nvd0_sor_dp_train_adj
30821 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30822 index bcac90b..53bfc76 100644
30823 --- a/drivers/gpu/drm/r128/r128_cce.c
30824 +++ b/drivers/gpu/drm/r128/r128_cce.c
30825 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30826
30827 /* GH: Simple idle check.
30828 */
30829 - atomic_set(&dev_priv->idle_count, 0);
30830 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30831
30832 /* We don't support anything other than bus-mastering ring mode,
30833 * but the ring can be in either AGP or PCI space for the ring
30834 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30835 index 930c71b..499aded 100644
30836 --- a/drivers/gpu/drm/r128/r128_drv.h
30837 +++ b/drivers/gpu/drm/r128/r128_drv.h
30838 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30839 int is_pci;
30840 unsigned long cce_buffers_offset;
30841
30842 - atomic_t idle_count;
30843 + atomic_unchecked_t idle_count;
30844
30845 int page_flipping;
30846 int current_page;
30847 u32 crtc_offset;
30848 u32 crtc_offset_cntl;
30849
30850 - atomic_t vbl_received;
30851 + atomic_unchecked_t vbl_received;
30852
30853 u32 color_fmt;
30854 unsigned int front_offset;
30855 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30856 index 429d5a0..7e899ed 100644
30857 --- a/drivers/gpu/drm/r128/r128_irq.c
30858 +++ b/drivers/gpu/drm/r128/r128_irq.c
30859 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30860 if (crtc != 0)
30861 return 0;
30862
30863 - return atomic_read(&dev_priv->vbl_received);
30864 + return atomic_read_unchecked(&dev_priv->vbl_received);
30865 }
30866
30867 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30868 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30869 /* VBLANK interrupt */
30870 if (status & R128_CRTC_VBLANK_INT) {
30871 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30872 - atomic_inc(&dev_priv->vbl_received);
30873 + atomic_inc_unchecked(&dev_priv->vbl_received);
30874 drm_handle_vblank(dev, 0);
30875 return IRQ_HANDLED;
30876 }
30877 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30878 index a9e33ce..09edd4b 100644
30879 --- a/drivers/gpu/drm/r128/r128_state.c
30880 +++ b/drivers/gpu/drm/r128/r128_state.c
30881 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30882
30883 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30884 {
30885 - if (atomic_read(&dev_priv->idle_count) == 0)
30886 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30887 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30888 else
30889 - atomic_set(&dev_priv->idle_count, 0);
30890 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30891 }
30892
30893 #endif
30894 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30895 index 5a82b6b..9e69c73 100644
30896 --- a/drivers/gpu/drm/radeon/mkregtable.c
30897 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30898 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30899 regex_t mask_rex;
30900 regmatch_t match[4];
30901 char buf[1024];
30902 - size_t end;
30903 + long end;
30904 int len;
30905 int done = 0;
30906 int r;
30907 unsigned o;
30908 struct offset *offset;
30909 char last_reg_s[10];
30910 - int last_reg;
30911 + unsigned long last_reg;
30912
30913 if (regcomp
30914 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30915 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30916 index fefcca5..20a5b90 100644
30917 --- a/drivers/gpu/drm/radeon/radeon.h
30918 +++ b/drivers/gpu/drm/radeon/radeon.h
30919 @@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30920 int x2, int y2);
30921 void (*draw_auto)(struct radeon_device *rdev);
30922 void (*set_default_state)(struct radeon_device *rdev);
30923 -};
30924 +} __no_const;
30925
30926 struct r600_blit {
30927 struct radeon_bo *shader_obj;
30928 @@ -1244,7 +1244,7 @@ struct radeon_asic {
30929 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30930 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30931 } pflip;
30932 -};
30933 +} __no_const;
30934
30935 /*
30936 * Asic structures
30937 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30938 index 066c98b..96ab858 100644
30939 --- a/drivers/gpu/drm/radeon/radeon_device.c
30940 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30941 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30942 bool can_switch;
30943
30944 spin_lock(&dev->count_lock);
30945 - can_switch = (dev->open_count == 0);
30946 + can_switch = (local_read(&dev->open_count) == 0);
30947 spin_unlock(&dev->count_lock);
30948 return can_switch;
30949 }
30950 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30951 index a1b59ca..86f2d44 100644
30952 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30953 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30954 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30955
30956 /* SW interrupt */
30957 wait_queue_head_t swi_queue;
30958 - atomic_t swi_emitted;
30959 + atomic_unchecked_t swi_emitted;
30960 int vblank_crtc;
30961 uint32_t irq_enable_reg;
30962 uint32_t r500_disp_irq_reg;
30963 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30964 index 48b7cea..342236f 100644
30965 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30966 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30967 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30968 request = compat_alloc_user_space(sizeof(*request));
30969 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30970 || __put_user(req32.param, &request->param)
30971 - || __put_user((void __user *)(unsigned long)req32.value,
30972 + || __put_user((unsigned long)req32.value,
30973 &request->value))
30974 return -EFAULT;
30975
30976 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30977 index 00da384..32f972d 100644
30978 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30979 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30980 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30981 unsigned int ret;
30982 RING_LOCALS;
30983
30984 - atomic_inc(&dev_priv->swi_emitted);
30985 - ret = atomic_read(&dev_priv->swi_emitted);
30986 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30987 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30988
30989 BEGIN_RING(4);
30990 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30991 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30992 drm_radeon_private_t *dev_priv =
30993 (drm_radeon_private_t *) dev->dev_private;
30994
30995 - atomic_set(&dev_priv->swi_emitted, 0);
30996 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30997 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30998
30999 dev->max_vblank_count = 0x001fffff;
31000 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31001 index e8422ae..d22d4a8 100644
31002 --- a/drivers/gpu/drm/radeon/radeon_state.c
31003 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31004 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31005 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31006 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31007
31008 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31009 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31010 sarea_priv->nbox * sizeof(depth_boxes[0])))
31011 return -EFAULT;
31012
31013 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31014 {
31015 drm_radeon_private_t *dev_priv = dev->dev_private;
31016 drm_radeon_getparam_t *param = data;
31017 - int value;
31018 + int value = 0;
31019
31020 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31021
31022 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31023 index c94a225..5795d34 100644
31024 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31025 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31026 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31027 }
31028 if (unlikely(ttm_vm_ops == NULL)) {
31029 ttm_vm_ops = vma->vm_ops;
31030 - radeon_ttm_vm_ops = *ttm_vm_ops;
31031 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31032 + pax_open_kernel();
31033 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31034 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31035 + pax_close_kernel();
31036 }
31037 vma->vm_ops = &radeon_ttm_vm_ops;
31038 return 0;
31039 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31040 index 159b6a4..fa82487 100644
31041 --- a/drivers/gpu/drm/radeon/rs690.c
31042 +++ b/drivers/gpu/drm/radeon/rs690.c
31043 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31044 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31045 rdev->pm.sideport_bandwidth.full)
31046 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31047 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31048 + read_delay_latency.full = dfixed_const(800 * 1000);
31049 read_delay_latency.full = dfixed_div(read_delay_latency,
31050 rdev->pm.igp_sideport_mclk);
31051 + a.full = dfixed_const(370);
31052 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31053 } else {
31054 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31055 rdev->pm.k8_bandwidth.full)
31056 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31057 index ebc6fac..a8313ed 100644
31058 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31059 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31060 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31061 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31062 struct shrink_control *sc)
31063 {
31064 - static atomic_t start_pool = ATOMIC_INIT(0);
31065 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31066 unsigned i;
31067 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31068 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31069 struct ttm_page_pool *pool;
31070 int shrink_pages = sc->nr_to_scan;
31071
31072 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31073 index 88edacc..1e5412b 100644
31074 --- a/drivers/gpu/drm/via/via_drv.h
31075 +++ b/drivers/gpu/drm/via/via_drv.h
31076 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31077 typedef uint32_t maskarray_t[5];
31078
31079 typedef struct drm_via_irq {
31080 - atomic_t irq_received;
31081 + atomic_unchecked_t irq_received;
31082 uint32_t pending_mask;
31083 uint32_t enable_mask;
31084 wait_queue_head_t irq_queue;
31085 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31086 struct timeval last_vblank;
31087 int last_vblank_valid;
31088 unsigned usec_per_vblank;
31089 - atomic_t vbl_received;
31090 + atomic_unchecked_t vbl_received;
31091 drm_via_state_t hc_state;
31092 char pci_buf[VIA_PCI_BUF_SIZE];
31093 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31094 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31095 index d391f48..10c8ca3 100644
31096 --- a/drivers/gpu/drm/via/via_irq.c
31097 +++ b/drivers/gpu/drm/via/via_irq.c
31098 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31099 if (crtc != 0)
31100 return 0;
31101
31102 - return atomic_read(&dev_priv->vbl_received);
31103 + return atomic_read_unchecked(&dev_priv->vbl_received);
31104 }
31105
31106 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31107 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31108
31109 status = VIA_READ(VIA_REG_INTERRUPT);
31110 if (status & VIA_IRQ_VBLANK_PENDING) {
31111 - atomic_inc(&dev_priv->vbl_received);
31112 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31113 + atomic_inc_unchecked(&dev_priv->vbl_received);
31114 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31115 do_gettimeofday(&cur_vblank);
31116 if (dev_priv->last_vblank_valid) {
31117 dev_priv->usec_per_vblank =
31118 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31119 dev_priv->last_vblank = cur_vblank;
31120 dev_priv->last_vblank_valid = 1;
31121 }
31122 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31123 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31124 DRM_DEBUG("US per vblank is: %u\n",
31125 dev_priv->usec_per_vblank);
31126 }
31127 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31128
31129 for (i = 0; i < dev_priv->num_irqs; ++i) {
31130 if (status & cur_irq->pending_mask) {
31131 - atomic_inc(&cur_irq->irq_received);
31132 + atomic_inc_unchecked(&cur_irq->irq_received);
31133 DRM_WAKEUP(&cur_irq->irq_queue);
31134 handled = 1;
31135 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31136 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31137 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31138 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31139 masks[irq][4]));
31140 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31141 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31142 } else {
31143 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31144 (((cur_irq_sequence =
31145 - atomic_read(&cur_irq->irq_received)) -
31146 + atomic_read_unchecked(&cur_irq->irq_received)) -
31147 *sequence) <= (1 << 23)));
31148 }
31149 *sequence = cur_irq_sequence;
31150 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31151 }
31152
31153 for (i = 0; i < dev_priv->num_irqs; ++i) {
31154 - atomic_set(&cur_irq->irq_received, 0);
31155 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31156 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31157 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31158 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31159 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31160 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31161 case VIA_IRQ_RELATIVE:
31162 irqwait->request.sequence +=
31163 - atomic_read(&cur_irq->irq_received);
31164 + atomic_read_unchecked(&cur_irq->irq_received);
31165 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31166 case VIA_IRQ_ABSOLUTE:
31167 break;
31168 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31169 index d0f2c07..9ebd9c3 100644
31170 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31171 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31172 @@ -263,7 +263,7 @@ struct vmw_private {
31173 * Fencing and IRQs.
31174 */
31175
31176 - atomic_t marker_seq;
31177 + atomic_unchecked_t marker_seq;
31178 wait_queue_head_t fence_queue;
31179 wait_queue_head_t fifo_queue;
31180 int fence_queue_waiters; /* Protected by hw_mutex */
31181 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31182 index a0c2f12..68ae6cb 100644
31183 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31184 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31185 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31186 (unsigned int) min,
31187 (unsigned int) fifo->capabilities);
31188
31189 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31190 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31191 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31192 vmw_marker_queue_init(&fifo->marker_queue);
31193 return vmw_fifo_send_fence(dev_priv, &dummy);
31194 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31195 if (reserveable)
31196 iowrite32(bytes, fifo_mem +
31197 SVGA_FIFO_RESERVED);
31198 - return fifo_mem + (next_cmd >> 2);
31199 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31200 } else {
31201 need_bounce = true;
31202 }
31203 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31204
31205 fm = vmw_fifo_reserve(dev_priv, bytes);
31206 if (unlikely(fm == NULL)) {
31207 - *seqno = atomic_read(&dev_priv->marker_seq);
31208 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31209 ret = -ENOMEM;
31210 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31211 false, 3*HZ);
31212 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31213 }
31214
31215 do {
31216 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31217 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31218 } while (*seqno == 0);
31219
31220 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31221 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31222 index cabc95f..14b3d77 100644
31223 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31224 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31225 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31226 * emitted. Then the fence is stale and signaled.
31227 */
31228
31229 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31230 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31231 > VMW_FENCE_WRAP);
31232
31233 return ret;
31234 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31235
31236 if (fifo_idle)
31237 down_read(&fifo_state->rwsem);
31238 - signal_seq = atomic_read(&dev_priv->marker_seq);
31239 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31240 ret = 0;
31241
31242 for (;;) {
31243 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31244 index 8a8725c..afed796 100644
31245 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31246 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31247 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31248 while (!vmw_lag_lt(queue, us)) {
31249 spin_lock(&queue->lock);
31250 if (list_empty(&queue->head))
31251 - seqno = atomic_read(&dev_priv->marker_seq);
31252 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31253 else {
31254 marker = list_first_entry(&queue->head,
31255 struct vmw_marker, head);
31256 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31257 index 1f6957c..b579481 100644
31258 --- a/drivers/hid/hid-core.c
31259 +++ b/drivers/hid/hid-core.c
31260 @@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31261
31262 int hid_add_device(struct hid_device *hdev)
31263 {
31264 - static atomic_t id = ATOMIC_INIT(0);
31265 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31266 int ret;
31267
31268 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31269 @@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31270 /* XXX hack, any other cleaner solution after the driver core
31271 * is converted to allow more than 20 bytes as the device name? */
31272 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31273 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31274 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31275
31276 hid_debug_register(hdev, dev_name(&hdev->dev));
31277 ret = device_add(&hdev->dev);
31278 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31279 index eec3291..8ed706b 100644
31280 --- a/drivers/hid/hid-wiimote-debug.c
31281 +++ b/drivers/hid/hid-wiimote-debug.c
31282 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31283 else if (size == 0)
31284 return -EIO;
31285
31286 - if (copy_to_user(u, buf, size))
31287 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31288 return -EFAULT;
31289
31290 *off += size;
31291 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31292 index 14599e2..711c965 100644
31293 --- a/drivers/hid/usbhid/hiddev.c
31294 +++ b/drivers/hid/usbhid/hiddev.c
31295 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31296 break;
31297
31298 case HIDIOCAPPLICATION:
31299 - if (arg < 0 || arg >= hid->maxapplication)
31300 + if (arg >= hid->maxapplication)
31301 break;
31302
31303 for (i = 0; i < hid->maxcollection; i++)
31304 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31305 index 4065374..10ed7dc 100644
31306 --- a/drivers/hv/channel.c
31307 +++ b/drivers/hv/channel.c
31308 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31309 int ret = 0;
31310 int t;
31311
31312 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31313 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31314 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31315 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31316
31317 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31318 if (ret)
31319 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31320 index 86f8885..ab9cb2b 100644
31321 --- a/drivers/hv/hv.c
31322 +++ b/drivers/hv/hv.c
31323 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31324 u64 output_address = (output) ? virt_to_phys(output) : 0;
31325 u32 output_address_hi = output_address >> 32;
31326 u32 output_address_lo = output_address & 0xFFFFFFFF;
31327 - void *hypercall_page = hv_context.hypercall_page;
31328 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31329
31330 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31331 "=a"(hv_status_lo) : "d" (control_hi),
31332 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31333 index b9426a6..677ce34 100644
31334 --- a/drivers/hv/hyperv_vmbus.h
31335 +++ b/drivers/hv/hyperv_vmbus.h
31336 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31337 struct vmbus_connection {
31338 enum vmbus_connect_state conn_state;
31339
31340 - atomic_t next_gpadl_handle;
31341 + atomic_unchecked_t next_gpadl_handle;
31342
31343 /*
31344 * Represents channel interrupts. Each bit position represents a
31345 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31346 index a220e57..428f54d 100644
31347 --- a/drivers/hv/vmbus_drv.c
31348 +++ b/drivers/hv/vmbus_drv.c
31349 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31350 {
31351 int ret = 0;
31352
31353 - static atomic_t device_num = ATOMIC_INIT(0);
31354 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31355
31356 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31357 - atomic_inc_return(&device_num));
31358 + atomic_inc_return_unchecked(&device_num));
31359
31360 child_device_obj->device.bus = &hv_bus;
31361 child_device_obj->device.parent = &hv_acpi_dev->dev;
31362 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31363 index 34ad5a2..e2b0ae8 100644
31364 --- a/drivers/hwmon/acpi_power_meter.c
31365 +++ b/drivers/hwmon/acpi_power_meter.c
31366 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31367 return res;
31368
31369 temp /= 1000;
31370 - if (temp < 0)
31371 - return -EINVAL;
31372
31373 mutex_lock(&resource->lock);
31374 resource->trip[attr->index - 7] = temp;
31375 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31376 index 8b011d0..3de24a1 100644
31377 --- a/drivers/hwmon/sht15.c
31378 +++ b/drivers/hwmon/sht15.c
31379 @@ -166,7 +166,7 @@ struct sht15_data {
31380 int supply_uV;
31381 bool supply_uV_valid;
31382 struct work_struct update_supply_work;
31383 - atomic_t interrupt_handled;
31384 + atomic_unchecked_t interrupt_handled;
31385 };
31386
31387 /**
31388 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31389 return ret;
31390
31391 gpio_direction_input(data->pdata->gpio_data);
31392 - atomic_set(&data->interrupt_handled, 0);
31393 + atomic_set_unchecked(&data->interrupt_handled, 0);
31394
31395 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31396 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31397 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31398 /* Only relevant if the interrupt hasn't occurred. */
31399 - if (!atomic_read(&data->interrupt_handled))
31400 + if (!atomic_read_unchecked(&data->interrupt_handled))
31401 schedule_work(&data->read_work);
31402 }
31403 ret = wait_event_timeout(data->wait_queue,
31404 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31405
31406 /* First disable the interrupt */
31407 disable_irq_nosync(irq);
31408 - atomic_inc(&data->interrupt_handled);
31409 + atomic_inc_unchecked(&data->interrupt_handled);
31410 /* Then schedule a reading work struct */
31411 if (data->state != SHT15_READING_NOTHING)
31412 schedule_work(&data->read_work);
31413 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31414 * If not, then start the interrupt again - care here as could
31415 * have gone low in meantime so verify it hasn't!
31416 */
31417 - atomic_set(&data->interrupt_handled, 0);
31418 + atomic_set_unchecked(&data->interrupt_handled, 0);
31419 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31420 /* If still not occurred or another handler was scheduled */
31421 if (gpio_get_value(data->pdata->gpio_data)
31422 - || atomic_read(&data->interrupt_handled))
31423 + || atomic_read_unchecked(&data->interrupt_handled))
31424 return;
31425 }
31426
31427 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31428 index 378fcb5..5e91fa8 100644
31429 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31430 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31431 @@ -43,7 +43,7 @@
31432 extern struct i2c_adapter amd756_smbus;
31433
31434 static struct i2c_adapter *s4882_adapter;
31435 -static struct i2c_algorithm *s4882_algo;
31436 +static i2c_algorithm_no_const *s4882_algo;
31437
31438 /* Wrapper access functions for multiplexed SMBus */
31439 static DEFINE_MUTEX(amd756_lock);
31440 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31441 index 29015eb..af2d8e9 100644
31442 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31443 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31444 @@ -41,7 +41,7 @@
31445 extern struct i2c_adapter *nforce2_smbus;
31446
31447 static struct i2c_adapter *s4985_adapter;
31448 -static struct i2c_algorithm *s4985_algo;
31449 +static i2c_algorithm_no_const *s4985_algo;
31450
31451 /* Wrapper access functions for multiplexed SMBus */
31452 static DEFINE_MUTEX(nforce2_lock);
31453 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31454 index 1038c38..eb92f51 100644
31455 --- a/drivers/i2c/i2c-mux.c
31456 +++ b/drivers/i2c/i2c-mux.c
31457 @@ -30,7 +30,7 @@
31458 /* multiplexer per channel data */
31459 struct i2c_mux_priv {
31460 struct i2c_adapter adap;
31461 - struct i2c_algorithm algo;
31462 + i2c_algorithm_no_const algo;
31463
31464 struct i2c_adapter *parent;
31465 void *mux_priv; /* the mux chip/device */
31466 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31467 index 57d00ca..0145194 100644
31468 --- a/drivers/ide/aec62xx.c
31469 +++ b/drivers/ide/aec62xx.c
31470 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31471 .cable_detect = atp86x_cable_detect,
31472 };
31473
31474 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31475 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31476 { /* 0: AEC6210 */
31477 .name = DRV_NAME,
31478 .init_chipset = init_chipset_aec62xx,
31479 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31480 index 2c8016a..911a27c 100644
31481 --- a/drivers/ide/alim15x3.c
31482 +++ b/drivers/ide/alim15x3.c
31483 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31484 .dma_sff_read_status = ide_dma_sff_read_status,
31485 };
31486
31487 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31488 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31489 .name = DRV_NAME,
31490 .init_chipset = init_chipset_ali15x3,
31491 .init_hwif = init_hwif_ali15x3,
31492 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31493 index 3747b25..56fc995 100644
31494 --- a/drivers/ide/amd74xx.c
31495 +++ b/drivers/ide/amd74xx.c
31496 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31497 .udma_mask = udma, \
31498 }
31499
31500 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31501 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31502 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31503 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31504 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31505 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31506 index 15f0ead..cb43480 100644
31507 --- a/drivers/ide/atiixp.c
31508 +++ b/drivers/ide/atiixp.c
31509 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31510 .cable_detect = atiixp_cable_detect,
31511 };
31512
31513 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31514 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31515 { /* 0: IXP200/300/400/700 */
31516 .name = DRV_NAME,
31517 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31518 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31519 index 5f80312..d1fc438 100644
31520 --- a/drivers/ide/cmd64x.c
31521 +++ b/drivers/ide/cmd64x.c
31522 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31523 .dma_sff_read_status = ide_dma_sff_read_status,
31524 };
31525
31526 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31527 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31528 { /* 0: CMD643 */
31529 .name = DRV_NAME,
31530 .init_chipset = init_chipset_cmd64x,
31531 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31532 index 2c1e5f7..1444762 100644
31533 --- a/drivers/ide/cs5520.c
31534 +++ b/drivers/ide/cs5520.c
31535 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31536 .set_dma_mode = cs5520_set_dma_mode,
31537 };
31538
31539 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31540 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31541 .name = DRV_NAME,
31542 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31543 .port_ops = &cs5520_port_ops,
31544 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31545 index 4dc4eb9..49b40ad 100644
31546 --- a/drivers/ide/cs5530.c
31547 +++ b/drivers/ide/cs5530.c
31548 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31549 .udma_filter = cs5530_udma_filter,
31550 };
31551
31552 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31553 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31554 .name = DRV_NAME,
31555 .init_chipset = init_chipset_cs5530,
31556 .init_hwif = init_hwif_cs5530,
31557 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31558 index 5059faf..18d4c85 100644
31559 --- a/drivers/ide/cs5535.c
31560 +++ b/drivers/ide/cs5535.c
31561 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31562 .cable_detect = cs5535_cable_detect,
31563 };
31564
31565 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31566 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31567 .name = DRV_NAME,
31568 .port_ops = &cs5535_port_ops,
31569 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31570 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31571 index 847553f..3ffb49d 100644
31572 --- a/drivers/ide/cy82c693.c
31573 +++ b/drivers/ide/cy82c693.c
31574 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31575 .set_dma_mode = cy82c693_set_dma_mode,
31576 };
31577
31578 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31579 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31580 .name = DRV_NAME,
31581 .init_iops = init_iops_cy82c693,
31582 .port_ops = &cy82c693_port_ops,
31583 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31584 index 58c51cd..4aec3b8 100644
31585 --- a/drivers/ide/hpt366.c
31586 +++ b/drivers/ide/hpt366.c
31587 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31588 }
31589 };
31590
31591 -static const struct hpt_info hpt36x __devinitdata = {
31592 +static const struct hpt_info hpt36x __devinitconst = {
31593 .chip_name = "HPT36x",
31594 .chip_type = HPT36x,
31595 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31596 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31597 .timings = &hpt36x_timings
31598 };
31599
31600 -static const struct hpt_info hpt370 __devinitdata = {
31601 +static const struct hpt_info hpt370 __devinitconst = {
31602 .chip_name = "HPT370",
31603 .chip_type = HPT370,
31604 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31605 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31606 .timings = &hpt37x_timings
31607 };
31608
31609 -static const struct hpt_info hpt370a __devinitdata = {
31610 +static const struct hpt_info hpt370a __devinitconst = {
31611 .chip_name = "HPT370A",
31612 .chip_type = HPT370A,
31613 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31614 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31615 .timings = &hpt37x_timings
31616 };
31617
31618 -static const struct hpt_info hpt374 __devinitdata = {
31619 +static const struct hpt_info hpt374 __devinitconst = {
31620 .chip_name = "HPT374",
31621 .chip_type = HPT374,
31622 .udma_mask = ATA_UDMA5,
31623 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31624 .timings = &hpt37x_timings
31625 };
31626
31627 -static const struct hpt_info hpt372 __devinitdata = {
31628 +static const struct hpt_info hpt372 __devinitconst = {
31629 .chip_name = "HPT372",
31630 .chip_type = HPT372,
31631 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31632 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31633 .timings = &hpt37x_timings
31634 };
31635
31636 -static const struct hpt_info hpt372a __devinitdata = {
31637 +static const struct hpt_info hpt372a __devinitconst = {
31638 .chip_name = "HPT372A",
31639 .chip_type = HPT372A,
31640 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31641 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31642 .timings = &hpt37x_timings
31643 };
31644
31645 -static const struct hpt_info hpt302 __devinitdata = {
31646 +static const struct hpt_info hpt302 __devinitconst = {
31647 .chip_name = "HPT302",
31648 .chip_type = HPT302,
31649 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31650 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31651 .timings = &hpt37x_timings
31652 };
31653
31654 -static const struct hpt_info hpt371 __devinitdata = {
31655 +static const struct hpt_info hpt371 __devinitconst = {
31656 .chip_name = "HPT371",
31657 .chip_type = HPT371,
31658 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31659 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31660 .timings = &hpt37x_timings
31661 };
31662
31663 -static const struct hpt_info hpt372n __devinitdata = {
31664 +static const struct hpt_info hpt372n __devinitconst = {
31665 .chip_name = "HPT372N",
31666 .chip_type = HPT372N,
31667 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31668 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31669 .timings = &hpt37x_timings
31670 };
31671
31672 -static const struct hpt_info hpt302n __devinitdata = {
31673 +static const struct hpt_info hpt302n __devinitconst = {
31674 .chip_name = "HPT302N",
31675 .chip_type = HPT302N,
31676 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31677 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31678 .timings = &hpt37x_timings
31679 };
31680
31681 -static const struct hpt_info hpt371n __devinitdata = {
31682 +static const struct hpt_info hpt371n __devinitconst = {
31683 .chip_name = "HPT371N",
31684 .chip_type = HPT371N,
31685 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31686 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31687 .dma_sff_read_status = ide_dma_sff_read_status,
31688 };
31689
31690 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31691 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31692 { /* 0: HPT36x */
31693 .name = DRV_NAME,
31694 .init_chipset = init_chipset_hpt366,
31695 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31696 index 8126824..55a2798 100644
31697 --- a/drivers/ide/ide-cd.c
31698 +++ b/drivers/ide/ide-cd.c
31699 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31700 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31701 if ((unsigned long)buf & alignment
31702 || blk_rq_bytes(rq) & q->dma_pad_mask
31703 - || object_is_on_stack(buf))
31704 + || object_starts_on_stack(buf))
31705 drive->dma = 0;
31706 }
31707 }
31708 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31709 index 7f56b73..dab5b67 100644
31710 --- a/drivers/ide/ide-pci-generic.c
31711 +++ b/drivers/ide/ide-pci-generic.c
31712 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31713 .udma_mask = ATA_UDMA6, \
31714 }
31715
31716 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31717 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31718 /* 0: Unknown */
31719 DECLARE_GENERIC_PCI_DEV(0),
31720
31721 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31722 index 560e66d..d5dd180 100644
31723 --- a/drivers/ide/it8172.c
31724 +++ b/drivers/ide/it8172.c
31725 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31726 .set_dma_mode = it8172_set_dma_mode,
31727 };
31728
31729 -static const struct ide_port_info it8172_port_info __devinitdata = {
31730 +static const struct ide_port_info it8172_port_info __devinitconst = {
31731 .name = DRV_NAME,
31732 .port_ops = &it8172_port_ops,
31733 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31734 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31735 index 46816ba..1847aeb 100644
31736 --- a/drivers/ide/it8213.c
31737 +++ b/drivers/ide/it8213.c
31738 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31739 .cable_detect = it8213_cable_detect,
31740 };
31741
31742 -static const struct ide_port_info it8213_chipset __devinitdata = {
31743 +static const struct ide_port_info it8213_chipset __devinitconst = {
31744 .name = DRV_NAME,
31745 .enablebits = { {0x41, 0x80, 0x80} },
31746 .port_ops = &it8213_port_ops,
31747 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31748 index 2e3169f..c5611db 100644
31749 --- a/drivers/ide/it821x.c
31750 +++ b/drivers/ide/it821x.c
31751 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31752 .cable_detect = it821x_cable_detect,
31753 };
31754
31755 -static const struct ide_port_info it821x_chipset __devinitdata = {
31756 +static const struct ide_port_info it821x_chipset __devinitconst = {
31757 .name = DRV_NAME,
31758 .init_chipset = init_chipset_it821x,
31759 .init_hwif = init_hwif_it821x,
31760 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31761 index 74c2c4a..efddd7d 100644
31762 --- a/drivers/ide/jmicron.c
31763 +++ b/drivers/ide/jmicron.c
31764 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31765 .cable_detect = jmicron_cable_detect,
31766 };
31767
31768 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31769 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31770 .name = DRV_NAME,
31771 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31772 .port_ops = &jmicron_port_ops,
31773 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31774 index 95327a2..73f78d8 100644
31775 --- a/drivers/ide/ns87415.c
31776 +++ b/drivers/ide/ns87415.c
31777 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31778 .dma_sff_read_status = superio_dma_sff_read_status,
31779 };
31780
31781 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31782 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31783 .name = DRV_NAME,
31784 .init_hwif = init_hwif_ns87415,
31785 .tp_ops = &ns87415_tp_ops,
31786 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31787 index 1a53a4c..39edc66 100644
31788 --- a/drivers/ide/opti621.c
31789 +++ b/drivers/ide/opti621.c
31790 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31791 .set_pio_mode = opti621_set_pio_mode,
31792 };
31793
31794 -static const struct ide_port_info opti621_chipset __devinitdata = {
31795 +static const struct ide_port_info opti621_chipset __devinitconst = {
31796 .name = DRV_NAME,
31797 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31798 .port_ops = &opti621_port_ops,
31799 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31800 index 9546fe2..2e5ceb6 100644
31801 --- a/drivers/ide/pdc202xx_new.c
31802 +++ b/drivers/ide/pdc202xx_new.c
31803 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31804 .udma_mask = udma, \
31805 }
31806
31807 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31808 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31809 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31810 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31811 };
31812 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31813 index 3a35ec6..5634510 100644
31814 --- a/drivers/ide/pdc202xx_old.c
31815 +++ b/drivers/ide/pdc202xx_old.c
31816 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31817 .max_sectors = sectors, \
31818 }
31819
31820 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31821 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31822 { /* 0: PDC20246 */
31823 .name = DRV_NAME,
31824 .init_chipset = init_chipset_pdc202xx,
31825 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31826 index 1892e81..fe0fd60 100644
31827 --- a/drivers/ide/piix.c
31828 +++ b/drivers/ide/piix.c
31829 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31830 .udma_mask = udma, \
31831 }
31832
31833 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31834 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31835 /* 0: MPIIX */
31836 { /*
31837 * MPIIX actually has only a single IDE channel mapped to
31838 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31839 index a6414a8..c04173e 100644
31840 --- a/drivers/ide/rz1000.c
31841 +++ b/drivers/ide/rz1000.c
31842 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31843 }
31844 }
31845
31846 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31847 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31848 .name = DRV_NAME,
31849 .host_flags = IDE_HFLAG_NO_DMA,
31850 };
31851 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31852 index 356b9b5..d4758eb 100644
31853 --- a/drivers/ide/sc1200.c
31854 +++ b/drivers/ide/sc1200.c
31855 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31856 .dma_sff_read_status = ide_dma_sff_read_status,
31857 };
31858
31859 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31860 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31861 .name = DRV_NAME,
31862 .port_ops = &sc1200_port_ops,
31863 .dma_ops = &sc1200_dma_ops,
31864 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31865 index b7f5b0c..9701038 100644
31866 --- a/drivers/ide/scc_pata.c
31867 +++ b/drivers/ide/scc_pata.c
31868 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31869 .dma_sff_read_status = scc_dma_sff_read_status,
31870 };
31871
31872 -static const struct ide_port_info scc_chipset __devinitdata = {
31873 +static const struct ide_port_info scc_chipset __devinitconst = {
31874 .name = "sccIDE",
31875 .init_iops = init_iops_scc,
31876 .init_dma = scc_init_dma,
31877 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31878 index 35fb8da..24d72ef 100644
31879 --- a/drivers/ide/serverworks.c
31880 +++ b/drivers/ide/serverworks.c
31881 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31882 .cable_detect = svwks_cable_detect,
31883 };
31884
31885 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31886 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31887 { /* 0: OSB4 */
31888 .name = DRV_NAME,
31889 .init_chipset = init_chipset_svwks,
31890 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31891 index ddeda44..46f7e30 100644
31892 --- a/drivers/ide/siimage.c
31893 +++ b/drivers/ide/siimage.c
31894 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31895 .udma_mask = ATA_UDMA6, \
31896 }
31897
31898 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31899 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31900 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31901 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31902 };
31903 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31904 index 4a00225..09e61b4 100644
31905 --- a/drivers/ide/sis5513.c
31906 +++ b/drivers/ide/sis5513.c
31907 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31908 .cable_detect = sis_cable_detect,
31909 };
31910
31911 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31912 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31913 .name = DRV_NAME,
31914 .init_chipset = init_chipset_sis5513,
31915 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31916 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31917 index f21dc2a..d051cd2 100644
31918 --- a/drivers/ide/sl82c105.c
31919 +++ b/drivers/ide/sl82c105.c
31920 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31921 .dma_sff_read_status = ide_dma_sff_read_status,
31922 };
31923
31924 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31925 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31926 .name = DRV_NAME,
31927 .init_chipset = init_chipset_sl82c105,
31928 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31929 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31930 index 864ffe0..863a5e9 100644
31931 --- a/drivers/ide/slc90e66.c
31932 +++ b/drivers/ide/slc90e66.c
31933 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31934 .cable_detect = slc90e66_cable_detect,
31935 };
31936
31937 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31938 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31939 .name = DRV_NAME,
31940 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31941 .port_ops = &slc90e66_port_ops,
31942 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31943 index 4799d5c..1794678 100644
31944 --- a/drivers/ide/tc86c001.c
31945 +++ b/drivers/ide/tc86c001.c
31946 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31947 .dma_sff_read_status = ide_dma_sff_read_status,
31948 };
31949
31950 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31951 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31952 .name = DRV_NAME,
31953 .init_hwif = init_hwif_tc86c001,
31954 .port_ops = &tc86c001_port_ops,
31955 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31956 index 281c914..55ce1b8 100644
31957 --- a/drivers/ide/triflex.c
31958 +++ b/drivers/ide/triflex.c
31959 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31960 .set_dma_mode = triflex_set_mode,
31961 };
31962
31963 -static const struct ide_port_info triflex_device __devinitdata = {
31964 +static const struct ide_port_info triflex_device __devinitconst = {
31965 .name = DRV_NAME,
31966 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31967 .port_ops = &triflex_port_ops,
31968 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31969 index 4b42ca0..e494a98 100644
31970 --- a/drivers/ide/trm290.c
31971 +++ b/drivers/ide/trm290.c
31972 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31973 .dma_check = trm290_dma_check,
31974 };
31975
31976 -static const struct ide_port_info trm290_chipset __devinitdata = {
31977 +static const struct ide_port_info trm290_chipset __devinitconst = {
31978 .name = DRV_NAME,
31979 .init_hwif = init_hwif_trm290,
31980 .tp_ops = &trm290_tp_ops,
31981 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31982 index f46f49c..eb77678 100644
31983 --- a/drivers/ide/via82cxxx.c
31984 +++ b/drivers/ide/via82cxxx.c
31985 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31986 .cable_detect = via82cxxx_cable_detect,
31987 };
31988
31989 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31990 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31991 .name = DRV_NAME,
31992 .init_chipset = init_chipset_via82cxxx,
31993 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31994 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31995 index 73d4531..c90cd2d 100644
31996 --- a/drivers/ieee802154/fakehard.c
31997 +++ b/drivers/ieee802154/fakehard.c
31998 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31999 phy->transmit_power = 0xbf;
32000
32001 dev->netdev_ops = &fake_ops;
32002 - dev->ml_priv = &fake_mlme;
32003 + dev->ml_priv = (void *)&fake_mlme;
32004
32005 priv = netdev_priv(dev);
32006 priv->phy = phy;
32007 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32008 index c889aae..6cf5aa7 100644
32009 --- a/drivers/infiniband/core/cm.c
32010 +++ b/drivers/infiniband/core/cm.c
32011 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32012
32013 struct cm_counter_group {
32014 struct kobject obj;
32015 - atomic_long_t counter[CM_ATTR_COUNT];
32016 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32017 };
32018
32019 struct cm_counter_attribute {
32020 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32021 struct ib_mad_send_buf *msg = NULL;
32022 int ret;
32023
32024 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32025 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32026 counter[CM_REQ_COUNTER]);
32027
32028 /* Quick state check to discard duplicate REQs. */
32029 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32030 if (!cm_id_priv)
32031 return;
32032
32033 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32034 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32035 counter[CM_REP_COUNTER]);
32036 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32037 if (ret)
32038 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32039 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32040 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32041 spin_unlock_irq(&cm_id_priv->lock);
32042 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32043 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32044 counter[CM_RTU_COUNTER]);
32045 goto out;
32046 }
32047 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32048 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32049 dreq_msg->local_comm_id);
32050 if (!cm_id_priv) {
32051 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32052 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32053 counter[CM_DREQ_COUNTER]);
32054 cm_issue_drep(work->port, work->mad_recv_wc);
32055 return -EINVAL;
32056 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32057 case IB_CM_MRA_REP_RCVD:
32058 break;
32059 case IB_CM_TIMEWAIT:
32060 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32061 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32062 counter[CM_DREQ_COUNTER]);
32063 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32064 goto unlock;
32065 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32066 cm_free_msg(msg);
32067 goto deref;
32068 case IB_CM_DREQ_RCVD:
32069 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32070 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32071 counter[CM_DREQ_COUNTER]);
32072 goto unlock;
32073 default:
32074 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32075 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32076 cm_id_priv->msg, timeout)) {
32077 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32078 - atomic_long_inc(&work->port->
32079 + atomic_long_inc_unchecked(&work->port->
32080 counter_group[CM_RECV_DUPLICATES].
32081 counter[CM_MRA_COUNTER]);
32082 goto out;
32083 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32084 break;
32085 case IB_CM_MRA_REQ_RCVD:
32086 case IB_CM_MRA_REP_RCVD:
32087 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32088 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32089 counter[CM_MRA_COUNTER]);
32090 /* fall through */
32091 default:
32092 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32093 case IB_CM_LAP_IDLE:
32094 break;
32095 case IB_CM_MRA_LAP_SENT:
32096 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32097 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32098 counter[CM_LAP_COUNTER]);
32099 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32100 goto unlock;
32101 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32102 cm_free_msg(msg);
32103 goto deref;
32104 case IB_CM_LAP_RCVD:
32105 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32106 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32107 counter[CM_LAP_COUNTER]);
32108 goto unlock;
32109 default:
32110 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32111 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32112 if (cur_cm_id_priv) {
32113 spin_unlock_irq(&cm.lock);
32114 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32115 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32116 counter[CM_SIDR_REQ_COUNTER]);
32117 goto out; /* Duplicate message. */
32118 }
32119 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32120 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32121 msg->retries = 1;
32122
32123 - atomic_long_add(1 + msg->retries,
32124 + atomic_long_add_unchecked(1 + msg->retries,
32125 &port->counter_group[CM_XMIT].counter[attr_index]);
32126 if (msg->retries)
32127 - atomic_long_add(msg->retries,
32128 + atomic_long_add_unchecked(msg->retries,
32129 &port->counter_group[CM_XMIT_RETRIES].
32130 counter[attr_index]);
32131
32132 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32133 }
32134
32135 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32136 - atomic_long_inc(&port->counter_group[CM_RECV].
32137 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32138 counter[attr_id - CM_ATTR_ID_OFFSET]);
32139
32140 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32141 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32142 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32143
32144 return sprintf(buf, "%ld\n",
32145 - atomic_long_read(&group->counter[cm_attr->index]));
32146 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32147 }
32148
32149 static const struct sysfs_ops cm_counter_ops = {
32150 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32151 index 176c8f9..2627b62 100644
32152 --- a/drivers/infiniband/core/fmr_pool.c
32153 +++ b/drivers/infiniband/core/fmr_pool.c
32154 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32155
32156 struct task_struct *thread;
32157
32158 - atomic_t req_ser;
32159 - atomic_t flush_ser;
32160 + atomic_unchecked_t req_ser;
32161 + atomic_unchecked_t flush_ser;
32162
32163 wait_queue_head_t force_wait;
32164 };
32165 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32166 struct ib_fmr_pool *pool = pool_ptr;
32167
32168 do {
32169 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32170 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32171 ib_fmr_batch_release(pool);
32172
32173 - atomic_inc(&pool->flush_ser);
32174 + atomic_inc_unchecked(&pool->flush_ser);
32175 wake_up_interruptible(&pool->force_wait);
32176
32177 if (pool->flush_function)
32178 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32179 }
32180
32181 set_current_state(TASK_INTERRUPTIBLE);
32182 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32183 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32184 !kthread_should_stop())
32185 schedule();
32186 __set_current_state(TASK_RUNNING);
32187 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32188 pool->dirty_watermark = params->dirty_watermark;
32189 pool->dirty_len = 0;
32190 spin_lock_init(&pool->pool_lock);
32191 - atomic_set(&pool->req_ser, 0);
32192 - atomic_set(&pool->flush_ser, 0);
32193 + atomic_set_unchecked(&pool->req_ser, 0);
32194 + atomic_set_unchecked(&pool->flush_ser, 0);
32195 init_waitqueue_head(&pool->force_wait);
32196
32197 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32198 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32199 }
32200 spin_unlock_irq(&pool->pool_lock);
32201
32202 - serial = atomic_inc_return(&pool->req_ser);
32203 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32204 wake_up_process(pool->thread);
32205
32206 if (wait_event_interruptible(pool->force_wait,
32207 - atomic_read(&pool->flush_ser) - serial >= 0))
32208 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32209 return -EINTR;
32210
32211 return 0;
32212 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32213 } else {
32214 list_add_tail(&fmr->list, &pool->dirty_list);
32215 if (++pool->dirty_len >= pool->dirty_watermark) {
32216 - atomic_inc(&pool->req_ser);
32217 + atomic_inc_unchecked(&pool->req_ser);
32218 wake_up_process(pool->thread);
32219 }
32220 }
32221 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32222 index 57e07c6..56d09d4 100644
32223 --- a/drivers/infiniband/hw/cxgb4/mem.c
32224 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32225 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32226 int err;
32227 struct fw_ri_tpte tpt;
32228 u32 stag_idx;
32229 - static atomic_t key;
32230 + static atomic_unchecked_t key;
32231
32232 if (c4iw_fatal_error(rdev))
32233 return -EIO;
32234 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32235 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32236 rdev->stats.stag.max = rdev->stats.stag.cur;
32237 mutex_unlock(&rdev->stats.lock);
32238 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32239 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32240 }
32241 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32242 __func__, stag_state, type, pdid, stag_idx);
32243 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32244 index 79b3dbc..96e5fcc 100644
32245 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32246 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32247 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32248 struct ib_atomic_eth *ateth;
32249 struct ipath_ack_entry *e;
32250 u64 vaddr;
32251 - atomic64_t *maddr;
32252 + atomic64_unchecked_t *maddr;
32253 u64 sdata;
32254 u32 rkey;
32255 u8 next;
32256 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32257 IB_ACCESS_REMOTE_ATOMIC)))
32258 goto nack_acc_unlck;
32259 /* Perform atomic OP and save result. */
32260 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32261 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32262 sdata = be64_to_cpu(ateth->swap_data);
32263 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32264 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32265 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32266 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32267 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32268 be64_to_cpu(ateth->compare_data),
32269 sdata);
32270 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32271 index 1f95bba..9530f87 100644
32272 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32273 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32274 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32275 unsigned long flags;
32276 struct ib_wc wc;
32277 u64 sdata;
32278 - atomic64_t *maddr;
32279 + atomic64_unchecked_t *maddr;
32280 enum ib_wc_status send_status;
32281
32282 /*
32283 @@ -382,11 +382,11 @@ again:
32284 IB_ACCESS_REMOTE_ATOMIC)))
32285 goto acc_err;
32286 /* Perform atomic OP and save result. */
32287 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32288 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32289 sdata = wqe->wr.wr.atomic.compare_add;
32290 *(u64 *) sqp->s_sge.sge.vaddr =
32291 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32292 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32293 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32294 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32295 sdata, wqe->wr.wr.atomic.swap);
32296 goto send_comp;
32297 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32298 index 7140199..da60063 100644
32299 --- a/drivers/infiniband/hw/nes/nes.c
32300 +++ b/drivers/infiniband/hw/nes/nes.c
32301 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32302 LIST_HEAD(nes_adapter_list);
32303 static LIST_HEAD(nes_dev_list);
32304
32305 -atomic_t qps_destroyed;
32306 +atomic_unchecked_t qps_destroyed;
32307
32308 static unsigned int ee_flsh_adapter;
32309 static unsigned int sysfs_nonidx_addr;
32310 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32311 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32312 struct nes_adapter *nesadapter = nesdev->nesadapter;
32313
32314 - atomic_inc(&qps_destroyed);
32315 + atomic_inc_unchecked(&qps_destroyed);
32316
32317 /* Free the control structures */
32318
32319 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32320 index c438e46..ca30356 100644
32321 --- a/drivers/infiniband/hw/nes/nes.h
32322 +++ b/drivers/infiniband/hw/nes/nes.h
32323 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32324 extern unsigned int wqm_quanta;
32325 extern struct list_head nes_adapter_list;
32326
32327 -extern atomic_t cm_connects;
32328 -extern atomic_t cm_accepts;
32329 -extern atomic_t cm_disconnects;
32330 -extern atomic_t cm_closes;
32331 -extern atomic_t cm_connecteds;
32332 -extern atomic_t cm_connect_reqs;
32333 -extern atomic_t cm_rejects;
32334 -extern atomic_t mod_qp_timouts;
32335 -extern atomic_t qps_created;
32336 -extern atomic_t qps_destroyed;
32337 -extern atomic_t sw_qps_destroyed;
32338 +extern atomic_unchecked_t cm_connects;
32339 +extern atomic_unchecked_t cm_accepts;
32340 +extern atomic_unchecked_t cm_disconnects;
32341 +extern atomic_unchecked_t cm_closes;
32342 +extern atomic_unchecked_t cm_connecteds;
32343 +extern atomic_unchecked_t cm_connect_reqs;
32344 +extern atomic_unchecked_t cm_rejects;
32345 +extern atomic_unchecked_t mod_qp_timouts;
32346 +extern atomic_unchecked_t qps_created;
32347 +extern atomic_unchecked_t qps_destroyed;
32348 +extern atomic_unchecked_t sw_qps_destroyed;
32349 extern u32 mh_detected;
32350 extern u32 mh_pauses_sent;
32351 extern u32 cm_packets_sent;
32352 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32353 extern u32 cm_packets_received;
32354 extern u32 cm_packets_dropped;
32355 extern u32 cm_packets_retrans;
32356 -extern atomic_t cm_listens_created;
32357 -extern atomic_t cm_listens_destroyed;
32358 +extern atomic_unchecked_t cm_listens_created;
32359 +extern atomic_unchecked_t cm_listens_destroyed;
32360 extern u32 cm_backlog_drops;
32361 -extern atomic_t cm_loopbacks;
32362 -extern atomic_t cm_nodes_created;
32363 -extern atomic_t cm_nodes_destroyed;
32364 -extern atomic_t cm_accel_dropped_pkts;
32365 -extern atomic_t cm_resets_recvd;
32366 -extern atomic_t pau_qps_created;
32367 -extern atomic_t pau_qps_destroyed;
32368 +extern atomic_unchecked_t cm_loopbacks;
32369 +extern atomic_unchecked_t cm_nodes_created;
32370 +extern atomic_unchecked_t cm_nodes_destroyed;
32371 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32372 +extern atomic_unchecked_t cm_resets_recvd;
32373 +extern atomic_unchecked_t pau_qps_created;
32374 +extern atomic_unchecked_t pau_qps_destroyed;
32375
32376 extern u32 int_mod_timer_init;
32377 extern u32 int_mod_cq_depth_256;
32378 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32379 index 020e95c..fbb3450 100644
32380 --- a/drivers/infiniband/hw/nes/nes_cm.c
32381 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32382 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32383 u32 cm_packets_retrans;
32384 u32 cm_packets_created;
32385 u32 cm_packets_received;
32386 -atomic_t cm_listens_created;
32387 -atomic_t cm_listens_destroyed;
32388 +atomic_unchecked_t cm_listens_created;
32389 +atomic_unchecked_t cm_listens_destroyed;
32390 u32 cm_backlog_drops;
32391 -atomic_t cm_loopbacks;
32392 -atomic_t cm_nodes_created;
32393 -atomic_t cm_nodes_destroyed;
32394 -atomic_t cm_accel_dropped_pkts;
32395 -atomic_t cm_resets_recvd;
32396 +atomic_unchecked_t cm_loopbacks;
32397 +atomic_unchecked_t cm_nodes_created;
32398 +atomic_unchecked_t cm_nodes_destroyed;
32399 +atomic_unchecked_t cm_accel_dropped_pkts;
32400 +atomic_unchecked_t cm_resets_recvd;
32401
32402 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32403 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32404 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32405
32406 static struct nes_cm_core *g_cm_core;
32407
32408 -atomic_t cm_connects;
32409 -atomic_t cm_accepts;
32410 -atomic_t cm_disconnects;
32411 -atomic_t cm_closes;
32412 -atomic_t cm_connecteds;
32413 -atomic_t cm_connect_reqs;
32414 -atomic_t cm_rejects;
32415 +atomic_unchecked_t cm_connects;
32416 +atomic_unchecked_t cm_accepts;
32417 +atomic_unchecked_t cm_disconnects;
32418 +atomic_unchecked_t cm_closes;
32419 +atomic_unchecked_t cm_connecteds;
32420 +atomic_unchecked_t cm_connect_reqs;
32421 +atomic_unchecked_t cm_rejects;
32422
32423 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32424 {
32425 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32426 kfree(listener);
32427 listener = NULL;
32428 ret = 0;
32429 - atomic_inc(&cm_listens_destroyed);
32430 + atomic_inc_unchecked(&cm_listens_destroyed);
32431 } else {
32432 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32433 }
32434 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32435 cm_node->rem_mac);
32436
32437 add_hte_node(cm_core, cm_node);
32438 - atomic_inc(&cm_nodes_created);
32439 + atomic_inc_unchecked(&cm_nodes_created);
32440
32441 return cm_node;
32442 }
32443 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32444 }
32445
32446 atomic_dec(&cm_core->node_cnt);
32447 - atomic_inc(&cm_nodes_destroyed);
32448 + atomic_inc_unchecked(&cm_nodes_destroyed);
32449 nesqp = cm_node->nesqp;
32450 if (nesqp) {
32451 nesqp->cm_node = NULL;
32452 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32453
32454 static void drop_packet(struct sk_buff *skb)
32455 {
32456 - atomic_inc(&cm_accel_dropped_pkts);
32457 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32458 dev_kfree_skb_any(skb);
32459 }
32460
32461 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32462 {
32463
32464 int reset = 0; /* whether to send reset in case of err.. */
32465 - atomic_inc(&cm_resets_recvd);
32466 + atomic_inc_unchecked(&cm_resets_recvd);
32467 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32468 " refcnt=%d\n", cm_node, cm_node->state,
32469 atomic_read(&cm_node->ref_count));
32470 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32471 rem_ref_cm_node(cm_node->cm_core, cm_node);
32472 return NULL;
32473 }
32474 - atomic_inc(&cm_loopbacks);
32475 + atomic_inc_unchecked(&cm_loopbacks);
32476 loopbackremotenode->loopbackpartner = cm_node;
32477 loopbackremotenode->tcp_cntxt.rcv_wscale =
32478 NES_CM_DEFAULT_RCV_WND_SCALE;
32479 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32480 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32481 else {
32482 rem_ref_cm_node(cm_core, cm_node);
32483 - atomic_inc(&cm_accel_dropped_pkts);
32484 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32485 dev_kfree_skb_any(skb);
32486 }
32487 break;
32488 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32489
32490 if ((cm_id) && (cm_id->event_handler)) {
32491 if (issue_disconn) {
32492 - atomic_inc(&cm_disconnects);
32493 + atomic_inc_unchecked(&cm_disconnects);
32494 cm_event.event = IW_CM_EVENT_DISCONNECT;
32495 cm_event.status = disconn_status;
32496 cm_event.local_addr = cm_id->local_addr;
32497 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32498 }
32499
32500 if (issue_close) {
32501 - atomic_inc(&cm_closes);
32502 + atomic_inc_unchecked(&cm_closes);
32503 nes_disconnect(nesqp, 1);
32504
32505 cm_id->provider_data = nesqp;
32506 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32507
32508 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32509 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32510 - atomic_inc(&cm_accepts);
32511 + atomic_inc_unchecked(&cm_accepts);
32512
32513 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32514 netdev_refcnt_read(nesvnic->netdev));
32515 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32516 struct nes_cm_core *cm_core;
32517 u8 *start_buff;
32518
32519 - atomic_inc(&cm_rejects);
32520 + atomic_inc_unchecked(&cm_rejects);
32521 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32522 loopback = cm_node->loopbackpartner;
32523 cm_core = cm_node->cm_core;
32524 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32525 ntohl(cm_id->local_addr.sin_addr.s_addr),
32526 ntohs(cm_id->local_addr.sin_port));
32527
32528 - atomic_inc(&cm_connects);
32529 + atomic_inc_unchecked(&cm_connects);
32530 nesqp->active_conn = 1;
32531
32532 /* cache the cm_id in the qp */
32533 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32534 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32535 return err;
32536 }
32537 - atomic_inc(&cm_listens_created);
32538 + atomic_inc_unchecked(&cm_listens_created);
32539 }
32540
32541 cm_id->add_ref(cm_id);
32542 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32543
32544 if (nesqp->destroyed)
32545 return;
32546 - atomic_inc(&cm_connecteds);
32547 + atomic_inc_unchecked(&cm_connecteds);
32548 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32549 " local port 0x%04X. jiffies = %lu.\n",
32550 nesqp->hwqp.qp_id,
32551 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32552
32553 cm_id->add_ref(cm_id);
32554 ret = cm_id->event_handler(cm_id, &cm_event);
32555 - atomic_inc(&cm_closes);
32556 + atomic_inc_unchecked(&cm_closes);
32557 cm_event.event = IW_CM_EVENT_CLOSE;
32558 cm_event.status = 0;
32559 cm_event.provider_data = cm_id->provider_data;
32560 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32561 return;
32562 cm_id = cm_node->cm_id;
32563
32564 - atomic_inc(&cm_connect_reqs);
32565 + atomic_inc_unchecked(&cm_connect_reqs);
32566 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32567 cm_node, cm_id, jiffies);
32568
32569 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32570 return;
32571 cm_id = cm_node->cm_id;
32572
32573 - atomic_inc(&cm_connect_reqs);
32574 + atomic_inc_unchecked(&cm_connect_reqs);
32575 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32576 cm_node, cm_id, jiffies);
32577
32578 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32579 index 3ba7be3..c81f6ff 100644
32580 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32581 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32582 @@ -40,8 +40,8 @@
32583 #include "nes.h"
32584 #include "nes_mgt.h"
32585
32586 -atomic_t pau_qps_created;
32587 -atomic_t pau_qps_destroyed;
32588 +atomic_unchecked_t pau_qps_created;
32589 +atomic_unchecked_t pau_qps_destroyed;
32590
32591 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32592 {
32593 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32594 {
32595 struct sk_buff *skb;
32596 unsigned long flags;
32597 - atomic_inc(&pau_qps_destroyed);
32598 + atomic_inc_unchecked(&pau_qps_destroyed);
32599
32600 /* Free packets that have not yet been forwarded */
32601 /* Lock is acquired by skb_dequeue when removing the skb */
32602 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32603 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32604 skb_queue_head_init(&nesqp->pau_list);
32605 spin_lock_init(&nesqp->pau_lock);
32606 - atomic_inc(&pau_qps_created);
32607 + atomic_inc_unchecked(&pau_qps_created);
32608 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32609 }
32610
32611 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32612 index f3a3ecf..57d311d 100644
32613 --- a/drivers/infiniband/hw/nes/nes_nic.c
32614 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32615 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32616 target_stat_values[++index] = mh_detected;
32617 target_stat_values[++index] = mh_pauses_sent;
32618 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32619 - target_stat_values[++index] = atomic_read(&cm_connects);
32620 - target_stat_values[++index] = atomic_read(&cm_accepts);
32621 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32622 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32623 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32624 - target_stat_values[++index] = atomic_read(&cm_rejects);
32625 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32626 - target_stat_values[++index] = atomic_read(&qps_created);
32627 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32628 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32629 - target_stat_values[++index] = atomic_read(&cm_closes);
32630 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32631 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32632 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32633 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32634 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32635 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32636 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32637 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32638 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32639 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32640 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32641 target_stat_values[++index] = cm_packets_sent;
32642 target_stat_values[++index] = cm_packets_bounced;
32643 target_stat_values[++index] = cm_packets_created;
32644 target_stat_values[++index] = cm_packets_received;
32645 target_stat_values[++index] = cm_packets_dropped;
32646 target_stat_values[++index] = cm_packets_retrans;
32647 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32648 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32649 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32650 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32651 target_stat_values[++index] = cm_backlog_drops;
32652 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32653 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32654 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32655 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32656 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32657 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32658 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32659 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32660 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32661 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32662 target_stat_values[++index] = nesadapter->free_4kpbl;
32663 target_stat_values[++index] = nesadapter->free_256pbl;
32664 target_stat_values[++index] = int_mod_timer_init;
32665 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32666 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32667 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32668 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32669 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32670 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32671 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32672 }
32673
32674 /**
32675 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32676 index 8b8812d..a5e1133 100644
32677 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32678 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32679 @@ -46,9 +46,9 @@
32680
32681 #include <rdma/ib_umem.h>
32682
32683 -atomic_t mod_qp_timouts;
32684 -atomic_t qps_created;
32685 -atomic_t sw_qps_destroyed;
32686 +atomic_unchecked_t mod_qp_timouts;
32687 +atomic_unchecked_t qps_created;
32688 +atomic_unchecked_t sw_qps_destroyed;
32689
32690 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32691
32692 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32693 if (init_attr->create_flags)
32694 return ERR_PTR(-EINVAL);
32695
32696 - atomic_inc(&qps_created);
32697 + atomic_inc_unchecked(&qps_created);
32698 switch (init_attr->qp_type) {
32699 case IB_QPT_RC:
32700 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32701 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32702 struct iw_cm_event cm_event;
32703 int ret = 0;
32704
32705 - atomic_inc(&sw_qps_destroyed);
32706 + atomic_inc_unchecked(&sw_qps_destroyed);
32707 nesqp->destroyed = 1;
32708
32709 /* Blow away the connection if it exists. */
32710 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32711 index 7e62f41..4c2b8e2 100644
32712 --- a/drivers/infiniband/hw/qib/qib.h
32713 +++ b/drivers/infiniband/hw/qib/qib.h
32714 @@ -51,6 +51,7 @@
32715 #include <linux/completion.h>
32716 #include <linux/kref.h>
32717 #include <linux/sched.h>
32718 +#include <linux/slab.h>
32719
32720 #include "qib_common.h"
32721 #include "qib_verbs.h"
32722 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32723 index da739d9..da1c7f4 100644
32724 --- a/drivers/input/gameport/gameport.c
32725 +++ b/drivers/input/gameport/gameport.c
32726 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32727 */
32728 static void gameport_init_port(struct gameport *gameport)
32729 {
32730 - static atomic_t gameport_no = ATOMIC_INIT(0);
32731 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32732
32733 __module_get(THIS_MODULE);
32734
32735 mutex_init(&gameport->drv_mutex);
32736 device_initialize(&gameport->dev);
32737 dev_set_name(&gameport->dev, "gameport%lu",
32738 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32739 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32740 gameport->dev.bus = &gameport_bus;
32741 gameport->dev.release = gameport_release_port;
32742 if (gameport->parent)
32743 diff --git a/drivers/input/input.c b/drivers/input/input.c
32744 index 8921c61..f5cd63d 100644
32745 --- a/drivers/input/input.c
32746 +++ b/drivers/input/input.c
32747 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32748 */
32749 int input_register_device(struct input_dev *dev)
32750 {
32751 - static atomic_t input_no = ATOMIC_INIT(0);
32752 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32753 struct input_handler *handler;
32754 const char *path;
32755 int error;
32756 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32757 dev->setkeycode = input_default_setkeycode;
32758
32759 dev_set_name(&dev->dev, "input%ld",
32760 - (unsigned long) atomic_inc_return(&input_no) - 1);
32761 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32762
32763 error = device_add(&dev->dev);
32764 if (error)
32765 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32766 index 04c69af..5f92d00 100644
32767 --- a/drivers/input/joystick/sidewinder.c
32768 +++ b/drivers/input/joystick/sidewinder.c
32769 @@ -30,6 +30,7 @@
32770 #include <linux/kernel.h>
32771 #include <linux/module.h>
32772 #include <linux/slab.h>
32773 +#include <linux/sched.h>
32774 #include <linux/init.h>
32775 #include <linux/input.h>
32776 #include <linux/gameport.h>
32777 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32778 index 83811e4..0822b90 100644
32779 --- a/drivers/input/joystick/xpad.c
32780 +++ b/drivers/input/joystick/xpad.c
32781 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32782
32783 static int xpad_led_probe(struct usb_xpad *xpad)
32784 {
32785 - static atomic_t led_seq = ATOMIC_INIT(0);
32786 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32787 long led_no;
32788 struct xpad_led *led;
32789 struct led_classdev *led_cdev;
32790 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32791 if (!led)
32792 return -ENOMEM;
32793
32794 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32795 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32796
32797 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32798 led->xpad = xpad;
32799 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32800 index 0110b5a..d3ad144 100644
32801 --- a/drivers/input/mousedev.c
32802 +++ b/drivers/input/mousedev.c
32803 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32804
32805 spin_unlock_irq(&client->packet_lock);
32806
32807 - if (copy_to_user(buffer, data, count))
32808 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32809 return -EFAULT;
32810
32811 return count;
32812 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32813 index d0f7533..fb8215b 100644
32814 --- a/drivers/input/serio/serio.c
32815 +++ b/drivers/input/serio/serio.c
32816 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32817 */
32818 static void serio_init_port(struct serio *serio)
32819 {
32820 - static atomic_t serio_no = ATOMIC_INIT(0);
32821 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32822
32823 __module_get(THIS_MODULE);
32824
32825 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32826 mutex_init(&serio->drv_mutex);
32827 device_initialize(&serio->dev);
32828 dev_set_name(&serio->dev, "serio%ld",
32829 - (long)atomic_inc_return(&serio_no) - 1);
32830 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32831 serio->dev.bus = &serio_bus;
32832 serio->dev.release = serio_release_port;
32833 serio->dev.groups = serio_device_attr_groups;
32834 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32835 index 38c4bd8..58965d9 100644
32836 --- a/drivers/isdn/capi/capi.c
32837 +++ b/drivers/isdn/capi/capi.c
32838 @@ -83,8 +83,8 @@ struct capiminor {
32839
32840 struct capi20_appl *ap;
32841 u32 ncci;
32842 - atomic_t datahandle;
32843 - atomic_t msgid;
32844 + atomic_unchecked_t datahandle;
32845 + atomic_unchecked_t msgid;
32846
32847 struct tty_port port;
32848 int ttyinstop;
32849 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32850 capimsg_setu16(s, 2, mp->ap->applid);
32851 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32852 capimsg_setu8 (s, 5, CAPI_RESP);
32853 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32854 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32855 capimsg_setu32(s, 8, mp->ncci);
32856 capimsg_setu16(s, 12, datahandle);
32857 }
32858 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32859 mp->outbytes -= len;
32860 spin_unlock_bh(&mp->outlock);
32861
32862 - datahandle = atomic_inc_return(&mp->datahandle);
32863 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32864 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32865 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32866 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32867 capimsg_setu16(skb->data, 2, mp->ap->applid);
32868 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32869 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32870 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32871 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32872 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32873 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32874 capimsg_setu16(skb->data, 16, len); /* Data length */
32875 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32876 index a6d9fd2..afdb8a3 100644
32877 --- a/drivers/isdn/gigaset/interface.c
32878 +++ b/drivers/isdn/gigaset/interface.c
32879 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32880 }
32881 tty->driver_data = cs;
32882
32883 - ++cs->port.count;
32884 + atomic_inc(&cs->port.count);
32885
32886 - if (cs->port.count == 1) {
32887 + if (atomic_read(&cs->port.count) == 1) {
32888 tty_port_tty_set(&cs->port, tty);
32889 tty->low_latency = 1;
32890 }
32891 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32892
32893 if (!cs->connected)
32894 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32895 - else if (!cs->port.count)
32896 + else if (!atomic_read(&cs->port.count))
32897 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32898 - else if (!--cs->port.count)
32899 + else if (!atomic_dec_return(&cs->port.count))
32900 tty_port_tty_set(&cs->port, NULL);
32901
32902 mutex_unlock(&cs->mutex);
32903 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32904 index 821f7ac..28d4030 100644
32905 --- a/drivers/isdn/hardware/avm/b1.c
32906 +++ b/drivers/isdn/hardware/avm/b1.c
32907 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32908 }
32909 if (left) {
32910 if (t4file->user) {
32911 - if (copy_from_user(buf, dp, left))
32912 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32913 return -EFAULT;
32914 } else {
32915 memcpy(buf, dp, left);
32916 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32917 }
32918 if (left) {
32919 if (config->user) {
32920 - if (copy_from_user(buf, dp, left))
32921 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32922 return -EFAULT;
32923 } else {
32924 memcpy(buf, dp, left);
32925 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32926 index dd6b53a..19d9ee6 100644
32927 --- a/drivers/isdn/hardware/eicon/divasync.h
32928 +++ b/drivers/isdn/hardware/eicon/divasync.h
32929 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32930 } diva_didd_add_adapter_t;
32931 typedef struct _diva_didd_remove_adapter {
32932 IDI_CALL p_request;
32933 -} diva_didd_remove_adapter_t;
32934 +} __no_const diva_didd_remove_adapter_t;
32935 typedef struct _diva_didd_read_adapter_array {
32936 void *buffer;
32937 dword length;
32938 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32939 index d303e65..28bcb7b 100644
32940 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32941 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32942 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32943 typedef struct _diva_os_idi_adapter_interface {
32944 diva_init_card_proc_t cleanup_adapter_proc;
32945 diva_cmd_card_proc_t cmd_proc;
32946 -} diva_os_idi_adapter_interface_t;
32947 +} __no_const diva_os_idi_adapter_interface_t;
32948
32949 typedef struct _diva_os_xdi_adapter {
32950 struct list_head link;
32951 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32952 index 7bc5067..fd36232 100644
32953 --- a/drivers/isdn/i4l/isdn_tty.c
32954 +++ b/drivers/isdn/i4l/isdn_tty.c
32955 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32956 port = &info->port;
32957 #ifdef ISDN_DEBUG_MODEM_OPEN
32958 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32959 - port->count);
32960 + atomic_read(&port->count))
32961 #endif
32962 - port->count++;
32963 + atomic_inc(&port->count);
32964 tty->driver_data = info;
32965 port->tty = tty;
32966 tty->port = port;
32967 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32968 #endif
32969 return;
32970 }
32971 - if ((tty->count == 1) && (port->count != 1)) {
32972 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32973 /*
32974 * Uh, oh. tty->count is 1, which means that the tty
32975 * structure will be freed. Info->count should always
32976 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32977 * serial port won't be shutdown.
32978 */
32979 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32980 - "info->count is %d\n", port->count);
32981 - port->count = 1;
32982 + "info->count is %d\n", atomic_read(&port->count));
32983 + atomic_set(&port->count, 1);
32984 }
32985 - if (--port->count < 0) {
32986 + if (atomic_dec_return(&port->count) < 0) {
32987 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32988 - info->line, port->count);
32989 - port->count = 0;
32990 + info->line, atomic_read(&port->count));
32991 + atomic_set(&port->count, 0);
32992 }
32993 - if (port->count) {
32994 + if (atomic_read(&port->count)) {
32995 #ifdef ISDN_DEBUG_MODEM_OPEN
32996 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32997 #endif
32998 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32999 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33000 return;
33001 isdn_tty_shutdown(info);
33002 - port->count = 0;
33003 + atomic_set(&port->count, 0);
33004 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33005 port->tty = NULL;
33006 wake_up_interruptible(&port->open_wait);
33007 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33008 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33009 modem_info *info = &dev->mdm.info[i];
33010
33011 - if (info->port.count == 0)
33012 + if (atomic_read(&info->port.count) == 0)
33013 continue;
33014 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33015 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33016 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33017 index e74df7c..03a03ba 100644
33018 --- a/drivers/isdn/icn/icn.c
33019 +++ b/drivers/isdn/icn/icn.c
33020 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33021 if (count > len)
33022 count = len;
33023 if (user) {
33024 - if (copy_from_user(msg, buf, count))
33025 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33026 return -EFAULT;
33027 } else
33028 memcpy(msg, buf, count);
33029 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33030 index b5fdcb7..5b6c59f 100644
33031 --- a/drivers/lguest/core.c
33032 +++ b/drivers/lguest/core.c
33033 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33034 * it's worked so far. The end address needs +1 because __get_vm_area
33035 * allocates an extra guard page, so we need space for that.
33036 */
33037 +
33038 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33039 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33040 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33041 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33042 +#else
33043 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33044 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33045 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33046 +#endif
33047 +
33048 if (!switcher_vma) {
33049 err = -ENOMEM;
33050 printk("lguest: could not map switcher pages high\n");
33051 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33052 * Now the Switcher is mapped at the right address, we can't fail!
33053 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33054 */
33055 - memcpy(switcher_vma->addr, start_switcher_text,
33056 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33057 end_switcher_text - start_switcher_text);
33058
33059 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33060 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33061 index 39809035..ce25c5e 100644
33062 --- a/drivers/lguest/x86/core.c
33063 +++ b/drivers/lguest/x86/core.c
33064 @@ -59,7 +59,7 @@ static struct {
33065 /* Offset from where switcher.S was compiled to where we've copied it */
33066 static unsigned long switcher_offset(void)
33067 {
33068 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33069 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33070 }
33071
33072 /* This cpu's struct lguest_pages. */
33073 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33074 * These copies are pretty cheap, so we do them unconditionally: */
33075 /* Save the current Host top-level page directory.
33076 */
33077 +
33078 +#ifdef CONFIG_PAX_PER_CPU_PGD
33079 + pages->state.host_cr3 = read_cr3();
33080 +#else
33081 pages->state.host_cr3 = __pa(current->mm->pgd);
33082 +#endif
33083 +
33084 /*
33085 * Set up the Guest's page tables to see this CPU's pages (and no
33086 * other CPU's pages).
33087 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33088 * compiled-in switcher code and the high-mapped copy we just made.
33089 */
33090 for (i = 0; i < IDT_ENTRIES; i++)
33091 - default_idt_entries[i] += switcher_offset();
33092 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33093
33094 /*
33095 * Set up the Switcher's per-cpu areas.
33096 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33097 * it will be undisturbed when we switch. To change %cs and jump we
33098 * need this structure to feed to Intel's "lcall" instruction.
33099 */
33100 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33101 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33102 lguest_entry.segment = LGUEST_CS;
33103
33104 /*
33105 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33106 index 40634b0..4f5855e 100644
33107 --- a/drivers/lguest/x86/switcher_32.S
33108 +++ b/drivers/lguest/x86/switcher_32.S
33109 @@ -87,6 +87,7 @@
33110 #include <asm/page.h>
33111 #include <asm/segment.h>
33112 #include <asm/lguest.h>
33113 +#include <asm/processor-flags.h>
33114
33115 // We mark the start of the code to copy
33116 // It's placed in .text tho it's never run here
33117 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33118 // Changes type when we load it: damn Intel!
33119 // For after we switch over our page tables
33120 // That entry will be read-only: we'd crash.
33121 +
33122 +#ifdef CONFIG_PAX_KERNEXEC
33123 + mov %cr0, %edx
33124 + xor $X86_CR0_WP, %edx
33125 + mov %edx, %cr0
33126 +#endif
33127 +
33128 movl $(GDT_ENTRY_TSS*8), %edx
33129 ltr %dx
33130
33131 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33132 // Let's clear it again for our return.
33133 // The GDT descriptor of the Host
33134 // Points to the table after two "size" bytes
33135 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33136 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33137 // Clear "used" from type field (byte 5, bit 2)
33138 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33139 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33140 +
33141 +#ifdef CONFIG_PAX_KERNEXEC
33142 + mov %cr0, %eax
33143 + xor $X86_CR0_WP, %eax
33144 + mov %eax, %cr0
33145 +#endif
33146
33147 // Once our page table's switched, the Guest is live!
33148 // The Host fades as we run this final step.
33149 @@ -295,13 +309,12 @@ deliver_to_host:
33150 // I consulted gcc, and it gave
33151 // These instructions, which I gladly credit:
33152 leal (%edx,%ebx,8), %eax
33153 - movzwl (%eax),%edx
33154 - movl 4(%eax), %eax
33155 - xorw %ax, %ax
33156 - orl %eax, %edx
33157 + movl 4(%eax), %edx
33158 + movw (%eax), %dx
33159 // Now the address of the handler's in %edx
33160 // We call it now: its "iret" drops us home.
33161 - jmp *%edx
33162 + ljmp $__KERNEL_CS, $1f
33163 +1: jmp *%edx
33164
33165 // Every interrupt can come to us here
33166 // But we must truly tell each apart.
33167 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33168 index 20e5c2c..9e849a9 100644
33169 --- a/drivers/macintosh/macio_asic.c
33170 +++ b/drivers/macintosh/macio_asic.c
33171 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33172 * MacIO is matched against any Apple ID, it's probe() function
33173 * will then decide wether it applies or not
33174 */
33175 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33176 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33177 .vendor = PCI_VENDOR_ID_APPLE,
33178 .device = PCI_ANY_ID,
33179 .subvendor = PCI_ANY_ID,
33180 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33181 index 15dbe03..743fc65 100644
33182 --- a/drivers/md/bitmap.c
33183 +++ b/drivers/md/bitmap.c
33184 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33185 chunk_kb ? "KB" : "B");
33186 if (bitmap->storage.file) {
33187 seq_printf(seq, ", file: ");
33188 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33189 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33190 }
33191
33192 seq_printf(seq, "\n");
33193 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33194 index a1a3e6d..1918bfc 100644
33195 --- a/drivers/md/dm-ioctl.c
33196 +++ b/drivers/md/dm-ioctl.c
33197 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33198 cmd == DM_LIST_VERSIONS_CMD)
33199 return 0;
33200
33201 - if ((cmd == DM_DEV_CREATE_CMD)) {
33202 + if (cmd == DM_DEV_CREATE_CMD) {
33203 if (!*param->name) {
33204 DMWARN("name not supplied when creating device");
33205 return -EINVAL;
33206 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33207 index b58b7a3..8018b19 100644
33208 --- a/drivers/md/dm-raid1.c
33209 +++ b/drivers/md/dm-raid1.c
33210 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33211
33212 struct mirror {
33213 struct mirror_set *ms;
33214 - atomic_t error_count;
33215 + atomic_unchecked_t error_count;
33216 unsigned long error_type;
33217 struct dm_dev *dev;
33218 sector_t offset;
33219 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33220 struct mirror *m;
33221
33222 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33223 - if (!atomic_read(&m->error_count))
33224 + if (!atomic_read_unchecked(&m->error_count))
33225 return m;
33226
33227 return NULL;
33228 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33229 * simple way to tell if a device has encountered
33230 * errors.
33231 */
33232 - atomic_inc(&m->error_count);
33233 + atomic_inc_unchecked(&m->error_count);
33234
33235 if (test_and_set_bit(error_type, &m->error_type))
33236 return;
33237 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33238 struct mirror *m = get_default_mirror(ms);
33239
33240 do {
33241 - if (likely(!atomic_read(&m->error_count)))
33242 + if (likely(!atomic_read_unchecked(&m->error_count)))
33243 return m;
33244
33245 if (m-- == ms->mirror)
33246 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33247 {
33248 struct mirror *default_mirror = get_default_mirror(m->ms);
33249
33250 - return !atomic_read(&default_mirror->error_count);
33251 + return !atomic_read_unchecked(&default_mirror->error_count);
33252 }
33253
33254 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33255 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33256 */
33257 if (likely(region_in_sync(ms, region, 1)))
33258 m = choose_mirror(ms, bio->bi_sector);
33259 - else if (m && atomic_read(&m->error_count))
33260 + else if (m && atomic_read_unchecked(&m->error_count))
33261 m = NULL;
33262
33263 if (likely(m))
33264 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33265 }
33266
33267 ms->mirror[mirror].ms = ms;
33268 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33269 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33270 ms->mirror[mirror].error_type = 0;
33271 ms->mirror[mirror].offset = offset;
33272
33273 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33274 */
33275 static char device_status_char(struct mirror *m)
33276 {
33277 - if (!atomic_read(&(m->error_count)))
33278 + if (!atomic_read_unchecked(&(m->error_count)))
33279 return 'A';
33280
33281 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33282 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33283 index 35c94ff..20d4c17 100644
33284 --- a/drivers/md/dm-stripe.c
33285 +++ b/drivers/md/dm-stripe.c
33286 @@ -20,7 +20,7 @@ struct stripe {
33287 struct dm_dev *dev;
33288 sector_t physical_start;
33289
33290 - atomic_t error_count;
33291 + atomic_unchecked_t error_count;
33292 };
33293
33294 struct stripe_c {
33295 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33296 kfree(sc);
33297 return r;
33298 }
33299 - atomic_set(&(sc->stripe[i].error_count), 0);
33300 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33301 }
33302
33303 ti->private = sc;
33304 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33305 DMEMIT("%d ", sc->stripes);
33306 for (i = 0; i < sc->stripes; i++) {
33307 DMEMIT("%s ", sc->stripe[i].dev->name);
33308 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33309 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33310 'D' : 'A';
33311 }
33312 buffer[i] = '\0';
33313 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33314 */
33315 for (i = 0; i < sc->stripes; i++)
33316 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33317 - atomic_inc(&(sc->stripe[i].error_count));
33318 - if (atomic_read(&(sc->stripe[i].error_count)) <
33319 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33320 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33321 DM_IO_ERROR_THRESHOLD)
33322 schedule_work(&sc->trigger_event);
33323 }
33324 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33325 index 2e227fb..44ead1f 100644
33326 --- a/drivers/md/dm-table.c
33327 +++ b/drivers/md/dm-table.c
33328 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33329 if (!dev_size)
33330 return 0;
33331
33332 - if ((start >= dev_size) || (start + len > dev_size)) {
33333 + if ((start >= dev_size) || (len > dev_size - start)) {
33334 DMWARN("%s: %s too small for target: "
33335 "start=%llu, len=%llu, dev_size=%llu",
33336 dm_device_name(ti->table->md), bdevname(bdev, b),
33337 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33338 index 3e2907f..c28851a 100644
33339 --- a/drivers/md/dm-thin-metadata.c
33340 +++ b/drivers/md/dm-thin-metadata.c
33341 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33342
33343 pmd->info.tm = tm;
33344 pmd->info.levels = 2;
33345 - pmd->info.value_type.context = pmd->data_sm;
33346 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33347 pmd->info.value_type.size = sizeof(__le64);
33348 pmd->info.value_type.inc = data_block_inc;
33349 pmd->info.value_type.dec = data_block_dec;
33350 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33351
33352 pmd->bl_info.tm = tm;
33353 pmd->bl_info.levels = 1;
33354 - pmd->bl_info.value_type.context = pmd->data_sm;
33355 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33356 pmd->bl_info.value_type.size = sizeof(__le64);
33357 pmd->bl_info.value_type.inc = data_block_inc;
33358 pmd->bl_info.value_type.dec = data_block_dec;
33359 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33360 index e24143c..ce2f21a1 100644
33361 --- a/drivers/md/dm.c
33362 +++ b/drivers/md/dm.c
33363 @@ -176,9 +176,9 @@ struct mapped_device {
33364 /*
33365 * Event handling.
33366 */
33367 - atomic_t event_nr;
33368 + atomic_unchecked_t event_nr;
33369 wait_queue_head_t eventq;
33370 - atomic_t uevent_seq;
33371 + atomic_unchecked_t uevent_seq;
33372 struct list_head uevent_list;
33373 spinlock_t uevent_lock; /* Protect access to uevent_list */
33374
33375 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33376 rwlock_init(&md->map_lock);
33377 atomic_set(&md->holders, 1);
33378 atomic_set(&md->open_count, 0);
33379 - atomic_set(&md->event_nr, 0);
33380 - atomic_set(&md->uevent_seq, 0);
33381 + atomic_set_unchecked(&md->event_nr, 0);
33382 + atomic_set_unchecked(&md->uevent_seq, 0);
33383 INIT_LIST_HEAD(&md->uevent_list);
33384 spin_lock_init(&md->uevent_lock);
33385
33386 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33387
33388 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33389
33390 - atomic_inc(&md->event_nr);
33391 + atomic_inc_unchecked(&md->event_nr);
33392 wake_up(&md->eventq);
33393 }
33394
33395 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33396
33397 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33398 {
33399 - return atomic_add_return(1, &md->uevent_seq);
33400 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33401 }
33402
33403 uint32_t dm_get_event_nr(struct mapped_device *md)
33404 {
33405 - return atomic_read(&md->event_nr);
33406 + return atomic_read_unchecked(&md->event_nr);
33407 }
33408
33409 int dm_wait_event(struct mapped_device *md, int event_nr)
33410 {
33411 return wait_event_interruptible(md->eventq,
33412 - (event_nr != atomic_read(&md->event_nr)));
33413 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33414 }
33415
33416 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33417 diff --git a/drivers/md/md.c b/drivers/md/md.c
33418 index d5ab449..7e9ed7b 100644
33419 --- a/drivers/md/md.c
33420 +++ b/drivers/md/md.c
33421 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33422 * start build, activate spare
33423 */
33424 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33425 -static atomic_t md_event_count;
33426 +static atomic_unchecked_t md_event_count;
33427 void md_new_event(struct mddev *mddev)
33428 {
33429 - atomic_inc(&md_event_count);
33430 + atomic_inc_unchecked(&md_event_count);
33431 wake_up(&md_event_waiters);
33432 }
33433 EXPORT_SYMBOL_GPL(md_new_event);
33434 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33435 */
33436 static void md_new_event_inintr(struct mddev *mddev)
33437 {
33438 - atomic_inc(&md_event_count);
33439 + atomic_inc_unchecked(&md_event_count);
33440 wake_up(&md_event_waiters);
33441 }
33442
33443 @@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33444 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33445 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33446 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33447 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33448 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33449
33450 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33451 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33452 @@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33453 else
33454 sb->resync_offset = cpu_to_le64(0);
33455
33456 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33457 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33458
33459 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33460 sb->size = cpu_to_le64(mddev->dev_sectors);
33461 @@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33462 static ssize_t
33463 errors_show(struct md_rdev *rdev, char *page)
33464 {
33465 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33466 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33467 }
33468
33469 static ssize_t
33470 @@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33471 char *e;
33472 unsigned long n = simple_strtoul(buf, &e, 10);
33473 if (*buf && (*e == 0 || *e == '\n')) {
33474 - atomic_set(&rdev->corrected_errors, n);
33475 + atomic_set_unchecked(&rdev->corrected_errors, n);
33476 return len;
33477 }
33478 return -EINVAL;
33479 @@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33480 rdev->sb_loaded = 0;
33481 rdev->bb_page = NULL;
33482 atomic_set(&rdev->nr_pending, 0);
33483 - atomic_set(&rdev->read_errors, 0);
33484 - atomic_set(&rdev->corrected_errors, 0);
33485 + atomic_set_unchecked(&rdev->read_errors, 0);
33486 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33487
33488 INIT_LIST_HEAD(&rdev->same_set);
33489 init_waitqueue_head(&rdev->blocked_wait);
33490 @@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33491
33492 spin_unlock(&pers_lock);
33493 seq_printf(seq, "\n");
33494 - seq->poll_event = atomic_read(&md_event_count);
33495 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33496 return 0;
33497 }
33498 if (v == (void*)2) {
33499 @@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33500 return error;
33501
33502 seq = file->private_data;
33503 - seq->poll_event = atomic_read(&md_event_count);
33504 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33505 return error;
33506 }
33507
33508 @@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33509 /* always allow read */
33510 mask = POLLIN | POLLRDNORM;
33511
33512 - if (seq->poll_event != atomic_read(&md_event_count))
33513 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33514 mask |= POLLERR | POLLPRI;
33515 return mask;
33516 }
33517 @@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33518 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33519 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33520 (int)part_stat_read(&disk->part0, sectors[1]) -
33521 - atomic_read(&disk->sync_io);
33522 + atomic_read_unchecked(&disk->sync_io);
33523 /* sync IO will cause sync_io to increase before the disk_stats
33524 * as sync_io is counted when a request starts, and
33525 * disk_stats is counted when it completes.
33526 diff --git a/drivers/md/md.h b/drivers/md/md.h
33527 index 7b4a3c3..994ad4f 100644
33528 --- a/drivers/md/md.h
33529 +++ b/drivers/md/md.h
33530 @@ -94,13 +94,13 @@ struct md_rdev {
33531 * only maintained for arrays that
33532 * support hot removal
33533 */
33534 - atomic_t read_errors; /* number of consecutive read errors that
33535 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33536 * we have tried to ignore.
33537 */
33538 struct timespec last_read_error; /* monotonic time since our
33539 * last read error
33540 */
33541 - atomic_t corrected_errors; /* number of corrected read errors,
33542 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33543 * for reporting to userspace and storing
33544 * in superblock.
33545 */
33546 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33547
33548 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33549 {
33550 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33551 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33552 }
33553
33554 struct md_personality
33555 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33556 index fc90c11..c8cd9a9 100644
33557 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33558 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33559 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33560 /*----------------------------------------------------------------*/
33561
33562 struct sm_checker {
33563 - struct dm_space_map sm;
33564 + dm_space_map_no_const sm;
33565
33566 struct count_array old_counts;
33567 struct count_array counts;
33568 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33569 index 3d0ed53..35dc592 100644
33570 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33571 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33572 @@ -23,7 +23,7 @@
33573 * Space map interface.
33574 */
33575 struct sm_disk {
33576 - struct dm_space_map sm;
33577 + dm_space_map_no_const sm;
33578
33579 struct ll_disk ll;
33580 struct ll_disk old_ll;
33581 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33582 index e89ae5e..062e4c2 100644
33583 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33584 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33585 @@ -43,7 +43,7 @@ struct block_op {
33586 };
33587
33588 struct sm_metadata {
33589 - struct dm_space_map sm;
33590 + dm_space_map_no_const sm;
33591
33592 struct ll_disk ll;
33593 struct ll_disk old_ll;
33594 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33595 index 1cbfc6b..56e1dbb 100644
33596 --- a/drivers/md/persistent-data/dm-space-map.h
33597 +++ b/drivers/md/persistent-data/dm-space-map.h
33598 @@ -60,6 +60,7 @@ struct dm_space_map {
33599 int (*root_size)(struct dm_space_map *sm, size_t *result);
33600 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33601 };
33602 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33603
33604 /*----------------------------------------------------------------*/
33605
33606 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33607 index 53aec45..250851c 100644
33608 --- a/drivers/md/raid1.c
33609 +++ b/drivers/md/raid1.c
33610 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33611 if (r1_sync_page_io(rdev, sect, s,
33612 bio->bi_io_vec[idx].bv_page,
33613 READ) != 0)
33614 - atomic_add(s, &rdev->corrected_errors);
33615 + atomic_add_unchecked(s, &rdev->corrected_errors);
33616 }
33617 sectors -= s;
33618 sect += s;
33619 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33620 test_bit(In_sync, &rdev->flags)) {
33621 if (r1_sync_page_io(rdev, sect, s,
33622 conf->tmppage, READ)) {
33623 - atomic_add(s, &rdev->corrected_errors);
33624 + atomic_add_unchecked(s, &rdev->corrected_errors);
33625 printk(KERN_INFO
33626 "md/raid1:%s: read error corrected "
33627 "(%d sectors at %llu on %s)\n",
33628 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33629 index 8da6282..8ec7103 100644
33630 --- a/drivers/md/raid10.c
33631 +++ b/drivers/md/raid10.c
33632 @@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33633 /* The write handler will notice the lack of
33634 * R10BIO_Uptodate and record any errors etc
33635 */
33636 - atomic_add(r10_bio->sectors,
33637 + atomic_add_unchecked(r10_bio->sectors,
33638 &conf->mirrors[d].rdev->corrected_errors);
33639
33640 /* for reconstruct, we always reschedule after a read.
33641 @@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33642 {
33643 struct timespec cur_time_mon;
33644 unsigned long hours_since_last;
33645 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33646 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33647
33648 ktime_get_ts(&cur_time_mon);
33649
33650 @@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33651 * overflowing the shift of read_errors by hours_since_last.
33652 */
33653 if (hours_since_last >= 8 * sizeof(read_errors))
33654 - atomic_set(&rdev->read_errors, 0);
33655 + atomic_set_unchecked(&rdev->read_errors, 0);
33656 else
33657 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33658 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33659 }
33660
33661 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33662 @@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33663 return;
33664
33665 check_decay_read_errors(mddev, rdev);
33666 - atomic_inc(&rdev->read_errors);
33667 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33668 + atomic_inc_unchecked(&rdev->read_errors);
33669 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33670 char b[BDEVNAME_SIZE];
33671 bdevname(rdev->bdev, b);
33672
33673 @@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33674 "md/raid10:%s: %s: Raid device exceeded "
33675 "read_error threshold [cur %d:max %d]\n",
33676 mdname(mddev), b,
33677 - atomic_read(&rdev->read_errors), max_read_errors);
33678 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33679 printk(KERN_NOTICE
33680 "md/raid10:%s: %s: Failing raid device\n",
33681 mdname(mddev), b);
33682 @@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33683 sect +
33684 choose_data_offset(r10_bio, rdev)),
33685 bdevname(rdev->bdev, b));
33686 - atomic_add(s, &rdev->corrected_errors);
33687 + atomic_add_unchecked(s, &rdev->corrected_errors);
33688 }
33689
33690 rdev_dec_pending(rdev, mddev);
33691 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33692 index 04348d7..62a4b9b 100644
33693 --- a/drivers/md/raid5.c
33694 +++ b/drivers/md/raid5.c
33695 @@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33696 mdname(conf->mddev), STRIPE_SECTORS,
33697 (unsigned long long)s,
33698 bdevname(rdev->bdev, b));
33699 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33700 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33701 clear_bit(R5_ReadError, &sh->dev[i].flags);
33702 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33703 }
33704 - if (atomic_read(&rdev->read_errors))
33705 - atomic_set(&rdev->read_errors, 0);
33706 + if (atomic_read_unchecked(&rdev->read_errors))
33707 + atomic_set_unchecked(&rdev->read_errors, 0);
33708 } else {
33709 const char *bdn = bdevname(rdev->bdev, b);
33710 int retry = 0;
33711 int set_bad = 0;
33712
33713 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33714 - atomic_inc(&rdev->read_errors);
33715 + atomic_inc_unchecked(&rdev->read_errors);
33716 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33717 printk_ratelimited(
33718 KERN_WARNING
33719 @@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33720 mdname(conf->mddev),
33721 (unsigned long long)s,
33722 bdn);
33723 - } else if (atomic_read(&rdev->read_errors)
33724 + } else if (atomic_read_unchecked(&rdev->read_errors)
33725 > conf->max_nr_stripes)
33726 printk(KERN_WARNING
33727 "md/raid:%s: Too many read errors, failing device %s.\n",
33728 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33729 index 131b938..8572ed1 100644
33730 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33731 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33732 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33733 .subvendor = _subvend, .subdevice = _subdev, \
33734 .driver_data = (unsigned long)&_driverdata }
33735
33736 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33737 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33738 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33739 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33740 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33741 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33742 index fa7188a..04a045e 100644
33743 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33744 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33745 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33746 union {
33747 dmx_ts_cb ts;
33748 dmx_section_cb sec;
33749 - } cb;
33750 + } __no_const cb;
33751
33752 struct dvb_demux *demux;
33753 void *priv;
33754 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33755 index 39eab73..60033e7 100644
33756 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33757 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33758 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33759 const struct dvb_device *template, void *priv, int type)
33760 {
33761 struct dvb_device *dvbdev;
33762 - struct file_operations *dvbdevfops;
33763 + file_operations_no_const *dvbdevfops;
33764 struct device *clsdev;
33765 int minor;
33766 int id;
33767 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33768 index 4008b9c..ce714f5 100644
33769 --- a/drivers/media/dvb/dvb-usb/az6007.c
33770 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33771 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33772 int ret;
33773
33774 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33775 - memcpy(mac, st->data, sizeof(mac));
33776 + memcpy(mac, st->data, 6);
33777
33778 if (ret > 0)
33779 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33780 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33781 index 3940bb0..fb3952a 100644
33782 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33783 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33784 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33785
33786 struct dib0700_adapter_state {
33787 int (*set_param_save) (struct dvb_frontend *);
33788 -};
33789 +} __no_const;
33790
33791 static int dib7070_set_param_override(struct dvb_frontend *fe)
33792 {
33793 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33794 index 9382895..ac8093c 100644
33795 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33796 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33797 @@ -95,7 +95,7 @@ struct su3000_state {
33798
33799 struct s6x0_state {
33800 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33801 -};
33802 +} __no_const;
33803
33804 /* debug */
33805 static int dvb_usb_dw2102_debug;
33806 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33807 index 404f63a..4796533 100644
33808 --- a/drivers/media/dvb/frontends/dib3000.h
33809 +++ b/drivers/media/dvb/frontends/dib3000.h
33810 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33811 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33812 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33813 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33814 -};
33815 +} __no_const;
33816
33817 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33818 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33819 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33820 index 7539a5d..06531a6 100644
33821 --- a/drivers/media/dvb/ngene/ngene-cards.c
33822 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33823 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33824
33825 /****************************************************************************/
33826
33827 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33828 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33829 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33830 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33831 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33832 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33833 index 16a089f..1661b11 100644
33834 --- a/drivers/media/radio/radio-cadet.c
33835 +++ b/drivers/media/radio/radio-cadet.c
33836 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33837 unsigned char readbuf[RDS_BUFFER];
33838 int i = 0;
33839
33840 + if (count > RDS_BUFFER)
33841 + return -EFAULT;
33842 mutex_lock(&dev->lock);
33843 if (dev->rdsstat == 0) {
33844 dev->rdsstat = 1;
33845 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33846 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33847 mutex_unlock(&dev->lock);
33848
33849 - if (copy_to_user(data, readbuf, i))
33850 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33851 return -EFAULT;
33852 return i;
33853 }
33854 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33855 index 9cde353..8c6a1c3 100644
33856 --- a/drivers/media/video/au0828/au0828.h
33857 +++ b/drivers/media/video/au0828/au0828.h
33858 @@ -191,7 +191,7 @@ struct au0828_dev {
33859
33860 /* I2C */
33861 struct i2c_adapter i2c_adap;
33862 - struct i2c_algorithm i2c_algo;
33863 + i2c_algorithm_no_const i2c_algo;
33864 struct i2c_client i2c_client;
33865 u32 i2c_rc;
33866
33867 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33868 index 04bf662..e0ac026 100644
33869 --- a/drivers/media/video/cx88/cx88-alsa.c
33870 +++ b/drivers/media/video/cx88/cx88-alsa.c
33871 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33872 * Only boards with eeprom and byte 1 at eeprom=1 have it
33873 */
33874
33875 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33876 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33877 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33878 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33879 {0, }
33880 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33881 index 88cf9d9..bbc4b2c 100644
33882 --- a/drivers/media/video/omap/omap_vout.c
33883 +++ b/drivers/media/video/omap/omap_vout.c
33884 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33885 OMAP_VIDEO2,
33886 };
33887
33888 -static struct videobuf_queue_ops video_vbq_ops;
33889 /* Variables configurable through module params*/
33890 static u32 video1_numbuffers = 3;
33891 static u32 video2_numbuffers = 3;
33892 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33893 {
33894 struct videobuf_queue *q;
33895 struct omap_vout_device *vout = NULL;
33896 + static struct videobuf_queue_ops video_vbq_ops = {
33897 + .buf_setup = omap_vout_buffer_setup,
33898 + .buf_prepare = omap_vout_buffer_prepare,
33899 + .buf_release = omap_vout_buffer_release,
33900 + .buf_queue = omap_vout_buffer_queue,
33901 + };
33902
33903 vout = video_drvdata(file);
33904 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33905 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33906 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33907
33908 q = &vout->vbq;
33909 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33910 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33911 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33912 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33913 spin_lock_init(&vout->vbq_lock);
33914
33915 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33916 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33917 index 036952f..80d356d 100644
33918 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33919 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33920 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33921
33922 /* I2C stuff */
33923 struct i2c_adapter i2c_adap;
33924 - struct i2c_algorithm i2c_algo;
33925 + i2c_algorithm_no_const i2c_algo;
33926 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33927 int i2c_cx25840_hack_state;
33928 int i2c_linked;
33929 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33930 index 02194c0..091733b 100644
33931 --- a/drivers/media/video/timblogiw.c
33932 +++ b/drivers/media/video/timblogiw.c
33933 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33934
33935 /* Platform device functions */
33936
33937 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33938 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33939 .vidioc_querycap = timblogiw_querycap,
33940 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33941 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33942 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33943 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33944 };
33945
33946 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33947 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33948 .owner = THIS_MODULE,
33949 .open = timblogiw_open,
33950 .release = timblogiw_close,
33951 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33952 index d99db56..a16b959 100644
33953 --- a/drivers/message/fusion/mptbase.c
33954 +++ b/drivers/message/fusion/mptbase.c
33955 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33956 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33957 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33958
33959 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33960 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33961 +#else
33962 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33963 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33964 +#endif
33965 +
33966 /*
33967 * Rounding UP to nearest 4-kB boundary here...
33968 */
33969 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33970 index 551262e..7551198 100644
33971 --- a/drivers/message/fusion/mptsas.c
33972 +++ b/drivers/message/fusion/mptsas.c
33973 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33974 return 0;
33975 }
33976
33977 +static inline void
33978 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33979 +{
33980 + if (phy_info->port_details) {
33981 + phy_info->port_details->rphy = rphy;
33982 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33983 + ioc->name, rphy));
33984 + }
33985 +
33986 + if (rphy) {
33987 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33988 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33989 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33990 + ioc->name, rphy, rphy->dev.release));
33991 + }
33992 +}
33993 +
33994 /* no mutex */
33995 static void
33996 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33997 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33998 return NULL;
33999 }
34000
34001 -static inline void
34002 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34003 -{
34004 - if (phy_info->port_details) {
34005 - phy_info->port_details->rphy = rphy;
34006 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34007 - ioc->name, rphy));
34008 - }
34009 -
34010 - if (rphy) {
34011 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34012 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34013 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34014 - ioc->name, rphy, rphy->dev.release));
34015 - }
34016 -}
34017 -
34018 static inline struct sas_port *
34019 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34020 {
34021 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34022 index 0c3ced7..1fe34ec 100644
34023 --- a/drivers/message/fusion/mptscsih.c
34024 +++ b/drivers/message/fusion/mptscsih.c
34025 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34026
34027 h = shost_priv(SChost);
34028
34029 - if (h) {
34030 - if (h->info_kbuf == NULL)
34031 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34032 - return h->info_kbuf;
34033 - h->info_kbuf[0] = '\0';
34034 + if (!h)
34035 + return NULL;
34036
34037 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34038 - h->info_kbuf[size-1] = '\0';
34039 - }
34040 + if (h->info_kbuf == NULL)
34041 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34042 + return h->info_kbuf;
34043 + h->info_kbuf[0] = '\0';
34044 +
34045 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34046 + h->info_kbuf[size-1] = '\0';
34047
34048 return h->info_kbuf;
34049 }
34050 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34051 index 506c36f..b137580 100644
34052 --- a/drivers/message/i2o/i2o_proc.c
34053 +++ b/drivers/message/i2o/i2o_proc.c
34054 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34055 "Array Controller Device"
34056 };
34057
34058 -static char *chtostr(u8 * chars, int n)
34059 -{
34060 - char tmp[256];
34061 - tmp[0] = 0;
34062 - return strncat(tmp, (char *)chars, n);
34063 -}
34064 -
34065 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34066 char *group)
34067 {
34068 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34069
34070 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34071 seq_printf(seq, "%-#8x", ddm_table.module_id);
34072 - seq_printf(seq, "%-29s",
34073 - chtostr(ddm_table.module_name_version, 28));
34074 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34075 seq_printf(seq, "%9d ", ddm_table.data_size);
34076 seq_printf(seq, "%8d", ddm_table.code_size);
34077
34078 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34079
34080 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34081 seq_printf(seq, "%-#8x", dst->module_id);
34082 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34083 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34084 + seq_printf(seq, "%-.28s", dst->module_name_version);
34085 + seq_printf(seq, "%-.8s", dst->date);
34086 seq_printf(seq, "%8d ", dst->module_size);
34087 seq_printf(seq, "%8d ", dst->mpb_size);
34088 seq_printf(seq, "0x%04x", dst->module_flags);
34089 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34090 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34091 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34092 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34093 - seq_printf(seq, "Vendor info : %s\n",
34094 - chtostr((u8 *) (work32 + 2), 16));
34095 - seq_printf(seq, "Product info : %s\n",
34096 - chtostr((u8 *) (work32 + 6), 16));
34097 - seq_printf(seq, "Description : %s\n",
34098 - chtostr((u8 *) (work32 + 10), 16));
34099 - seq_printf(seq, "Product rev. : %s\n",
34100 - chtostr((u8 *) (work32 + 14), 8));
34101 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34102 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34103 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34104 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34105
34106 seq_printf(seq, "Serial number : ");
34107 print_serial_number(seq, (u8 *) (work32 + 16),
34108 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34109 }
34110
34111 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34112 - seq_printf(seq, "Module name : %s\n",
34113 - chtostr(result.module_name, 24));
34114 - seq_printf(seq, "Module revision : %s\n",
34115 - chtostr(result.module_rev, 8));
34116 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34117 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34118
34119 seq_printf(seq, "Serial number : ");
34120 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34121 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34122 return 0;
34123 }
34124
34125 - seq_printf(seq, "Device name : %s\n",
34126 - chtostr(result.device_name, 64));
34127 - seq_printf(seq, "Service name : %s\n",
34128 - chtostr(result.service_name, 64));
34129 - seq_printf(seq, "Physical name : %s\n",
34130 - chtostr(result.physical_location, 64));
34131 - seq_printf(seq, "Instance number : %s\n",
34132 - chtostr(result.instance_number, 4));
34133 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34134 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34135 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34136 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34137
34138 return 0;
34139 }
34140 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34141 index a8c08f3..155fe3d 100644
34142 --- a/drivers/message/i2o/iop.c
34143 +++ b/drivers/message/i2o/iop.c
34144 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34145
34146 spin_lock_irqsave(&c->context_list_lock, flags);
34147
34148 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34149 - atomic_inc(&c->context_list_counter);
34150 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34151 + atomic_inc_unchecked(&c->context_list_counter);
34152
34153 - entry->context = atomic_read(&c->context_list_counter);
34154 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34155
34156 list_add(&entry->list, &c->context_list);
34157
34158 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34159
34160 #if BITS_PER_LONG == 64
34161 spin_lock_init(&c->context_list_lock);
34162 - atomic_set(&c->context_list_counter, 0);
34163 + atomic_set_unchecked(&c->context_list_counter, 0);
34164 INIT_LIST_HEAD(&c->context_list);
34165 #endif
34166
34167 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34168 index 7ce65f4..e66e9bc 100644
34169 --- a/drivers/mfd/abx500-core.c
34170 +++ b/drivers/mfd/abx500-core.c
34171 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34172
34173 struct abx500_device_entry {
34174 struct list_head list;
34175 - struct abx500_ops ops;
34176 + abx500_ops_no_const ops;
34177 struct device *dev;
34178 };
34179
34180 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34181 index 2ea9998..51dabee 100644
34182 --- a/drivers/mfd/janz-cmodio.c
34183 +++ b/drivers/mfd/janz-cmodio.c
34184 @@ -13,6 +13,7 @@
34185
34186 #include <linux/kernel.h>
34187 #include <linux/module.h>
34188 +#include <linux/slab.h>
34189 #include <linux/init.h>
34190 #include <linux/pci.h>
34191 #include <linux/interrupt.h>
34192 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34193 index a981e2a..5ca0c8b 100644
34194 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34195 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34196 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34197 * the lid is closed. This leads to interrupts as soon as a little move
34198 * is done.
34199 */
34200 - atomic_inc(&lis3->count);
34201 + atomic_inc_unchecked(&lis3->count);
34202
34203 wake_up_interruptible(&lis3->misc_wait);
34204 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34205 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34206 if (lis3->pm_dev)
34207 pm_runtime_get_sync(lis3->pm_dev);
34208
34209 - atomic_set(&lis3->count, 0);
34210 + atomic_set_unchecked(&lis3->count, 0);
34211 return 0;
34212 }
34213
34214 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34215 add_wait_queue(&lis3->misc_wait, &wait);
34216 while (true) {
34217 set_current_state(TASK_INTERRUPTIBLE);
34218 - data = atomic_xchg(&lis3->count, 0);
34219 + data = atomic_xchg_unchecked(&lis3->count, 0);
34220 if (data)
34221 break;
34222
34223 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34224 struct lis3lv02d, miscdev);
34225
34226 poll_wait(file, &lis3->misc_wait, wait);
34227 - if (atomic_read(&lis3->count))
34228 + if (atomic_read_unchecked(&lis3->count))
34229 return POLLIN | POLLRDNORM;
34230 return 0;
34231 }
34232 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34233 index 2b1482a..5d33616 100644
34234 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34235 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34236 @@ -266,7 +266,7 @@ struct lis3lv02d {
34237 struct input_polled_dev *idev; /* input device */
34238 struct platform_device *pdev; /* platform device */
34239 struct regulator_bulk_data regulators[2];
34240 - atomic_t count; /* interrupt count after last read */
34241 + atomic_unchecked_t count; /* interrupt count after last read */
34242 union axis_conversion ac; /* hw -> logical axis */
34243 int mapped_btns[3];
34244
34245 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34246 index 28adefe..08aad69 100644
34247 --- a/drivers/misc/lkdtm.c
34248 +++ b/drivers/misc/lkdtm.c
34249 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34250 int i, n, out;
34251
34252 buf = (char *)__get_free_page(GFP_KERNEL);
34253 + if (buf == NULL)
34254 + return -ENOMEM;
34255
34256 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34257 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34258 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34259 index 2f30bad..c4c13d0 100644
34260 --- a/drivers/misc/sgi-gru/gruhandles.c
34261 +++ b/drivers/misc/sgi-gru/gruhandles.c
34262 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34263 unsigned long nsec;
34264
34265 nsec = CLKS2NSEC(clks);
34266 - atomic_long_inc(&mcs_op_statistics[op].count);
34267 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34268 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34269 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34270 if (mcs_op_statistics[op].max < nsec)
34271 mcs_op_statistics[op].max = nsec;
34272 }
34273 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34274 index 950dbe9..eeef0f8 100644
34275 --- a/drivers/misc/sgi-gru/gruprocfs.c
34276 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34277 @@ -32,9 +32,9 @@
34278
34279 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34280
34281 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34282 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34283 {
34284 - unsigned long val = atomic_long_read(v);
34285 + unsigned long val = atomic_long_read_unchecked(v);
34286
34287 seq_printf(s, "%16lu %s\n", val, id);
34288 }
34289 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34290
34291 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34292 for (op = 0; op < mcsop_last; op++) {
34293 - count = atomic_long_read(&mcs_op_statistics[op].count);
34294 - total = atomic_long_read(&mcs_op_statistics[op].total);
34295 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34296 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34297 max = mcs_op_statistics[op].max;
34298 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34299 count ? total / count : 0, max);
34300 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34301 index 5c3ce24..4915ccb 100644
34302 --- a/drivers/misc/sgi-gru/grutables.h
34303 +++ b/drivers/misc/sgi-gru/grutables.h
34304 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34305 * GRU statistics.
34306 */
34307 struct gru_stats_s {
34308 - atomic_long_t vdata_alloc;
34309 - atomic_long_t vdata_free;
34310 - atomic_long_t gts_alloc;
34311 - atomic_long_t gts_free;
34312 - atomic_long_t gms_alloc;
34313 - atomic_long_t gms_free;
34314 - atomic_long_t gts_double_allocate;
34315 - atomic_long_t assign_context;
34316 - atomic_long_t assign_context_failed;
34317 - atomic_long_t free_context;
34318 - atomic_long_t load_user_context;
34319 - atomic_long_t load_kernel_context;
34320 - atomic_long_t lock_kernel_context;
34321 - atomic_long_t unlock_kernel_context;
34322 - atomic_long_t steal_user_context;
34323 - atomic_long_t steal_kernel_context;
34324 - atomic_long_t steal_context_failed;
34325 - atomic_long_t nopfn;
34326 - atomic_long_t asid_new;
34327 - atomic_long_t asid_next;
34328 - atomic_long_t asid_wrap;
34329 - atomic_long_t asid_reuse;
34330 - atomic_long_t intr;
34331 - atomic_long_t intr_cbr;
34332 - atomic_long_t intr_tfh;
34333 - atomic_long_t intr_spurious;
34334 - atomic_long_t intr_mm_lock_failed;
34335 - atomic_long_t call_os;
34336 - atomic_long_t call_os_wait_queue;
34337 - atomic_long_t user_flush_tlb;
34338 - atomic_long_t user_unload_context;
34339 - atomic_long_t user_exception;
34340 - atomic_long_t set_context_option;
34341 - atomic_long_t check_context_retarget_intr;
34342 - atomic_long_t check_context_unload;
34343 - atomic_long_t tlb_dropin;
34344 - atomic_long_t tlb_preload_page;
34345 - atomic_long_t tlb_dropin_fail_no_asid;
34346 - atomic_long_t tlb_dropin_fail_upm;
34347 - atomic_long_t tlb_dropin_fail_invalid;
34348 - atomic_long_t tlb_dropin_fail_range_active;
34349 - atomic_long_t tlb_dropin_fail_idle;
34350 - atomic_long_t tlb_dropin_fail_fmm;
34351 - atomic_long_t tlb_dropin_fail_no_exception;
34352 - atomic_long_t tfh_stale_on_fault;
34353 - atomic_long_t mmu_invalidate_range;
34354 - atomic_long_t mmu_invalidate_page;
34355 - atomic_long_t flush_tlb;
34356 - atomic_long_t flush_tlb_gru;
34357 - atomic_long_t flush_tlb_gru_tgh;
34358 - atomic_long_t flush_tlb_gru_zero_asid;
34359 + atomic_long_unchecked_t vdata_alloc;
34360 + atomic_long_unchecked_t vdata_free;
34361 + atomic_long_unchecked_t gts_alloc;
34362 + atomic_long_unchecked_t gts_free;
34363 + atomic_long_unchecked_t gms_alloc;
34364 + atomic_long_unchecked_t gms_free;
34365 + atomic_long_unchecked_t gts_double_allocate;
34366 + atomic_long_unchecked_t assign_context;
34367 + atomic_long_unchecked_t assign_context_failed;
34368 + atomic_long_unchecked_t free_context;
34369 + atomic_long_unchecked_t load_user_context;
34370 + atomic_long_unchecked_t load_kernel_context;
34371 + atomic_long_unchecked_t lock_kernel_context;
34372 + atomic_long_unchecked_t unlock_kernel_context;
34373 + atomic_long_unchecked_t steal_user_context;
34374 + atomic_long_unchecked_t steal_kernel_context;
34375 + atomic_long_unchecked_t steal_context_failed;
34376 + atomic_long_unchecked_t nopfn;
34377 + atomic_long_unchecked_t asid_new;
34378 + atomic_long_unchecked_t asid_next;
34379 + atomic_long_unchecked_t asid_wrap;
34380 + atomic_long_unchecked_t asid_reuse;
34381 + atomic_long_unchecked_t intr;
34382 + atomic_long_unchecked_t intr_cbr;
34383 + atomic_long_unchecked_t intr_tfh;
34384 + atomic_long_unchecked_t intr_spurious;
34385 + atomic_long_unchecked_t intr_mm_lock_failed;
34386 + atomic_long_unchecked_t call_os;
34387 + atomic_long_unchecked_t call_os_wait_queue;
34388 + atomic_long_unchecked_t user_flush_tlb;
34389 + atomic_long_unchecked_t user_unload_context;
34390 + atomic_long_unchecked_t user_exception;
34391 + atomic_long_unchecked_t set_context_option;
34392 + atomic_long_unchecked_t check_context_retarget_intr;
34393 + atomic_long_unchecked_t check_context_unload;
34394 + atomic_long_unchecked_t tlb_dropin;
34395 + atomic_long_unchecked_t tlb_preload_page;
34396 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34397 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34398 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34399 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34400 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34401 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34402 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34403 + atomic_long_unchecked_t tfh_stale_on_fault;
34404 + atomic_long_unchecked_t mmu_invalidate_range;
34405 + atomic_long_unchecked_t mmu_invalidate_page;
34406 + atomic_long_unchecked_t flush_tlb;
34407 + atomic_long_unchecked_t flush_tlb_gru;
34408 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34409 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34410
34411 - atomic_long_t copy_gpa;
34412 - atomic_long_t read_gpa;
34413 + atomic_long_unchecked_t copy_gpa;
34414 + atomic_long_unchecked_t read_gpa;
34415
34416 - atomic_long_t mesq_receive;
34417 - atomic_long_t mesq_receive_none;
34418 - atomic_long_t mesq_send;
34419 - atomic_long_t mesq_send_failed;
34420 - atomic_long_t mesq_noop;
34421 - atomic_long_t mesq_send_unexpected_error;
34422 - atomic_long_t mesq_send_lb_overflow;
34423 - atomic_long_t mesq_send_qlimit_reached;
34424 - atomic_long_t mesq_send_amo_nacked;
34425 - atomic_long_t mesq_send_put_nacked;
34426 - atomic_long_t mesq_page_overflow;
34427 - atomic_long_t mesq_qf_locked;
34428 - atomic_long_t mesq_qf_noop_not_full;
34429 - atomic_long_t mesq_qf_switch_head_failed;
34430 - atomic_long_t mesq_qf_unexpected_error;
34431 - atomic_long_t mesq_noop_unexpected_error;
34432 - atomic_long_t mesq_noop_lb_overflow;
34433 - atomic_long_t mesq_noop_qlimit_reached;
34434 - atomic_long_t mesq_noop_amo_nacked;
34435 - atomic_long_t mesq_noop_put_nacked;
34436 - atomic_long_t mesq_noop_page_overflow;
34437 + atomic_long_unchecked_t mesq_receive;
34438 + atomic_long_unchecked_t mesq_receive_none;
34439 + atomic_long_unchecked_t mesq_send;
34440 + atomic_long_unchecked_t mesq_send_failed;
34441 + atomic_long_unchecked_t mesq_noop;
34442 + atomic_long_unchecked_t mesq_send_unexpected_error;
34443 + atomic_long_unchecked_t mesq_send_lb_overflow;
34444 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34445 + atomic_long_unchecked_t mesq_send_amo_nacked;
34446 + atomic_long_unchecked_t mesq_send_put_nacked;
34447 + atomic_long_unchecked_t mesq_page_overflow;
34448 + atomic_long_unchecked_t mesq_qf_locked;
34449 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34450 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34451 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34452 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34453 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34454 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34455 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34456 + atomic_long_unchecked_t mesq_noop_put_nacked;
34457 + atomic_long_unchecked_t mesq_noop_page_overflow;
34458
34459 };
34460
34461 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34462 tghop_invalidate, mcsop_last};
34463
34464 struct mcs_op_statistic {
34465 - atomic_long_t count;
34466 - atomic_long_t total;
34467 + atomic_long_unchecked_t count;
34468 + atomic_long_unchecked_t total;
34469 unsigned long max;
34470 };
34471
34472 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34473
34474 #define STAT(id) do { \
34475 if (gru_options & OPT_STATS) \
34476 - atomic_long_inc(&gru_stats.id); \
34477 + atomic_long_inc_unchecked(&gru_stats.id); \
34478 } while (0)
34479
34480 #ifdef CONFIG_SGI_GRU_DEBUG
34481 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34482 index c862cd4..0d176fe 100644
34483 --- a/drivers/misc/sgi-xp/xp.h
34484 +++ b/drivers/misc/sgi-xp/xp.h
34485 @@ -288,7 +288,7 @@ struct xpc_interface {
34486 xpc_notify_func, void *);
34487 void (*received) (short, int, void *);
34488 enum xp_retval (*partid_to_nasids) (short, void *);
34489 -};
34490 +} __no_const;
34491
34492 extern struct xpc_interface xpc_interface;
34493
34494 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34495 index b94d5f7..7f494c5 100644
34496 --- a/drivers/misc/sgi-xp/xpc.h
34497 +++ b/drivers/misc/sgi-xp/xpc.h
34498 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34499 void (*received_payload) (struct xpc_channel *, void *);
34500 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34501 };
34502 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34503
34504 /* struct xpc_partition act_state values (for XPC HB) */
34505
34506 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34507 /* found in xpc_main.c */
34508 extern struct device *xpc_part;
34509 extern struct device *xpc_chan;
34510 -extern struct xpc_arch_operations xpc_arch_ops;
34511 +extern xpc_arch_operations_no_const xpc_arch_ops;
34512 extern int xpc_disengage_timelimit;
34513 extern int xpc_disengage_timedout;
34514 extern int xpc_activate_IRQ_rcvd;
34515 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34516 index 8d082b4..aa749ae 100644
34517 --- a/drivers/misc/sgi-xp/xpc_main.c
34518 +++ b/drivers/misc/sgi-xp/xpc_main.c
34519 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34520 .notifier_call = xpc_system_die,
34521 };
34522
34523 -struct xpc_arch_operations xpc_arch_ops;
34524 +xpc_arch_operations_no_const xpc_arch_ops;
34525
34526 /*
34527 * Timer function to enforce the timelimit on the partition disengage.
34528 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34529 index 2b62232..acfaeeb 100644
34530 --- a/drivers/misc/ti-st/st_core.c
34531 +++ b/drivers/misc/ti-st/st_core.c
34532 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34533 st_gdata->rx_skb = alloc_skb(
34534 st_gdata->list[type]->max_frame_size,
34535 GFP_ATOMIC);
34536 + if (st_gdata->rx_skb == NULL) {
34537 + pr_err("out of memory: dropping\n");
34538 + goto done;
34539 + }
34540 +
34541 skb_reserve(st_gdata->rx_skb,
34542 st_gdata->list[type]->reserve);
34543 /* next 2 required for BT only */
34544 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34545 index 504da71..9722d43 100644
34546 --- a/drivers/mmc/host/sdhci-pci.c
34547 +++ b/drivers/mmc/host/sdhci-pci.c
34548 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34549 .probe = via_probe,
34550 };
34551
34552 -static const struct pci_device_id pci_ids[] __devinitdata = {
34553 +static const struct pci_device_id pci_ids[] __devinitconst = {
34554 {
34555 .vendor = PCI_VENDOR_ID_RICOH,
34556 .device = PCI_DEVICE_ID_RICOH_R5C822,
34557 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34558 index a4eb8b5..8c0628f 100644
34559 --- a/drivers/mtd/devices/doc2000.c
34560 +++ b/drivers/mtd/devices/doc2000.c
34561 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34562
34563 /* The ECC will not be calculated correctly if less than 512 is written */
34564 /* DBB-
34565 - if (len != 0x200 && eccbuf)
34566 + if (len != 0x200)
34567 printk(KERN_WARNING
34568 "ECC needs a full sector write (adr: %lx size %lx)\n",
34569 (long) to, (long) len);
34570 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34571 index 0650aaf..7718762 100644
34572 --- a/drivers/mtd/nand/denali.c
34573 +++ b/drivers/mtd/nand/denali.c
34574 @@ -26,6 +26,7 @@
34575 #include <linux/pci.h>
34576 #include <linux/mtd/mtd.h>
34577 #include <linux/module.h>
34578 +#include <linux/slab.h>
34579
34580 #include "denali.h"
34581
34582 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34583 index 51b9d6a..52af9a7 100644
34584 --- a/drivers/mtd/nftlmount.c
34585 +++ b/drivers/mtd/nftlmount.c
34586 @@ -24,6 +24,7 @@
34587 #include <asm/errno.h>
34588 #include <linux/delay.h>
34589 #include <linux/slab.h>
34590 +#include <linux/sched.h>
34591 #include <linux/mtd/mtd.h>
34592 #include <linux/mtd/nand.h>
34593 #include <linux/mtd/nftl.h>
34594 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34595 index 6762dc4..9956862 100644
34596 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34597 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34598 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34599 */
34600
34601 #define ATL2_PARAM(X, desc) \
34602 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34603 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34604 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34605 MODULE_PARM_DESC(X, desc);
34606 #else
34607 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34608 index efd80bd..21fcff0 100644
34609 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34610 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34611 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34612
34613 int (*wait_comp)(struct bnx2x *bp,
34614 struct bnx2x_rx_mode_ramrod_params *p);
34615 -};
34616 +} __no_const;
34617
34618 /********************** Set multicast group ***********************************/
34619
34620 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34621 index 93865f8..5448741 100644
34622 --- a/drivers/net/ethernet/broadcom/tg3.h
34623 +++ b/drivers/net/ethernet/broadcom/tg3.h
34624 @@ -140,6 +140,7 @@
34625 #define CHIPREV_ID_5750_A0 0x4000
34626 #define CHIPREV_ID_5750_A1 0x4001
34627 #define CHIPREV_ID_5750_A3 0x4003
34628 +#define CHIPREV_ID_5750_C1 0x4201
34629 #define CHIPREV_ID_5750_C2 0x4202
34630 #define CHIPREV_ID_5752_A0_HW 0x5000
34631 #define CHIPREV_ID_5752_A0 0x6000
34632 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34633 index c4e8643..0979484 100644
34634 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34635 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34636 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34637 */
34638 struct l2t_skb_cb {
34639 arp_failure_handler_func arp_failure_handler;
34640 -};
34641 +} __no_const;
34642
34643 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34644
34645 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34646 index d3cd489..0fd52dd 100644
34647 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34648 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34649 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34650 for (i=0; i<ETH_ALEN; i++) {
34651 tmp.addr[i] = dev->dev_addr[i];
34652 }
34653 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34654 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34655 break;
34656
34657 case DE4X5_SET_HWADDR: /* Set the hardware address */
34658 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34659 spin_lock_irqsave(&lp->lock, flags);
34660 memcpy(&statbuf, &lp->pktStats, ioc->len);
34661 spin_unlock_irqrestore(&lp->lock, flags);
34662 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34663 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34664 return -EFAULT;
34665 break;
34666 }
34667 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34668 index ed7d1dc..d426748 100644
34669 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34670 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34671 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34672 {NULL}};
34673
34674
34675 -static const char *block_name[] __devinitdata = {
34676 +static const char *block_name[] __devinitconst = {
34677 "21140 non-MII",
34678 "21140 MII PHY",
34679 "21142 Serial PHY",
34680 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34681 index 75d45f8..3d9c55b 100644
34682 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34683 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34684 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34685 struct uli_phy_ops {
34686 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34687 u16 (*read)(struct uli526x_board_info *, u8, u8);
34688 - } phy;
34689 + } __no_const phy;
34690 struct net_device *next_dev; /* next device */
34691 struct pci_dev *pdev; /* PCI device */
34692 spinlock_t lock;
34693 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34694 index 4d1ffca..7c1ec4d 100644
34695 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34696 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34697 @@ -236,7 +236,7 @@ struct pci_id_info {
34698 int drv_flags; /* Driver use, intended as capability flags. */
34699 };
34700
34701 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34702 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34703 { /* Sometime a Level-One switch card. */
34704 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34705 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34706 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34707 index d7bb52a..3b83588 100644
34708 --- a/drivers/net/ethernet/dlink/sundance.c
34709 +++ b/drivers/net/ethernet/dlink/sundance.c
34710 @@ -218,7 +218,7 @@ enum {
34711 struct pci_id_info {
34712 const char *name;
34713 };
34714 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34715 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34716 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34717 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34718 {"D-Link DFE-580TX 4 port Server Adapter"},
34719 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34720 index bd5cf7e..c165651 100644
34721 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34722 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34723 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34724
34725 if (wrapped)
34726 newacc += 65536;
34727 - ACCESS_ONCE(*acc) = newacc;
34728 + ACCESS_ONCE_RW(*acc) = newacc;
34729 }
34730
34731 void be_parse_stats(struct be_adapter *adapter)
34732 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34733 index 16b0704..d2c07d7 100644
34734 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34735 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34736 @@ -31,6 +31,8 @@
34737 #include <linux/netdevice.h>
34738 #include <linux/phy.h>
34739 #include <linux/platform_device.h>
34740 +#include <linux/interrupt.h>
34741 +#include <linux/irqreturn.h>
34742 #include <net/ip.h>
34743
34744 #include "ftgmac100.h"
34745 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34746 index 829b109..4ae5f6a 100644
34747 --- a/drivers/net/ethernet/faraday/ftmac100.c
34748 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34749 @@ -31,6 +31,8 @@
34750 #include <linux/module.h>
34751 #include <linux/netdevice.h>
34752 #include <linux/platform_device.h>
34753 +#include <linux/interrupt.h>
34754 +#include <linux/irqreturn.h>
34755
34756 #include "ftmac100.h"
34757
34758 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34759 index 9d71c9c..0e4a0ac 100644
34760 --- a/drivers/net/ethernet/fealnx.c
34761 +++ b/drivers/net/ethernet/fealnx.c
34762 @@ -150,7 +150,7 @@ struct chip_info {
34763 int flags;
34764 };
34765
34766 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34767 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34768 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34769 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34770 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34771 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34772 index 6e6fffb..588f361 100644
34773 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34774 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34775 @@ -181,7 +181,7 @@ struct e1000_info;
34776 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34777 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34778 E1000_TXDCTL_COUNT_DESC | \
34779 - (5 << 16) | /* wthresh must be +1 more than desired */\
34780 + (1 << 16) | /* wthresh must be +1 more than desired */\
34781 (1 << 8) | /* hthresh */ \
34782 0x1f) /* pthresh */
34783
34784 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34785 index ed5b409..ec37828 100644
34786 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34787 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34788 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34789 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34790 s32 (*read_mac_addr)(struct e1000_hw *);
34791 };
34792 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34793
34794 /*
34795 * When to use various PHY register access functions:
34796 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34797 void (*power_up)(struct e1000_hw *);
34798 void (*power_down)(struct e1000_hw *);
34799 };
34800 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34801
34802 /* Function pointers for the NVM. */
34803 struct e1000_nvm_operations {
34804 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34805 s32 (*validate)(struct e1000_hw *);
34806 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34807 };
34808 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34809
34810 struct e1000_mac_info {
34811 - struct e1000_mac_operations ops;
34812 + e1000_mac_operations_no_const ops;
34813 u8 addr[ETH_ALEN];
34814 u8 perm_addr[ETH_ALEN];
34815
34816 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34817 };
34818
34819 struct e1000_phy_info {
34820 - struct e1000_phy_operations ops;
34821 + e1000_phy_operations_no_const ops;
34822
34823 enum e1000_phy_type type;
34824
34825 @@ -926,7 +929,7 @@ struct e1000_phy_info {
34826 };
34827
34828 struct e1000_nvm_info {
34829 - struct e1000_nvm_operations ops;
34830 + e1000_nvm_operations_no_const ops;
34831
34832 enum e1000_nvm_type type;
34833 enum e1000_nvm_override override;
34834 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34835 index c2a51dc..c2bd262 100644
34836 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34837 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34838 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34839 void (*release_swfw_sync)(struct e1000_hw *, u16);
34840
34841 };
34842 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34843
34844 struct e1000_phy_operations {
34845 s32 (*acquire)(struct e1000_hw *);
34846 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34847 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34848 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34849 };
34850 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34851
34852 struct e1000_nvm_operations {
34853 s32 (*acquire)(struct e1000_hw *);
34854 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34855 s32 (*validate)(struct e1000_hw *);
34856 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34857 };
34858 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34859
34860 struct e1000_info {
34861 s32 (*get_invariants)(struct e1000_hw *);
34862 @@ -364,7 +367,7 @@ struct e1000_info {
34863 extern const struct e1000_info e1000_82575_info;
34864
34865 struct e1000_mac_info {
34866 - struct e1000_mac_operations ops;
34867 + e1000_mac_operations_no_const ops;
34868
34869 u8 addr[6];
34870 u8 perm_addr[6];
34871 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34872 };
34873
34874 struct e1000_phy_info {
34875 - struct e1000_phy_operations ops;
34876 + e1000_phy_operations_no_const ops;
34877
34878 enum e1000_phy_type type;
34879
34880 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34881 };
34882
34883 struct e1000_nvm_info {
34884 - struct e1000_nvm_operations ops;
34885 + e1000_nvm_operations_no_const ops;
34886 enum e1000_nvm_type type;
34887 enum e1000_nvm_override override;
34888
34889 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34890 s32 (*check_for_ack)(struct e1000_hw *, u16);
34891 s32 (*check_for_rst)(struct e1000_hw *, u16);
34892 };
34893 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34894
34895 struct e1000_mbx_stats {
34896 u32 msgs_tx;
34897 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34898 };
34899
34900 struct e1000_mbx_info {
34901 - struct e1000_mbx_operations ops;
34902 + e1000_mbx_operations_no_const ops;
34903 struct e1000_mbx_stats stats;
34904 u32 timeout;
34905 u32 usec_delay;
34906 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34907 index 57db3c6..aa825fc 100644
34908 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34909 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34910 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34911 s32 (*read_mac_addr)(struct e1000_hw *);
34912 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34913 };
34914 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34915
34916 struct e1000_mac_info {
34917 - struct e1000_mac_operations ops;
34918 + e1000_mac_operations_no_const ops;
34919 u8 addr[6];
34920 u8 perm_addr[6];
34921
34922 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34923 s32 (*check_for_ack)(struct e1000_hw *);
34924 s32 (*check_for_rst)(struct e1000_hw *);
34925 };
34926 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34927
34928 struct e1000_mbx_stats {
34929 u32 msgs_tx;
34930 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34931 };
34932
34933 struct e1000_mbx_info {
34934 - struct e1000_mbx_operations ops;
34935 + e1000_mbx_operations_no_const ops;
34936 struct e1000_mbx_stats stats;
34937 u32 timeout;
34938 u32 usec_delay;
34939 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34940 index dcebd12..c1fe8be 100644
34941 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34942 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34943 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34944 /* store the new cycle speed */
34945 adapter->cycle_speed = cycle_speed;
34946
34947 - ACCESS_ONCE(adapter->base_incval) = incval;
34948 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34949 smp_mb();
34950
34951 /* grab the ptp lock */
34952 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34953 index 204848d..d8aeaec 100644
34954 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34955 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34956 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34957 s32 (*update_checksum)(struct ixgbe_hw *);
34958 u16 (*calc_checksum)(struct ixgbe_hw *);
34959 };
34960 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34961
34962 struct ixgbe_mac_operations {
34963 s32 (*init_hw)(struct ixgbe_hw *);
34964 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34965 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34966 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34967 };
34968 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34969
34970 struct ixgbe_phy_operations {
34971 s32 (*identify)(struct ixgbe_hw *);
34972 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34973 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34974 s32 (*check_overtemp)(struct ixgbe_hw *);
34975 };
34976 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34977
34978 struct ixgbe_eeprom_info {
34979 - struct ixgbe_eeprom_operations ops;
34980 + ixgbe_eeprom_operations_no_const ops;
34981 enum ixgbe_eeprom_type type;
34982 u32 semaphore_delay;
34983 u16 word_size;
34984 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34985
34986 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34987 struct ixgbe_mac_info {
34988 - struct ixgbe_mac_operations ops;
34989 + ixgbe_mac_operations_no_const ops;
34990 enum ixgbe_mac_type type;
34991 u8 addr[ETH_ALEN];
34992 u8 perm_addr[ETH_ALEN];
34993 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34994 };
34995
34996 struct ixgbe_phy_info {
34997 - struct ixgbe_phy_operations ops;
34998 + ixgbe_phy_operations_no_const ops;
34999 struct mdio_if_info mdio;
35000 enum ixgbe_phy_type type;
35001 u32 id;
35002 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
35003 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35004 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35005 };
35006 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35007
35008 struct ixgbe_mbx_stats {
35009 u32 msgs_tx;
35010 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
35011 };
35012
35013 struct ixgbe_mbx_info {
35014 - struct ixgbe_mbx_operations ops;
35015 + ixgbe_mbx_operations_no_const ops;
35016 struct ixgbe_mbx_stats stats;
35017 u32 timeout;
35018 u32 usec_delay;
35019 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35020 index 25c951d..cc7cf33 100644
35021 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35022 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35023 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35024 s32 (*clear_vfta)(struct ixgbe_hw *);
35025 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35026 };
35027 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35028
35029 enum ixgbe_mac_type {
35030 ixgbe_mac_unknown = 0,
35031 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35032 };
35033
35034 struct ixgbe_mac_info {
35035 - struct ixgbe_mac_operations ops;
35036 + ixgbe_mac_operations_no_const ops;
35037 u8 addr[6];
35038 u8 perm_addr[6];
35039
35040 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35041 s32 (*check_for_ack)(struct ixgbe_hw *);
35042 s32 (*check_for_rst)(struct ixgbe_hw *);
35043 };
35044 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35045
35046 struct ixgbe_mbx_stats {
35047 u32 msgs_tx;
35048 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35049 };
35050
35051 struct ixgbe_mbx_info {
35052 - struct ixgbe_mbx_operations ops;
35053 + ixgbe_mbx_operations_no_const ops;
35054 struct ixgbe_mbx_stats stats;
35055 u32 timeout;
35056 u32 udelay;
35057 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35058 index a0313de..e83a572 100644
35059 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35060 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35061 @@ -41,6 +41,7 @@
35062 #include <linux/slab.h>
35063 #include <linux/io-mapping.h>
35064 #include <linux/delay.h>
35065 +#include <linux/sched.h>
35066
35067 #include <linux/mlx4/device.h>
35068 #include <linux/mlx4/doorbell.h>
35069 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35070 index 5046a64..71ca936 100644
35071 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35072 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35073 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35074 void (*link_down)(struct __vxge_hw_device *devh);
35075 void (*crit_err)(struct __vxge_hw_device *devh,
35076 enum vxge_hw_event type, u64 ext_data);
35077 -};
35078 +} __no_const;
35079
35080 /*
35081 * struct __vxge_hw_blockpool_entry - Block private data structure
35082 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35083 index 4a518a3..936b334 100644
35084 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35085 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35086 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35087 struct vxge_hw_mempool_dma *dma_object,
35088 u32 index,
35089 u32 is_last);
35090 -};
35091 +} __no_const;
35092
35093 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35094 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35095 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35096 index eb81da4..1592b62 100644
35097 --- a/drivers/net/ethernet/realtek/r8169.c
35098 +++ b/drivers/net/ethernet/realtek/r8169.c
35099 @@ -723,22 +723,22 @@ struct rtl8169_private {
35100 struct mdio_ops {
35101 void (*write)(void __iomem *, int, int);
35102 int (*read)(void __iomem *, int);
35103 - } mdio_ops;
35104 + } __no_const mdio_ops;
35105
35106 struct pll_power_ops {
35107 void (*down)(struct rtl8169_private *);
35108 void (*up)(struct rtl8169_private *);
35109 - } pll_power_ops;
35110 + } __no_const pll_power_ops;
35111
35112 struct jumbo_ops {
35113 void (*enable)(struct rtl8169_private *);
35114 void (*disable)(struct rtl8169_private *);
35115 - } jumbo_ops;
35116 + } __no_const jumbo_ops;
35117
35118 struct csi_ops {
35119 void (*write)(void __iomem *, int, int);
35120 u32 (*read)(void __iomem *, int);
35121 - } csi_ops;
35122 + } __no_const csi_ops;
35123
35124 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35125 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35126 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35127 index 4613591..d816601 100644
35128 --- a/drivers/net/ethernet/sis/sis190.c
35129 +++ b/drivers/net/ethernet/sis/sis190.c
35130 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35131 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35132 struct net_device *dev)
35133 {
35134 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35135 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35136 struct sis190_private *tp = netdev_priv(dev);
35137 struct pci_dev *isa_bridge;
35138 u8 reg, tmp8;
35139 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35140 index c07cfe9..81cbf7e 100644
35141 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35142 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35143 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35144
35145 writel(value, ioaddr + MMC_CNTRL);
35146
35147 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35148 - MMC_CNTRL, value);
35149 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35150 +// MMC_CNTRL, value);
35151 }
35152
35153 /* To mask all all interrupts.*/
35154 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35155 index 2857ab0..9a1f9b0 100644
35156 --- a/drivers/net/hyperv/hyperv_net.h
35157 +++ b/drivers/net/hyperv/hyperv_net.h
35158 @@ -99,7 +99,7 @@ struct rndis_device {
35159
35160 enum rndis_device_state state;
35161 bool link_state;
35162 - atomic_t new_req_id;
35163 + atomic_unchecked_t new_req_id;
35164
35165 spinlock_t request_lock;
35166 struct list_head req_list;
35167 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35168 index 981ebb1..b34959b 100644
35169 --- a/drivers/net/hyperv/rndis_filter.c
35170 +++ b/drivers/net/hyperv/rndis_filter.c
35171 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35172 * template
35173 */
35174 set = &rndis_msg->msg.set_req;
35175 - set->req_id = atomic_inc_return(&dev->new_req_id);
35176 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35177
35178 /* Add to the request list */
35179 spin_lock_irqsave(&dev->request_lock, flags);
35180 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35181
35182 /* Setup the rndis set */
35183 halt = &request->request_msg.msg.halt_req;
35184 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35185 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35186
35187 /* Ignore return since this msg is optional. */
35188 rndis_filter_send_request(dev, request);
35189 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35190 index 5c05572..389610b 100644
35191 --- a/drivers/net/ppp/ppp_generic.c
35192 +++ b/drivers/net/ppp/ppp_generic.c
35193 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35194 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35195 struct ppp_stats stats;
35196 struct ppp_comp_stats cstats;
35197 - char *vers;
35198
35199 switch (cmd) {
35200 case SIOCGPPPSTATS:
35201 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35202 break;
35203
35204 case SIOCGPPPVER:
35205 - vers = PPP_VERSION;
35206 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35207 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35208 break;
35209 err = 0;
35210 break;
35211 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35212 index 62f30b4..ff99dfd 100644
35213 --- a/drivers/net/usb/hso.c
35214 +++ b/drivers/net/usb/hso.c
35215 @@ -71,7 +71,7 @@
35216 #include <asm/byteorder.h>
35217 #include <linux/serial_core.h>
35218 #include <linux/serial.h>
35219 -
35220 +#include <asm/local.h>
35221
35222 #define MOD_AUTHOR "Option Wireless"
35223 #define MOD_DESCRIPTION "USB High Speed Option driver"
35224 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35225 struct urb *urb;
35226
35227 urb = serial->rx_urb[0];
35228 - if (serial->port.count > 0) {
35229 + if (atomic_read(&serial->port.count) > 0) {
35230 count = put_rxbuf_data(urb, serial);
35231 if (count == -1)
35232 return;
35233 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35234 DUMP1(urb->transfer_buffer, urb->actual_length);
35235
35236 /* Anyone listening? */
35237 - if (serial->port.count == 0)
35238 + if (atomic_read(&serial->port.count) == 0)
35239 return;
35240
35241 if (status == 0) {
35242 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35243 tty_port_tty_set(&serial->port, tty);
35244
35245 /* check for port already opened, if not set the termios */
35246 - serial->port.count++;
35247 - if (serial->port.count == 1) {
35248 + if (atomic_inc_return(&serial->port.count) == 1) {
35249 serial->rx_state = RX_IDLE;
35250 /* Force default termio settings */
35251 _hso_serial_set_termios(tty, NULL);
35252 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35253 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35254 if (result) {
35255 hso_stop_serial_device(serial->parent);
35256 - serial->port.count--;
35257 + atomic_dec(&serial->port.count);
35258 kref_put(&serial->parent->ref, hso_serial_ref_free);
35259 }
35260 } else {
35261 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35262
35263 /* reset the rts and dtr */
35264 /* do the actual close */
35265 - serial->port.count--;
35266 + atomic_dec(&serial->port.count);
35267
35268 - if (serial->port.count <= 0) {
35269 - serial->port.count = 0;
35270 + if (atomic_read(&serial->port.count) <= 0) {
35271 + atomic_set(&serial->port.count, 0);
35272 tty_port_tty_set(&serial->port, NULL);
35273 if (!usb_gone)
35274 hso_stop_serial_device(serial->parent);
35275 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35276
35277 /* the actual setup */
35278 spin_lock_irqsave(&serial->serial_lock, flags);
35279 - if (serial->port.count)
35280 + if (atomic_read(&serial->port.count))
35281 _hso_serial_set_termios(tty, old);
35282 else
35283 tty->termios = old;
35284 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35285 D1("Pending read interrupt on port %d\n", i);
35286 spin_lock(&serial->serial_lock);
35287 if (serial->rx_state == RX_IDLE &&
35288 - serial->port.count > 0) {
35289 + atomic_read(&serial->port.count) > 0) {
35290 /* Setup and send a ctrl req read on
35291 * port i */
35292 if (!serial->rx_urb_filled[0]) {
35293 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35294 /* Start all serial ports */
35295 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35296 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35297 - if (dev2ser(serial_table[i])->port.count) {
35298 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35299 result =
35300 hso_start_serial_device(serial_table[i], GFP_NOIO);
35301 hso_kick_transmit(dev2ser(serial_table[i]));
35302 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35303 index 420d69b..74f90a2 100644
35304 --- a/drivers/net/wireless/ath/ath.h
35305 +++ b/drivers/net/wireless/ath/ath.h
35306 @@ -119,6 +119,7 @@ struct ath_ops {
35307 void (*write_flush) (void *);
35308 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35309 };
35310 +typedef struct ath_ops __no_const ath_ops_no_const;
35311
35312 struct ath_common;
35313 struct ath_bus_ops;
35314 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35315 index 8d78253..bebbb68 100644
35316 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35317 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35318 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35319 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35320 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35321
35322 - ACCESS_ONCE(ads->ds_link) = i->link;
35323 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35324 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35325 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35326
35327 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35328 ctl6 = SM(i->keytype, AR_EncrType);
35329 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35330
35331 if ((i->is_first || i->is_last) &&
35332 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35333 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35334 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35335 | set11nTries(i->rates, 1)
35336 | set11nTries(i->rates, 2)
35337 | set11nTries(i->rates, 3)
35338 | (i->dur_update ? AR_DurUpdateEna : 0)
35339 | SM(0, AR_BurstDur);
35340
35341 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35342 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35343 | set11nRate(i->rates, 1)
35344 | set11nRate(i->rates, 2)
35345 | set11nRate(i->rates, 3);
35346 } else {
35347 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35348 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35349 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35350 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35351 }
35352
35353 if (!i->is_first) {
35354 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35355 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35356 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35357 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35358 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35359 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35360 return;
35361 }
35362
35363 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35364 break;
35365 }
35366
35367 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35368 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35369 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35370 | SM(i->txpower, AR_XmitPower)
35371 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35372 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35373 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35374 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35375
35376 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35377 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35378 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35379 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35380
35381 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35382 return;
35383
35384 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35385 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35386 | set11nPktDurRTSCTS(i->rates, 1);
35387
35388 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35389 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35390 | set11nPktDurRTSCTS(i->rates, 3);
35391
35392 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35393 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35394 | set11nRateFlags(i->rates, 1)
35395 | set11nRateFlags(i->rates, 2)
35396 | set11nRateFlags(i->rates, 3)
35397 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35398 index d9e0824..1a874e7 100644
35399 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35400 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35401 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35402 (i->qcu << AR_TxQcuNum_S) | desc_len;
35403
35404 checksum += val;
35405 - ACCESS_ONCE(ads->info) = val;
35406 + ACCESS_ONCE_RW(ads->info) = val;
35407
35408 checksum += i->link;
35409 - ACCESS_ONCE(ads->link) = i->link;
35410 + ACCESS_ONCE_RW(ads->link) = i->link;
35411
35412 checksum += i->buf_addr[0];
35413 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35414 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35415 checksum += i->buf_addr[1];
35416 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35417 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35418 checksum += i->buf_addr[2];
35419 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35420 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35421 checksum += i->buf_addr[3];
35422 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35423 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35424
35425 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35426 - ACCESS_ONCE(ads->ctl3) = val;
35427 + ACCESS_ONCE_RW(ads->ctl3) = val;
35428 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35429 - ACCESS_ONCE(ads->ctl5) = val;
35430 + ACCESS_ONCE_RW(ads->ctl5) = val;
35431 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35432 - ACCESS_ONCE(ads->ctl7) = val;
35433 + ACCESS_ONCE_RW(ads->ctl7) = val;
35434 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35435 - ACCESS_ONCE(ads->ctl9) = val;
35436 + ACCESS_ONCE_RW(ads->ctl9) = val;
35437
35438 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35439 - ACCESS_ONCE(ads->ctl10) = checksum;
35440 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35441
35442 if (i->is_first || i->is_last) {
35443 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35444 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35445 | set11nTries(i->rates, 1)
35446 | set11nTries(i->rates, 2)
35447 | set11nTries(i->rates, 3)
35448 | (i->dur_update ? AR_DurUpdateEna : 0)
35449 | SM(0, AR_BurstDur);
35450
35451 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35452 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35453 | set11nRate(i->rates, 1)
35454 | set11nRate(i->rates, 2)
35455 | set11nRate(i->rates, 3);
35456 } else {
35457 - ACCESS_ONCE(ads->ctl13) = 0;
35458 - ACCESS_ONCE(ads->ctl14) = 0;
35459 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35460 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35461 }
35462
35463 ads->ctl20 = 0;
35464 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35465
35466 ctl17 = SM(i->keytype, AR_EncrType);
35467 if (!i->is_first) {
35468 - ACCESS_ONCE(ads->ctl11) = 0;
35469 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35470 - ACCESS_ONCE(ads->ctl15) = 0;
35471 - ACCESS_ONCE(ads->ctl16) = 0;
35472 - ACCESS_ONCE(ads->ctl17) = ctl17;
35473 - ACCESS_ONCE(ads->ctl18) = 0;
35474 - ACCESS_ONCE(ads->ctl19) = 0;
35475 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35476 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35477 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35478 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35479 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35480 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35481 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35482 return;
35483 }
35484
35485 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35486 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35487 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35488 | SM(i->txpower, AR_XmitPower)
35489 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35490 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35491 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35492 ctl12 |= SM(val, AR_PAPRDChainMask);
35493
35494 - ACCESS_ONCE(ads->ctl12) = ctl12;
35495 - ACCESS_ONCE(ads->ctl17) = ctl17;
35496 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35497 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35498
35499 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35500 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35501 | set11nPktDurRTSCTS(i->rates, 1);
35502
35503 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35504 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35505 | set11nPktDurRTSCTS(i->rates, 3);
35506
35507 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35508 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35509 | set11nRateFlags(i->rates, 1)
35510 | set11nRateFlags(i->rates, 2)
35511 | set11nRateFlags(i->rates, 3)
35512 | SM(i->rtscts_rate, AR_RTSCTSRate);
35513
35514 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35515 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35516 }
35517
35518 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35519 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35520 index 02f5007..bd0bd8f 100644
35521 --- a/drivers/net/wireless/ath/ath9k/hw.h
35522 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35523 @@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35524
35525 /* ANI */
35526 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35527 -};
35528 +} __no_const;
35529
35530 /**
35531 * struct ath_hw_ops - callbacks used by hardware code and driver code
35532 @@ -640,7 +640,7 @@ struct ath_hw_ops {
35533 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35534 struct ath_hw_antcomb_conf *antconf);
35535
35536 -};
35537 +} __no_const;
35538
35539 struct ath_nf_limits {
35540 s16 max;
35541 @@ -660,7 +660,7 @@ enum ath_cal_list {
35542 #define AH_FASTCC 0x4
35543
35544 struct ath_hw {
35545 - struct ath_ops reg_ops;
35546 + ath_ops_no_const reg_ops;
35547
35548 struct ieee80211_hw *hw;
35549 struct ath_common common;
35550 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35551 index af00e2c..ab04d34 100644
35552 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35553 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35554 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35555 void (*carrsuppr)(struct brcms_phy *);
35556 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35557 void (*detach)(struct brcms_phy *);
35558 -};
35559 +} __no_const;
35560
35561 struct brcms_phy {
35562 struct brcms_phy_pub pubpi_ro;
35563 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35564 index faec404..a5277f1 100644
35565 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35566 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35567 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35568 */
35569 if (il3945_mod_params.disable_hw_scan) {
35570 D_INFO("Disabling hw_scan\n");
35571 - il3945_mac_ops.hw_scan = NULL;
35572 + pax_open_kernel();
35573 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35574 + pax_close_kernel();
35575 }
35576
35577 D_INFO("*** LOAD DRIVER ***\n");
35578 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35579 index a0b7cfd..20b49f7 100644
35580 --- a/drivers/net/wireless/mac80211_hwsim.c
35581 +++ b/drivers/net/wireless/mac80211_hwsim.c
35582 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35583 return -EINVAL;
35584
35585 if (fake_hw_scan) {
35586 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35587 - mac80211_hwsim_ops.sw_scan_start = NULL;
35588 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35589 + pax_open_kernel();
35590 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35591 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35592 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35593 + pax_close_kernel();
35594 }
35595
35596 spin_lock_init(&hwsim_radio_lock);
35597 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35598 index bd3b0bf..f9db92a 100644
35599 --- a/drivers/net/wireless/mwifiex/main.h
35600 +++ b/drivers/net/wireless/mwifiex/main.h
35601 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35602 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35603 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35604 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35605 -};
35606 +} __no_const;
35607
35608 struct mwifiex_adapter {
35609 u8 iface_type;
35610 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35611 index dfcd02a..a42a59d 100644
35612 --- a/drivers/net/wireless/rndis_wlan.c
35613 +++ b/drivers/net/wireless/rndis_wlan.c
35614 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35615
35616 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35617
35618 - if (rts_threshold < 0 || rts_threshold > 2347)
35619 + if (rts_threshold > 2347)
35620 rts_threshold = 2347;
35621
35622 tmp = cpu_to_le32(rts_threshold);
35623 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35624 index 8f75402..eed109d 100644
35625 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35626 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35627 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35628 * for hardware which doesn't support hardware
35629 * sequence counting.
35630 */
35631 - atomic_t seqno;
35632 + atomic_unchecked_t seqno;
35633 };
35634
35635 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35636 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35637 index 2fd8301..9767e8c 100644
35638 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35639 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35640 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35641 * sequence counter given by mac80211.
35642 */
35643 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35644 - seqno = atomic_add_return(0x10, &intf->seqno);
35645 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35646 else
35647 - seqno = atomic_read(&intf->seqno);
35648 + seqno = atomic_read_unchecked(&intf->seqno);
35649
35650 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35651 hdr->seq_ctrl |= cpu_to_le16(seqno);
35652 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35653 index 9d8f581..0f6589e 100644
35654 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35655 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35656 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35657 void (*reset)(struct wl1251 *wl);
35658 void (*enable_irq)(struct wl1251 *wl);
35659 void (*disable_irq)(struct wl1251 *wl);
35660 -};
35661 +} __no_const;
35662
35663 struct wl1251 {
35664 struct ieee80211_hw *hw;
35665 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35666 index 0b3f0b5..62f68bd 100644
35667 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35668 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35669 @@ -61,7 +61,7 @@ struct wlcore_ops {
35670 struct wl12xx_vif *wlvif);
35671 s8 (*get_pg_ver)(struct wl1271 *wl);
35672 void (*get_mac)(struct wl1271 *wl);
35673 -};
35674 +} __no_const;
35675
35676 enum wlcore_partitions {
35677 PART_DOWN,
35678 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35679 index f34b5b2..b5abb9f 100644
35680 --- a/drivers/oprofile/buffer_sync.c
35681 +++ b/drivers/oprofile/buffer_sync.c
35682 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35683 if (cookie == NO_COOKIE)
35684 offset = pc;
35685 if (cookie == INVALID_COOKIE) {
35686 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35687 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35688 offset = pc;
35689 }
35690 if (cookie != last_cookie) {
35691 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35692 /* add userspace sample */
35693
35694 if (!mm) {
35695 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35696 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35697 return 0;
35698 }
35699
35700 cookie = lookup_dcookie(mm, s->eip, &offset);
35701
35702 if (cookie == INVALID_COOKIE) {
35703 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35704 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35705 return 0;
35706 }
35707
35708 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35709 /* ignore backtraces if failed to add a sample */
35710 if (state == sb_bt_start) {
35711 state = sb_bt_ignore;
35712 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35713 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35714 }
35715 }
35716 release_mm(mm);
35717 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35718 index c0cc4e7..44d4e54 100644
35719 --- a/drivers/oprofile/event_buffer.c
35720 +++ b/drivers/oprofile/event_buffer.c
35721 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35722 }
35723
35724 if (buffer_pos == buffer_size) {
35725 - atomic_inc(&oprofile_stats.event_lost_overflow);
35726 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35727 return;
35728 }
35729
35730 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35731 index ed2c3ec..deda85a 100644
35732 --- a/drivers/oprofile/oprof.c
35733 +++ b/drivers/oprofile/oprof.c
35734 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35735 if (oprofile_ops.switch_events())
35736 return;
35737
35738 - atomic_inc(&oprofile_stats.multiplex_counter);
35739 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35740 start_switch_worker();
35741 }
35742
35743 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35744 index 917d28e..d62d981 100644
35745 --- a/drivers/oprofile/oprofile_stats.c
35746 +++ b/drivers/oprofile/oprofile_stats.c
35747 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35748 cpu_buf->sample_invalid_eip = 0;
35749 }
35750
35751 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35752 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35753 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35754 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35755 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35756 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35757 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35758 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35759 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35760 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35761 }
35762
35763
35764 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35765 index 38b6fc0..b5cbfce 100644
35766 --- a/drivers/oprofile/oprofile_stats.h
35767 +++ b/drivers/oprofile/oprofile_stats.h
35768 @@ -13,11 +13,11 @@
35769 #include <linux/atomic.h>
35770
35771 struct oprofile_stat_struct {
35772 - atomic_t sample_lost_no_mm;
35773 - atomic_t sample_lost_no_mapping;
35774 - atomic_t bt_lost_no_mapping;
35775 - atomic_t event_lost_overflow;
35776 - atomic_t multiplex_counter;
35777 + atomic_unchecked_t sample_lost_no_mm;
35778 + atomic_unchecked_t sample_lost_no_mapping;
35779 + atomic_unchecked_t bt_lost_no_mapping;
35780 + atomic_unchecked_t event_lost_overflow;
35781 + atomic_unchecked_t multiplex_counter;
35782 };
35783
35784 extern struct oprofile_stat_struct oprofile_stats;
35785 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35786 index 849357c..b83c1e0 100644
35787 --- a/drivers/oprofile/oprofilefs.c
35788 +++ b/drivers/oprofile/oprofilefs.c
35789 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35790
35791
35792 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35793 - char const *name, atomic_t *val)
35794 + char const *name, atomic_unchecked_t *val)
35795 {
35796 return __oprofilefs_create_file(sb, root, name,
35797 &atomic_ro_fops, 0444, val);
35798 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35799 index 3f56bc0..707d642 100644
35800 --- a/drivers/parport/procfs.c
35801 +++ b/drivers/parport/procfs.c
35802 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35803
35804 *ppos += len;
35805
35806 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35807 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35808 }
35809
35810 #ifdef CONFIG_PARPORT_1284
35811 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35812
35813 *ppos += len;
35814
35815 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35816 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35817 }
35818 #endif /* IEEE1284.3 support. */
35819
35820 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35821 index 9fff878..ad0ad53 100644
35822 --- a/drivers/pci/hotplug/cpci_hotplug.h
35823 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35824 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35825 int (*hardware_test) (struct slot* slot, u32 value);
35826 u8 (*get_power) (struct slot* slot);
35827 int (*set_power) (struct slot* slot, int value);
35828 -};
35829 +} __no_const;
35830
35831 struct cpci_hp_controller {
35832 unsigned int irq;
35833 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35834 index 76ba8a1..20ca857 100644
35835 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35836 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35837 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35838
35839 void compaq_nvram_init (void __iomem *rom_start)
35840 {
35841 +
35842 +#ifndef CONFIG_PAX_KERNEXEC
35843 if (rom_start) {
35844 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35845 }
35846 +#endif
35847 +
35848 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35849
35850 /* initialize our int15 lock */
35851 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35852 index b500840..d7159d3 100644
35853 --- a/drivers/pci/pcie/aspm.c
35854 +++ b/drivers/pci/pcie/aspm.c
35855 @@ -27,9 +27,9 @@
35856 #define MODULE_PARAM_PREFIX "pcie_aspm."
35857
35858 /* Note: those are not register definitions */
35859 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35860 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35861 -#define ASPM_STATE_L1 (4) /* L1 state */
35862 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35863 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35864 +#define ASPM_STATE_L1 (4U) /* L1 state */
35865 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35866 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35867
35868 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35869 index 658ac97..05e1b90 100644
35870 --- a/drivers/pci/probe.c
35871 +++ b/drivers/pci/probe.c
35872 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35873 u16 orig_cmd;
35874 struct pci_bus_region region;
35875
35876 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35877 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35878
35879 if (!dev->mmio_always_on) {
35880 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35881 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35882 index 27911b5..5b6db88 100644
35883 --- a/drivers/pci/proc.c
35884 +++ b/drivers/pci/proc.c
35885 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35886 static int __init pci_proc_init(void)
35887 {
35888 struct pci_dev *dev = NULL;
35889 +
35890 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35891 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35892 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35893 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35894 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35895 +#endif
35896 +#else
35897 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35898 +#endif
35899 proc_create("devices", 0, proc_bus_pci_dir,
35900 &proc_bus_pci_dev_operations);
35901 proc_initialized = 1;
35902 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35903 index 8b5610d..a4c22bb 100644
35904 --- a/drivers/platform/x86/thinkpad_acpi.c
35905 +++ b/drivers/platform/x86/thinkpad_acpi.c
35906 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35907 return 0;
35908 }
35909
35910 -void static hotkey_mask_warn_incomplete_mask(void)
35911 +static void hotkey_mask_warn_incomplete_mask(void)
35912 {
35913 /* log only what the user can fix... */
35914 const u32 wantedmask = hotkey_driver_mask &
35915 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35916 }
35917 }
35918
35919 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35920 - struct tp_nvram_state *newn,
35921 - const u32 event_mask)
35922 -{
35923 -
35924 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35925 do { \
35926 if ((event_mask & (1 << __scancode)) && \
35927 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35928 tpacpi_hotkey_send_key(__scancode); \
35929 } while (0)
35930
35931 - void issue_volchange(const unsigned int oldvol,
35932 - const unsigned int newvol)
35933 - {
35934 - unsigned int i = oldvol;
35935 +static void issue_volchange(const unsigned int oldvol,
35936 + const unsigned int newvol,
35937 + const u32 event_mask)
35938 +{
35939 + unsigned int i = oldvol;
35940
35941 - while (i > newvol) {
35942 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35943 - i--;
35944 - }
35945 - while (i < newvol) {
35946 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35947 - i++;
35948 - }
35949 + while (i > newvol) {
35950 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35951 + i--;
35952 }
35953 + while (i < newvol) {
35954 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35955 + i++;
35956 + }
35957 +}
35958
35959 - void issue_brightnesschange(const unsigned int oldbrt,
35960 - const unsigned int newbrt)
35961 - {
35962 - unsigned int i = oldbrt;
35963 +static void issue_brightnesschange(const unsigned int oldbrt,
35964 + const unsigned int newbrt,
35965 + const u32 event_mask)
35966 +{
35967 + unsigned int i = oldbrt;
35968
35969 - while (i > newbrt) {
35970 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35971 - i--;
35972 - }
35973 - while (i < newbrt) {
35974 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35975 - i++;
35976 - }
35977 + while (i > newbrt) {
35978 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35979 + i--;
35980 + }
35981 + while (i < newbrt) {
35982 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35983 + i++;
35984 }
35985 +}
35986
35987 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35988 + struct tp_nvram_state *newn,
35989 + const u32 event_mask)
35990 +{
35991 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35992 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35993 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35994 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35995 oldn->volume_level != newn->volume_level) {
35996 /* recently muted, or repeated mute keypress, or
35997 * multiple presses ending in mute */
35998 - issue_volchange(oldn->volume_level, newn->volume_level);
35999 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36000 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36001 }
36002 } else {
36003 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36004 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36005 }
36006 if (oldn->volume_level != newn->volume_level) {
36007 - issue_volchange(oldn->volume_level, newn->volume_level);
36008 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36009 } else if (oldn->volume_toggle != newn->volume_toggle) {
36010 /* repeated vol up/down keypress at end of scale ? */
36011 if (newn->volume_level == 0)
36012 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36013 /* handle brightness */
36014 if (oldn->brightness_level != newn->brightness_level) {
36015 issue_brightnesschange(oldn->brightness_level,
36016 - newn->brightness_level);
36017 + newn->brightness_level,
36018 + event_mask);
36019 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36020 /* repeated key presses that didn't change state */
36021 if (newn->brightness_level == 0)
36022 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36023 && !tp_features.bright_unkfw)
36024 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36025 }
36026 +}
36027
36028 #undef TPACPI_COMPARE_KEY
36029 #undef TPACPI_MAY_SEND_KEY
36030 -}
36031
36032 /*
36033 * Polling driver
36034 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36035 index 769d265..a3a05ca 100644
36036 --- a/drivers/pnp/pnpbios/bioscalls.c
36037 +++ b/drivers/pnp/pnpbios/bioscalls.c
36038 @@ -58,7 +58,7 @@ do { \
36039 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36040 } while(0)
36041
36042 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36043 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36044 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36045
36046 /*
36047 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36048
36049 cpu = get_cpu();
36050 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36051 +
36052 + pax_open_kernel();
36053 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36054 + pax_close_kernel();
36055
36056 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36057 spin_lock_irqsave(&pnp_bios_lock, flags);
36058 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36059 :"memory");
36060 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36061
36062 + pax_open_kernel();
36063 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36064 + pax_close_kernel();
36065 +
36066 put_cpu();
36067
36068 /* If we get here and this is set then the PnP BIOS faulted on us. */
36069 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36070 return status;
36071 }
36072
36073 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36074 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36075 {
36076 int i;
36077
36078 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36079 pnp_bios_callpoint.offset = header->fields.pm16offset;
36080 pnp_bios_callpoint.segment = PNP_CS16;
36081
36082 + pax_open_kernel();
36083 +
36084 for_each_possible_cpu(i) {
36085 struct desc_struct *gdt = get_cpu_gdt_table(i);
36086 if (!gdt)
36087 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36088 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36089 (unsigned long)__va(header->fields.pm16dseg));
36090 }
36091 +
36092 + pax_close_kernel();
36093 }
36094 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36095 index b0ecacb..7c9da2e 100644
36096 --- a/drivers/pnp/resource.c
36097 +++ b/drivers/pnp/resource.c
36098 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36099 return 1;
36100
36101 /* check if the resource is valid */
36102 - if (*irq < 0 || *irq > 15)
36103 + if (*irq > 15)
36104 return 0;
36105
36106 /* check if the resource is reserved */
36107 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36108 return 1;
36109
36110 /* check if the resource is valid */
36111 - if (*dma < 0 || *dma == 4 || *dma > 7)
36112 + if (*dma == 4 || *dma > 7)
36113 return 0;
36114
36115 /* check if the resource is reserved */
36116 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36117 index f5d6d37..739f6a9 100644
36118 --- a/drivers/power/bq27x00_battery.c
36119 +++ b/drivers/power/bq27x00_battery.c
36120 @@ -72,7 +72,7 @@
36121 struct bq27x00_device_info;
36122 struct bq27x00_access_methods {
36123 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36124 -};
36125 +} __no_const;
36126
36127 enum bq27x00_chip { BQ27000, BQ27500 };
36128
36129 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36130 index 8d53174..04c65de 100644
36131 --- a/drivers/regulator/max8660.c
36132 +++ b/drivers/regulator/max8660.c
36133 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36134 max8660->shadow_regs[MAX8660_OVER1] = 5;
36135 } else {
36136 /* Otherwise devices can be toggled via software */
36137 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36138 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36139 + pax_open_kernel();
36140 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36141 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36142 + pax_close_kernel();
36143 }
36144
36145 /*
36146 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36147 index 970a233..ee1f241 100644
36148 --- a/drivers/regulator/mc13892-regulator.c
36149 +++ b/drivers/regulator/mc13892-regulator.c
36150 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36151 }
36152 mc13xxx_unlock(mc13892);
36153
36154 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36155 + pax_open_kernel();
36156 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36157 = mc13892_vcam_set_mode;
36158 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36159 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36160 = mc13892_vcam_get_mode;
36161 + pax_close_kernel();
36162
36163 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36164 ARRAY_SIZE(mc13892_regulators));
36165 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36166 index cace6d3..f623fda 100644
36167 --- a/drivers/rtc/rtc-dev.c
36168 +++ b/drivers/rtc/rtc-dev.c
36169 @@ -14,6 +14,7 @@
36170 #include <linux/module.h>
36171 #include <linux/rtc.h>
36172 #include <linux/sched.h>
36173 +#include <linux/grsecurity.h>
36174 #include "rtc-core.h"
36175
36176 static dev_t rtc_devt;
36177 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36178 if (copy_from_user(&tm, uarg, sizeof(tm)))
36179 return -EFAULT;
36180
36181 + gr_log_timechange();
36182 +
36183 return rtc_set_time(rtc, &tm);
36184
36185 case RTC_PIE_ON:
36186 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36187 index 3fcf627..f334910 100644
36188 --- a/drivers/scsi/aacraid/aacraid.h
36189 +++ b/drivers/scsi/aacraid/aacraid.h
36190 @@ -492,7 +492,7 @@ struct adapter_ops
36191 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36192 /* Administrative operations */
36193 int (*adapter_comm)(struct aac_dev * dev, int comm);
36194 -};
36195 +} __no_const;
36196
36197 /*
36198 * Define which interrupt handler needs to be installed
36199 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36200 index 0d279c44..3d25a97 100644
36201 --- a/drivers/scsi/aacraid/linit.c
36202 +++ b/drivers/scsi/aacraid/linit.c
36203 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36204 #elif defined(__devinitconst)
36205 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36206 #else
36207 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36208 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36209 #endif
36210 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36211 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36212 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36213 index ff80552..1c4120c 100644
36214 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36215 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36216 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36217 .lldd_ata_set_dmamode = asd_set_dmamode,
36218 };
36219
36220 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36221 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36222 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36223 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36224 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36225 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36226 index 4ad7e36..d004679 100644
36227 --- a/drivers/scsi/bfa/bfa.h
36228 +++ b/drivers/scsi/bfa/bfa.h
36229 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36230 u32 *end);
36231 int cpe_vec_q0;
36232 int rme_vec_q0;
36233 -};
36234 +} __no_const;
36235 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36236
36237 struct bfa_faa_cbfn_s {
36238 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36239 index f0f80e2..8ec946b 100644
36240 --- a/drivers/scsi/bfa/bfa_fcpim.c
36241 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36242 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36243
36244 bfa_iotag_attach(fcp);
36245
36246 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36247 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36248 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36249 (fcp->num_itns * sizeof(struct bfa_itn_s));
36250 memset(fcp->itn_arr, 0,
36251 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36252 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36253 {
36254 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36255 - struct bfa_itn_s *itn;
36256 + bfa_itn_s_no_const *itn;
36257
36258 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36259 itn->isr = isr;
36260 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36261 index 36f26da..38a34a8 100644
36262 --- a/drivers/scsi/bfa/bfa_fcpim.h
36263 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36264 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36265 struct bfa_itn_s {
36266 bfa_isr_func_t isr;
36267 };
36268 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36269
36270 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36271 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36272 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36273 struct list_head iotag_tio_free_q; /* free IO resources */
36274 struct list_head iotag_unused_q; /* unused IO resources*/
36275 struct bfa_iotag_s *iotag_arr;
36276 - struct bfa_itn_s *itn_arr;
36277 + bfa_itn_s_no_const *itn_arr;
36278 int num_ioim_reqs;
36279 int num_fwtio_reqs;
36280 int num_itns;
36281 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36282 index 1a99d4b..e85d64b 100644
36283 --- a/drivers/scsi/bfa/bfa_ioc.h
36284 +++ b/drivers/scsi/bfa/bfa_ioc.h
36285 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36286 bfa_ioc_disable_cbfn_t disable_cbfn;
36287 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36288 bfa_ioc_reset_cbfn_t reset_cbfn;
36289 -};
36290 +} __no_const;
36291
36292 /*
36293 * IOC event notification mechanism.
36294 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36295 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36296 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36297 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36298 -};
36299 +} __no_const;
36300
36301 /*
36302 * Queue element to wait for room in request queue. FIFO order is
36303 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36304 index b48c24f..dac0fbc 100644
36305 --- a/drivers/scsi/hosts.c
36306 +++ b/drivers/scsi/hosts.c
36307 @@ -42,7 +42,7 @@
36308 #include "scsi_logging.h"
36309
36310
36311 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36312 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36313
36314
36315 static void scsi_host_cls_release(struct device *dev)
36316 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36317 * subtract one because we increment first then return, but we need to
36318 * know what the next host number was before increment
36319 */
36320 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36321 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36322 shost->dma_channel = 0xff;
36323
36324 /* These three are default values which can be overridden */
36325 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36326 index 796482b..d08435c 100644
36327 --- a/drivers/scsi/hpsa.c
36328 +++ b/drivers/scsi/hpsa.c
36329 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36330 unsigned long flags;
36331
36332 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36333 - return h->access.command_completed(h, q);
36334 + return h->access->command_completed(h, q);
36335
36336 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36337 a = rq->head[rq->current_entry];
36338 @@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36339 while (!list_empty(&h->reqQ)) {
36340 c = list_entry(h->reqQ.next, struct CommandList, list);
36341 /* can't do anything if fifo is full */
36342 - if ((h->access.fifo_full(h))) {
36343 + if ((h->access->fifo_full(h))) {
36344 dev_warn(&h->pdev->dev, "fifo full\n");
36345 break;
36346 }
36347 @@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36348
36349 /* Tell the controller execute command */
36350 spin_unlock_irqrestore(&h->lock, flags);
36351 - h->access.submit_command(h, c);
36352 + h->access->submit_command(h, c);
36353 spin_lock_irqsave(&h->lock, flags);
36354 }
36355 spin_unlock_irqrestore(&h->lock, flags);
36356 @@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36357
36358 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36359 {
36360 - return h->access.command_completed(h, q);
36361 + return h->access->command_completed(h, q);
36362 }
36363
36364 static inline bool interrupt_pending(struct ctlr_info *h)
36365 {
36366 - return h->access.intr_pending(h);
36367 + return h->access->intr_pending(h);
36368 }
36369
36370 static inline long interrupt_not_for_us(struct ctlr_info *h)
36371 {
36372 - return (h->access.intr_pending(h) == 0) ||
36373 + return (h->access->intr_pending(h) == 0) ||
36374 (h->interrupts_enabled == 0);
36375 }
36376
36377 @@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36378 if (prod_index < 0)
36379 return -ENODEV;
36380 h->product_name = products[prod_index].product_name;
36381 - h->access = *(products[prod_index].access);
36382 + h->access = products[prod_index].access;
36383
36384 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36385 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36386 @@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36387
36388 assert_spin_locked(&lockup_detector_lock);
36389 remove_ctlr_from_lockup_detector_list(h);
36390 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36391 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36392 spin_lock_irqsave(&h->lock, flags);
36393 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36394 spin_unlock_irqrestore(&h->lock, flags);
36395 @@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36396 }
36397
36398 /* make sure the board interrupts are off */
36399 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36400 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36401
36402 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36403 goto clean2;
36404 @@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36405 * fake ones to scoop up any residual completions.
36406 */
36407 spin_lock_irqsave(&h->lock, flags);
36408 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36409 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36410 spin_unlock_irqrestore(&h->lock, flags);
36411 free_irqs(h);
36412 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36413 @@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36414 dev_info(&h->pdev->dev, "Board READY.\n");
36415 dev_info(&h->pdev->dev,
36416 "Waiting for stale completions to drain.\n");
36417 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36418 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36419 msleep(10000);
36420 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36421 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36422
36423 rc = controller_reset_failed(h->cfgtable);
36424 if (rc)
36425 @@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36426 }
36427
36428 /* Turn the interrupts on so we can service requests */
36429 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36430 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36431
36432 hpsa_hba_inquiry(h);
36433 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36434 @@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36435 * To write all data in the battery backed cache to disks
36436 */
36437 hpsa_flush_cache(h);
36438 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36439 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36440 hpsa_free_irqs_and_disable_msix(h);
36441 }
36442
36443 @@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36444 return;
36445 }
36446 /* Change the access methods to the performant access methods */
36447 - h->access = SA5_performant_access;
36448 + h->access = &SA5_performant_access;
36449 h->transMethod = CFGTBL_Trans_Performant;
36450 }
36451
36452 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36453 index 9816479..c5d4e97 100644
36454 --- a/drivers/scsi/hpsa.h
36455 +++ b/drivers/scsi/hpsa.h
36456 @@ -79,7 +79,7 @@ struct ctlr_info {
36457 unsigned int msix_vector;
36458 unsigned int msi_vector;
36459 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36460 - struct access_method access;
36461 + struct access_method *access;
36462
36463 /* queue and queue Info */
36464 struct list_head reqQ;
36465 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36466 index f2df059..a3a9930 100644
36467 --- a/drivers/scsi/ips.h
36468 +++ b/drivers/scsi/ips.h
36469 @@ -1027,7 +1027,7 @@ typedef struct {
36470 int (*intr)(struct ips_ha *);
36471 void (*enableint)(struct ips_ha *);
36472 uint32_t (*statupd)(struct ips_ha *);
36473 -} ips_hw_func_t;
36474 +} __no_const ips_hw_func_t;
36475
36476 typedef struct ips_ha {
36477 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36478 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36479 index aceffad..c35c08d 100644
36480 --- a/drivers/scsi/libfc/fc_exch.c
36481 +++ b/drivers/scsi/libfc/fc_exch.c
36482 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36483 * all together if not used XXX
36484 */
36485 struct {
36486 - atomic_t no_free_exch;
36487 - atomic_t no_free_exch_xid;
36488 - atomic_t xid_not_found;
36489 - atomic_t xid_busy;
36490 - atomic_t seq_not_found;
36491 - atomic_t non_bls_resp;
36492 + atomic_unchecked_t no_free_exch;
36493 + atomic_unchecked_t no_free_exch_xid;
36494 + atomic_unchecked_t xid_not_found;
36495 + atomic_unchecked_t xid_busy;
36496 + atomic_unchecked_t seq_not_found;
36497 + atomic_unchecked_t non_bls_resp;
36498 } stats;
36499 };
36500
36501 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36502 /* allocate memory for exchange */
36503 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36504 if (!ep) {
36505 - atomic_inc(&mp->stats.no_free_exch);
36506 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36507 goto out;
36508 }
36509 memset(ep, 0, sizeof(*ep));
36510 @@ -780,7 +780,7 @@ out:
36511 return ep;
36512 err:
36513 spin_unlock_bh(&pool->lock);
36514 - atomic_inc(&mp->stats.no_free_exch_xid);
36515 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36516 mempool_free(ep, mp->ep_pool);
36517 return NULL;
36518 }
36519 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36520 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36521 ep = fc_exch_find(mp, xid);
36522 if (!ep) {
36523 - atomic_inc(&mp->stats.xid_not_found);
36524 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36525 reject = FC_RJT_OX_ID;
36526 goto out;
36527 }
36528 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36529 ep = fc_exch_find(mp, xid);
36530 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36531 if (ep) {
36532 - atomic_inc(&mp->stats.xid_busy);
36533 + atomic_inc_unchecked(&mp->stats.xid_busy);
36534 reject = FC_RJT_RX_ID;
36535 goto rel;
36536 }
36537 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36538 }
36539 xid = ep->xid; /* get our XID */
36540 } else if (!ep) {
36541 - atomic_inc(&mp->stats.xid_not_found);
36542 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36543 reject = FC_RJT_RX_ID; /* XID not found */
36544 goto out;
36545 }
36546 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36547 } else {
36548 sp = &ep->seq;
36549 if (sp->id != fh->fh_seq_id) {
36550 - atomic_inc(&mp->stats.seq_not_found);
36551 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36552 if (f_ctl & FC_FC_END_SEQ) {
36553 /*
36554 * Update sequence_id based on incoming last
36555 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36556
36557 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36558 if (!ep) {
36559 - atomic_inc(&mp->stats.xid_not_found);
36560 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36561 goto out;
36562 }
36563 if (ep->esb_stat & ESB_ST_COMPLETE) {
36564 - atomic_inc(&mp->stats.xid_not_found);
36565 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36566 goto rel;
36567 }
36568 if (ep->rxid == FC_XID_UNKNOWN)
36569 ep->rxid = ntohs(fh->fh_rx_id);
36570 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36571 - atomic_inc(&mp->stats.xid_not_found);
36572 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36573 goto rel;
36574 }
36575 if (ep->did != ntoh24(fh->fh_s_id) &&
36576 ep->did != FC_FID_FLOGI) {
36577 - atomic_inc(&mp->stats.xid_not_found);
36578 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36579 goto rel;
36580 }
36581 sof = fr_sof(fp);
36582 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36583 sp->ssb_stat |= SSB_ST_RESP;
36584 sp->id = fh->fh_seq_id;
36585 } else if (sp->id != fh->fh_seq_id) {
36586 - atomic_inc(&mp->stats.seq_not_found);
36587 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36588 goto rel;
36589 }
36590
36591 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36592 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36593
36594 if (!sp)
36595 - atomic_inc(&mp->stats.xid_not_found);
36596 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36597 else
36598 - atomic_inc(&mp->stats.non_bls_resp);
36599 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36600
36601 fc_frame_free(fp);
36602 }
36603 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36604 index d109cc3..09f4e7d 100644
36605 --- a/drivers/scsi/libsas/sas_ata.c
36606 +++ b/drivers/scsi/libsas/sas_ata.c
36607 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36608 .postreset = ata_std_postreset,
36609 .error_handler = ata_std_error_handler,
36610 .post_internal_cmd = sas_ata_post_internal,
36611 - .qc_defer = ata_std_qc_defer,
36612 + .qc_defer = ata_std_qc_defer,
36613 .qc_prep = ata_noop_qc_prep,
36614 .qc_issue = sas_ata_qc_issue,
36615 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36616 diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36617 index fe5d396..e93d526 100644
36618 --- a/drivers/scsi/lpfc/Makefile
36619 +++ b/drivers/scsi/lpfc/Makefile
36620 @@ -22,7 +22,7 @@
36621 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36622 ccflags-$(GCOV) += -O0
36623
36624 -ccflags-y += -Werror
36625 +#ccflags-y += -Werror
36626
36627 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36628
36629 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36630 index e5da6da..c888d48 100644
36631 --- a/drivers/scsi/lpfc/lpfc.h
36632 +++ b/drivers/scsi/lpfc/lpfc.h
36633 @@ -416,7 +416,7 @@ struct lpfc_vport {
36634 struct dentry *debug_nodelist;
36635 struct dentry *vport_debugfs_root;
36636 struct lpfc_debugfs_trc *disc_trc;
36637 - atomic_t disc_trc_cnt;
36638 + atomic_unchecked_t disc_trc_cnt;
36639 #endif
36640 uint8_t stat_data_enabled;
36641 uint8_t stat_data_blocked;
36642 @@ -830,8 +830,8 @@ struct lpfc_hba {
36643 struct timer_list fabric_block_timer;
36644 unsigned long bit_flags;
36645 #define FABRIC_COMANDS_BLOCKED 0
36646 - atomic_t num_rsrc_err;
36647 - atomic_t num_cmd_success;
36648 + atomic_unchecked_t num_rsrc_err;
36649 + atomic_unchecked_t num_cmd_success;
36650 unsigned long last_rsrc_error_time;
36651 unsigned long last_ramp_down_time;
36652 unsigned long last_ramp_up_time;
36653 @@ -867,7 +867,7 @@ struct lpfc_hba {
36654
36655 struct dentry *debug_slow_ring_trc;
36656 struct lpfc_debugfs_trc *slow_ring_trc;
36657 - atomic_t slow_ring_trc_cnt;
36658 + atomic_unchecked_t slow_ring_trc_cnt;
36659 /* iDiag debugfs sub-directory */
36660 struct dentry *idiag_root;
36661 struct dentry *idiag_pci_cfg;
36662 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36663 index 3217d63..c417981 100644
36664 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36665 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36666 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36667
36668 #include <linux/debugfs.h>
36669
36670 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36671 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36672 static unsigned long lpfc_debugfs_start_time = 0L;
36673
36674 /* iDiag */
36675 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36676 lpfc_debugfs_enable = 0;
36677
36678 len = 0;
36679 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36680 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36681 (lpfc_debugfs_max_disc_trc - 1);
36682 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36683 dtp = vport->disc_trc + i;
36684 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36685 lpfc_debugfs_enable = 0;
36686
36687 len = 0;
36688 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36689 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36690 (lpfc_debugfs_max_slow_ring_trc - 1);
36691 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36692 dtp = phba->slow_ring_trc + i;
36693 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36694 !vport || !vport->disc_trc)
36695 return;
36696
36697 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36698 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36699 (lpfc_debugfs_max_disc_trc - 1);
36700 dtp = vport->disc_trc + index;
36701 dtp->fmt = fmt;
36702 dtp->data1 = data1;
36703 dtp->data2 = data2;
36704 dtp->data3 = data3;
36705 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36706 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36707 dtp->jif = jiffies;
36708 #endif
36709 return;
36710 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36711 !phba || !phba->slow_ring_trc)
36712 return;
36713
36714 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36715 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36716 (lpfc_debugfs_max_slow_ring_trc - 1);
36717 dtp = phba->slow_ring_trc + index;
36718 dtp->fmt = fmt;
36719 dtp->data1 = data1;
36720 dtp->data2 = data2;
36721 dtp->data3 = data3;
36722 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36723 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36724 dtp->jif = jiffies;
36725 #endif
36726 return;
36727 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36728 "slow_ring buffer\n");
36729 goto debug_failed;
36730 }
36731 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36732 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36733 memset(phba->slow_ring_trc, 0,
36734 (sizeof(struct lpfc_debugfs_trc) *
36735 lpfc_debugfs_max_slow_ring_trc));
36736 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36737 "buffer\n");
36738 goto debug_failed;
36739 }
36740 - atomic_set(&vport->disc_trc_cnt, 0);
36741 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36742
36743 snprintf(name, sizeof(name), "discovery_trace");
36744 vport->debug_disc_trc =
36745 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36746 index 411ed48..967f553 100644
36747 --- a/drivers/scsi/lpfc/lpfc_init.c
36748 +++ b/drivers/scsi/lpfc/lpfc_init.c
36749 @@ -10341,8 +10341,10 @@ lpfc_init(void)
36750 "misc_register returned with status %d", error);
36751
36752 if (lpfc_enable_npiv) {
36753 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36754 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36755 + pax_open_kernel();
36756 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36757 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36758 + pax_close_kernel();
36759 }
36760 lpfc_transport_template =
36761 fc_attach_transport(&lpfc_transport_functions);
36762 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36763 index 66e0906..1620281 100644
36764 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36765 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36766 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36767 uint32_t evt_posted;
36768
36769 spin_lock_irqsave(&phba->hbalock, flags);
36770 - atomic_inc(&phba->num_rsrc_err);
36771 + atomic_inc_unchecked(&phba->num_rsrc_err);
36772 phba->last_rsrc_error_time = jiffies;
36773
36774 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36775 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36776 unsigned long flags;
36777 struct lpfc_hba *phba = vport->phba;
36778 uint32_t evt_posted;
36779 - atomic_inc(&phba->num_cmd_success);
36780 + atomic_inc_unchecked(&phba->num_cmd_success);
36781
36782 if (vport->cfg_lun_queue_depth <= queue_depth)
36783 return;
36784 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36785 unsigned long num_rsrc_err, num_cmd_success;
36786 int i;
36787
36788 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36789 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36790 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36791 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36792
36793 /*
36794 * The error and success command counters are global per
36795 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36796 }
36797 }
36798 lpfc_destroy_vport_work_array(phba, vports);
36799 - atomic_set(&phba->num_rsrc_err, 0);
36800 - atomic_set(&phba->num_cmd_success, 0);
36801 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36802 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36803 }
36804
36805 /**
36806 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36807 }
36808 }
36809 lpfc_destroy_vport_work_array(phba, vports);
36810 - atomic_set(&phba->num_rsrc_err, 0);
36811 - atomic_set(&phba->num_cmd_success, 0);
36812 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36813 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36814 }
36815
36816 /**
36817 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36818 index ea8a0b4..812a124 100644
36819 --- a/drivers/scsi/pmcraid.c
36820 +++ b/drivers/scsi/pmcraid.c
36821 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36822 res->scsi_dev = scsi_dev;
36823 scsi_dev->hostdata = res;
36824 res->change_detected = 0;
36825 - atomic_set(&res->read_failures, 0);
36826 - atomic_set(&res->write_failures, 0);
36827 + atomic_set_unchecked(&res->read_failures, 0);
36828 + atomic_set_unchecked(&res->write_failures, 0);
36829 rc = 0;
36830 }
36831 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36832 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36833
36834 /* If this was a SCSI read/write command keep count of errors */
36835 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36836 - atomic_inc(&res->read_failures);
36837 + atomic_inc_unchecked(&res->read_failures);
36838 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36839 - atomic_inc(&res->write_failures);
36840 + atomic_inc_unchecked(&res->write_failures);
36841
36842 if (!RES_IS_GSCSI(res->cfg_entry) &&
36843 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36844 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36845 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36846 * hrrq_id assigned here in queuecommand
36847 */
36848 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36849 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36850 pinstance->num_hrrq;
36851 cmd->cmd_done = pmcraid_io_done;
36852
36853 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36854 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36855 * hrrq_id assigned here in queuecommand
36856 */
36857 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36858 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36859 pinstance->num_hrrq;
36860
36861 if (request_size) {
36862 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36863
36864 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36865 /* add resources only after host is added into system */
36866 - if (!atomic_read(&pinstance->expose_resources))
36867 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36868 return;
36869
36870 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36871 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36872 init_waitqueue_head(&pinstance->reset_wait_q);
36873
36874 atomic_set(&pinstance->outstanding_cmds, 0);
36875 - atomic_set(&pinstance->last_message_id, 0);
36876 - atomic_set(&pinstance->expose_resources, 0);
36877 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36878 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36879
36880 INIT_LIST_HEAD(&pinstance->free_res_q);
36881 INIT_LIST_HEAD(&pinstance->used_res_q);
36882 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36883 /* Schedule worker thread to handle CCN and take care of adding and
36884 * removing devices to OS
36885 */
36886 - atomic_set(&pinstance->expose_resources, 1);
36887 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36888 schedule_work(&pinstance->worker_q);
36889 return rc;
36890
36891 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36892 index e1d150f..6c6df44 100644
36893 --- a/drivers/scsi/pmcraid.h
36894 +++ b/drivers/scsi/pmcraid.h
36895 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36896 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36897
36898 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36899 - atomic_t last_message_id;
36900 + atomic_unchecked_t last_message_id;
36901
36902 /* configuration table */
36903 struct pmcraid_config_table *cfg_table;
36904 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36905 atomic_t outstanding_cmds;
36906
36907 /* should add/delete resources to mid-layer now ?*/
36908 - atomic_t expose_resources;
36909 + atomic_unchecked_t expose_resources;
36910
36911
36912
36913 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36914 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36915 };
36916 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36917 - atomic_t read_failures; /* count of failed READ commands */
36918 - atomic_t write_failures; /* count of failed WRITE commands */
36919 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36920 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36921
36922 /* To indicate add/delete/modify during CCN */
36923 u8 change_detected;
36924 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36925 index 5ab9530..2dd80f7 100644
36926 --- a/drivers/scsi/qla2xxx/qla_attr.c
36927 +++ b/drivers/scsi/qla2xxx/qla_attr.c
36928 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36929 return 0;
36930 }
36931
36932 -struct fc_function_template qla2xxx_transport_functions = {
36933 +fc_function_template_no_const qla2xxx_transport_functions = {
36934
36935 .show_host_node_name = 1,
36936 .show_host_port_name = 1,
36937 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36938 .bsg_timeout = qla24xx_bsg_timeout,
36939 };
36940
36941 -struct fc_function_template qla2xxx_transport_vport_functions = {
36942 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
36943
36944 .show_host_node_name = 1,
36945 .show_host_port_name = 1,
36946 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36947 index 39007f5..7fafc64 100644
36948 --- a/drivers/scsi/qla2xxx/qla_def.h
36949 +++ b/drivers/scsi/qla2xxx/qla_def.h
36950 @@ -2284,7 +2284,7 @@ struct isp_operations {
36951 int (*start_scsi) (srb_t *);
36952 int (*abort_isp) (struct scsi_qla_host *);
36953 int (*iospace_config)(struct qla_hw_data*);
36954 -};
36955 +} __no_const;
36956
36957 /* MSI-X Support *************************************************************/
36958
36959 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36960 index 9eacd2d..d79629c 100644
36961 --- a/drivers/scsi/qla2xxx/qla_gbl.h
36962 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
36963 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36964 struct device_attribute;
36965 extern struct device_attribute *qla2x00_host_attrs[];
36966 struct fc_function_template;
36967 -extern struct fc_function_template qla2xxx_transport_functions;
36968 -extern struct fc_function_template qla2xxx_transport_vport_functions;
36969 +extern fc_function_template_no_const qla2xxx_transport_functions;
36970 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36971 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36972 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36973 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36974 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36975 index 96a5616..eeb185a 100644
36976 --- a/drivers/scsi/qla4xxx/ql4_def.h
36977 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36978 @@ -268,7 +268,7 @@ struct ddb_entry {
36979 * (4000 only) */
36980 atomic_t relogin_timer; /* Max Time to wait for
36981 * relogin to complete */
36982 - atomic_t relogin_retry_count; /* Num of times relogin has been
36983 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36984 * retried */
36985 uint32_t default_time2wait; /* Default Min time between
36986 * relogins (+aens) */
36987 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36988 index cd15678..f7e6846 100644
36989 --- a/drivers/scsi/qla4xxx/ql4_os.c
36990 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36991 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36992 */
36993 if (!iscsi_is_session_online(cls_sess)) {
36994 /* Reset retry relogin timer */
36995 - atomic_inc(&ddb_entry->relogin_retry_count);
36996 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36997 DEBUG2(ql4_printk(KERN_INFO, ha,
36998 "%s: index[%d] relogin timed out-retrying"
36999 " relogin (%d), retry (%d)\n", __func__,
37000 ddb_entry->fw_ddb_index,
37001 - atomic_read(&ddb_entry->relogin_retry_count),
37002 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37003 ddb_entry->default_time2wait + 4));
37004 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37005 atomic_set(&ddb_entry->retry_relogin_timer,
37006 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37007
37008 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37009 atomic_set(&ddb_entry->relogin_timer, 0);
37010 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37011 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37012 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37013 ddb_entry->default_relogin_timeout =
37014 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37015 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37016 index bbbc9c9..ce22f77 100644
37017 --- a/drivers/scsi/scsi.c
37018 +++ b/drivers/scsi/scsi.c
37019 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37020 unsigned long timeout;
37021 int rtn = 0;
37022
37023 - atomic_inc(&cmd->device->iorequest_cnt);
37024 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37025
37026 /* check if the device is still usable */
37027 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37028 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37029 index 495db80..fb37d59 100644
37030 --- a/drivers/scsi/scsi_lib.c
37031 +++ b/drivers/scsi/scsi_lib.c
37032 @@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37033 shost = sdev->host;
37034 scsi_init_cmd_errh(cmd);
37035 cmd->result = DID_NO_CONNECT << 16;
37036 - atomic_inc(&cmd->device->iorequest_cnt);
37037 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37038
37039 /*
37040 * SCSI request completion path will do scsi_device_unbusy(),
37041 @@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
37042
37043 INIT_LIST_HEAD(&cmd->eh_entry);
37044
37045 - atomic_inc(&cmd->device->iodone_cnt);
37046 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37047 if (cmd->result)
37048 - atomic_inc(&cmd->device->ioerr_cnt);
37049 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37050
37051 disposition = scsi_decide_disposition(cmd);
37052 if (disposition != SUCCESS &&
37053 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37054 index bb7c482..7551a95 100644
37055 --- a/drivers/scsi/scsi_sysfs.c
37056 +++ b/drivers/scsi/scsi_sysfs.c
37057 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37058 char *buf) \
37059 { \
37060 struct scsi_device *sdev = to_scsi_device(dev); \
37061 - unsigned long long count = atomic_read(&sdev->field); \
37062 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37063 return snprintf(buf, 20, "0x%llx\n", count); \
37064 } \
37065 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37066 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37067 index 84a1fdf..693b0d6 100644
37068 --- a/drivers/scsi/scsi_tgt_lib.c
37069 +++ b/drivers/scsi/scsi_tgt_lib.c
37070 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37071 int err;
37072
37073 dprintk("%lx %u\n", uaddr, len);
37074 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37075 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37076 if (err) {
37077 /*
37078 * TODO: need to fixup sg_tablesize, max_segment_size,
37079 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37080 index 5797604..289a5b5 100644
37081 --- a/drivers/scsi/scsi_transport_fc.c
37082 +++ b/drivers/scsi/scsi_transport_fc.c
37083 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37084 * Netlink Infrastructure
37085 */
37086
37087 -static atomic_t fc_event_seq;
37088 +static atomic_unchecked_t fc_event_seq;
37089
37090 /**
37091 * fc_get_event_number - Obtain the next sequential FC event number
37092 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37093 u32
37094 fc_get_event_number(void)
37095 {
37096 - return atomic_add_return(1, &fc_event_seq);
37097 + return atomic_add_return_unchecked(1, &fc_event_seq);
37098 }
37099 EXPORT_SYMBOL(fc_get_event_number);
37100
37101 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37102 {
37103 int error;
37104
37105 - atomic_set(&fc_event_seq, 0);
37106 + atomic_set_unchecked(&fc_event_seq, 0);
37107
37108 error = transport_class_register(&fc_host_class);
37109 if (error)
37110 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37111 char *cp;
37112
37113 *val = simple_strtoul(buf, &cp, 0);
37114 - if ((*cp && (*cp != '\n')) || (*val < 0))
37115 + if (*cp && (*cp != '\n'))
37116 return -EINVAL;
37117 /*
37118 * Check for overflow; dev_loss_tmo is u32
37119 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37120 index 1cf640e..78e9014 100644
37121 --- a/drivers/scsi/scsi_transport_iscsi.c
37122 +++ b/drivers/scsi/scsi_transport_iscsi.c
37123 @@ -79,7 +79,7 @@ struct iscsi_internal {
37124 struct transport_container session_cont;
37125 };
37126
37127 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37128 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37129 static struct workqueue_struct *iscsi_eh_timer_workq;
37130
37131 static DEFINE_IDA(iscsi_sess_ida);
37132 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37133 int err;
37134
37135 ihost = shost->shost_data;
37136 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37137 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37138
37139 if (target_id == ISCSI_MAX_TARGET) {
37140 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37141 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37142 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37143 ISCSI_TRANSPORT_VERSION);
37144
37145 - atomic_set(&iscsi_session_nr, 0);
37146 + atomic_set_unchecked(&iscsi_session_nr, 0);
37147
37148 err = class_register(&iscsi_transport_class);
37149 if (err)
37150 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37151 index 21a045e..ec89e03 100644
37152 --- a/drivers/scsi/scsi_transport_srp.c
37153 +++ b/drivers/scsi/scsi_transport_srp.c
37154 @@ -33,7 +33,7 @@
37155 #include "scsi_transport_srp_internal.h"
37156
37157 struct srp_host_attrs {
37158 - atomic_t next_port_id;
37159 + atomic_unchecked_t next_port_id;
37160 };
37161 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37162
37163 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37164 struct Scsi_Host *shost = dev_to_shost(dev);
37165 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37166
37167 - atomic_set(&srp_host->next_port_id, 0);
37168 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37169 return 0;
37170 }
37171
37172 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37173 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37174 rport->roles = ids->roles;
37175
37176 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37177 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37178 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37179
37180 transport_setup_device(&rport->dev);
37181 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37182 index 9c5c5f2..8414557 100644
37183 --- a/drivers/scsi/sg.c
37184 +++ b/drivers/scsi/sg.c
37185 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37186 sdp->disk->disk_name,
37187 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37188 NULL,
37189 - (char *)arg);
37190 + (char __user *)arg);
37191 case BLKTRACESTART:
37192 return blk_trace_startstop(sdp->device->request_queue, 1);
37193 case BLKTRACESTOP:
37194 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37195 index 1041cb8..4a946fa 100644
37196 --- a/drivers/spi/spi.c
37197 +++ b/drivers/spi/spi.c
37198 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37199 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37200
37201 /* portable code must never pass more than 32 bytes */
37202 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37203 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37204
37205 static u8 *buf;
37206
37207 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37208 index 34afc16..ffe44dd 100644
37209 --- a/drivers/staging/octeon/ethernet-rx.c
37210 +++ b/drivers/staging/octeon/ethernet-rx.c
37211 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37212 /* Increment RX stats for virtual ports */
37213 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37214 #ifdef CONFIG_64BIT
37215 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37216 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37217 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37218 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37219 #else
37220 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37221 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37222 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37223 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37224 #endif
37225 }
37226 netif_receive_skb(skb);
37227 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37228 dev->name);
37229 */
37230 #ifdef CONFIG_64BIT
37231 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37232 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37233 #else
37234 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37235 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37236 #endif
37237 dev_kfree_skb_irq(skb);
37238 }
37239 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37240 index 18f7a79..cc3bc24 100644
37241 --- a/drivers/staging/octeon/ethernet.c
37242 +++ b/drivers/staging/octeon/ethernet.c
37243 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37244 * since the RX tasklet also increments it.
37245 */
37246 #ifdef CONFIG_64BIT
37247 - atomic64_add(rx_status.dropped_packets,
37248 - (atomic64_t *)&priv->stats.rx_dropped);
37249 + atomic64_add_unchecked(rx_status.dropped_packets,
37250 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37251 #else
37252 - atomic_add(rx_status.dropped_packets,
37253 - (atomic_t *)&priv->stats.rx_dropped);
37254 + atomic_add_unchecked(rx_status.dropped_packets,
37255 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37256 #endif
37257 }
37258
37259 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37260 index dc23395..cf7e9b1 100644
37261 --- a/drivers/staging/rtl8712/rtl871x_io.h
37262 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37263 @@ -108,7 +108,7 @@ struct _io_ops {
37264 u8 *pmem);
37265 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37266 u8 *pmem);
37267 -};
37268 +} __no_const;
37269
37270 struct io_req {
37271 struct list_head list;
37272 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37273 index c7b5e8b..783d6cb 100644
37274 --- a/drivers/staging/sbe-2t3e3/netdev.c
37275 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37276 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37277 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37278
37279 if (rlen)
37280 - if (copy_to_user(data, &resp, rlen))
37281 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37282 return -EFAULT;
37283
37284 return 0;
37285 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37286 index 42cdafe..2769103 100644
37287 --- a/drivers/staging/speakup/speakup_soft.c
37288 +++ b/drivers/staging/speakup/speakup_soft.c
37289 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37290 break;
37291 } else if (!initialized) {
37292 if (*init) {
37293 - ch = *init;
37294 init++;
37295 } else {
37296 initialized = 1;
37297 }
37298 + ch = *init;
37299 } else {
37300 ch = synth_buffer_getc();
37301 }
37302 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37303 index 5d89c0f..9261317 100644
37304 --- a/drivers/staging/usbip/usbip_common.h
37305 +++ b/drivers/staging/usbip/usbip_common.h
37306 @@ -289,7 +289,7 @@ struct usbip_device {
37307 void (*shutdown)(struct usbip_device *);
37308 void (*reset)(struct usbip_device *);
37309 void (*unusable)(struct usbip_device *);
37310 - } eh_ops;
37311 + } __no_const eh_ops;
37312 };
37313
37314 #define kthread_get_run(threadfn, data, namefmt, ...) \
37315 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37316 index 88b3298..3783eee 100644
37317 --- a/drivers/staging/usbip/vhci.h
37318 +++ b/drivers/staging/usbip/vhci.h
37319 @@ -88,7 +88,7 @@ struct vhci_hcd {
37320 unsigned resuming:1;
37321 unsigned long re_timeout;
37322
37323 - atomic_t seqnum;
37324 + atomic_unchecked_t seqnum;
37325
37326 /*
37327 * NOTE:
37328 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37329 index f708cba..2de6d72 100644
37330 --- a/drivers/staging/usbip/vhci_hcd.c
37331 +++ b/drivers/staging/usbip/vhci_hcd.c
37332 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37333 return;
37334 }
37335
37336 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37337 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37338 if (priv->seqnum == 0xffff)
37339 dev_info(&urb->dev->dev, "seqnum max\n");
37340
37341 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37342 return -ENOMEM;
37343 }
37344
37345 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37346 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37347 if (unlink->seqnum == 0xffff)
37348 pr_info("seqnum max\n");
37349
37350 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37351 vdev->rhport = rhport;
37352 }
37353
37354 - atomic_set(&vhci->seqnum, 0);
37355 + atomic_set_unchecked(&vhci->seqnum, 0);
37356 spin_lock_init(&vhci->lock);
37357
37358 hcd->power_budget = 0; /* no limit */
37359 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37360 index f0eaf04..5a82e06 100644
37361 --- a/drivers/staging/usbip/vhci_rx.c
37362 +++ b/drivers/staging/usbip/vhci_rx.c
37363 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37364 if (!urb) {
37365 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37366 pr_info("max seqnum %d\n",
37367 - atomic_read(&the_controller->seqnum));
37368 + atomic_read_unchecked(&the_controller->seqnum));
37369 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37370 return;
37371 }
37372 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37373 index 7735027..30eed13 100644
37374 --- a/drivers/staging/vt6655/hostap.c
37375 +++ b/drivers/staging/vt6655/hostap.c
37376 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37377 *
37378 */
37379
37380 +static net_device_ops_no_const apdev_netdev_ops;
37381 +
37382 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37383 {
37384 PSDevice apdev_priv;
37385 struct net_device *dev = pDevice->dev;
37386 int ret;
37387 - const struct net_device_ops apdev_netdev_ops = {
37388 - .ndo_start_xmit = pDevice->tx_80211,
37389 - };
37390
37391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37392
37393 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37394 *apdev_priv = *pDevice;
37395 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37396
37397 + /* only half broken now */
37398 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37399 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37400
37401 pDevice->apdev->type = ARPHRD_IEEE80211;
37402 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37403 index 51b5adf..098e320 100644
37404 --- a/drivers/staging/vt6656/hostap.c
37405 +++ b/drivers/staging/vt6656/hostap.c
37406 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37407 *
37408 */
37409
37410 +static net_device_ops_no_const apdev_netdev_ops;
37411 +
37412 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37413 {
37414 PSDevice apdev_priv;
37415 struct net_device *dev = pDevice->dev;
37416 int ret;
37417 - const struct net_device_ops apdev_netdev_ops = {
37418 - .ndo_start_xmit = pDevice->tx_80211,
37419 - };
37420
37421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37422
37423 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37424 *apdev_priv = *pDevice;
37425 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37426
37427 + /* only half broken now */
37428 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37429 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37430
37431 pDevice->apdev->type = ARPHRD_IEEE80211;
37432 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37433 index 7843dfd..3db105f 100644
37434 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37435 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37436 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37437
37438 struct usbctlx_completor {
37439 int (*complete) (struct usbctlx_completor *);
37440 -};
37441 +} __no_const;
37442
37443 static int
37444 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37445 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37446 index 1ca66ea..76f1343 100644
37447 --- a/drivers/staging/zcache/tmem.c
37448 +++ b/drivers/staging/zcache/tmem.c
37449 @@ -39,7 +39,7 @@
37450 * A tmem host implementation must use this function to register callbacks
37451 * for memory allocation.
37452 */
37453 -static struct tmem_hostops tmem_hostops;
37454 +static tmem_hostops_no_const tmem_hostops;
37455
37456 static void tmem_objnode_tree_init(void);
37457
37458 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37459 * A tmem host implementation must use this function to register
37460 * callbacks for a page-accessible memory (PAM) implementation
37461 */
37462 -static struct tmem_pamops tmem_pamops;
37463 +static tmem_pamops_no_const tmem_pamops;
37464
37465 void tmem_register_pamops(struct tmem_pamops *m)
37466 {
37467 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37468 index 0d4aa82..f7832d4 100644
37469 --- a/drivers/staging/zcache/tmem.h
37470 +++ b/drivers/staging/zcache/tmem.h
37471 @@ -180,6 +180,7 @@ struct tmem_pamops {
37472 void (*new_obj)(struct tmem_obj *);
37473 int (*replace_in_obj)(void *, struct tmem_obj *);
37474 };
37475 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37476 extern void tmem_register_pamops(struct tmem_pamops *m);
37477
37478 /* memory allocation methods provided by the host implementation */
37479 @@ -189,6 +190,7 @@ struct tmem_hostops {
37480 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37481 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37482 };
37483 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37484 extern void tmem_register_hostops(struct tmem_hostops *m);
37485
37486 /* core tmem accessor functions */
37487 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37488 index c6c385f..b23c65d 100644
37489 --- a/drivers/target/target_core_transport.c
37490 +++ b/drivers/target/target_core_transport.c
37491 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37492 spin_lock_init(&dev->se_port_lock);
37493 spin_lock_init(&dev->se_tmr_lock);
37494 spin_lock_init(&dev->qf_cmd_lock);
37495 - atomic_set(&dev->dev_ordered_id, 0);
37496 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37497
37498 se_dev_set_default_attribs(dev, dev_limits);
37499
37500 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37501 * Used to determine when ORDERED commands should go from
37502 * Dormant to Active status.
37503 */
37504 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37505 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37506 smp_mb__after_atomic_inc();
37507 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37508 cmd->se_ordered_id, cmd->sam_task_attr,
37509 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37510 index e61cabd..7617d26 100644
37511 --- a/drivers/tty/cyclades.c
37512 +++ b/drivers/tty/cyclades.c
37513 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37514 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37515 info->port.count);
37516 #endif
37517 - info->port.count++;
37518 + atomic_inc(&info->port.count);
37519 #ifdef CY_DEBUG_COUNT
37520 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37521 - current->pid, info->port.count);
37522 + current->pid, atomic_read(&info->port.count));
37523 #endif
37524
37525 /*
37526 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37527 for (j = 0; j < cy_card[i].nports; j++) {
37528 info = &cy_card[i].ports[j];
37529
37530 - if (info->port.count) {
37531 + if (atomic_read(&info->port.count)) {
37532 /* XXX is the ldisc num worth this? */
37533 struct tty_struct *tty;
37534 struct tty_ldisc *ld;
37535 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37536 index 2d691eb..be02ebd 100644
37537 --- a/drivers/tty/hvc/hvc_console.c
37538 +++ b/drivers/tty/hvc/hvc_console.c
37539 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37540
37541 spin_lock_irqsave(&hp->port.lock, flags);
37542 /* Check and then increment for fast path open. */
37543 - if (hp->port.count++ > 0) {
37544 + if (atomic_inc_return(&hp->port.count) > 1) {
37545 spin_unlock_irqrestore(&hp->port.lock, flags);
37546 hvc_kick();
37547 return 0;
37548 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37549
37550 spin_lock_irqsave(&hp->port.lock, flags);
37551
37552 - if (--hp->port.count == 0) {
37553 + if (atomic_dec_return(&hp->port.count) == 0) {
37554 spin_unlock_irqrestore(&hp->port.lock, flags);
37555 /* We are done with the tty pointer now. */
37556 tty_port_tty_set(&hp->port, NULL);
37557 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37558 */
37559 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37560 } else {
37561 - if (hp->port.count < 0)
37562 + if (atomic_read(&hp->port.count) < 0)
37563 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37564 - hp->vtermno, hp->port.count);
37565 + hp->vtermno, atomic_read(&hp->port.count));
37566 spin_unlock_irqrestore(&hp->port.lock, flags);
37567 }
37568
37569 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37570 * open->hangup case this can be called after the final close so prevent
37571 * that from happening for now.
37572 */
37573 - if (hp->port.count <= 0) {
37574 + if (atomic_read(&hp->port.count) <= 0) {
37575 spin_unlock_irqrestore(&hp->port.lock, flags);
37576 return;
37577 }
37578
37579 - temp_open_count = hp->port.count;
37580 - hp->port.count = 0;
37581 + temp_open_count = atomic_read(&hp->port.count);
37582 + atomic_set(&hp->port.count, 0);
37583 spin_unlock_irqrestore(&hp->port.lock, flags);
37584 tty_port_tty_set(&hp->port, NULL);
37585
37586 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37587 return -EPIPE;
37588
37589 /* FIXME what's this (unprotected) check for? */
37590 - if (hp->port.count <= 0)
37591 + if (atomic_read(&hp->port.count) <= 0)
37592 return -EIO;
37593
37594 spin_lock_irqsave(&hp->lock, flags);
37595 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37596 index d56788c..12d8f85 100644
37597 --- a/drivers/tty/hvc/hvcs.c
37598 +++ b/drivers/tty/hvc/hvcs.c
37599 @@ -83,6 +83,7 @@
37600 #include <asm/hvcserver.h>
37601 #include <asm/uaccess.h>
37602 #include <asm/vio.h>
37603 +#include <asm/local.h>
37604
37605 /*
37606 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37607 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37608
37609 spin_lock_irqsave(&hvcsd->lock, flags);
37610
37611 - if (hvcsd->port.count > 0) {
37612 + if (atomic_read(&hvcsd->port.count) > 0) {
37613 spin_unlock_irqrestore(&hvcsd->lock, flags);
37614 printk(KERN_INFO "HVCS: vterm state unchanged. "
37615 "The hvcs device node is still in use.\n");
37616 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37617 if ((retval = hvcs_partner_connect(hvcsd)))
37618 goto error_release;
37619
37620 - hvcsd->port.count = 1;
37621 + atomic_set(&hvcsd->port.count, 1);
37622 hvcsd->port.tty = tty;
37623 tty->driver_data = hvcsd;
37624
37625 @@ -1168,7 +1169,7 @@ fast_open:
37626
37627 spin_lock_irqsave(&hvcsd->lock, flags);
37628 tty_port_get(&hvcsd->port);
37629 - hvcsd->port.count++;
37630 + atomic_inc(&hvcsd->port.count);
37631 hvcsd->todo_mask |= HVCS_SCHED_READ;
37632 spin_unlock_irqrestore(&hvcsd->lock, flags);
37633
37634 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37635 hvcsd = tty->driver_data;
37636
37637 spin_lock_irqsave(&hvcsd->lock, flags);
37638 - if (--hvcsd->port.count == 0) {
37639 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37640
37641 vio_disable_interrupts(hvcsd->vdev);
37642
37643 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37644 free_irq(irq, hvcsd);
37645 tty_port_put(&hvcsd->port);
37646 return;
37647 - } else if (hvcsd->port.count < 0) {
37648 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37649 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37650 " is missmanaged.\n",
37651 - hvcsd->vdev->unit_address, hvcsd->port.count);
37652 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37653 }
37654
37655 spin_unlock_irqrestore(&hvcsd->lock, flags);
37656 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37657
37658 spin_lock_irqsave(&hvcsd->lock, flags);
37659 /* Preserve this so that we know how many kref refs to put */
37660 - temp_open_count = hvcsd->port.count;
37661 + temp_open_count = atomic_read(&hvcsd->port.count);
37662
37663 /*
37664 * Don't kref put inside the spinlock because the destruction
37665 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37666 tty->driver_data = NULL;
37667 hvcsd->port.tty = NULL;
37668
37669 - hvcsd->port.count = 0;
37670 + atomic_set(&hvcsd->port.count, 0);
37671
37672 /* This will drop any buffered data on the floor which is OK in a hangup
37673 * scenario. */
37674 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37675 * the middle of a write operation? This is a crummy place to do this
37676 * but we want to keep it all in the spinlock.
37677 */
37678 - if (hvcsd->port.count <= 0) {
37679 + if (atomic_read(&hvcsd->port.count) <= 0) {
37680 spin_unlock_irqrestore(&hvcsd->lock, flags);
37681 return -ENODEV;
37682 }
37683 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37684 {
37685 struct hvcs_struct *hvcsd = tty->driver_data;
37686
37687 - if (!hvcsd || hvcsd->port.count <= 0)
37688 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37689 return 0;
37690
37691 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37692 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37693 index f8b5fa0..4ba9f89 100644
37694 --- a/drivers/tty/ipwireless/tty.c
37695 +++ b/drivers/tty/ipwireless/tty.c
37696 @@ -29,6 +29,7 @@
37697 #include <linux/tty_driver.h>
37698 #include <linux/tty_flip.h>
37699 #include <linux/uaccess.h>
37700 +#include <asm/local.h>
37701
37702 #include "tty.h"
37703 #include "network.h"
37704 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37705 mutex_unlock(&tty->ipw_tty_mutex);
37706 return -ENODEV;
37707 }
37708 - if (tty->port.count == 0)
37709 + if (atomic_read(&tty->port.count) == 0)
37710 tty->tx_bytes_queued = 0;
37711
37712 - tty->port.count++;
37713 + atomic_inc(&tty->port.count);
37714
37715 tty->port.tty = linux_tty;
37716 linux_tty->driver_data = tty;
37717 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37718
37719 static void do_ipw_close(struct ipw_tty *tty)
37720 {
37721 - tty->port.count--;
37722 -
37723 - if (tty->port.count == 0) {
37724 + if (atomic_dec_return(&tty->port.count) == 0) {
37725 struct tty_struct *linux_tty = tty->port.tty;
37726
37727 if (linux_tty != NULL) {
37728 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37729 return;
37730
37731 mutex_lock(&tty->ipw_tty_mutex);
37732 - if (tty->port.count == 0) {
37733 + if (atomic_read(&tty->port.count) == 0) {
37734 mutex_unlock(&tty->ipw_tty_mutex);
37735 return;
37736 }
37737 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37738 return;
37739 }
37740
37741 - if (!tty->port.count) {
37742 + if (!atomic_read(&tty->port.count)) {
37743 mutex_unlock(&tty->ipw_tty_mutex);
37744 return;
37745 }
37746 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37747 return -ENODEV;
37748
37749 mutex_lock(&tty->ipw_tty_mutex);
37750 - if (!tty->port.count) {
37751 + if (!atomic_read(&tty->port.count)) {
37752 mutex_unlock(&tty->ipw_tty_mutex);
37753 return -EINVAL;
37754 }
37755 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37756 if (!tty)
37757 return -ENODEV;
37758
37759 - if (!tty->port.count)
37760 + if (!atomic_read(&tty->port.count))
37761 return -EINVAL;
37762
37763 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37764 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37765 if (!tty)
37766 return 0;
37767
37768 - if (!tty->port.count)
37769 + if (!atomic_read(&tty->port.count))
37770 return 0;
37771
37772 return tty->tx_bytes_queued;
37773 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37774 if (!tty)
37775 return -ENODEV;
37776
37777 - if (!tty->port.count)
37778 + if (!atomic_read(&tty->port.count))
37779 return -EINVAL;
37780
37781 return get_control_lines(tty);
37782 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37783 if (!tty)
37784 return -ENODEV;
37785
37786 - if (!tty->port.count)
37787 + if (!atomic_read(&tty->port.count))
37788 return -EINVAL;
37789
37790 return set_control_lines(tty, set, clear);
37791 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37792 if (!tty)
37793 return -ENODEV;
37794
37795 - if (!tty->port.count)
37796 + if (!atomic_read(&tty->port.count))
37797 return -EINVAL;
37798
37799 /* FIXME: Exactly how is the tty object locked here .. */
37800 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37801 * are gone */
37802 mutex_lock(&ttyj->ipw_tty_mutex);
37803 }
37804 - while (ttyj->port.count)
37805 + while (atomic_read(&ttyj->port.count))
37806 do_ipw_close(ttyj);
37807 ipwireless_disassociate_network_ttys(network,
37808 ttyj->channel_idx);
37809 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37810 index 324467d..504cc25 100644
37811 --- a/drivers/tty/moxa.c
37812 +++ b/drivers/tty/moxa.c
37813 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37814 }
37815
37816 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37817 - ch->port.count++;
37818 + atomic_inc(&ch->port.count);
37819 tty->driver_data = ch;
37820 tty_port_tty_set(&ch->port, tty);
37821 mutex_lock(&ch->port.mutex);
37822 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37823 index c43b683..4dab83e 100644
37824 --- a/drivers/tty/n_gsm.c
37825 +++ b/drivers/tty/n_gsm.c
37826 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37827 kref_init(&dlci->ref);
37828 mutex_init(&dlci->mutex);
37829 dlci->fifo = &dlci->_fifo;
37830 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37831 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37832 kfree(dlci);
37833 return NULL;
37834 }
37835 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37836 if (dlci == NULL)
37837 return -ENOMEM;
37838 port = &dlci->port;
37839 - port->count++;
37840 + atomic_inc(&port->count);
37841 tty->driver_data = dlci;
37842 dlci_get(dlci);
37843 dlci_get(dlci->gsm->dlci[0]);
37844 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37845 index ee1c268..0e97caf 100644
37846 --- a/drivers/tty/n_tty.c
37847 +++ b/drivers/tty/n_tty.c
37848 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37849 {
37850 *ops = tty_ldisc_N_TTY;
37851 ops->owner = NULL;
37852 - ops->refcount = ops->flags = 0;
37853 + atomic_set(&ops->refcount, 0);
37854 + ops->flags = 0;
37855 }
37856 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37857 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37858 index 5505ffc..7affff9 100644
37859 --- a/drivers/tty/pty.c
37860 +++ b/drivers/tty/pty.c
37861 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37862 panic("Couldn't register Unix98 pts driver");
37863
37864 /* Now create the /dev/ptmx special device */
37865 + pax_open_kernel();
37866 tty_default_fops(&ptmx_fops);
37867 - ptmx_fops.open = ptmx_open;
37868 + *(void **)&ptmx_fops.open = ptmx_open;
37869 + pax_close_kernel();
37870
37871 cdev_init(&ptmx_cdev, &ptmx_fops);
37872 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37873 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37874 index 777d5f9..56d67ca 100644
37875 --- a/drivers/tty/rocket.c
37876 +++ b/drivers/tty/rocket.c
37877 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37878 tty->driver_data = info;
37879 tty_port_tty_set(port, tty);
37880
37881 - if (port->count++ == 0) {
37882 + if (atomic_inc_return(&port->count) == 1) {
37883 atomic_inc(&rp_num_ports_open);
37884
37885 #ifdef ROCKET_DEBUG_OPEN
37886 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37887 #endif
37888 }
37889 #ifdef ROCKET_DEBUG_OPEN
37890 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37891 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37892 #endif
37893
37894 /*
37895 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37896 spin_unlock_irqrestore(&info->port.lock, flags);
37897 return;
37898 }
37899 - if (info->port.count)
37900 + if (atomic_read(&info->port.count))
37901 atomic_dec(&rp_num_ports_open);
37902 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37903 spin_unlock_irqrestore(&info->port.lock, flags);
37904 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37905 index 2b42a01..32a2ed3 100644
37906 --- a/drivers/tty/serial/kgdboc.c
37907 +++ b/drivers/tty/serial/kgdboc.c
37908 @@ -24,8 +24,9 @@
37909 #define MAX_CONFIG_LEN 40
37910
37911 static struct kgdb_io kgdboc_io_ops;
37912 +static struct kgdb_io kgdboc_io_ops_console;
37913
37914 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37915 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37916 static int configured = -1;
37917
37918 static char config[MAX_CONFIG_LEN];
37919 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37920 kgdboc_unregister_kbd();
37921 if (configured == 1)
37922 kgdb_unregister_io_module(&kgdboc_io_ops);
37923 + else if (configured == 2)
37924 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37925 }
37926
37927 static int configure_kgdboc(void)
37928 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37929 int err;
37930 char *cptr = config;
37931 struct console *cons;
37932 + int is_console = 0;
37933
37934 err = kgdboc_option_setup(config);
37935 if (err || !strlen(config) || isspace(config[0]))
37936 goto noconfig;
37937
37938 err = -ENODEV;
37939 - kgdboc_io_ops.is_console = 0;
37940 kgdb_tty_driver = NULL;
37941
37942 kgdboc_use_kms = 0;
37943 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37944 int idx;
37945 if (cons->device && cons->device(cons, &idx) == p &&
37946 idx == tty_line) {
37947 - kgdboc_io_ops.is_console = 1;
37948 + is_console = 1;
37949 break;
37950 }
37951 cons = cons->next;
37952 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37953 kgdb_tty_line = tty_line;
37954
37955 do_register:
37956 - err = kgdb_register_io_module(&kgdboc_io_ops);
37957 + if (is_console) {
37958 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37959 + configured = 2;
37960 + } else {
37961 + err = kgdb_register_io_module(&kgdboc_io_ops);
37962 + configured = 1;
37963 + }
37964 if (err)
37965 goto noconfig;
37966
37967 - configured = 1;
37968 -
37969 return 0;
37970
37971 noconfig:
37972 @@ -213,7 +220,7 @@ noconfig:
37973 static int __init init_kgdboc(void)
37974 {
37975 /* Already configured? */
37976 - if (configured == 1)
37977 + if (configured >= 1)
37978 return 0;
37979
37980 return configure_kgdboc();
37981 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37982 if (config[len - 1] == '\n')
37983 config[len - 1] = '\0';
37984
37985 - if (configured == 1)
37986 + if (configured >= 1)
37987 cleanup_kgdboc();
37988
37989 /* Go and configure with the new params. */
37990 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37991 .post_exception = kgdboc_post_exp_handler,
37992 };
37993
37994 +static struct kgdb_io kgdboc_io_ops_console = {
37995 + .name = "kgdboc",
37996 + .read_char = kgdboc_get_char,
37997 + .write_char = kgdboc_put_char,
37998 + .pre_exception = kgdboc_pre_exp_handler,
37999 + .post_exception = kgdboc_post_exp_handler,
38000 + .is_console = 1
38001 +};
38002 +
38003 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38004 /* This is only available if kgdboc is a built in for early debugging */
38005 static int __init kgdboc_early_init(char *opt)
38006 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38007 index 246b823..9e0db76 100644
38008 --- a/drivers/tty/serial/serial_core.c
38009 +++ b/drivers/tty/serial/serial_core.c
38010 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38011 uart_flush_buffer(tty);
38012 uart_shutdown(tty, state);
38013 spin_lock_irqsave(&port->lock, flags);
38014 - port->count = 0;
38015 + atomic_set(&port->count, 0);
38016 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38017 spin_unlock_irqrestore(&port->lock, flags);
38018 tty_port_tty_set(port, NULL);
38019 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38020 goto end;
38021 }
38022
38023 - port->count++;
38024 + atomic_inc(&port->count);
38025 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38026 retval = -ENXIO;
38027 goto err_dec_count;
38028 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38029 /*
38030 * Make sure the device is in D0 state.
38031 */
38032 - if (port->count == 1)
38033 + if (atomic_read(&port->count) == 1)
38034 uart_change_pm(state, 0);
38035
38036 /*
38037 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38038 end:
38039 return retval;
38040 err_dec_count:
38041 - port->count--;
38042 + atomic_inc(&port->count);
38043 mutex_unlock(&port->mutex);
38044 goto end;
38045 }
38046 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38047 index 593d40a..bdc61f3 100644
38048 --- a/drivers/tty/synclink.c
38049 +++ b/drivers/tty/synclink.c
38050 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38051
38052 if (debug_level >= DEBUG_LEVEL_INFO)
38053 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38054 - __FILE__,__LINE__, info->device_name, info->port.count);
38055 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38056
38057 if (tty_port_close_start(&info->port, tty, filp) == 0)
38058 goto cleanup;
38059 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38060 cleanup:
38061 if (debug_level >= DEBUG_LEVEL_INFO)
38062 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38063 - tty->driver->name, info->port.count);
38064 + tty->driver->name, atomic_read(&info->port.count));
38065
38066 } /* end of mgsl_close() */
38067
38068 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38069
38070 mgsl_flush_buffer(tty);
38071 shutdown(info);
38072 -
38073 - info->port.count = 0;
38074 +
38075 + atomic_set(&info->port.count, 0);
38076 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38077 info->port.tty = NULL;
38078
38079 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38080
38081 if (debug_level >= DEBUG_LEVEL_INFO)
38082 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38083 - __FILE__,__LINE__, tty->driver->name, port->count );
38084 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38085
38086 spin_lock_irqsave(&info->irq_spinlock, flags);
38087 if (!tty_hung_up_p(filp)) {
38088 extra_count = true;
38089 - port->count--;
38090 + atomic_dec(&port->count);
38091 }
38092 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38093 port->blocked_open++;
38094 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38095
38096 if (debug_level >= DEBUG_LEVEL_INFO)
38097 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38098 - __FILE__,__LINE__, tty->driver->name, port->count );
38099 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38100
38101 tty_unlock();
38102 schedule();
38103 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38104
38105 /* FIXME: Racy on hangup during close wait */
38106 if (extra_count)
38107 - port->count++;
38108 + atomic_inc(&port->count);
38109 port->blocked_open--;
38110
38111 if (debug_level >= DEBUG_LEVEL_INFO)
38112 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38113 - __FILE__,__LINE__, tty->driver->name, port->count );
38114 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38115
38116 if (!retval)
38117 port->flags |= ASYNC_NORMAL_ACTIVE;
38118 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38119
38120 if (debug_level >= DEBUG_LEVEL_INFO)
38121 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38122 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38123 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38124
38125 /* If port is closing, signal caller to try again */
38126 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38127 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38128 spin_unlock_irqrestore(&info->netlock, flags);
38129 goto cleanup;
38130 }
38131 - info->port.count++;
38132 + atomic_inc(&info->port.count);
38133 spin_unlock_irqrestore(&info->netlock, flags);
38134
38135 - if (info->port.count == 1) {
38136 + if (atomic_read(&info->port.count) == 1) {
38137 /* 1st open on this device, init hardware */
38138 retval = startup(info);
38139 if (retval < 0)
38140 @@ -3444,8 +3444,8 @@ cleanup:
38141 if (retval) {
38142 if (tty->count == 1)
38143 info->port.tty = NULL; /* tty layer will release tty struct */
38144 - if(info->port.count)
38145 - info->port.count--;
38146 + if (atomic_read(&info->port.count))
38147 + atomic_dec(&info->port.count);
38148 }
38149
38150 return retval;
38151 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38152 unsigned short new_crctype;
38153
38154 /* return error if TTY interface open */
38155 - if (info->port.count)
38156 + if (atomic_read(&info->port.count))
38157 return -EBUSY;
38158
38159 switch (encoding)
38160 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38161
38162 /* arbitrate between network and tty opens */
38163 spin_lock_irqsave(&info->netlock, flags);
38164 - if (info->port.count != 0 || info->netcount != 0) {
38165 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38166 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38167 spin_unlock_irqrestore(&info->netlock, flags);
38168 return -EBUSY;
38169 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38170 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38171
38172 /* return error if TTY interface open */
38173 - if (info->port.count)
38174 + if (atomic_read(&info->port.count))
38175 return -EBUSY;
38176
38177 if (cmd != SIOCWANDEV)
38178 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38179 index aa1debf..9297a16 100644
38180 --- a/drivers/tty/synclink_gt.c
38181 +++ b/drivers/tty/synclink_gt.c
38182 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38183 tty->driver_data = info;
38184 info->port.tty = tty;
38185
38186 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38187 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38188
38189 /* If port is closing, signal caller to try again */
38190 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38191 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38192 mutex_unlock(&info->port.mutex);
38193 goto cleanup;
38194 }
38195 - info->port.count++;
38196 + atomic_inc(&info->port.count);
38197 spin_unlock_irqrestore(&info->netlock, flags);
38198
38199 - if (info->port.count == 1) {
38200 + if (atomic_read(&info->port.count) == 1) {
38201 /* 1st open on this device, init hardware */
38202 retval = startup(info);
38203 if (retval < 0) {
38204 @@ -716,8 +716,8 @@ cleanup:
38205 if (retval) {
38206 if (tty->count == 1)
38207 info->port.tty = NULL; /* tty layer will release tty struct */
38208 - if(info->port.count)
38209 - info->port.count--;
38210 + if(atomic_read(&info->port.count))
38211 + atomic_dec(&info->port.count);
38212 }
38213
38214 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38215 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38216
38217 if (sanity_check(info, tty->name, "close"))
38218 return;
38219 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38220 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38221
38222 if (tty_port_close_start(&info->port, tty, filp) == 0)
38223 goto cleanup;
38224 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38225 tty_port_close_end(&info->port, tty);
38226 info->port.tty = NULL;
38227 cleanup:
38228 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38229 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38230 }
38231
38232 static void hangup(struct tty_struct *tty)
38233 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38234 shutdown(info);
38235
38236 spin_lock_irqsave(&info->port.lock, flags);
38237 - info->port.count = 0;
38238 + atomic_set(&info->port.count, 0);
38239 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38240 info->port.tty = NULL;
38241 spin_unlock_irqrestore(&info->port.lock, flags);
38242 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38243 unsigned short new_crctype;
38244
38245 /* return error if TTY interface open */
38246 - if (info->port.count)
38247 + if (atomic_read(&info->port.count))
38248 return -EBUSY;
38249
38250 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38251 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38252
38253 /* arbitrate between network and tty opens */
38254 spin_lock_irqsave(&info->netlock, flags);
38255 - if (info->port.count != 0 || info->netcount != 0) {
38256 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38257 DBGINFO(("%s hdlc_open busy\n", dev->name));
38258 spin_unlock_irqrestore(&info->netlock, flags);
38259 return -EBUSY;
38260 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38261 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38262
38263 /* return error if TTY interface open */
38264 - if (info->port.count)
38265 + if (atomic_read(&info->port.count))
38266 return -EBUSY;
38267
38268 if (cmd != SIOCWANDEV)
38269 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38270 if (port == NULL)
38271 continue;
38272 spin_lock(&port->lock);
38273 - if ((port->port.count || port->netcount) &&
38274 + if ((atomic_read(&port->port.count) || port->netcount) &&
38275 port->pending_bh && !port->bh_running &&
38276 !port->bh_requested) {
38277 DBGISR(("%s bh queued\n", port->device_name));
38278 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38279 spin_lock_irqsave(&info->lock, flags);
38280 if (!tty_hung_up_p(filp)) {
38281 extra_count = true;
38282 - port->count--;
38283 + atomic_dec(&port->count);
38284 }
38285 spin_unlock_irqrestore(&info->lock, flags);
38286 port->blocked_open++;
38287 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38288 remove_wait_queue(&port->open_wait, &wait);
38289
38290 if (extra_count)
38291 - port->count++;
38292 + atomic_inc(&port->count);
38293 port->blocked_open--;
38294
38295 if (!retval)
38296 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38297 index a3dddc1..8905ab2 100644
38298 --- a/drivers/tty/synclinkmp.c
38299 +++ b/drivers/tty/synclinkmp.c
38300 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38301
38302 if (debug_level >= DEBUG_LEVEL_INFO)
38303 printk("%s(%d):%s open(), old ref count = %d\n",
38304 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38305 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38306
38307 /* If port is closing, signal caller to try again */
38308 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38309 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38310 spin_unlock_irqrestore(&info->netlock, flags);
38311 goto cleanup;
38312 }
38313 - info->port.count++;
38314 + atomic_inc(&info->port.count);
38315 spin_unlock_irqrestore(&info->netlock, flags);
38316
38317 - if (info->port.count == 1) {
38318 + if (atomic_read(&info->port.count) == 1) {
38319 /* 1st open on this device, init hardware */
38320 retval = startup(info);
38321 if (retval < 0)
38322 @@ -788,8 +788,8 @@ cleanup:
38323 if (retval) {
38324 if (tty->count == 1)
38325 info->port.tty = NULL; /* tty layer will release tty struct */
38326 - if(info->port.count)
38327 - info->port.count--;
38328 + if(atomic_read(&info->port.count))
38329 + atomic_dec(&info->port.count);
38330 }
38331
38332 return retval;
38333 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38334
38335 if (debug_level >= DEBUG_LEVEL_INFO)
38336 printk("%s(%d):%s close() entry, count=%d\n",
38337 - __FILE__,__LINE__, info->device_name, info->port.count);
38338 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38339
38340 if (tty_port_close_start(&info->port, tty, filp) == 0)
38341 goto cleanup;
38342 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38343 cleanup:
38344 if (debug_level >= DEBUG_LEVEL_INFO)
38345 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38346 - tty->driver->name, info->port.count);
38347 + tty->driver->name, atomic_read(&info->port.count));
38348 }
38349
38350 /* Called by tty_hangup() when a hangup is signaled.
38351 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38352 shutdown(info);
38353
38354 spin_lock_irqsave(&info->port.lock, flags);
38355 - info->port.count = 0;
38356 + atomic_set(&info->port.count, 0);
38357 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38358 info->port.tty = NULL;
38359 spin_unlock_irqrestore(&info->port.lock, flags);
38360 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38361 unsigned short new_crctype;
38362
38363 /* return error if TTY interface open */
38364 - if (info->port.count)
38365 + if (atomic_read(&info->port.count))
38366 return -EBUSY;
38367
38368 switch (encoding)
38369 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38370
38371 /* arbitrate between network and tty opens */
38372 spin_lock_irqsave(&info->netlock, flags);
38373 - if (info->port.count != 0 || info->netcount != 0) {
38374 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38375 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38376 spin_unlock_irqrestore(&info->netlock, flags);
38377 return -EBUSY;
38378 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38379 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38380
38381 /* return error if TTY interface open */
38382 - if (info->port.count)
38383 + if (atomic_read(&info->port.count))
38384 return -EBUSY;
38385
38386 if (cmd != SIOCWANDEV)
38387 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38388 * do not request bottom half processing if the
38389 * device is not open in a normal mode.
38390 */
38391 - if ( port && (port->port.count || port->netcount) &&
38392 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38393 port->pending_bh && !port->bh_running &&
38394 !port->bh_requested ) {
38395 if ( debug_level >= DEBUG_LEVEL_ISR )
38396 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38397
38398 if (debug_level >= DEBUG_LEVEL_INFO)
38399 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38400 - __FILE__,__LINE__, tty->driver->name, port->count );
38401 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38402
38403 spin_lock_irqsave(&info->lock, flags);
38404 if (!tty_hung_up_p(filp)) {
38405 extra_count = true;
38406 - port->count--;
38407 + atomic_dec(&port->count);
38408 }
38409 spin_unlock_irqrestore(&info->lock, flags);
38410 port->blocked_open++;
38411 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38412
38413 if (debug_level >= DEBUG_LEVEL_INFO)
38414 printk("%s(%d):%s block_til_ready() count=%d\n",
38415 - __FILE__,__LINE__, tty->driver->name, port->count );
38416 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38417
38418 tty_unlock();
38419 schedule();
38420 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38421 remove_wait_queue(&port->open_wait, &wait);
38422
38423 if (extra_count)
38424 - port->count++;
38425 + atomic_inc(&port->count);
38426 port->blocked_open--;
38427
38428 if (debug_level >= DEBUG_LEVEL_INFO)
38429 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38430 - __FILE__,__LINE__, tty->driver->name, port->count );
38431 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38432
38433 if (!retval)
38434 port->flags |= ASYNC_NORMAL_ACTIVE;
38435 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38436 index 05728894..b9d44c6 100644
38437 --- a/drivers/tty/sysrq.c
38438 +++ b/drivers/tty/sysrq.c
38439 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38440 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38441 size_t count, loff_t *ppos)
38442 {
38443 - if (count) {
38444 + if (count && capable(CAP_SYS_ADMIN)) {
38445 char c;
38446
38447 if (get_user(c, buf))
38448 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38449 index b425c79..08a3f06 100644
38450 --- a/drivers/tty/tty_io.c
38451 +++ b/drivers/tty/tty_io.c
38452 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38453
38454 void tty_default_fops(struct file_operations *fops)
38455 {
38456 - *fops = tty_fops;
38457 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38458 }
38459
38460 /*
38461 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38462 index 9911eb6..5abe0e1 100644
38463 --- a/drivers/tty/tty_ldisc.c
38464 +++ b/drivers/tty/tty_ldisc.c
38465 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38466 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38467 struct tty_ldisc_ops *ldo = ld->ops;
38468
38469 - ldo->refcount--;
38470 + atomic_dec(&ldo->refcount);
38471 module_put(ldo->owner);
38472 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38473
38474 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38475 spin_lock_irqsave(&tty_ldisc_lock, flags);
38476 tty_ldiscs[disc] = new_ldisc;
38477 new_ldisc->num = disc;
38478 - new_ldisc->refcount = 0;
38479 + atomic_set(&new_ldisc->refcount, 0);
38480 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38481
38482 return ret;
38483 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38484 return -EINVAL;
38485
38486 spin_lock_irqsave(&tty_ldisc_lock, flags);
38487 - if (tty_ldiscs[disc]->refcount)
38488 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38489 ret = -EBUSY;
38490 else
38491 tty_ldiscs[disc] = NULL;
38492 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38493 if (ldops) {
38494 ret = ERR_PTR(-EAGAIN);
38495 if (try_module_get(ldops->owner)) {
38496 - ldops->refcount++;
38497 + atomic_inc(&ldops->refcount);
38498 ret = ldops;
38499 }
38500 }
38501 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38502 unsigned long flags;
38503
38504 spin_lock_irqsave(&tty_ldisc_lock, flags);
38505 - ldops->refcount--;
38506 + atomic_dec(&ldops->refcount);
38507 module_put(ldops->owner);
38508 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38509 }
38510 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38511 index bf6e238..d401c04 100644
38512 --- a/drivers/tty/tty_port.c
38513 +++ b/drivers/tty/tty_port.c
38514 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38515 unsigned long flags;
38516
38517 spin_lock_irqsave(&port->lock, flags);
38518 - port->count = 0;
38519 + atomic_set(&port->count, 0);
38520 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38521 if (port->tty) {
38522 set_bit(TTY_IO_ERROR, &port->tty->flags);
38523 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38524 /* The port lock protects the port counts */
38525 spin_lock_irqsave(&port->lock, flags);
38526 if (!tty_hung_up_p(filp))
38527 - port->count--;
38528 + atomic_dec(&port->count);
38529 port->blocked_open++;
38530 spin_unlock_irqrestore(&port->lock, flags);
38531
38532 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38533 we must not mess that up further */
38534 spin_lock_irqsave(&port->lock, flags);
38535 if (!tty_hung_up_p(filp))
38536 - port->count++;
38537 + atomic_inc(&port->count);
38538 port->blocked_open--;
38539 if (retval == 0)
38540 port->flags |= ASYNC_NORMAL_ACTIVE;
38541 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38542 return 0;
38543 }
38544
38545 - if (tty->count == 1 && port->count != 1) {
38546 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38547 printk(KERN_WARNING
38548 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38549 - port->count);
38550 - port->count = 1;
38551 + atomic_read(&port->count));
38552 + atomic_set(&port->count, 1);
38553 }
38554 - if (--port->count < 0) {
38555 + if (atomic_dec_return(&port->count) < 0) {
38556 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38557 - port->count);
38558 - port->count = 0;
38559 + atomic_read(&port->count));
38560 + atomic_set(&port->count, 0);
38561 }
38562
38563 - if (port->count) {
38564 + if (atomic_read(&port->count)) {
38565 spin_unlock_irqrestore(&port->lock, flags);
38566 if (port->ops->drop)
38567 port->ops->drop(port);
38568 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38569 {
38570 spin_lock_irq(&port->lock);
38571 if (!tty_hung_up_p(filp))
38572 - ++port->count;
38573 + atomic_inc(&port->count);
38574 spin_unlock_irq(&port->lock);
38575 tty_port_tty_set(port, tty);
38576
38577 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38578 index 48cc6f2..85584dd 100644
38579 --- a/drivers/tty/vt/keyboard.c
38580 +++ b/drivers/tty/vt/keyboard.c
38581 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38582 kbd->kbdmode == VC_OFF) &&
38583 value != KVAL(K_SAK))
38584 return; /* SAK is allowed even in raw mode */
38585 +
38586 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38587 + {
38588 + void *func = fn_handler[value];
38589 + if (func == fn_show_state || func == fn_show_ptregs ||
38590 + func == fn_show_mem)
38591 + return;
38592 + }
38593 +#endif
38594 +
38595 fn_handler[value](vc);
38596 }
38597
38598 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38599 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38600 return -EFAULT;
38601
38602 - if (!capable(CAP_SYS_TTY_CONFIG))
38603 - perm = 0;
38604 -
38605 switch (cmd) {
38606 case KDGKBENT:
38607 /* Ensure another thread doesn't free it under us */
38608 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38609 spin_unlock_irqrestore(&kbd_event_lock, flags);
38610 return put_user(val, &user_kbe->kb_value);
38611 case KDSKBENT:
38612 + if (!capable(CAP_SYS_TTY_CONFIG))
38613 + perm = 0;
38614 +
38615 if (!perm)
38616 return -EPERM;
38617 if (!i && v == K_NOSUCHMAP) {
38618 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38619 int i, j, k;
38620 int ret;
38621
38622 - if (!capable(CAP_SYS_TTY_CONFIG))
38623 - perm = 0;
38624 -
38625 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38626 if (!kbs) {
38627 ret = -ENOMEM;
38628 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38629 kfree(kbs);
38630 return ((p && *p) ? -EOVERFLOW : 0);
38631 case KDSKBSENT:
38632 + if (!capable(CAP_SYS_TTY_CONFIG))
38633 + perm = 0;
38634 +
38635 if (!perm) {
38636 ret = -EPERM;
38637 goto reterr;
38638 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38639 index a783d53..cb30d94 100644
38640 --- a/drivers/uio/uio.c
38641 +++ b/drivers/uio/uio.c
38642 @@ -25,6 +25,7 @@
38643 #include <linux/kobject.h>
38644 #include <linux/cdev.h>
38645 #include <linux/uio_driver.h>
38646 +#include <asm/local.h>
38647
38648 #define UIO_MAX_DEVICES (1U << MINORBITS)
38649
38650 @@ -32,10 +33,10 @@ struct uio_device {
38651 struct module *owner;
38652 struct device *dev;
38653 int minor;
38654 - atomic_t event;
38655 + atomic_unchecked_t event;
38656 struct fasync_struct *async_queue;
38657 wait_queue_head_t wait;
38658 - int vma_count;
38659 + local_t vma_count;
38660 struct uio_info *info;
38661 struct kobject *map_dir;
38662 struct kobject *portio_dir;
38663 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38664 struct device_attribute *attr, char *buf)
38665 {
38666 struct uio_device *idev = dev_get_drvdata(dev);
38667 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38668 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38669 }
38670
38671 static struct device_attribute uio_class_attributes[] = {
38672 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38673 {
38674 struct uio_device *idev = info->uio_dev;
38675
38676 - atomic_inc(&idev->event);
38677 + atomic_inc_unchecked(&idev->event);
38678 wake_up_interruptible(&idev->wait);
38679 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38680 }
38681 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38682 }
38683
38684 listener->dev = idev;
38685 - listener->event_count = atomic_read(&idev->event);
38686 + listener->event_count = atomic_read_unchecked(&idev->event);
38687 filep->private_data = listener;
38688
38689 if (idev->info->open) {
38690 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38691 return -EIO;
38692
38693 poll_wait(filep, &idev->wait, wait);
38694 - if (listener->event_count != atomic_read(&idev->event))
38695 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38696 return POLLIN | POLLRDNORM;
38697 return 0;
38698 }
38699 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38700 do {
38701 set_current_state(TASK_INTERRUPTIBLE);
38702
38703 - event_count = atomic_read(&idev->event);
38704 + event_count = atomic_read_unchecked(&idev->event);
38705 if (event_count != listener->event_count) {
38706 if (copy_to_user(buf, &event_count, count))
38707 retval = -EFAULT;
38708 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38709 static void uio_vma_open(struct vm_area_struct *vma)
38710 {
38711 struct uio_device *idev = vma->vm_private_data;
38712 - idev->vma_count++;
38713 + local_inc(&idev->vma_count);
38714 }
38715
38716 static void uio_vma_close(struct vm_area_struct *vma)
38717 {
38718 struct uio_device *idev = vma->vm_private_data;
38719 - idev->vma_count--;
38720 + local_dec(&idev->vma_count);
38721 }
38722
38723 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38724 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38725 idev->owner = owner;
38726 idev->info = info;
38727 init_waitqueue_head(&idev->wait);
38728 - atomic_set(&idev->event, 0);
38729 + atomic_set_unchecked(&idev->event, 0);
38730
38731 ret = uio_get_minor(idev);
38732 if (ret)
38733 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38734 index b7eb86a..36d28af 100644
38735 --- a/drivers/usb/atm/cxacru.c
38736 +++ b/drivers/usb/atm/cxacru.c
38737 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38738 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38739 if (ret < 2)
38740 return -EINVAL;
38741 - if (index < 0 || index > 0x7f)
38742 + if (index > 0x7f)
38743 return -EINVAL;
38744 pos += tmp;
38745
38746 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38747 index ee62b35..b663594 100644
38748 --- a/drivers/usb/atm/usbatm.c
38749 +++ b/drivers/usb/atm/usbatm.c
38750 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38751 if (printk_ratelimit())
38752 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38753 __func__, vpi, vci);
38754 - atomic_inc(&vcc->stats->rx_err);
38755 + atomic_inc_unchecked(&vcc->stats->rx_err);
38756 return;
38757 }
38758
38759 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38760 if (length > ATM_MAX_AAL5_PDU) {
38761 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38762 __func__, length, vcc);
38763 - atomic_inc(&vcc->stats->rx_err);
38764 + atomic_inc_unchecked(&vcc->stats->rx_err);
38765 goto out;
38766 }
38767
38768 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38769 if (sarb->len < pdu_length) {
38770 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38771 __func__, pdu_length, sarb->len, vcc);
38772 - atomic_inc(&vcc->stats->rx_err);
38773 + atomic_inc_unchecked(&vcc->stats->rx_err);
38774 goto out;
38775 }
38776
38777 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38778 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38779 __func__, vcc);
38780 - atomic_inc(&vcc->stats->rx_err);
38781 + atomic_inc_unchecked(&vcc->stats->rx_err);
38782 goto out;
38783 }
38784
38785 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38786 if (printk_ratelimit())
38787 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38788 __func__, length);
38789 - atomic_inc(&vcc->stats->rx_drop);
38790 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38791 goto out;
38792 }
38793
38794 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38795
38796 vcc->push(vcc, skb);
38797
38798 - atomic_inc(&vcc->stats->rx);
38799 + atomic_inc_unchecked(&vcc->stats->rx);
38800 out:
38801 skb_trim(sarb, 0);
38802 }
38803 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38804 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38805
38806 usbatm_pop(vcc, skb);
38807 - atomic_inc(&vcc->stats->tx);
38808 + atomic_inc_unchecked(&vcc->stats->tx);
38809
38810 skb = skb_dequeue(&instance->sndqueue);
38811 }
38812 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38813 if (!left--)
38814 return sprintf(page,
38815 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38816 - atomic_read(&atm_dev->stats.aal5.tx),
38817 - atomic_read(&atm_dev->stats.aal5.tx_err),
38818 - atomic_read(&atm_dev->stats.aal5.rx),
38819 - atomic_read(&atm_dev->stats.aal5.rx_err),
38820 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38821 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38822 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38823 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38824 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38825 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38826
38827 if (!left--) {
38828 if (instance->disconnected)
38829 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38830 index d956965..4179a77 100644
38831 --- a/drivers/usb/core/devices.c
38832 +++ b/drivers/usb/core/devices.c
38833 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38834 * time it gets called.
38835 */
38836 static struct device_connect_event {
38837 - atomic_t count;
38838 + atomic_unchecked_t count;
38839 wait_queue_head_t wait;
38840 } device_event = {
38841 .count = ATOMIC_INIT(1),
38842 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38843
38844 void usbfs_conn_disc_event(void)
38845 {
38846 - atomic_add(2, &device_event.count);
38847 + atomic_add_unchecked(2, &device_event.count);
38848 wake_up(&device_event.wait);
38849 }
38850
38851 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38852
38853 poll_wait(file, &device_event.wait, wait);
38854
38855 - event_count = atomic_read(&device_event.count);
38856 + event_count = atomic_read_unchecked(&device_event.count);
38857 if (file->f_version != event_count) {
38858 file->f_version = event_count;
38859 return POLLIN | POLLRDNORM;
38860 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38861 index 347bb05..63e1b73 100644
38862 --- a/drivers/usb/early/ehci-dbgp.c
38863 +++ b/drivers/usb/early/ehci-dbgp.c
38864 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38865
38866 #ifdef CONFIG_KGDB
38867 static struct kgdb_io kgdbdbgp_io_ops;
38868 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38869 +static struct kgdb_io kgdbdbgp_io_ops_console;
38870 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38871 #else
38872 #define dbgp_kgdb_mode (0)
38873 #endif
38874 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38875 .write_char = kgdbdbgp_write_char,
38876 };
38877
38878 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38879 + .name = "kgdbdbgp",
38880 + .read_char = kgdbdbgp_read_char,
38881 + .write_char = kgdbdbgp_write_char,
38882 + .is_console = 1
38883 +};
38884 +
38885 static int kgdbdbgp_wait_time;
38886
38887 static int __init kgdbdbgp_parse_config(char *str)
38888 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38889 ptr++;
38890 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38891 }
38892 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38893 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38894 + if (early_dbgp_console.index != -1)
38895 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38896 + else
38897 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38898
38899 return 0;
38900 }
38901 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38902 index 5b3f5ff..6e00893 100644
38903 --- a/drivers/usb/gadget/u_serial.c
38904 +++ b/drivers/usb/gadget/u_serial.c
38905 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38906 spin_lock_irq(&port->port_lock);
38907
38908 /* already open? Great. */
38909 - if (port->port.count) {
38910 + if (atomic_read(&port->port.count)) {
38911 status = 0;
38912 - port->port.count++;
38913 + atomic_inc(&port->port.count);
38914
38915 /* currently opening/closing? wait ... */
38916 } else if (port->openclose) {
38917 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38918 tty->driver_data = port;
38919 port->port.tty = tty;
38920
38921 - port->port.count = 1;
38922 + atomic_set(&port->port.count, 1);
38923 port->openclose = false;
38924
38925 /* if connected, start the I/O stream */
38926 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38927
38928 spin_lock_irq(&port->port_lock);
38929
38930 - if (port->port.count != 1) {
38931 - if (port->port.count == 0)
38932 + if (atomic_read(&port->port.count) != 1) {
38933 + if (atomic_read(&port->port.count) == 0)
38934 WARN_ON(1);
38935 else
38936 - --port->port.count;
38937 + atomic_dec(&port->port.count);
38938 goto exit;
38939 }
38940
38941 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38942 * and sleep if necessary
38943 */
38944 port->openclose = true;
38945 - port->port.count = 0;
38946 + atomic_set(&port->port.count, 0);
38947
38948 gser = port->port_usb;
38949 if (gser && gser->disconnect)
38950 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38951 int cond;
38952
38953 spin_lock_irq(&port->port_lock);
38954 - cond = (port->port.count == 0) && !port->openclose;
38955 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38956 spin_unlock_irq(&port->port_lock);
38957 return cond;
38958 }
38959 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38960 /* if it's already open, start I/O ... and notify the serial
38961 * protocol about open/close status (connect/disconnect).
38962 */
38963 - if (port->port.count) {
38964 + if (atomic_read(&port->port.count)) {
38965 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38966 gs_start_io(port);
38967 if (gser->connect)
38968 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38969
38970 port->port_usb = NULL;
38971 gser->ioport = NULL;
38972 - if (port->port.count > 0 || port->openclose) {
38973 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
38974 wake_up_interruptible(&port->drain_wait);
38975 if (port->port.tty)
38976 tty_hangup(port->port.tty);
38977 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38978
38979 /* finally, free any unused/unusable I/O buffers */
38980 spin_lock_irqsave(&port->port_lock, flags);
38981 - if (port->port.count == 0 && !port->openclose)
38982 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
38983 gs_buf_free(&port->port_write_buf);
38984 gs_free_requests(gser->out, &port->read_pool, NULL);
38985 gs_free_requests(gser->out, &port->read_queue, NULL);
38986 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38987 index b9cca6d..75c75df 100644
38988 --- a/drivers/usb/serial/console.c
38989 +++ b/drivers/usb/serial/console.c
38990 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38991
38992 info->port = port;
38993
38994 - ++port->port.count;
38995 + atomic_inc(&port->port.count);
38996 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38997 if (serial->type->set_termios) {
38998 /*
38999 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39000 }
39001 /* Now that any required fake tty operations are completed restore
39002 * the tty port count */
39003 - --port->port.count;
39004 + atomic_dec(&port->port.count);
39005 /* The console is special in terms of closing the device so
39006 * indicate this port is now acting as a system console. */
39007 port->port.console = 1;
39008 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39009 free_tty:
39010 kfree(tty);
39011 reset_open_count:
39012 - port->port.count = 0;
39013 + atomic_set(&port->port.count, 0);
39014 usb_autopm_put_interface(serial->interface);
39015 error_get_interface:
39016 usb_serial_put(serial);
39017 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39018 index d6bea3e..60b250e 100644
39019 --- a/drivers/usb/wusbcore/wa-hc.h
39020 +++ b/drivers/usb/wusbcore/wa-hc.h
39021 @@ -192,7 +192,7 @@ struct wahc {
39022 struct list_head xfer_delayed_list;
39023 spinlock_t xfer_list_lock;
39024 struct work_struct xfer_work;
39025 - atomic_t xfer_id_count;
39026 + atomic_unchecked_t xfer_id_count;
39027 };
39028
39029
39030 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39031 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39032 spin_lock_init(&wa->xfer_list_lock);
39033 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39034 - atomic_set(&wa->xfer_id_count, 1);
39035 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39036 }
39037
39038 /**
39039 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39040 index 57c01ab..8a05959 100644
39041 --- a/drivers/usb/wusbcore/wa-xfer.c
39042 +++ b/drivers/usb/wusbcore/wa-xfer.c
39043 @@ -296,7 +296,7 @@ out:
39044 */
39045 static void wa_xfer_id_init(struct wa_xfer *xfer)
39046 {
39047 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39048 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39049 }
39050
39051 /*
39052 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39053 index 112156f..eb81154 100644
39054 --- a/drivers/vhost/vhost.c
39055 +++ b/drivers/vhost/vhost.c
39056 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39057 return 0;
39058 }
39059
39060 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39061 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39062 {
39063 struct file *eventfp, *filep = NULL,
39064 *pollstart = NULL, *pollstop = NULL;
39065 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39066 index b0b2ac3..89a4399 100644
39067 --- a/drivers/video/aty/aty128fb.c
39068 +++ b/drivers/video/aty/aty128fb.c
39069 @@ -148,7 +148,7 @@ enum {
39070 };
39071
39072 /* Must match above enum */
39073 -static const char *r128_family[] __devinitdata = {
39074 +static const char *r128_family[] __devinitconst = {
39075 "AGP",
39076 "PCI",
39077 "PRO AGP",
39078 diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
39079 index 2e471c2..f00eb3e 100644
39080 --- a/drivers/video/console/fbcon.c
39081 +++ b/drivers/video/console/fbcon.c
39082 @@ -442,7 +442,7 @@ static int __init fb_console_setup(char *this_opt)
39083
39084 while ((options = strsep(&this_opt, ",")) != NULL) {
39085 if (!strncmp(options, "font:", 5))
39086 - strcpy(fontname, options + 5);
39087 + strlcpy(fontname, options + 5, sizeof(fontname));
39088
39089 if (!strncmp(options, "scrollback:", 11)) {
39090 options += 11;
39091 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39092 index 5c3960d..15cf8fc 100644
39093 --- a/drivers/video/fbcmap.c
39094 +++ b/drivers/video/fbcmap.c
39095 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39096 rc = -ENODEV;
39097 goto out;
39098 }
39099 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39100 - !info->fbops->fb_setcmap)) {
39101 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39102 rc = -EINVAL;
39103 goto out1;
39104 }
39105 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39106 index 0dff12a..2ef47b3 100644
39107 --- a/drivers/video/fbmem.c
39108 +++ b/drivers/video/fbmem.c
39109 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39110 image->dx += image->width + 8;
39111 }
39112 } else if (rotate == FB_ROTATE_UD) {
39113 - for (x = 0; x < num && image->dx >= 0; x++) {
39114 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39115 info->fbops->fb_imageblit(info, image);
39116 image->dx -= image->width + 8;
39117 }
39118 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39119 image->dy += image->height + 8;
39120 }
39121 } else if (rotate == FB_ROTATE_CCW) {
39122 - for (x = 0; x < num && image->dy >= 0; x++) {
39123 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39124 info->fbops->fb_imageblit(info, image);
39125 image->dy -= image->height + 8;
39126 }
39127 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39128 return -EFAULT;
39129 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39130 return -EINVAL;
39131 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39132 + if (con2fb.framebuffer >= FB_MAX)
39133 return -EINVAL;
39134 if (!registered_fb[con2fb.framebuffer])
39135 request_module("fb%d", con2fb.framebuffer);
39136 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39137 index 5a5d092..265c5ed 100644
39138 --- a/drivers/video/geode/gx1fb_core.c
39139 +++ b/drivers/video/geode/gx1fb_core.c
39140 @@ -29,7 +29,7 @@ static int crt_option = 1;
39141 static char panel_option[32] = "";
39142
39143 /* Modes relevant to the GX1 (taken from modedb.c) */
39144 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39145 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39146 /* 640x480-60 VESA */
39147 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39148 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39149 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39150 index 0fad23f..0e9afa4 100644
39151 --- a/drivers/video/gxt4500.c
39152 +++ b/drivers/video/gxt4500.c
39153 @@ -156,7 +156,7 @@ struct gxt4500_par {
39154 static char *mode_option;
39155
39156 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39157 -static const struct fb_videomode defaultmode __devinitdata = {
39158 +static const struct fb_videomode defaultmode __devinitconst = {
39159 .refresh = 60,
39160 .xres = 1280,
39161 .yres = 1024,
39162 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39163 return 0;
39164 }
39165
39166 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39167 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39168 .id = "IBM GXT4500P",
39169 .type = FB_TYPE_PACKED_PIXELS,
39170 .visual = FB_VISUAL_PSEUDOCOLOR,
39171 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39172 index 7672d2e..b56437f 100644
39173 --- a/drivers/video/i810/i810_accel.c
39174 +++ b/drivers/video/i810/i810_accel.c
39175 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39176 }
39177 }
39178 printk("ringbuffer lockup!!!\n");
39179 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39180 i810_report_error(mmio);
39181 par->dev_flags |= LOCKUP;
39182 info->pixmap.scan_align = 1;
39183 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39184 index b83f361..2b05a91 100644
39185 --- a/drivers/video/i810/i810_main.c
39186 +++ b/drivers/video/i810/i810_main.c
39187 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39188 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39189
39190 /* PCI */
39191 -static const char *i810_pci_list[] __devinitdata = {
39192 +static const char *i810_pci_list[] __devinitconst = {
39193 "Intel(R) 810 Framebuffer Device" ,
39194 "Intel(R) 810-DC100 Framebuffer Device" ,
39195 "Intel(R) 810E Framebuffer Device" ,
39196 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39197 index de36693..3c63fc2 100644
39198 --- a/drivers/video/jz4740_fb.c
39199 +++ b/drivers/video/jz4740_fb.c
39200 @@ -136,7 +136,7 @@ struct jzfb {
39201 uint32_t pseudo_palette[16];
39202 };
39203
39204 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39205 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39206 .id = "JZ4740 FB",
39207 .type = FB_TYPE_PACKED_PIXELS,
39208 .visual = FB_VISUAL_TRUECOLOR,
39209 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39210 index 3c14e43..eafa544 100644
39211 --- a/drivers/video/logo/logo_linux_clut224.ppm
39212 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39213 @@ -1,1604 +1,1123 @@
39214 P3
39215 -# Standard 224-color Linux logo
39216 80 80
39217 255
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 0 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 6 6 6 6 6 6 10 10 10 10 10 10
39228 - 10 10 10 6 6 6 6 6 6 6 6 6
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 0 0 0 0 0 0 0 0 0 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 6 6 6 10 10 10 14 14 14
39247 - 22 22 22 26 26 26 30 30 30 34 34 34
39248 - 30 30 30 30 30 30 26 26 26 18 18 18
39249 - 14 14 14 10 10 10 6 6 6 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 0 0 0 0 0 0 0 0 0 0 0 0
39256 - 0 0 0 0 0 0 0 0 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 1 0 0 1 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 6 6 6 14 14 14 26 26 26 42 42 42
39267 - 54 54 54 66 66 66 78 78 78 78 78 78
39268 - 78 78 78 74 74 74 66 66 66 54 54 54
39269 - 42 42 42 26 26 26 18 18 18 10 10 10
39270 - 6 6 6 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 0 0 0 0 0 0 0 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 1 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 10 10 10
39286 - 22 22 22 42 42 42 66 66 66 86 86 86
39287 - 66 66 66 38 38 38 38 38 38 22 22 22
39288 - 26 26 26 34 34 34 54 54 54 66 66 66
39289 - 86 86 86 70 70 70 46 46 46 26 26 26
39290 - 14 14 14 6 6 6 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
39296 - 0 0 0 0 0 0 0 0 0 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 1 0 0 1 0 0 1 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 10 10 10 26 26 26
39306 - 50 50 50 82 82 82 58 58 58 6 6 6
39307 - 2 2 6 2 2 6 2 2 6 2 2 6
39308 - 2 2 6 2 2 6 2 2 6 2 2 6
39309 - 6 6 6 54 54 54 86 86 86 66 66 66
39310 - 38 38 38 18 18 18 6 6 6 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 0 0 0
39315 - 0 0 0 0 0 0 0 0 0 0 0 0
39316 - 0 0 0 0 0 0 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 6 6 6 22 22 22 50 50 50
39326 - 78 78 78 34 34 34 2 2 6 2 2 6
39327 - 2 2 6 2 2 6 2 2 6 2 2 6
39328 - 2 2 6 2 2 6 2 2 6 2 2 6
39329 - 2 2 6 2 2 6 6 6 6 70 70 70
39330 - 78 78 78 46 46 46 22 22 22 6 6 6
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 0 0 0
39335 - 0 0 0 0 0 0 0 0 0 0 0 0
39336 - 0 0 0 0 0 0 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 1 0 0 1 0 0 1 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 0 0 0
39343 - 0 0 0 0 0 0 0 0 0 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 6 6 6 18 18 18 42 42 42 82 82 82
39346 - 26 26 26 2 2 6 2 2 6 2 2 6
39347 - 2 2 6 2 2 6 2 2 6 2 2 6
39348 - 2 2 6 2 2 6 2 2 6 14 14 14
39349 - 46 46 46 34 34 34 6 6 6 2 2 6
39350 - 42 42 42 78 78 78 42 42 42 18 18 18
39351 - 6 6 6 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 0 0 0
39355 - 0 0 0 0 0 0 0 0 0 0 0 0
39356 - 0 0 0 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 1 0 0 0 0 0 1 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 0 0 0
39363 - 0 0 0 0 0 0 0 0 0 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 10 10 10 30 30 30 66 66 66 58 58 58
39366 - 2 2 6 2 2 6 2 2 6 2 2 6
39367 - 2 2 6 2 2 6 2 2 6 2 2 6
39368 - 2 2 6 2 2 6 2 2 6 26 26 26
39369 - 86 86 86 101 101 101 46 46 46 10 10 10
39370 - 2 2 6 58 58 58 70 70 70 34 34 34
39371 - 10 10 10 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 0 0 0
39375 - 0 0 0 0 0 0 0 0 0 0 0 0
39376 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 1 0 0 1 0 0 1 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 0 0 0
39383 - 0 0 0 0 0 0 0 0 0 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 14 14 14 42 42 42 86 86 86 10 10 10
39386 - 2 2 6 2 2 6 2 2 6 2 2 6
39387 - 2 2 6 2 2 6 2 2 6 2 2 6
39388 - 2 2 6 2 2 6 2 2 6 30 30 30
39389 - 94 94 94 94 94 94 58 58 58 26 26 26
39390 - 2 2 6 6 6 6 78 78 78 54 54 54
39391 - 22 22 22 6 6 6 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 0 0 0
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 6 6 6
39405 - 22 22 22 62 62 62 62 62 62 2 2 6
39406 - 2 2 6 2 2 6 2 2 6 2 2 6
39407 - 2 2 6 2 2 6 2 2 6 2 2 6
39408 - 2 2 6 2 2 6 2 2 6 26 26 26
39409 - 54 54 54 38 38 38 18 18 18 10 10 10
39410 - 2 2 6 2 2 6 34 34 34 82 82 82
39411 - 38 38 38 14 14 14 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 0 0 0
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 1 0 0 1 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 6 6 6
39425 - 30 30 30 78 78 78 30 30 30 2 2 6
39426 - 2 2 6 2 2 6 2 2 6 2 2 6
39427 - 2 2 6 2 2 6 2 2 6 2 2 6
39428 - 2 2 6 2 2 6 2 2 6 10 10 10
39429 - 10 10 10 2 2 6 2 2 6 2 2 6
39430 - 2 2 6 2 2 6 2 2 6 78 78 78
39431 - 50 50 50 18 18 18 6 6 6 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 0 0 0 0 0 0
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 1 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 10 10 10
39445 - 38 38 38 86 86 86 14 14 14 2 2 6
39446 - 2 2 6 2 2 6 2 2 6 2 2 6
39447 - 2 2 6 2 2 6 2 2 6 2 2 6
39448 - 2 2 6 2 2 6 2 2 6 2 2 6
39449 - 2 2 6 2 2 6 2 2 6 2 2 6
39450 - 2 2 6 2 2 6 2 2 6 54 54 54
39451 - 66 66 66 26 26 26 6 6 6 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 0 0 0
39454 - 0 0 0 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 0 0 0 0 0 0 0 0 0
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 1 0 0 1 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 14 14 14
39465 - 42 42 42 82 82 82 2 2 6 2 2 6
39466 - 2 2 6 6 6 6 10 10 10 2 2 6
39467 - 2 2 6 2 2 6 2 2 6 2 2 6
39468 - 2 2 6 2 2 6 2 2 6 6 6 6
39469 - 14 14 14 10 10 10 2 2 6 2 2 6
39470 - 2 2 6 2 2 6 2 2 6 18 18 18
39471 - 82 82 82 34 34 34 10 10 10 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 0 0 0 0
39475 - 0 0 0 0 0 0 0 0 0 0 0 0
39476 - 0 0 0 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 1 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 14 14 14
39485 - 46 46 46 86 86 86 2 2 6 2 2 6
39486 - 6 6 6 6 6 6 22 22 22 34 34 34
39487 - 6 6 6 2 2 6 2 2 6 2 2 6
39488 - 2 2 6 2 2 6 18 18 18 34 34 34
39489 - 10 10 10 50 50 50 22 22 22 2 2 6
39490 - 2 2 6 2 2 6 2 2 6 10 10 10
39491 - 86 86 86 42 42 42 14 14 14 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 0 0 0
39494 - 0 0 0 0 0 0 0 0 0 0 0 0
39495 - 0 0 0 0 0 0 0 0 0 0 0 0
39496 - 0 0 0 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 1 0 0 1 0 0 1 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 14 14 14
39505 - 46 46 46 86 86 86 2 2 6 2 2 6
39506 - 38 38 38 116 116 116 94 94 94 22 22 22
39507 - 22 22 22 2 2 6 2 2 6 2 2 6
39508 - 14 14 14 86 86 86 138 138 138 162 162 162
39509 -154 154 154 38 38 38 26 26 26 6 6 6
39510 - 2 2 6 2 2 6 2 2 6 2 2 6
39511 - 86 86 86 46 46 46 14 14 14 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 0 0 0 0
39515 - 0 0 0 0 0 0 0 0 0 0 0 0
39516 - 0 0 0 0 0 0 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 14 14 14
39525 - 46 46 46 86 86 86 2 2 6 14 14 14
39526 -134 134 134 198 198 198 195 195 195 116 116 116
39527 - 10 10 10 2 2 6 2 2 6 6 6 6
39528 -101 98 89 187 187 187 210 210 210 218 218 218
39529 -214 214 214 134 134 134 14 14 14 6 6 6
39530 - 2 2 6 2 2 6 2 2 6 2 2 6
39531 - 86 86 86 50 50 50 18 18 18 6 6 6
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 1 0 0 0
39539 - 0 0 1 0 0 1 0 0 1 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 14 14 14
39545 - 46 46 46 86 86 86 2 2 6 54 54 54
39546 -218 218 218 195 195 195 226 226 226 246 246 246
39547 - 58 58 58 2 2 6 2 2 6 30 30 30
39548 -210 210 210 253 253 253 174 174 174 123 123 123
39549 -221 221 221 234 234 234 74 74 74 2 2 6
39550 - 2 2 6 2 2 6 2 2 6 2 2 6
39551 - 70 70 70 58 58 58 22 22 22 6 6 6
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 14 14 14
39565 - 46 46 46 82 82 82 2 2 6 106 106 106
39566 -170 170 170 26 26 26 86 86 86 226 226 226
39567 -123 123 123 10 10 10 14 14 14 46 46 46
39568 -231 231 231 190 190 190 6 6 6 70 70 70
39569 - 90 90 90 238 238 238 158 158 158 2 2 6
39570 - 2 2 6 2 2 6 2 2 6 2 2 6
39571 - 70 70 70 58 58 58 22 22 22 6 6 6
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 1 0 0 0
39579 - 0 0 1 0 0 1 0 0 1 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 14 14 14
39585 - 42 42 42 86 86 86 6 6 6 116 116 116
39586 -106 106 106 6 6 6 70 70 70 149 149 149
39587 -128 128 128 18 18 18 38 38 38 54 54 54
39588 -221 221 221 106 106 106 2 2 6 14 14 14
39589 - 46 46 46 190 190 190 198 198 198 2 2 6
39590 - 2 2 6 2 2 6 2 2 6 2 2 6
39591 - 74 74 74 62 62 62 22 22 22 6 6 6
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 1 0 0 0
39599 - 0 0 1 0 0 0 0 0 1 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 14 14 14
39605 - 42 42 42 94 94 94 14 14 14 101 101 101
39606 -128 128 128 2 2 6 18 18 18 116 116 116
39607 -118 98 46 121 92 8 121 92 8 98 78 10
39608 -162 162 162 106 106 106 2 2 6 2 2 6
39609 - 2 2 6 195 195 195 195 195 195 6 6 6
39610 - 2 2 6 2 2 6 2 2 6 2 2 6
39611 - 74 74 74 62 62 62 22 22 22 6 6 6
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 1 0 0 1
39619 - 0 0 1 0 0 0 0 0 1 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 10 10 10
39625 - 38 38 38 90 90 90 14 14 14 58 58 58
39626 -210 210 210 26 26 26 54 38 6 154 114 10
39627 -226 170 11 236 186 11 225 175 15 184 144 12
39628 -215 174 15 175 146 61 37 26 9 2 2 6
39629 - 70 70 70 246 246 246 138 138 138 2 2 6
39630 - 2 2 6 2 2 6 2 2 6 2 2 6
39631 - 70 70 70 66 66 66 26 26 26 6 6 6
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 10 10 10
39645 - 38 38 38 86 86 86 14 14 14 10 10 10
39646 -195 195 195 188 164 115 192 133 9 225 175 15
39647 -239 182 13 234 190 10 232 195 16 232 200 30
39648 -245 207 45 241 208 19 232 195 16 184 144 12
39649 -218 194 134 211 206 186 42 42 42 2 2 6
39650 - 2 2 6 2 2 6 2 2 6 2 2 6
39651 - 50 50 50 74 74 74 30 30 30 6 6 6
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 10 10 10
39665 - 34 34 34 86 86 86 14 14 14 2 2 6
39666 -121 87 25 192 133 9 219 162 10 239 182 13
39667 -236 186 11 232 195 16 241 208 19 244 214 54
39668 -246 218 60 246 218 38 246 215 20 241 208 19
39669 -241 208 19 226 184 13 121 87 25 2 2 6
39670 - 2 2 6 2 2 6 2 2 6 2 2 6
39671 - 50 50 50 82 82 82 34 34 34 10 10 10
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 10 10 10
39685 - 34 34 34 82 82 82 30 30 30 61 42 6
39686 -180 123 7 206 145 10 230 174 11 239 182 13
39687 -234 190 10 238 202 15 241 208 19 246 218 74
39688 -246 218 38 246 215 20 246 215 20 246 215 20
39689 -226 184 13 215 174 15 184 144 12 6 6 6
39690 - 2 2 6 2 2 6 2 2 6 2 2 6
39691 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 10 10 10
39705 - 30 30 30 78 78 78 50 50 50 104 69 6
39706 -192 133 9 216 158 10 236 178 12 236 186 11
39707 -232 195 16 241 208 19 244 214 54 245 215 43
39708 -246 215 20 246 215 20 241 208 19 198 155 10
39709 -200 144 11 216 158 10 156 118 10 2 2 6
39710 - 2 2 6 2 2 6 2 2 6 2 2 6
39711 - 6 6 6 90 90 90 54 54 54 18 18 18
39712 - 6 6 6 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 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 10 10 10
39725 - 30 30 30 78 78 78 46 46 46 22 22 22
39726 -137 92 6 210 162 10 239 182 13 238 190 10
39727 -238 202 15 241 208 19 246 215 20 246 215 20
39728 -241 208 19 203 166 17 185 133 11 210 150 10
39729 -216 158 10 210 150 10 102 78 10 2 2 6
39730 - 6 6 6 54 54 54 14 14 14 2 2 6
39731 - 2 2 6 62 62 62 74 74 74 30 30 30
39732 - 10 10 10 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 0 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 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 10 10 10
39745 - 34 34 34 78 78 78 50 50 50 6 6 6
39746 - 94 70 30 139 102 15 190 146 13 226 184 13
39747 -232 200 30 232 195 16 215 174 15 190 146 13
39748 -168 122 10 192 133 9 210 150 10 213 154 11
39749 -202 150 34 182 157 106 101 98 89 2 2 6
39750 - 2 2 6 78 78 78 116 116 116 58 58 58
39751 - 2 2 6 22 22 22 90 90 90 46 46 46
39752 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 10 10 10
39765 - 38 38 38 86 86 86 50 50 50 6 6 6
39766 -128 128 128 174 154 114 156 107 11 168 122 10
39767 -198 155 10 184 144 12 197 138 11 200 144 11
39768 -206 145 10 206 145 10 197 138 11 188 164 115
39769 -195 195 195 198 198 198 174 174 174 14 14 14
39770 - 2 2 6 22 22 22 116 116 116 116 116 116
39771 - 22 22 22 2 2 6 74 74 74 70 70 70
39772 - 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 6 6 6 18 18 18
39785 - 50 50 50 101 101 101 26 26 26 10 10 10
39786 -138 138 138 190 190 190 174 154 114 156 107 11
39787 -197 138 11 200 144 11 197 138 11 192 133 9
39788 -180 123 7 190 142 34 190 178 144 187 187 187
39789 -202 202 202 221 221 221 214 214 214 66 66 66
39790 - 2 2 6 2 2 6 50 50 50 62 62 62
39791 - 6 6 6 2 2 6 10 10 10 90 90 90
39792 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 10 10 10 34 34 34
39805 - 74 74 74 74 74 74 2 2 6 6 6 6
39806 -144 144 144 198 198 198 190 190 190 178 166 146
39807 -154 121 60 156 107 11 156 107 11 168 124 44
39808 -174 154 114 187 187 187 190 190 190 210 210 210
39809 -246 246 246 253 253 253 253 253 253 182 182 182
39810 - 6 6 6 2 2 6 2 2 6 2 2 6
39811 - 2 2 6 2 2 6 2 2 6 62 62 62
39812 - 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 10 10 10 22 22 22 54 54 54
39825 - 94 94 94 18 18 18 2 2 6 46 46 46
39826 -234 234 234 221 221 221 190 190 190 190 190 190
39827 -190 190 190 187 187 187 187 187 187 190 190 190
39828 -190 190 190 195 195 195 214 214 214 242 242 242
39829 -253 253 253 253 253 253 253 253 253 253 253 253
39830 - 82 82 82 2 2 6 2 2 6 2 2 6
39831 - 2 2 6 2 2 6 2 2 6 14 14 14
39832 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 6 6 6 18 18 18 46 46 46 90 90 90
39845 - 46 46 46 18 18 18 6 6 6 182 182 182
39846 -253 253 253 246 246 246 206 206 206 190 190 190
39847 -190 190 190 190 190 190 190 190 190 190 190 190
39848 -206 206 206 231 231 231 250 250 250 253 253 253
39849 -253 253 253 253 253 253 253 253 253 253 253 253
39850 -202 202 202 14 14 14 2 2 6 2 2 6
39851 - 2 2 6 2 2 6 2 2 6 2 2 6
39852 - 42 42 42 86 86 86 42 42 42 18 18 18
39853 - 6 6 6 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 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 6 6 6
39864 - 14 14 14 38 38 38 74 74 74 66 66 66
39865 - 2 2 6 6 6 6 90 90 90 250 250 250
39866 -253 253 253 253 253 253 238 238 238 198 198 198
39867 -190 190 190 190 190 190 195 195 195 221 221 221
39868 -246 246 246 253 253 253 253 253 253 253 253 253
39869 -253 253 253 253 253 253 253 253 253 253 253 253
39870 -253 253 253 82 82 82 2 2 6 2 2 6
39871 - 2 2 6 2 2 6 2 2 6 2 2 6
39872 - 2 2 6 78 78 78 70 70 70 34 34 34
39873 - 14 14 14 6 6 6 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 0 0 0 0 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 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 14 14 14
39884 - 34 34 34 66 66 66 78 78 78 6 6 6
39885 - 2 2 6 18 18 18 218 218 218 253 253 253
39886 -253 253 253 253 253 253 253 253 253 246 246 246
39887 -226 226 226 231 231 231 246 246 246 253 253 253
39888 -253 253 253 253 253 253 253 253 253 253 253 253
39889 -253 253 253 253 253 253 253 253 253 253 253 253
39890 -253 253 253 178 178 178 2 2 6 2 2 6
39891 - 2 2 6 2 2 6 2 2 6 2 2 6
39892 - 2 2 6 18 18 18 90 90 90 62 62 62
39893 - 30 30 30 10 10 10 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 0 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 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 10 10 10 26 26 26
39904 - 58 58 58 90 90 90 18 18 18 2 2 6
39905 - 2 2 6 110 110 110 253 253 253 253 253 253
39906 -253 253 253 253 253 253 253 253 253 253 253 253
39907 -250 250 250 253 253 253 253 253 253 253 253 253
39908 -253 253 253 253 253 253 253 253 253 253 253 253
39909 -253 253 253 253 253 253 253 253 253 253 253 253
39910 -253 253 253 231 231 231 18 18 18 2 2 6
39911 - 2 2 6 2 2 6 2 2 6 2 2 6
39912 - 2 2 6 2 2 6 18 18 18 94 94 94
39913 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 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 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 6 6 6 22 22 22 50 50 50
39924 - 90 90 90 26 26 26 2 2 6 2 2 6
39925 - 14 14 14 195 195 195 250 250 250 253 253 253
39926 -253 253 253 253 253 253 253 253 253 253 253 253
39927 -253 253 253 253 253 253 253 253 253 253 253 253
39928 -253 253 253 253 253 253 253 253 253 253 253 253
39929 -253 253 253 253 253 253 253 253 253 253 253 253
39930 -250 250 250 242 242 242 54 54 54 2 2 6
39931 - 2 2 6 2 2 6 2 2 6 2 2 6
39932 - 2 2 6 2 2 6 2 2 6 38 38 38
39933 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 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 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 6 6 6 14 14 14 38 38 38 82 82 82
39944 - 34 34 34 2 2 6 2 2 6 2 2 6
39945 - 42 42 42 195 195 195 246 246 246 253 253 253
39946 -253 253 253 253 253 253 253 253 253 250 250 250
39947 -242 242 242 242 242 242 250 250 250 253 253 253
39948 -253 253 253 253 253 253 253 253 253 253 253 253
39949 -253 253 253 250 250 250 246 246 246 238 238 238
39950 -226 226 226 231 231 231 101 101 101 6 6 6
39951 - 2 2 6 2 2 6 2 2 6 2 2 6
39952 - 2 2 6 2 2 6 2 2 6 2 2 6
39953 - 38 38 38 82 82 82 42 42 42 14 14 14
39954 - 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 10 10 10 26 26 26 62 62 62 66 66 66
39964 - 2 2 6 2 2 6 2 2 6 6 6 6
39965 - 70 70 70 170 170 170 206 206 206 234 234 234
39966 -246 246 246 250 250 250 250 250 250 238 238 238
39967 -226 226 226 231 231 231 238 238 238 250 250 250
39968 -250 250 250 250 250 250 246 246 246 231 231 231
39969 -214 214 214 206 206 206 202 202 202 202 202 202
39970 -198 198 198 202 202 202 182 182 182 18 18 18
39971 - 2 2 6 2 2 6 2 2 6 2 2 6
39972 - 2 2 6 2 2 6 2 2 6 2 2 6
39973 - 2 2 6 62 62 62 66 66 66 30 30 30
39974 - 10 10 10 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 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 14 14 14 42 42 42 82 82 82 18 18 18
39984 - 2 2 6 2 2 6 2 2 6 10 10 10
39985 - 94 94 94 182 182 182 218 218 218 242 242 242
39986 -250 250 250 253 253 253 253 253 253 250 250 250
39987 -234 234 234 253 253 253 253 253 253 253 253 253
39988 -253 253 253 253 253 253 253 253 253 246 246 246
39989 -238 238 238 226 226 226 210 210 210 202 202 202
39990 -195 195 195 195 195 195 210 210 210 158 158 158
39991 - 6 6 6 14 14 14 50 50 50 14 14 14
39992 - 2 2 6 2 2 6 2 2 6 2 2 6
39993 - 2 2 6 6 6 6 86 86 86 46 46 46
39994 - 18 18 18 6 6 6 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 6 6 6
40003 - 22 22 22 54 54 54 70 70 70 2 2 6
40004 - 2 2 6 10 10 10 2 2 6 22 22 22
40005 -166 166 166 231 231 231 250 250 250 253 253 253
40006 -253 253 253 253 253 253 253 253 253 250 250 250
40007 -242 242 242 253 253 253 253 253 253 253 253 253
40008 -253 253 253 253 253 253 253 253 253 253 253 253
40009 -253 253 253 253 253 253 253 253 253 246 246 246
40010 -231 231 231 206 206 206 198 198 198 226 226 226
40011 - 94 94 94 2 2 6 6 6 6 38 38 38
40012 - 30 30 30 2 2 6 2 2 6 2 2 6
40013 - 2 2 6 2 2 6 62 62 62 66 66 66
40014 - 26 26 26 10 10 10 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 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 10 10 10
40023 - 30 30 30 74 74 74 50 50 50 2 2 6
40024 - 26 26 26 26 26 26 2 2 6 106 106 106
40025 -238 238 238 253 253 253 253 253 253 253 253 253
40026 -253 253 253 253 253 253 253 253 253 253 253 253
40027 -253 253 253 253 253 253 253 253 253 253 253 253
40028 -253 253 253 253 253 253 253 253 253 253 253 253
40029 -253 253 253 253 253 253 253 253 253 253 253 253
40030 -253 253 253 246 246 246 218 218 218 202 202 202
40031 -210 210 210 14 14 14 2 2 6 2 2 6
40032 - 30 30 30 22 22 22 2 2 6 2 2 6
40033 - 2 2 6 2 2 6 18 18 18 86 86 86
40034 - 42 42 42 14 14 14 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 14 14 14
40043 - 42 42 42 90 90 90 22 22 22 2 2 6
40044 - 42 42 42 2 2 6 18 18 18 218 218 218
40045 -253 253 253 253 253 253 253 253 253 253 253 253
40046 -253 253 253 253 253 253 253 253 253 253 253 253
40047 -253 253 253 253 253 253 253 253 253 253 253 253
40048 -253 253 253 253 253 253 253 253 253 253 253 253
40049 -253 253 253 253 253 253 253 253 253 253 253 253
40050 -253 253 253 253 253 253 250 250 250 221 221 221
40051 -218 218 218 101 101 101 2 2 6 14 14 14
40052 - 18 18 18 38 38 38 10 10 10 2 2 6
40053 - 2 2 6 2 2 6 2 2 6 78 78 78
40054 - 58 58 58 22 22 22 6 6 6 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40062 - 0 0 0 0 0 0 6 6 6 18 18 18
40063 - 54 54 54 82 82 82 2 2 6 26 26 26
40064 - 22 22 22 2 2 6 123 123 123 253 253 253
40065 -253 253 253 253 253 253 253 253 253 253 253 253
40066 -253 253 253 253 253 253 253 253 253 253 253 253
40067 -253 253 253 253 253 253 253 253 253 253 253 253
40068 -253 253 253 253 253 253 253 253 253 253 253 253
40069 -253 253 253 253 253 253 253 253 253 253 253 253
40070 -253 253 253 253 253 253 253 253 253 250 250 250
40071 -238 238 238 198 198 198 6 6 6 38 38 38
40072 - 58 58 58 26 26 26 38 38 38 2 2 6
40073 - 2 2 6 2 2 6 2 2 6 46 46 46
40074 - 78 78 78 30 30 30 10 10 10 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40082 - 0 0 0 0 0 0 10 10 10 30 30 30
40083 - 74 74 74 58 58 58 2 2 6 42 42 42
40084 - 2 2 6 22 22 22 231 231 231 253 253 253
40085 -253 253 253 253 253 253 253 253 253 253 253 253
40086 -253 253 253 253 253 253 253 253 253 250 250 250
40087 -253 253 253 253 253 253 253 253 253 253 253 253
40088 -253 253 253 253 253 253 253 253 253 253 253 253
40089 -253 253 253 253 253 253 253 253 253 253 253 253
40090 -253 253 253 253 253 253 253 253 253 253 253 253
40091 -253 253 253 246 246 246 46 46 46 38 38 38
40092 - 42 42 42 14 14 14 38 38 38 14 14 14
40093 - 2 2 6 2 2 6 2 2 6 6 6 6
40094 - 86 86 86 46 46 46 14 14 14 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 0 0 0
40102 - 0 0 0 6 6 6 14 14 14 42 42 42
40103 - 90 90 90 18 18 18 18 18 18 26 26 26
40104 - 2 2 6 116 116 116 253 253 253 253 253 253
40105 -253 253 253 253 253 253 253 253 253 253 253 253
40106 -253 253 253 253 253 253 250 250 250 238 238 238
40107 -253 253 253 253 253 253 253 253 253 253 253 253
40108 -253 253 253 253 253 253 253 253 253 253 253 253
40109 -253 253 253 253 253 253 253 253 253 253 253 253
40110 -253 253 253 253 253 253 253 253 253 253 253 253
40111 -253 253 253 253 253 253 94 94 94 6 6 6
40112 - 2 2 6 2 2 6 10 10 10 34 34 34
40113 - 2 2 6 2 2 6 2 2 6 2 2 6
40114 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
40122 - 0 0 0 10 10 10 26 26 26 66 66 66
40123 - 82 82 82 2 2 6 38 38 38 6 6 6
40124 - 14 14 14 210 210 210 253 253 253 253 253 253
40125 -253 253 253 253 253 253 253 253 253 253 253 253
40126 -253 253 253 253 253 253 246 246 246 242 242 242
40127 -253 253 253 253 253 253 253 253 253 253 253 253
40128 -253 253 253 253 253 253 253 253 253 253 253 253
40129 -253 253 253 253 253 253 253 253 253 253 253 253
40130 -253 253 253 253 253 253 253 253 253 253 253 253
40131 -253 253 253 253 253 253 144 144 144 2 2 6
40132 - 2 2 6 2 2 6 2 2 6 46 46 46
40133 - 2 2 6 2 2 6 2 2 6 2 2 6
40134 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
40142 - 6 6 6 14 14 14 42 42 42 90 90 90
40143 - 26 26 26 6 6 6 42 42 42 2 2 6
40144 - 74 74 74 250 250 250 253 253 253 253 253 253
40145 -253 253 253 253 253 253 253 253 253 253 253 253
40146 -253 253 253 253 253 253 242 242 242 242 242 242
40147 -253 253 253 253 253 253 253 253 253 253 253 253
40148 -253 253 253 253 253 253 253 253 253 253 253 253
40149 -253 253 253 253 253 253 253 253 253 253 253 253
40150 -253 253 253 253 253 253 253 253 253 253 253 253
40151 -253 253 253 253 253 253 182 182 182 2 2 6
40152 - 2 2 6 2 2 6 2 2 6 46 46 46
40153 - 2 2 6 2 2 6 2 2 6 2 2 6
40154 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
40162 - 10 10 10 26 26 26 66 66 66 82 82 82
40163 - 2 2 6 22 22 22 18 18 18 2 2 6
40164 -149 149 149 253 253 253 253 253 253 253 253 253
40165 -253 253 253 253 253 253 253 253 253 253 253 253
40166 -253 253 253 253 253 253 234 234 234 242 242 242
40167 -253 253 253 253 253 253 253 253 253 253 253 253
40168 -253 253 253 253 253 253 253 253 253 253 253 253
40169 -253 253 253 253 253 253 253 253 253 253 253 253
40170 -253 253 253 253 253 253 253 253 253 253 253 253
40171 -253 253 253 253 253 253 206 206 206 2 2 6
40172 - 2 2 6 2 2 6 2 2 6 38 38 38
40173 - 2 2 6 2 2 6 2 2 6 2 2 6
40174 - 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
40182 - 18 18 18 46 46 46 86 86 86 18 18 18
40183 - 2 2 6 34 34 34 10 10 10 6 6 6
40184 -210 210 210 253 253 253 253 253 253 253 253 253
40185 -253 253 253 253 253 253 253 253 253 253 253 253
40186 -253 253 253 253 253 253 234 234 234 242 242 242
40187 -253 253 253 253 253 253 253 253 253 253 253 253
40188 -253 253 253 253 253 253 253 253 253 253 253 253
40189 -253 253 253 253 253 253 253 253 253 253 253 253
40190 -253 253 253 253 253 253 253 253 253 253 253 253
40191 -253 253 253 253 253 253 221 221 221 6 6 6
40192 - 2 2 6 2 2 6 6 6 6 30 30 30
40193 - 2 2 6 2 2 6 2 2 6 2 2 6
40194 - 2 2 6 82 82 82 54 54 54 18 18 18
40195 - 6 6 6 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 - 26 26 26 66 66 66 62 62 62 2 2 6
40203 - 2 2 6 38 38 38 10 10 10 26 26 26
40204 -238 238 238 253 253 253 253 253 253 253 253 253
40205 -253 253 253 253 253 253 253 253 253 253 253 253
40206 -253 253 253 253 253 253 231 231 231 238 238 238
40207 -253 253 253 253 253 253 253 253 253 253 253 253
40208 -253 253 253 253 253 253 253 253 253 253 253 253
40209 -253 253 253 253 253 253 253 253 253 253 253 253
40210 -253 253 253 253 253 253 253 253 253 253 253 253
40211 -253 253 253 253 253 253 231 231 231 6 6 6
40212 - 2 2 6 2 2 6 10 10 10 30 30 30
40213 - 2 2 6 2 2 6 2 2 6 2 2 6
40214 - 2 2 6 66 66 66 58 58 58 22 22 22
40215 - 6 6 6 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 78 78 78 6 6 6 2 2 6
40223 - 2 2 6 46 46 46 14 14 14 42 42 42
40224 -246 246 246 253 253 253 253 253 253 253 253 253
40225 -253 253 253 253 253 253 253 253 253 253 253 253
40226 -253 253 253 253 253 253 231 231 231 242 242 242
40227 -253 253 253 253 253 253 253 253 253 253 253 253
40228 -253 253 253 253 253 253 253 253 253 253 253 253
40229 -253 253 253 253 253 253 253 253 253 253 253 253
40230 -253 253 253 253 253 253 253 253 253 253 253 253
40231 -253 253 253 253 253 253 234 234 234 10 10 10
40232 - 2 2 6 2 2 6 22 22 22 14 14 14
40233 - 2 2 6 2 2 6 2 2 6 2 2 6
40234 - 2 2 6 66 66 66 62 62 62 22 22 22
40235 - 6 6 6 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 74 74 74 2 2 6 2 2 6
40243 - 14 14 14 70 70 70 34 34 34 62 62 62
40244 -250 250 250 253 253 253 253 253 253 253 253 253
40245 -253 253 253 253 253 253 253 253 253 253 253 253
40246 -253 253 253 253 253 253 231 231 231 246 246 246
40247 -253 253 253 253 253 253 253 253 253 253 253 253
40248 -253 253 253 253 253 253 253 253 253 253 253 253
40249 -253 253 253 253 253 253 253 253 253 253 253 253
40250 -253 253 253 253 253 253 253 253 253 253 253 253
40251 -253 253 253 253 253 253 234 234 234 14 14 14
40252 - 2 2 6 2 2 6 30 30 30 2 2 6
40253 - 2 2 6 2 2 6 2 2 6 2 2 6
40254 - 2 2 6 66 66 66 62 62 62 22 22 22
40255 - 6 6 6 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 6 6 6 18 18 18
40262 - 54 54 54 62 62 62 2 2 6 2 2 6
40263 - 2 2 6 30 30 30 46 46 46 70 70 70
40264 -250 250 250 253 253 253 253 253 253 253 253 253
40265 -253 253 253 253 253 253 253 253 253 253 253 253
40266 -253 253 253 253 253 253 231 231 231 246 246 246
40267 -253 253 253 253 253 253 253 253 253 253 253 253
40268 -253 253 253 253 253 253 253 253 253 253 253 253
40269 -253 253 253 253 253 253 253 253 253 253 253 253
40270 -253 253 253 253 253 253 253 253 253 253 253 253
40271 -253 253 253 253 253 253 226 226 226 10 10 10
40272 - 2 2 6 6 6 6 30 30 30 2 2 6
40273 - 2 2 6 2 2 6 2 2 6 2 2 6
40274 - 2 2 6 66 66 66 58 58 58 22 22 22
40275 - 6 6 6 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 0 0 0 6 6 6 22 22 22
40282 - 58 58 58 62 62 62 2 2 6 2 2 6
40283 - 2 2 6 2 2 6 30 30 30 78 78 78
40284 -250 250 250 253 253 253 253 253 253 253 253 253
40285 -253 253 253 253 253 253 253 253 253 253 253 253
40286 -253 253 253 253 253 253 231 231 231 246 246 246
40287 -253 253 253 253 253 253 253 253 253 253 253 253
40288 -253 253 253 253 253 253 253 253 253 253 253 253
40289 -253 253 253 253 253 253 253 253 253 253 253 253
40290 -253 253 253 253 253 253 253 253 253 253 253 253
40291 -253 253 253 253 253 253 206 206 206 2 2 6
40292 - 22 22 22 34 34 34 18 14 6 22 22 22
40293 - 26 26 26 18 18 18 6 6 6 2 2 6
40294 - 2 2 6 82 82 82 54 54 54 18 18 18
40295 - 6 6 6 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 - 0 0 0 0 0 0 6 6 6 26 26 26
40302 - 62 62 62 106 106 106 74 54 14 185 133 11
40303 -210 162 10 121 92 8 6 6 6 62 62 62
40304 -238 238 238 253 253 253 253 253 253 253 253 253
40305 -253 253 253 253 253 253 253 253 253 253 253 253
40306 -253 253 253 253 253 253 231 231 231 246 246 246
40307 -253 253 253 253 253 253 253 253 253 253 253 253
40308 -253 253 253 253 253 253 253 253 253 253 253 253
40309 -253 253 253 253 253 253 253 253 253 253 253 253
40310 -253 253 253 253 253 253 253 253 253 253 253 253
40311 -253 253 253 253 253 253 158 158 158 18 18 18
40312 - 14 14 14 2 2 6 2 2 6 2 2 6
40313 - 6 6 6 18 18 18 66 66 66 38 38 38
40314 - 6 6 6 94 94 94 50 50 50 18 18 18
40315 - 6 6 6 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 - 10 10 10 10 10 10 18 18 18 38 38 38
40322 - 78 78 78 142 134 106 216 158 10 242 186 14
40323 -246 190 14 246 190 14 156 118 10 10 10 10
40324 - 90 90 90 238 238 238 253 253 253 253 253 253
40325 -253 253 253 253 253 253 253 253 253 253 253 253
40326 -253 253 253 253 253 253 231 231 231 250 250 250
40327 -253 253 253 253 253 253 253 253 253 253 253 253
40328 -253 253 253 253 253 253 253 253 253 253 253 253
40329 -253 253 253 253 253 253 253 253 253 253 253 253
40330 -253 253 253 253 253 253 253 253 253 246 230 190
40331 -238 204 91 238 204 91 181 142 44 37 26 9
40332 - 2 2 6 2 2 6 2 2 6 2 2 6
40333 - 2 2 6 2 2 6 38 38 38 46 46 46
40334 - 26 26 26 106 106 106 54 54 54 18 18 18
40335 - 6 6 6 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 6 6 6 14 14 14 22 22 22
40341 - 30 30 30 38 38 38 50 50 50 70 70 70
40342 -106 106 106 190 142 34 226 170 11 242 186 14
40343 -246 190 14 246 190 14 246 190 14 154 114 10
40344 - 6 6 6 74 74 74 226 226 226 253 253 253
40345 -253 253 253 253 253 253 253 253 253 253 253 253
40346 -253 253 253 253 253 253 231 231 231 250 250 250
40347 -253 253 253 253 253 253 253 253 253 253 253 253
40348 -253 253 253 253 253 253 253 253 253 253 253 253
40349 -253 253 253 253 253 253 253 253 253 253 253 253
40350 -253 253 253 253 253 253 253 253 253 228 184 62
40351 -241 196 14 241 208 19 232 195 16 38 30 10
40352 - 2 2 6 2 2 6 2 2 6 2 2 6
40353 - 2 2 6 6 6 6 30 30 30 26 26 26
40354 -203 166 17 154 142 90 66 66 66 26 26 26
40355 - 6 6 6 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 - 6 6 6 18 18 18 38 38 38 58 58 58
40361 - 78 78 78 86 86 86 101 101 101 123 123 123
40362 -175 146 61 210 150 10 234 174 13 246 186 14
40363 -246 190 14 246 190 14 246 190 14 238 190 10
40364 -102 78 10 2 2 6 46 46 46 198 198 198
40365 -253 253 253 253 253 253 253 253 253 253 253 253
40366 -253 253 253 253 253 253 234 234 234 242 242 242
40367 -253 253 253 253 253 253 253 253 253 253 253 253
40368 -253 253 253 253 253 253 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -253 253 253 253 253 253 253 253 253 224 178 62
40371 -242 186 14 241 196 14 210 166 10 22 18 6
40372 - 2 2 6 2 2 6 2 2 6 2 2 6
40373 - 2 2 6 2 2 6 6 6 6 121 92 8
40374 -238 202 15 232 195 16 82 82 82 34 34 34
40375 - 10 10 10 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 - 14 14 14 38 38 38 70 70 70 154 122 46
40381 -190 142 34 200 144 11 197 138 11 197 138 11
40382 -213 154 11 226 170 11 242 186 14 246 190 14
40383 -246 190 14 246 190 14 246 190 14 246 190 14
40384 -225 175 15 46 32 6 2 2 6 22 22 22
40385 -158 158 158 250 250 250 253 253 253 253 253 253
40386 -253 253 253 253 253 253 253 253 253 253 253 253
40387 -253 253 253 253 253 253 253 253 253 253 253 253
40388 -253 253 253 253 253 253 253 253 253 253 253 253
40389 -253 253 253 253 253 253 253 253 253 253 253 253
40390 -253 253 253 250 250 250 242 242 242 224 178 62
40391 -239 182 13 236 186 11 213 154 11 46 32 6
40392 - 2 2 6 2 2 6 2 2 6 2 2 6
40393 - 2 2 6 2 2 6 61 42 6 225 175 15
40394 -238 190 10 236 186 11 112 100 78 42 42 42
40395 - 14 14 14 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 6 6 6
40400 - 22 22 22 54 54 54 154 122 46 213 154 11
40401 -226 170 11 230 174 11 226 170 11 226 170 11
40402 -236 178 12 242 186 14 246 190 14 246 190 14
40403 -246 190 14 246 190 14 246 190 14 246 190 14
40404 -241 196 14 184 144 12 10 10 10 2 2 6
40405 - 6 6 6 116 116 116 242 242 242 253 253 253
40406 -253 253 253 253 253 253 253 253 253 253 253 253
40407 -253 253 253 253 253 253 253 253 253 253 253 253
40408 -253 253 253 253 253 253 253 253 253 253 253 253
40409 -253 253 253 253 253 253 253 253 253 253 253 253
40410 -253 253 253 231 231 231 198 198 198 214 170 54
40411 -236 178 12 236 178 12 210 150 10 137 92 6
40412 - 18 14 6 2 2 6 2 2 6 2 2 6
40413 - 6 6 6 70 47 6 200 144 11 236 178 12
40414 -239 182 13 239 182 13 124 112 88 58 58 58
40415 - 22 22 22 6 6 6 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 10 10 10
40420 - 30 30 30 70 70 70 180 133 36 226 170 11
40421 -239 182 13 242 186 14 242 186 14 246 186 14
40422 -246 190 14 246 190 14 246 190 14 246 190 14
40423 -246 190 14 246 190 14 246 190 14 246 190 14
40424 -246 190 14 232 195 16 98 70 6 2 2 6
40425 - 2 2 6 2 2 6 66 66 66 221 221 221
40426 -253 253 253 253 253 253 253 253 253 253 253 253
40427 -253 253 253 253 253 253 253 253 253 253 253 253
40428 -253 253 253 253 253 253 253 253 253 253 253 253
40429 -253 253 253 253 253 253 253 253 253 253 253 253
40430 -253 253 253 206 206 206 198 198 198 214 166 58
40431 -230 174 11 230 174 11 216 158 10 192 133 9
40432 -163 110 8 116 81 8 102 78 10 116 81 8
40433 -167 114 7 197 138 11 226 170 11 239 182 13
40434 -242 186 14 242 186 14 162 146 94 78 78 78
40435 - 34 34 34 14 14 14 6 6 6 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 6 6 6
40440 - 30 30 30 78 78 78 190 142 34 226 170 11
40441 -239 182 13 246 190 14 246 190 14 246 190 14
40442 -246 190 14 246 190 14 246 190 14 246 190 14
40443 -246 190 14 246 190 14 246 190 14 246 190 14
40444 -246 190 14 241 196 14 203 166 17 22 18 6
40445 - 2 2 6 2 2 6 2 2 6 38 38 38
40446 -218 218 218 253 253 253 253 253 253 253 253 253
40447 -253 253 253 253 253 253 253 253 253 253 253 253
40448 -253 253 253 253 253 253 253 253 253 253 253 253
40449 -253 253 253 253 253 253 253 253 253 253 253 253
40450 -250 250 250 206 206 206 198 198 198 202 162 69
40451 -226 170 11 236 178 12 224 166 10 210 150 10
40452 -200 144 11 197 138 11 192 133 9 197 138 11
40453 -210 150 10 226 170 11 242 186 14 246 190 14
40454 -246 190 14 246 186 14 225 175 15 124 112 88
40455 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
40460 - 30 30 30 78 78 78 174 135 50 224 166 10
40461 -239 182 13 246 190 14 246 190 14 246 190 14
40462 -246 190 14 246 190 14 246 190 14 246 190 14
40463 -246 190 14 246 190 14 246 190 14 246 190 14
40464 -246 190 14 246 190 14 241 196 14 139 102 15
40465 - 2 2 6 2 2 6 2 2 6 2 2 6
40466 - 78 78 78 250 250 250 253 253 253 253 253 253
40467 -253 253 253 253 253 253 253 253 253 253 253 253
40468 -253 253 253 253 253 253 253 253 253 253 253 253
40469 -253 253 253 253 253 253 253 253 253 253 253 253
40470 -250 250 250 214 214 214 198 198 198 190 150 46
40471 -219 162 10 236 178 12 234 174 13 224 166 10
40472 -216 158 10 213 154 11 213 154 11 216 158 10
40473 -226 170 11 239 182 13 246 190 14 246 190 14
40474 -246 190 14 246 190 14 242 186 14 206 162 42
40475 -101 101 101 58 58 58 30 30 30 14 14 14
40476 - 6 6 6 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 174 135 50 216 158 10
40481 -236 178 12 246 190 14 246 190 14 246 190 14
40482 -246 190 14 246 190 14 246 190 14 246 190 14
40483 -246 190 14 246 190 14 246 190 14 246 190 14
40484 -246 190 14 246 190 14 241 196 14 226 184 13
40485 - 61 42 6 2 2 6 2 2 6 2 2 6
40486 - 22 22 22 238 238 238 253 253 253 253 253 253
40487 -253 253 253 253 253 253 253 253 253 253 253 253
40488 -253 253 253 253 253 253 253 253 253 253 253 253
40489 -253 253 253 253 253 253 253 253 253 253 253 253
40490 -253 253 253 226 226 226 187 187 187 180 133 36
40491 -216 158 10 236 178 12 239 182 13 236 178 12
40492 -230 174 11 226 170 11 226 170 11 230 174 11
40493 -236 178 12 242 186 14 246 190 14 246 190 14
40494 -246 190 14 246 190 14 246 186 14 239 182 13
40495 -206 162 42 106 106 106 66 66 66 34 34 34
40496 - 14 14 14 6 6 6 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 6 6 6
40500 - 26 26 26 70 70 70 163 133 67 213 154 11
40501 -236 178 12 246 190 14 246 190 14 246 190 14
40502 -246 190 14 246 190 14 246 190 14 246 190 14
40503 -246 190 14 246 190 14 246 190 14 246 190 14
40504 -246 190 14 246 190 14 246 190 14 241 196 14
40505 -190 146 13 18 14 6 2 2 6 2 2 6
40506 - 46 46 46 246 246 246 253 253 253 253 253 253
40507 -253 253 253 253 253 253 253 253 253 253 253 253
40508 -253 253 253 253 253 253 253 253 253 253 253 253
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 221 221 221 86 86 86 156 107 11
40511 -216 158 10 236 178 12 242 186 14 246 186 14
40512 -242 186 14 239 182 13 239 182 13 242 186 14
40513 -242 186 14 246 186 14 246 190 14 246 190 14
40514 -246 190 14 246 190 14 246 190 14 246 190 14
40515 -242 186 14 225 175 15 142 122 72 66 66 66
40516 - 30 30 30 10 10 10 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 0 0 0 6 6 6
40520 - 26 26 26 70 70 70 163 133 67 210 150 10
40521 -236 178 12 246 190 14 246 190 14 246 190 14
40522 -246 190 14 246 190 14 246 190 14 246 190 14
40523 -246 190 14 246 190 14 246 190 14 246 190 14
40524 -246 190 14 246 190 14 246 190 14 246 190 14
40525 -232 195 16 121 92 8 34 34 34 106 106 106
40526 -221 221 221 253 253 253 253 253 253 253 253 253
40527 -253 253 253 253 253 253 253 253 253 253 253 253
40528 -253 253 253 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -242 242 242 82 82 82 18 14 6 163 110 8
40531 -216 158 10 236 178 12 242 186 14 246 190 14
40532 -246 190 14 246 190 14 246 190 14 246 190 14
40533 -246 190 14 246 190 14 246 190 14 246 190 14
40534 -246 190 14 246 190 14 246 190 14 246 190 14
40535 -246 190 14 246 190 14 242 186 14 163 133 67
40536 - 46 46 46 18 18 18 6 6 6 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 0 0 0 10 10 10
40540 - 30 30 30 78 78 78 163 133 67 210 150 10
40541 -236 178 12 246 186 14 246 190 14 246 190 14
40542 -246 190 14 246 190 14 246 190 14 246 190 14
40543 -246 190 14 246 190 14 246 190 14 246 190 14
40544 -246 190 14 246 190 14 246 190 14 246 190 14
40545 -241 196 14 215 174 15 190 178 144 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 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 218 218 218
40550 - 58 58 58 2 2 6 22 18 6 167 114 7
40551 -216 158 10 236 178 12 246 186 14 246 190 14
40552 -246 190 14 246 190 14 246 190 14 246 190 14
40553 -246 190 14 246 190 14 246 190 14 246 190 14
40554 -246 190 14 246 190 14 246 190 14 246 190 14
40555 -246 190 14 246 186 14 242 186 14 190 150 46
40556 - 54 54 54 22 22 22 6 6 6 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 0 0 0 0 0 0 14 14 14
40560 - 38 38 38 86 86 86 180 133 36 213 154 11
40561 -236 178 12 246 186 14 246 190 14 246 190 14
40562 -246 190 14 246 190 14 246 190 14 246 190 14
40563 -246 190 14 246 190 14 246 190 14 246 190 14
40564 -246 190 14 246 190 14 246 190 14 246 190 14
40565 -246 190 14 232 195 16 190 146 13 214 214 214
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 253 253 253 253 253 253
40569 -253 253 253 250 250 250 170 170 170 26 26 26
40570 - 2 2 6 2 2 6 37 26 9 163 110 8
40571 -219 162 10 239 182 13 246 186 14 246 190 14
40572 -246 190 14 246 190 14 246 190 14 246 190 14
40573 -246 190 14 246 190 14 246 190 14 246 190 14
40574 -246 190 14 246 190 14 246 190 14 246 190 14
40575 -246 186 14 236 178 12 224 166 10 142 122 72
40576 - 46 46 46 18 18 18 6 6 6 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 0 0 0 6 6 6 18 18 18
40580 - 50 50 50 109 106 95 192 133 9 224 166 10
40581 -242 186 14 246 190 14 246 190 14 246 190 14
40582 -246 190 14 246 190 14 246 190 14 246 190 14
40583 -246 190 14 246 190 14 246 190 14 246 190 14
40584 -246 190 14 246 190 14 246 190 14 246 190 14
40585 -242 186 14 226 184 13 210 162 10 142 110 46
40586 -226 226 226 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 253 253 253 253 253 253
40589 -198 198 198 66 66 66 2 2 6 2 2 6
40590 - 2 2 6 2 2 6 50 34 6 156 107 11
40591 -219 162 10 239 182 13 246 186 14 246 190 14
40592 -246 190 14 246 190 14 246 190 14 246 190 14
40593 -246 190 14 246 190 14 246 190 14 246 190 14
40594 -246 190 14 246 190 14 246 190 14 242 186 14
40595 -234 174 13 213 154 11 154 122 46 66 66 66
40596 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 6 6 6 22 22 22
40600 - 58 58 58 154 121 60 206 145 10 234 174 13
40601 -242 186 14 246 186 14 246 190 14 246 190 14
40602 -246 190 14 246 190 14 246 190 14 246 190 14
40603 -246 190 14 246 190 14 246 190 14 246 190 14
40604 -246 190 14 246 190 14 246 190 14 246 190 14
40605 -246 186 14 236 178 12 210 162 10 163 110 8
40606 - 61 42 6 138 138 138 218 218 218 250 250 250
40607 -253 253 253 253 253 253 253 253 253 250 250 250
40608 -242 242 242 210 210 210 144 144 144 66 66 66
40609 - 6 6 6 2 2 6 2 2 6 2 2 6
40610 - 2 2 6 2 2 6 61 42 6 163 110 8
40611 -216 158 10 236 178 12 246 190 14 246 190 14
40612 -246 190 14 246 190 14 246 190 14 246 190 14
40613 -246 190 14 246 190 14 246 190 14 246 190 14
40614 -246 190 14 239 182 13 230 174 11 216 158 10
40615 -190 142 34 124 112 88 70 70 70 38 38 38
40616 - 18 18 18 6 6 6 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 - 0 0 0 0 0 0 6 6 6 22 22 22
40620 - 62 62 62 168 124 44 206 145 10 224 166 10
40621 -236 178 12 239 182 13 242 186 14 242 186 14
40622 -246 186 14 246 190 14 246 190 14 246 190 14
40623 -246 190 14 246 190 14 246 190 14 246 190 14
40624 -246 190 14 246 190 14 246 190 14 246 190 14
40625 -246 190 14 236 178 12 216 158 10 175 118 6
40626 - 80 54 7 2 2 6 6 6 6 30 30 30
40627 - 54 54 54 62 62 62 50 50 50 38 38 38
40628 - 14 14 14 2 2 6 2 2 6 2 2 6
40629 - 2 2 6 2 2 6 2 2 6 2 2 6
40630 - 2 2 6 6 6 6 80 54 7 167 114 7
40631 -213 154 11 236 178 12 246 190 14 246 190 14
40632 -246 190 14 246 190 14 246 190 14 246 190 14
40633 -246 190 14 242 186 14 239 182 13 239 182 13
40634 -230 174 11 210 150 10 174 135 50 124 112 88
40635 - 82 82 82 54 54 54 34 34 34 18 18 18
40636 - 6 6 6 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 0 0 0
40639 - 0 0 0 0 0 0 6 6 6 18 18 18
40640 - 50 50 50 158 118 36 192 133 9 200 144 11
40641 -216 158 10 219 162 10 224 166 10 226 170 11
40642 -230 174 11 236 178 12 239 182 13 239 182 13
40643 -242 186 14 246 186 14 246 190 14 246 190 14
40644 -246 190 14 246 190 14 246 190 14 246 190 14
40645 -246 186 14 230 174 11 210 150 10 163 110 8
40646 -104 69 6 10 10 10 2 2 6 2 2 6
40647 - 2 2 6 2 2 6 2 2 6 2 2 6
40648 - 2 2 6 2 2 6 2 2 6 2 2 6
40649 - 2 2 6 2 2 6 2 2 6 2 2 6
40650 - 2 2 6 6 6 6 91 60 6 167 114 7
40651 -206 145 10 230 174 11 242 186 14 246 190 14
40652 -246 190 14 246 190 14 246 186 14 242 186 14
40653 -239 182 13 230 174 11 224 166 10 213 154 11
40654 -180 133 36 124 112 88 86 86 86 58 58 58
40655 - 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 14 14 14
40660 - 34 34 34 70 70 70 138 110 50 158 118 36
40661 -167 114 7 180 123 7 192 133 9 197 138 11
40662 -200 144 11 206 145 10 213 154 11 219 162 10
40663 -224 166 10 230 174 11 239 182 13 242 186 14
40664 -246 186 14 246 186 14 246 186 14 246 186 14
40665 -239 182 13 216 158 10 185 133 11 152 99 6
40666 -104 69 6 18 14 6 2 2 6 2 2 6
40667 - 2 2 6 2 2 6 2 2 6 2 2 6
40668 - 2 2 6 2 2 6 2 2 6 2 2 6
40669 - 2 2 6 2 2 6 2 2 6 2 2 6
40670 - 2 2 6 6 6 6 80 54 7 152 99 6
40671 -192 133 9 219 162 10 236 178 12 239 182 13
40672 -246 186 14 242 186 14 239 182 13 236 178 12
40673 -224 166 10 206 145 10 192 133 9 154 121 60
40674 - 94 94 94 62 62 62 42 42 42 22 22 22
40675 - 14 14 14 6 6 6 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 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 6 6 6
40680 - 18 18 18 34 34 34 58 58 58 78 78 78
40681 -101 98 89 124 112 88 142 110 46 156 107 11
40682 -163 110 8 167 114 7 175 118 6 180 123 7
40683 -185 133 11 197 138 11 210 150 10 219 162 10
40684 -226 170 11 236 178 12 236 178 12 234 174 13
40685 -219 162 10 197 138 11 163 110 8 130 83 6
40686 - 91 60 6 10 10 10 2 2 6 2 2 6
40687 - 18 18 18 38 38 38 38 38 38 38 38 38
40688 - 38 38 38 38 38 38 38 38 38 38 38 38
40689 - 38 38 38 38 38 38 26 26 26 2 2 6
40690 - 2 2 6 6 6 6 70 47 6 137 92 6
40691 -175 118 6 200 144 11 219 162 10 230 174 11
40692 -234 174 13 230 174 11 219 162 10 210 150 10
40693 -192 133 9 163 110 8 124 112 88 82 82 82
40694 - 50 50 50 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 6 6 6 14 14 14 22 22 22 34 34 34
40701 - 42 42 42 58 58 58 74 74 74 86 86 86
40702 -101 98 89 122 102 70 130 98 46 121 87 25
40703 -137 92 6 152 99 6 163 110 8 180 123 7
40704 -185 133 11 197 138 11 206 145 10 200 144 11
40705 -180 123 7 156 107 11 130 83 6 104 69 6
40706 - 50 34 6 54 54 54 110 110 110 101 98 89
40707 - 86 86 86 82 82 82 78 78 78 78 78 78
40708 - 78 78 78 78 78 78 78 78 78 78 78 78
40709 - 78 78 78 82 82 82 86 86 86 94 94 94
40710 -106 106 106 101 101 101 86 66 34 124 80 6
40711 -156 107 11 180 123 7 192 133 9 200 144 11
40712 -206 145 10 200 144 11 192 133 9 175 118 6
40713 -139 102 15 109 106 95 70 70 70 42 42 42
40714 - 22 22 22 10 10 10 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 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 6 6 6 10 10 10
40721 - 14 14 14 22 22 22 30 30 30 38 38 38
40722 - 50 50 50 62 62 62 74 74 74 90 90 90
40723 -101 98 89 112 100 78 121 87 25 124 80 6
40724 -137 92 6 152 99 6 152 99 6 152 99 6
40725 -138 86 6 124 80 6 98 70 6 86 66 30
40726 -101 98 89 82 82 82 58 58 58 46 46 46
40727 - 38 38 38 34 34 34 34 34 34 34 34 34
40728 - 34 34 34 34 34 34 34 34 34 34 34 34
40729 - 34 34 34 34 34 34 38 38 38 42 42 42
40730 - 54 54 54 82 82 82 94 86 76 91 60 6
40731 -134 86 6 156 107 11 167 114 7 175 118 6
40732 -175 118 6 167 114 7 152 99 6 121 87 25
40733 -101 98 89 62 62 62 34 34 34 18 18 18
40734 - 6 6 6 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 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 6 6 6 6 6 6 10 10 10
40742 - 18 18 18 22 22 22 30 30 30 42 42 42
40743 - 50 50 50 66 66 66 86 86 86 101 98 89
40744 -106 86 58 98 70 6 104 69 6 104 69 6
40745 -104 69 6 91 60 6 82 62 34 90 90 90
40746 - 62 62 62 38 38 38 22 22 22 14 14 14
40747 - 10 10 10 10 10 10 10 10 10 10 10 10
40748 - 10 10 10 10 10 10 6 6 6 10 10 10
40749 - 10 10 10 10 10 10 10 10 10 14 14 14
40750 - 22 22 22 42 42 42 70 70 70 89 81 66
40751 - 80 54 7 104 69 6 124 80 6 137 92 6
40752 -134 86 6 116 81 8 100 82 52 86 86 86
40753 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 0 0 0
40762 - 0 0 0 6 6 6 10 10 10 14 14 14
40763 - 18 18 18 26 26 26 38 38 38 54 54 54
40764 - 70 70 70 86 86 86 94 86 76 89 81 66
40765 - 89 81 66 86 86 86 74 74 74 50 50 50
40766 - 30 30 30 14 14 14 6 6 6 0 0 0
40767 - 0 0 0 0 0 0 0 0 0 0 0 0
40768 - 0 0 0 0 0 0 0 0 0 0 0 0
40769 - 0 0 0 0 0 0 0 0 0 0 0 0
40770 - 6 6 6 18 18 18 34 34 34 58 58 58
40771 - 82 82 82 89 81 66 89 81 66 89 81 66
40772 - 94 86 66 94 86 76 74 74 74 50 50 50
40773 - 26 26 26 14 14 14 6 6 6 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 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 0 0 0
40782 - 0 0 0 0 0 0 0 0 0 0 0 0
40783 - 6 6 6 6 6 6 14 14 14 18 18 18
40784 - 30 30 30 38 38 38 46 46 46 54 54 54
40785 - 50 50 50 42 42 42 30 30 30 18 18 18
40786 - 10 10 10 0 0 0 0 0 0 0 0 0
40787 - 0 0 0 0 0 0 0 0 0 0 0 0
40788 - 0 0 0 0 0 0 0 0 0 0 0 0
40789 - 0 0 0 0 0 0 0 0 0 0 0 0
40790 - 0 0 0 6 6 6 14 14 14 26 26 26
40791 - 38 38 38 50 50 50 58 58 58 58 58 58
40792 - 54 54 54 42 42 42 30 30 30 18 18 18
40793 - 10 10 10 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 0 0 0 0 0 0 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 0 0 0
40802 - 0 0 0 0 0 0 0 0 0 0 0 0
40803 - 0 0 0 0 0 0 0 0 0 6 6 6
40804 - 6 6 6 10 10 10 14 14 14 18 18 18
40805 - 18 18 18 14 14 14 10 10 10 6 6 6
40806 - 0 0 0 0 0 0 0 0 0 0 0 0
40807 - 0 0 0 0 0 0 0 0 0 0 0 0
40808 - 0 0 0 0 0 0 0 0 0 0 0 0
40809 - 0 0 0 0 0 0 0 0 0 0 0 0
40810 - 0 0 0 0 0 0 0 0 0 6 6 6
40811 - 14 14 14 18 18 18 22 22 22 22 22 22
40812 - 18 18 18 14 14 14 10 10 10 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40831 +4 4 4 4 4 4
40832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40845 +4 4 4 4 4 4
40846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859 +4 4 4 4 4 4
40860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40873 +4 4 4 4 4 4
40874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40887 +4 4 4 4 4 4
40888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40901 +4 4 4 4 4 4
40902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40907 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40911 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40912 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40913 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40915 +4 4 4 4 4 4
40916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40921 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40922 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40925 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40926 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40927 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40928 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40929 +4 4 4 4 4 4
40930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40934 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40935 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40936 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40939 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40940 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40941 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40942 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40943 +4 4 4 4 4 4
40944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40948 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40949 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40950 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40953 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40954 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40955 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40956 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40957 +4 4 4 4 4 4
40958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40962 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40963 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40964 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40965 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40966 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40967 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40968 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40969 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40970 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40971 +4 4 4 4 4 4
40972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40975 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40976 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40977 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40978 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40979 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40980 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40981 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40982 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40983 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40984 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40985 +4 4 4 4 4 4
40986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40988 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40989 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40990 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40991 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40992 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40993 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40994 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40995 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40996 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40997 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40998 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40999 +4 4 4 4 4 4
41000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41002 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41003 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41004 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41005 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41006 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41007 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41008 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41009 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41010 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41011 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41012 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41013 +4 4 4 4 4 4
41014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41016 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41017 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41018 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41019 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41020 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41021 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41022 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41023 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41024 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41025 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41026 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41027 +4 4 4 4 4 4
41028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41030 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41031 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41032 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41033 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41034 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41035 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41036 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41037 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41038 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41039 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41040 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41041 +4 4 4 4 4 4
41042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41043 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41044 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41045 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41046 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41047 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41048 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41049 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41050 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41051 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41052 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41053 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41054 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41055 +4 4 4 4 4 4
41056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41058 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41059 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41060 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41061 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41062 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41063 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41064 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41065 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41066 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41067 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41068 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41069 +0 0 0 4 4 4
41070 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41071 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41072 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41073 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41074 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41075 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41076 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41077 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41078 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41079 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41080 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41081 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41082 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41083 +2 0 0 0 0 0
41084 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41085 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41086 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41087 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41088 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41089 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41090 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41091 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41092 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41093 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41094 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41095 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41096 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41097 +37 38 37 0 0 0
41098 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41099 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41100 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41101 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41102 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41103 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41104 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41105 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41106 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41107 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41108 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41109 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41110 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41111 +85 115 134 4 0 0
41112 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41113 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41114 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41115 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41116 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41117 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41118 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41119 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41120 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41121 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41122 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41123 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41124 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41125 +60 73 81 4 0 0
41126 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41127 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41128 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41129 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41130 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41131 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41132 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41133 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41134 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41135 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41136 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41137 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41138 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41139 +16 19 21 4 0 0
41140 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41141 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41142 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41143 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41144 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41145 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41146 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41147 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41148 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41149 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41150 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41151 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41152 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41153 +4 0 0 4 3 3
41154 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41155 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41156 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41158 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41159 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41160 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41161 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41162 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41163 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41164 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41165 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41166 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41167 +3 2 2 4 4 4
41168 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41169 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41170 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41171 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41172 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41173 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41174 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41175 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41176 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41177 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41178 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41179 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41180 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41181 +4 4 4 4 4 4
41182 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41183 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41184 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41185 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41186 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41187 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41188 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41189 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41190 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41191 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41192 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41193 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41194 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41195 +4 4 4 4 4 4
41196 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41197 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41198 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41199 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41200 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41201 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41202 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41203 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41204 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41205 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41206 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41207 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41208 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41209 +5 5 5 5 5 5
41210 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41211 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41212 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41213 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41214 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41215 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41216 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41217 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41218 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41219 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41220 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41221 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41222 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41223 +5 5 5 4 4 4
41224 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41225 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41226 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41227 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41228 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41229 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41230 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41231 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41232 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41233 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41234 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41235 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4
41238 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41239 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41240 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41241 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41242 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41243 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41244 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41245 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41246 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41247 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41248 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41249 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4
41252 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41253 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41254 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41255 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41256 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41257 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41258 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41259 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41260 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41261 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41262 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4
41266 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41267 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41268 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41269 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41270 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41271 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41272 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41273 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41274 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41275 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41276 +6 6 6 4 0 0 4 0 0 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
41280 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41281 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41282 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41283 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41284 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41285 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41286 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41287 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41288 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41289 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41290 +4 0 0 4 3 3 5 5 5 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
41294 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41295 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41296 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41297 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41298 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41299 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41300 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41301 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41302 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41303 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41304 +6 6 6 4 0 0 6 6 6 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
41308 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41309 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41310 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41311 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41312 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41313 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41314 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41315 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41316 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41317 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41318 +4 0 0 3 2 2 5 5 5 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
41322 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41323 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41324 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41325 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41326 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41327 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41328 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41329 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41330 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41331 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41332 +4 0 0 4 3 3 5 5 5 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
41336 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41337 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41338 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41339 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41340 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41341 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41342 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41343 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41344 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41345 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41346 +4 0 0 4 3 3 5 5 5 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
41350 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41351 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41352 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41353 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41354 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41355 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41356 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41357 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41358 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41359 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41360 +4 0 0 3 3 3 5 5 5 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
41364 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41365 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41366 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41367 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41368 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41369 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41370 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41371 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41372 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41373 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41374 +0 0 0 3 3 3 5 5 5 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
41378 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41379 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41380 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41381 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41382 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41383 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41384 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41385 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41386 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41387 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41388 +0 0 0 3 3 3 5 5 5 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 +4 4 4 4 4 4
41392 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41393 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41394 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41395 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41396 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41397 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41398 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41399 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41400 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41401 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41402 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4
41406 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41407 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41408 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41409 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41410 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41411 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41412 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41413 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41414 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41415 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41416 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4
41420 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41421 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41422 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41423 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41424 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41425 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41426 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41427 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41428 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41429 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41430 +0 0 0 3 3 3 5 5 5 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 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4
41434 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41435 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41436 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41437 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41438 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41439 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41440 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41441 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41442 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41443 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41444 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4
41448 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41449 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41450 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41451 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41452 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41453 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41454 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41455 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41456 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41457 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41458 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4
41462 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41463 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41464 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41465 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41466 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41467 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41468 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41469 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41470 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41471 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41472 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4
41476 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41477 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41478 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41479 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41480 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41481 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41482 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41483 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41484 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41485 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41486 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4
41490 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41491 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41492 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41493 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41494 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41495 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41496 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41497 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41498 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41499 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41500 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4
41504 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41505 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41506 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41507 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41508 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41509 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41510 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41511 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41512 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41513 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41514 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4
41518 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41519 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41520 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41521 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41522 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41523 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41524 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41525 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41526 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41527 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41528 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4
41532 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41533 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41534 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41535 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41536 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41537 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41538 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41539 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41540 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41541 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41542 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4
41546 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41547 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41548 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41549 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41550 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41551 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41552 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41553 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41554 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41555 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41556 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4
41560 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41561 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41562 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41564 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41565 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41566 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41567 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41568 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41569 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41570 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4
41574 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41575 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41576 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41577 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41578 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41579 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41580 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41581 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41582 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41583 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41584 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4
41588 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41589 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41590 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41591 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41592 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41593 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41594 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41595 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41596 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41597 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41598 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4
41602 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41603 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41604 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41605 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41607 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41608 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41610 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41611 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41612 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4
41616 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41617 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41618 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41619 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41620 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41621 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41622 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41623 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41624 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41625 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41626 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4
41630 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41631 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41632 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41633 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41634 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41635 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41636 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41637 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41638 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41639 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4
41644 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41645 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41646 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41647 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41648 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41649 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41650 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41651 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41652 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41653 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4
41658 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41659 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41660 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41661 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41662 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41663 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41664 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41665 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41666 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41667 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4
41672 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41673 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41674 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41675 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41676 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41677 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41678 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41679 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41680 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41681 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4
41686 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41687 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41688 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41689 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41690 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41691 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41692 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41693 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41694 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4
41700 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41701 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41702 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41703 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41704 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41705 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41706 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41707 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41708 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4
41714 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41715 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41716 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41717 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41718 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41719 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41720 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41721 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41722 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4
41728 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41729 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41730 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41731 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41732 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41733 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41734 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41735 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41743 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41744 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41745 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41746 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41747 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41748 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41749 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41757 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41758 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41759 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41760 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41761 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41762 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41763 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4
41770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41772 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41773 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41774 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41775 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41776 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41777 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4
41784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41786 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41787 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41788 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41789 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41790 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41791 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4
41798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41801 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41802 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41803 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41804 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41805 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4
41812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41815 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41816 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41817 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41818 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4
41826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41830 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41831 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41832 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
41835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4
41840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41844 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41845 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41846 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4
41854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41858 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41859 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41860 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4
41868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41872 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41873 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41874 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881 +4 4 4 4 4 4
41882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41887 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41888 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895 +4 4 4 4 4 4
41896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41901 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41902 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41909 +4 4 4 4 4 4
41910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41915 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +4 4 4 4 4 4
41924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41929 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +4 4 4 4 4 4
41938 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41939 index 8af6414..658c030 100644
41940 --- a/drivers/video/udlfb.c
41941 +++ b/drivers/video/udlfb.c
41942 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41943 dlfb_urb_completion(urb);
41944
41945 error:
41946 - atomic_add(bytes_sent, &dev->bytes_sent);
41947 - atomic_add(bytes_identical, &dev->bytes_identical);
41948 - atomic_add(width*height*2, &dev->bytes_rendered);
41949 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41950 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41951 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41952 end_cycles = get_cycles();
41953 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41954 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41955 >> 10)), /* Kcycles */
41956 &dev->cpu_kcycles_used);
41957
41958 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41959 dlfb_urb_completion(urb);
41960
41961 error:
41962 - atomic_add(bytes_sent, &dev->bytes_sent);
41963 - atomic_add(bytes_identical, &dev->bytes_identical);
41964 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41965 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41966 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41967 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41968 end_cycles = get_cycles();
41969 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41970 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41971 >> 10)), /* Kcycles */
41972 &dev->cpu_kcycles_used);
41973 }
41974 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41975 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41976 struct dlfb_data *dev = fb_info->par;
41977 return snprintf(buf, PAGE_SIZE, "%u\n",
41978 - atomic_read(&dev->bytes_rendered));
41979 + atomic_read_unchecked(&dev->bytes_rendered));
41980 }
41981
41982 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41983 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41984 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41985 struct dlfb_data *dev = fb_info->par;
41986 return snprintf(buf, PAGE_SIZE, "%u\n",
41987 - atomic_read(&dev->bytes_identical));
41988 + atomic_read_unchecked(&dev->bytes_identical));
41989 }
41990
41991 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41992 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41993 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41994 struct dlfb_data *dev = fb_info->par;
41995 return snprintf(buf, PAGE_SIZE, "%u\n",
41996 - atomic_read(&dev->bytes_sent));
41997 + atomic_read_unchecked(&dev->bytes_sent));
41998 }
41999
42000 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42001 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42002 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42003 struct dlfb_data *dev = fb_info->par;
42004 return snprintf(buf, PAGE_SIZE, "%u\n",
42005 - atomic_read(&dev->cpu_kcycles_used));
42006 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42007 }
42008
42009 static ssize_t edid_show(
42010 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42011 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42012 struct dlfb_data *dev = fb_info->par;
42013
42014 - atomic_set(&dev->bytes_rendered, 0);
42015 - atomic_set(&dev->bytes_identical, 0);
42016 - atomic_set(&dev->bytes_sent, 0);
42017 - atomic_set(&dev->cpu_kcycles_used, 0);
42018 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42019 + atomic_set_unchecked(&dev->bytes_identical, 0);
42020 + atomic_set_unchecked(&dev->bytes_sent, 0);
42021 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42022
42023 return count;
42024 }
42025 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42026 index b0e2a42..e2df3ad 100644
42027 --- a/drivers/video/uvesafb.c
42028 +++ b/drivers/video/uvesafb.c
42029 @@ -19,6 +19,7 @@
42030 #include <linux/io.h>
42031 #include <linux/mutex.h>
42032 #include <linux/slab.h>
42033 +#include <linux/moduleloader.h>
42034 #include <video/edid.h>
42035 #include <video/uvesafb.h>
42036 #ifdef CONFIG_X86
42037 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42038 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42039 par->pmi_setpal = par->ypan = 0;
42040 } else {
42041 +
42042 +#ifdef CONFIG_PAX_KERNEXEC
42043 +#ifdef CONFIG_MODULES
42044 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42045 +#endif
42046 + if (!par->pmi_code) {
42047 + par->pmi_setpal = par->ypan = 0;
42048 + return 0;
42049 + }
42050 +#endif
42051 +
42052 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42053 + task->t.regs.edi);
42054 +
42055 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42056 + pax_open_kernel();
42057 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42058 + pax_close_kernel();
42059 +
42060 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42061 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42062 +#else
42063 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42064 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42065 +#endif
42066 +
42067 printk(KERN_INFO "uvesafb: protected mode interface info at "
42068 "%04x:%04x\n",
42069 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42070 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42071 par->ypan = ypan;
42072
42073 if (par->pmi_setpal || par->ypan) {
42074 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42075 if (__supported_pte_mask & _PAGE_NX) {
42076 par->pmi_setpal = par->ypan = 0;
42077 printk(KERN_WARNING "uvesafb: NX protection is actively."
42078 "We have better not to use the PMI.\n");
42079 - } else {
42080 + } else
42081 +#endif
42082 uvesafb_vbe_getpmi(task, par);
42083 - }
42084 }
42085 #else
42086 /* The protected mode interface is not available on non-x86. */
42087 @@ -1836,6 +1860,11 @@ out:
42088 if (par->vbe_modes)
42089 kfree(par->vbe_modes);
42090
42091 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42092 + if (par->pmi_code)
42093 + module_free_exec(NULL, par->pmi_code);
42094 +#endif
42095 +
42096 framebuffer_release(info);
42097 return err;
42098 }
42099 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42100 kfree(par->vbe_state_orig);
42101 if (par->vbe_state_saved)
42102 kfree(par->vbe_state_saved);
42103 +
42104 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42105 + if (par->pmi_code)
42106 + module_free_exec(NULL, par->pmi_code);
42107 +#endif
42108 +
42109 }
42110
42111 framebuffer_release(info);
42112 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42113 index 501b340..86bd4cf 100644
42114 --- a/drivers/video/vesafb.c
42115 +++ b/drivers/video/vesafb.c
42116 @@ -9,6 +9,7 @@
42117 */
42118
42119 #include <linux/module.h>
42120 +#include <linux/moduleloader.h>
42121 #include <linux/kernel.h>
42122 #include <linux/errno.h>
42123 #include <linux/string.h>
42124 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42125 static int vram_total __initdata; /* Set total amount of memory */
42126 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42127 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42128 -static void (*pmi_start)(void) __read_mostly;
42129 -static void (*pmi_pal) (void) __read_mostly;
42130 +static void (*pmi_start)(void) __read_only;
42131 +static void (*pmi_pal) (void) __read_only;
42132 static int depth __read_mostly;
42133 static int vga_compat __read_mostly;
42134 /* --------------------------------------------------------------------- */
42135 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42136 unsigned int size_vmode;
42137 unsigned int size_remap;
42138 unsigned int size_total;
42139 + void *pmi_code = NULL;
42140
42141 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42142 return -ENODEV;
42143 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42144 size_remap = size_total;
42145 vesafb_fix.smem_len = size_remap;
42146
42147 -#ifndef __i386__
42148 - screen_info.vesapm_seg = 0;
42149 -#endif
42150 -
42151 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42152 printk(KERN_WARNING
42153 "vesafb: cannot reserve video memory at 0x%lx\n",
42154 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42155 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42156 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42157
42158 +#ifdef __i386__
42159 +
42160 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42161 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42162 + if (!pmi_code)
42163 +#elif !defined(CONFIG_PAX_KERNEXEC)
42164 + if (0)
42165 +#endif
42166 +
42167 +#endif
42168 + screen_info.vesapm_seg = 0;
42169 +
42170 if (screen_info.vesapm_seg) {
42171 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42172 - screen_info.vesapm_seg,screen_info.vesapm_off);
42173 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42174 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42175 }
42176
42177 if (screen_info.vesapm_seg < 0xc000)
42178 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42179
42180 if (ypan || pmi_setpal) {
42181 unsigned short *pmi_base;
42182 +
42183 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42184 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42185 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42186 +
42187 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42188 + pax_open_kernel();
42189 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42190 +#else
42191 + pmi_code = pmi_base;
42192 +#endif
42193 +
42194 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42195 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42196 +
42197 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42198 + pmi_start = ktva_ktla(pmi_start);
42199 + pmi_pal = ktva_ktla(pmi_pal);
42200 + pax_close_kernel();
42201 +#endif
42202 +
42203 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42204 if (pmi_base[3]) {
42205 printk(KERN_INFO "vesafb: pmi: ports = ");
42206 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42207 info->node, info->fix.id);
42208 return 0;
42209 err:
42210 +
42211 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42212 + module_free_exec(NULL, pmi_code);
42213 +#endif
42214 +
42215 if (info->screen_base)
42216 iounmap(info->screen_base);
42217 framebuffer_release(info);
42218 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42219 index 88714ae..16c2e11 100644
42220 --- a/drivers/video/via/via_clock.h
42221 +++ b/drivers/video/via/via_clock.h
42222 @@ -56,7 +56,7 @@ struct via_clock {
42223
42224 void (*set_engine_pll_state)(u8 state);
42225 void (*set_engine_pll)(struct via_pll_config config);
42226 -};
42227 +} __no_const;
42228
42229
42230 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42231 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42232 index e56c934..fc22f4b 100644
42233 --- a/drivers/xen/xen-pciback/conf_space.h
42234 +++ b/drivers/xen/xen-pciback/conf_space.h
42235 @@ -44,15 +44,15 @@ struct config_field {
42236 struct {
42237 conf_dword_write write;
42238 conf_dword_read read;
42239 - } dw;
42240 + } __no_const dw;
42241 struct {
42242 conf_word_write write;
42243 conf_word_read read;
42244 - } w;
42245 + } __no_const w;
42246 struct {
42247 conf_byte_write write;
42248 conf_byte_read read;
42249 - } b;
42250 + } __no_const b;
42251 } u;
42252 struct list_head list;
42253 };
42254 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42255 index 57ccb75..f6d05f8 100644
42256 --- a/fs/9p/vfs_inode.c
42257 +++ b/fs/9p/vfs_inode.c
42258 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42259 void
42260 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42261 {
42262 - char *s = nd_get_link(nd);
42263 + const char *s = nd_get_link(nd);
42264
42265 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42266 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42267 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42268 index 0225742..1cd4732 100644
42269 --- a/fs/Kconfig.binfmt
42270 +++ b/fs/Kconfig.binfmt
42271 @@ -89,7 +89,7 @@ config HAVE_AOUT
42272
42273 config BINFMT_AOUT
42274 tristate "Kernel support for a.out and ECOFF binaries"
42275 - depends on HAVE_AOUT
42276 + depends on HAVE_AOUT && BROKEN
42277 ---help---
42278 A.out (Assembler.OUTput) is a set of formats for libraries and
42279 executables used in the earliest versions of UNIX. Linux used
42280 diff --git a/fs/aio.c b/fs/aio.c
42281 index 55c4c76..11aee6f 100644
42282 --- a/fs/aio.c
42283 +++ b/fs/aio.c
42284 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42285 size += sizeof(struct io_event) * nr_events;
42286 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42287
42288 - if (nr_pages < 0)
42289 + if (nr_pages <= 0)
42290 return -EINVAL;
42291
42292 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42293 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42294 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42295 {
42296 ssize_t ret;
42297 + struct iovec iovstack;
42298
42299 #ifdef CONFIG_COMPAT
42300 if (compat)
42301 ret = compat_rw_copy_check_uvector(type,
42302 (struct compat_iovec __user *)kiocb->ki_buf,
42303 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42304 + kiocb->ki_nbytes, 1, &iovstack,
42305 &kiocb->ki_iovec);
42306 else
42307 #endif
42308 ret = rw_copy_check_uvector(type,
42309 (struct iovec __user *)kiocb->ki_buf,
42310 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42311 + kiocb->ki_nbytes, 1, &iovstack,
42312 &kiocb->ki_iovec);
42313 if (ret < 0)
42314 goto out;
42315 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42316 if (ret < 0)
42317 goto out;
42318
42319 + if (kiocb->ki_iovec == &iovstack) {
42320 + kiocb->ki_inline_vec = iovstack;
42321 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42322 + }
42323 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42324 kiocb->ki_cur_seg = 0;
42325 /* ki_nbytes/left now reflect bytes instead of segs */
42326 diff --git a/fs/attr.c b/fs/attr.c
42327 index 0da9095..1386693 100644
42328 --- a/fs/attr.c
42329 +++ b/fs/attr.c
42330 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42331 unsigned long limit;
42332
42333 limit = rlimit(RLIMIT_FSIZE);
42334 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42335 if (limit != RLIM_INFINITY && offset > limit)
42336 goto out_sig;
42337 if (offset > inode->i_sb->s_maxbytes)
42338 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42339 index da8876d..4456166 100644
42340 --- a/fs/autofs4/waitq.c
42341 +++ b/fs/autofs4/waitq.c
42342 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42343 {
42344 unsigned long sigpipe, flags;
42345 mm_segment_t fs;
42346 - const char *data = (const char *)addr;
42347 + const char __user *data = (const char __force_user *)addr;
42348 ssize_t wr = 0;
42349
42350 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42351 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42352 return 1;
42353 }
42354
42355 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42356 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42357 +#endif
42358 +
42359 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42360 enum autofs_notify notify)
42361 {
42362 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42363
42364 /* If this is a direct mount request create a dummy name */
42365 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42366 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42367 + /* this name does get written to userland via autofs4_write() */
42368 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42369 +#else
42370 qstr.len = sprintf(name, "%p", dentry);
42371 +#endif
42372 else {
42373 qstr.len = autofs4_getpath(sbi, dentry, &name);
42374 if (!qstr.len) {
42375 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42376 index e18da23..affc30e 100644
42377 --- a/fs/befs/linuxvfs.c
42378 +++ b/fs/befs/linuxvfs.c
42379 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42380 {
42381 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42382 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42383 - char *link = nd_get_link(nd);
42384 + const char *link = nd_get_link(nd);
42385 if (!IS_ERR(link))
42386 kfree(link);
42387 }
42388 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42389 index d146e18..12d1bd1 100644
42390 --- a/fs/binfmt_aout.c
42391 +++ b/fs/binfmt_aout.c
42392 @@ -16,6 +16,7 @@
42393 #include <linux/string.h>
42394 #include <linux/fs.h>
42395 #include <linux/file.h>
42396 +#include <linux/security.h>
42397 #include <linux/stat.h>
42398 #include <linux/fcntl.h>
42399 #include <linux/ptrace.h>
42400 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42401 #endif
42402 # define START_STACK(u) ((void __user *)u.start_stack)
42403
42404 + memset(&dump, 0, sizeof(dump));
42405 +
42406 fs = get_fs();
42407 set_fs(KERNEL_DS);
42408 has_dumped = 1;
42409 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42410
42411 /* If the size of the dump file exceeds the rlimit, then see what would happen
42412 if we wrote the stack, but not the data area. */
42413 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42414 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42415 dump.u_dsize = 0;
42416
42417 /* Make sure we have enough room to write the stack and data areas. */
42418 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42419 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42420 dump.u_ssize = 0;
42421
42422 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42423 rlim = rlimit(RLIMIT_DATA);
42424 if (rlim >= RLIM_INFINITY)
42425 rlim = ~0;
42426 +
42427 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42428 if (ex.a_data + ex.a_bss > rlim)
42429 return -ENOMEM;
42430
42431 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42432
42433 install_exec_creds(bprm);
42434
42435 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42436 + current->mm->pax_flags = 0UL;
42437 +#endif
42438 +
42439 +#ifdef CONFIG_PAX_PAGEEXEC
42440 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42441 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42442 +
42443 +#ifdef CONFIG_PAX_EMUTRAMP
42444 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42445 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42446 +#endif
42447 +
42448 +#ifdef CONFIG_PAX_MPROTECT
42449 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42450 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42451 +#endif
42452 +
42453 + }
42454 +#endif
42455 +
42456 if (N_MAGIC(ex) == OMAGIC) {
42457 unsigned long text_addr, map_size;
42458 loff_t pos;
42459 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42460 }
42461
42462 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42463 - PROT_READ | PROT_WRITE | PROT_EXEC,
42464 + PROT_READ | PROT_WRITE,
42465 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42466 fd_offset + ex.a_text);
42467 if (error != N_DATADDR(ex)) {
42468 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42469 index 1b52956..271266e 100644
42470 --- a/fs/binfmt_elf.c
42471 +++ b/fs/binfmt_elf.c
42472 @@ -32,6 +32,7 @@
42473 #include <linux/elf.h>
42474 #include <linux/utsname.h>
42475 #include <linux/coredump.h>
42476 +#include <linux/xattr.h>
42477 #include <asm/uaccess.h>
42478 #include <asm/param.h>
42479 #include <asm/page.h>
42480 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42481 #define elf_core_dump NULL
42482 #endif
42483
42484 +#ifdef CONFIG_PAX_MPROTECT
42485 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42486 +#endif
42487 +
42488 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42489 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42490 #else
42491 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42492 .load_binary = load_elf_binary,
42493 .load_shlib = load_elf_library,
42494 .core_dump = elf_core_dump,
42495 +
42496 +#ifdef CONFIG_PAX_MPROTECT
42497 + .handle_mprotect= elf_handle_mprotect,
42498 +#endif
42499 +
42500 .min_coredump = ELF_EXEC_PAGESIZE,
42501 };
42502
42503 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42504
42505 static int set_brk(unsigned long start, unsigned long end)
42506 {
42507 + unsigned long e = end;
42508 +
42509 start = ELF_PAGEALIGN(start);
42510 end = ELF_PAGEALIGN(end);
42511 if (end > start) {
42512 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42513 if (BAD_ADDR(addr))
42514 return addr;
42515 }
42516 - current->mm->start_brk = current->mm->brk = end;
42517 + current->mm->start_brk = current->mm->brk = e;
42518 return 0;
42519 }
42520
42521 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42522 elf_addr_t __user *u_rand_bytes;
42523 const char *k_platform = ELF_PLATFORM;
42524 const char *k_base_platform = ELF_BASE_PLATFORM;
42525 - unsigned char k_rand_bytes[16];
42526 + u32 k_rand_bytes[4];
42527 int items;
42528 elf_addr_t *elf_info;
42529 int ei_index = 0;
42530 const struct cred *cred = current_cred();
42531 struct vm_area_struct *vma;
42532 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42533
42534 /*
42535 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42536 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42537 * Generate 16 random bytes for userspace PRNG seeding.
42538 */
42539 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42540 - u_rand_bytes = (elf_addr_t __user *)
42541 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42542 + srandom32(k_rand_bytes[0] ^ random32());
42543 + srandom32(k_rand_bytes[1] ^ random32());
42544 + srandom32(k_rand_bytes[2] ^ random32());
42545 + srandom32(k_rand_bytes[3] ^ random32());
42546 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42547 + u_rand_bytes = (elf_addr_t __user *) p;
42548 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42549 return -EFAULT;
42550
42551 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42552 return -EFAULT;
42553 current->mm->env_end = p;
42554
42555 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42556 +
42557 /* Put the elf_info on the stack in the right place. */
42558 sp = (elf_addr_t __user *)envp + 1;
42559 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42560 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42561 return -EFAULT;
42562 return 0;
42563 }
42564 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42565 {
42566 struct elf_phdr *elf_phdata;
42567 struct elf_phdr *eppnt;
42568 - unsigned long load_addr = 0;
42569 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42570 int load_addr_set = 0;
42571 unsigned long last_bss = 0, elf_bss = 0;
42572 - unsigned long error = ~0UL;
42573 + unsigned long error = -EINVAL;
42574 unsigned long total_size;
42575 int retval, i, size;
42576
42577 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42578 goto out_close;
42579 }
42580
42581 +#ifdef CONFIG_PAX_SEGMEXEC
42582 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42583 + pax_task_size = SEGMEXEC_TASK_SIZE;
42584 +#endif
42585 +
42586 eppnt = elf_phdata;
42587 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42588 if (eppnt->p_type == PT_LOAD) {
42589 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42590 k = load_addr + eppnt->p_vaddr;
42591 if (BAD_ADDR(k) ||
42592 eppnt->p_filesz > eppnt->p_memsz ||
42593 - eppnt->p_memsz > TASK_SIZE ||
42594 - TASK_SIZE - eppnt->p_memsz < k) {
42595 + eppnt->p_memsz > pax_task_size ||
42596 + pax_task_size - eppnt->p_memsz < k) {
42597 error = -ENOMEM;
42598 goto out_close;
42599 }
42600 @@ -523,6 +547,311 @@ out:
42601 return error;
42602 }
42603
42604 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42605 +#ifdef CONFIG_PAX_SOFTMODE
42606 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42607 +{
42608 + unsigned long pax_flags = 0UL;
42609 +
42610 +#ifdef CONFIG_PAX_PAGEEXEC
42611 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42612 + pax_flags |= MF_PAX_PAGEEXEC;
42613 +#endif
42614 +
42615 +#ifdef CONFIG_PAX_SEGMEXEC
42616 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42617 + pax_flags |= MF_PAX_SEGMEXEC;
42618 +#endif
42619 +
42620 +#ifdef CONFIG_PAX_EMUTRAMP
42621 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42622 + pax_flags |= MF_PAX_EMUTRAMP;
42623 +#endif
42624 +
42625 +#ifdef CONFIG_PAX_MPROTECT
42626 + if (elf_phdata->p_flags & PF_MPROTECT)
42627 + pax_flags |= MF_PAX_MPROTECT;
42628 +#endif
42629 +
42630 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42631 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42632 + pax_flags |= MF_PAX_RANDMMAP;
42633 +#endif
42634 +
42635 + return pax_flags;
42636 +}
42637 +#endif
42638 +
42639 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42640 +{
42641 + unsigned long pax_flags = 0UL;
42642 +
42643 +#ifdef CONFIG_PAX_PAGEEXEC
42644 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42645 + pax_flags |= MF_PAX_PAGEEXEC;
42646 +#endif
42647 +
42648 +#ifdef CONFIG_PAX_SEGMEXEC
42649 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42650 + pax_flags |= MF_PAX_SEGMEXEC;
42651 +#endif
42652 +
42653 +#ifdef CONFIG_PAX_EMUTRAMP
42654 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42655 + pax_flags |= MF_PAX_EMUTRAMP;
42656 +#endif
42657 +
42658 +#ifdef CONFIG_PAX_MPROTECT
42659 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42660 + pax_flags |= MF_PAX_MPROTECT;
42661 +#endif
42662 +
42663 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42664 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42665 + pax_flags |= MF_PAX_RANDMMAP;
42666 +#endif
42667 +
42668 + return pax_flags;
42669 +}
42670 +#endif
42671 +
42672 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42673 +#ifdef CONFIG_PAX_SOFTMODE
42674 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42675 +{
42676 + unsigned long pax_flags = 0UL;
42677 +
42678 +#ifdef CONFIG_PAX_PAGEEXEC
42679 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42680 + pax_flags |= MF_PAX_PAGEEXEC;
42681 +#endif
42682 +
42683 +#ifdef CONFIG_PAX_SEGMEXEC
42684 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42685 + pax_flags |= MF_PAX_SEGMEXEC;
42686 +#endif
42687 +
42688 +#ifdef CONFIG_PAX_EMUTRAMP
42689 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42690 + pax_flags |= MF_PAX_EMUTRAMP;
42691 +#endif
42692 +
42693 +#ifdef CONFIG_PAX_MPROTECT
42694 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42695 + pax_flags |= MF_PAX_MPROTECT;
42696 +#endif
42697 +
42698 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42699 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42700 + pax_flags |= MF_PAX_RANDMMAP;
42701 +#endif
42702 +
42703 + return pax_flags;
42704 +}
42705 +#endif
42706 +
42707 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42708 +{
42709 + unsigned long pax_flags = 0UL;
42710 +
42711 +#ifdef CONFIG_PAX_PAGEEXEC
42712 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42713 + pax_flags |= MF_PAX_PAGEEXEC;
42714 +#endif
42715 +
42716 +#ifdef CONFIG_PAX_SEGMEXEC
42717 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42718 + pax_flags |= MF_PAX_SEGMEXEC;
42719 +#endif
42720 +
42721 +#ifdef CONFIG_PAX_EMUTRAMP
42722 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42723 + pax_flags |= MF_PAX_EMUTRAMP;
42724 +#endif
42725 +
42726 +#ifdef CONFIG_PAX_MPROTECT
42727 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42728 + pax_flags |= MF_PAX_MPROTECT;
42729 +#endif
42730 +
42731 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42732 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42733 + pax_flags |= MF_PAX_RANDMMAP;
42734 +#endif
42735 +
42736 + return pax_flags;
42737 +}
42738 +#endif
42739 +
42740 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42741 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42742 +{
42743 + unsigned long pax_flags = 0UL;
42744 +
42745 +#ifdef CONFIG_PAX_EI_PAX
42746 +
42747 +#ifdef CONFIG_PAX_PAGEEXEC
42748 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42749 + pax_flags |= MF_PAX_PAGEEXEC;
42750 +#endif
42751 +
42752 +#ifdef CONFIG_PAX_SEGMEXEC
42753 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42754 + pax_flags |= MF_PAX_SEGMEXEC;
42755 +#endif
42756 +
42757 +#ifdef CONFIG_PAX_EMUTRAMP
42758 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42759 + pax_flags |= MF_PAX_EMUTRAMP;
42760 +#endif
42761 +
42762 +#ifdef CONFIG_PAX_MPROTECT
42763 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42764 + pax_flags |= MF_PAX_MPROTECT;
42765 +#endif
42766 +
42767 +#ifdef CONFIG_PAX_ASLR
42768 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42769 + pax_flags |= MF_PAX_RANDMMAP;
42770 +#endif
42771 +
42772 +#else
42773 +
42774 +#ifdef CONFIG_PAX_PAGEEXEC
42775 + pax_flags |= MF_PAX_PAGEEXEC;
42776 +#endif
42777 +
42778 +#ifdef CONFIG_PAX_SEGMEXEC
42779 + pax_flags |= MF_PAX_SEGMEXEC;
42780 +#endif
42781 +
42782 +#ifdef CONFIG_PAX_MPROTECT
42783 + pax_flags |= MF_PAX_MPROTECT;
42784 +#endif
42785 +
42786 +#ifdef CONFIG_PAX_RANDMMAP
42787 + if (randomize_va_space)
42788 + pax_flags |= MF_PAX_RANDMMAP;
42789 +#endif
42790 +
42791 +#endif
42792 +
42793 + return pax_flags;
42794 +}
42795 +
42796 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42797 +{
42798 +
42799 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42800 + unsigned long i;
42801 +
42802 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42803 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42804 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42805 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42806 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42807 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42808 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42809 + return ~0UL;
42810 +
42811 +#ifdef CONFIG_PAX_SOFTMODE
42812 + if (pax_softmode)
42813 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42814 + else
42815 +#endif
42816 +
42817 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42818 + break;
42819 + }
42820 +#endif
42821 +
42822 + return ~0UL;
42823 +}
42824 +
42825 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42826 +{
42827 +
42828 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42829 + ssize_t xattr_size, i;
42830 + unsigned char xattr_value[5];
42831 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42832 +
42833 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42834 + if (xattr_size <= 0)
42835 + return ~0UL;
42836 +
42837 + for (i = 0; i < xattr_size; i++)
42838 + switch (xattr_value[i]) {
42839 + default:
42840 + return ~0UL;
42841 +
42842 +#define parse_flag(option1, option2, flag) \
42843 + case option1: \
42844 + pax_flags_hardmode |= MF_PAX_##flag; \
42845 + break; \
42846 + case option2: \
42847 + pax_flags_softmode |= MF_PAX_##flag; \
42848 + break;
42849 +
42850 + parse_flag('p', 'P', PAGEEXEC);
42851 + parse_flag('e', 'E', EMUTRAMP);
42852 + parse_flag('m', 'M', MPROTECT);
42853 + parse_flag('r', 'R', RANDMMAP);
42854 + parse_flag('s', 'S', SEGMEXEC);
42855 +
42856 +#undef parse_flag
42857 + }
42858 +
42859 + if (pax_flags_hardmode & pax_flags_softmode)
42860 + return ~0UL;
42861 +
42862 +#ifdef CONFIG_PAX_SOFTMODE
42863 + if (pax_softmode)
42864 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42865 + else
42866 +#endif
42867 +
42868 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42869 +#else
42870 + return ~0UL;
42871 +#endif
42872 +
42873 +}
42874 +
42875 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42876 +{
42877 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42878 +
42879 + pax_flags = pax_parse_ei_pax(elf_ex);
42880 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42881 + xattr_pax_flags = pax_parse_xattr_pax(file);
42882 +
42883 + if (pt_pax_flags == ~0UL)
42884 + pt_pax_flags = xattr_pax_flags;
42885 + else if (xattr_pax_flags == ~0UL)
42886 + xattr_pax_flags = pt_pax_flags;
42887 + if (pt_pax_flags != xattr_pax_flags)
42888 + return -EINVAL;
42889 + if (pt_pax_flags != ~0UL)
42890 + pax_flags = pt_pax_flags;
42891 +
42892 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42893 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42894 + if ((__supported_pte_mask & _PAGE_NX))
42895 + pax_flags &= ~MF_PAX_SEGMEXEC;
42896 + else
42897 + pax_flags &= ~MF_PAX_PAGEEXEC;
42898 + }
42899 +#endif
42900 +
42901 + if (0 > pax_check_flags(&pax_flags))
42902 + return -EINVAL;
42903 +
42904 + current->mm->pax_flags = pax_flags;
42905 + return 0;
42906 +}
42907 +#endif
42908 +
42909 /*
42910 * These are the functions used to load ELF style executables and shared
42911 * libraries. There is no binary dependent code anywhere else.
42912 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42913 {
42914 unsigned int random_variable = 0;
42915
42916 +#ifdef CONFIG_PAX_RANDUSTACK
42917 + if (randomize_va_space)
42918 + return stack_top - current->mm->delta_stack;
42919 +#endif
42920 +
42921 if ((current->flags & PF_RANDOMIZE) &&
42922 !(current->personality & ADDR_NO_RANDOMIZE)) {
42923 random_variable = get_random_int() & STACK_RND_MASK;
42924 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42925 unsigned long load_addr = 0, load_bias = 0;
42926 int load_addr_set = 0;
42927 char * elf_interpreter = NULL;
42928 - unsigned long error;
42929 + unsigned long error = 0;
42930 struct elf_phdr *elf_ppnt, *elf_phdata;
42931 unsigned long elf_bss, elf_brk;
42932 int retval, i;
42933 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42934 unsigned long start_code, end_code, start_data, end_data;
42935 unsigned long reloc_func_desc __maybe_unused = 0;
42936 int executable_stack = EXSTACK_DEFAULT;
42937 - unsigned long def_flags = 0;
42938 struct {
42939 struct elfhdr elf_ex;
42940 struct elfhdr interp_elf_ex;
42941 } *loc;
42942 + unsigned long pax_task_size = TASK_SIZE;
42943
42944 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42945 if (!loc) {
42946 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42947 goto out_free_dentry;
42948
42949 /* OK, This is the point of no return */
42950 - current->mm->def_flags = def_flags;
42951 +
42952 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42953 + current->mm->pax_flags = 0UL;
42954 +#endif
42955 +
42956 +#ifdef CONFIG_PAX_DLRESOLVE
42957 + current->mm->call_dl_resolve = 0UL;
42958 +#endif
42959 +
42960 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42961 + current->mm->call_syscall = 0UL;
42962 +#endif
42963 +
42964 +#ifdef CONFIG_PAX_ASLR
42965 + current->mm->delta_mmap = 0UL;
42966 + current->mm->delta_stack = 0UL;
42967 +#endif
42968 +
42969 + current->mm->def_flags = 0;
42970 +
42971 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42972 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42973 + send_sig(SIGKILL, current, 0);
42974 + goto out_free_dentry;
42975 + }
42976 +#endif
42977 +
42978 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42979 + pax_set_initial_flags(bprm);
42980 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42981 + if (pax_set_initial_flags_func)
42982 + (pax_set_initial_flags_func)(bprm);
42983 +#endif
42984 +
42985 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42986 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42987 + current->mm->context.user_cs_limit = PAGE_SIZE;
42988 + current->mm->def_flags |= VM_PAGEEXEC;
42989 + }
42990 +#endif
42991 +
42992 +#ifdef CONFIG_PAX_SEGMEXEC
42993 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42994 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42995 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42996 + pax_task_size = SEGMEXEC_TASK_SIZE;
42997 + current->mm->def_flags |= VM_NOHUGEPAGE;
42998 + }
42999 +#endif
43000 +
43001 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43002 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43003 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43004 + put_cpu();
43005 + }
43006 +#endif
43007
43008 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43009 may depend on the personality. */
43010 SET_PERSONALITY(loc->elf_ex);
43011 +
43012 +#ifdef CONFIG_PAX_ASLR
43013 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43014 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43015 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43016 + }
43017 +#endif
43018 +
43019 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43020 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43021 + executable_stack = EXSTACK_DISABLE_X;
43022 + current->personality &= ~READ_IMPLIES_EXEC;
43023 + } else
43024 +#endif
43025 +
43026 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43027 current->personality |= READ_IMPLIES_EXEC;
43028
43029 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43030 #else
43031 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43032 #endif
43033 +
43034 +#ifdef CONFIG_PAX_RANDMMAP
43035 + /* PaX: randomize base address at the default exe base if requested */
43036 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43037 +#ifdef CONFIG_SPARC64
43038 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43039 +#else
43040 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43041 +#endif
43042 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43043 + elf_flags |= MAP_FIXED;
43044 + }
43045 +#endif
43046 +
43047 }
43048
43049 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43050 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43051 * allowed task size. Note that p_filesz must always be
43052 * <= p_memsz so it is only necessary to check p_memsz.
43053 */
43054 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43055 - elf_ppnt->p_memsz > TASK_SIZE ||
43056 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43057 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43058 + elf_ppnt->p_memsz > pax_task_size ||
43059 + pax_task_size - elf_ppnt->p_memsz < k) {
43060 /* set_brk can never work. Avoid overflows. */
43061 send_sig(SIGKILL, current, 0);
43062 retval = -EINVAL;
43063 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43064 goto out_free_dentry;
43065 }
43066 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43067 - send_sig(SIGSEGV, current, 0);
43068 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43069 - goto out_free_dentry;
43070 + /*
43071 + * This bss-zeroing can fail if the ELF
43072 + * file specifies odd protections. So
43073 + * we don't check the return value
43074 + */
43075 }
43076
43077 +#ifdef CONFIG_PAX_RANDMMAP
43078 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43079 + unsigned long start, size;
43080 +
43081 + start = ELF_PAGEALIGN(elf_brk);
43082 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43083 + down_read(&current->mm->mmap_sem);
43084 + retval = -ENOMEM;
43085 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43086 + unsigned long prot = PROT_NONE;
43087 +
43088 + up_read(&current->mm->mmap_sem);
43089 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43090 +// if (current->personality & ADDR_NO_RANDOMIZE)
43091 +// prot = PROT_READ;
43092 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43093 + retval = IS_ERR_VALUE(start) ? start : 0;
43094 + } else
43095 + up_read(&current->mm->mmap_sem);
43096 + if (retval == 0)
43097 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43098 + if (retval < 0) {
43099 + send_sig(SIGKILL, current, 0);
43100 + goto out_free_dentry;
43101 + }
43102 + }
43103 +#endif
43104 +
43105 if (elf_interpreter) {
43106 unsigned long uninitialized_var(interp_map_addr);
43107
43108 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43109 * Decide what to dump of a segment, part, all or none.
43110 */
43111 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43112 - unsigned long mm_flags)
43113 + unsigned long mm_flags, long signr)
43114 {
43115 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43116
43117 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43118 if (vma->vm_file == NULL)
43119 return 0;
43120
43121 - if (FILTER(MAPPED_PRIVATE))
43122 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43123 goto whole;
43124
43125 /*
43126 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43127 {
43128 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43129 int i = 0;
43130 - do
43131 + do {
43132 i += 2;
43133 - while (auxv[i - 2] != AT_NULL);
43134 + } while (auxv[i - 2] != AT_NULL);
43135 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43136 }
43137
43138 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43139 }
43140
43141 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43142 - unsigned long mm_flags)
43143 + struct coredump_params *cprm)
43144 {
43145 struct vm_area_struct *vma;
43146 size_t size = 0;
43147
43148 for (vma = first_vma(current, gate_vma); vma != NULL;
43149 vma = next_vma(vma, gate_vma))
43150 - size += vma_dump_size(vma, mm_flags);
43151 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43152 return size;
43153 }
43154
43155 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43156
43157 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43158
43159 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43160 + offset += elf_core_vma_data_size(gate_vma, cprm);
43161 offset += elf_core_extra_data_size();
43162 e_shoff = offset;
43163
43164 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43165 offset = dataoff;
43166
43167 size += sizeof(*elf);
43168 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43169 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43170 goto end_coredump;
43171
43172 size += sizeof(*phdr4note);
43173 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43174 if (size > cprm->limit
43175 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43176 goto end_coredump;
43177 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43178 phdr.p_offset = offset;
43179 phdr.p_vaddr = vma->vm_start;
43180 phdr.p_paddr = 0;
43181 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43182 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43183 phdr.p_memsz = vma->vm_end - vma->vm_start;
43184 offset += phdr.p_filesz;
43185 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43186 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43187 phdr.p_align = ELF_EXEC_PAGESIZE;
43188
43189 size += sizeof(phdr);
43190 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43191 if (size > cprm->limit
43192 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43193 goto end_coredump;
43194 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43195 unsigned long addr;
43196 unsigned long end;
43197
43198 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43199 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43200
43201 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43202 struct page *page;
43203 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43204 page = get_dump_page(addr);
43205 if (page) {
43206 void *kaddr = kmap(page);
43207 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43208 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43209 !dump_write(cprm->file, kaddr,
43210 PAGE_SIZE);
43211 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43212
43213 if (e_phnum == PN_XNUM) {
43214 size += sizeof(*shdr4extnum);
43215 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43216 if (size > cprm->limit
43217 || !dump_write(cprm->file, shdr4extnum,
43218 sizeof(*shdr4extnum)))
43219 @@ -2103,6 +2556,97 @@ out:
43220
43221 #endif /* CONFIG_ELF_CORE */
43222
43223 +#ifdef CONFIG_PAX_MPROTECT
43224 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43225 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43226 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43227 + *
43228 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43229 + * basis because we want to allow the common case and not the special ones.
43230 + */
43231 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43232 +{
43233 + struct elfhdr elf_h;
43234 + struct elf_phdr elf_p;
43235 + unsigned long i;
43236 + unsigned long oldflags;
43237 + bool is_textrel_rw, is_textrel_rx, is_relro;
43238 +
43239 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43240 + return;
43241 +
43242 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43243 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43244 +
43245 +#ifdef CONFIG_PAX_ELFRELOCS
43246 + /* possible TEXTREL */
43247 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43248 + 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);
43249 +#else
43250 + is_textrel_rw = false;
43251 + is_textrel_rx = false;
43252 +#endif
43253 +
43254 + /* possible RELRO */
43255 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43256 +
43257 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43258 + return;
43259 +
43260 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43261 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43262 +
43263 +#ifdef CONFIG_PAX_ETEXECRELOCS
43264 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43265 +#else
43266 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43267 +#endif
43268 +
43269 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43270 + !elf_check_arch(&elf_h) ||
43271 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43272 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43273 + return;
43274 +
43275 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43276 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43277 + return;
43278 + switch (elf_p.p_type) {
43279 + case PT_DYNAMIC:
43280 + if (!is_textrel_rw && !is_textrel_rx)
43281 + continue;
43282 + i = 0UL;
43283 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43284 + elf_dyn dyn;
43285 +
43286 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43287 + return;
43288 + if (dyn.d_tag == DT_NULL)
43289 + return;
43290 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43291 + gr_log_textrel(vma);
43292 + if (is_textrel_rw)
43293 + vma->vm_flags |= VM_MAYWRITE;
43294 + else
43295 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43296 + vma->vm_flags &= ~VM_MAYWRITE;
43297 + return;
43298 + }
43299 + i++;
43300 + }
43301 + return;
43302 +
43303 + case PT_GNU_RELRO:
43304 + if (!is_relro)
43305 + continue;
43306 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43307 + vma->vm_flags &= ~VM_MAYWRITE;
43308 + return;
43309 + }
43310 + }
43311 +}
43312 +#endif
43313 +
43314 static int __init init_elf_binfmt(void)
43315 {
43316 register_binfmt(&elf_format);
43317 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43318 index 178cb70..8972997 100644
43319 --- a/fs/binfmt_flat.c
43320 +++ b/fs/binfmt_flat.c
43321 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43322 realdatastart = (unsigned long) -ENOMEM;
43323 printk("Unable to allocate RAM for process data, errno %d\n",
43324 (int)-realdatastart);
43325 + down_write(&current->mm->mmap_sem);
43326 vm_munmap(textpos, text_len);
43327 + up_write(&current->mm->mmap_sem);
43328 ret = realdatastart;
43329 goto err;
43330 }
43331 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43332 }
43333 if (IS_ERR_VALUE(result)) {
43334 printk("Unable to read data+bss, errno %d\n", (int)-result);
43335 + down_write(&current->mm->mmap_sem);
43336 vm_munmap(textpos, text_len);
43337 vm_munmap(realdatastart, len);
43338 + up_write(&current->mm->mmap_sem);
43339 ret = result;
43340 goto err;
43341 }
43342 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43343 }
43344 if (IS_ERR_VALUE(result)) {
43345 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43346 + down_write(&current->mm->mmap_sem);
43347 vm_munmap(textpos, text_len + data_len + extra +
43348 MAX_SHARED_LIBS * sizeof(unsigned long));
43349 + up_write(&current->mm->mmap_sem);
43350 ret = result;
43351 goto err;
43352 }
43353 diff --git a/fs/bio.c b/fs/bio.c
43354 index 73922ab..16642dd 100644
43355 --- a/fs/bio.c
43356 +++ b/fs/bio.c
43357 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43358 /*
43359 * Overflow, abort
43360 */
43361 - if (end < start)
43362 + if (end < start || end - start > INT_MAX - nr_pages)
43363 return ERR_PTR(-EINVAL);
43364
43365 nr_pages += end - start;
43366 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43367 /*
43368 * Overflow, abort
43369 */
43370 - if (end < start)
43371 + if (end < start || end - start > INT_MAX - nr_pages)
43372 return ERR_PTR(-EINVAL);
43373
43374 nr_pages += end - start;
43375 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43376 const int read = bio_data_dir(bio) == READ;
43377 struct bio_map_data *bmd = bio->bi_private;
43378 int i;
43379 - char *p = bmd->sgvecs[0].iov_base;
43380 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43381
43382 __bio_for_each_segment(bvec, bio, i, 0) {
43383 char *addr = page_address(bvec->bv_page);
43384 diff --git a/fs/block_dev.c b/fs/block_dev.c
43385 index c2bbe1f..9dfbc23 100644
43386 --- a/fs/block_dev.c
43387 +++ b/fs/block_dev.c
43388 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43389 else if (bdev->bd_contains == bdev)
43390 return true; /* is a whole device which isn't held */
43391
43392 - else if (whole->bd_holder == bd_may_claim)
43393 + else if (whole->bd_holder == (void *)bd_may_claim)
43394 return true; /* is a partition of a device that is being partitioned */
43395 else if (whole->bd_holder != NULL)
43396 return false; /* is a partition of a held device */
43397 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43398 index da6e936..1598dd0 100644
43399 --- a/fs/btrfs/check-integrity.c
43400 +++ b/fs/btrfs/check-integrity.c
43401 @@ -155,7 +155,7 @@ struct btrfsic_block {
43402 union {
43403 bio_end_io_t *bio;
43404 bh_end_io_t *bh;
43405 - } orig_bio_bh_end_io;
43406 + } __no_const orig_bio_bh_end_io;
43407 int submit_bio_bh_rw;
43408 u64 flush_gen; /* only valid if !never_written */
43409 };
43410 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43411 index 8206b39..06d5654 100644
43412 --- a/fs/btrfs/ctree.c
43413 +++ b/fs/btrfs/ctree.c
43414 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43415 free_extent_buffer(buf);
43416 add_root_to_dirty_list(root);
43417 } else {
43418 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43419 - parent_start = parent->start;
43420 - else
43421 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43422 + if (parent)
43423 + parent_start = parent->start;
43424 + else
43425 + parent_start = 0;
43426 + } else
43427 parent_start = 0;
43428
43429 WARN_ON(trans->transid != btrfs_header_generation(parent));
43430 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43431 index a7d1921..a32dba2 100644
43432 --- a/fs/btrfs/inode.c
43433 +++ b/fs/btrfs/inode.c
43434 @@ -7111,7 +7111,7 @@ fail:
43435 return -ENOMEM;
43436 }
43437
43438 -static int btrfs_getattr(struct vfsmount *mnt,
43439 +int btrfs_getattr(struct vfsmount *mnt,
43440 struct dentry *dentry, struct kstat *stat)
43441 {
43442 struct inode *inode = dentry->d_inode;
43443 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43444 return 0;
43445 }
43446
43447 +EXPORT_SYMBOL(btrfs_getattr);
43448 +
43449 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43450 +{
43451 + return BTRFS_I(inode)->root->anon_dev;
43452 +}
43453 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43454 +
43455 /*
43456 * If a file is moved, it will inherit the cow and compression flags of the new
43457 * directory.
43458 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43459 index 0e92e57..8b560de 100644
43460 --- a/fs/btrfs/ioctl.c
43461 +++ b/fs/btrfs/ioctl.c
43462 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43463 for (i = 0; i < num_types; i++) {
43464 struct btrfs_space_info *tmp;
43465
43466 + /* Don't copy in more than we allocated */
43467 if (!slot_count)
43468 break;
43469
43470 + slot_count--;
43471 +
43472 info = NULL;
43473 rcu_read_lock();
43474 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43475 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43476 memcpy(dest, &space, sizeof(space));
43477 dest++;
43478 space_args.total_spaces++;
43479 - slot_count--;
43480 }
43481 - if (!slot_count)
43482 - break;
43483 }
43484 up_read(&info->groups_sem);
43485 }
43486 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43487 index 646ee21..f020f87 100644
43488 --- a/fs/btrfs/relocation.c
43489 +++ b/fs/btrfs/relocation.c
43490 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43491 }
43492 spin_unlock(&rc->reloc_root_tree.lock);
43493
43494 - BUG_ON((struct btrfs_root *)node->data != root);
43495 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43496
43497 if (!del) {
43498 spin_lock(&rc->reloc_root_tree.lock);
43499 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43500 index 622f469..e8d2d55 100644
43501 --- a/fs/cachefiles/bind.c
43502 +++ b/fs/cachefiles/bind.c
43503 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43504 args);
43505
43506 /* start by checking things over */
43507 - ASSERT(cache->fstop_percent >= 0 &&
43508 - cache->fstop_percent < cache->fcull_percent &&
43509 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43510 cache->fcull_percent < cache->frun_percent &&
43511 cache->frun_percent < 100);
43512
43513 - ASSERT(cache->bstop_percent >= 0 &&
43514 - cache->bstop_percent < cache->bcull_percent &&
43515 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43516 cache->bcull_percent < cache->brun_percent &&
43517 cache->brun_percent < 100);
43518
43519 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43520 index 0a1467b..6a53245 100644
43521 --- a/fs/cachefiles/daemon.c
43522 +++ b/fs/cachefiles/daemon.c
43523 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43524 if (n > buflen)
43525 return -EMSGSIZE;
43526
43527 - if (copy_to_user(_buffer, buffer, n) != 0)
43528 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43529 return -EFAULT;
43530
43531 return n;
43532 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43533 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43534 return -EIO;
43535
43536 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43537 + if (datalen > PAGE_SIZE - 1)
43538 return -EOPNOTSUPP;
43539
43540 /* drag the command string into the kernel so we can parse it */
43541 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43542 if (args[0] != '%' || args[1] != '\0')
43543 return -EINVAL;
43544
43545 - if (fstop < 0 || fstop >= cache->fcull_percent)
43546 + if (fstop >= cache->fcull_percent)
43547 return cachefiles_daemon_range_error(cache, args);
43548
43549 cache->fstop_percent = fstop;
43550 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43551 if (args[0] != '%' || args[1] != '\0')
43552 return -EINVAL;
43553
43554 - if (bstop < 0 || bstop >= cache->bcull_percent)
43555 + if (bstop >= cache->bcull_percent)
43556 return cachefiles_daemon_range_error(cache, args);
43557
43558 cache->bstop_percent = bstop;
43559 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43560 index bd6bc1b..b627b53 100644
43561 --- a/fs/cachefiles/internal.h
43562 +++ b/fs/cachefiles/internal.h
43563 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43564 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43565 struct rb_root active_nodes; /* active nodes (can't be culled) */
43566 rwlock_t active_lock; /* lock for active_nodes */
43567 - atomic_t gravecounter; /* graveyard uniquifier */
43568 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43569 unsigned frun_percent; /* when to stop culling (% files) */
43570 unsigned fcull_percent; /* when to start culling (% files) */
43571 unsigned fstop_percent; /* when to stop allocating (% files) */
43572 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43573 * proc.c
43574 */
43575 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43576 -extern atomic_t cachefiles_lookup_histogram[HZ];
43577 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43578 -extern atomic_t cachefiles_create_histogram[HZ];
43579 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43580 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43581 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43582
43583 extern int __init cachefiles_proc_init(void);
43584 extern void cachefiles_proc_cleanup(void);
43585 static inline
43586 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43587 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43588 {
43589 unsigned long jif = jiffies - start_jif;
43590 if (jif >= HZ)
43591 jif = HZ - 1;
43592 - atomic_inc(&histogram[jif]);
43593 + atomic_inc_unchecked(&histogram[jif]);
43594 }
43595
43596 #else
43597 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43598 index 7f0771d..87d4f36 100644
43599 --- a/fs/cachefiles/namei.c
43600 +++ b/fs/cachefiles/namei.c
43601 @@ -318,7 +318,7 @@ try_again:
43602 /* first step is to make up a grave dentry in the graveyard */
43603 sprintf(nbuffer, "%08x%08x",
43604 (uint32_t) get_seconds(),
43605 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43606 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43607
43608 /* do the multiway lock magic */
43609 trap = lock_rename(cache->graveyard, dir);
43610 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43611 index eccd339..4c1d995 100644
43612 --- a/fs/cachefiles/proc.c
43613 +++ b/fs/cachefiles/proc.c
43614 @@ -14,9 +14,9 @@
43615 #include <linux/seq_file.h>
43616 #include "internal.h"
43617
43618 -atomic_t cachefiles_lookup_histogram[HZ];
43619 -atomic_t cachefiles_mkdir_histogram[HZ];
43620 -atomic_t cachefiles_create_histogram[HZ];
43621 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43622 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43623 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43624
43625 /*
43626 * display the latency histogram
43627 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43628 return 0;
43629 default:
43630 index = (unsigned long) v - 3;
43631 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43632 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43633 - z = atomic_read(&cachefiles_create_histogram[index]);
43634 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43635 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43636 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43637 if (x == 0 && y == 0 && z == 0)
43638 return 0;
43639
43640 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43641 index 0e3c092..818480e 100644
43642 --- a/fs/cachefiles/rdwr.c
43643 +++ b/fs/cachefiles/rdwr.c
43644 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43645 old_fs = get_fs();
43646 set_fs(KERNEL_DS);
43647 ret = file->f_op->write(
43648 - file, (const void __user *) data, len, &pos);
43649 + file, (const void __force_user *) data, len, &pos);
43650 set_fs(old_fs);
43651 kunmap(page);
43652 if (ret != len)
43653 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43654 index 3e8094b..cb3ff3d 100644
43655 --- a/fs/ceph/dir.c
43656 +++ b/fs/ceph/dir.c
43657 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43658 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43659 struct ceph_mds_client *mdsc = fsc->mdsc;
43660 unsigned frag = fpos_frag(filp->f_pos);
43661 - int off = fpos_off(filp->f_pos);
43662 + unsigned int off = fpos_off(filp->f_pos);
43663 int err;
43664 u32 ftype;
43665 struct ceph_mds_reply_info_parsed *rinfo;
43666 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43667 if (nd &&
43668 (nd->flags & LOOKUP_OPEN) &&
43669 !(nd->intent.open.flags & O_CREAT)) {
43670 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43671 + int mode = nd->intent.open.create_mode & ~current_umask();
43672 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43673 }
43674
43675 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43676 index e814052..28dcdf7 100644
43677 --- a/fs/cifs/cifs_debug.c
43678 +++ b/fs/cifs/cifs_debug.c
43679 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43680
43681 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43682 #ifdef CONFIG_CIFS_STATS2
43683 - atomic_set(&totBufAllocCount, 0);
43684 - atomic_set(&totSmBufAllocCount, 0);
43685 + atomic_set_unchecked(&totBufAllocCount, 0);
43686 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43687 #endif /* CONFIG_CIFS_STATS2 */
43688 spin_lock(&cifs_tcp_ses_lock);
43689 list_for_each(tmp1, &cifs_tcp_ses_list) {
43690 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43691 tcon = list_entry(tmp3,
43692 struct cifs_tcon,
43693 tcon_list);
43694 - atomic_set(&tcon->num_smbs_sent, 0);
43695 - atomic_set(&tcon->num_writes, 0);
43696 - atomic_set(&tcon->num_reads, 0);
43697 - atomic_set(&tcon->num_oplock_brks, 0);
43698 - atomic_set(&tcon->num_opens, 0);
43699 - atomic_set(&tcon->num_posixopens, 0);
43700 - atomic_set(&tcon->num_posixmkdirs, 0);
43701 - atomic_set(&tcon->num_closes, 0);
43702 - atomic_set(&tcon->num_deletes, 0);
43703 - atomic_set(&tcon->num_mkdirs, 0);
43704 - atomic_set(&tcon->num_rmdirs, 0);
43705 - atomic_set(&tcon->num_renames, 0);
43706 - atomic_set(&tcon->num_t2renames, 0);
43707 - atomic_set(&tcon->num_ffirst, 0);
43708 - atomic_set(&tcon->num_fnext, 0);
43709 - atomic_set(&tcon->num_fclose, 0);
43710 - atomic_set(&tcon->num_hardlinks, 0);
43711 - atomic_set(&tcon->num_symlinks, 0);
43712 - atomic_set(&tcon->num_locks, 0);
43713 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43714 + atomic_set_unchecked(&tcon->num_writes, 0);
43715 + atomic_set_unchecked(&tcon->num_reads, 0);
43716 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43717 + atomic_set_unchecked(&tcon->num_opens, 0);
43718 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43719 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43720 + atomic_set_unchecked(&tcon->num_closes, 0);
43721 + atomic_set_unchecked(&tcon->num_deletes, 0);
43722 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43723 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43724 + atomic_set_unchecked(&tcon->num_renames, 0);
43725 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43726 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43727 + atomic_set_unchecked(&tcon->num_fnext, 0);
43728 + atomic_set_unchecked(&tcon->num_fclose, 0);
43729 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43730 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43731 + atomic_set_unchecked(&tcon->num_locks, 0);
43732 }
43733 }
43734 }
43735 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43736 smBufAllocCount.counter, cifs_min_small);
43737 #ifdef CONFIG_CIFS_STATS2
43738 seq_printf(m, "Total Large %d Small %d Allocations\n",
43739 - atomic_read(&totBufAllocCount),
43740 - atomic_read(&totSmBufAllocCount));
43741 + atomic_read_unchecked(&totBufAllocCount),
43742 + atomic_read_unchecked(&totSmBufAllocCount));
43743 #endif /* CONFIG_CIFS_STATS2 */
43744
43745 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43746 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43747 if (tcon->need_reconnect)
43748 seq_puts(m, "\tDISCONNECTED ");
43749 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43750 - atomic_read(&tcon->num_smbs_sent),
43751 - atomic_read(&tcon->num_oplock_brks));
43752 + atomic_read_unchecked(&tcon->num_smbs_sent),
43753 + atomic_read_unchecked(&tcon->num_oplock_brks));
43754 seq_printf(m, "\nReads: %d Bytes: %lld",
43755 - atomic_read(&tcon->num_reads),
43756 + atomic_read_unchecked(&tcon->num_reads),
43757 (long long)(tcon->bytes_read));
43758 seq_printf(m, "\nWrites: %d Bytes: %lld",
43759 - atomic_read(&tcon->num_writes),
43760 + atomic_read_unchecked(&tcon->num_writes),
43761 (long long)(tcon->bytes_written));
43762 seq_printf(m, "\nFlushes: %d",
43763 - atomic_read(&tcon->num_flushes));
43764 + atomic_read_unchecked(&tcon->num_flushes));
43765 seq_printf(m, "\nLocks: %d HardLinks: %d "
43766 "Symlinks: %d",
43767 - atomic_read(&tcon->num_locks),
43768 - atomic_read(&tcon->num_hardlinks),
43769 - atomic_read(&tcon->num_symlinks));
43770 + atomic_read_unchecked(&tcon->num_locks),
43771 + atomic_read_unchecked(&tcon->num_hardlinks),
43772 + atomic_read_unchecked(&tcon->num_symlinks));
43773 seq_printf(m, "\nOpens: %d Closes: %d "
43774 "Deletes: %d",
43775 - atomic_read(&tcon->num_opens),
43776 - atomic_read(&tcon->num_closes),
43777 - atomic_read(&tcon->num_deletes));
43778 + atomic_read_unchecked(&tcon->num_opens),
43779 + atomic_read_unchecked(&tcon->num_closes),
43780 + atomic_read_unchecked(&tcon->num_deletes));
43781 seq_printf(m, "\nPosix Opens: %d "
43782 "Posix Mkdirs: %d",
43783 - atomic_read(&tcon->num_posixopens),
43784 - atomic_read(&tcon->num_posixmkdirs));
43785 + atomic_read_unchecked(&tcon->num_posixopens),
43786 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43787 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43788 - atomic_read(&tcon->num_mkdirs),
43789 - atomic_read(&tcon->num_rmdirs));
43790 + atomic_read_unchecked(&tcon->num_mkdirs),
43791 + atomic_read_unchecked(&tcon->num_rmdirs));
43792 seq_printf(m, "\nRenames: %d T2 Renames %d",
43793 - atomic_read(&tcon->num_renames),
43794 - atomic_read(&tcon->num_t2renames));
43795 + atomic_read_unchecked(&tcon->num_renames),
43796 + atomic_read_unchecked(&tcon->num_t2renames));
43797 seq_printf(m, "\nFindFirst: %d FNext %d "
43798 "FClose %d",
43799 - atomic_read(&tcon->num_ffirst),
43800 - atomic_read(&tcon->num_fnext),
43801 - atomic_read(&tcon->num_fclose));
43802 + atomic_read_unchecked(&tcon->num_ffirst),
43803 + atomic_read_unchecked(&tcon->num_fnext),
43804 + atomic_read_unchecked(&tcon->num_fclose));
43805 }
43806 }
43807 }
43808 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43809 index 8b6e344..303a662 100644
43810 --- a/fs/cifs/cifsfs.c
43811 +++ b/fs/cifs/cifsfs.c
43812 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43813 cifs_req_cachep = kmem_cache_create("cifs_request",
43814 CIFSMaxBufSize +
43815 MAX_CIFS_HDR_SIZE, 0,
43816 - SLAB_HWCACHE_ALIGN, NULL);
43817 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43818 if (cifs_req_cachep == NULL)
43819 return -ENOMEM;
43820
43821 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43822 efficient to alloc 1 per page off the slab compared to 17K (5page)
43823 alloc of large cifs buffers even when page debugging is on */
43824 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43825 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43826 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43827 NULL);
43828 if (cifs_sm_req_cachep == NULL) {
43829 mempool_destroy(cifs_req_poolp);
43830 @@ -1106,8 +1106,8 @@ init_cifs(void)
43831 atomic_set(&bufAllocCount, 0);
43832 atomic_set(&smBufAllocCount, 0);
43833 #ifdef CONFIG_CIFS_STATS2
43834 - atomic_set(&totBufAllocCount, 0);
43835 - atomic_set(&totSmBufAllocCount, 0);
43836 + atomic_set_unchecked(&totBufAllocCount, 0);
43837 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43838 #endif /* CONFIG_CIFS_STATS2 */
43839
43840 atomic_set(&midCount, 0);
43841 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43842 index d86ba9f..e80049d 100644
43843 --- a/fs/cifs/cifsglob.h
43844 +++ b/fs/cifs/cifsglob.h
43845 @@ -491,28 +491,28 @@ struct cifs_tcon {
43846 __u16 Flags; /* optional support bits */
43847 enum statusEnum tidStatus;
43848 #ifdef CONFIG_CIFS_STATS
43849 - atomic_t num_smbs_sent;
43850 - atomic_t num_writes;
43851 - atomic_t num_reads;
43852 - atomic_t num_flushes;
43853 - atomic_t num_oplock_brks;
43854 - atomic_t num_opens;
43855 - atomic_t num_closes;
43856 - atomic_t num_deletes;
43857 - atomic_t num_mkdirs;
43858 - atomic_t num_posixopens;
43859 - atomic_t num_posixmkdirs;
43860 - atomic_t num_rmdirs;
43861 - atomic_t num_renames;
43862 - atomic_t num_t2renames;
43863 - atomic_t num_ffirst;
43864 - atomic_t num_fnext;
43865 - atomic_t num_fclose;
43866 - atomic_t num_hardlinks;
43867 - atomic_t num_symlinks;
43868 - atomic_t num_locks;
43869 - atomic_t num_acl_get;
43870 - atomic_t num_acl_set;
43871 + atomic_unchecked_t num_smbs_sent;
43872 + atomic_unchecked_t num_writes;
43873 + atomic_unchecked_t num_reads;
43874 + atomic_unchecked_t num_flushes;
43875 + atomic_unchecked_t num_oplock_brks;
43876 + atomic_unchecked_t num_opens;
43877 + atomic_unchecked_t num_closes;
43878 + atomic_unchecked_t num_deletes;
43879 + atomic_unchecked_t num_mkdirs;
43880 + atomic_unchecked_t num_posixopens;
43881 + atomic_unchecked_t num_posixmkdirs;
43882 + atomic_unchecked_t num_rmdirs;
43883 + atomic_unchecked_t num_renames;
43884 + atomic_unchecked_t num_t2renames;
43885 + atomic_unchecked_t num_ffirst;
43886 + atomic_unchecked_t num_fnext;
43887 + atomic_unchecked_t num_fclose;
43888 + atomic_unchecked_t num_hardlinks;
43889 + atomic_unchecked_t num_symlinks;
43890 + atomic_unchecked_t num_locks;
43891 + atomic_unchecked_t num_acl_get;
43892 + atomic_unchecked_t num_acl_set;
43893 #ifdef CONFIG_CIFS_STATS2
43894 unsigned long long time_writes;
43895 unsigned long long time_reads;
43896 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43897 }
43898
43899 #ifdef CONFIG_CIFS_STATS
43900 -#define cifs_stats_inc atomic_inc
43901 +#define cifs_stats_inc atomic_inc_unchecked
43902
43903 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43904 unsigned int bytes)
43905 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43906 /* Various Debug counters */
43907 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43908 #ifdef CONFIG_CIFS_STATS2
43909 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43910 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43911 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43912 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43913 #endif
43914 GLOBAL_EXTERN atomic_t smBufAllocCount;
43915 GLOBAL_EXTERN atomic_t midCount;
43916 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43917 index 6b0e064..94e6c3c 100644
43918 --- a/fs/cifs/link.c
43919 +++ b/fs/cifs/link.c
43920 @@ -600,7 +600,7 @@ symlink_exit:
43921
43922 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43923 {
43924 - char *p = nd_get_link(nd);
43925 + const char *p = nd_get_link(nd);
43926 if (!IS_ERR(p))
43927 kfree(p);
43928 }
43929 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43930 index 557506a..2fd3816 100644
43931 --- a/fs/cifs/misc.c
43932 +++ b/fs/cifs/misc.c
43933 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43934 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43935 atomic_inc(&bufAllocCount);
43936 #ifdef CONFIG_CIFS_STATS2
43937 - atomic_inc(&totBufAllocCount);
43938 + atomic_inc_unchecked(&totBufAllocCount);
43939 #endif /* CONFIG_CIFS_STATS2 */
43940 }
43941
43942 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43943 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43944 atomic_inc(&smBufAllocCount);
43945 #ifdef CONFIG_CIFS_STATS2
43946 - atomic_inc(&totSmBufAllocCount);
43947 + atomic_inc_unchecked(&totSmBufAllocCount);
43948 #endif /* CONFIG_CIFS_STATS2 */
43949
43950 }
43951 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43952 index 6901578..d402eb5 100644
43953 --- a/fs/coda/cache.c
43954 +++ b/fs/coda/cache.c
43955 @@ -24,7 +24,7 @@
43956 #include "coda_linux.h"
43957 #include "coda_cache.h"
43958
43959 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43960 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43961
43962 /* replace or extend an acl cache hit */
43963 void coda_cache_enter(struct inode *inode, int mask)
43964 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43965 struct coda_inode_info *cii = ITOC(inode);
43966
43967 spin_lock(&cii->c_lock);
43968 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43969 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43970 if (cii->c_uid != current_fsuid()) {
43971 cii->c_uid = current_fsuid();
43972 cii->c_cached_perm = mask;
43973 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43974 {
43975 struct coda_inode_info *cii = ITOC(inode);
43976 spin_lock(&cii->c_lock);
43977 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43978 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43979 spin_unlock(&cii->c_lock);
43980 }
43981
43982 /* remove all acl caches */
43983 void coda_cache_clear_all(struct super_block *sb)
43984 {
43985 - atomic_inc(&permission_epoch);
43986 + atomic_inc_unchecked(&permission_epoch);
43987 }
43988
43989
43990 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43991 spin_lock(&cii->c_lock);
43992 hit = (mask & cii->c_cached_perm) == mask &&
43993 cii->c_uid == current_fsuid() &&
43994 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43995 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43996 spin_unlock(&cii->c_lock);
43997
43998 return hit;
43999 diff --git a/fs/compat.c b/fs/compat.c
44000 index 6161255..9f28287 100644
44001 --- a/fs/compat.c
44002 +++ b/fs/compat.c
44003 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44004
44005 set_fs(KERNEL_DS);
44006 /* The __user pointer cast is valid because of the set_fs() */
44007 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44008 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44009 set_fs(oldfs);
44010 /* truncating is ok because it's a user address */
44011 if (!ret)
44012 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44013 goto out;
44014
44015 ret = -EINVAL;
44016 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44017 + if (nr_segs > UIO_MAXIOV)
44018 goto out;
44019 if (nr_segs > fast_segs) {
44020 ret = -ENOMEM;
44021 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44022
44023 struct compat_readdir_callback {
44024 struct compat_old_linux_dirent __user *dirent;
44025 + struct file * file;
44026 int result;
44027 };
44028
44029 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44030 buf->result = -EOVERFLOW;
44031 return -EOVERFLOW;
44032 }
44033 +
44034 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44035 + return 0;
44036 +
44037 buf->result++;
44038 dirent = buf->dirent;
44039 if (!access_ok(VERIFY_WRITE, dirent,
44040 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44041
44042 buf.result = 0;
44043 buf.dirent = dirent;
44044 + buf.file = file;
44045
44046 error = vfs_readdir(file, compat_fillonedir, &buf);
44047 if (buf.result)
44048 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44049 struct compat_getdents_callback {
44050 struct compat_linux_dirent __user *current_dir;
44051 struct compat_linux_dirent __user *previous;
44052 + struct file * file;
44053 int count;
44054 int error;
44055 };
44056 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44057 buf->error = -EOVERFLOW;
44058 return -EOVERFLOW;
44059 }
44060 +
44061 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44062 + return 0;
44063 +
44064 dirent = buf->previous;
44065 if (dirent) {
44066 if (__put_user(offset, &dirent->d_off))
44067 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44068 buf.previous = NULL;
44069 buf.count = count;
44070 buf.error = 0;
44071 + buf.file = file;
44072
44073 error = vfs_readdir(file, compat_filldir, &buf);
44074 if (error >= 0)
44075 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44076 struct compat_getdents_callback64 {
44077 struct linux_dirent64 __user *current_dir;
44078 struct linux_dirent64 __user *previous;
44079 + struct file * file;
44080 int count;
44081 int error;
44082 };
44083 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44084 buf->error = -EINVAL; /* only used if we fail.. */
44085 if (reclen > buf->count)
44086 return -EINVAL;
44087 +
44088 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44089 + return 0;
44090 +
44091 dirent = buf->previous;
44092
44093 if (dirent) {
44094 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44095 buf.previous = NULL;
44096 buf.count = count;
44097 buf.error = 0;
44098 + buf.file = file;
44099
44100 error = vfs_readdir(file, compat_filldir64, &buf);
44101 if (error >= 0)
44102 error = buf.error;
44103 lastdirent = buf.previous;
44104 if (lastdirent) {
44105 - typeof(lastdirent->d_off) d_off = file->f_pos;
44106 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44107 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44108 error = -EFAULT;
44109 else
44110 @@ -1155,11 +1173,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
44111 struct file *file;
44112 int fput_needed;
44113 ssize_t ret;
44114 + loff_t pos;
44115
44116 file = fget_light(fd, &fput_needed);
44117 if (!file)
44118 return -EBADF;
44119 - ret = compat_readv(file, vec, vlen, &file->f_pos);
44120 + pos = file->f_pos;
44121 + ret = compat_readv(file, vec, vlen, &pos);
44122 + file->f_pos = pos;
44123 fput_light(file, fput_needed);
44124 return ret;
44125 }
44126 @@ -1221,11 +1242,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
44127 struct file *file;
44128 int fput_needed;
44129 ssize_t ret;
44130 + loff_t pos;
44131
44132 file = fget_light(fd, &fput_needed);
44133 if (!file)
44134 return -EBADF;
44135 - ret = compat_writev(file, vec, vlen, &file->f_pos);
44136 + pos = file->f_pos;
44137 + ret = compat_writev(file, vec, vlen, &pos);
44138 + file->f_pos = pos;
44139 fput_light(file, fput_needed);
44140 return ret;
44141 }
44142 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44143 index 112e45a..b59845b 100644
44144 --- a/fs/compat_binfmt_elf.c
44145 +++ b/fs/compat_binfmt_elf.c
44146 @@ -30,11 +30,13 @@
44147 #undef elf_phdr
44148 #undef elf_shdr
44149 #undef elf_note
44150 +#undef elf_dyn
44151 #undef elf_addr_t
44152 #define elfhdr elf32_hdr
44153 #define elf_phdr elf32_phdr
44154 #define elf_shdr elf32_shdr
44155 #define elf_note elf32_note
44156 +#define elf_dyn Elf32_Dyn
44157 #define elf_addr_t Elf32_Addr
44158
44159 /*
44160 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44161 index debdfe0..75d31d4 100644
44162 --- a/fs/compat_ioctl.c
44163 +++ b/fs/compat_ioctl.c
44164 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44165
44166 err = get_user(palp, &up->palette);
44167 err |= get_user(length, &up->length);
44168 + if (err)
44169 + return -EFAULT;
44170
44171 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44172 err = put_user(compat_ptr(palp), &up_native->palette);
44173 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44174 return -EFAULT;
44175 if (__get_user(udata, &ss32->iomem_base))
44176 return -EFAULT;
44177 - ss.iomem_base = compat_ptr(udata);
44178 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44179 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44180 __get_user(ss.port_high, &ss32->port_high))
44181 return -EFAULT;
44182 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44183 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44184 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44185 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44186 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44187 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44188 return -EFAULT;
44189
44190 return ioctl_preallocate(file, p);
44191 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44192 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44193 {
44194 unsigned int a, b;
44195 - a = *(unsigned int *)p;
44196 - b = *(unsigned int *)q;
44197 + a = *(const unsigned int *)p;
44198 + b = *(const unsigned int *)q;
44199 if (a > b)
44200 return 1;
44201 if (a < b)
44202 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44203 index 7e6c52d..94bc756 100644
44204 --- a/fs/configfs/dir.c
44205 +++ b/fs/configfs/dir.c
44206 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44207 }
44208 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44209 struct configfs_dirent *next;
44210 - const char * name;
44211 + const unsigned char * name;
44212 + char d_name[sizeof(next->s_dentry->d_iname)];
44213 int len;
44214 struct inode *inode = NULL;
44215
44216 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44217 continue;
44218
44219 name = configfs_get_name(next);
44220 - len = strlen(name);
44221 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44222 + len = next->s_dentry->d_name.len;
44223 + memcpy(d_name, name, len);
44224 + name = d_name;
44225 + } else
44226 + len = strlen(name);
44227
44228 /*
44229 * We'll have a dentry and an inode for
44230 diff --git a/fs/dcache.c b/fs/dcache.c
44231 index 4046904..5e31505 100644
44232 --- a/fs/dcache.c
44233 +++ b/fs/dcache.c
44234 @@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44235 mempages -= reserve;
44236
44237 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44238 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44239 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44240
44241 dcache_init();
44242 inode_init();
44243 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44244 index b80bc84..0d46d1a 100644
44245 --- a/fs/debugfs/inode.c
44246 +++ b/fs/debugfs/inode.c
44247 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44248 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44249 {
44250 return debugfs_create_file(name,
44251 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44252 + S_IFDIR | S_IRWXU,
44253 +#else
44254 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44255 +#endif
44256 parent, NULL, NULL);
44257 }
44258 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44259 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44260 index a07441a..046fc0d 100644
44261 --- a/fs/ecryptfs/inode.c
44262 +++ b/fs/ecryptfs/inode.c
44263 @@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44264 old_fs = get_fs();
44265 set_fs(get_ds());
44266 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44267 - (char __user *)lower_buf,
44268 + (char __force_user *)lower_buf,
44269 PATH_MAX);
44270 set_fs(old_fs);
44271 if (rc < 0)
44272 @@ -703,7 +703,7 @@ out:
44273 static void
44274 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44275 {
44276 - char *buf = nd_get_link(nd);
44277 + const char *buf = nd_get_link(nd);
44278 if (!IS_ERR(buf)) {
44279 /* Free the char* */
44280 kfree(buf);
44281 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44282 index c0038f6..47ab347 100644
44283 --- a/fs/ecryptfs/miscdev.c
44284 +++ b/fs/ecryptfs/miscdev.c
44285 @@ -355,7 +355,7 @@ check_list:
44286 goto out_unlock_msg_ctx;
44287 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44288 if (msg_ctx->msg) {
44289 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44290 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44291 goto out_unlock_msg_ctx;
44292 i += packet_length_size;
44293 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44294 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44295 index b2a34a1..162fa69 100644
44296 --- a/fs/ecryptfs/read_write.c
44297 +++ b/fs/ecryptfs/read_write.c
44298 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44299 return -EIO;
44300 fs_save = get_fs();
44301 set_fs(get_ds());
44302 - rc = vfs_write(lower_file, data, size, &offset);
44303 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44304 set_fs(fs_save);
44305 mark_inode_dirty_sync(ecryptfs_inode);
44306 return rc;
44307 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44308 return -EIO;
44309 fs_save = get_fs();
44310 set_fs(get_ds());
44311 - rc = vfs_read(lower_file, data, size, &offset);
44312 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44313 set_fs(fs_save);
44314 return rc;
44315 }
44316 diff --git a/fs/eventpoll.c b/fs/eventpoll.c
44317 index 1c8b556..eedec84 100644
44318 --- a/fs/eventpoll.c
44319 +++ b/fs/eventpoll.c
44320 @@ -1654,8 +1654,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
44321 error = PTR_ERR(file);
44322 goto out_free_fd;
44323 }
44324 - fd_install(fd, file);
44325 ep->file = file;
44326 + fd_install(fd, file);
44327 return fd;
44328
44329 out_free_fd:
44330 diff --git a/fs/exec.c b/fs/exec.c
44331 index e95aeed..a943469 100644
44332 --- a/fs/exec.c
44333 +++ b/fs/exec.c
44334 @@ -55,6 +55,15 @@
44335 #include <linux/pipe_fs_i.h>
44336 #include <linux/oom.h>
44337 #include <linux/compat.h>
44338 +#include <linux/random.h>
44339 +#include <linux/seq_file.h>
44340 +
44341 +#ifdef CONFIG_PAX_REFCOUNT
44342 +#include <linux/kallsyms.h>
44343 +#include <linux/kdebug.h>
44344 +#endif
44345 +
44346 +#include <trace/events/fs.h>
44347
44348 #include <asm/uaccess.h>
44349 #include <asm/mmu_context.h>
44350 @@ -66,6 +75,18 @@
44351
44352 #include <trace/events/sched.h>
44353
44354 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44355 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44356 +{
44357 + 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");
44358 +}
44359 +#endif
44360 +
44361 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44362 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44363 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44364 +#endif
44365 +
44366 int core_uses_pid;
44367 char core_pattern[CORENAME_MAX_SIZE] = "core";
44368 unsigned int core_pipe_limit;
44369 @@ -75,7 +96,7 @@ struct core_name {
44370 char *corename;
44371 int used, size;
44372 };
44373 -static atomic_t call_count = ATOMIC_INIT(1);
44374 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44375
44376 /* The maximal length of core_pattern is also specified in sysctl.c */
44377
44378 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44379 int write)
44380 {
44381 struct page *page;
44382 - int ret;
44383
44384 -#ifdef CONFIG_STACK_GROWSUP
44385 - if (write) {
44386 - ret = expand_downwards(bprm->vma, pos);
44387 - if (ret < 0)
44388 - return NULL;
44389 - }
44390 -#endif
44391 - ret = get_user_pages(current, bprm->mm, pos,
44392 - 1, write, 1, &page, NULL);
44393 - if (ret <= 0)
44394 + if (0 > expand_downwards(bprm->vma, pos))
44395 + return NULL;
44396 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44397 return NULL;
44398
44399 if (write) {
44400 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44401 if (size <= ARG_MAX)
44402 return page;
44403
44404 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44405 + // only allow 512KB for argv+env on suid/sgid binaries
44406 + // to prevent easy ASLR exhaustion
44407 + if (((bprm->cred->euid != current_euid()) ||
44408 + (bprm->cred->egid != current_egid())) &&
44409 + (size > (512 * 1024))) {
44410 + put_page(page);
44411 + return NULL;
44412 + }
44413 +#endif
44414 +
44415 /*
44416 * Limit to 1/4-th the stack size for the argv+env strings.
44417 * This ensures that:
44418 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44419 vma->vm_end = STACK_TOP_MAX;
44420 vma->vm_start = vma->vm_end - PAGE_SIZE;
44421 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44422 +
44423 +#ifdef CONFIG_PAX_SEGMEXEC
44424 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44425 +#endif
44426 +
44427 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44428 INIT_LIST_HEAD(&vma->anon_vma_chain);
44429
44430 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44431 mm->stack_vm = mm->total_vm = 1;
44432 up_write(&mm->mmap_sem);
44433 bprm->p = vma->vm_end - sizeof(void *);
44434 +
44435 +#ifdef CONFIG_PAX_RANDUSTACK
44436 + if (randomize_va_space)
44437 + bprm->p ^= random32() & ~PAGE_MASK;
44438 +#endif
44439 +
44440 return 0;
44441 err:
44442 up_write(&mm->mmap_sem);
44443 @@ -395,19 +430,7 @@ err:
44444 return err;
44445 }
44446
44447 -struct user_arg_ptr {
44448 -#ifdef CONFIG_COMPAT
44449 - bool is_compat;
44450 -#endif
44451 - union {
44452 - const char __user *const __user *native;
44453 -#ifdef CONFIG_COMPAT
44454 - compat_uptr_t __user *compat;
44455 -#endif
44456 - } ptr;
44457 -};
44458 -
44459 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44460 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44461 {
44462 const char __user *native;
44463
44464 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44465 compat_uptr_t compat;
44466
44467 if (get_user(compat, argv.ptr.compat + nr))
44468 - return ERR_PTR(-EFAULT);
44469 + return (const char __force_user *)ERR_PTR(-EFAULT);
44470
44471 return compat_ptr(compat);
44472 }
44473 #endif
44474
44475 if (get_user(native, argv.ptr.native + nr))
44476 - return ERR_PTR(-EFAULT);
44477 + return (const char __force_user *)ERR_PTR(-EFAULT);
44478
44479 return native;
44480 }
44481 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44482 if (!p)
44483 break;
44484
44485 - if (IS_ERR(p))
44486 + if (IS_ERR((const char __force_kernel *)p))
44487 return -EFAULT;
44488
44489 if (i++ >= max)
44490 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44491
44492 ret = -EFAULT;
44493 str = get_user_arg_ptr(argv, argc);
44494 - if (IS_ERR(str))
44495 + if (IS_ERR((const char __force_kernel *)str))
44496 goto out;
44497
44498 len = strnlen_user(str, MAX_ARG_STRLEN);
44499 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44500 int r;
44501 mm_segment_t oldfs = get_fs();
44502 struct user_arg_ptr argv = {
44503 - .ptr.native = (const char __user *const __user *)__argv,
44504 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44505 };
44506
44507 set_fs(KERNEL_DS);
44508 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44509 unsigned long new_end = old_end - shift;
44510 struct mmu_gather tlb;
44511
44512 - BUG_ON(new_start > new_end);
44513 + if (new_start >= new_end || new_start < mmap_min_addr)
44514 + return -ENOMEM;
44515
44516 /*
44517 * ensure there are no vmas between where we want to go
44518 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44519 if (vma != find_vma(mm, new_start))
44520 return -EFAULT;
44521
44522 +#ifdef CONFIG_PAX_SEGMEXEC
44523 + BUG_ON(pax_find_mirror_vma(vma));
44524 +#endif
44525 +
44526 /*
44527 * cover the whole range: [new_start, old_end)
44528 */
44529 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44530 stack_top = arch_align_stack(stack_top);
44531 stack_top = PAGE_ALIGN(stack_top);
44532
44533 - if (unlikely(stack_top < mmap_min_addr) ||
44534 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44535 - return -ENOMEM;
44536 -
44537 stack_shift = vma->vm_end - stack_top;
44538
44539 bprm->p -= stack_shift;
44540 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44541 bprm->exec -= stack_shift;
44542
44543 down_write(&mm->mmap_sem);
44544 +
44545 + /* Move stack pages down in memory. */
44546 + if (stack_shift) {
44547 + ret = shift_arg_pages(vma, stack_shift);
44548 + if (ret)
44549 + goto out_unlock;
44550 + }
44551 +
44552 vm_flags = VM_STACK_FLAGS;
44553
44554 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44555 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44556 + vm_flags &= ~VM_EXEC;
44557 +
44558 +#ifdef CONFIG_PAX_MPROTECT
44559 + if (mm->pax_flags & MF_PAX_MPROTECT)
44560 + vm_flags &= ~VM_MAYEXEC;
44561 +#endif
44562 +
44563 + }
44564 +#endif
44565 +
44566 /*
44567 * Adjust stack execute permissions; explicitly enable for
44568 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44569 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44570 goto out_unlock;
44571 BUG_ON(prev != vma);
44572
44573 - /* Move stack pages down in memory. */
44574 - if (stack_shift) {
44575 - ret = shift_arg_pages(vma, stack_shift);
44576 - if (ret)
44577 - goto out_unlock;
44578 - }
44579 -
44580 /* mprotect_fixup is overkill to remove the temporary stack flags */
44581 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44582
44583 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44584
44585 fsnotify_open(file);
44586
44587 + trace_open_exec(name);
44588 +
44589 err = deny_write_access(file);
44590 if (err)
44591 goto exit;
44592 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44593 old_fs = get_fs();
44594 set_fs(get_ds());
44595 /* The cast to a user pointer is valid due to the set_fs() */
44596 - result = vfs_read(file, (void __user *)addr, count, &pos);
44597 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44598 set_fs(old_fs);
44599 return result;
44600 }
44601 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44602 }
44603 rcu_read_unlock();
44604
44605 - if (p->fs->users > n_fs) {
44606 + if (atomic_read(&p->fs->users) > n_fs) {
44607 bprm->unsafe |= LSM_UNSAFE_SHARE;
44608 } else {
44609 res = -EAGAIN;
44610 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44611
44612 EXPORT_SYMBOL(search_binary_handler);
44613
44614 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44615 +static DEFINE_PER_CPU(u64, exec_counter);
44616 +static int __init init_exec_counters(void)
44617 +{
44618 + unsigned int cpu;
44619 +
44620 + for_each_possible_cpu(cpu) {
44621 + per_cpu(exec_counter, cpu) = (u64)cpu;
44622 + }
44623 +
44624 + return 0;
44625 +}
44626 +early_initcall(init_exec_counters);
44627 +static inline void increment_exec_counter(void)
44628 +{
44629 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44630 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44631 +}
44632 +#else
44633 +static inline void increment_exec_counter(void) {}
44634 +#endif
44635 +
44636 /*
44637 * sys_execve() executes a new program.
44638 */
44639 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44640 struct user_arg_ptr envp,
44641 struct pt_regs *regs)
44642 {
44643 +#ifdef CONFIG_GRKERNSEC
44644 + struct file *old_exec_file;
44645 + struct acl_subject_label *old_acl;
44646 + struct rlimit old_rlim[RLIM_NLIMITS];
44647 +#endif
44648 struct linux_binprm *bprm;
44649 struct file *file;
44650 struct files_struct *displaced;
44651 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44652 int retval;
44653 const struct cred *cred = current_cred();
44654
44655 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44656 +
44657 /*
44658 * We move the actual failure in case of RLIMIT_NPROC excess from
44659 * set*uid() to execve() because too many poorly written programs
44660 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44661 if (IS_ERR(file))
44662 goto out_unmark;
44663
44664 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44665 + retval = -EPERM;
44666 + goto out_file;
44667 + }
44668 +
44669 sched_exec();
44670
44671 bprm->file = file;
44672 bprm->filename = filename;
44673 bprm->interp = filename;
44674
44675 + if (gr_process_user_ban()) {
44676 + retval = -EPERM;
44677 + goto out_file;
44678 + }
44679 +
44680 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44681 + retval = -EACCES;
44682 + goto out_file;
44683 + }
44684 +
44685 retval = bprm_mm_init(bprm);
44686 if (retval)
44687 goto out_file;
44688 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44689 if (retval < 0)
44690 goto out;
44691
44692 +#ifdef CONFIG_GRKERNSEC
44693 + old_acl = current->acl;
44694 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44695 + old_exec_file = current->exec_file;
44696 + get_file(file);
44697 + current->exec_file = file;
44698 +#endif
44699 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44700 + /* limit suid stack to 8MB
44701 + we saved the old limits above and will restore them if this exec fails
44702 + */
44703 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44704 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44705 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44706 +#endif
44707 +
44708 + if (!gr_tpe_allow(file)) {
44709 + retval = -EACCES;
44710 + goto out_fail;
44711 + }
44712 +
44713 + if (gr_check_crash_exec(file)) {
44714 + retval = -EACCES;
44715 + goto out_fail;
44716 + }
44717 +
44718 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44719 + bprm->unsafe);
44720 + if (retval < 0)
44721 + goto out_fail;
44722 +
44723 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44724 if (retval < 0)
44725 - goto out;
44726 + goto out_fail;
44727
44728 bprm->exec = bprm->p;
44729 retval = copy_strings(bprm->envc, envp, bprm);
44730 if (retval < 0)
44731 - goto out;
44732 + goto out_fail;
44733
44734 retval = copy_strings(bprm->argc, argv, bprm);
44735 if (retval < 0)
44736 - goto out;
44737 + goto out_fail;
44738 +
44739 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44740 +
44741 + gr_handle_exec_args(bprm, argv);
44742
44743 retval = search_binary_handler(bprm,regs);
44744 if (retval < 0)
44745 - goto out;
44746 + goto out_fail;
44747 +#ifdef CONFIG_GRKERNSEC
44748 + if (old_exec_file)
44749 + fput(old_exec_file);
44750 +#endif
44751
44752 /* execve succeeded */
44753 +
44754 + increment_exec_counter();
44755 current->fs->in_exec = 0;
44756 current->in_execve = 0;
44757 acct_update_integrals(current);
44758 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44759 put_files_struct(displaced);
44760 return retval;
44761
44762 +out_fail:
44763 +#ifdef CONFIG_GRKERNSEC
44764 + current->acl = old_acl;
44765 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44766 + fput(current->exec_file);
44767 + current->exec_file = old_exec_file;
44768 +#endif
44769 +
44770 out:
44771 if (bprm->mm) {
44772 acct_arg_size(bprm, 0);
44773 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44774 {
44775 char *old_corename = cn->corename;
44776
44777 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44778 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44779 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44780
44781 if (!cn->corename) {
44782 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44783 int pid_in_pattern = 0;
44784 int err = 0;
44785
44786 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44787 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44788 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44789 cn->used = 0;
44790
44791 @@ -1830,6 +1962,250 @@ out:
44792 return ispipe;
44793 }
44794
44795 +int pax_check_flags(unsigned long *flags)
44796 +{
44797 + int retval = 0;
44798 +
44799 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44800 + if (*flags & MF_PAX_SEGMEXEC)
44801 + {
44802 + *flags &= ~MF_PAX_SEGMEXEC;
44803 + retval = -EINVAL;
44804 + }
44805 +#endif
44806 +
44807 + if ((*flags & MF_PAX_PAGEEXEC)
44808 +
44809 +#ifdef CONFIG_PAX_PAGEEXEC
44810 + && (*flags & MF_PAX_SEGMEXEC)
44811 +#endif
44812 +
44813 + )
44814 + {
44815 + *flags &= ~MF_PAX_PAGEEXEC;
44816 + retval = -EINVAL;
44817 + }
44818 +
44819 + if ((*flags & MF_PAX_MPROTECT)
44820 +
44821 +#ifdef CONFIG_PAX_MPROTECT
44822 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44823 +#endif
44824 +
44825 + )
44826 + {
44827 + *flags &= ~MF_PAX_MPROTECT;
44828 + retval = -EINVAL;
44829 + }
44830 +
44831 + if ((*flags & MF_PAX_EMUTRAMP)
44832 +
44833 +#ifdef CONFIG_PAX_EMUTRAMP
44834 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44835 +#endif
44836 +
44837 + )
44838 + {
44839 + *flags &= ~MF_PAX_EMUTRAMP;
44840 + retval = -EINVAL;
44841 + }
44842 +
44843 + return retval;
44844 +}
44845 +
44846 +EXPORT_SYMBOL(pax_check_flags);
44847 +
44848 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44849 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44850 +{
44851 + struct task_struct *tsk = current;
44852 + struct mm_struct *mm = current->mm;
44853 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44854 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44855 + char *path_exec = NULL;
44856 + char *path_fault = NULL;
44857 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44858 +
44859 + if (buffer_exec && buffer_fault) {
44860 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44861 +
44862 + down_read(&mm->mmap_sem);
44863 + vma = mm->mmap;
44864 + while (vma && (!vma_exec || !vma_fault)) {
44865 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44866 + vma_exec = vma;
44867 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44868 + vma_fault = vma;
44869 + vma = vma->vm_next;
44870 + }
44871 + if (vma_exec) {
44872 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44873 + if (IS_ERR(path_exec))
44874 + path_exec = "<path too long>";
44875 + else {
44876 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44877 + if (path_exec) {
44878 + *path_exec = 0;
44879 + path_exec = buffer_exec;
44880 + } else
44881 + path_exec = "<path too long>";
44882 + }
44883 + }
44884 + if (vma_fault) {
44885 + start = vma_fault->vm_start;
44886 + end = vma_fault->vm_end;
44887 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44888 + if (vma_fault->vm_file) {
44889 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44890 + if (IS_ERR(path_fault))
44891 + path_fault = "<path too long>";
44892 + else {
44893 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44894 + if (path_fault) {
44895 + *path_fault = 0;
44896 + path_fault = buffer_fault;
44897 + } else
44898 + path_fault = "<path too long>";
44899 + }
44900 + } else
44901 + path_fault = "<anonymous mapping>";
44902 + }
44903 + up_read(&mm->mmap_sem);
44904 + }
44905 + if (tsk->signal->curr_ip)
44906 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44907 + else
44908 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44909 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44910 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44911 + task_uid(tsk), task_euid(tsk), pc, sp);
44912 + free_page((unsigned long)buffer_exec);
44913 + free_page((unsigned long)buffer_fault);
44914 + pax_report_insns(regs, pc, sp);
44915 + do_coredump(SIGKILL, SIGKILL, regs);
44916 +}
44917 +#endif
44918 +
44919 +#ifdef CONFIG_PAX_REFCOUNT
44920 +void pax_report_refcount_overflow(struct pt_regs *regs)
44921 +{
44922 + if (current->signal->curr_ip)
44923 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44924 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44925 + else
44926 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44927 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44928 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44929 + show_regs(regs);
44930 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44931 +}
44932 +#endif
44933 +
44934 +#ifdef CONFIG_PAX_USERCOPY
44935 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44936 +static noinline int check_stack_object(const void *obj, unsigned long len)
44937 +{
44938 + const void * const stack = task_stack_page(current);
44939 + const void * const stackend = stack + THREAD_SIZE;
44940 +
44941 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44942 + const void *frame = NULL;
44943 + const void *oldframe;
44944 +#endif
44945 +
44946 + if (obj + len < obj)
44947 + return -1;
44948 +
44949 + if (obj + len <= stack || stackend <= obj)
44950 + return 0;
44951 +
44952 + if (obj < stack || stackend < obj + len)
44953 + return -1;
44954 +
44955 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44956 + oldframe = __builtin_frame_address(1);
44957 + if (oldframe)
44958 + frame = __builtin_frame_address(2);
44959 + /*
44960 + low ----------------------------------------------> high
44961 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44962 + ^----------------^
44963 + allow copies only within here
44964 + */
44965 + while (stack <= frame && frame < stackend) {
44966 + /* if obj + len extends past the last frame, this
44967 + check won't pass and the next frame will be 0,
44968 + causing us to bail out and correctly report
44969 + the copy as invalid
44970 + */
44971 + if (obj + len <= frame)
44972 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44973 + oldframe = frame;
44974 + frame = *(const void * const *)frame;
44975 + }
44976 + return -1;
44977 +#else
44978 + return 1;
44979 +#endif
44980 +}
44981 +
44982 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44983 +{
44984 + if (current->signal->curr_ip)
44985 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44986 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44987 + else
44988 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44989 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44990 + dump_stack();
44991 + gr_handle_kernel_exploit();
44992 + do_group_exit(SIGKILL);
44993 +}
44994 +#endif
44995 +
44996 +void check_object_size(const void *ptr, unsigned long n, bool to)
44997 +{
44998 +
44999 +#ifdef CONFIG_PAX_USERCOPY
45000 + const char *type;
45001 +
45002 + if (!n)
45003 + return;
45004 +
45005 + type = check_heap_object(ptr, n, to);
45006 + if (!type) {
45007 + if (check_stack_object(ptr, n) != -1)
45008 + return;
45009 + type = "<process stack>";
45010 + }
45011 +
45012 + pax_report_usercopy(ptr, n, to, type);
45013 +#endif
45014 +
45015 +}
45016 +EXPORT_SYMBOL(check_object_size);
45017 +
45018 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45019 +void pax_track_stack(void)
45020 +{
45021 + unsigned long sp = (unsigned long)&sp;
45022 + if (sp < current_thread_info()->lowest_stack &&
45023 + sp > (unsigned long)task_stack_page(current))
45024 + current_thread_info()->lowest_stack = sp;
45025 +}
45026 +EXPORT_SYMBOL(pax_track_stack);
45027 +#endif
45028 +
45029 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45030 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45031 +{
45032 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45033 + dump_stack();
45034 + do_group_exit(SIGKILL);
45035 +}
45036 +EXPORT_SYMBOL(report_size_overflow);
45037 +#endif
45038 +
45039 static int zap_process(struct task_struct *start, int exit_code)
45040 {
45041 struct task_struct *t;
45042 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
45043 void set_dumpable(struct mm_struct *mm, int value)
45044 {
45045 switch (value) {
45046 - case 0:
45047 + case SUID_DUMPABLE_DISABLED:
45048 clear_bit(MMF_DUMPABLE, &mm->flags);
45049 smp_wmb();
45050 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45051 break;
45052 - case 1:
45053 + case SUID_DUMPABLE_ENABLED:
45054 set_bit(MMF_DUMPABLE, &mm->flags);
45055 smp_wmb();
45056 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45057 break;
45058 - case 2:
45059 + case SUID_DUMPABLE_SAFE:
45060 set_bit(MMF_DUMP_SECURELY, &mm->flags);
45061 smp_wmb();
45062 set_bit(MMF_DUMPABLE, &mm->flags);
45063 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
45064 int ret;
45065
45066 ret = mm_flags & MMF_DUMPABLE_MASK;
45067 - return (ret >= 2) ? 2 : ret;
45068 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
45069 }
45070
45071 int get_dumpable(struct mm_struct *mm)
45072 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45073 pipe = file->f_path.dentry->d_inode->i_pipe;
45074
45075 pipe_lock(pipe);
45076 - pipe->readers++;
45077 - pipe->writers--;
45078 + atomic_inc(&pipe->readers);
45079 + atomic_dec(&pipe->writers);
45080
45081 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45082 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45083 wake_up_interruptible_sync(&pipe->wait);
45084 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45085 pipe_wait(pipe);
45086 }
45087
45088 - pipe->readers--;
45089 - pipe->writers++;
45090 + atomic_dec(&pipe->readers);
45091 + atomic_inc(&pipe->writers);
45092 pipe_unlock(pipe);
45093
45094 }
45095 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45096 int retval = 0;
45097 int flag = 0;
45098 int ispipe;
45099 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45100 + bool need_nonrelative = false;
45101 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45102 struct coredump_params cprm = {
45103 .signr = signr,
45104 .regs = regs,
45105 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45106
45107 audit_core_dumps(signr);
45108
45109 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45110 + gr_handle_brute_attach(current, cprm.mm_flags);
45111 +
45112 binfmt = mm->binfmt;
45113 if (!binfmt || !binfmt->core_dump)
45114 goto fail;
45115 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45116 if (!cred)
45117 goto fail;
45118 /*
45119 - * We cannot trust fsuid as being the "true" uid of the
45120 - * process nor do we know its entire history. We only know it
45121 - * was tainted so we dump it as root in mode 2.
45122 + * We cannot trust fsuid as being the "true" uid of the process
45123 + * nor do we know its entire history. We only know it was tainted
45124 + * so we dump it as root in mode 2, and only into a controlled
45125 + * environment (pipe handler or fully qualified path).
45126 */
45127 - if (__get_dumpable(cprm.mm_flags) == 2) {
45128 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45129 /* Setuid core dump mode */
45130 flag = O_EXCL; /* Stop rewrite attacks */
45131 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45132 + need_nonrelative = true;
45133 }
45134
45135 retval = coredump_wait(exit_code, &core_state);
45136 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45137 }
45138 cprm.limit = RLIM_INFINITY;
45139
45140 - dump_count = atomic_inc_return(&core_dump_count);
45141 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45142 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45143 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45144 task_tgid_vnr(current), current->comm);
45145 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45146 } else {
45147 struct inode *inode;
45148
45149 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45150 +
45151 if (cprm.limit < binfmt->min_coredump)
45152 goto fail_unlock;
45153
45154 + if (need_nonrelative && cn.corename[0] != '/') {
45155 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45156 + "to fully qualified path!\n",
45157 + task_tgid_vnr(current), current->comm);
45158 + printk(KERN_WARNING "Skipping core dump\n");
45159 + goto fail_unlock;
45160 + }
45161 +
45162 cprm.file = filp_open(cn.corename,
45163 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45164 0600);
45165 @@ -2263,7 +2655,7 @@ close_fail:
45166 filp_close(cprm.file, NULL);
45167 fail_dropcount:
45168 if (ispipe)
45169 - atomic_dec(&core_dump_count);
45170 + atomic_dec_unchecked(&core_dump_count);
45171 fail_unlock:
45172 kfree(cn.corename);
45173 fail_corename:
45174 @@ -2282,7 +2674,7 @@ fail:
45175 */
45176 int dump_write(struct file *file, const void *addr, int nr)
45177 {
45178 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45179 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45180 }
45181 EXPORT_SYMBOL(dump_write);
45182
45183 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45184 index 1c36139..cf6b350 100644
45185 --- a/fs/ext2/balloc.c
45186 +++ b/fs/ext2/balloc.c
45187 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45188
45189 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45190 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45191 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45192 + if (free_blocks < root_blocks + 1 &&
45193 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45194 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45195 - !in_group_p (sbi->s_resgid))) {
45196 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45197 return 0;
45198 }
45199 return 1;
45200 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45201 index 25cd608..9ed5294 100644
45202 --- a/fs/ext3/balloc.c
45203 +++ b/fs/ext3/balloc.c
45204 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45205
45206 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45207 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45208 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45209 + if (free_blocks < root_blocks + 1 &&
45210 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45211 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45212 - !in_group_p (sbi->s_resgid))) {
45213 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45214 return 0;
45215 }
45216 return 1;
45217 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45218 index 1b50890..e56c5ad 100644
45219 --- a/fs/ext4/balloc.c
45220 +++ b/fs/ext4/balloc.c
45221 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45222 /* Hm, nope. Are (enough) root reserved clusters available? */
45223 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45224 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45225 - capable(CAP_SYS_RESOURCE) ||
45226 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45227 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45228 + capable_nolog(CAP_SYS_RESOURCE)) {
45229
45230 if (free_clusters >= (nclusters + dirty_clusters))
45231 return 1;
45232 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45233 index 01434f2..bd995b4 100644
45234 --- a/fs/ext4/ext4.h
45235 +++ b/fs/ext4/ext4.h
45236 @@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45237 unsigned long s_mb_last_start;
45238
45239 /* stats for buddy allocator */
45240 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45241 - atomic_t s_bal_success; /* we found long enough chunks */
45242 - atomic_t s_bal_allocated; /* in blocks */
45243 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45244 - atomic_t s_bal_goals; /* goal hits */
45245 - atomic_t s_bal_breaks; /* too long searches */
45246 - atomic_t s_bal_2orders; /* 2^order hits */
45247 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45248 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45249 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45250 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45251 + atomic_unchecked_t s_bal_goals; /* goal hits */
45252 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45253 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45254 spinlock_t s_bal_lock;
45255 unsigned long s_mb_buddies_generated;
45256 unsigned long long s_mb_generation_time;
45257 - atomic_t s_mb_lost_chunks;
45258 - atomic_t s_mb_preallocated;
45259 - atomic_t s_mb_discarded;
45260 + atomic_unchecked_t s_mb_lost_chunks;
45261 + atomic_unchecked_t s_mb_preallocated;
45262 + atomic_unchecked_t s_mb_discarded;
45263 atomic_t s_lock_busy;
45264
45265 /* locality groups */
45266 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45267 index 1cd6994..5799d45 100644
45268 --- a/fs/ext4/mballoc.c
45269 +++ b/fs/ext4/mballoc.c
45270 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45271 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45272
45273 if (EXT4_SB(sb)->s_mb_stats)
45274 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45275 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45276
45277 break;
45278 }
45279 @@ -2041,7 +2041,7 @@ repeat:
45280 ac->ac_status = AC_STATUS_CONTINUE;
45281 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45282 cr = 3;
45283 - atomic_inc(&sbi->s_mb_lost_chunks);
45284 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45285 goto repeat;
45286 }
45287 }
45288 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45289 if (sbi->s_mb_stats) {
45290 ext4_msg(sb, KERN_INFO,
45291 "mballoc: %u blocks %u reqs (%u success)",
45292 - atomic_read(&sbi->s_bal_allocated),
45293 - atomic_read(&sbi->s_bal_reqs),
45294 - atomic_read(&sbi->s_bal_success));
45295 + atomic_read_unchecked(&sbi->s_bal_allocated),
45296 + atomic_read_unchecked(&sbi->s_bal_reqs),
45297 + atomic_read_unchecked(&sbi->s_bal_success));
45298 ext4_msg(sb, KERN_INFO,
45299 "mballoc: %u extents scanned, %u goal hits, "
45300 "%u 2^N hits, %u breaks, %u lost",
45301 - atomic_read(&sbi->s_bal_ex_scanned),
45302 - atomic_read(&sbi->s_bal_goals),
45303 - atomic_read(&sbi->s_bal_2orders),
45304 - atomic_read(&sbi->s_bal_breaks),
45305 - atomic_read(&sbi->s_mb_lost_chunks));
45306 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45307 + atomic_read_unchecked(&sbi->s_bal_goals),
45308 + atomic_read_unchecked(&sbi->s_bal_2orders),
45309 + atomic_read_unchecked(&sbi->s_bal_breaks),
45310 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45311 ext4_msg(sb, KERN_INFO,
45312 "mballoc: %lu generated and it took %Lu",
45313 sbi->s_mb_buddies_generated,
45314 sbi->s_mb_generation_time);
45315 ext4_msg(sb, KERN_INFO,
45316 "mballoc: %u preallocated, %u discarded",
45317 - atomic_read(&sbi->s_mb_preallocated),
45318 - atomic_read(&sbi->s_mb_discarded));
45319 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45320 + atomic_read_unchecked(&sbi->s_mb_discarded));
45321 }
45322
45323 free_percpu(sbi->s_locality_groups);
45324 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45325 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45326
45327 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45328 - atomic_inc(&sbi->s_bal_reqs);
45329 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45330 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45331 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45332 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45333 - atomic_inc(&sbi->s_bal_success);
45334 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45335 + atomic_inc_unchecked(&sbi->s_bal_success);
45336 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45337 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45338 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45339 - atomic_inc(&sbi->s_bal_goals);
45340 + atomic_inc_unchecked(&sbi->s_bal_goals);
45341 if (ac->ac_found > sbi->s_mb_max_to_scan)
45342 - atomic_inc(&sbi->s_bal_breaks);
45343 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45344 }
45345
45346 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45347 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45348 trace_ext4_mb_new_inode_pa(ac, pa);
45349
45350 ext4_mb_use_inode_pa(ac, pa);
45351 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45352 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45353
45354 ei = EXT4_I(ac->ac_inode);
45355 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45356 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45357 trace_ext4_mb_new_group_pa(ac, pa);
45358
45359 ext4_mb_use_group_pa(ac, pa);
45360 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45361 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45362
45363 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45364 lg = ac->ac_lg;
45365 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45366 * from the bitmap and continue.
45367 */
45368 }
45369 - atomic_add(free, &sbi->s_mb_discarded);
45370 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45371
45372 return err;
45373 }
45374 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45375 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45376 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45377 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45378 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45379 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45380 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45381
45382 return 0;
45383 diff --git a/fs/fcntl.c b/fs/fcntl.c
45384 index 81b70e6..d9ae6cf 100644
45385 --- a/fs/fcntl.c
45386 +++ b/fs/fcntl.c
45387 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45388 if (err)
45389 return err;
45390
45391 + if (gr_handle_chroot_fowner(pid, type))
45392 + return -ENOENT;
45393 + if (gr_check_protected_task_fowner(pid, type))
45394 + return -EACCES;
45395 +
45396 f_modown(filp, pid, type, force);
45397 return 0;
45398 }
45399 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45400
45401 static int f_setown_ex(struct file *filp, unsigned long arg)
45402 {
45403 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45404 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45405 struct f_owner_ex owner;
45406 struct pid *pid;
45407 int type;
45408 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45409
45410 static int f_getown_ex(struct file *filp, unsigned long arg)
45411 {
45412 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45413 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45414 struct f_owner_ex owner;
45415 int ret = 0;
45416
45417 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45418 switch (cmd) {
45419 case F_DUPFD:
45420 case F_DUPFD_CLOEXEC:
45421 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45422 if (arg >= rlimit(RLIMIT_NOFILE))
45423 break;
45424 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45425 diff --git a/fs/fifo.c b/fs/fifo.c
45426 index cf6f434..3d7942c 100644
45427 --- a/fs/fifo.c
45428 +++ b/fs/fifo.c
45429 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45430 */
45431 filp->f_op = &read_pipefifo_fops;
45432 pipe->r_counter++;
45433 - if (pipe->readers++ == 0)
45434 + if (atomic_inc_return(&pipe->readers) == 1)
45435 wake_up_partner(inode);
45436
45437 - if (!pipe->writers) {
45438 + if (!atomic_read(&pipe->writers)) {
45439 if ((filp->f_flags & O_NONBLOCK)) {
45440 /* suppress POLLHUP until we have
45441 * seen a writer */
45442 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45443 * errno=ENXIO when there is no process reading the FIFO.
45444 */
45445 ret = -ENXIO;
45446 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45447 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45448 goto err;
45449
45450 filp->f_op = &write_pipefifo_fops;
45451 pipe->w_counter++;
45452 - if (!pipe->writers++)
45453 + if (atomic_inc_return(&pipe->writers) == 1)
45454 wake_up_partner(inode);
45455
45456 - if (!pipe->readers) {
45457 + if (!atomic_read(&pipe->readers)) {
45458 if (wait_for_partner(inode, &pipe->r_counter))
45459 goto err_wr;
45460 }
45461 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45462 */
45463 filp->f_op = &rdwr_pipefifo_fops;
45464
45465 - pipe->readers++;
45466 - pipe->writers++;
45467 + atomic_inc(&pipe->readers);
45468 + atomic_inc(&pipe->writers);
45469 pipe->r_counter++;
45470 pipe->w_counter++;
45471 - if (pipe->readers == 1 || pipe->writers == 1)
45472 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45473 wake_up_partner(inode);
45474 break;
45475
45476 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45477 return 0;
45478
45479 err_rd:
45480 - if (!--pipe->readers)
45481 + if (atomic_dec_and_test(&pipe->readers))
45482 wake_up_interruptible(&pipe->wait);
45483 ret = -ERESTARTSYS;
45484 goto err;
45485
45486 err_wr:
45487 - if (!--pipe->writers)
45488 + if (atomic_dec_and_test(&pipe->writers))
45489 wake_up_interruptible(&pipe->wait);
45490 ret = -ERESTARTSYS;
45491 goto err;
45492
45493 err:
45494 - if (!pipe->readers && !pipe->writers)
45495 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45496 free_pipe_info(inode);
45497
45498 err_nocleanup:
45499 diff --git a/fs/file.c b/fs/file.c
45500 index ba3f605..fade102 100644
45501 --- a/fs/file.c
45502 +++ b/fs/file.c
45503 @@ -15,6 +15,7 @@
45504 #include <linux/slab.h>
45505 #include <linux/vmalloc.h>
45506 #include <linux/file.h>
45507 +#include <linux/security.h>
45508 #include <linux/fdtable.h>
45509 #include <linux/bitops.h>
45510 #include <linux/interrupt.h>
45511 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45512 * N.B. For clone tasks sharing a files structure, this test
45513 * will limit the total number of files that can be opened.
45514 */
45515 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45516 if (nr >= rlimit(RLIMIT_NOFILE))
45517 return -EMFILE;
45518
45519 diff --git a/fs/filesystems.c b/fs/filesystems.c
45520 index 96f2428..f5eeb8e 100644
45521 --- a/fs/filesystems.c
45522 +++ b/fs/filesystems.c
45523 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45524 int len = dot ? dot - name : strlen(name);
45525
45526 fs = __get_fs_type(name, len);
45527 +
45528 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45529 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45530 +#else
45531 if (!fs && (request_module("%.*s", len, name) == 0))
45532 +#endif
45533 fs = __get_fs_type(name, len);
45534
45535 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45536 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45537 index e159e68..e7d2a6f 100644
45538 --- a/fs/fs_struct.c
45539 +++ b/fs/fs_struct.c
45540 @@ -4,6 +4,7 @@
45541 #include <linux/path.h>
45542 #include <linux/slab.h>
45543 #include <linux/fs_struct.h>
45544 +#include <linux/grsecurity.h>
45545 #include "internal.h"
45546
45547 static inline void path_get_longterm(struct path *path)
45548 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45549 write_seqcount_begin(&fs->seq);
45550 old_root = fs->root;
45551 fs->root = *path;
45552 + gr_set_chroot_entries(current, path);
45553 write_seqcount_end(&fs->seq);
45554 spin_unlock(&fs->lock);
45555 if (old_root.dentry)
45556 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45557 return 1;
45558 }
45559
45560 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45561 +{
45562 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45563 + return 0;
45564 + *p = *new;
45565 +
45566 + gr_set_chroot_entries(task, new);
45567 +
45568 + return 1;
45569 +}
45570 +
45571 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45572 {
45573 struct task_struct *g, *p;
45574 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45575 int hits = 0;
45576 spin_lock(&fs->lock);
45577 write_seqcount_begin(&fs->seq);
45578 - hits += replace_path(&fs->root, old_root, new_root);
45579 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45580 hits += replace_path(&fs->pwd, old_root, new_root);
45581 write_seqcount_end(&fs->seq);
45582 while (hits--) {
45583 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45584 task_lock(tsk);
45585 spin_lock(&fs->lock);
45586 tsk->fs = NULL;
45587 - kill = !--fs->users;
45588 + gr_clear_chroot_entries(tsk);
45589 + kill = !atomic_dec_return(&fs->users);
45590 spin_unlock(&fs->lock);
45591 task_unlock(tsk);
45592 if (kill)
45593 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45594 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45595 /* We don't need to lock fs - think why ;-) */
45596 if (fs) {
45597 - fs->users = 1;
45598 + atomic_set(&fs->users, 1);
45599 fs->in_exec = 0;
45600 spin_lock_init(&fs->lock);
45601 seqcount_init(&fs->seq);
45602 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45603 spin_lock(&old->lock);
45604 fs->root = old->root;
45605 path_get_longterm(&fs->root);
45606 + /* instead of calling gr_set_chroot_entries here,
45607 + we call it from every caller of this function
45608 + */
45609 fs->pwd = old->pwd;
45610 path_get_longterm(&fs->pwd);
45611 spin_unlock(&old->lock);
45612 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45613
45614 task_lock(current);
45615 spin_lock(&fs->lock);
45616 - kill = !--fs->users;
45617 + kill = !atomic_dec_return(&fs->users);
45618 current->fs = new_fs;
45619 + gr_set_chroot_entries(current, &new_fs->root);
45620 spin_unlock(&fs->lock);
45621 task_unlock(current);
45622
45623 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45624
45625 int current_umask(void)
45626 {
45627 - return current->fs->umask;
45628 + return current->fs->umask | gr_acl_umask();
45629 }
45630 EXPORT_SYMBOL(current_umask);
45631
45632 /* to be mentioned only in INIT_TASK */
45633 struct fs_struct init_fs = {
45634 - .users = 1,
45635 + .users = ATOMIC_INIT(1),
45636 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45637 .seq = SEQCNT_ZERO,
45638 .umask = 0022,
45639 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45640 task_lock(current);
45641
45642 spin_lock(&init_fs.lock);
45643 - init_fs.users++;
45644 + atomic_inc(&init_fs.users);
45645 spin_unlock(&init_fs.lock);
45646
45647 spin_lock(&fs->lock);
45648 current->fs = &init_fs;
45649 - kill = !--fs->users;
45650 + gr_set_chroot_entries(current, &current->fs->root);
45651 + kill = !atomic_dec_return(&fs->users);
45652 spin_unlock(&fs->lock);
45653
45654 task_unlock(current);
45655 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45656 index 9905350..02eaec4 100644
45657 --- a/fs/fscache/cookie.c
45658 +++ b/fs/fscache/cookie.c
45659 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45660 parent ? (char *) parent->def->name : "<no-parent>",
45661 def->name, netfs_data);
45662
45663 - fscache_stat(&fscache_n_acquires);
45664 + fscache_stat_unchecked(&fscache_n_acquires);
45665
45666 /* if there's no parent cookie, then we don't create one here either */
45667 if (!parent) {
45668 - fscache_stat(&fscache_n_acquires_null);
45669 + fscache_stat_unchecked(&fscache_n_acquires_null);
45670 _leave(" [no parent]");
45671 return NULL;
45672 }
45673 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45674 /* allocate and initialise a cookie */
45675 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45676 if (!cookie) {
45677 - fscache_stat(&fscache_n_acquires_oom);
45678 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45679 _leave(" [ENOMEM]");
45680 return NULL;
45681 }
45682 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45683
45684 switch (cookie->def->type) {
45685 case FSCACHE_COOKIE_TYPE_INDEX:
45686 - fscache_stat(&fscache_n_cookie_index);
45687 + fscache_stat_unchecked(&fscache_n_cookie_index);
45688 break;
45689 case FSCACHE_COOKIE_TYPE_DATAFILE:
45690 - fscache_stat(&fscache_n_cookie_data);
45691 + fscache_stat_unchecked(&fscache_n_cookie_data);
45692 break;
45693 default:
45694 - fscache_stat(&fscache_n_cookie_special);
45695 + fscache_stat_unchecked(&fscache_n_cookie_special);
45696 break;
45697 }
45698
45699 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45700 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45701 atomic_dec(&parent->n_children);
45702 __fscache_cookie_put(cookie);
45703 - fscache_stat(&fscache_n_acquires_nobufs);
45704 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45705 _leave(" = NULL");
45706 return NULL;
45707 }
45708 }
45709
45710 - fscache_stat(&fscache_n_acquires_ok);
45711 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45712 _leave(" = %p", cookie);
45713 return cookie;
45714 }
45715 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45716 cache = fscache_select_cache_for_object(cookie->parent);
45717 if (!cache) {
45718 up_read(&fscache_addremove_sem);
45719 - fscache_stat(&fscache_n_acquires_no_cache);
45720 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45721 _leave(" = -ENOMEDIUM [no cache]");
45722 return -ENOMEDIUM;
45723 }
45724 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45725 object = cache->ops->alloc_object(cache, cookie);
45726 fscache_stat_d(&fscache_n_cop_alloc_object);
45727 if (IS_ERR(object)) {
45728 - fscache_stat(&fscache_n_object_no_alloc);
45729 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45730 ret = PTR_ERR(object);
45731 goto error;
45732 }
45733
45734 - fscache_stat(&fscache_n_object_alloc);
45735 + fscache_stat_unchecked(&fscache_n_object_alloc);
45736
45737 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45738
45739 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45740 struct fscache_object *object;
45741 struct hlist_node *_p;
45742
45743 - fscache_stat(&fscache_n_updates);
45744 + fscache_stat_unchecked(&fscache_n_updates);
45745
45746 if (!cookie) {
45747 - fscache_stat(&fscache_n_updates_null);
45748 + fscache_stat_unchecked(&fscache_n_updates_null);
45749 _leave(" [no cookie]");
45750 return;
45751 }
45752 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45753 struct fscache_object *object;
45754 unsigned long event;
45755
45756 - fscache_stat(&fscache_n_relinquishes);
45757 + fscache_stat_unchecked(&fscache_n_relinquishes);
45758 if (retire)
45759 - fscache_stat(&fscache_n_relinquishes_retire);
45760 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45761
45762 if (!cookie) {
45763 - fscache_stat(&fscache_n_relinquishes_null);
45764 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45765 _leave(" [no cookie]");
45766 return;
45767 }
45768 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45769
45770 /* wait for the cookie to finish being instantiated (or to fail) */
45771 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45772 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45773 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45774 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45775 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45776 }
45777 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45778 index f6aad48..88dcf26 100644
45779 --- a/fs/fscache/internal.h
45780 +++ b/fs/fscache/internal.h
45781 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45782 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45783 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45784
45785 -extern atomic_t fscache_n_op_pend;
45786 -extern atomic_t fscache_n_op_run;
45787 -extern atomic_t fscache_n_op_enqueue;
45788 -extern atomic_t fscache_n_op_deferred_release;
45789 -extern atomic_t fscache_n_op_release;
45790 -extern atomic_t fscache_n_op_gc;
45791 -extern atomic_t fscache_n_op_cancelled;
45792 -extern atomic_t fscache_n_op_rejected;
45793 +extern atomic_unchecked_t fscache_n_op_pend;
45794 +extern atomic_unchecked_t fscache_n_op_run;
45795 +extern atomic_unchecked_t fscache_n_op_enqueue;
45796 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45797 +extern atomic_unchecked_t fscache_n_op_release;
45798 +extern atomic_unchecked_t fscache_n_op_gc;
45799 +extern atomic_unchecked_t fscache_n_op_cancelled;
45800 +extern atomic_unchecked_t fscache_n_op_rejected;
45801
45802 -extern atomic_t fscache_n_attr_changed;
45803 -extern atomic_t fscache_n_attr_changed_ok;
45804 -extern atomic_t fscache_n_attr_changed_nobufs;
45805 -extern atomic_t fscache_n_attr_changed_nomem;
45806 -extern atomic_t fscache_n_attr_changed_calls;
45807 +extern atomic_unchecked_t fscache_n_attr_changed;
45808 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45809 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45810 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45811 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45812
45813 -extern atomic_t fscache_n_allocs;
45814 -extern atomic_t fscache_n_allocs_ok;
45815 -extern atomic_t fscache_n_allocs_wait;
45816 -extern atomic_t fscache_n_allocs_nobufs;
45817 -extern atomic_t fscache_n_allocs_intr;
45818 -extern atomic_t fscache_n_allocs_object_dead;
45819 -extern atomic_t fscache_n_alloc_ops;
45820 -extern atomic_t fscache_n_alloc_op_waits;
45821 +extern atomic_unchecked_t fscache_n_allocs;
45822 +extern atomic_unchecked_t fscache_n_allocs_ok;
45823 +extern atomic_unchecked_t fscache_n_allocs_wait;
45824 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45825 +extern atomic_unchecked_t fscache_n_allocs_intr;
45826 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45827 +extern atomic_unchecked_t fscache_n_alloc_ops;
45828 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45829
45830 -extern atomic_t fscache_n_retrievals;
45831 -extern atomic_t fscache_n_retrievals_ok;
45832 -extern atomic_t fscache_n_retrievals_wait;
45833 -extern atomic_t fscache_n_retrievals_nodata;
45834 -extern atomic_t fscache_n_retrievals_nobufs;
45835 -extern atomic_t fscache_n_retrievals_intr;
45836 -extern atomic_t fscache_n_retrievals_nomem;
45837 -extern atomic_t fscache_n_retrievals_object_dead;
45838 -extern atomic_t fscache_n_retrieval_ops;
45839 -extern atomic_t fscache_n_retrieval_op_waits;
45840 +extern atomic_unchecked_t fscache_n_retrievals;
45841 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45842 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45843 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45844 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45845 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45846 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45847 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45848 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45849 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45850
45851 -extern atomic_t fscache_n_stores;
45852 -extern atomic_t fscache_n_stores_ok;
45853 -extern atomic_t fscache_n_stores_again;
45854 -extern atomic_t fscache_n_stores_nobufs;
45855 -extern atomic_t fscache_n_stores_oom;
45856 -extern atomic_t fscache_n_store_ops;
45857 -extern atomic_t fscache_n_store_calls;
45858 -extern atomic_t fscache_n_store_pages;
45859 -extern atomic_t fscache_n_store_radix_deletes;
45860 -extern atomic_t fscache_n_store_pages_over_limit;
45861 +extern atomic_unchecked_t fscache_n_stores;
45862 +extern atomic_unchecked_t fscache_n_stores_ok;
45863 +extern atomic_unchecked_t fscache_n_stores_again;
45864 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45865 +extern atomic_unchecked_t fscache_n_stores_oom;
45866 +extern atomic_unchecked_t fscache_n_store_ops;
45867 +extern atomic_unchecked_t fscache_n_store_calls;
45868 +extern atomic_unchecked_t fscache_n_store_pages;
45869 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45870 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45871
45872 -extern atomic_t fscache_n_store_vmscan_not_storing;
45873 -extern atomic_t fscache_n_store_vmscan_gone;
45874 -extern atomic_t fscache_n_store_vmscan_busy;
45875 -extern atomic_t fscache_n_store_vmscan_cancelled;
45876 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45877 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45878 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45879 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45880
45881 -extern atomic_t fscache_n_marks;
45882 -extern atomic_t fscache_n_uncaches;
45883 +extern atomic_unchecked_t fscache_n_marks;
45884 +extern atomic_unchecked_t fscache_n_uncaches;
45885
45886 -extern atomic_t fscache_n_acquires;
45887 -extern atomic_t fscache_n_acquires_null;
45888 -extern atomic_t fscache_n_acquires_no_cache;
45889 -extern atomic_t fscache_n_acquires_ok;
45890 -extern atomic_t fscache_n_acquires_nobufs;
45891 -extern atomic_t fscache_n_acquires_oom;
45892 +extern atomic_unchecked_t fscache_n_acquires;
45893 +extern atomic_unchecked_t fscache_n_acquires_null;
45894 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45895 +extern atomic_unchecked_t fscache_n_acquires_ok;
45896 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45897 +extern atomic_unchecked_t fscache_n_acquires_oom;
45898
45899 -extern atomic_t fscache_n_updates;
45900 -extern atomic_t fscache_n_updates_null;
45901 -extern atomic_t fscache_n_updates_run;
45902 +extern atomic_unchecked_t fscache_n_updates;
45903 +extern atomic_unchecked_t fscache_n_updates_null;
45904 +extern atomic_unchecked_t fscache_n_updates_run;
45905
45906 -extern atomic_t fscache_n_relinquishes;
45907 -extern atomic_t fscache_n_relinquishes_null;
45908 -extern atomic_t fscache_n_relinquishes_waitcrt;
45909 -extern atomic_t fscache_n_relinquishes_retire;
45910 +extern atomic_unchecked_t fscache_n_relinquishes;
45911 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45912 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45913 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45914
45915 -extern atomic_t fscache_n_cookie_index;
45916 -extern atomic_t fscache_n_cookie_data;
45917 -extern atomic_t fscache_n_cookie_special;
45918 +extern atomic_unchecked_t fscache_n_cookie_index;
45919 +extern atomic_unchecked_t fscache_n_cookie_data;
45920 +extern atomic_unchecked_t fscache_n_cookie_special;
45921
45922 -extern atomic_t fscache_n_object_alloc;
45923 -extern atomic_t fscache_n_object_no_alloc;
45924 -extern atomic_t fscache_n_object_lookups;
45925 -extern atomic_t fscache_n_object_lookups_negative;
45926 -extern atomic_t fscache_n_object_lookups_positive;
45927 -extern atomic_t fscache_n_object_lookups_timed_out;
45928 -extern atomic_t fscache_n_object_created;
45929 -extern atomic_t fscache_n_object_avail;
45930 -extern atomic_t fscache_n_object_dead;
45931 +extern atomic_unchecked_t fscache_n_object_alloc;
45932 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45933 +extern atomic_unchecked_t fscache_n_object_lookups;
45934 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45935 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45936 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45937 +extern atomic_unchecked_t fscache_n_object_created;
45938 +extern atomic_unchecked_t fscache_n_object_avail;
45939 +extern atomic_unchecked_t fscache_n_object_dead;
45940
45941 -extern atomic_t fscache_n_checkaux_none;
45942 -extern atomic_t fscache_n_checkaux_okay;
45943 -extern atomic_t fscache_n_checkaux_update;
45944 -extern atomic_t fscache_n_checkaux_obsolete;
45945 +extern atomic_unchecked_t fscache_n_checkaux_none;
45946 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45947 +extern atomic_unchecked_t fscache_n_checkaux_update;
45948 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45949
45950 extern atomic_t fscache_n_cop_alloc_object;
45951 extern atomic_t fscache_n_cop_lookup_object;
45952 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45953 atomic_inc(stat);
45954 }
45955
45956 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45957 +{
45958 + atomic_inc_unchecked(stat);
45959 +}
45960 +
45961 static inline void fscache_stat_d(atomic_t *stat)
45962 {
45963 atomic_dec(stat);
45964 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45965
45966 #define __fscache_stat(stat) (NULL)
45967 #define fscache_stat(stat) do {} while (0)
45968 +#define fscache_stat_unchecked(stat) do {} while (0)
45969 #define fscache_stat_d(stat) do {} while (0)
45970 #endif
45971
45972 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45973 index b6b897c..0ffff9c 100644
45974 --- a/fs/fscache/object.c
45975 +++ b/fs/fscache/object.c
45976 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45977 /* update the object metadata on disk */
45978 case FSCACHE_OBJECT_UPDATING:
45979 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45980 - fscache_stat(&fscache_n_updates_run);
45981 + fscache_stat_unchecked(&fscache_n_updates_run);
45982 fscache_stat(&fscache_n_cop_update_object);
45983 object->cache->ops->update_object(object);
45984 fscache_stat_d(&fscache_n_cop_update_object);
45985 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45986 spin_lock(&object->lock);
45987 object->state = FSCACHE_OBJECT_DEAD;
45988 spin_unlock(&object->lock);
45989 - fscache_stat(&fscache_n_object_dead);
45990 + fscache_stat_unchecked(&fscache_n_object_dead);
45991 goto terminal_transit;
45992
45993 /* handle the parent cache of this object being withdrawn from
45994 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45995 spin_lock(&object->lock);
45996 object->state = FSCACHE_OBJECT_DEAD;
45997 spin_unlock(&object->lock);
45998 - fscache_stat(&fscache_n_object_dead);
45999 + fscache_stat_unchecked(&fscache_n_object_dead);
46000 goto terminal_transit;
46001
46002 /* complain about the object being woken up once it is
46003 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46004 parent->cookie->def->name, cookie->def->name,
46005 object->cache->tag->name);
46006
46007 - fscache_stat(&fscache_n_object_lookups);
46008 + fscache_stat_unchecked(&fscache_n_object_lookups);
46009 fscache_stat(&fscache_n_cop_lookup_object);
46010 ret = object->cache->ops->lookup_object(object);
46011 fscache_stat_d(&fscache_n_cop_lookup_object);
46012 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46013 if (ret == -ETIMEDOUT) {
46014 /* probably stuck behind another object, so move this one to
46015 * the back of the queue */
46016 - fscache_stat(&fscache_n_object_lookups_timed_out);
46017 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46018 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46019 }
46020
46021 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46022
46023 spin_lock(&object->lock);
46024 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46025 - fscache_stat(&fscache_n_object_lookups_negative);
46026 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46027
46028 /* transit here to allow write requests to begin stacking up
46029 * and read requests to begin returning ENODATA */
46030 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46031 * result, in which case there may be data available */
46032 spin_lock(&object->lock);
46033 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46034 - fscache_stat(&fscache_n_object_lookups_positive);
46035 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46036
46037 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46038
46039 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46040 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46041 } else {
46042 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46043 - fscache_stat(&fscache_n_object_created);
46044 + fscache_stat_unchecked(&fscache_n_object_created);
46045
46046 object->state = FSCACHE_OBJECT_AVAILABLE;
46047 spin_unlock(&object->lock);
46048 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46049 fscache_enqueue_dependents(object);
46050
46051 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46052 - fscache_stat(&fscache_n_object_avail);
46053 + fscache_stat_unchecked(&fscache_n_object_avail);
46054
46055 _leave("");
46056 }
46057 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46058 enum fscache_checkaux result;
46059
46060 if (!object->cookie->def->check_aux) {
46061 - fscache_stat(&fscache_n_checkaux_none);
46062 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46063 return FSCACHE_CHECKAUX_OKAY;
46064 }
46065
46066 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46067 switch (result) {
46068 /* entry okay as is */
46069 case FSCACHE_CHECKAUX_OKAY:
46070 - fscache_stat(&fscache_n_checkaux_okay);
46071 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46072 break;
46073
46074 /* entry requires update */
46075 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46076 - fscache_stat(&fscache_n_checkaux_update);
46077 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46078 break;
46079
46080 /* entry requires deletion */
46081 case FSCACHE_CHECKAUX_OBSOLETE:
46082 - fscache_stat(&fscache_n_checkaux_obsolete);
46083 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46084 break;
46085
46086 default:
46087 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46088 index 30afdfa..2256596 100644
46089 --- a/fs/fscache/operation.c
46090 +++ b/fs/fscache/operation.c
46091 @@ -17,7 +17,7 @@
46092 #include <linux/slab.h>
46093 #include "internal.h"
46094
46095 -atomic_t fscache_op_debug_id;
46096 +atomic_unchecked_t fscache_op_debug_id;
46097 EXPORT_SYMBOL(fscache_op_debug_id);
46098
46099 /**
46100 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46101 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46102 ASSERTCMP(atomic_read(&op->usage), >, 0);
46103
46104 - fscache_stat(&fscache_n_op_enqueue);
46105 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46106 switch (op->flags & FSCACHE_OP_TYPE) {
46107 case FSCACHE_OP_ASYNC:
46108 _debug("queue async");
46109 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46110 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46111 if (op->processor)
46112 fscache_enqueue_operation(op);
46113 - fscache_stat(&fscache_n_op_run);
46114 + fscache_stat_unchecked(&fscache_n_op_run);
46115 }
46116
46117 /*
46118 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46119 if (object->n_ops > 1) {
46120 atomic_inc(&op->usage);
46121 list_add_tail(&op->pend_link, &object->pending_ops);
46122 - fscache_stat(&fscache_n_op_pend);
46123 + fscache_stat_unchecked(&fscache_n_op_pend);
46124 } else if (!list_empty(&object->pending_ops)) {
46125 atomic_inc(&op->usage);
46126 list_add_tail(&op->pend_link, &object->pending_ops);
46127 - fscache_stat(&fscache_n_op_pend);
46128 + fscache_stat_unchecked(&fscache_n_op_pend);
46129 fscache_start_operations(object);
46130 } else {
46131 ASSERTCMP(object->n_in_progress, ==, 0);
46132 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46133 object->n_exclusive++; /* reads and writes must wait */
46134 atomic_inc(&op->usage);
46135 list_add_tail(&op->pend_link, &object->pending_ops);
46136 - fscache_stat(&fscache_n_op_pend);
46137 + fscache_stat_unchecked(&fscache_n_op_pend);
46138 ret = 0;
46139 } else {
46140 /* not allowed to submit ops in any other state */
46141 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46142 if (object->n_exclusive > 0) {
46143 atomic_inc(&op->usage);
46144 list_add_tail(&op->pend_link, &object->pending_ops);
46145 - fscache_stat(&fscache_n_op_pend);
46146 + fscache_stat_unchecked(&fscache_n_op_pend);
46147 } else if (!list_empty(&object->pending_ops)) {
46148 atomic_inc(&op->usage);
46149 list_add_tail(&op->pend_link, &object->pending_ops);
46150 - fscache_stat(&fscache_n_op_pend);
46151 + fscache_stat_unchecked(&fscache_n_op_pend);
46152 fscache_start_operations(object);
46153 } else {
46154 ASSERTCMP(object->n_exclusive, ==, 0);
46155 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46156 object->n_ops++;
46157 atomic_inc(&op->usage);
46158 list_add_tail(&op->pend_link, &object->pending_ops);
46159 - fscache_stat(&fscache_n_op_pend);
46160 + fscache_stat_unchecked(&fscache_n_op_pend);
46161 ret = 0;
46162 } else if (object->state == FSCACHE_OBJECT_DYING ||
46163 object->state == FSCACHE_OBJECT_LC_DYING ||
46164 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46165 - fscache_stat(&fscache_n_op_rejected);
46166 + fscache_stat_unchecked(&fscache_n_op_rejected);
46167 ret = -ENOBUFS;
46168 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46169 fscache_report_unexpected_submission(object, op, ostate);
46170 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46171
46172 ret = -EBUSY;
46173 if (!list_empty(&op->pend_link)) {
46174 - fscache_stat(&fscache_n_op_cancelled);
46175 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46176 list_del_init(&op->pend_link);
46177 object->n_ops--;
46178 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46179 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46180 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46181 BUG();
46182
46183 - fscache_stat(&fscache_n_op_release);
46184 + fscache_stat_unchecked(&fscache_n_op_release);
46185
46186 if (op->release) {
46187 op->release(op);
46188 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46189 * lock, and defer it otherwise */
46190 if (!spin_trylock(&object->lock)) {
46191 _debug("defer put");
46192 - fscache_stat(&fscache_n_op_deferred_release);
46193 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46194
46195 cache = object->cache;
46196 spin_lock(&cache->op_gc_list_lock);
46197 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46198
46199 _debug("GC DEFERRED REL OBJ%x OP%x",
46200 object->debug_id, op->debug_id);
46201 - fscache_stat(&fscache_n_op_gc);
46202 + fscache_stat_unchecked(&fscache_n_op_gc);
46203
46204 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46205
46206 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46207 index 3f7a59b..cf196cc 100644
46208 --- a/fs/fscache/page.c
46209 +++ b/fs/fscache/page.c
46210 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46211 val = radix_tree_lookup(&cookie->stores, page->index);
46212 if (!val) {
46213 rcu_read_unlock();
46214 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46215 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46216 __fscache_uncache_page(cookie, page);
46217 return true;
46218 }
46219 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46220 spin_unlock(&cookie->stores_lock);
46221
46222 if (xpage) {
46223 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46224 - fscache_stat(&fscache_n_store_radix_deletes);
46225 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46226 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46227 ASSERTCMP(xpage, ==, page);
46228 } else {
46229 - fscache_stat(&fscache_n_store_vmscan_gone);
46230 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46231 }
46232
46233 wake_up_bit(&cookie->flags, 0);
46234 @@ -107,7 +107,7 @@ page_busy:
46235 /* we might want to wait here, but that could deadlock the allocator as
46236 * the work threads writing to the cache may all end up sleeping
46237 * on memory allocation */
46238 - fscache_stat(&fscache_n_store_vmscan_busy);
46239 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46240 return false;
46241 }
46242 EXPORT_SYMBOL(__fscache_maybe_release_page);
46243 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46244 FSCACHE_COOKIE_STORING_TAG);
46245 if (!radix_tree_tag_get(&cookie->stores, page->index,
46246 FSCACHE_COOKIE_PENDING_TAG)) {
46247 - fscache_stat(&fscache_n_store_radix_deletes);
46248 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46249 xpage = radix_tree_delete(&cookie->stores, page->index);
46250 }
46251 spin_unlock(&cookie->stores_lock);
46252 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46253
46254 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46255
46256 - fscache_stat(&fscache_n_attr_changed_calls);
46257 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46258
46259 if (fscache_object_is_active(object)) {
46260 fscache_stat(&fscache_n_cop_attr_changed);
46261 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46262
46263 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46264
46265 - fscache_stat(&fscache_n_attr_changed);
46266 + fscache_stat_unchecked(&fscache_n_attr_changed);
46267
46268 op = kzalloc(sizeof(*op), GFP_KERNEL);
46269 if (!op) {
46270 - fscache_stat(&fscache_n_attr_changed_nomem);
46271 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46272 _leave(" = -ENOMEM");
46273 return -ENOMEM;
46274 }
46275 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46276 if (fscache_submit_exclusive_op(object, op) < 0)
46277 goto nobufs;
46278 spin_unlock(&cookie->lock);
46279 - fscache_stat(&fscache_n_attr_changed_ok);
46280 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46281 fscache_put_operation(op);
46282 _leave(" = 0");
46283 return 0;
46284 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46285 nobufs:
46286 spin_unlock(&cookie->lock);
46287 kfree(op);
46288 - fscache_stat(&fscache_n_attr_changed_nobufs);
46289 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46290 _leave(" = %d", -ENOBUFS);
46291 return -ENOBUFS;
46292 }
46293 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46294 /* allocate a retrieval operation and attempt to submit it */
46295 op = kzalloc(sizeof(*op), GFP_NOIO);
46296 if (!op) {
46297 - fscache_stat(&fscache_n_retrievals_nomem);
46298 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46299 return NULL;
46300 }
46301
46302 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46303 return 0;
46304 }
46305
46306 - fscache_stat(&fscache_n_retrievals_wait);
46307 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46308
46309 jif = jiffies;
46310 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46311 fscache_wait_bit_interruptible,
46312 TASK_INTERRUPTIBLE) != 0) {
46313 - fscache_stat(&fscache_n_retrievals_intr);
46314 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46315 _leave(" = -ERESTARTSYS");
46316 return -ERESTARTSYS;
46317 }
46318 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46319 */
46320 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46321 struct fscache_retrieval *op,
46322 - atomic_t *stat_op_waits,
46323 - atomic_t *stat_object_dead)
46324 + atomic_unchecked_t *stat_op_waits,
46325 + atomic_unchecked_t *stat_object_dead)
46326 {
46327 int ret;
46328
46329 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46330 goto check_if_dead;
46331
46332 _debug(">>> WT");
46333 - fscache_stat(stat_op_waits);
46334 + fscache_stat_unchecked(stat_op_waits);
46335 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46336 fscache_wait_bit_interruptible,
46337 TASK_INTERRUPTIBLE) < 0) {
46338 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46339
46340 check_if_dead:
46341 if (unlikely(fscache_object_is_dead(object))) {
46342 - fscache_stat(stat_object_dead);
46343 + fscache_stat_unchecked(stat_object_dead);
46344 return -ENOBUFS;
46345 }
46346 return 0;
46347 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46348
46349 _enter("%p,%p,,,", cookie, page);
46350
46351 - fscache_stat(&fscache_n_retrievals);
46352 + fscache_stat_unchecked(&fscache_n_retrievals);
46353
46354 if (hlist_empty(&cookie->backing_objects))
46355 goto nobufs;
46356 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46357 goto nobufs_unlock;
46358 spin_unlock(&cookie->lock);
46359
46360 - fscache_stat(&fscache_n_retrieval_ops);
46361 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46362
46363 /* pin the netfs read context in case we need to do the actual netfs
46364 * read because we've encountered a cache read failure */
46365 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46366
46367 error:
46368 if (ret == -ENOMEM)
46369 - fscache_stat(&fscache_n_retrievals_nomem);
46370 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46371 else if (ret == -ERESTARTSYS)
46372 - fscache_stat(&fscache_n_retrievals_intr);
46373 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46374 else if (ret == -ENODATA)
46375 - fscache_stat(&fscache_n_retrievals_nodata);
46376 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46377 else if (ret < 0)
46378 - fscache_stat(&fscache_n_retrievals_nobufs);
46379 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46380 else
46381 - fscache_stat(&fscache_n_retrievals_ok);
46382 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46383
46384 fscache_put_retrieval(op);
46385 _leave(" = %d", ret);
46386 @@ -429,7 +429,7 @@ nobufs_unlock:
46387 spin_unlock(&cookie->lock);
46388 kfree(op);
46389 nobufs:
46390 - fscache_stat(&fscache_n_retrievals_nobufs);
46391 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46392 _leave(" = -ENOBUFS");
46393 return -ENOBUFS;
46394 }
46395 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46396
46397 _enter("%p,,%d,,,", cookie, *nr_pages);
46398
46399 - fscache_stat(&fscache_n_retrievals);
46400 + fscache_stat_unchecked(&fscache_n_retrievals);
46401
46402 if (hlist_empty(&cookie->backing_objects))
46403 goto nobufs;
46404 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46405 goto nobufs_unlock;
46406 spin_unlock(&cookie->lock);
46407
46408 - fscache_stat(&fscache_n_retrieval_ops);
46409 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46410
46411 /* pin the netfs read context in case we need to do the actual netfs
46412 * read because we've encountered a cache read failure */
46413 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46414
46415 error:
46416 if (ret == -ENOMEM)
46417 - fscache_stat(&fscache_n_retrievals_nomem);
46418 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46419 else if (ret == -ERESTARTSYS)
46420 - fscache_stat(&fscache_n_retrievals_intr);
46421 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46422 else if (ret == -ENODATA)
46423 - fscache_stat(&fscache_n_retrievals_nodata);
46424 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46425 else if (ret < 0)
46426 - fscache_stat(&fscache_n_retrievals_nobufs);
46427 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46428 else
46429 - fscache_stat(&fscache_n_retrievals_ok);
46430 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46431
46432 fscache_put_retrieval(op);
46433 _leave(" = %d", ret);
46434 @@ -545,7 +545,7 @@ nobufs_unlock:
46435 spin_unlock(&cookie->lock);
46436 kfree(op);
46437 nobufs:
46438 - fscache_stat(&fscache_n_retrievals_nobufs);
46439 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46440 _leave(" = -ENOBUFS");
46441 return -ENOBUFS;
46442 }
46443 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46444
46445 _enter("%p,%p,,,", cookie, page);
46446
46447 - fscache_stat(&fscache_n_allocs);
46448 + fscache_stat_unchecked(&fscache_n_allocs);
46449
46450 if (hlist_empty(&cookie->backing_objects))
46451 goto nobufs;
46452 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46453 goto nobufs_unlock;
46454 spin_unlock(&cookie->lock);
46455
46456 - fscache_stat(&fscache_n_alloc_ops);
46457 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46458
46459 ret = fscache_wait_for_retrieval_activation(
46460 object, op,
46461 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46462
46463 error:
46464 if (ret == -ERESTARTSYS)
46465 - fscache_stat(&fscache_n_allocs_intr);
46466 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46467 else if (ret < 0)
46468 - fscache_stat(&fscache_n_allocs_nobufs);
46469 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46470 else
46471 - fscache_stat(&fscache_n_allocs_ok);
46472 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46473
46474 fscache_put_retrieval(op);
46475 _leave(" = %d", ret);
46476 @@ -625,7 +625,7 @@ nobufs_unlock:
46477 spin_unlock(&cookie->lock);
46478 kfree(op);
46479 nobufs:
46480 - fscache_stat(&fscache_n_allocs_nobufs);
46481 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46482 _leave(" = -ENOBUFS");
46483 return -ENOBUFS;
46484 }
46485 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46486
46487 spin_lock(&cookie->stores_lock);
46488
46489 - fscache_stat(&fscache_n_store_calls);
46490 + fscache_stat_unchecked(&fscache_n_store_calls);
46491
46492 /* find a page to store */
46493 page = NULL;
46494 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46495 page = results[0];
46496 _debug("gang %d [%lx]", n, page->index);
46497 if (page->index > op->store_limit) {
46498 - fscache_stat(&fscache_n_store_pages_over_limit);
46499 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46500 goto superseded;
46501 }
46502
46503 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46504 spin_unlock(&cookie->stores_lock);
46505 spin_unlock(&object->lock);
46506
46507 - fscache_stat(&fscache_n_store_pages);
46508 + fscache_stat_unchecked(&fscache_n_store_pages);
46509 fscache_stat(&fscache_n_cop_write_page);
46510 ret = object->cache->ops->write_page(op, page);
46511 fscache_stat_d(&fscache_n_cop_write_page);
46512 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46513 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46514 ASSERT(PageFsCache(page));
46515
46516 - fscache_stat(&fscache_n_stores);
46517 + fscache_stat_unchecked(&fscache_n_stores);
46518
46519 op = kzalloc(sizeof(*op), GFP_NOIO);
46520 if (!op)
46521 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46522 spin_unlock(&cookie->stores_lock);
46523 spin_unlock(&object->lock);
46524
46525 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46526 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46527 op->store_limit = object->store_limit;
46528
46529 if (fscache_submit_op(object, &op->op) < 0)
46530 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46531
46532 spin_unlock(&cookie->lock);
46533 radix_tree_preload_end();
46534 - fscache_stat(&fscache_n_store_ops);
46535 - fscache_stat(&fscache_n_stores_ok);
46536 + fscache_stat_unchecked(&fscache_n_store_ops);
46537 + fscache_stat_unchecked(&fscache_n_stores_ok);
46538
46539 /* the work queue now carries its own ref on the object */
46540 fscache_put_operation(&op->op);
46541 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46542 return 0;
46543
46544 already_queued:
46545 - fscache_stat(&fscache_n_stores_again);
46546 + fscache_stat_unchecked(&fscache_n_stores_again);
46547 already_pending:
46548 spin_unlock(&cookie->stores_lock);
46549 spin_unlock(&object->lock);
46550 spin_unlock(&cookie->lock);
46551 radix_tree_preload_end();
46552 kfree(op);
46553 - fscache_stat(&fscache_n_stores_ok);
46554 + fscache_stat_unchecked(&fscache_n_stores_ok);
46555 _leave(" = 0");
46556 return 0;
46557
46558 @@ -851,14 +851,14 @@ nobufs:
46559 spin_unlock(&cookie->lock);
46560 radix_tree_preload_end();
46561 kfree(op);
46562 - fscache_stat(&fscache_n_stores_nobufs);
46563 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46564 _leave(" = -ENOBUFS");
46565 return -ENOBUFS;
46566
46567 nomem_free:
46568 kfree(op);
46569 nomem:
46570 - fscache_stat(&fscache_n_stores_oom);
46571 + fscache_stat_unchecked(&fscache_n_stores_oom);
46572 _leave(" = -ENOMEM");
46573 return -ENOMEM;
46574 }
46575 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46576 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46577 ASSERTCMP(page, !=, NULL);
46578
46579 - fscache_stat(&fscache_n_uncaches);
46580 + fscache_stat_unchecked(&fscache_n_uncaches);
46581
46582 /* cache withdrawal may beat us to it */
46583 if (!PageFsCache(page))
46584 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46585 unsigned long loop;
46586
46587 #ifdef CONFIG_FSCACHE_STATS
46588 - atomic_add(pagevec->nr, &fscache_n_marks);
46589 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46590 #endif
46591
46592 for (loop = 0; loop < pagevec->nr; loop++) {
46593 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46594 index 4765190..2a067f2 100644
46595 --- a/fs/fscache/stats.c
46596 +++ b/fs/fscache/stats.c
46597 @@ -18,95 +18,95 @@
46598 /*
46599 * operation counters
46600 */
46601 -atomic_t fscache_n_op_pend;
46602 -atomic_t fscache_n_op_run;
46603 -atomic_t fscache_n_op_enqueue;
46604 -atomic_t fscache_n_op_requeue;
46605 -atomic_t fscache_n_op_deferred_release;
46606 -atomic_t fscache_n_op_release;
46607 -atomic_t fscache_n_op_gc;
46608 -atomic_t fscache_n_op_cancelled;
46609 -atomic_t fscache_n_op_rejected;
46610 +atomic_unchecked_t fscache_n_op_pend;
46611 +atomic_unchecked_t fscache_n_op_run;
46612 +atomic_unchecked_t fscache_n_op_enqueue;
46613 +atomic_unchecked_t fscache_n_op_requeue;
46614 +atomic_unchecked_t fscache_n_op_deferred_release;
46615 +atomic_unchecked_t fscache_n_op_release;
46616 +atomic_unchecked_t fscache_n_op_gc;
46617 +atomic_unchecked_t fscache_n_op_cancelled;
46618 +atomic_unchecked_t fscache_n_op_rejected;
46619
46620 -atomic_t fscache_n_attr_changed;
46621 -atomic_t fscache_n_attr_changed_ok;
46622 -atomic_t fscache_n_attr_changed_nobufs;
46623 -atomic_t fscache_n_attr_changed_nomem;
46624 -atomic_t fscache_n_attr_changed_calls;
46625 +atomic_unchecked_t fscache_n_attr_changed;
46626 +atomic_unchecked_t fscache_n_attr_changed_ok;
46627 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46628 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46629 +atomic_unchecked_t fscache_n_attr_changed_calls;
46630
46631 -atomic_t fscache_n_allocs;
46632 -atomic_t fscache_n_allocs_ok;
46633 -atomic_t fscache_n_allocs_wait;
46634 -atomic_t fscache_n_allocs_nobufs;
46635 -atomic_t fscache_n_allocs_intr;
46636 -atomic_t fscache_n_allocs_object_dead;
46637 -atomic_t fscache_n_alloc_ops;
46638 -atomic_t fscache_n_alloc_op_waits;
46639 +atomic_unchecked_t fscache_n_allocs;
46640 +atomic_unchecked_t fscache_n_allocs_ok;
46641 +atomic_unchecked_t fscache_n_allocs_wait;
46642 +atomic_unchecked_t fscache_n_allocs_nobufs;
46643 +atomic_unchecked_t fscache_n_allocs_intr;
46644 +atomic_unchecked_t fscache_n_allocs_object_dead;
46645 +atomic_unchecked_t fscache_n_alloc_ops;
46646 +atomic_unchecked_t fscache_n_alloc_op_waits;
46647
46648 -atomic_t fscache_n_retrievals;
46649 -atomic_t fscache_n_retrievals_ok;
46650 -atomic_t fscache_n_retrievals_wait;
46651 -atomic_t fscache_n_retrievals_nodata;
46652 -atomic_t fscache_n_retrievals_nobufs;
46653 -atomic_t fscache_n_retrievals_intr;
46654 -atomic_t fscache_n_retrievals_nomem;
46655 -atomic_t fscache_n_retrievals_object_dead;
46656 -atomic_t fscache_n_retrieval_ops;
46657 -atomic_t fscache_n_retrieval_op_waits;
46658 +atomic_unchecked_t fscache_n_retrievals;
46659 +atomic_unchecked_t fscache_n_retrievals_ok;
46660 +atomic_unchecked_t fscache_n_retrievals_wait;
46661 +atomic_unchecked_t fscache_n_retrievals_nodata;
46662 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46663 +atomic_unchecked_t fscache_n_retrievals_intr;
46664 +atomic_unchecked_t fscache_n_retrievals_nomem;
46665 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46666 +atomic_unchecked_t fscache_n_retrieval_ops;
46667 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46668
46669 -atomic_t fscache_n_stores;
46670 -atomic_t fscache_n_stores_ok;
46671 -atomic_t fscache_n_stores_again;
46672 -atomic_t fscache_n_stores_nobufs;
46673 -atomic_t fscache_n_stores_oom;
46674 -atomic_t fscache_n_store_ops;
46675 -atomic_t fscache_n_store_calls;
46676 -atomic_t fscache_n_store_pages;
46677 -atomic_t fscache_n_store_radix_deletes;
46678 -atomic_t fscache_n_store_pages_over_limit;
46679 +atomic_unchecked_t fscache_n_stores;
46680 +atomic_unchecked_t fscache_n_stores_ok;
46681 +atomic_unchecked_t fscache_n_stores_again;
46682 +atomic_unchecked_t fscache_n_stores_nobufs;
46683 +atomic_unchecked_t fscache_n_stores_oom;
46684 +atomic_unchecked_t fscache_n_store_ops;
46685 +atomic_unchecked_t fscache_n_store_calls;
46686 +atomic_unchecked_t fscache_n_store_pages;
46687 +atomic_unchecked_t fscache_n_store_radix_deletes;
46688 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46689
46690 -atomic_t fscache_n_store_vmscan_not_storing;
46691 -atomic_t fscache_n_store_vmscan_gone;
46692 -atomic_t fscache_n_store_vmscan_busy;
46693 -atomic_t fscache_n_store_vmscan_cancelled;
46694 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46695 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46696 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46697 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46698
46699 -atomic_t fscache_n_marks;
46700 -atomic_t fscache_n_uncaches;
46701 +atomic_unchecked_t fscache_n_marks;
46702 +atomic_unchecked_t fscache_n_uncaches;
46703
46704 -atomic_t fscache_n_acquires;
46705 -atomic_t fscache_n_acquires_null;
46706 -atomic_t fscache_n_acquires_no_cache;
46707 -atomic_t fscache_n_acquires_ok;
46708 -atomic_t fscache_n_acquires_nobufs;
46709 -atomic_t fscache_n_acquires_oom;
46710 +atomic_unchecked_t fscache_n_acquires;
46711 +atomic_unchecked_t fscache_n_acquires_null;
46712 +atomic_unchecked_t fscache_n_acquires_no_cache;
46713 +atomic_unchecked_t fscache_n_acquires_ok;
46714 +atomic_unchecked_t fscache_n_acquires_nobufs;
46715 +atomic_unchecked_t fscache_n_acquires_oom;
46716
46717 -atomic_t fscache_n_updates;
46718 -atomic_t fscache_n_updates_null;
46719 -atomic_t fscache_n_updates_run;
46720 +atomic_unchecked_t fscache_n_updates;
46721 +atomic_unchecked_t fscache_n_updates_null;
46722 +atomic_unchecked_t fscache_n_updates_run;
46723
46724 -atomic_t fscache_n_relinquishes;
46725 -atomic_t fscache_n_relinquishes_null;
46726 -atomic_t fscache_n_relinquishes_waitcrt;
46727 -atomic_t fscache_n_relinquishes_retire;
46728 +atomic_unchecked_t fscache_n_relinquishes;
46729 +atomic_unchecked_t fscache_n_relinquishes_null;
46730 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46731 +atomic_unchecked_t fscache_n_relinquishes_retire;
46732
46733 -atomic_t fscache_n_cookie_index;
46734 -atomic_t fscache_n_cookie_data;
46735 -atomic_t fscache_n_cookie_special;
46736 +atomic_unchecked_t fscache_n_cookie_index;
46737 +atomic_unchecked_t fscache_n_cookie_data;
46738 +atomic_unchecked_t fscache_n_cookie_special;
46739
46740 -atomic_t fscache_n_object_alloc;
46741 -atomic_t fscache_n_object_no_alloc;
46742 -atomic_t fscache_n_object_lookups;
46743 -atomic_t fscache_n_object_lookups_negative;
46744 -atomic_t fscache_n_object_lookups_positive;
46745 -atomic_t fscache_n_object_lookups_timed_out;
46746 -atomic_t fscache_n_object_created;
46747 -atomic_t fscache_n_object_avail;
46748 -atomic_t fscache_n_object_dead;
46749 +atomic_unchecked_t fscache_n_object_alloc;
46750 +atomic_unchecked_t fscache_n_object_no_alloc;
46751 +atomic_unchecked_t fscache_n_object_lookups;
46752 +atomic_unchecked_t fscache_n_object_lookups_negative;
46753 +atomic_unchecked_t fscache_n_object_lookups_positive;
46754 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46755 +atomic_unchecked_t fscache_n_object_created;
46756 +atomic_unchecked_t fscache_n_object_avail;
46757 +atomic_unchecked_t fscache_n_object_dead;
46758
46759 -atomic_t fscache_n_checkaux_none;
46760 -atomic_t fscache_n_checkaux_okay;
46761 -atomic_t fscache_n_checkaux_update;
46762 -atomic_t fscache_n_checkaux_obsolete;
46763 +atomic_unchecked_t fscache_n_checkaux_none;
46764 +atomic_unchecked_t fscache_n_checkaux_okay;
46765 +atomic_unchecked_t fscache_n_checkaux_update;
46766 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46767
46768 atomic_t fscache_n_cop_alloc_object;
46769 atomic_t fscache_n_cop_lookup_object;
46770 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46771 seq_puts(m, "FS-Cache statistics\n");
46772
46773 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46774 - atomic_read(&fscache_n_cookie_index),
46775 - atomic_read(&fscache_n_cookie_data),
46776 - atomic_read(&fscache_n_cookie_special));
46777 + atomic_read_unchecked(&fscache_n_cookie_index),
46778 + atomic_read_unchecked(&fscache_n_cookie_data),
46779 + atomic_read_unchecked(&fscache_n_cookie_special));
46780
46781 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46782 - atomic_read(&fscache_n_object_alloc),
46783 - atomic_read(&fscache_n_object_no_alloc),
46784 - atomic_read(&fscache_n_object_avail),
46785 - atomic_read(&fscache_n_object_dead));
46786 + atomic_read_unchecked(&fscache_n_object_alloc),
46787 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46788 + atomic_read_unchecked(&fscache_n_object_avail),
46789 + atomic_read_unchecked(&fscache_n_object_dead));
46790 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46791 - atomic_read(&fscache_n_checkaux_none),
46792 - atomic_read(&fscache_n_checkaux_okay),
46793 - atomic_read(&fscache_n_checkaux_update),
46794 - atomic_read(&fscache_n_checkaux_obsolete));
46795 + atomic_read_unchecked(&fscache_n_checkaux_none),
46796 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46797 + atomic_read_unchecked(&fscache_n_checkaux_update),
46798 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46799
46800 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46801 - atomic_read(&fscache_n_marks),
46802 - atomic_read(&fscache_n_uncaches));
46803 + atomic_read_unchecked(&fscache_n_marks),
46804 + atomic_read_unchecked(&fscache_n_uncaches));
46805
46806 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46807 " oom=%u\n",
46808 - atomic_read(&fscache_n_acquires),
46809 - atomic_read(&fscache_n_acquires_null),
46810 - atomic_read(&fscache_n_acquires_no_cache),
46811 - atomic_read(&fscache_n_acquires_ok),
46812 - atomic_read(&fscache_n_acquires_nobufs),
46813 - atomic_read(&fscache_n_acquires_oom));
46814 + atomic_read_unchecked(&fscache_n_acquires),
46815 + atomic_read_unchecked(&fscache_n_acquires_null),
46816 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46817 + atomic_read_unchecked(&fscache_n_acquires_ok),
46818 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46819 + atomic_read_unchecked(&fscache_n_acquires_oom));
46820
46821 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46822 - atomic_read(&fscache_n_object_lookups),
46823 - atomic_read(&fscache_n_object_lookups_negative),
46824 - atomic_read(&fscache_n_object_lookups_positive),
46825 - atomic_read(&fscache_n_object_created),
46826 - atomic_read(&fscache_n_object_lookups_timed_out));
46827 + atomic_read_unchecked(&fscache_n_object_lookups),
46828 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46829 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46830 + atomic_read_unchecked(&fscache_n_object_created),
46831 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46832
46833 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46834 - atomic_read(&fscache_n_updates),
46835 - atomic_read(&fscache_n_updates_null),
46836 - atomic_read(&fscache_n_updates_run));
46837 + atomic_read_unchecked(&fscache_n_updates),
46838 + atomic_read_unchecked(&fscache_n_updates_null),
46839 + atomic_read_unchecked(&fscache_n_updates_run));
46840
46841 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46842 - atomic_read(&fscache_n_relinquishes),
46843 - atomic_read(&fscache_n_relinquishes_null),
46844 - atomic_read(&fscache_n_relinquishes_waitcrt),
46845 - atomic_read(&fscache_n_relinquishes_retire));
46846 + atomic_read_unchecked(&fscache_n_relinquishes),
46847 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46848 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46849 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46850
46851 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46852 - atomic_read(&fscache_n_attr_changed),
46853 - atomic_read(&fscache_n_attr_changed_ok),
46854 - atomic_read(&fscache_n_attr_changed_nobufs),
46855 - atomic_read(&fscache_n_attr_changed_nomem),
46856 - atomic_read(&fscache_n_attr_changed_calls));
46857 + atomic_read_unchecked(&fscache_n_attr_changed),
46858 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46859 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46860 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46861 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46862
46863 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46864 - atomic_read(&fscache_n_allocs),
46865 - atomic_read(&fscache_n_allocs_ok),
46866 - atomic_read(&fscache_n_allocs_wait),
46867 - atomic_read(&fscache_n_allocs_nobufs),
46868 - atomic_read(&fscache_n_allocs_intr));
46869 + atomic_read_unchecked(&fscache_n_allocs),
46870 + atomic_read_unchecked(&fscache_n_allocs_ok),
46871 + atomic_read_unchecked(&fscache_n_allocs_wait),
46872 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46873 + atomic_read_unchecked(&fscache_n_allocs_intr));
46874 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46875 - atomic_read(&fscache_n_alloc_ops),
46876 - atomic_read(&fscache_n_alloc_op_waits),
46877 - atomic_read(&fscache_n_allocs_object_dead));
46878 + atomic_read_unchecked(&fscache_n_alloc_ops),
46879 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46880 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46881
46882 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46883 " int=%u oom=%u\n",
46884 - atomic_read(&fscache_n_retrievals),
46885 - atomic_read(&fscache_n_retrievals_ok),
46886 - atomic_read(&fscache_n_retrievals_wait),
46887 - atomic_read(&fscache_n_retrievals_nodata),
46888 - atomic_read(&fscache_n_retrievals_nobufs),
46889 - atomic_read(&fscache_n_retrievals_intr),
46890 - atomic_read(&fscache_n_retrievals_nomem));
46891 + atomic_read_unchecked(&fscache_n_retrievals),
46892 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46893 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46894 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46895 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46896 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46897 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46898 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46899 - atomic_read(&fscache_n_retrieval_ops),
46900 - atomic_read(&fscache_n_retrieval_op_waits),
46901 - atomic_read(&fscache_n_retrievals_object_dead));
46902 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46903 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46904 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46905
46906 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46907 - atomic_read(&fscache_n_stores),
46908 - atomic_read(&fscache_n_stores_ok),
46909 - atomic_read(&fscache_n_stores_again),
46910 - atomic_read(&fscache_n_stores_nobufs),
46911 - atomic_read(&fscache_n_stores_oom));
46912 + atomic_read_unchecked(&fscache_n_stores),
46913 + atomic_read_unchecked(&fscache_n_stores_ok),
46914 + atomic_read_unchecked(&fscache_n_stores_again),
46915 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46916 + atomic_read_unchecked(&fscache_n_stores_oom));
46917 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46918 - atomic_read(&fscache_n_store_ops),
46919 - atomic_read(&fscache_n_store_calls),
46920 - atomic_read(&fscache_n_store_pages),
46921 - atomic_read(&fscache_n_store_radix_deletes),
46922 - atomic_read(&fscache_n_store_pages_over_limit));
46923 + atomic_read_unchecked(&fscache_n_store_ops),
46924 + atomic_read_unchecked(&fscache_n_store_calls),
46925 + atomic_read_unchecked(&fscache_n_store_pages),
46926 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46927 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46928
46929 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46930 - atomic_read(&fscache_n_store_vmscan_not_storing),
46931 - atomic_read(&fscache_n_store_vmscan_gone),
46932 - atomic_read(&fscache_n_store_vmscan_busy),
46933 - atomic_read(&fscache_n_store_vmscan_cancelled));
46934 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46935 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46936 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46937 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46938
46939 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46940 - atomic_read(&fscache_n_op_pend),
46941 - atomic_read(&fscache_n_op_run),
46942 - atomic_read(&fscache_n_op_enqueue),
46943 - atomic_read(&fscache_n_op_cancelled),
46944 - atomic_read(&fscache_n_op_rejected));
46945 + atomic_read_unchecked(&fscache_n_op_pend),
46946 + atomic_read_unchecked(&fscache_n_op_run),
46947 + atomic_read_unchecked(&fscache_n_op_enqueue),
46948 + atomic_read_unchecked(&fscache_n_op_cancelled),
46949 + atomic_read_unchecked(&fscache_n_op_rejected));
46950 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46951 - atomic_read(&fscache_n_op_deferred_release),
46952 - atomic_read(&fscache_n_op_release),
46953 - atomic_read(&fscache_n_op_gc));
46954 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46955 + atomic_read_unchecked(&fscache_n_op_release),
46956 + atomic_read_unchecked(&fscache_n_op_gc));
46957
46958 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46959 atomic_read(&fscache_n_cop_alloc_object),
46960 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46961 index 3426521..3b75162 100644
46962 --- a/fs/fuse/cuse.c
46963 +++ b/fs/fuse/cuse.c
46964 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46965 INIT_LIST_HEAD(&cuse_conntbl[i]);
46966
46967 /* inherit and extend fuse_dev_operations */
46968 - cuse_channel_fops = fuse_dev_operations;
46969 - cuse_channel_fops.owner = THIS_MODULE;
46970 - cuse_channel_fops.open = cuse_channel_open;
46971 - cuse_channel_fops.release = cuse_channel_release;
46972 + pax_open_kernel();
46973 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46974 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46975 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46976 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46977 + pax_close_kernel();
46978
46979 cuse_class = class_create(THIS_MODULE, "cuse");
46980 if (IS_ERR(cuse_class))
46981 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46982 index 7df2b5e..5804aa7 100644
46983 --- a/fs/fuse/dev.c
46984 +++ b/fs/fuse/dev.c
46985 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46986 ret = 0;
46987 pipe_lock(pipe);
46988
46989 - if (!pipe->readers) {
46990 + if (!atomic_read(&pipe->readers)) {
46991 send_sig(SIGPIPE, current, 0);
46992 if (!ret)
46993 ret = -EPIPE;
46994 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46995 index 334e0b1..fc571e8 100644
46996 --- a/fs/fuse/dir.c
46997 +++ b/fs/fuse/dir.c
46998 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46999 return link;
47000 }
47001
47002 -static void free_link(char *link)
47003 +static void free_link(const char *link)
47004 {
47005 if (!IS_ERR(link))
47006 free_page((unsigned long) link);
47007 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47008 index a9ba244..d9df391 100644
47009 --- a/fs/gfs2/inode.c
47010 +++ b/fs/gfs2/inode.c
47011 @@ -1496,7 +1496,7 @@ out:
47012
47013 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47014 {
47015 - char *s = nd_get_link(nd);
47016 + const char *s = nd_get_link(nd);
47017 if (!IS_ERR(s))
47018 kfree(s);
47019 }
47020 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47021 index cc9281b..58996fb 100644
47022 --- a/fs/hugetlbfs/inode.c
47023 +++ b/fs/hugetlbfs/inode.c
47024 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47025 .kill_sb = kill_litter_super,
47026 };
47027
47028 -static struct vfsmount *hugetlbfs_vfsmount;
47029 +struct vfsmount *hugetlbfs_vfsmount;
47030
47031 static int can_do_hugetlb_shm(void)
47032 {
47033 diff --git a/fs/inode.c b/fs/inode.c
47034 index c99163b..a11ad40 100644
47035 --- a/fs/inode.c
47036 +++ b/fs/inode.c
47037 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47038
47039 #ifdef CONFIG_SMP
47040 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47041 - static atomic_t shared_last_ino;
47042 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47043 + static atomic_unchecked_t shared_last_ino;
47044 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47045
47046 res = next - LAST_INO_BATCH;
47047 }
47048 diff --git a/fs/isofs/export.c b/fs/isofs/export.c
47049 index aa4356d..1d38044 100644
47050 --- a/fs/isofs/export.c
47051 +++ b/fs/isofs/export.c
47052 @@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
47053 len = 3;
47054 fh32[0] = ei->i_iget5_block;
47055 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
47056 + fh16[3] = 0; /* avoid leaking uninitialized data */
47057 fh32[2] = inode->i_generation;
47058 if (parent) {
47059 struct iso_inode_info *eparent;
47060 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47061 index 4a6cf28..d3a29d3 100644
47062 --- a/fs/jffs2/erase.c
47063 +++ b/fs/jffs2/erase.c
47064 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47065 struct jffs2_unknown_node marker = {
47066 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47067 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47068 - .totlen = cpu_to_je32(c->cleanmarker_size)
47069 + .totlen = cpu_to_je32(c->cleanmarker_size),
47070 + .hdr_crc = cpu_to_je32(0)
47071 };
47072
47073 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47074 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47075 index 6f4529d..bf12806 100644
47076 --- a/fs/jffs2/wbuf.c
47077 +++ b/fs/jffs2/wbuf.c
47078 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47079 {
47080 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47081 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47082 - .totlen = constant_cpu_to_je32(8)
47083 + .totlen = constant_cpu_to_je32(8),
47084 + .hdr_crc = constant_cpu_to_je32(0)
47085 };
47086
47087 /*
47088 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47089 index 4a82950..bcaa0cb 100644
47090 --- a/fs/jfs/super.c
47091 +++ b/fs/jfs/super.c
47092 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47093
47094 jfs_inode_cachep =
47095 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47096 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47097 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47098 init_once);
47099 if (jfs_inode_cachep == NULL)
47100 return -ENOMEM;
47101 diff --git a/fs/libfs.c b/fs/libfs.c
47102 index f86ec27..4734776 100644
47103 --- a/fs/libfs.c
47104 +++ b/fs/libfs.c
47105 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47106
47107 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47108 struct dentry *next;
47109 + char d_name[sizeof(next->d_iname)];
47110 + const unsigned char *name;
47111 +
47112 next = list_entry(p, struct dentry, d_u.d_child);
47113 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47114 if (!simple_positive(next)) {
47115 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47116
47117 spin_unlock(&next->d_lock);
47118 spin_unlock(&dentry->d_lock);
47119 - if (filldir(dirent, next->d_name.name,
47120 + name = next->d_name.name;
47121 + if (name == next->d_iname) {
47122 + memcpy(d_name, name, next->d_name.len);
47123 + name = d_name;
47124 + }
47125 + if (filldir(dirent, name,
47126 next->d_name.len, filp->f_pos,
47127 next->d_inode->i_ino,
47128 dt_type(next->d_inode)) < 0)
47129 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47130 index 8392cb8..80d6193 100644
47131 --- a/fs/lockd/clntproc.c
47132 +++ b/fs/lockd/clntproc.c
47133 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47134 /*
47135 * Cookie counter for NLM requests
47136 */
47137 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47138 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47139
47140 void nlmclnt_next_cookie(struct nlm_cookie *c)
47141 {
47142 - u32 cookie = atomic_inc_return(&nlm_cookie);
47143 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47144
47145 memcpy(c->data, &cookie, 4);
47146 c->len=4;
47147 diff --git a/fs/locks.c b/fs/locks.c
47148 index 82c3533..34e929c 100644
47149 --- a/fs/locks.c
47150 +++ b/fs/locks.c
47151 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47152 return;
47153
47154 if (filp->f_op && filp->f_op->flock) {
47155 - struct file_lock fl = {
47156 + struct file_lock flock = {
47157 .fl_pid = current->tgid,
47158 .fl_file = filp,
47159 .fl_flags = FL_FLOCK,
47160 .fl_type = F_UNLCK,
47161 .fl_end = OFFSET_MAX,
47162 };
47163 - filp->f_op->flock(filp, F_SETLKW, &fl);
47164 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47165 - fl.fl_ops->fl_release_private(&fl);
47166 + filp->f_op->flock(filp, F_SETLKW, &flock);
47167 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47168 + flock.fl_ops->fl_release_private(&flock);
47169 }
47170
47171 lock_flocks();
47172 diff --git a/fs/namei.c b/fs/namei.c
47173 index 7d69419..c7a09f0 100644
47174 --- a/fs/namei.c
47175 +++ b/fs/namei.c
47176 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47177 if (ret != -EACCES)
47178 return ret;
47179
47180 +#ifdef CONFIG_GRKERNSEC
47181 + /* we'll block if we have to log due to a denied capability use */
47182 + if (mask & MAY_NOT_BLOCK)
47183 + return -ECHILD;
47184 +#endif
47185 +
47186 if (S_ISDIR(inode->i_mode)) {
47187 /* DACs are overridable for directories */
47188 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47189 - return 0;
47190 if (!(mask & MAY_WRITE))
47191 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47192 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47193 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47194 return 0;
47195 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47196 + return 0;
47197 return -EACCES;
47198 }
47199 /*
47200 + * Searching includes executable on directories, else just read.
47201 + */
47202 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47203 + if (mask == MAY_READ)
47204 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47205 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47206 + return 0;
47207 +
47208 + /*
47209 * Read/write DACs are always overridable.
47210 * Executable DACs are overridable when there is
47211 * at least one exec bit set.
47212 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47213 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47214 return 0;
47215
47216 - /*
47217 - * Searching includes executable on directories, else just read.
47218 - */
47219 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47220 - if (mask == MAY_READ)
47221 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47222 - return 0;
47223 -
47224 return -EACCES;
47225 }
47226
47227 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47228 return error;
47229 }
47230
47231 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47232 + dentry->d_inode, dentry, nd->path.mnt)) {
47233 + error = -EACCES;
47234 + *p = ERR_PTR(error); /* no ->put_link(), please */
47235 + path_put(&nd->path);
47236 + return error;
47237 + }
47238 +
47239 nd->last_type = LAST_BIND;
47240 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47241 error = PTR_ERR(*p);
47242 if (!IS_ERR(*p)) {
47243 - char *s = nd_get_link(nd);
47244 + const char *s = nd_get_link(nd);
47245 error = 0;
47246 if (s)
47247 error = __vfs_follow_link(nd, s);
47248 @@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47249 if (!res)
47250 res = walk_component(nd, path, &nd->last,
47251 nd->last_type, LOOKUP_FOLLOW);
47252 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47253 + res = -EACCES;
47254 put_link(nd, &link, cookie);
47255 } while (res > 0);
47256
47257 @@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47258 err = follow_link(&link, nd, &cookie);
47259 if (!err)
47260 err = lookup_last(nd, &path);
47261 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47262 + err = -EACCES;
47263 put_link(nd, &link, cookie);
47264 }
47265 }
47266 @@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47267 if (!err)
47268 err = complete_walk(nd);
47269
47270 + if (!(nd->flags & LOOKUP_PARENT)) {
47271 +#ifdef CONFIG_GRKERNSEC
47272 + if (flags & LOOKUP_RCU) {
47273 + if (!err)
47274 + path_put(&nd->path);
47275 + err = -ECHILD;
47276 + } else
47277 +#endif
47278 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47279 + if (!err)
47280 + path_put(&nd->path);
47281 + err = -ENOENT;
47282 + }
47283 + }
47284 +
47285 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47286 if (!nd->inode->i_op->lookup) {
47287 path_put(&nd->path);
47288 @@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47289 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47290
47291 if (likely(!retval)) {
47292 + if (*name != '/' && nd->path.dentry && nd->inode) {
47293 +#ifdef CONFIG_GRKERNSEC
47294 + if (flags & LOOKUP_RCU)
47295 + return -ECHILD;
47296 +#endif
47297 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47298 + return -ENOENT;
47299 + }
47300 +
47301 if (unlikely(!audit_dummy_context())) {
47302 if (nd->path.dentry && nd->inode)
47303 audit_inode(name, nd->path.dentry);
47304 @@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47305 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47306 return -EPERM;
47307
47308 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47309 + return -EPERM;
47310 + if (gr_handle_rawio(inode))
47311 + return -EPERM;
47312 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47313 + return -EACCES;
47314 +
47315 return 0;
47316 }
47317
47318 @@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47319 /*
47320 * Handle the last step of open()
47321 */
47322 -static struct file *do_last(struct nameidata *nd, struct path *path,
47323 +static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47324 const struct open_flags *op, const char *pathname)
47325 {
47326 struct dentry *dir = nd->path.dentry;
47327 @@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47328 error = complete_walk(nd);
47329 if (error)
47330 return ERR_PTR(error);
47331 +#ifdef CONFIG_GRKERNSEC
47332 + if (nd->flags & LOOKUP_RCU) {
47333 + error = -ECHILD;
47334 + goto exit;
47335 + }
47336 +#endif
47337 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47338 + error = -ENOENT;
47339 + goto exit;
47340 + }
47341 audit_inode(pathname, nd->path.dentry);
47342 if (open_flag & O_CREAT) {
47343 error = -EISDIR;
47344 goto exit;
47345 }
47346 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47347 + error = -EACCES;
47348 + goto exit;
47349 + }
47350 goto ok;
47351 case LAST_BIND:
47352 error = complete_walk(nd);
47353 if (error)
47354 return ERR_PTR(error);
47355 +#ifdef CONFIG_GRKERNSEC
47356 + if (nd->flags & LOOKUP_RCU) {
47357 + error = -ECHILD;
47358 + goto exit;
47359 + }
47360 +#endif
47361 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47362 + error = -ENOENT;
47363 + goto exit;
47364 + }
47365 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47366 + error = -EACCES;
47367 + goto exit;
47368 + }
47369 audit_inode(pathname, dir);
47370 goto ok;
47371 }
47372 @@ -2285,6 +2364,17 @@ retry_lookup:
47373 /* Negative dentry, just create the file */
47374 if (!dentry->d_inode) {
47375 umode_t mode = op->mode;
47376 +
47377 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47378 + error = -EACCES;
47379 + goto exit_mutex_unlock;
47380 + }
47381 +
47382 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47383 + error = -EACCES;
47384 + goto exit_mutex_unlock;
47385 + }
47386 +
47387 if (!IS_POSIXACL(dir->d_inode))
47388 mode &= ~current_umask();
47389 /*
47390 @@ -2308,6 +2398,8 @@ retry_lookup:
47391 error = vfs_create(dir->d_inode, dentry, mode, nd);
47392 if (error)
47393 goto exit_mutex_unlock;
47394 + else
47395 + gr_handle_create(path->dentry, path->mnt);
47396 mutex_unlock(&dir->d_inode->i_mutex);
47397 dput(nd->path.dentry);
47398 nd->path.dentry = dentry;
47399 @@ -2317,6 +2409,23 @@ retry_lookup:
47400 /*
47401 * It already exists.
47402 */
47403 +
47404 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47405 + error = -ENOENT;
47406 + goto exit_mutex_unlock;
47407 + }
47408 + if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47409 + error = -EACCES;
47410 + goto exit_mutex_unlock;
47411 + }
47412 +
47413 + /* only check if O_CREAT is specified, all other checks need to go
47414 + into may_open */
47415 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47416 + error = -EACCES;
47417 + goto exit_mutex_unlock;
47418 + }
47419 +
47420 mutex_unlock(&dir->d_inode->i_mutex);
47421 audit_inode(pathname, path->dentry);
47422
47423 @@ -2349,6 +2458,11 @@ finish_lookup:
47424 }
47425 }
47426 BUG_ON(inode != path->dentry->d_inode);
47427 + /* if we're resolving a symlink to another symlink */
47428 + if (link && gr_handle_symlink_owner(link, inode)) {
47429 + error = -EACCES;
47430 + goto exit;
47431 + }
47432 return NULL;
47433 }
47434
47435 @@ -2358,7 +2472,6 @@ finish_lookup:
47436 save_parent.dentry = nd->path.dentry;
47437 save_parent.mnt = mntget(path->mnt);
47438 nd->path.dentry = path->dentry;
47439 -
47440 }
47441 nd->inode = inode;
47442 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47443 @@ -2367,6 +2480,21 @@ finish_lookup:
47444 path_put(&save_parent);
47445 return ERR_PTR(error);
47446 }
47447 +#ifdef CONFIG_GRKERNSEC
47448 + if (nd->flags & LOOKUP_RCU) {
47449 + error = -ECHILD;
47450 + goto exit;
47451 + }
47452 +#endif
47453 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47454 + error = -ENOENT;
47455 + goto exit;
47456 + }
47457 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47458 + error = -EACCES;
47459 + goto exit;
47460 + }
47461 +
47462 error = -EISDIR;
47463 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47464 goto exit;
47465 @@ -2461,7 +2589,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47466 if (unlikely(error))
47467 goto out_filp;
47468
47469 - filp = do_last(nd, &path, op, pathname);
47470 + filp = do_last(nd, &path, NULL, op, pathname);
47471 while (unlikely(!filp)) { /* trailing symlink */
47472 struct path link = path;
47473 void *cookie;
47474 @@ -2476,8 +2604,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47475 error = follow_link(&link, nd, &cookie);
47476 if (unlikely(error))
47477 filp = ERR_PTR(error);
47478 - else
47479 - filp = do_last(nd, &path, op, pathname);
47480 + else {
47481 + filp = do_last(nd, &path, &link, op, pathname);
47482 + }
47483 put_link(nd, &link, cookie);
47484 }
47485 out:
47486 @@ -2577,6 +2706,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47487 *path = nd.path;
47488 return dentry;
47489 eexist:
47490 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47491 + dput(dentry);
47492 + dentry = ERR_PTR(-ENOENT);
47493 + goto fail;
47494 + }
47495 dput(dentry);
47496 dentry = ERR_PTR(-EEXIST);
47497 fail:
47498 @@ -2599,6 +2733,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47499 }
47500 EXPORT_SYMBOL(user_path_create);
47501
47502 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47503 +{
47504 + char *tmp = getname(pathname);
47505 + struct dentry *res;
47506 + if (IS_ERR(tmp))
47507 + return ERR_CAST(tmp);
47508 + res = kern_path_create(dfd, tmp, path, is_dir);
47509 + if (IS_ERR(res))
47510 + putname(tmp);
47511 + else
47512 + *to = tmp;
47513 + return res;
47514 +}
47515 +
47516 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47517 {
47518 int error = may_create(dir, dentry);
47519 @@ -2665,6 +2813,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47520 error = mnt_want_write(path.mnt);
47521 if (error)
47522 goto out_dput;
47523 +
47524 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47525 + error = -EPERM;
47526 + goto out_drop_write;
47527 + }
47528 +
47529 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47530 + error = -EACCES;
47531 + goto out_drop_write;
47532 + }
47533 +
47534 error = security_path_mknod(&path, dentry, mode, dev);
47535 if (error)
47536 goto out_drop_write;
47537 @@ -2682,6 +2841,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47538 }
47539 out_drop_write:
47540 mnt_drop_write(path.mnt);
47541 +
47542 + if (!error)
47543 + gr_handle_create(dentry, path.mnt);
47544 out_dput:
47545 dput(dentry);
47546 mutex_unlock(&path.dentry->d_inode->i_mutex);
47547 @@ -2735,12 +2897,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47548 error = mnt_want_write(path.mnt);
47549 if (error)
47550 goto out_dput;
47551 +
47552 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47553 + error = -EACCES;
47554 + goto out_drop_write;
47555 + }
47556 +
47557 error = security_path_mkdir(&path, dentry, mode);
47558 if (error)
47559 goto out_drop_write;
47560 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47561 out_drop_write:
47562 mnt_drop_write(path.mnt);
47563 +
47564 + if (!error)
47565 + gr_handle_create(dentry, path.mnt);
47566 out_dput:
47567 dput(dentry);
47568 mutex_unlock(&path.dentry->d_inode->i_mutex);
47569 @@ -2820,6 +2991,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47570 char * name;
47571 struct dentry *dentry;
47572 struct nameidata nd;
47573 + ino_t saved_ino = 0;
47574 + dev_t saved_dev = 0;
47575
47576 error = user_path_parent(dfd, pathname, &nd, &name);
47577 if (error)
47578 @@ -2848,6 +3021,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47579 error = -ENOENT;
47580 goto exit3;
47581 }
47582 +
47583 + saved_ino = dentry->d_inode->i_ino;
47584 + saved_dev = gr_get_dev_from_dentry(dentry);
47585 +
47586 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47587 + error = -EACCES;
47588 + goto exit3;
47589 + }
47590 +
47591 error = mnt_want_write(nd.path.mnt);
47592 if (error)
47593 goto exit3;
47594 @@ -2855,6 +3037,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47595 if (error)
47596 goto exit4;
47597 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47598 + if (!error && (saved_dev || saved_ino))
47599 + gr_handle_delete(saved_ino, saved_dev);
47600 exit4:
47601 mnt_drop_write(nd.path.mnt);
47602 exit3:
47603 @@ -2917,6 +3101,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47604 struct dentry *dentry;
47605 struct nameidata nd;
47606 struct inode *inode = NULL;
47607 + ino_t saved_ino = 0;
47608 + dev_t saved_dev = 0;
47609
47610 error = user_path_parent(dfd, pathname, &nd, &name);
47611 if (error)
47612 @@ -2939,6 +3125,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47613 if (!inode)
47614 goto slashes;
47615 ihold(inode);
47616 +
47617 + if (inode->i_nlink <= 1) {
47618 + saved_ino = inode->i_ino;
47619 + saved_dev = gr_get_dev_from_dentry(dentry);
47620 + }
47621 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47622 + error = -EACCES;
47623 + goto exit2;
47624 + }
47625 +
47626 error = mnt_want_write(nd.path.mnt);
47627 if (error)
47628 goto exit2;
47629 @@ -2946,6 +3142,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47630 if (error)
47631 goto exit3;
47632 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47633 + if (!error && (saved_ino || saved_dev))
47634 + gr_handle_delete(saved_ino, saved_dev);
47635 exit3:
47636 mnt_drop_write(nd.path.mnt);
47637 exit2:
47638 @@ -3021,10 +3219,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47639 error = mnt_want_write(path.mnt);
47640 if (error)
47641 goto out_dput;
47642 +
47643 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47644 + error = -EACCES;
47645 + goto out_drop_write;
47646 + }
47647 +
47648 error = security_path_symlink(&path, dentry, from);
47649 if (error)
47650 goto out_drop_write;
47651 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47652 + if (!error)
47653 + gr_handle_create(dentry, path.mnt);
47654 out_drop_write:
47655 mnt_drop_write(path.mnt);
47656 out_dput:
47657 @@ -3099,6 +3305,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47658 {
47659 struct dentry *new_dentry;
47660 struct path old_path, new_path;
47661 + char *to = NULL;
47662 int how = 0;
47663 int error;
47664
47665 @@ -3122,7 +3329,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47666 if (error)
47667 return error;
47668
47669 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47670 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47671 error = PTR_ERR(new_dentry);
47672 if (IS_ERR(new_dentry))
47673 goto out;
47674 @@ -3133,13 +3340,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47675 error = mnt_want_write(new_path.mnt);
47676 if (error)
47677 goto out_dput;
47678 +
47679 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47680 + old_path.dentry->d_inode,
47681 + old_path.dentry->d_inode->i_mode, to)) {
47682 + error = -EACCES;
47683 + goto out_drop_write;
47684 + }
47685 +
47686 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47687 + old_path.dentry, old_path.mnt, to)) {
47688 + error = -EACCES;
47689 + goto out_drop_write;
47690 + }
47691 +
47692 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47693 if (error)
47694 goto out_drop_write;
47695 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47696 + if (!error)
47697 + gr_handle_create(new_dentry, new_path.mnt);
47698 out_drop_write:
47699 mnt_drop_write(new_path.mnt);
47700 out_dput:
47701 + putname(to);
47702 dput(new_dentry);
47703 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47704 path_put(&new_path);
47705 @@ -3373,6 +3597,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47706 if (new_dentry == trap)
47707 goto exit5;
47708
47709 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47710 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47711 + to);
47712 + if (error)
47713 + goto exit5;
47714 +
47715 error = mnt_want_write(oldnd.path.mnt);
47716 if (error)
47717 goto exit5;
47718 @@ -3382,6 +3612,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47719 goto exit6;
47720 error = vfs_rename(old_dir->d_inode, old_dentry,
47721 new_dir->d_inode, new_dentry);
47722 + if (!error)
47723 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47724 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47725 exit6:
47726 mnt_drop_write(oldnd.path.mnt);
47727 exit5:
47728 @@ -3407,6 +3640,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47729
47730 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47731 {
47732 + char tmpbuf[64];
47733 + const char *newlink;
47734 int len;
47735
47736 len = PTR_ERR(link);
47737 @@ -3416,7 +3651,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47738 len = strlen(link);
47739 if (len > (unsigned) buflen)
47740 len = buflen;
47741 - if (copy_to_user(buffer, link, len))
47742 +
47743 + if (len < sizeof(tmpbuf)) {
47744 + memcpy(tmpbuf, link, len);
47745 + newlink = tmpbuf;
47746 + } else
47747 + newlink = link;
47748 +
47749 + if (copy_to_user(buffer, newlink, len))
47750 len = -EFAULT;
47751 out:
47752 return len;
47753 diff --git a/fs/namespace.c b/fs/namespace.c
47754 index 1e4a5fe..a5ce747 100644
47755 --- a/fs/namespace.c
47756 +++ b/fs/namespace.c
47757 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47758 if (!(sb->s_flags & MS_RDONLY))
47759 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47760 up_write(&sb->s_umount);
47761 +
47762 + gr_log_remount(mnt->mnt_devname, retval);
47763 +
47764 return retval;
47765 }
47766
47767 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47768 br_write_unlock(&vfsmount_lock);
47769 up_write(&namespace_sem);
47770 release_mounts(&umount_list);
47771 +
47772 + gr_log_unmount(mnt->mnt_devname, retval);
47773 +
47774 return retval;
47775 }
47776
47777 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47778 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47779 MS_STRICTATIME);
47780
47781 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47782 + retval = -EPERM;
47783 + goto dput_out;
47784 + }
47785 +
47786 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47787 + retval = -EPERM;
47788 + goto dput_out;
47789 + }
47790 +
47791 if (flags & MS_REMOUNT)
47792 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47793 data_page);
47794 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47795 dev_name, data_page);
47796 dput_out:
47797 path_put(&path);
47798 +
47799 + gr_log_mount(dev_name, dir_name, retval);
47800 +
47801 return retval;
47802 }
47803
47804 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47805 if (error)
47806 goto out2;
47807
47808 + if (gr_handle_chroot_pivot()) {
47809 + error = -EPERM;
47810 + goto out2;
47811 + }
47812 +
47813 get_fs_root(current->fs, &root);
47814 error = lock_mount(&old);
47815 if (error)
47816 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47817 index f729698..2bac081 100644
47818 --- a/fs/nfs/inode.c
47819 +++ b/fs/nfs/inode.c
47820 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47821 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47822 nfsi->attrtimeo_timestamp = jiffies;
47823
47824 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47825 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47826 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47827 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47828 else
47829 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47830 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47831 }
47832
47833 -static atomic_long_t nfs_attr_generation_counter;
47834 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47835
47836 static unsigned long nfs_read_attr_generation_counter(void)
47837 {
47838 - return atomic_long_read(&nfs_attr_generation_counter);
47839 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47840 }
47841
47842 unsigned long nfs_inc_attr_generation_counter(void)
47843 {
47844 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47845 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47846 }
47847
47848 void nfs_fattr_init(struct nfs_fattr *fattr)
47849 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47850 index c8bd9c3..4f83416 100644
47851 --- a/fs/nfsd/vfs.c
47852 +++ b/fs/nfsd/vfs.c
47853 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47854 } else {
47855 oldfs = get_fs();
47856 set_fs(KERNEL_DS);
47857 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47858 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47859 set_fs(oldfs);
47860 }
47861
47862 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47863
47864 /* Write the data. */
47865 oldfs = get_fs(); set_fs(KERNEL_DS);
47866 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47867 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47868 set_fs(oldfs);
47869 if (host_err < 0)
47870 goto out_nfserr;
47871 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47872 */
47873
47874 oldfs = get_fs(); set_fs(KERNEL_DS);
47875 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47876 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47877 set_fs(oldfs);
47878
47879 if (host_err < 0)
47880 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47881 index 3568c8a..e0240d8 100644
47882 --- a/fs/notify/fanotify/fanotify_user.c
47883 +++ b/fs/notify/fanotify/fanotify_user.c
47884 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47885 goto out_close_fd;
47886
47887 ret = -EFAULT;
47888 - if (copy_to_user(buf, &fanotify_event_metadata,
47889 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47890 + copy_to_user(buf, &fanotify_event_metadata,
47891 fanotify_event_metadata.event_len))
47892 goto out_kill_access_response;
47893
47894 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47895 index c887b13..0fdf472 100644
47896 --- a/fs/notify/notification.c
47897 +++ b/fs/notify/notification.c
47898 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47899 * get set to 0 so it will never get 'freed'
47900 */
47901 static struct fsnotify_event *q_overflow_event;
47902 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47903 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47904
47905 /**
47906 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47907 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47908 */
47909 u32 fsnotify_get_cookie(void)
47910 {
47911 - return atomic_inc_return(&fsnotify_sync_cookie);
47912 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47913 }
47914 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47915
47916 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47917 index 99e3610..02c1068 100644
47918 --- a/fs/ntfs/dir.c
47919 +++ b/fs/ntfs/dir.c
47920 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47921 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47922 ~(s64)(ndir->itype.index.block_size - 1)));
47923 /* Bounds checks. */
47924 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47925 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47926 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47927 "inode 0x%lx or driver bug.", vdir->i_ino);
47928 goto err_out;
47929 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47930 index 7389d2d..dfd5dbe 100644
47931 --- a/fs/ntfs/file.c
47932 +++ b/fs/ntfs/file.c
47933 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47934 #endif /* NTFS_RW */
47935 };
47936
47937 -const struct file_operations ntfs_empty_file_ops = {};
47938 +const struct file_operations ntfs_empty_file_ops __read_only;
47939
47940 -const struct inode_operations ntfs_empty_inode_ops = {};
47941 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47942 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47943 index 210c352..a174f83 100644
47944 --- a/fs/ocfs2/localalloc.c
47945 +++ b/fs/ocfs2/localalloc.c
47946 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47947 goto bail;
47948 }
47949
47950 - atomic_inc(&osb->alloc_stats.moves);
47951 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47952
47953 bail:
47954 if (handle)
47955 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47956 index d355e6e..578d905 100644
47957 --- a/fs/ocfs2/ocfs2.h
47958 +++ b/fs/ocfs2/ocfs2.h
47959 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47960
47961 struct ocfs2_alloc_stats
47962 {
47963 - atomic_t moves;
47964 - atomic_t local_data;
47965 - atomic_t bitmap_data;
47966 - atomic_t bg_allocs;
47967 - atomic_t bg_extends;
47968 + atomic_unchecked_t moves;
47969 + atomic_unchecked_t local_data;
47970 + atomic_unchecked_t bitmap_data;
47971 + atomic_unchecked_t bg_allocs;
47972 + atomic_unchecked_t bg_extends;
47973 };
47974
47975 enum ocfs2_local_alloc_state
47976 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47977 index f169da4..9112253 100644
47978 --- a/fs/ocfs2/suballoc.c
47979 +++ b/fs/ocfs2/suballoc.c
47980 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47981 mlog_errno(status);
47982 goto bail;
47983 }
47984 - atomic_inc(&osb->alloc_stats.bg_extends);
47985 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47986
47987 /* You should never ask for this much metadata */
47988 BUG_ON(bits_wanted >
47989 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47990 mlog_errno(status);
47991 goto bail;
47992 }
47993 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47994 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47995
47996 *suballoc_loc = res.sr_bg_blkno;
47997 *suballoc_bit_start = res.sr_bit_offset;
47998 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47999 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48000 res->sr_bits);
48001
48002 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48003 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48004
48005 BUG_ON(res->sr_bits != 1);
48006
48007 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48008 mlog_errno(status);
48009 goto bail;
48010 }
48011 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48012 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48013
48014 BUG_ON(res.sr_bits != 1);
48015
48016 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48017 cluster_start,
48018 num_clusters);
48019 if (!status)
48020 - atomic_inc(&osb->alloc_stats.local_data);
48021 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48022 } else {
48023 if (min_clusters > (osb->bitmap_cpg - 1)) {
48024 /* The only paths asking for contiguousness
48025 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48026 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48027 res.sr_bg_blkno,
48028 res.sr_bit_offset);
48029 - atomic_inc(&osb->alloc_stats.bitmap_data);
48030 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48031 *num_clusters = res.sr_bits;
48032 }
48033 }
48034 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48035 index 68f4541..89cfe6a 100644
48036 --- a/fs/ocfs2/super.c
48037 +++ b/fs/ocfs2/super.c
48038 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48039 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48040 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48041 "Stats",
48042 - atomic_read(&osb->alloc_stats.bitmap_data),
48043 - atomic_read(&osb->alloc_stats.local_data),
48044 - atomic_read(&osb->alloc_stats.bg_allocs),
48045 - atomic_read(&osb->alloc_stats.moves),
48046 - atomic_read(&osb->alloc_stats.bg_extends));
48047 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48048 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48049 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48050 + atomic_read_unchecked(&osb->alloc_stats.moves),
48051 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48052
48053 out += snprintf(buf + out, len - out,
48054 "%10s => State: %u Descriptor: %llu Size: %u bits "
48055 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48056 spin_lock_init(&osb->osb_xattr_lock);
48057 ocfs2_init_steal_slots(osb);
48058
48059 - atomic_set(&osb->alloc_stats.moves, 0);
48060 - atomic_set(&osb->alloc_stats.local_data, 0);
48061 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48062 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48063 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48064 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48065 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48066 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48067 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48068 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48069
48070 /* Copy the blockcheck stats from the superblock probe */
48071 osb->osb_ecc_stats = *stats;
48072 diff --git a/fs/open.c b/fs/open.c
48073 index 1540632..79d7242 100644
48074 --- a/fs/open.c
48075 +++ b/fs/open.c
48076 @@ -31,6 +31,8 @@
48077 #include <linux/ima.h>
48078 #include <linux/dnotify.h>
48079
48080 +#define CREATE_TRACE_POINTS
48081 +#include <trace/events/fs.h>
48082 #include "internal.h"
48083
48084 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48085 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48086 error = locks_verify_truncate(inode, NULL, length);
48087 if (!error)
48088 error = security_path_truncate(&path);
48089 +
48090 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48091 + error = -EACCES;
48092 +
48093 if (!error)
48094 error = do_truncate(path.dentry, length, 0, NULL);
48095
48096 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48097 if (__mnt_is_readonly(path.mnt))
48098 res = -EROFS;
48099
48100 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48101 + res = -EACCES;
48102 +
48103 out_path_release:
48104 path_put(&path);
48105 out:
48106 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48107 if (error)
48108 goto dput_and_out;
48109
48110 + gr_log_chdir(path.dentry, path.mnt);
48111 +
48112 set_fs_pwd(current->fs, &path);
48113
48114 dput_and_out:
48115 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48116 goto out_putf;
48117
48118 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48119 +
48120 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48121 + error = -EPERM;
48122 +
48123 + if (!error)
48124 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48125 +
48126 if (!error)
48127 set_fs_pwd(current->fs, &file->f_path);
48128 out_putf:
48129 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48130 if (error)
48131 goto dput_and_out;
48132
48133 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48134 + goto dput_and_out;
48135 +
48136 set_fs_root(current->fs, &path);
48137 +
48138 + gr_handle_chroot_chdir(&path);
48139 +
48140 error = 0;
48141 dput_and_out:
48142 path_put(&path);
48143 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48144 if (error)
48145 return error;
48146 mutex_lock(&inode->i_mutex);
48147 +
48148 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48149 + error = -EACCES;
48150 + goto out_unlock;
48151 + }
48152 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48153 + error = -EACCES;
48154 + goto out_unlock;
48155 + }
48156 +
48157 error = security_path_chmod(path, mode);
48158 if (error)
48159 goto out_unlock;
48160 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48161 uid = make_kuid(current_user_ns(), user);
48162 gid = make_kgid(current_user_ns(), group);
48163
48164 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48165 + return -EACCES;
48166 +
48167 newattrs.ia_valid = ATTR_CTIME;
48168 if (user != (uid_t) -1) {
48169 if (!uid_valid(uid))
48170 @@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48171 } else {
48172 fsnotify_open(f);
48173 fd_install(fd, f);
48174 + trace_do_sys_open(tmp, flags, mode);
48175 }
48176 }
48177 putname(tmp);
48178 diff --git a/fs/pipe.c b/fs/pipe.c
48179 index 49c1065..13b9e12 100644
48180 --- a/fs/pipe.c
48181 +++ b/fs/pipe.c
48182 @@ -438,9 +438,9 @@ redo:
48183 }
48184 if (bufs) /* More to do? */
48185 continue;
48186 - if (!pipe->writers)
48187 + if (!atomic_read(&pipe->writers))
48188 break;
48189 - if (!pipe->waiting_writers) {
48190 + if (!atomic_read(&pipe->waiting_writers)) {
48191 /* syscall merging: Usually we must not sleep
48192 * if O_NONBLOCK is set, or if we got some data.
48193 * But if a writer sleeps in kernel space, then
48194 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48195 mutex_lock(&inode->i_mutex);
48196 pipe = inode->i_pipe;
48197
48198 - if (!pipe->readers) {
48199 + if (!atomic_read(&pipe->readers)) {
48200 send_sig(SIGPIPE, current, 0);
48201 ret = -EPIPE;
48202 goto out;
48203 @@ -553,7 +553,7 @@ redo1:
48204 for (;;) {
48205 int bufs;
48206
48207 - if (!pipe->readers) {
48208 + if (!atomic_read(&pipe->readers)) {
48209 send_sig(SIGPIPE, current, 0);
48210 if (!ret)
48211 ret = -EPIPE;
48212 @@ -644,9 +644,9 @@ redo2:
48213 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48214 do_wakeup = 0;
48215 }
48216 - pipe->waiting_writers++;
48217 + atomic_inc(&pipe->waiting_writers);
48218 pipe_wait(pipe);
48219 - pipe->waiting_writers--;
48220 + atomic_dec(&pipe->waiting_writers);
48221 }
48222 out:
48223 mutex_unlock(&inode->i_mutex);
48224 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48225 mask = 0;
48226 if (filp->f_mode & FMODE_READ) {
48227 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48228 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48229 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48230 mask |= POLLHUP;
48231 }
48232
48233 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48234 * Most Unices do not set POLLERR for FIFOs but on Linux they
48235 * behave exactly like pipes for poll().
48236 */
48237 - if (!pipe->readers)
48238 + if (!atomic_read(&pipe->readers))
48239 mask |= POLLERR;
48240 }
48241
48242 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48243
48244 mutex_lock(&inode->i_mutex);
48245 pipe = inode->i_pipe;
48246 - pipe->readers -= decr;
48247 - pipe->writers -= decw;
48248 + atomic_sub(decr, &pipe->readers);
48249 + atomic_sub(decw, &pipe->writers);
48250
48251 - if (!pipe->readers && !pipe->writers) {
48252 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48253 free_pipe_info(inode);
48254 } else {
48255 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48256 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48257
48258 if (inode->i_pipe) {
48259 ret = 0;
48260 - inode->i_pipe->readers++;
48261 + atomic_inc(&inode->i_pipe->readers);
48262 }
48263
48264 mutex_unlock(&inode->i_mutex);
48265 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48266
48267 if (inode->i_pipe) {
48268 ret = 0;
48269 - inode->i_pipe->writers++;
48270 + atomic_inc(&inode->i_pipe->writers);
48271 }
48272
48273 mutex_unlock(&inode->i_mutex);
48274 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48275 if (inode->i_pipe) {
48276 ret = 0;
48277 if (filp->f_mode & FMODE_READ)
48278 - inode->i_pipe->readers++;
48279 + atomic_inc(&inode->i_pipe->readers);
48280 if (filp->f_mode & FMODE_WRITE)
48281 - inode->i_pipe->writers++;
48282 + atomic_inc(&inode->i_pipe->writers);
48283 }
48284
48285 mutex_unlock(&inode->i_mutex);
48286 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48287 inode->i_pipe = NULL;
48288 }
48289
48290 -static struct vfsmount *pipe_mnt __read_mostly;
48291 +struct vfsmount *pipe_mnt __read_mostly;
48292
48293 /*
48294 * pipefs_dname() is called from d_path().
48295 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48296 goto fail_iput;
48297 inode->i_pipe = pipe;
48298
48299 - pipe->readers = pipe->writers = 1;
48300 + atomic_set(&pipe->readers, 1);
48301 + atomic_set(&pipe->writers, 1);
48302 inode->i_fop = &rdwr_pipefifo_fops;
48303
48304 /*
48305 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48306 index 15af622..0e9f4467 100644
48307 --- a/fs/proc/Kconfig
48308 +++ b/fs/proc/Kconfig
48309 @@ -30,12 +30,12 @@ config PROC_FS
48310
48311 config PROC_KCORE
48312 bool "/proc/kcore support" if !ARM
48313 - depends on PROC_FS && MMU
48314 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48315
48316 config PROC_VMCORE
48317 bool "/proc/vmcore support"
48318 - depends on PROC_FS && CRASH_DUMP
48319 - default y
48320 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48321 + default n
48322 help
48323 Exports the dump image of crashed kernel in ELF format.
48324
48325 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48326 limited in memory.
48327
48328 config PROC_PAGE_MONITOR
48329 - default y
48330 - depends on PROC_FS && MMU
48331 + default n
48332 + depends on PROC_FS && MMU && !GRKERNSEC
48333 bool "Enable /proc page monitoring" if EXPERT
48334 help
48335 Various /proc files exist to monitor process memory utilization:
48336 diff --git a/fs/proc/array.c b/fs/proc/array.c
48337 index c1c207c..5179411 100644
48338 --- a/fs/proc/array.c
48339 +++ b/fs/proc/array.c
48340 @@ -60,6 +60,7 @@
48341 #include <linux/tty.h>
48342 #include <linux/string.h>
48343 #include <linux/mman.h>
48344 +#include <linux/grsecurity.h>
48345 #include <linux/proc_fs.h>
48346 #include <linux/ioport.h>
48347 #include <linux/uaccess.h>
48348 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48349 seq_putc(m, '\n');
48350 }
48351
48352 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48353 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48354 +{
48355 + if (p->mm)
48356 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48357 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48358 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48359 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48360 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48361 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48362 + else
48363 + seq_printf(m, "PaX:\t-----\n");
48364 +}
48365 +#endif
48366 +
48367 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48368 struct pid *pid, struct task_struct *task)
48369 {
48370 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48371 task_cpus_allowed(m, task);
48372 cpuset_task_status_allowed(m, task);
48373 task_context_switch_counts(m, task);
48374 +
48375 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48376 + task_pax(m, task);
48377 +#endif
48378 +
48379 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48380 + task_grsec_rbac(m, task);
48381 +#endif
48382 +
48383 return 0;
48384 }
48385
48386 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48387 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48388 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48389 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48390 +#endif
48391 +
48392 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48393 struct pid *pid, struct task_struct *task, int whole)
48394 {
48395 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48396 char tcomm[sizeof(task->comm)];
48397 unsigned long flags;
48398
48399 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48400 + if (current->exec_id != m->exec_id) {
48401 + gr_log_badprocpid("stat");
48402 + return 0;
48403 + }
48404 +#endif
48405 +
48406 state = *get_task_state(task);
48407 vsize = eip = esp = 0;
48408 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48409 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48410 gtime = task->gtime;
48411 }
48412
48413 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48414 + if (PAX_RAND_FLAGS(mm)) {
48415 + eip = 0;
48416 + esp = 0;
48417 + wchan = 0;
48418 + }
48419 +#endif
48420 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48421 + wchan = 0;
48422 + eip =0;
48423 + esp =0;
48424 +#endif
48425 +
48426 /* scale priority and nice values from timeslices to -20..20 */
48427 /* to make it look like a "normal" Unix priority/nice value */
48428 priority = task_prio(task);
48429 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48430 seq_put_decimal_ull(m, ' ', vsize);
48431 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48432 seq_put_decimal_ull(m, ' ', rsslim);
48433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48434 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48435 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48436 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48437 +#else
48438 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48439 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48440 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48441 +#endif
48442 seq_put_decimal_ull(m, ' ', esp);
48443 seq_put_decimal_ull(m, ' ', eip);
48444 /* The signal information here is obsolete.
48445 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48446 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48447 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48448
48449 - if (mm && permitted) {
48450 + if (mm && permitted
48451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48452 + && !PAX_RAND_FLAGS(mm)
48453 +#endif
48454 + ) {
48455 seq_put_decimal_ull(m, ' ', mm->start_data);
48456 seq_put_decimal_ull(m, ' ', mm->end_data);
48457 seq_put_decimal_ull(m, ' ', mm->start_brk);
48458 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48459 struct pid *pid, struct task_struct *task)
48460 {
48461 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48462 - struct mm_struct *mm = get_task_mm(task);
48463 + struct mm_struct *mm;
48464
48465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48466 + if (current->exec_id != m->exec_id) {
48467 + gr_log_badprocpid("statm");
48468 + return 0;
48469 + }
48470 +#endif
48471 + mm = get_task_mm(task);
48472 if (mm) {
48473 size = task_statm(mm, &shared, &text, &data, &resident);
48474 mmput(mm);
48475 @@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48476 return 0;
48477 }
48478
48479 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48480 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48481 +{
48482 + u32 curr_ip = 0;
48483 + unsigned long flags;
48484 +
48485 + if (lock_task_sighand(task, &flags)) {
48486 + curr_ip = task->signal->curr_ip;
48487 + unlock_task_sighand(task, &flags);
48488 + }
48489 +
48490 + return sprintf(buffer, "%pI4\n", &curr_ip);
48491 +}
48492 +#endif
48493 +
48494 #ifdef CONFIG_CHECKPOINT_RESTORE
48495 static struct pid *
48496 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48497 diff --git a/fs/proc/base.c b/fs/proc/base.c
48498 index 437195f..cd2210d 100644
48499 --- a/fs/proc/base.c
48500 +++ b/fs/proc/base.c
48501 @@ -110,6 +110,14 @@ struct pid_entry {
48502 union proc_op op;
48503 };
48504
48505 +struct getdents_callback {
48506 + struct linux_dirent __user * current_dir;
48507 + struct linux_dirent __user * previous;
48508 + struct file * file;
48509 + int count;
48510 + int error;
48511 +};
48512 +
48513 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48514 .name = (NAME), \
48515 .len = sizeof(NAME) - 1, \
48516 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48517 if (!mm->arg_end)
48518 goto out_mm; /* Shh! No looking before we're done */
48519
48520 + if (gr_acl_handle_procpidmem(task))
48521 + goto out_mm;
48522 +
48523 len = mm->arg_end - mm->arg_start;
48524
48525 if (len > PAGE_SIZE)
48526 @@ -236,12 +247,28 @@ out:
48527 return res;
48528 }
48529
48530 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48531 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48532 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48533 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48534 +#endif
48535 +
48536 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48537 {
48538 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48539 int res = PTR_ERR(mm);
48540 if (mm && !IS_ERR(mm)) {
48541 unsigned int nwords = 0;
48542 +
48543 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48544 + /* allow if we're currently ptracing this task */
48545 + if (PAX_RAND_FLAGS(mm) &&
48546 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48547 + mmput(mm);
48548 + return 0;
48549 + }
48550 +#endif
48551 +
48552 do {
48553 nwords += 2;
48554 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48555 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48556 }
48557
48558
48559 -#ifdef CONFIG_KALLSYMS
48560 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48561 /*
48562 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48563 * Returns the resolved symbol. If that fails, simply return the address.
48564 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48565 mutex_unlock(&task->signal->cred_guard_mutex);
48566 }
48567
48568 -#ifdef CONFIG_STACKTRACE
48569 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48570
48571 #define MAX_STACK_TRACE_DEPTH 64
48572
48573 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48574 return count;
48575 }
48576
48577 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48578 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48579 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48580 {
48581 long nr;
48582 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48583 /************************************************************************/
48584
48585 /* permission checks */
48586 -static int proc_fd_access_allowed(struct inode *inode)
48587 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48588 {
48589 struct task_struct *task;
48590 int allowed = 0;
48591 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48592 */
48593 task = get_proc_task(inode);
48594 if (task) {
48595 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48596 + if (log)
48597 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48598 + else
48599 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48600 put_task_struct(task);
48601 }
48602 return allowed;
48603 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48604 struct task_struct *task,
48605 int hide_pid_min)
48606 {
48607 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48608 + return false;
48609 +
48610 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48611 + rcu_read_lock();
48612 + {
48613 + const struct cred *tmpcred = current_cred();
48614 + const struct cred *cred = __task_cred(task);
48615 +
48616 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48617 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48618 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48619 +#endif
48620 + ) {
48621 + rcu_read_unlock();
48622 + return true;
48623 + }
48624 + }
48625 + rcu_read_unlock();
48626 +
48627 + if (!pid->hide_pid)
48628 + return false;
48629 +#endif
48630 +
48631 if (pid->hide_pid < hide_pid_min)
48632 return true;
48633 if (in_group_p(pid->pid_gid))
48634 return true;
48635 +
48636 return ptrace_may_access(task, PTRACE_MODE_READ);
48637 }
48638
48639 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48640 put_task_struct(task);
48641
48642 if (!has_perms) {
48643 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48644 + {
48645 +#else
48646 if (pid->hide_pid == 2) {
48647 +#endif
48648 /*
48649 * Let's make getdents(), stat(), and open()
48650 * consistent with each other. If a process
48651 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48652 if (!task)
48653 return -ESRCH;
48654
48655 + if (gr_acl_handle_procpidmem(task)) {
48656 + put_task_struct(task);
48657 + return -EPERM;
48658 + }
48659 +
48660 mm = mm_access(task, mode);
48661 put_task_struct(task);
48662
48663 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48664 mmput(mm);
48665 }
48666
48667 - /* OK to pass negative loff_t, we can catch out-of-range */
48668 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
48669 file->private_data = mm;
48670
48671 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48672 + file->f_version = current->exec_id;
48673 +#endif
48674 +
48675 return 0;
48676 }
48677
48678 static int mem_open(struct inode *inode, struct file *file)
48679 {
48680 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48681 + int ret;
48682 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48683 +
48684 + /* OK to pass negative loff_t, we can catch out-of-range */
48685 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
48686 +
48687 + return ret;
48688 }
48689
48690 static ssize_t mem_rw(struct file *file, char __user *buf,
48691 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48692 ssize_t copied;
48693 char *page;
48694
48695 +#ifdef CONFIG_GRKERNSEC
48696 + if (write)
48697 + return -EPERM;
48698 +#endif
48699 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48700 + if (file->f_version != current->exec_id) {
48701 + gr_log_badprocpid("mem");
48702 + return 0;
48703 + }
48704 +#endif
48705 +
48706 if (!mm)
48707 return 0;
48708
48709 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48710 if (!mm)
48711 return 0;
48712
48713 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48714 + if (file->f_version != current->exec_id) {
48715 + gr_log_badprocpid("environ");
48716 + return 0;
48717 + }
48718 +#endif
48719 +
48720 page = (char *)__get_free_page(GFP_TEMPORARY);
48721 if (!page)
48722 return -ENOMEM;
48723 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48724 if (!atomic_inc_not_zero(&mm->mm_users))
48725 goto free;
48726 while (count > 0) {
48727 - int this_len, retval, max_len;
48728 + size_t this_len, max_len;
48729 + int retval;
48730 +
48731 + if (src >= (mm->env_end - mm->env_start))
48732 + break;
48733
48734 this_len = mm->env_end - (mm->env_start + src);
48735
48736 - if (this_len <= 0)
48737 - break;
48738
48739 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48740 - this_len = (this_len > max_len) ? max_len : this_len;
48741 + max_len = min_t(size_t, PAGE_SIZE, count);
48742 + this_len = min(max_len, this_len);
48743
48744 retval = access_remote_vm(mm, (mm->env_start + src),
48745 page, this_len, 0);
48746 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48747 path_put(&nd->path);
48748
48749 /* Are we allowed to snoop on the tasks file descriptors? */
48750 - if (!proc_fd_access_allowed(inode))
48751 + if (!proc_fd_access_allowed(inode, 0))
48752 goto out;
48753
48754 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48755 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48756 struct path path;
48757
48758 /* Are we allowed to snoop on the tasks file descriptors? */
48759 - if (!proc_fd_access_allowed(inode))
48760 - goto out;
48761 + /* logging this is needed for learning on chromium to work properly,
48762 + but we don't want to flood the logs from 'ps' which does a readlink
48763 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48764 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48765 + */
48766 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48767 + if (!proc_fd_access_allowed(inode,0))
48768 + goto out;
48769 + } else {
48770 + if (!proc_fd_access_allowed(inode,1))
48771 + goto out;
48772 + }
48773
48774 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48775 if (error)
48776 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48777 rcu_read_lock();
48778 cred = __task_cred(task);
48779 inode->i_uid = cred->euid;
48780 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48781 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48782 +#else
48783 inode->i_gid = cred->egid;
48784 +#endif
48785 rcu_read_unlock();
48786 }
48787 security_task_to_inode(task, inode);
48788 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48789 return -ENOENT;
48790 }
48791 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48792 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48793 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48794 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48795 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48796 +#endif
48797 task_dumpable(task)) {
48798 cred = __task_cred(task);
48799 stat->uid = cred->euid;
48800 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48801 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48802 +#else
48803 stat->gid = cred->egid;
48804 +#endif
48805 }
48806 }
48807 rcu_read_unlock();
48808 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48809
48810 if (task) {
48811 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48812 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48813 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48814 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48815 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48816 +#endif
48817 task_dumpable(task)) {
48818 rcu_read_lock();
48819 cred = __task_cred(task);
48820 inode->i_uid = cred->euid;
48821 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48822 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48823 +#else
48824 inode->i_gid = cred->egid;
48825 +#endif
48826 rcu_read_unlock();
48827 } else {
48828 inode->i_uid = GLOBAL_ROOT_UID;
48829 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48830 int fd = proc_fd(inode);
48831
48832 if (task) {
48833 - files = get_files_struct(task);
48834 + if (!gr_acl_handle_procpidmem(task))
48835 + files = get_files_struct(task);
48836 put_task_struct(task);
48837 }
48838 if (files) {
48839 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48840 */
48841 static int proc_fd_permission(struct inode *inode, int mask)
48842 {
48843 + struct task_struct *task;
48844 int rv = generic_permission(inode, mask);
48845 - if (rv == 0)
48846 - return 0;
48847 +
48848 if (task_pid(current) == proc_pid(inode))
48849 rv = 0;
48850 +
48851 + task = get_proc_task(inode);
48852 + if (task == NULL)
48853 + return rv;
48854 +
48855 + if (gr_acl_handle_procpidmem(task))
48856 + rv = -EACCES;
48857 +
48858 + put_task_struct(task);
48859 +
48860 return rv;
48861 }
48862
48863 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48864 if (!task)
48865 goto out_no_task;
48866
48867 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48868 + goto out;
48869 +
48870 /*
48871 * Yes, it does not scale. And it should not. Don't add
48872 * new entries into /proc/<tgid>/ without very good reasons.
48873 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48874 if (!task)
48875 goto out_no_task;
48876
48877 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48878 + goto out;
48879 +
48880 ret = 0;
48881 i = filp->f_pos;
48882 switch (i) {
48883 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48884 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48885 void *cookie)
48886 {
48887 - char *s = nd_get_link(nd);
48888 + const char *s = nd_get_link(nd);
48889 if (!IS_ERR(s))
48890 __putname(s);
48891 }
48892 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48893 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48894 #endif
48895 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48896 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48897 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48898 INF("syscall", S_IRUGO, proc_pid_syscall),
48899 #endif
48900 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48901 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48902 #ifdef CONFIG_SECURITY
48903 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48904 #endif
48905 -#ifdef CONFIG_KALLSYMS
48906 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48907 INF("wchan", S_IRUGO, proc_pid_wchan),
48908 #endif
48909 -#ifdef CONFIG_STACKTRACE
48910 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48911 ONE("stack", S_IRUGO, proc_pid_stack),
48912 #endif
48913 #ifdef CONFIG_SCHEDSTATS
48914 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48915 #ifdef CONFIG_HARDWALL
48916 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48917 #endif
48918 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48919 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48920 +#endif
48921 #ifdef CONFIG_USER_NS
48922 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48923 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48924 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48925 if (!inode)
48926 goto out;
48927
48928 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48929 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48930 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48931 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48932 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48933 +#else
48934 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48935 +#endif
48936 inode->i_op = &proc_tgid_base_inode_operations;
48937 inode->i_fop = &proc_tgid_base_operations;
48938 inode->i_flags|=S_IMMUTABLE;
48939 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48940 if (!task)
48941 goto out;
48942
48943 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48944 + goto out_put_task;
48945 +
48946 result = proc_pid_instantiate(dir, dentry, task, NULL);
48947 +out_put_task:
48948 put_task_struct(task);
48949 out:
48950 return result;
48951 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48952 static int fake_filldir(void *buf, const char *name, int namelen,
48953 loff_t offset, u64 ino, unsigned d_type)
48954 {
48955 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48956 + __buf->error = -EINVAL;
48957 return 0;
48958 }
48959
48960 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48961 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48962 #endif
48963 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48964 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48965 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48966 INF("syscall", S_IRUGO, proc_pid_syscall),
48967 #endif
48968 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48969 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48970 #ifdef CONFIG_SECURITY
48971 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48972 #endif
48973 -#ifdef CONFIG_KALLSYMS
48974 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48975 INF("wchan", S_IRUGO, proc_pid_wchan),
48976 #endif
48977 -#ifdef CONFIG_STACKTRACE
48978 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48979 ONE("stack", S_IRUGO, proc_pid_stack),
48980 #endif
48981 #ifdef CONFIG_SCHEDSTATS
48982 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48983 index 82676e3..5f8518a 100644
48984 --- a/fs/proc/cmdline.c
48985 +++ b/fs/proc/cmdline.c
48986 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48987
48988 static int __init proc_cmdline_init(void)
48989 {
48990 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48991 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48992 +#else
48993 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48994 +#endif
48995 return 0;
48996 }
48997 module_init(proc_cmdline_init);
48998 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48999 index b143471..bb105e5 100644
49000 --- a/fs/proc/devices.c
49001 +++ b/fs/proc/devices.c
49002 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49003
49004 static int __init proc_devices_init(void)
49005 {
49006 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49007 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49008 +#else
49009 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49010 +#endif
49011 return 0;
49012 }
49013 module_init(proc_devices_init);
49014 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49015 index 7ac817b..abab1a5 100644
49016 --- a/fs/proc/inode.c
49017 +++ b/fs/proc/inode.c
49018 @@ -21,11 +21,17 @@
49019 #include <linux/seq_file.h>
49020 #include <linux/slab.h>
49021 #include <linux/mount.h>
49022 +#include <linux/grsecurity.h>
49023
49024 #include <asm/uaccess.h>
49025
49026 #include "internal.h"
49027
49028 +#ifdef CONFIG_PROC_SYSCTL
49029 +extern const struct inode_operations proc_sys_inode_operations;
49030 +extern const struct inode_operations proc_sys_dir_operations;
49031 +#endif
49032 +
49033 static void proc_evict_inode(struct inode *inode)
49034 {
49035 struct proc_dir_entry *de;
49036 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49037 ns_ops = PROC_I(inode)->ns_ops;
49038 if (ns_ops && ns_ops->put)
49039 ns_ops->put(PROC_I(inode)->ns);
49040 +
49041 +#ifdef CONFIG_PROC_SYSCTL
49042 + if (inode->i_op == &proc_sys_inode_operations ||
49043 + inode->i_op == &proc_sys_dir_operations)
49044 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49045 +#endif
49046 +
49047 }
49048
49049 static struct kmem_cache * proc_inode_cachep;
49050 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49051 if (de->mode) {
49052 inode->i_mode = de->mode;
49053 inode->i_uid = de->uid;
49054 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49055 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49056 +#else
49057 inode->i_gid = de->gid;
49058 +#endif
49059 }
49060 if (de->size)
49061 inode->i_size = de->size;
49062 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49063 index eca4aca..19166b2 100644
49064 --- a/fs/proc/internal.h
49065 +++ b/fs/proc/internal.h
49066 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49067 struct pid *pid, struct task_struct *task);
49068 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49069 struct pid *pid, struct task_struct *task);
49070 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49071 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49072 +#endif
49073 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49074
49075 extern const struct file_operations proc_tid_children_operations;
49076 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49077 index 86c67ee..cdca321 100644
49078 --- a/fs/proc/kcore.c
49079 +++ b/fs/proc/kcore.c
49080 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49081 * the addresses in the elf_phdr on our list.
49082 */
49083 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49084 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49085 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49086 + if (tsz > buflen)
49087 tsz = buflen;
49088 -
49089 +
49090 while (buflen) {
49091 struct kcore_list *m;
49092
49093 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49094 kfree(elf_buf);
49095 } else {
49096 if (kern_addr_valid(start)) {
49097 - unsigned long n;
49098 + char *elf_buf;
49099 + mm_segment_t oldfs;
49100
49101 - n = copy_to_user(buffer, (char *)start, tsz);
49102 - /*
49103 - * We cannot distinguish between fault on source
49104 - * and fault on destination. When this happens
49105 - * we clear too and hope it will trigger the
49106 - * EFAULT again.
49107 - */
49108 - if (n) {
49109 - if (clear_user(buffer + tsz - n,
49110 - n))
49111 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49112 + if (!elf_buf)
49113 + return -ENOMEM;
49114 + oldfs = get_fs();
49115 + set_fs(KERNEL_DS);
49116 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49117 + set_fs(oldfs);
49118 + if (copy_to_user(buffer, elf_buf, tsz)) {
49119 + kfree(elf_buf);
49120 return -EFAULT;
49121 + }
49122 }
49123 + set_fs(oldfs);
49124 + kfree(elf_buf);
49125 } else {
49126 if (clear_user(buffer, tsz))
49127 return -EFAULT;
49128 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49129
49130 static int open_kcore(struct inode *inode, struct file *filp)
49131 {
49132 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49133 + return -EPERM;
49134 +#endif
49135 if (!capable(CAP_SYS_RAWIO))
49136 return -EPERM;
49137 if (kcore_need_update)
49138 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49139 index 80e4645..53e5fcf 100644
49140 --- a/fs/proc/meminfo.c
49141 +++ b/fs/proc/meminfo.c
49142 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49143 vmi.used >> 10,
49144 vmi.largest_chunk >> 10
49145 #ifdef CONFIG_MEMORY_FAILURE
49146 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49147 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49148 #endif
49149 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49150 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49151 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49152 index b1822dd..df622cb 100644
49153 --- a/fs/proc/nommu.c
49154 +++ b/fs/proc/nommu.c
49155 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49156 if (len < 1)
49157 len = 1;
49158 seq_printf(m, "%*c", len, ' ');
49159 - seq_path(m, &file->f_path, "");
49160 + seq_path(m, &file->f_path, "\n\\");
49161 }
49162
49163 seq_putc(m, '\n');
49164 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49165 index 06e1cc1..177cd98 100644
49166 --- a/fs/proc/proc_net.c
49167 +++ b/fs/proc/proc_net.c
49168 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49169 struct task_struct *task;
49170 struct nsproxy *ns;
49171 struct net *net = NULL;
49172 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49173 + const struct cred *cred = current_cred();
49174 +#endif
49175 +
49176 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49177 + if (cred->fsuid)
49178 + return net;
49179 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49180 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49181 + return net;
49182 +#endif
49183
49184 rcu_read_lock();
49185 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49186 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49187 index 3476bca..cb6d86a 100644
49188 --- a/fs/proc/proc_sysctl.c
49189 +++ b/fs/proc/proc_sysctl.c
49190 @@ -12,11 +12,15 @@
49191 #include <linux/module.h>
49192 #include "internal.h"
49193
49194 +extern int gr_handle_chroot_sysctl(const int op);
49195 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49196 + const int op);
49197 +
49198 static const struct dentry_operations proc_sys_dentry_operations;
49199 static const struct file_operations proc_sys_file_operations;
49200 -static const struct inode_operations proc_sys_inode_operations;
49201 +const struct inode_operations proc_sys_inode_operations;
49202 static const struct file_operations proc_sys_dir_file_operations;
49203 -static const struct inode_operations proc_sys_dir_operations;
49204 +const struct inode_operations proc_sys_dir_operations;
49205
49206 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49207 {
49208 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49209
49210 err = NULL;
49211 d_set_d_op(dentry, &proc_sys_dentry_operations);
49212 +
49213 + gr_handle_proc_create(dentry, inode);
49214 +
49215 d_add(dentry, inode);
49216
49217 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49218 + err = ERR_PTR(-ENOENT);
49219 +
49220 out:
49221 sysctl_head_finish(head);
49222 return err;
49223 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49224 struct inode *inode = filp->f_path.dentry->d_inode;
49225 struct ctl_table_header *head = grab_header(inode);
49226 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49227 + int op = write ? MAY_WRITE : MAY_READ;
49228 ssize_t error;
49229 size_t res;
49230
49231 if (IS_ERR(head))
49232 return PTR_ERR(head);
49233
49234 +
49235 /*
49236 * At this point we know that the sysctl was not unregistered
49237 * and won't be until we finish.
49238 */
49239 error = -EPERM;
49240 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49241 + if (sysctl_perm(head->root, table, op))
49242 goto out;
49243
49244 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49245 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49246 if (!table->proc_handler)
49247 goto out;
49248
49249 +#ifdef CONFIG_GRKERNSEC
49250 + error = -EPERM;
49251 + if (gr_handle_chroot_sysctl(op))
49252 + goto out;
49253 + dget(filp->f_path.dentry);
49254 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49255 + dput(filp->f_path.dentry);
49256 + goto out;
49257 + }
49258 + dput(filp->f_path.dentry);
49259 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49260 + goto out;
49261 + if (write && !capable(CAP_SYS_ADMIN))
49262 + goto out;
49263 +#endif
49264 +
49265 /* careful: calling conventions are nasty here */
49266 res = count;
49267 error = table->proc_handler(table, write, buf, &res, ppos);
49268 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49269 return -ENOMEM;
49270 } else {
49271 d_set_d_op(child, &proc_sys_dentry_operations);
49272 +
49273 + gr_handle_proc_create(child, inode);
49274 +
49275 d_add(child, inode);
49276 }
49277 } else {
49278 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49279 if ((*pos)++ < file->f_pos)
49280 return 0;
49281
49282 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49283 + return 0;
49284 +
49285 if (unlikely(S_ISLNK(table->mode)))
49286 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49287 else
49288 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49289 if (IS_ERR(head))
49290 return PTR_ERR(head);
49291
49292 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49293 + return -ENOENT;
49294 +
49295 generic_fillattr(inode, stat);
49296 if (table)
49297 stat->mode = (stat->mode & S_IFMT) | table->mode;
49298 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49299 .llseek = generic_file_llseek,
49300 };
49301
49302 -static const struct inode_operations proc_sys_inode_operations = {
49303 +const struct inode_operations proc_sys_inode_operations = {
49304 .permission = proc_sys_permission,
49305 .setattr = proc_sys_setattr,
49306 .getattr = proc_sys_getattr,
49307 };
49308
49309 -static const struct inode_operations proc_sys_dir_operations = {
49310 +const struct inode_operations proc_sys_dir_operations = {
49311 .lookup = proc_sys_lookup,
49312 .permission = proc_sys_permission,
49313 .setattr = proc_sys_setattr,
49314 diff --git a/fs/proc/root.c b/fs/proc/root.c
49315 index 7c30fce..b3d3aa2 100644
49316 --- a/fs/proc/root.c
49317 +++ b/fs/proc/root.c
49318 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49319 #ifdef CONFIG_PROC_DEVICETREE
49320 proc_device_tree_init();
49321 #endif
49322 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49323 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49324 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49325 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49326 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49327 +#endif
49328 +#else
49329 proc_mkdir("bus", NULL);
49330 +#endif
49331 proc_sys_init();
49332 }
49333
49334 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49335 index 4540b8f..1b9772f 100644
49336 --- a/fs/proc/task_mmu.c
49337 +++ b/fs/proc/task_mmu.c
49338 @@ -11,12 +11,19 @@
49339 #include <linux/rmap.h>
49340 #include <linux/swap.h>
49341 #include <linux/swapops.h>
49342 +#include <linux/grsecurity.h>
49343
49344 #include <asm/elf.h>
49345 #include <asm/uaccess.h>
49346 #include <asm/tlbflush.h>
49347 #include "internal.h"
49348
49349 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49350 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49351 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49352 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49353 +#endif
49354 +
49355 void task_mem(struct seq_file *m, struct mm_struct *mm)
49356 {
49357 unsigned long data, text, lib, swap;
49358 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49359 "VmExe:\t%8lu kB\n"
49360 "VmLib:\t%8lu kB\n"
49361 "VmPTE:\t%8lu kB\n"
49362 - "VmSwap:\t%8lu kB\n",
49363 - hiwater_vm << (PAGE_SHIFT-10),
49364 + "VmSwap:\t%8lu kB\n"
49365 +
49366 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49367 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49368 +#endif
49369 +
49370 + ,hiwater_vm << (PAGE_SHIFT-10),
49371 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49372 mm->locked_vm << (PAGE_SHIFT-10),
49373 mm->pinned_vm << (PAGE_SHIFT-10),
49374 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49375 data << (PAGE_SHIFT-10),
49376 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49377 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49378 - swap << (PAGE_SHIFT-10));
49379 + swap << (PAGE_SHIFT-10)
49380 +
49381 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49382 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49383 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49384 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49385 +#else
49386 + , mm->context.user_cs_base
49387 + , mm->context.user_cs_limit
49388 +#endif
49389 +#endif
49390 +
49391 + );
49392 }
49393
49394 unsigned long task_vsize(struct mm_struct *mm)
49395 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49396 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49397 }
49398
49399 - /* We don't show the stack guard page in /proc/maps */
49400 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49401 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49402 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49403 +#else
49404 start = vma->vm_start;
49405 - if (stack_guard_page_start(vma, start))
49406 - start += PAGE_SIZE;
49407 end = vma->vm_end;
49408 - if (stack_guard_page_end(vma, end))
49409 - end -= PAGE_SIZE;
49410 +#endif
49411
49412 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49413 start,
49414 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49415 flags & VM_WRITE ? 'w' : '-',
49416 flags & VM_EXEC ? 'x' : '-',
49417 flags & VM_MAYSHARE ? 's' : 'p',
49418 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49419 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49420 +#else
49421 pgoff,
49422 +#endif
49423 MAJOR(dev), MINOR(dev), ino, &len);
49424
49425 /*
49426 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49427 */
49428 if (file) {
49429 pad_len_spaces(m, len);
49430 - seq_path(m, &file->f_path, "\n");
49431 + seq_path(m, &file->f_path, "\n\\");
49432 goto done;
49433 }
49434
49435 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49436 * Thread stack in /proc/PID/task/TID/maps or
49437 * the main process stack.
49438 */
49439 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49440 - vma->vm_end >= mm->start_stack)) {
49441 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49442 + (vma->vm_start <= mm->start_stack &&
49443 + vma->vm_end >= mm->start_stack)) {
49444 name = "[stack]";
49445 } else {
49446 /* Thread stack in /proc/PID/maps */
49447 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49448 struct proc_maps_private *priv = m->private;
49449 struct task_struct *task = priv->task;
49450
49451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49452 + if (current->exec_id != m->exec_id) {
49453 + gr_log_badprocpid("maps");
49454 + return 0;
49455 + }
49456 +#endif
49457 +
49458 show_map_vma(m, vma, is_pid);
49459
49460 if (m->count < m->size) /* vma is copied successfully */
49461 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49462 .private = &mss,
49463 };
49464
49465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49466 + if (current->exec_id != m->exec_id) {
49467 + gr_log_badprocpid("smaps");
49468 + return 0;
49469 + }
49470 +#endif
49471 memset(&mss, 0, sizeof mss);
49472 - mss.vma = vma;
49473 - /* mmap_sem is held in m_start */
49474 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49475 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49476 -
49477 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49478 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49479 +#endif
49480 + mss.vma = vma;
49481 + /* mmap_sem is held in m_start */
49482 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49483 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49484 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49485 + }
49486 +#endif
49487 show_map_vma(m, vma, is_pid);
49488
49489 seq_printf(m,
49490 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49491 "KernelPageSize: %8lu kB\n"
49492 "MMUPageSize: %8lu kB\n"
49493 "Locked: %8lu kB\n",
49494 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49495 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49496 +#else
49497 (vma->vm_end - vma->vm_start) >> 10,
49498 +#endif
49499 mss.resident >> 10,
49500 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49501 mss.shared_clean >> 10,
49502 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49503 int n;
49504 char buffer[50];
49505
49506 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49507 + if (current->exec_id != m->exec_id) {
49508 + gr_log_badprocpid("numa_maps");
49509 + return 0;
49510 + }
49511 +#endif
49512 +
49513 if (!mm)
49514 return 0;
49515
49516 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49517 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49518 mpol_cond_put(pol);
49519
49520 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49521 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49522 +#else
49523 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49524 +#endif
49525
49526 if (file) {
49527 seq_printf(m, " file=");
49528 - seq_path(m, &file->f_path, "\n\t= ");
49529 + seq_path(m, &file->f_path, "\n\t\\= ");
49530 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49531 seq_printf(m, " heap");
49532 } else {
49533 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49534 index 1ccfa53..0848f95 100644
49535 --- a/fs/proc/task_nommu.c
49536 +++ b/fs/proc/task_nommu.c
49537 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49538 else
49539 bytes += kobjsize(mm);
49540
49541 - if (current->fs && current->fs->users > 1)
49542 + if (current->fs && atomic_read(&current->fs->users) > 1)
49543 sbytes += kobjsize(current->fs);
49544 else
49545 bytes += kobjsize(current->fs);
49546 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49547
49548 if (file) {
49549 pad_len_spaces(m, len);
49550 - seq_path(m, &file->f_path, "");
49551 + seq_path(m, &file->f_path, "\n\\");
49552 } else if (mm) {
49553 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49554
49555 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49556 index d67908b..d13f6a6 100644
49557 --- a/fs/quota/netlink.c
49558 +++ b/fs/quota/netlink.c
49559 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49560 void quota_send_warning(short type, unsigned int id, dev_t dev,
49561 const char warntype)
49562 {
49563 - static atomic_t seq;
49564 + static atomic_unchecked_t seq;
49565 struct sk_buff *skb;
49566 void *msg_head;
49567 int ret;
49568 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49569 "VFS: Not enough memory to send quota warning.\n");
49570 return;
49571 }
49572 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49573 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49574 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49575 if (!msg_head) {
49576 printk(KERN_ERR
49577 diff --git a/fs/readdir.c b/fs/readdir.c
49578 index 39e3370..20d446d 100644
49579 --- a/fs/readdir.c
49580 +++ b/fs/readdir.c
49581 @@ -17,6 +17,7 @@
49582 #include <linux/security.h>
49583 #include <linux/syscalls.h>
49584 #include <linux/unistd.h>
49585 +#include <linux/namei.h>
49586
49587 #include <asm/uaccess.h>
49588
49589 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49590
49591 struct readdir_callback {
49592 struct old_linux_dirent __user * dirent;
49593 + struct file * file;
49594 int result;
49595 };
49596
49597 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49598 buf->result = -EOVERFLOW;
49599 return -EOVERFLOW;
49600 }
49601 +
49602 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49603 + return 0;
49604 +
49605 buf->result++;
49606 dirent = buf->dirent;
49607 if (!access_ok(VERIFY_WRITE, dirent,
49608 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49609
49610 buf.result = 0;
49611 buf.dirent = dirent;
49612 + buf.file = file;
49613
49614 error = vfs_readdir(file, fillonedir, &buf);
49615 if (buf.result)
49616 @@ -141,6 +148,7 @@ struct linux_dirent {
49617 struct getdents_callback {
49618 struct linux_dirent __user * current_dir;
49619 struct linux_dirent __user * previous;
49620 + struct file * file;
49621 int count;
49622 int error;
49623 };
49624 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49625 buf->error = -EOVERFLOW;
49626 return -EOVERFLOW;
49627 }
49628 +
49629 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49630 + return 0;
49631 +
49632 dirent = buf->previous;
49633 if (dirent) {
49634 if (__put_user(offset, &dirent->d_off))
49635 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49636 buf.previous = NULL;
49637 buf.count = count;
49638 buf.error = 0;
49639 + buf.file = file;
49640
49641 error = vfs_readdir(file, filldir, &buf);
49642 if (error >= 0)
49643 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49644 struct getdents_callback64 {
49645 struct linux_dirent64 __user * current_dir;
49646 struct linux_dirent64 __user * previous;
49647 + struct file *file;
49648 int count;
49649 int error;
49650 };
49651 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49652 buf->error = -EINVAL; /* only used if we fail.. */
49653 if (reclen > buf->count)
49654 return -EINVAL;
49655 +
49656 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49657 + return 0;
49658 +
49659 dirent = buf->previous;
49660 if (dirent) {
49661 if (__put_user(offset, &dirent->d_off))
49662 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49663
49664 buf.current_dir = dirent;
49665 buf.previous = NULL;
49666 + buf.file = file;
49667 buf.count = count;
49668 buf.error = 0;
49669
49670 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49671 error = buf.error;
49672 lastdirent = buf.previous;
49673 if (lastdirent) {
49674 - typeof(lastdirent->d_off) d_off = file->f_pos;
49675 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49676 if (__put_user(d_off, &lastdirent->d_off))
49677 error = -EFAULT;
49678 else
49679 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49680 index 2b7882b..1c5ef48 100644
49681 --- a/fs/reiserfs/do_balan.c
49682 +++ b/fs/reiserfs/do_balan.c
49683 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49684 return;
49685 }
49686
49687 - atomic_inc(&(fs_generation(tb->tb_sb)));
49688 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49689 do_balance_starts(tb);
49690
49691 /* balance leaf returns 0 except if combining L R and S into
49692 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49693 index 2c1ade6..8c59d8d 100644
49694 --- a/fs/reiserfs/procfs.c
49695 +++ b/fs/reiserfs/procfs.c
49696 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49697 "SMALL_TAILS " : "NO_TAILS ",
49698 replay_only(sb) ? "REPLAY_ONLY " : "",
49699 convert_reiserfs(sb) ? "CONV " : "",
49700 - atomic_read(&r->s_generation_counter),
49701 + atomic_read_unchecked(&r->s_generation_counter),
49702 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49703 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49704 SF(s_good_search_by_key_reada), SF(s_bmaps),
49705 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49706 index 33215f5..c5d427a 100644
49707 --- a/fs/reiserfs/reiserfs.h
49708 +++ b/fs/reiserfs/reiserfs.h
49709 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49710 /* Comment? -Hans */
49711 wait_queue_head_t s_wait;
49712 /* To be obsoleted soon by per buffer seals.. -Hans */
49713 - atomic_t s_generation_counter; // increased by one every time the
49714 + atomic_unchecked_t s_generation_counter; // increased by one every time the
49715 // tree gets re-balanced
49716 unsigned long s_properties; /* File system properties. Currently holds
49717 on-disk FS format */
49718 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49719 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49720
49721 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49722 -#define get_generation(s) atomic_read (&fs_generation(s))
49723 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49724 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49725 #define __fs_changed(gen,s) (gen != get_generation (s))
49726 #define fs_changed(gen,s) \
49727 diff --git a/fs/select.c b/fs/select.c
49728 index db14c78..3aae1bd 100644
49729 --- a/fs/select.c
49730 +++ b/fs/select.c
49731 @@ -20,6 +20,7 @@
49732 #include <linux/export.h>
49733 #include <linux/slab.h>
49734 #include <linux/poll.h>
49735 +#include <linux/security.h>
49736 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49737 #include <linux/file.h>
49738 #include <linux/fdtable.h>
49739 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49740 struct poll_list *walk = head;
49741 unsigned long todo = nfds;
49742
49743 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49744 if (nfds > rlimit(RLIMIT_NOFILE))
49745 return -EINVAL;
49746
49747 diff --git a/fs/seq_file.c b/fs/seq_file.c
49748 index 0cbd049..64e705c 100644
49749 --- a/fs/seq_file.c
49750 +++ b/fs/seq_file.c
49751 @@ -9,6 +9,7 @@
49752 #include <linux/export.h>
49753 #include <linux/seq_file.h>
49754 #include <linux/slab.h>
49755 +#include <linux/sched.h>
49756
49757 #include <asm/uaccess.h>
49758 #include <asm/page.h>
49759 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49760 memset(p, 0, sizeof(*p));
49761 mutex_init(&p->lock);
49762 p->op = op;
49763 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49764 + p->exec_id = current->exec_id;
49765 +#endif
49766
49767 /*
49768 * Wrappers around seq_open(e.g. swaps_open) need to be
49769 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49770 return 0;
49771 }
49772 if (!m->buf) {
49773 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49774 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49775 if (!m->buf)
49776 return -ENOMEM;
49777 }
49778 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49779 Eoverflow:
49780 m->op->stop(m, p);
49781 kfree(m->buf);
49782 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49783 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49784 return !m->buf ? -ENOMEM : -EAGAIN;
49785 }
49786
49787 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49788
49789 /* grab buffer if we didn't have one */
49790 if (!m->buf) {
49791 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49792 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49793 if (!m->buf)
49794 goto Enomem;
49795 }
49796 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49797 goto Fill;
49798 m->op->stop(m, p);
49799 kfree(m->buf);
49800 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49801 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49802 if (!m->buf)
49803 goto Enomem;
49804 m->count = 0;
49805 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49806 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49807 void *data)
49808 {
49809 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49810 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49811 int res = -ENOMEM;
49812
49813 if (op) {
49814 diff --git a/fs/splice.c b/fs/splice.c
49815 index 7bf08fa..eb35c2f 100644
49816 --- a/fs/splice.c
49817 +++ b/fs/splice.c
49818 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49819 pipe_lock(pipe);
49820
49821 for (;;) {
49822 - if (!pipe->readers) {
49823 + if (!atomic_read(&pipe->readers)) {
49824 send_sig(SIGPIPE, current, 0);
49825 if (!ret)
49826 ret = -EPIPE;
49827 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49828 do_wakeup = 0;
49829 }
49830
49831 - pipe->waiting_writers++;
49832 + atomic_inc(&pipe->waiting_writers);
49833 pipe_wait(pipe);
49834 - pipe->waiting_writers--;
49835 + atomic_dec(&pipe->waiting_writers);
49836 }
49837
49838 pipe_unlock(pipe);
49839 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49840 old_fs = get_fs();
49841 set_fs(get_ds());
49842 /* The cast to a user pointer is valid due to the set_fs() */
49843 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49844 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49845 set_fs(old_fs);
49846
49847 return res;
49848 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49849 old_fs = get_fs();
49850 set_fs(get_ds());
49851 /* The cast to a user pointer is valid due to the set_fs() */
49852 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49853 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49854 set_fs(old_fs);
49855
49856 return res;
49857 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49858 goto err;
49859
49860 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49861 - vec[i].iov_base = (void __user *) page_address(page);
49862 + vec[i].iov_base = (void __force_user *) page_address(page);
49863 vec[i].iov_len = this_len;
49864 spd.pages[i] = page;
49865 spd.nr_pages++;
49866 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49867 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49868 {
49869 while (!pipe->nrbufs) {
49870 - if (!pipe->writers)
49871 + if (!atomic_read(&pipe->writers))
49872 return 0;
49873
49874 - if (!pipe->waiting_writers && sd->num_spliced)
49875 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49876 return 0;
49877
49878 if (sd->flags & SPLICE_F_NONBLOCK)
49879 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49880 * out of the pipe right after the splice_to_pipe(). So set
49881 * PIPE_READERS appropriately.
49882 */
49883 - pipe->readers = 1;
49884 + atomic_set(&pipe->readers, 1);
49885
49886 current->splice_pipe = pipe;
49887 }
49888 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49889 ret = -ERESTARTSYS;
49890 break;
49891 }
49892 - if (!pipe->writers)
49893 + if (!atomic_read(&pipe->writers))
49894 break;
49895 - if (!pipe->waiting_writers) {
49896 + if (!atomic_read(&pipe->waiting_writers)) {
49897 if (flags & SPLICE_F_NONBLOCK) {
49898 ret = -EAGAIN;
49899 break;
49900 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49901 pipe_lock(pipe);
49902
49903 while (pipe->nrbufs >= pipe->buffers) {
49904 - if (!pipe->readers) {
49905 + if (!atomic_read(&pipe->readers)) {
49906 send_sig(SIGPIPE, current, 0);
49907 ret = -EPIPE;
49908 break;
49909 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49910 ret = -ERESTARTSYS;
49911 break;
49912 }
49913 - pipe->waiting_writers++;
49914 + atomic_inc(&pipe->waiting_writers);
49915 pipe_wait(pipe);
49916 - pipe->waiting_writers--;
49917 + atomic_dec(&pipe->waiting_writers);
49918 }
49919
49920 pipe_unlock(pipe);
49921 @@ -1825,14 +1825,14 @@ retry:
49922 pipe_double_lock(ipipe, opipe);
49923
49924 do {
49925 - if (!opipe->readers) {
49926 + if (!atomic_read(&opipe->readers)) {
49927 send_sig(SIGPIPE, current, 0);
49928 if (!ret)
49929 ret = -EPIPE;
49930 break;
49931 }
49932
49933 - if (!ipipe->nrbufs && !ipipe->writers)
49934 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49935 break;
49936
49937 /*
49938 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49939 pipe_double_lock(ipipe, opipe);
49940
49941 do {
49942 - if (!opipe->readers) {
49943 + if (!atomic_read(&opipe->readers)) {
49944 send_sig(SIGPIPE, current, 0);
49945 if (!ret)
49946 ret = -EPIPE;
49947 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49948 * return EAGAIN if we have the potential of some data in the
49949 * future, otherwise just return 0
49950 */
49951 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49952 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49953 ret = -EAGAIN;
49954
49955 pipe_unlock(ipipe);
49956 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49957 index e6bb9b2..d8e3951 100644
49958 --- a/fs/sysfs/dir.c
49959 +++ b/fs/sysfs/dir.c
49960 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49961 struct sysfs_dirent *sd;
49962 int rc;
49963
49964 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49965 + const char *parent_name = parent_sd->s_name;
49966 +
49967 + mode = S_IFDIR | S_IRWXU;
49968 +
49969 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49970 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49971 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49972 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49973 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49974 +#endif
49975 +
49976 /* allocate */
49977 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49978 if (!sd)
49979 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49980 index 00012e3..8392349 100644
49981 --- a/fs/sysfs/file.c
49982 +++ b/fs/sysfs/file.c
49983 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49984
49985 struct sysfs_open_dirent {
49986 atomic_t refcnt;
49987 - atomic_t event;
49988 + atomic_unchecked_t event;
49989 wait_queue_head_t poll;
49990 struct list_head buffers; /* goes through sysfs_buffer.list */
49991 };
49992 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49993 if (!sysfs_get_active(attr_sd))
49994 return -ENODEV;
49995
49996 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49997 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49998 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49999
50000 sysfs_put_active(attr_sd);
50001 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50002 return -ENOMEM;
50003
50004 atomic_set(&new_od->refcnt, 0);
50005 - atomic_set(&new_od->event, 1);
50006 + atomic_set_unchecked(&new_od->event, 1);
50007 init_waitqueue_head(&new_od->poll);
50008 INIT_LIST_HEAD(&new_od->buffers);
50009 goto retry;
50010 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50011
50012 sysfs_put_active(attr_sd);
50013
50014 - if (buffer->event != atomic_read(&od->event))
50015 + if (buffer->event != atomic_read_unchecked(&od->event))
50016 goto trigger;
50017
50018 return DEFAULT_POLLMASK;
50019 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50020
50021 od = sd->s_attr.open;
50022 if (od) {
50023 - atomic_inc(&od->event);
50024 + atomic_inc_unchecked(&od->event);
50025 wake_up_interruptible(&od->poll);
50026 }
50027
50028 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50029 index a7ac78f..02158e1 100644
50030 --- a/fs/sysfs/symlink.c
50031 +++ b/fs/sysfs/symlink.c
50032 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50033
50034 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50035 {
50036 - char *page = nd_get_link(nd);
50037 + const char *page = nd_get_link(nd);
50038 if (!IS_ERR(page))
50039 free_page((unsigned long)page);
50040 }
50041 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50042 index c175b4d..8f36a16 100644
50043 --- a/fs/udf/misc.c
50044 +++ b/fs/udf/misc.c
50045 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50046
50047 u8 udf_tag_checksum(const struct tag *t)
50048 {
50049 - u8 *data = (u8 *)t;
50050 + const u8 *data = (const u8 *)t;
50051 u8 checksum = 0;
50052 int i;
50053 for (i = 0; i < sizeof(struct tag); ++i)
50054 diff --git a/fs/udf/namei.c b/fs/udf/namei.c
50055 index 1802417..c31deb3 100644
50056 --- a/fs/udf/namei.c
50057 +++ b/fs/udf/namei.c
50058 @@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
50059 *lenp = 3;
50060 fid->udf.block = location.logicalBlockNum;
50061 fid->udf.partref = location.partitionReferenceNum;
50062 + fid->udf.parent_partref = 0;
50063 fid->udf.generation = inode->i_generation;
50064
50065 if (parent) {
50066 diff --git a/fs/utimes.c b/fs/utimes.c
50067 index fa4dbe4..e12d1b9 100644
50068 --- a/fs/utimes.c
50069 +++ b/fs/utimes.c
50070 @@ -1,6 +1,7 @@
50071 #include <linux/compiler.h>
50072 #include <linux/file.h>
50073 #include <linux/fs.h>
50074 +#include <linux/security.h>
50075 #include <linux/linkage.h>
50076 #include <linux/mount.h>
50077 #include <linux/namei.h>
50078 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50079 goto mnt_drop_write_and_out;
50080 }
50081 }
50082 +
50083 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50084 + error = -EACCES;
50085 + goto mnt_drop_write_and_out;
50086 + }
50087 +
50088 mutex_lock(&inode->i_mutex);
50089 error = notify_change(path->dentry, &newattrs);
50090 mutex_unlock(&inode->i_mutex);
50091 diff --git a/fs/xattr.c b/fs/xattr.c
50092 index 1d7ac37..23cb9ec 100644
50093 --- a/fs/xattr.c
50094 +++ b/fs/xattr.c
50095 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50096 * Extended attribute SET operations
50097 */
50098 static long
50099 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50100 +setxattr(struct path *path, const char __user *name, const void __user *value,
50101 size_t size, int flags)
50102 {
50103 int error;
50104 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50105 }
50106 }
50107
50108 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50109 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50110 + error = -EACCES;
50111 + goto out;
50112 + }
50113 +
50114 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50115 out:
50116 if (vvalue)
50117 vfree(vvalue);
50118 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50119 return error;
50120 error = mnt_want_write(path.mnt);
50121 if (!error) {
50122 - error = setxattr(path.dentry, name, value, size, flags);
50123 + error = setxattr(&path, name, value, size, flags);
50124 mnt_drop_write(path.mnt);
50125 }
50126 path_put(&path);
50127 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50128 return error;
50129 error = mnt_want_write(path.mnt);
50130 if (!error) {
50131 - error = setxattr(path.dentry, name, value, size, flags);
50132 + error = setxattr(&path, name, value, size, flags);
50133 mnt_drop_write(path.mnt);
50134 }
50135 path_put(&path);
50136 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50137 {
50138 int fput_needed;
50139 struct file *f;
50140 - struct dentry *dentry;
50141 int error = -EBADF;
50142
50143 f = fget_light(fd, &fput_needed);
50144 if (!f)
50145 return error;
50146 - dentry = f->f_path.dentry;
50147 - audit_inode(NULL, dentry);
50148 + audit_inode(NULL, f->f_path.dentry);
50149 error = mnt_want_write_file(f);
50150 if (!error) {
50151 - error = setxattr(dentry, name, value, size, flags);
50152 + error = setxattr(&f->f_path, name, value, size, flags);
50153 mnt_drop_write_file(f);
50154 }
50155 fput_light(f, fput_needed);
50156 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50157 index 69d06b0..c0996e5 100644
50158 --- a/fs/xattr_acl.c
50159 +++ b/fs/xattr_acl.c
50160 @@ -17,8 +17,8 @@
50161 struct posix_acl *
50162 posix_acl_from_xattr(const void *value, size_t size)
50163 {
50164 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50165 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50166 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50167 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50168 int count;
50169 struct posix_acl *acl;
50170 struct posix_acl_entry *acl_e;
50171 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50172 index 58b815e..595ddee 100644
50173 --- a/fs/xfs/xfs_bmap.c
50174 +++ b/fs/xfs/xfs_bmap.c
50175 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50176 int nmap,
50177 int ret_nmap);
50178 #else
50179 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50180 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50181 #endif /* DEBUG */
50182
50183 STATIC int
50184 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50185 index 19bf0c5..9f26b02 100644
50186 --- a/fs/xfs/xfs_dir2_sf.c
50187 +++ b/fs/xfs/xfs_dir2_sf.c
50188 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50189 }
50190
50191 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50192 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50193 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50194 + char name[sfep->namelen];
50195 + memcpy(name, sfep->name, sfep->namelen);
50196 + if (filldir(dirent, name, sfep->namelen,
50197 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50198 + *offset = off & 0x7fffffff;
50199 + return 0;
50200 + }
50201 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50202 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50203 *offset = off & 0x7fffffff;
50204 return 0;
50205 diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
50206 index f9c3fe3..69cf4fc 100644
50207 --- a/fs/xfs/xfs_discard.c
50208 +++ b/fs/xfs/xfs_discard.c
50209 @@ -179,12 +179,14 @@ xfs_ioc_trim(
50210 * used by the fstrim application. In the end it really doesn't
50211 * matter as trimming blocks is an advisory interface.
50212 */
50213 + if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
50214 + range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
50215 + return -XFS_ERROR(EINVAL);
50216 +
50217 start = BTOBB(range.start);
50218 end = start + BTOBBT(range.len) - 1;
50219 minlen = BTOBB(max_t(u64, granularity, range.minlen));
50220
50221 - if (XFS_BB_TO_FSB(mp, start) >= mp->m_sb.sb_dblocks)
50222 - return -XFS_ERROR(EINVAL);
50223 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
50224 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
50225
50226 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50227 index 3a05a41..320bec6 100644
50228 --- a/fs/xfs/xfs_ioctl.c
50229 +++ b/fs/xfs/xfs_ioctl.c
50230 @@ -126,7 +126,7 @@ xfs_find_handle(
50231 }
50232
50233 error = -EFAULT;
50234 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50235 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50236 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50237 goto out_put;
50238
50239 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50240 index 1a25fd8..e935581 100644
50241 --- a/fs/xfs/xfs_iops.c
50242 +++ b/fs/xfs/xfs_iops.c
50243 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50244 struct nameidata *nd,
50245 void *p)
50246 {
50247 - char *s = nd_get_link(nd);
50248 + const char *s = nd_get_link(nd);
50249
50250 if (!IS_ERR(s))
50251 kfree(s);
50252 diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
50253 index 92d4331..ca28a4b 100644
50254 --- a/fs/xfs/xfs_rtalloc.c
50255 +++ b/fs/xfs/xfs_rtalloc.c
50256 @@ -857,7 +857,7 @@ xfs_rtbuf_get(
50257 xfs_buf_t *bp; /* block buffer, result */
50258 xfs_inode_t *ip; /* bitmap or summary inode */
50259 xfs_bmbt_irec_t map;
50260 - int nmap;
50261 + int nmap = 1;
50262 int error; /* error value */
50263
50264 ip = issum ? mp->m_rsumip : mp->m_rbmip;
50265 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50266 new file mode 100644
50267 index 0000000..4d533f1
50268 --- /dev/null
50269 +++ b/grsecurity/Kconfig
50270 @@ -0,0 +1,941 @@
50271 +#
50272 +# grecurity configuration
50273 +#
50274 +menu "Memory Protections"
50275 +depends on GRKERNSEC
50276 +
50277 +config GRKERNSEC_KMEM
50278 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50279 + default y if GRKERNSEC_CONFIG_AUTO
50280 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50281 + help
50282 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50283 + be written to or read from to modify or leak the contents of the running
50284 + kernel. /dev/port will also not be allowed to be opened. If you have module
50285 + support disabled, enabling this will close up four ways that are
50286 + currently used to insert malicious code into the running kernel.
50287 + Even with all these features enabled, we still highly recommend that
50288 + you use the RBAC system, as it is still possible for an attacker to
50289 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50290 + If you are not using XFree86, you may be able to stop this additional
50291 + case by enabling the 'Disable privileged I/O' option. Though nothing
50292 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50293 + but only to video memory, which is the only writing we allow in this
50294 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50295 + not be allowed to mprotect it with PROT_WRITE later.
50296 + It is highly recommended that you say Y here if you meet all the
50297 + conditions above.
50298 +
50299 +config GRKERNSEC_VM86
50300 + bool "Restrict VM86 mode"
50301 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50302 + depends on X86_32
50303 +
50304 + help
50305 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50306 + make use of a special execution mode on 32bit x86 processors called
50307 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50308 + video cards and will still work with this option enabled. The purpose
50309 + of the option is to prevent exploitation of emulation errors in
50310 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50311 + Nearly all users should be able to enable this option.
50312 +
50313 +config GRKERNSEC_IO
50314 + bool "Disable privileged I/O"
50315 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50316 + depends on X86
50317 + select RTC_CLASS
50318 + select RTC_INTF_DEV
50319 + select RTC_DRV_CMOS
50320 +
50321 + help
50322 + If you say Y here, all ioperm and iopl calls will return an error.
50323 + Ioperm and iopl can be used to modify the running kernel.
50324 + Unfortunately, some programs need this access to operate properly,
50325 + the most notable of which are XFree86 and hwclock. hwclock can be
50326 + remedied by having RTC support in the kernel, so real-time
50327 + clock support is enabled if this option is enabled, to ensure
50328 + that hwclock operates correctly. XFree86 still will not
50329 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50330 + IF YOU USE XFree86. If you use XFree86 and you still want to
50331 + protect your kernel against modification, use the RBAC system.
50332 +
50333 +config GRKERNSEC_PROC_MEMMAP
50334 + bool "Harden ASLR against information leaks and entropy reduction"
50335 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50336 + depends on PAX_NOEXEC || PAX_ASLR
50337 + help
50338 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50339 + give no information about the addresses of its mappings if
50340 + PaX features that rely on random addresses are enabled on the task.
50341 + In addition to sanitizing this information and disabling other
50342 + dangerous sources of information, this option causes reads of sensitive
50343 + /proc/<pid> entries where the file descriptor was opened in a different
50344 + task than the one performing the read. Such attempts are logged.
50345 + This option also limits argv/env strings for suid/sgid binaries
50346 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50347 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50348 + binaries to prevent alternative mmap layouts from being abused.
50349 +
50350 + If you use PaX it is essential that you say Y here as it closes up
50351 + several holes that make full ASLR useless locally.
50352 +
50353 +config GRKERNSEC_BRUTE
50354 + bool "Deter exploit bruteforcing"
50355 + default y if GRKERNSEC_CONFIG_AUTO
50356 + help
50357 + If you say Y here, attempts to bruteforce exploits against forking
50358 + daemons such as apache or sshd, as well as against suid/sgid binaries
50359 + will be deterred. When a child of a forking daemon is killed by PaX
50360 + or crashes due to an illegal instruction or other suspicious signal,
50361 + the parent process will be delayed 30 seconds upon every subsequent
50362 + fork until the administrator is able to assess the situation and
50363 + restart the daemon.
50364 + In the suid/sgid case, the attempt is logged, the user has all their
50365 + processes terminated, and they are prevented from executing any further
50366 + processes for 15 minutes.
50367 + It is recommended that you also enable signal logging in the auditing
50368 + section so that logs are generated when a process triggers a suspicious
50369 + signal.
50370 + If the sysctl option is enabled, a sysctl option with name
50371 + "deter_bruteforce" is created.
50372 +
50373 +
50374 +config GRKERNSEC_MODHARDEN
50375 + bool "Harden module auto-loading"
50376 + default y if GRKERNSEC_CONFIG_AUTO
50377 + depends on MODULES
50378 + help
50379 + If you say Y here, module auto-loading in response to use of some
50380 + feature implemented by an unloaded module will be restricted to
50381 + root users. Enabling this option helps defend against attacks
50382 + by unprivileged users who abuse the auto-loading behavior to
50383 + cause a vulnerable module to load that is then exploited.
50384 +
50385 + If this option prevents a legitimate use of auto-loading for a
50386 + non-root user, the administrator can execute modprobe manually
50387 + with the exact name of the module mentioned in the alert log.
50388 + Alternatively, the administrator can add the module to the list
50389 + of modules loaded at boot by modifying init scripts.
50390 +
50391 + Modification of init scripts will most likely be needed on
50392 + Ubuntu servers with encrypted home directory support enabled,
50393 + as the first non-root user logging in will cause the ecb(aes),
50394 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50395 +
50396 +config GRKERNSEC_HIDESYM
50397 + bool "Hide kernel symbols"
50398 + default y if GRKERNSEC_CONFIG_AUTO
50399 + select PAX_USERCOPY_SLABS
50400 + help
50401 + If you say Y here, getting information on loaded modules, and
50402 + displaying all kernel symbols through a syscall will be restricted
50403 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50404 + /proc/kallsyms will be restricted to the root user. The RBAC
50405 + system can hide that entry even from root.
50406 +
50407 + This option also prevents leaking of kernel addresses through
50408 + several /proc entries.
50409 +
50410 + Note that this option is only effective provided the following
50411 + conditions are met:
50412 + 1) The kernel using grsecurity is not precompiled by some distribution
50413 + 2) You have also enabled GRKERNSEC_DMESG
50414 + 3) You are using the RBAC system and hiding other files such as your
50415 + kernel image and System.map. Alternatively, enabling this option
50416 + causes the permissions on /boot, /lib/modules, and the kernel
50417 + source directory to change at compile time to prevent
50418 + reading by non-root users.
50419 + If the above conditions are met, this option will aid in providing a
50420 + useful protection against local kernel exploitation of overflows
50421 + and arbitrary read/write vulnerabilities.
50422 +
50423 +config GRKERNSEC_KERN_LOCKOUT
50424 + bool "Active kernel exploit response"
50425 + default y if GRKERNSEC_CONFIG_AUTO
50426 + depends on X86 || ARM || PPC || SPARC
50427 + help
50428 + If you say Y here, when a PaX alert is triggered due to suspicious
50429 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50430 + or an OOPS occurs due to bad memory accesses, instead of just
50431 + terminating the offending process (and potentially allowing
50432 + a subsequent exploit from the same user), we will take one of two
50433 + actions:
50434 + If the user was root, we will panic the system
50435 + If the user was non-root, we will log the attempt, terminate
50436 + all processes owned by the user, then prevent them from creating
50437 + any new processes until the system is restarted
50438 + This deters repeated kernel exploitation/bruteforcing attempts
50439 + and is useful for later forensics.
50440 +
50441 +endmenu
50442 +menu "Role Based Access Control Options"
50443 +depends on GRKERNSEC
50444 +
50445 +config GRKERNSEC_RBAC_DEBUG
50446 + bool
50447 +
50448 +config GRKERNSEC_NO_RBAC
50449 + bool "Disable RBAC system"
50450 + help
50451 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50452 + preventing the RBAC system from being enabled. You should only say Y
50453 + here if you have no intention of using the RBAC system, so as to prevent
50454 + an attacker with root access from misusing the RBAC system to hide files
50455 + and processes when loadable module support and /dev/[k]mem have been
50456 + locked down.
50457 +
50458 +config GRKERNSEC_ACL_HIDEKERN
50459 + bool "Hide kernel processes"
50460 + help
50461 + If you say Y here, all kernel threads will be hidden to all
50462 + processes but those whose subject has the "view hidden processes"
50463 + flag.
50464 +
50465 +config GRKERNSEC_ACL_MAXTRIES
50466 + int "Maximum tries before password lockout"
50467 + default 3
50468 + help
50469 + This option enforces the maximum number of times a user can attempt
50470 + to authorize themselves with the grsecurity RBAC system before being
50471 + denied the ability to attempt authorization again for a specified time.
50472 + The lower the number, the harder it will be to brute-force a password.
50473 +
50474 +config GRKERNSEC_ACL_TIMEOUT
50475 + int "Time to wait after max password tries, in seconds"
50476 + default 30
50477 + help
50478 + This option specifies the time the user must wait after attempting to
50479 + authorize to the RBAC system with the maximum number of invalid
50480 + passwords. The higher the number, the harder it will be to brute-force
50481 + a password.
50482 +
50483 +endmenu
50484 +menu "Filesystem Protections"
50485 +depends on GRKERNSEC
50486 +
50487 +config GRKERNSEC_PROC
50488 + bool "Proc restrictions"
50489 + default y if GRKERNSEC_CONFIG_AUTO
50490 + help
50491 + If you say Y here, the permissions of the /proc filesystem
50492 + will be altered to enhance system security and privacy. You MUST
50493 + choose either a user only restriction or a user and group restriction.
50494 + Depending upon the option you choose, you can either restrict users to
50495 + see only the processes they themselves run, or choose a group that can
50496 + view all processes and files normally restricted to root if you choose
50497 + the "restrict to user only" option. NOTE: If you're running identd or
50498 + ntpd as a non-root user, you will have to run it as the group you
50499 + specify here.
50500 +
50501 +config GRKERNSEC_PROC_USER
50502 + bool "Restrict /proc to user only"
50503 + depends on GRKERNSEC_PROC
50504 + help
50505 + If you say Y here, non-root users will only be able to view their own
50506 + processes, and restricts them from viewing network-related information,
50507 + and viewing kernel symbol and module information.
50508 +
50509 +config GRKERNSEC_PROC_USERGROUP
50510 + bool "Allow special group"
50511 + default y if GRKERNSEC_CONFIG_AUTO
50512 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50513 + help
50514 + If you say Y here, you will be able to select a group that will be
50515 + able to view all processes and network-related information. If you've
50516 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50517 + remain hidden. This option is useful if you want to run identd as
50518 + a non-root user.
50519 +
50520 +config GRKERNSEC_PROC_GID
50521 + int "GID for special group"
50522 + depends on GRKERNSEC_PROC_USERGROUP
50523 + default 1001
50524 +
50525 +config GRKERNSEC_PROC_ADD
50526 + bool "Additional restrictions"
50527 + default y if GRKERNSEC_CONFIG_AUTO
50528 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50529 + help
50530 + If you say Y here, additional restrictions will be placed on
50531 + /proc that keep normal users from viewing device information and
50532 + slabinfo information that could be useful for exploits.
50533 +
50534 +config GRKERNSEC_LINK
50535 + bool "Linking restrictions"
50536 + default y if GRKERNSEC_CONFIG_AUTO
50537 + help
50538 + If you say Y here, /tmp race exploits will be prevented, since users
50539 + will no longer be able to follow symlinks owned by other users in
50540 + world-writable +t directories (e.g. /tmp), unless the owner of the
50541 + symlink is the owner of the directory. users will also not be
50542 + able to hardlink to files they do not own. If the sysctl option is
50543 + enabled, a sysctl option with name "linking_restrictions" is created.
50544 +
50545 +config GRKERNSEC_SYMLINKOWN
50546 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50547 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50548 + help
50549 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50550 + that prevents it from being used as a security feature. As Apache
50551 + verifies the symlink by performing a stat() against the target of
50552 + the symlink before it is followed, an attacker can setup a symlink
50553 + to point to a same-owned file, then replace the symlink with one
50554 + that targets another user's file just after Apache "validates" the
50555 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50556 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50557 + will be in place for the group you specify. If the sysctl option
50558 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50559 + created.
50560 +
50561 +config GRKERNSEC_SYMLINKOWN_GID
50562 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50563 + depends on GRKERNSEC_SYMLINKOWN
50564 + default 1006
50565 + help
50566 + Setting this GID determines what group kernel-enforced
50567 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50568 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50569 +
50570 +config GRKERNSEC_FIFO
50571 + bool "FIFO restrictions"
50572 + default y if GRKERNSEC_CONFIG_AUTO
50573 + help
50574 + If you say Y here, users will not be able to write to FIFOs they don't
50575 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50576 + the FIFO is the same owner of the directory it's held in. If the sysctl
50577 + option is enabled, a sysctl option with name "fifo_restrictions" is
50578 + created.
50579 +
50580 +config GRKERNSEC_SYSFS_RESTRICT
50581 + bool "Sysfs/debugfs restriction"
50582 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50583 + depends on SYSFS
50584 + help
50585 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50586 + any filesystem normally mounted under it (e.g. debugfs) will be
50587 + mostly accessible only by root. These filesystems generally provide access
50588 + to hardware and debug information that isn't appropriate for unprivileged
50589 + users of the system. Sysfs and debugfs have also become a large source
50590 + of new vulnerabilities, ranging from infoleaks to local compromise.
50591 + There has been very little oversight with an eye toward security involved
50592 + in adding new exporters of information to these filesystems, so their
50593 + use is discouraged.
50594 + For reasons of compatibility, a few directories have been whitelisted
50595 + for access by non-root users:
50596 + /sys/fs/selinux
50597 + /sys/fs/fuse
50598 + /sys/devices/system/cpu
50599 +
50600 +config GRKERNSEC_ROFS
50601 + bool "Runtime read-only mount protection"
50602 + help
50603 + If you say Y here, a sysctl option with name "romount_protect" will
50604 + be created. By setting this option to 1 at runtime, filesystems
50605 + will be protected in the following ways:
50606 + * No new writable mounts will be allowed
50607 + * Existing read-only mounts won't be able to be remounted read/write
50608 + * Write operations will be denied on all block devices
50609 + This option acts independently of grsec_lock: once it is set to 1,
50610 + it cannot be turned off. Therefore, please be mindful of the resulting
50611 + behavior if this option is enabled in an init script on a read-only
50612 + filesystem. This feature is mainly intended for secure embedded systems.
50613 +
50614 +config GRKERNSEC_CHROOT
50615 + bool "Chroot jail restrictions"
50616 + default y if GRKERNSEC_CONFIG_AUTO
50617 + help
50618 + If you say Y here, you will be able to choose several options that will
50619 + make breaking out of a chrooted jail much more difficult. If you
50620 + encounter no software incompatibilities with the following options, it
50621 + is recommended that you enable each one.
50622 +
50623 +config GRKERNSEC_CHROOT_MOUNT
50624 + bool "Deny mounts"
50625 + default y if GRKERNSEC_CONFIG_AUTO
50626 + depends on GRKERNSEC_CHROOT
50627 + help
50628 + If you say Y here, processes inside a chroot will not be able to
50629 + mount or remount filesystems. If the sysctl option is enabled, a
50630 + sysctl option with name "chroot_deny_mount" is created.
50631 +
50632 +config GRKERNSEC_CHROOT_DOUBLE
50633 + bool "Deny double-chroots"
50634 + default y if GRKERNSEC_CONFIG_AUTO
50635 + depends on GRKERNSEC_CHROOT
50636 + help
50637 + If you say Y here, processes inside a chroot will not be able to chroot
50638 + again outside the chroot. This is a widely used method of breaking
50639 + out of a chroot jail and should not be allowed. If the sysctl
50640 + option is enabled, a sysctl option with name
50641 + "chroot_deny_chroot" is created.
50642 +
50643 +config GRKERNSEC_CHROOT_PIVOT
50644 + bool "Deny pivot_root in chroot"
50645 + default y if GRKERNSEC_CONFIG_AUTO
50646 + depends on GRKERNSEC_CHROOT
50647 + help
50648 + If you say Y here, processes inside a chroot will not be able to use
50649 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50650 + works similar to chroot in that it changes the root filesystem. This
50651 + function could be misused in a chrooted process to attempt to break out
50652 + of the chroot, and therefore should not be allowed. If the sysctl
50653 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50654 + created.
50655 +
50656 +config GRKERNSEC_CHROOT_CHDIR
50657 + bool "Enforce chdir(\"/\") on all chroots"
50658 + default y if GRKERNSEC_CONFIG_AUTO
50659 + depends on GRKERNSEC_CHROOT
50660 + help
50661 + If you say Y here, the current working directory of all newly-chrooted
50662 + applications will be set to the the root directory of the chroot.
50663 + The man page on chroot(2) states:
50664 + Note that this call does not change the current working
50665 + directory, so that `.' can be outside the tree rooted at
50666 + `/'. In particular, the super-user can escape from a
50667 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50668 +
50669 + It is recommended that you say Y here, since it's not known to break
50670 + any software. If the sysctl option is enabled, a sysctl option with
50671 + name "chroot_enforce_chdir" is created.
50672 +
50673 +config GRKERNSEC_CHROOT_CHMOD
50674 + bool "Deny (f)chmod +s"
50675 + default y if GRKERNSEC_CONFIG_AUTO
50676 + depends on GRKERNSEC_CHROOT
50677 + help
50678 + If you say Y here, processes inside a chroot will not be able to chmod
50679 + or fchmod files to make them have suid or sgid bits. This protects
50680 + against another published method of breaking a chroot. If the sysctl
50681 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50682 + created.
50683 +
50684 +config GRKERNSEC_CHROOT_FCHDIR
50685 + bool "Deny fchdir out of chroot"
50686 + default y if GRKERNSEC_CONFIG_AUTO
50687 + depends on GRKERNSEC_CHROOT
50688 + help
50689 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50690 + to a file descriptor of the chrooting process that points to a directory
50691 + outside the filesystem will be stopped. If the sysctl option
50692 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50693 +
50694 +config GRKERNSEC_CHROOT_MKNOD
50695 + bool "Deny mknod"
50696 + default y if GRKERNSEC_CONFIG_AUTO
50697 + depends on GRKERNSEC_CHROOT
50698 + help
50699 + If you say Y here, processes inside a chroot will not be allowed to
50700 + mknod. The problem with using mknod inside a chroot is that it
50701 + would allow an attacker to create a device entry that is the same
50702 + as one on the physical root of your system, which could range from
50703 + anything from the console device to a device for your harddrive (which
50704 + they could then use to wipe the drive or steal data). It is recommended
50705 + that you say Y here, unless you run into software incompatibilities.
50706 + If the sysctl option is enabled, a sysctl option with name
50707 + "chroot_deny_mknod" is created.
50708 +
50709 +config GRKERNSEC_CHROOT_SHMAT
50710 + bool "Deny shmat() out of chroot"
50711 + default y if GRKERNSEC_CONFIG_AUTO
50712 + depends on GRKERNSEC_CHROOT
50713 + help
50714 + If you say Y here, processes inside a chroot will not be able to attach
50715 + to shared memory segments that were created outside of the chroot jail.
50716 + It is recommended that you say Y here. If the sysctl option is enabled,
50717 + a sysctl option with name "chroot_deny_shmat" is created.
50718 +
50719 +config GRKERNSEC_CHROOT_UNIX
50720 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50721 + default y if GRKERNSEC_CONFIG_AUTO
50722 + depends on GRKERNSEC_CHROOT
50723 + help
50724 + If you say Y here, processes inside a chroot will not be able to
50725 + connect to abstract (meaning not belonging to a filesystem) Unix
50726 + domain sockets that were bound outside of a chroot. It is recommended
50727 + that you say Y here. If the sysctl option is enabled, a sysctl option
50728 + with name "chroot_deny_unix" is created.
50729 +
50730 +config GRKERNSEC_CHROOT_FINDTASK
50731 + bool "Protect outside processes"
50732 + default y if GRKERNSEC_CONFIG_AUTO
50733 + depends on GRKERNSEC_CHROOT
50734 + help
50735 + If you say Y here, processes inside a chroot will not be able to
50736 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50737 + getsid, or view any process outside of the chroot. If the sysctl
50738 + option is enabled, a sysctl option with name "chroot_findtask" is
50739 + created.
50740 +
50741 +config GRKERNSEC_CHROOT_NICE
50742 + bool "Restrict priority changes"
50743 + default y if GRKERNSEC_CONFIG_AUTO
50744 + depends on GRKERNSEC_CHROOT
50745 + help
50746 + If you say Y here, processes inside a chroot will not be able to raise
50747 + the priority of processes in the chroot, or alter the priority of
50748 + processes outside the chroot. This provides more security than simply
50749 + removing CAP_SYS_NICE from the process' capability set. If the
50750 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50751 + is created.
50752 +
50753 +config GRKERNSEC_CHROOT_SYSCTL
50754 + bool "Deny sysctl writes"
50755 + default y if GRKERNSEC_CONFIG_AUTO
50756 + depends on GRKERNSEC_CHROOT
50757 + help
50758 + If you say Y here, an attacker in a chroot will not be able to
50759 + write to sysctl entries, either by sysctl(2) or through a /proc
50760 + interface. It is strongly recommended that you say Y here. If the
50761 + sysctl option is enabled, a sysctl option with name
50762 + "chroot_deny_sysctl" is created.
50763 +
50764 +config GRKERNSEC_CHROOT_CAPS
50765 + bool "Capability restrictions"
50766 + default y if GRKERNSEC_CONFIG_AUTO
50767 + depends on GRKERNSEC_CHROOT
50768 + help
50769 + If you say Y here, the capabilities on all processes within a
50770 + chroot jail will be lowered to stop module insertion, raw i/o,
50771 + system and net admin tasks, rebooting the system, modifying immutable
50772 + files, modifying IPC owned by another, and changing the system time.
50773 + This is left an option because it can break some apps. Disable this
50774 + if your chrooted apps are having problems performing those kinds of
50775 + tasks. If the sysctl option is enabled, a sysctl option with
50776 + name "chroot_caps" is created.
50777 +
50778 +endmenu
50779 +menu "Kernel Auditing"
50780 +depends on GRKERNSEC
50781 +
50782 +config GRKERNSEC_AUDIT_GROUP
50783 + bool "Single group for auditing"
50784 + help
50785 + If you say Y here, the exec, chdir, and (un)mount logging features
50786 + will only operate on a group you specify. This option is recommended
50787 + if you only want to watch certain users instead of having a large
50788 + amount of logs from the entire system. If the sysctl option is enabled,
50789 + a sysctl option with name "audit_group" is created.
50790 +
50791 +config GRKERNSEC_AUDIT_GID
50792 + int "GID for auditing"
50793 + depends on GRKERNSEC_AUDIT_GROUP
50794 + default 1007
50795 +
50796 +config GRKERNSEC_EXECLOG
50797 + bool "Exec logging"
50798 + help
50799 + If you say Y here, all execve() calls will be logged (since the
50800 + other exec*() calls are frontends to execve(), all execution
50801 + will be logged). Useful for shell-servers that like to keep track
50802 + of their users. If the sysctl option is enabled, a sysctl option with
50803 + name "exec_logging" is created.
50804 + WARNING: This option when enabled will produce a LOT of logs, especially
50805 + on an active system.
50806 +
50807 +config GRKERNSEC_RESLOG
50808 + bool "Resource logging"
50809 + default y if GRKERNSEC_CONFIG_AUTO
50810 + help
50811 + If you say Y here, all attempts to overstep resource limits will
50812 + be logged with the resource name, the requested size, and the current
50813 + limit. It is highly recommended that you say Y here. If the sysctl
50814 + option is enabled, a sysctl option with name "resource_logging" is
50815 + created. If the RBAC system is enabled, the sysctl value is ignored.
50816 +
50817 +config GRKERNSEC_CHROOT_EXECLOG
50818 + bool "Log execs within chroot"
50819 + help
50820 + If you say Y here, all executions inside a chroot jail will be logged
50821 + to syslog. This can cause a large amount of logs if certain
50822 + applications (eg. djb's daemontools) are installed on the system, and
50823 + is therefore left as an option. If the sysctl option is enabled, a
50824 + sysctl option with name "chroot_execlog" is created.
50825 +
50826 +config GRKERNSEC_AUDIT_PTRACE
50827 + bool "Ptrace logging"
50828 + help
50829 + If you say Y here, all attempts to attach to a process via ptrace
50830 + will be logged. If the sysctl option is enabled, a sysctl option
50831 + with name "audit_ptrace" is created.
50832 +
50833 +config GRKERNSEC_AUDIT_CHDIR
50834 + bool "Chdir logging"
50835 + help
50836 + If you say Y here, all chdir() calls will be logged. If the sysctl
50837 + option is enabled, a sysctl option with name "audit_chdir" is created.
50838 +
50839 +config GRKERNSEC_AUDIT_MOUNT
50840 + bool "(Un)Mount logging"
50841 + help
50842 + If you say Y here, all mounts and unmounts will be logged. If the
50843 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50844 + created.
50845 +
50846 +config GRKERNSEC_SIGNAL
50847 + bool "Signal logging"
50848 + default y if GRKERNSEC_CONFIG_AUTO
50849 + help
50850 + If you say Y here, certain important signals will be logged, such as
50851 + SIGSEGV, which will as a result inform you of when a error in a program
50852 + occurred, which in some cases could mean a possible exploit attempt.
50853 + If the sysctl option is enabled, a sysctl option with name
50854 + "signal_logging" is created.
50855 +
50856 +config GRKERNSEC_FORKFAIL
50857 + bool "Fork failure logging"
50858 + help
50859 + If you say Y here, all failed fork() attempts will be logged.
50860 + This could suggest a fork bomb, or someone attempting to overstep
50861 + their process limit. If the sysctl option is enabled, a sysctl option
50862 + with name "forkfail_logging" is created.
50863 +
50864 +config GRKERNSEC_TIME
50865 + bool "Time change logging"
50866 + default y if GRKERNSEC_CONFIG_AUTO
50867 + help
50868 + If you say Y here, any changes of the system clock will be logged.
50869 + If the sysctl option is enabled, a sysctl option with name
50870 + "timechange_logging" is created.
50871 +
50872 +config GRKERNSEC_PROC_IPADDR
50873 + bool "/proc/<pid>/ipaddr support"
50874 + default y if GRKERNSEC_CONFIG_AUTO
50875 + help
50876 + If you say Y here, a new entry will be added to each /proc/<pid>
50877 + directory that contains the IP address of the person using the task.
50878 + The IP is carried across local TCP and AF_UNIX stream sockets.
50879 + This information can be useful for IDS/IPSes to perform remote response
50880 + to a local attack. The entry is readable by only the owner of the
50881 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50882 + the RBAC system), and thus does not create privacy concerns.
50883 +
50884 +config GRKERNSEC_RWXMAP_LOG
50885 + bool 'Denied RWX mmap/mprotect logging'
50886 + default y if GRKERNSEC_CONFIG_AUTO
50887 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50888 + help
50889 + If you say Y here, calls to mmap() and mprotect() with explicit
50890 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50891 + denied by the PAX_MPROTECT feature. If the sysctl option is
50892 + enabled, a sysctl option with name "rwxmap_logging" is created.
50893 +
50894 +config GRKERNSEC_AUDIT_TEXTREL
50895 + bool 'ELF text relocations logging (READ HELP)'
50896 + depends on PAX_MPROTECT
50897 + help
50898 + If you say Y here, text relocations will be logged with the filename
50899 + of the offending library or binary. The purpose of the feature is
50900 + to help Linux distribution developers get rid of libraries and
50901 + binaries that need text relocations which hinder the future progress
50902 + of PaX. Only Linux distribution developers should say Y here, and
50903 + never on a production machine, as this option creates an information
50904 + leak that could aid an attacker in defeating the randomization of
50905 + a single memory region. If the sysctl option is enabled, a sysctl
50906 + option with name "audit_textrel" is created.
50907 +
50908 +endmenu
50909 +
50910 +menu "Executable Protections"
50911 +depends on GRKERNSEC
50912 +
50913 +config GRKERNSEC_DMESG
50914 + bool "Dmesg(8) restriction"
50915 + default y if GRKERNSEC_CONFIG_AUTO
50916 + help
50917 + If you say Y here, non-root users will not be able to use dmesg(8)
50918 + to view up to the last 4kb of messages in the kernel's log buffer.
50919 + The kernel's log buffer often contains kernel addresses and other
50920 + identifying information useful to an attacker in fingerprinting a
50921 + system for a targeted exploit.
50922 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50923 + created.
50924 +
50925 +config GRKERNSEC_HARDEN_PTRACE
50926 + bool "Deter ptrace-based process snooping"
50927 + default y if GRKERNSEC_CONFIG_AUTO
50928 + help
50929 + If you say Y here, TTY sniffers and other malicious monitoring
50930 + programs implemented through ptrace will be defeated. If you
50931 + have been using the RBAC system, this option has already been
50932 + enabled for several years for all users, with the ability to make
50933 + fine-grained exceptions.
50934 +
50935 + This option only affects the ability of non-root users to ptrace
50936 + processes that are not a descendent of the ptracing process.
50937 + This means that strace ./binary and gdb ./binary will still work,
50938 + but attaching to arbitrary processes will not. If the sysctl
50939 + option is enabled, a sysctl option with name "harden_ptrace" is
50940 + created.
50941 +
50942 +config GRKERNSEC_PTRACE_READEXEC
50943 + bool "Require read access to ptrace sensitive binaries"
50944 + default y if GRKERNSEC_CONFIG_AUTO
50945 + help
50946 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50947 + binaries. This option is useful in environments that
50948 + remove the read bits (e.g. file mode 4711) from suid binaries to
50949 + prevent infoleaking of their contents. This option adds
50950 + consistency to the use of that file mode, as the binary could normally
50951 + be read out when run without privileges while ptracing.
50952 +
50953 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50954 + is created.
50955 +
50956 +config GRKERNSEC_SETXID
50957 + bool "Enforce consistent multithreaded privileges"
50958 + default y if GRKERNSEC_CONFIG_AUTO
50959 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50960 + help
50961 + If you say Y here, a change from a root uid to a non-root uid
50962 + in a multithreaded application will cause the resulting uids,
50963 + gids, supplementary groups, and capabilities in that thread
50964 + to be propagated to the other threads of the process. In most
50965 + cases this is unnecessary, as glibc will emulate this behavior
50966 + on behalf of the application. Other libcs do not act in the
50967 + same way, allowing the other threads of the process to continue
50968 + running with root privileges. If the sysctl option is enabled,
50969 + a sysctl option with name "consistent_setxid" is created.
50970 +
50971 +config GRKERNSEC_TPE
50972 + bool "Trusted Path Execution (TPE)"
50973 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50974 + help
50975 + If you say Y here, you will be able to choose a gid to add to the
50976 + supplementary groups of users you want to mark as "untrusted."
50977 + These users will not be able to execute any files that are not in
50978 + root-owned directories writable only by root. If the sysctl option
50979 + is enabled, a sysctl option with name "tpe" is created.
50980 +
50981 +config GRKERNSEC_TPE_ALL
50982 + bool "Partially restrict all non-root users"
50983 + depends on GRKERNSEC_TPE
50984 + help
50985 + If you say Y here, all non-root users will be covered under
50986 + a weaker TPE restriction. This is separate from, and in addition to,
50987 + the main TPE options that you have selected elsewhere. Thus, if a
50988 + "trusted" GID is chosen, this restriction applies to even that GID.
50989 + Under this restriction, all non-root users will only be allowed to
50990 + execute files in directories they own that are not group or
50991 + world-writable, or in directories owned by root and writable only by
50992 + root. If the sysctl option is enabled, a sysctl option with name
50993 + "tpe_restrict_all" is created.
50994 +
50995 +config GRKERNSEC_TPE_INVERT
50996 + bool "Invert GID option"
50997 + depends on GRKERNSEC_TPE
50998 + help
50999 + If you say Y here, the group you specify in the TPE configuration will
51000 + decide what group TPE restrictions will be *disabled* for. This
51001 + option is useful if you want TPE restrictions to be applied to most
51002 + users on the system. If the sysctl option is enabled, a sysctl option
51003 + with name "tpe_invert" is created. Unlike other sysctl options, this
51004 + entry will default to on for backward-compatibility.
51005 +
51006 +config GRKERNSEC_TPE_GID
51007 + int "GID for untrusted users"
51008 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51009 + default 1005
51010 + help
51011 + Setting this GID determines what group TPE restrictions will be
51012 + *enabled* for. If the sysctl option is enabled, a sysctl option
51013 + with name "tpe_gid" is created.
51014 +
51015 +config GRKERNSEC_TPE_GID
51016 + int "GID for trusted users"
51017 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51018 + default 1005
51019 + help
51020 + Setting this GID determines what group TPE restrictions will be
51021 + *disabled* for. If the sysctl option is enabled, a sysctl option
51022 + with name "tpe_gid" is created.
51023 +
51024 +endmenu
51025 +menu "Network Protections"
51026 +depends on GRKERNSEC
51027 +
51028 +config GRKERNSEC_RANDNET
51029 + bool "Larger entropy pools"
51030 + default y if GRKERNSEC_CONFIG_AUTO
51031 + help
51032 + If you say Y here, the entropy pools used for many features of Linux
51033 + and grsecurity will be doubled in size. Since several grsecurity
51034 + features use additional randomness, it is recommended that you say Y
51035 + here. Saying Y here has a similar effect as modifying
51036 + /proc/sys/kernel/random/poolsize.
51037 +
51038 +config GRKERNSEC_BLACKHOLE
51039 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51040 + default y if GRKERNSEC_CONFIG_AUTO
51041 + depends on NET
51042 + help
51043 + If you say Y here, neither TCP resets nor ICMP
51044 + destination-unreachable packets will be sent in response to packets
51045 + sent to ports for which no associated listening process exists.
51046 + This feature supports both IPV4 and IPV6 and exempts the
51047 + loopback interface from blackholing. Enabling this feature
51048 + makes a host more resilient to DoS attacks and reduces network
51049 + visibility against scanners.
51050 +
51051 + The blackhole feature as-implemented is equivalent to the FreeBSD
51052 + blackhole feature, as it prevents RST responses to all packets, not
51053 + just SYNs. Under most application behavior this causes no
51054 + problems, but applications (like haproxy) may not close certain
51055 + connections in a way that cleanly terminates them on the remote
51056 + end, leaving the remote host in LAST_ACK state. Because of this
51057 + side-effect and to prevent intentional LAST_ACK DoSes, this
51058 + feature also adds automatic mitigation against such attacks.
51059 + The mitigation drastically reduces the amount of time a socket
51060 + can spend in LAST_ACK state. If you're using haproxy and not
51061 + all servers it connects to have this option enabled, consider
51062 + disabling this feature on the haproxy host.
51063 +
51064 + If the sysctl option is enabled, two sysctl options with names
51065 + "ip_blackhole" and "lastack_retries" will be created.
51066 + While "ip_blackhole" takes the standard zero/non-zero on/off
51067 + toggle, "lastack_retries" uses the same kinds of values as
51068 + "tcp_retries1" and "tcp_retries2". The default value of 4
51069 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51070 + state.
51071 +
51072 +config GRKERNSEC_SOCKET
51073 + bool "Socket restrictions"
51074 + depends on NET
51075 + help
51076 + If you say Y here, you will be able to choose from several options.
51077 + If you assign a GID on your system and add it to the supplementary
51078 + groups of users you want to restrict socket access to, this patch
51079 + will perform up to three things, based on the option(s) you choose.
51080 +
51081 +config GRKERNSEC_SOCKET_ALL
51082 + bool "Deny any sockets to group"
51083 + depends on GRKERNSEC_SOCKET
51084 + help
51085 + If you say Y here, you will be able to choose a GID of whose users will
51086 + be unable to connect to other hosts from your machine or run server
51087 + applications from your machine. If the sysctl option is enabled, a
51088 + sysctl option with name "socket_all" is created.
51089 +
51090 +config GRKERNSEC_SOCKET_ALL_GID
51091 + int "GID to deny all sockets for"
51092 + depends on GRKERNSEC_SOCKET_ALL
51093 + default 1004
51094 + help
51095 + Here you can choose the GID to disable socket access for. Remember to
51096 + add the users you want socket access disabled for to the GID
51097 + specified here. If the sysctl option is enabled, a sysctl option
51098 + with name "socket_all_gid" is created.
51099 +
51100 +config GRKERNSEC_SOCKET_CLIENT
51101 + bool "Deny client sockets to group"
51102 + depends on GRKERNSEC_SOCKET
51103 + help
51104 + If you say Y here, you will be able to choose a GID of whose users will
51105 + be unable to connect to other hosts from your machine, but will be
51106 + able to run servers. If this option is enabled, all users in the group
51107 + you specify will have to use passive mode when initiating ftp transfers
51108 + from the shell on your machine. If the sysctl option is enabled, a
51109 + sysctl option with name "socket_client" is created.
51110 +
51111 +config GRKERNSEC_SOCKET_CLIENT_GID
51112 + int "GID to deny client sockets for"
51113 + depends on GRKERNSEC_SOCKET_CLIENT
51114 + default 1003
51115 + help
51116 + Here you can choose the GID to disable client socket access for.
51117 + Remember to add the users you want client socket access disabled for to
51118 + the GID specified here. If the sysctl option is enabled, a sysctl
51119 + option with name "socket_client_gid" is created.
51120 +
51121 +config GRKERNSEC_SOCKET_SERVER
51122 + bool "Deny server sockets to group"
51123 + depends on GRKERNSEC_SOCKET
51124 + help
51125 + If you say Y here, you will be able to choose a GID of whose users will
51126 + be unable to run server applications from your machine. If the sysctl
51127 + option is enabled, a sysctl option with name "socket_server" is created.
51128 +
51129 +config GRKERNSEC_SOCKET_SERVER_GID
51130 + int "GID to deny server sockets for"
51131 + depends on GRKERNSEC_SOCKET_SERVER
51132 + default 1002
51133 + help
51134 + Here you can choose the GID to disable server socket access for.
51135 + Remember to add the users you want server socket access disabled for to
51136 + the GID specified here. If the sysctl option is enabled, a sysctl
51137 + option with name "socket_server_gid" is created.
51138 +
51139 +endmenu
51140 +menu "Sysctl Support"
51141 +depends on GRKERNSEC && SYSCTL
51142 +
51143 +config GRKERNSEC_SYSCTL
51144 + bool "Sysctl support"
51145 + default y if GRKERNSEC_CONFIG_AUTO
51146 + help
51147 + If you say Y here, you will be able to change the options that
51148 + grsecurity runs with at bootup, without having to recompile your
51149 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51150 + to enable (1) or disable (0) various features. All the sysctl entries
51151 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51152 + All features enabled in the kernel configuration are disabled at boot
51153 + if you do not say Y to the "Turn on features by default" option.
51154 + All options should be set at startup, and the grsec_lock entry should
51155 + be set to a non-zero value after all the options are set.
51156 + *THIS IS EXTREMELY IMPORTANT*
51157 +
51158 +config GRKERNSEC_SYSCTL_DISTRO
51159 + bool "Extra sysctl support for distro makers (READ HELP)"
51160 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51161 + help
51162 + If you say Y here, additional sysctl options will be created
51163 + for features that affect processes running as root. Therefore,
51164 + it is critical when using this option that the grsec_lock entry be
51165 + enabled after boot. Only distros with prebuilt kernel packages
51166 + with this option enabled that can ensure grsec_lock is enabled
51167 + after boot should use this option.
51168 + *Failure to set grsec_lock after boot makes all grsec features
51169 + this option covers useless*
51170 +
51171 + Currently this option creates the following sysctl entries:
51172 + "Disable Privileged I/O": "disable_priv_io"
51173 +
51174 +config GRKERNSEC_SYSCTL_ON
51175 + bool "Turn on features by default"
51176 + default y if GRKERNSEC_CONFIG_AUTO
51177 + depends on GRKERNSEC_SYSCTL
51178 + help
51179 + If you say Y here, instead of having all features enabled in the
51180 + kernel configuration disabled at boot time, the features will be
51181 + enabled at boot time. It is recommended you say Y here unless
51182 + there is some reason you would want all sysctl-tunable features to
51183 + be disabled by default. As mentioned elsewhere, it is important
51184 + to enable the grsec_lock entry once you have finished modifying
51185 + the sysctl entries.
51186 +
51187 +endmenu
51188 +menu "Logging Options"
51189 +depends on GRKERNSEC
51190 +
51191 +config GRKERNSEC_FLOODTIME
51192 + int "Seconds in between log messages (minimum)"
51193 + default 10
51194 + help
51195 + This option allows you to enforce the number of seconds between
51196 + grsecurity log messages. The default should be suitable for most
51197 + people, however, if you choose to change it, choose a value small enough
51198 + to allow informative logs to be produced, but large enough to
51199 + prevent flooding.
51200 +
51201 +config GRKERNSEC_FLOODBURST
51202 + int "Number of messages in a burst (maximum)"
51203 + default 6
51204 + help
51205 + This option allows you to choose the maximum number of messages allowed
51206 + within the flood time interval you chose in a separate option. The
51207 + default should be suitable for most people, however if you find that
51208 + many of your logs are being interpreted as flooding, you may want to
51209 + raise this value.
51210 +
51211 +endmenu
51212 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51213 new file mode 100644
51214 index 0000000..1b9afa9
51215 --- /dev/null
51216 +++ b/grsecurity/Makefile
51217 @@ -0,0 +1,38 @@
51218 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51219 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51220 +# into an RBAC system
51221 +#
51222 +# All code in this directory and various hooks inserted throughout the kernel
51223 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51224 +# under the GPL v2 or higher
51225 +
51226 +KBUILD_CFLAGS += -Werror
51227 +
51228 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51229 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51230 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51231 +
51232 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51233 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51234 + gracl_learn.o grsec_log.o
51235 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51236 +
51237 +ifdef CONFIG_NET
51238 +obj-y += grsec_sock.o
51239 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51240 +endif
51241 +
51242 +ifndef CONFIG_GRKERNSEC
51243 +obj-y += grsec_disabled.o
51244 +endif
51245 +
51246 +ifdef CONFIG_GRKERNSEC_HIDESYM
51247 +extra-y := grsec_hidesym.o
51248 +$(obj)/grsec_hidesym.o:
51249 + @-chmod -f 500 /boot
51250 + @-chmod -f 500 /lib/modules
51251 + @-chmod -f 500 /lib64/modules
51252 + @-chmod -f 500 /lib32/modules
51253 + @-chmod -f 700 .
51254 + @echo ' grsec: protected kernel image paths'
51255 +endif
51256 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51257 new file mode 100644
51258 index 0000000..1561617
51259 --- /dev/null
51260 +++ b/grsecurity/gracl.c
51261 @@ -0,0 +1,4017 @@
51262 +#include <linux/kernel.h>
51263 +#include <linux/module.h>
51264 +#include <linux/sched.h>
51265 +#include <linux/mm.h>
51266 +#include <linux/file.h>
51267 +#include <linux/fs.h>
51268 +#include <linux/namei.h>
51269 +#include <linux/mount.h>
51270 +#include <linux/tty.h>
51271 +#include <linux/proc_fs.h>
51272 +#include <linux/lglock.h>
51273 +#include <linux/slab.h>
51274 +#include <linux/vmalloc.h>
51275 +#include <linux/types.h>
51276 +#include <linux/sysctl.h>
51277 +#include <linux/netdevice.h>
51278 +#include <linux/ptrace.h>
51279 +#include <linux/gracl.h>
51280 +#include <linux/gralloc.h>
51281 +#include <linux/security.h>
51282 +#include <linux/grinternal.h>
51283 +#include <linux/pid_namespace.h>
51284 +#include <linux/stop_machine.h>
51285 +#include <linux/fdtable.h>
51286 +#include <linux/percpu.h>
51287 +#include <linux/lglock.h>
51288 +#include "../fs/mount.h"
51289 +
51290 +#include <asm/uaccess.h>
51291 +#include <asm/errno.h>
51292 +#include <asm/mman.h>
51293 +
51294 +extern struct lglock vfsmount_lock;
51295 +
51296 +static struct acl_role_db acl_role_set;
51297 +static struct name_db name_set;
51298 +static struct inodev_db inodev_set;
51299 +
51300 +/* for keeping track of userspace pointers used for subjects, so we
51301 + can share references in the kernel as well
51302 +*/
51303 +
51304 +static struct path real_root;
51305 +
51306 +static struct acl_subj_map_db subj_map_set;
51307 +
51308 +static struct acl_role_label *default_role;
51309 +
51310 +static struct acl_role_label *role_list;
51311 +
51312 +static u16 acl_sp_role_value;
51313 +
51314 +extern char *gr_shared_page[4];
51315 +static DEFINE_MUTEX(gr_dev_mutex);
51316 +DEFINE_RWLOCK(gr_inode_lock);
51317 +
51318 +struct gr_arg *gr_usermode;
51319 +
51320 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51321 +
51322 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51323 +extern void gr_clear_learn_entries(void);
51324 +
51325 +#ifdef CONFIG_GRKERNSEC_RESLOG
51326 +extern void gr_log_resource(const struct task_struct *task,
51327 + const int res, const unsigned long wanted, const int gt);
51328 +#endif
51329 +
51330 +unsigned char *gr_system_salt;
51331 +unsigned char *gr_system_sum;
51332 +
51333 +static struct sprole_pw **acl_special_roles = NULL;
51334 +static __u16 num_sprole_pws = 0;
51335 +
51336 +static struct acl_role_label *kernel_role = NULL;
51337 +
51338 +static unsigned int gr_auth_attempts = 0;
51339 +static unsigned long gr_auth_expires = 0UL;
51340 +
51341 +#ifdef CONFIG_NET
51342 +extern struct vfsmount *sock_mnt;
51343 +#endif
51344 +
51345 +extern struct vfsmount *pipe_mnt;
51346 +extern struct vfsmount *shm_mnt;
51347 +#ifdef CONFIG_HUGETLBFS
51348 +extern struct vfsmount *hugetlbfs_vfsmount;
51349 +#endif
51350 +
51351 +static struct acl_object_label *fakefs_obj_rw;
51352 +static struct acl_object_label *fakefs_obj_rwx;
51353 +
51354 +extern int gr_init_uidset(void);
51355 +extern void gr_free_uidset(void);
51356 +extern void gr_remove_uid(uid_t uid);
51357 +extern int gr_find_uid(uid_t uid);
51358 +
51359 +__inline__ int
51360 +gr_acl_is_enabled(void)
51361 +{
51362 + return (gr_status & GR_READY);
51363 +}
51364 +
51365 +#ifdef CONFIG_BTRFS_FS
51366 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51367 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51368 +#endif
51369 +
51370 +static inline dev_t __get_dev(const struct dentry *dentry)
51371 +{
51372 +#ifdef CONFIG_BTRFS_FS
51373 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51374 + return get_btrfs_dev_from_inode(dentry->d_inode);
51375 + else
51376 +#endif
51377 + return dentry->d_inode->i_sb->s_dev;
51378 +}
51379 +
51380 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51381 +{
51382 + return __get_dev(dentry);
51383 +}
51384 +
51385 +static char gr_task_roletype_to_char(struct task_struct *task)
51386 +{
51387 + switch (task->role->roletype &
51388 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51389 + GR_ROLE_SPECIAL)) {
51390 + case GR_ROLE_DEFAULT:
51391 + return 'D';
51392 + case GR_ROLE_USER:
51393 + return 'U';
51394 + case GR_ROLE_GROUP:
51395 + return 'G';
51396 + case GR_ROLE_SPECIAL:
51397 + return 'S';
51398 + }
51399 +
51400 + return 'X';
51401 +}
51402 +
51403 +char gr_roletype_to_char(void)
51404 +{
51405 + return gr_task_roletype_to_char(current);
51406 +}
51407 +
51408 +__inline__ int
51409 +gr_acl_tpe_check(void)
51410 +{
51411 + if (unlikely(!(gr_status & GR_READY)))
51412 + return 0;
51413 + if (current->role->roletype & GR_ROLE_TPE)
51414 + return 1;
51415 + else
51416 + return 0;
51417 +}
51418 +
51419 +int
51420 +gr_handle_rawio(const struct inode *inode)
51421 +{
51422 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51423 + if (inode && S_ISBLK(inode->i_mode) &&
51424 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51425 + !capable(CAP_SYS_RAWIO))
51426 + return 1;
51427 +#endif
51428 + return 0;
51429 +}
51430 +
51431 +static int
51432 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51433 +{
51434 + if (likely(lena != lenb))
51435 + return 0;
51436 +
51437 + return !memcmp(a, b, lena);
51438 +}
51439 +
51440 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51441 +{
51442 + *buflen -= namelen;
51443 + if (*buflen < 0)
51444 + return -ENAMETOOLONG;
51445 + *buffer -= namelen;
51446 + memcpy(*buffer, str, namelen);
51447 + return 0;
51448 +}
51449 +
51450 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51451 +{
51452 + return prepend(buffer, buflen, name->name, name->len);
51453 +}
51454 +
51455 +static int prepend_path(const struct path *path, struct path *root,
51456 + char **buffer, int *buflen)
51457 +{
51458 + struct dentry *dentry = path->dentry;
51459 + struct vfsmount *vfsmnt = path->mnt;
51460 + struct mount *mnt = real_mount(vfsmnt);
51461 + bool slash = false;
51462 + int error = 0;
51463 +
51464 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51465 + struct dentry * parent;
51466 +
51467 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51468 + /* Global root? */
51469 + if (!mnt_has_parent(mnt)) {
51470 + goto out;
51471 + }
51472 + dentry = mnt->mnt_mountpoint;
51473 + mnt = mnt->mnt_parent;
51474 + vfsmnt = &mnt->mnt;
51475 + continue;
51476 + }
51477 + parent = dentry->d_parent;
51478 + prefetch(parent);
51479 + spin_lock(&dentry->d_lock);
51480 + error = prepend_name(buffer, buflen, &dentry->d_name);
51481 + spin_unlock(&dentry->d_lock);
51482 + if (!error)
51483 + error = prepend(buffer, buflen, "/", 1);
51484 + if (error)
51485 + break;
51486 +
51487 + slash = true;
51488 + dentry = parent;
51489 + }
51490 +
51491 +out:
51492 + if (!error && !slash)
51493 + error = prepend(buffer, buflen, "/", 1);
51494 +
51495 + return error;
51496 +}
51497 +
51498 +/* this must be called with vfsmount_lock and rename_lock held */
51499 +
51500 +static char *__our_d_path(const struct path *path, struct path *root,
51501 + char *buf, int buflen)
51502 +{
51503 + char *res = buf + buflen;
51504 + int error;
51505 +
51506 + prepend(&res, &buflen, "\0", 1);
51507 + error = prepend_path(path, root, &res, &buflen);
51508 + if (error)
51509 + return ERR_PTR(error);
51510 +
51511 + return res;
51512 +}
51513 +
51514 +static char *
51515 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51516 +{
51517 + char *retval;
51518 +
51519 + retval = __our_d_path(path, root, buf, buflen);
51520 + if (unlikely(IS_ERR(retval)))
51521 + retval = strcpy(buf, "<path too long>");
51522 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51523 + retval[1] = '\0';
51524 +
51525 + return retval;
51526 +}
51527 +
51528 +static char *
51529 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51530 + char *buf, int buflen)
51531 +{
51532 + struct path path;
51533 + char *res;
51534 +
51535 + path.dentry = (struct dentry *)dentry;
51536 + path.mnt = (struct vfsmount *)vfsmnt;
51537 +
51538 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51539 + by the RBAC system */
51540 + res = gen_full_path(&path, &real_root, buf, buflen);
51541 +
51542 + return res;
51543 +}
51544 +
51545 +static char *
51546 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51547 + char *buf, int buflen)
51548 +{
51549 + char *res;
51550 + struct path path;
51551 + struct path root;
51552 + struct task_struct *reaper = init_pid_ns.child_reaper;
51553 +
51554 + path.dentry = (struct dentry *)dentry;
51555 + path.mnt = (struct vfsmount *)vfsmnt;
51556 +
51557 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51558 + get_fs_root(reaper->fs, &root);
51559 +
51560 + write_seqlock(&rename_lock);
51561 + br_read_lock(&vfsmount_lock);
51562 + res = gen_full_path(&path, &root, buf, buflen);
51563 + br_read_unlock(&vfsmount_lock);
51564 + write_sequnlock(&rename_lock);
51565 +
51566 + path_put(&root);
51567 + return res;
51568 +}
51569 +
51570 +static char *
51571 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51572 +{
51573 + char *ret;
51574 + write_seqlock(&rename_lock);
51575 + br_read_lock(&vfsmount_lock);
51576 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51577 + PAGE_SIZE);
51578 + br_read_unlock(&vfsmount_lock);
51579 + write_sequnlock(&rename_lock);
51580 + return ret;
51581 +}
51582 +
51583 +static char *
51584 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51585 +{
51586 + char *ret;
51587 + char *buf;
51588 + int buflen;
51589 +
51590 + write_seqlock(&rename_lock);
51591 + br_read_lock(&vfsmount_lock);
51592 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51593 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51594 + buflen = (int)(ret - buf);
51595 + if (buflen >= 5)
51596 + prepend(&ret, &buflen, "/proc", 5);
51597 + else
51598 + ret = strcpy(buf, "<path too long>");
51599 + br_read_unlock(&vfsmount_lock);
51600 + write_sequnlock(&rename_lock);
51601 + return ret;
51602 +}
51603 +
51604 +char *
51605 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51606 +{
51607 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51608 + PAGE_SIZE);
51609 +}
51610 +
51611 +char *
51612 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51613 +{
51614 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51615 + PAGE_SIZE);
51616 +}
51617 +
51618 +char *
51619 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51620 +{
51621 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51622 + PAGE_SIZE);
51623 +}
51624 +
51625 +char *
51626 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51627 +{
51628 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51629 + PAGE_SIZE);
51630 +}
51631 +
51632 +char *
51633 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51634 +{
51635 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51636 + PAGE_SIZE);
51637 +}
51638 +
51639 +__inline__ __u32
51640 +to_gr_audit(const __u32 reqmode)
51641 +{
51642 + /* masks off auditable permission flags, then shifts them to create
51643 + auditing flags, and adds the special case of append auditing if
51644 + we're requesting write */
51645 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51646 +}
51647 +
51648 +struct acl_subject_label *
51649 +lookup_subject_map(const struct acl_subject_label *userp)
51650 +{
51651 + unsigned int index = shash(userp, subj_map_set.s_size);
51652 + struct subject_map *match;
51653 +
51654 + match = subj_map_set.s_hash[index];
51655 +
51656 + while (match && match->user != userp)
51657 + match = match->next;
51658 +
51659 + if (match != NULL)
51660 + return match->kernel;
51661 + else
51662 + return NULL;
51663 +}
51664 +
51665 +static void
51666 +insert_subj_map_entry(struct subject_map *subjmap)
51667 +{
51668 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51669 + struct subject_map **curr;
51670 +
51671 + subjmap->prev = NULL;
51672 +
51673 + curr = &subj_map_set.s_hash[index];
51674 + if (*curr != NULL)
51675 + (*curr)->prev = subjmap;
51676 +
51677 + subjmap->next = *curr;
51678 + *curr = subjmap;
51679 +
51680 + return;
51681 +}
51682 +
51683 +static struct acl_role_label *
51684 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51685 + const gid_t gid)
51686 +{
51687 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51688 + struct acl_role_label *match;
51689 + struct role_allowed_ip *ipp;
51690 + unsigned int x;
51691 + u32 curr_ip = task->signal->curr_ip;
51692 +
51693 + task->signal->saved_ip = curr_ip;
51694 +
51695 + match = acl_role_set.r_hash[index];
51696 +
51697 + while (match) {
51698 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51699 + for (x = 0; x < match->domain_child_num; x++) {
51700 + if (match->domain_children[x] == uid)
51701 + goto found;
51702 + }
51703 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51704 + break;
51705 + match = match->next;
51706 + }
51707 +found:
51708 + if (match == NULL) {
51709 + try_group:
51710 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51711 + match = acl_role_set.r_hash[index];
51712 +
51713 + while (match) {
51714 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51715 + for (x = 0; x < match->domain_child_num; x++) {
51716 + if (match->domain_children[x] == gid)
51717 + goto found2;
51718 + }
51719 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51720 + break;
51721 + match = match->next;
51722 + }
51723 +found2:
51724 + if (match == NULL)
51725 + match = default_role;
51726 + if (match->allowed_ips == NULL)
51727 + return match;
51728 + else {
51729 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51730 + if (likely
51731 + ((ntohl(curr_ip) & ipp->netmask) ==
51732 + (ntohl(ipp->addr) & ipp->netmask)))
51733 + return match;
51734 + }
51735 + match = default_role;
51736 + }
51737 + } else if (match->allowed_ips == NULL) {
51738 + return match;
51739 + } else {
51740 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51741 + if (likely
51742 + ((ntohl(curr_ip) & ipp->netmask) ==
51743 + (ntohl(ipp->addr) & ipp->netmask)))
51744 + return match;
51745 + }
51746 + goto try_group;
51747 + }
51748 +
51749 + return match;
51750 +}
51751 +
51752 +struct acl_subject_label *
51753 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51754 + const struct acl_role_label *role)
51755 +{
51756 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51757 + struct acl_subject_label *match;
51758 +
51759 + match = role->subj_hash[index];
51760 +
51761 + while (match && (match->inode != ino || match->device != dev ||
51762 + (match->mode & GR_DELETED))) {
51763 + match = match->next;
51764 + }
51765 +
51766 + if (match && !(match->mode & GR_DELETED))
51767 + return match;
51768 + else
51769 + return NULL;
51770 +}
51771 +
51772 +struct acl_subject_label *
51773 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51774 + const struct acl_role_label *role)
51775 +{
51776 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51777 + struct acl_subject_label *match;
51778 +
51779 + match = role->subj_hash[index];
51780 +
51781 + while (match && (match->inode != ino || match->device != dev ||
51782 + !(match->mode & GR_DELETED))) {
51783 + match = match->next;
51784 + }
51785 +
51786 + if (match && (match->mode & GR_DELETED))
51787 + return match;
51788 + else
51789 + return NULL;
51790 +}
51791 +
51792 +static struct acl_object_label *
51793 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51794 + const struct acl_subject_label *subj)
51795 +{
51796 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51797 + struct acl_object_label *match;
51798 +
51799 + match = subj->obj_hash[index];
51800 +
51801 + while (match && (match->inode != ino || match->device != dev ||
51802 + (match->mode & GR_DELETED))) {
51803 + match = match->next;
51804 + }
51805 +
51806 + if (match && !(match->mode & GR_DELETED))
51807 + return match;
51808 + else
51809 + return NULL;
51810 +}
51811 +
51812 +static struct acl_object_label *
51813 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51814 + const struct acl_subject_label *subj)
51815 +{
51816 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51817 + struct acl_object_label *match;
51818 +
51819 + match = subj->obj_hash[index];
51820 +
51821 + while (match && (match->inode != ino || match->device != dev ||
51822 + !(match->mode & GR_DELETED))) {
51823 + match = match->next;
51824 + }
51825 +
51826 + if (match && (match->mode & GR_DELETED))
51827 + return match;
51828 +
51829 + match = subj->obj_hash[index];
51830 +
51831 + while (match && (match->inode != ino || match->device != dev ||
51832 + (match->mode & GR_DELETED))) {
51833 + match = match->next;
51834 + }
51835 +
51836 + if (match && !(match->mode & GR_DELETED))
51837 + return match;
51838 + else
51839 + return NULL;
51840 +}
51841 +
51842 +static struct name_entry *
51843 +lookup_name_entry(const char *name)
51844 +{
51845 + unsigned int len = strlen(name);
51846 + unsigned int key = full_name_hash(name, len);
51847 + unsigned int index = key % name_set.n_size;
51848 + struct name_entry *match;
51849 +
51850 + match = name_set.n_hash[index];
51851 +
51852 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51853 + match = match->next;
51854 +
51855 + return match;
51856 +}
51857 +
51858 +static struct name_entry *
51859 +lookup_name_entry_create(const char *name)
51860 +{
51861 + unsigned int len = strlen(name);
51862 + unsigned int key = full_name_hash(name, len);
51863 + unsigned int index = key % name_set.n_size;
51864 + struct name_entry *match;
51865 +
51866 + match = name_set.n_hash[index];
51867 +
51868 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51869 + !match->deleted))
51870 + match = match->next;
51871 +
51872 + if (match && match->deleted)
51873 + return match;
51874 +
51875 + match = name_set.n_hash[index];
51876 +
51877 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51878 + match->deleted))
51879 + match = match->next;
51880 +
51881 + if (match && !match->deleted)
51882 + return match;
51883 + else
51884 + return NULL;
51885 +}
51886 +
51887 +static struct inodev_entry *
51888 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51889 +{
51890 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51891 + struct inodev_entry *match;
51892 +
51893 + match = inodev_set.i_hash[index];
51894 +
51895 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51896 + match = match->next;
51897 +
51898 + return match;
51899 +}
51900 +
51901 +static void
51902 +insert_inodev_entry(struct inodev_entry *entry)
51903 +{
51904 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51905 + inodev_set.i_size);
51906 + struct inodev_entry **curr;
51907 +
51908 + entry->prev = NULL;
51909 +
51910 + curr = &inodev_set.i_hash[index];
51911 + if (*curr != NULL)
51912 + (*curr)->prev = entry;
51913 +
51914 + entry->next = *curr;
51915 + *curr = entry;
51916 +
51917 + return;
51918 +}
51919 +
51920 +static void
51921 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51922 +{
51923 + unsigned int index =
51924 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51925 + struct acl_role_label **curr;
51926 + struct acl_role_label *tmp, *tmp2;
51927 +
51928 + curr = &acl_role_set.r_hash[index];
51929 +
51930 + /* simple case, slot is empty, just set it to our role */
51931 + if (*curr == NULL) {
51932 + *curr = role;
51933 + } else {
51934 + /* example:
51935 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51936 + 2 -> 3
51937 + */
51938 + /* first check to see if we can already be reached via this slot */
51939 + tmp = *curr;
51940 + while (tmp && tmp != role)
51941 + tmp = tmp->next;
51942 + if (tmp == role) {
51943 + /* we don't need to add ourselves to this slot's chain */
51944 + return;
51945 + }
51946 + /* we need to add ourselves to this chain, two cases */
51947 + if (role->next == NULL) {
51948 + /* simple case, append the current chain to our role */
51949 + role->next = *curr;
51950 + *curr = role;
51951 + } else {
51952 + /* 1 -> 2 -> 3 -> 4
51953 + 2 -> 3 -> 4
51954 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51955 + */
51956 + /* trickier case: walk our role's chain until we find
51957 + the role for the start of the current slot's chain */
51958 + tmp = role;
51959 + tmp2 = *curr;
51960 + while (tmp->next && tmp->next != tmp2)
51961 + tmp = tmp->next;
51962 + if (tmp->next == tmp2) {
51963 + /* from example above, we found 3, so just
51964 + replace this slot's chain with ours */
51965 + *curr = role;
51966 + } else {
51967 + /* we didn't find a subset of our role's chain
51968 + in the current slot's chain, so append their
51969 + chain to ours, and set us as the first role in
51970 + the slot's chain
51971 +
51972 + we could fold this case with the case above,
51973 + but making it explicit for clarity
51974 + */
51975 + tmp->next = tmp2;
51976 + *curr = role;
51977 + }
51978 + }
51979 + }
51980 +
51981 + return;
51982 +}
51983 +
51984 +static void
51985 +insert_acl_role_label(struct acl_role_label *role)
51986 +{
51987 + int i;
51988 +
51989 + if (role_list == NULL) {
51990 + role_list = role;
51991 + role->prev = NULL;
51992 + } else {
51993 + role->prev = role_list;
51994 + role_list = role;
51995 + }
51996 +
51997 + /* used for hash chains */
51998 + role->next = NULL;
51999 +
52000 + if (role->roletype & GR_ROLE_DOMAIN) {
52001 + for (i = 0; i < role->domain_child_num; i++)
52002 + __insert_acl_role_label(role, role->domain_children[i]);
52003 + } else
52004 + __insert_acl_role_label(role, role->uidgid);
52005 +}
52006 +
52007 +static int
52008 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52009 +{
52010 + struct name_entry **curr, *nentry;
52011 + struct inodev_entry *ientry;
52012 + unsigned int len = strlen(name);
52013 + unsigned int key = full_name_hash(name, len);
52014 + unsigned int index = key % name_set.n_size;
52015 +
52016 + curr = &name_set.n_hash[index];
52017 +
52018 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52019 + curr = &((*curr)->next);
52020 +
52021 + if (*curr != NULL)
52022 + return 1;
52023 +
52024 + nentry = acl_alloc(sizeof (struct name_entry));
52025 + if (nentry == NULL)
52026 + return 0;
52027 + ientry = acl_alloc(sizeof (struct inodev_entry));
52028 + if (ientry == NULL)
52029 + return 0;
52030 + ientry->nentry = nentry;
52031 +
52032 + nentry->key = key;
52033 + nentry->name = name;
52034 + nentry->inode = inode;
52035 + nentry->device = device;
52036 + nentry->len = len;
52037 + nentry->deleted = deleted;
52038 +
52039 + nentry->prev = NULL;
52040 + curr = &name_set.n_hash[index];
52041 + if (*curr != NULL)
52042 + (*curr)->prev = nentry;
52043 + nentry->next = *curr;
52044 + *curr = nentry;
52045 +
52046 + /* insert us into the table searchable by inode/dev */
52047 + insert_inodev_entry(ientry);
52048 +
52049 + return 1;
52050 +}
52051 +
52052 +static void
52053 +insert_acl_obj_label(struct acl_object_label *obj,
52054 + struct acl_subject_label *subj)
52055 +{
52056 + unsigned int index =
52057 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52058 + struct acl_object_label **curr;
52059 +
52060 +
52061 + obj->prev = NULL;
52062 +
52063 + curr = &subj->obj_hash[index];
52064 + if (*curr != NULL)
52065 + (*curr)->prev = obj;
52066 +
52067 + obj->next = *curr;
52068 + *curr = obj;
52069 +
52070 + return;
52071 +}
52072 +
52073 +static void
52074 +insert_acl_subj_label(struct acl_subject_label *obj,
52075 + struct acl_role_label *role)
52076 +{
52077 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52078 + struct acl_subject_label **curr;
52079 +
52080 + obj->prev = NULL;
52081 +
52082 + curr = &role->subj_hash[index];
52083 + if (*curr != NULL)
52084 + (*curr)->prev = obj;
52085 +
52086 + obj->next = *curr;
52087 + *curr = obj;
52088 +
52089 + return;
52090 +}
52091 +
52092 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52093 +
52094 +static void *
52095 +create_table(__u32 * len, int elementsize)
52096 +{
52097 + unsigned int table_sizes[] = {
52098 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52099 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52100 + 4194301, 8388593, 16777213, 33554393, 67108859
52101 + };
52102 + void *newtable = NULL;
52103 + unsigned int pwr = 0;
52104 +
52105 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52106 + table_sizes[pwr] <= *len)
52107 + pwr++;
52108 +
52109 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52110 + return newtable;
52111 +
52112 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52113 + newtable =
52114 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52115 + else
52116 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52117 +
52118 + *len = table_sizes[pwr];
52119 +
52120 + return newtable;
52121 +}
52122 +
52123 +static int
52124 +init_variables(const struct gr_arg *arg)
52125 +{
52126 + struct task_struct *reaper = init_pid_ns.child_reaper;
52127 + unsigned int stacksize;
52128 +
52129 + subj_map_set.s_size = arg->role_db.num_subjects;
52130 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52131 + name_set.n_size = arg->role_db.num_objects;
52132 + inodev_set.i_size = arg->role_db.num_objects;
52133 +
52134 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52135 + !name_set.n_size || !inodev_set.i_size)
52136 + return 1;
52137 +
52138 + if (!gr_init_uidset())
52139 + return 1;
52140 +
52141 + /* set up the stack that holds allocation info */
52142 +
52143 + stacksize = arg->role_db.num_pointers + 5;
52144 +
52145 + if (!acl_alloc_stack_init(stacksize))
52146 + return 1;
52147 +
52148 + /* grab reference for the real root dentry and vfsmount */
52149 + get_fs_root(reaper->fs, &real_root);
52150 +
52151 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52152 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52153 +#endif
52154 +
52155 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52156 + if (fakefs_obj_rw == NULL)
52157 + return 1;
52158 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52159 +
52160 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52161 + if (fakefs_obj_rwx == NULL)
52162 + return 1;
52163 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52164 +
52165 + subj_map_set.s_hash =
52166 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52167 + acl_role_set.r_hash =
52168 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52169 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52170 + inodev_set.i_hash =
52171 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52172 +
52173 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52174 + !name_set.n_hash || !inodev_set.i_hash)
52175 + return 1;
52176 +
52177 + memset(subj_map_set.s_hash, 0,
52178 + sizeof(struct subject_map *) * subj_map_set.s_size);
52179 + memset(acl_role_set.r_hash, 0,
52180 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52181 + memset(name_set.n_hash, 0,
52182 + sizeof (struct name_entry *) * name_set.n_size);
52183 + memset(inodev_set.i_hash, 0,
52184 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52185 +
52186 + return 0;
52187 +}
52188 +
52189 +/* free information not needed after startup
52190 + currently contains user->kernel pointer mappings for subjects
52191 +*/
52192 +
52193 +static void
52194 +free_init_variables(void)
52195 +{
52196 + __u32 i;
52197 +
52198 + if (subj_map_set.s_hash) {
52199 + for (i = 0; i < subj_map_set.s_size; i++) {
52200 + if (subj_map_set.s_hash[i]) {
52201 + kfree(subj_map_set.s_hash[i]);
52202 + subj_map_set.s_hash[i] = NULL;
52203 + }
52204 + }
52205 +
52206 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52207 + PAGE_SIZE)
52208 + kfree(subj_map_set.s_hash);
52209 + else
52210 + vfree(subj_map_set.s_hash);
52211 + }
52212 +
52213 + return;
52214 +}
52215 +
52216 +static void
52217 +free_variables(void)
52218 +{
52219 + struct acl_subject_label *s;
52220 + struct acl_role_label *r;
52221 + struct task_struct *task, *task2;
52222 + unsigned int x;
52223 +
52224 + gr_clear_learn_entries();
52225 +
52226 + read_lock(&tasklist_lock);
52227 + do_each_thread(task2, task) {
52228 + task->acl_sp_role = 0;
52229 + task->acl_role_id = 0;
52230 + task->acl = NULL;
52231 + task->role = NULL;
52232 + } while_each_thread(task2, task);
52233 + read_unlock(&tasklist_lock);
52234 +
52235 + /* release the reference to the real root dentry and vfsmount */
52236 + path_put(&real_root);
52237 + memset(&real_root, 0, sizeof(real_root));
52238 +
52239 + /* free all object hash tables */
52240 +
52241 + FOR_EACH_ROLE_START(r)
52242 + if (r->subj_hash == NULL)
52243 + goto next_role;
52244 + FOR_EACH_SUBJECT_START(r, s, x)
52245 + if (s->obj_hash == NULL)
52246 + break;
52247 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52248 + kfree(s->obj_hash);
52249 + else
52250 + vfree(s->obj_hash);
52251 + FOR_EACH_SUBJECT_END(s, x)
52252 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52253 + if (s->obj_hash == NULL)
52254 + break;
52255 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52256 + kfree(s->obj_hash);
52257 + else
52258 + vfree(s->obj_hash);
52259 + FOR_EACH_NESTED_SUBJECT_END(s)
52260 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52261 + kfree(r->subj_hash);
52262 + else
52263 + vfree(r->subj_hash);
52264 + r->subj_hash = NULL;
52265 +next_role:
52266 + FOR_EACH_ROLE_END(r)
52267 +
52268 + acl_free_all();
52269 +
52270 + if (acl_role_set.r_hash) {
52271 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52272 + PAGE_SIZE)
52273 + kfree(acl_role_set.r_hash);
52274 + else
52275 + vfree(acl_role_set.r_hash);
52276 + }
52277 + if (name_set.n_hash) {
52278 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52279 + PAGE_SIZE)
52280 + kfree(name_set.n_hash);
52281 + else
52282 + vfree(name_set.n_hash);
52283 + }
52284 +
52285 + if (inodev_set.i_hash) {
52286 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52287 + PAGE_SIZE)
52288 + kfree(inodev_set.i_hash);
52289 + else
52290 + vfree(inodev_set.i_hash);
52291 + }
52292 +
52293 + gr_free_uidset();
52294 +
52295 + memset(&name_set, 0, sizeof (struct name_db));
52296 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52297 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52298 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52299 +
52300 + default_role = NULL;
52301 + kernel_role = NULL;
52302 + role_list = NULL;
52303 +
52304 + return;
52305 +}
52306 +
52307 +static __u32
52308 +count_user_objs(struct acl_object_label *userp)
52309 +{
52310 + struct acl_object_label o_tmp;
52311 + __u32 num = 0;
52312 +
52313 + while (userp) {
52314 + if (copy_from_user(&o_tmp, userp,
52315 + sizeof (struct acl_object_label)))
52316 + break;
52317 +
52318 + userp = o_tmp.prev;
52319 + num++;
52320 + }
52321 +
52322 + return num;
52323 +}
52324 +
52325 +static struct acl_subject_label *
52326 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52327 +
52328 +static int
52329 +copy_user_glob(struct acl_object_label *obj)
52330 +{
52331 + struct acl_object_label *g_tmp, **guser;
52332 + unsigned int len;
52333 + char *tmp;
52334 +
52335 + if (obj->globbed == NULL)
52336 + return 0;
52337 +
52338 + guser = &obj->globbed;
52339 + while (*guser) {
52340 + g_tmp = (struct acl_object_label *)
52341 + acl_alloc(sizeof (struct acl_object_label));
52342 + if (g_tmp == NULL)
52343 + return -ENOMEM;
52344 +
52345 + if (copy_from_user(g_tmp, *guser,
52346 + sizeof (struct acl_object_label)))
52347 + return -EFAULT;
52348 +
52349 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52350 +
52351 + if (!len || len >= PATH_MAX)
52352 + return -EINVAL;
52353 +
52354 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52355 + return -ENOMEM;
52356 +
52357 + if (copy_from_user(tmp, g_tmp->filename, len))
52358 + return -EFAULT;
52359 + tmp[len-1] = '\0';
52360 + g_tmp->filename = tmp;
52361 +
52362 + *guser = g_tmp;
52363 + guser = &(g_tmp->next);
52364 + }
52365 +
52366 + return 0;
52367 +}
52368 +
52369 +static int
52370 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52371 + struct acl_role_label *role)
52372 +{
52373 + struct acl_object_label *o_tmp;
52374 + unsigned int len;
52375 + int ret;
52376 + char *tmp;
52377 +
52378 + while (userp) {
52379 + if ((o_tmp = (struct acl_object_label *)
52380 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52381 + return -ENOMEM;
52382 +
52383 + if (copy_from_user(o_tmp, userp,
52384 + sizeof (struct acl_object_label)))
52385 + return -EFAULT;
52386 +
52387 + userp = o_tmp->prev;
52388 +
52389 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52390 +
52391 + if (!len || len >= PATH_MAX)
52392 + return -EINVAL;
52393 +
52394 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52395 + return -ENOMEM;
52396 +
52397 + if (copy_from_user(tmp, o_tmp->filename, len))
52398 + return -EFAULT;
52399 + tmp[len-1] = '\0';
52400 + o_tmp->filename = tmp;
52401 +
52402 + insert_acl_obj_label(o_tmp, subj);
52403 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52404 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52405 + return -ENOMEM;
52406 +
52407 + ret = copy_user_glob(o_tmp);
52408 + if (ret)
52409 + return ret;
52410 +
52411 + if (o_tmp->nested) {
52412 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52413 + if (IS_ERR(o_tmp->nested))
52414 + return PTR_ERR(o_tmp->nested);
52415 +
52416 + /* insert into nested subject list */
52417 + o_tmp->nested->next = role->hash->first;
52418 + role->hash->first = o_tmp->nested;
52419 + }
52420 + }
52421 +
52422 + return 0;
52423 +}
52424 +
52425 +static __u32
52426 +count_user_subjs(struct acl_subject_label *userp)
52427 +{
52428 + struct acl_subject_label s_tmp;
52429 + __u32 num = 0;
52430 +
52431 + while (userp) {
52432 + if (copy_from_user(&s_tmp, userp,
52433 + sizeof (struct acl_subject_label)))
52434 + break;
52435 +
52436 + userp = s_tmp.prev;
52437 + /* do not count nested subjects against this count, since
52438 + they are not included in the hash table, but are
52439 + attached to objects. We have already counted
52440 + the subjects in userspace for the allocation
52441 + stack
52442 + */
52443 + if (!(s_tmp.mode & GR_NESTED))
52444 + num++;
52445 + }
52446 +
52447 + return num;
52448 +}
52449 +
52450 +static int
52451 +copy_user_allowedips(struct acl_role_label *rolep)
52452 +{
52453 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52454 +
52455 + ruserip = rolep->allowed_ips;
52456 +
52457 + while (ruserip) {
52458 + rlast = rtmp;
52459 +
52460 + if ((rtmp = (struct role_allowed_ip *)
52461 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52462 + return -ENOMEM;
52463 +
52464 + if (copy_from_user(rtmp, ruserip,
52465 + sizeof (struct role_allowed_ip)))
52466 + return -EFAULT;
52467 +
52468 + ruserip = rtmp->prev;
52469 +
52470 + if (!rlast) {
52471 + rtmp->prev = NULL;
52472 + rolep->allowed_ips = rtmp;
52473 + } else {
52474 + rlast->next = rtmp;
52475 + rtmp->prev = rlast;
52476 + }
52477 +
52478 + if (!ruserip)
52479 + rtmp->next = NULL;
52480 + }
52481 +
52482 + return 0;
52483 +}
52484 +
52485 +static int
52486 +copy_user_transitions(struct acl_role_label *rolep)
52487 +{
52488 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52489 +
52490 + unsigned int len;
52491 + char *tmp;
52492 +
52493 + rusertp = rolep->transitions;
52494 +
52495 + while (rusertp) {
52496 + rlast = rtmp;
52497 +
52498 + if ((rtmp = (struct role_transition *)
52499 + acl_alloc(sizeof (struct role_transition))) == NULL)
52500 + return -ENOMEM;
52501 +
52502 + if (copy_from_user(rtmp, rusertp,
52503 + sizeof (struct role_transition)))
52504 + return -EFAULT;
52505 +
52506 + rusertp = rtmp->prev;
52507 +
52508 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52509 +
52510 + if (!len || len >= GR_SPROLE_LEN)
52511 + return -EINVAL;
52512 +
52513 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52514 + return -ENOMEM;
52515 +
52516 + if (copy_from_user(tmp, rtmp->rolename, len))
52517 + return -EFAULT;
52518 + tmp[len-1] = '\0';
52519 + rtmp->rolename = tmp;
52520 +
52521 + if (!rlast) {
52522 + rtmp->prev = NULL;
52523 + rolep->transitions = rtmp;
52524 + } else {
52525 + rlast->next = rtmp;
52526 + rtmp->prev = rlast;
52527 + }
52528 +
52529 + if (!rusertp)
52530 + rtmp->next = NULL;
52531 + }
52532 +
52533 + return 0;
52534 +}
52535 +
52536 +static struct acl_subject_label *
52537 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52538 +{
52539 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52540 + unsigned int len;
52541 + char *tmp;
52542 + __u32 num_objs;
52543 + struct acl_ip_label **i_tmp, *i_utmp2;
52544 + struct gr_hash_struct ghash;
52545 + struct subject_map *subjmap;
52546 + unsigned int i_num;
52547 + int err;
52548 +
52549 + s_tmp = lookup_subject_map(userp);
52550 +
52551 + /* we've already copied this subject into the kernel, just return
52552 + the reference to it, and don't copy it over again
52553 + */
52554 + if (s_tmp)
52555 + return(s_tmp);
52556 +
52557 + if ((s_tmp = (struct acl_subject_label *)
52558 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52559 + return ERR_PTR(-ENOMEM);
52560 +
52561 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52562 + if (subjmap == NULL)
52563 + return ERR_PTR(-ENOMEM);
52564 +
52565 + subjmap->user = userp;
52566 + subjmap->kernel = s_tmp;
52567 + insert_subj_map_entry(subjmap);
52568 +
52569 + if (copy_from_user(s_tmp, userp,
52570 + sizeof (struct acl_subject_label)))
52571 + return ERR_PTR(-EFAULT);
52572 +
52573 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52574 +
52575 + if (!len || len >= PATH_MAX)
52576 + return ERR_PTR(-EINVAL);
52577 +
52578 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52579 + return ERR_PTR(-ENOMEM);
52580 +
52581 + if (copy_from_user(tmp, s_tmp->filename, len))
52582 + return ERR_PTR(-EFAULT);
52583 + tmp[len-1] = '\0';
52584 + s_tmp->filename = tmp;
52585 +
52586 + if (!strcmp(s_tmp->filename, "/"))
52587 + role->root_label = s_tmp;
52588 +
52589 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52590 + return ERR_PTR(-EFAULT);
52591 +
52592 + /* copy user and group transition tables */
52593 +
52594 + if (s_tmp->user_trans_num) {
52595 + uid_t *uidlist;
52596 +
52597 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52598 + if (uidlist == NULL)
52599 + return ERR_PTR(-ENOMEM);
52600 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52601 + return ERR_PTR(-EFAULT);
52602 +
52603 + s_tmp->user_transitions = uidlist;
52604 + }
52605 +
52606 + if (s_tmp->group_trans_num) {
52607 + gid_t *gidlist;
52608 +
52609 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52610 + if (gidlist == NULL)
52611 + return ERR_PTR(-ENOMEM);
52612 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52613 + return ERR_PTR(-EFAULT);
52614 +
52615 + s_tmp->group_transitions = gidlist;
52616 + }
52617 +
52618 + /* set up object hash table */
52619 + num_objs = count_user_objs(ghash.first);
52620 +
52621 + s_tmp->obj_hash_size = num_objs;
52622 + s_tmp->obj_hash =
52623 + (struct acl_object_label **)
52624 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52625 +
52626 + if (!s_tmp->obj_hash)
52627 + return ERR_PTR(-ENOMEM);
52628 +
52629 + memset(s_tmp->obj_hash, 0,
52630 + s_tmp->obj_hash_size *
52631 + sizeof (struct acl_object_label *));
52632 +
52633 + /* add in objects */
52634 + err = copy_user_objs(ghash.first, s_tmp, role);
52635 +
52636 + if (err)
52637 + return ERR_PTR(err);
52638 +
52639 + /* set pointer for parent subject */
52640 + if (s_tmp->parent_subject) {
52641 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52642 +
52643 + if (IS_ERR(s_tmp2))
52644 + return s_tmp2;
52645 +
52646 + s_tmp->parent_subject = s_tmp2;
52647 + }
52648 +
52649 + /* add in ip acls */
52650 +
52651 + if (!s_tmp->ip_num) {
52652 + s_tmp->ips = NULL;
52653 + goto insert;
52654 + }
52655 +
52656 + i_tmp =
52657 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52658 + sizeof (struct acl_ip_label *));
52659 +
52660 + if (!i_tmp)
52661 + return ERR_PTR(-ENOMEM);
52662 +
52663 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52664 + *(i_tmp + i_num) =
52665 + (struct acl_ip_label *)
52666 + acl_alloc(sizeof (struct acl_ip_label));
52667 + if (!*(i_tmp + i_num))
52668 + return ERR_PTR(-ENOMEM);
52669 +
52670 + if (copy_from_user
52671 + (&i_utmp2, s_tmp->ips + i_num,
52672 + sizeof (struct acl_ip_label *)))
52673 + return ERR_PTR(-EFAULT);
52674 +
52675 + if (copy_from_user
52676 + (*(i_tmp + i_num), i_utmp2,
52677 + sizeof (struct acl_ip_label)))
52678 + return ERR_PTR(-EFAULT);
52679 +
52680 + if ((*(i_tmp + i_num))->iface == NULL)
52681 + continue;
52682 +
52683 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52684 + if (!len || len >= IFNAMSIZ)
52685 + return ERR_PTR(-EINVAL);
52686 + tmp = acl_alloc(len);
52687 + if (tmp == NULL)
52688 + return ERR_PTR(-ENOMEM);
52689 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52690 + return ERR_PTR(-EFAULT);
52691 + (*(i_tmp + i_num))->iface = tmp;
52692 + }
52693 +
52694 + s_tmp->ips = i_tmp;
52695 +
52696 +insert:
52697 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52698 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52699 + return ERR_PTR(-ENOMEM);
52700 +
52701 + return s_tmp;
52702 +}
52703 +
52704 +static int
52705 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52706 +{
52707 + struct acl_subject_label s_pre;
52708 + struct acl_subject_label * ret;
52709 + int err;
52710 +
52711 + while (userp) {
52712 + if (copy_from_user(&s_pre, userp,
52713 + sizeof (struct acl_subject_label)))
52714 + return -EFAULT;
52715 +
52716 + /* do not add nested subjects here, add
52717 + while parsing objects
52718 + */
52719 +
52720 + if (s_pre.mode & GR_NESTED) {
52721 + userp = s_pre.prev;
52722 + continue;
52723 + }
52724 +
52725 + ret = do_copy_user_subj(userp, role);
52726 +
52727 + err = PTR_ERR(ret);
52728 + if (IS_ERR(ret))
52729 + return err;
52730 +
52731 + insert_acl_subj_label(ret, role);
52732 +
52733 + userp = s_pre.prev;
52734 + }
52735 +
52736 + return 0;
52737 +}
52738 +
52739 +static int
52740 +copy_user_acl(struct gr_arg *arg)
52741 +{
52742 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52743 + struct sprole_pw *sptmp;
52744 + struct gr_hash_struct *ghash;
52745 + uid_t *domainlist;
52746 + unsigned int r_num;
52747 + unsigned int len;
52748 + char *tmp;
52749 + int err = 0;
52750 + __u16 i;
52751 + __u32 num_subjs;
52752 +
52753 + /* we need a default and kernel role */
52754 + if (arg->role_db.num_roles < 2)
52755 + return -EINVAL;
52756 +
52757 + /* copy special role authentication info from userspace */
52758 +
52759 + num_sprole_pws = arg->num_sprole_pws;
52760 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52761 +
52762 + if (!acl_special_roles && num_sprole_pws)
52763 + return -ENOMEM;
52764 +
52765 + for (i = 0; i < num_sprole_pws; i++) {
52766 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52767 + if (!sptmp)
52768 + return -ENOMEM;
52769 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52770 + sizeof (struct sprole_pw)))
52771 + return -EFAULT;
52772 +
52773 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52774 +
52775 + if (!len || len >= GR_SPROLE_LEN)
52776 + return -EINVAL;
52777 +
52778 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52779 + return -ENOMEM;
52780 +
52781 + if (copy_from_user(tmp, sptmp->rolename, len))
52782 + return -EFAULT;
52783 +
52784 + tmp[len-1] = '\0';
52785 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52786 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52787 +#endif
52788 + sptmp->rolename = tmp;
52789 + acl_special_roles[i] = sptmp;
52790 + }
52791 +
52792 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52793 +
52794 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52795 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52796 +
52797 + if (!r_tmp)
52798 + return -ENOMEM;
52799 +
52800 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52801 + sizeof (struct acl_role_label *)))
52802 + return -EFAULT;
52803 +
52804 + if (copy_from_user(r_tmp, r_utmp2,
52805 + sizeof (struct acl_role_label)))
52806 + return -EFAULT;
52807 +
52808 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52809 +
52810 + if (!len || len >= PATH_MAX)
52811 + return -EINVAL;
52812 +
52813 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52814 + return -ENOMEM;
52815 +
52816 + if (copy_from_user(tmp, r_tmp->rolename, len))
52817 + return -EFAULT;
52818 +
52819 + tmp[len-1] = '\0';
52820 + r_tmp->rolename = tmp;
52821 +
52822 + if (!strcmp(r_tmp->rolename, "default")
52823 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52824 + default_role = r_tmp;
52825 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52826 + kernel_role = r_tmp;
52827 + }
52828 +
52829 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52830 + return -ENOMEM;
52831 +
52832 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52833 + return -EFAULT;
52834 +
52835 + r_tmp->hash = ghash;
52836 +
52837 + num_subjs = count_user_subjs(r_tmp->hash->first);
52838 +
52839 + r_tmp->subj_hash_size = num_subjs;
52840 + r_tmp->subj_hash =
52841 + (struct acl_subject_label **)
52842 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52843 +
52844 + if (!r_tmp->subj_hash)
52845 + return -ENOMEM;
52846 +
52847 + err = copy_user_allowedips(r_tmp);
52848 + if (err)
52849 + return err;
52850 +
52851 + /* copy domain info */
52852 + if (r_tmp->domain_children != NULL) {
52853 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52854 + if (domainlist == NULL)
52855 + return -ENOMEM;
52856 +
52857 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52858 + return -EFAULT;
52859 +
52860 + r_tmp->domain_children = domainlist;
52861 + }
52862 +
52863 + err = copy_user_transitions(r_tmp);
52864 + if (err)
52865 + return err;
52866 +
52867 + memset(r_tmp->subj_hash, 0,
52868 + r_tmp->subj_hash_size *
52869 + sizeof (struct acl_subject_label *));
52870 +
52871 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52872 +
52873 + if (err)
52874 + return err;
52875 +
52876 + /* set nested subject list to null */
52877 + r_tmp->hash->first = NULL;
52878 +
52879 + insert_acl_role_label(r_tmp);
52880 + }
52881 +
52882 + if (default_role == NULL || kernel_role == NULL)
52883 + return -EINVAL;
52884 +
52885 + return err;
52886 +}
52887 +
52888 +static int
52889 +gracl_init(struct gr_arg *args)
52890 +{
52891 + int error = 0;
52892 +
52893 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52894 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52895 +
52896 + if (init_variables(args)) {
52897 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52898 + error = -ENOMEM;
52899 + free_variables();
52900 + goto out;
52901 + }
52902 +
52903 + error = copy_user_acl(args);
52904 + free_init_variables();
52905 + if (error) {
52906 + free_variables();
52907 + goto out;
52908 + }
52909 +
52910 + if ((error = gr_set_acls(0))) {
52911 + free_variables();
52912 + goto out;
52913 + }
52914 +
52915 + pax_open_kernel();
52916 + gr_status |= GR_READY;
52917 + pax_close_kernel();
52918 +
52919 + out:
52920 + return error;
52921 +}
52922 +
52923 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52924 +
52925 +static int
52926 +glob_match(const char *p, const char *n)
52927 +{
52928 + char c;
52929 +
52930 + while ((c = *p++) != '\0') {
52931 + switch (c) {
52932 + case '?':
52933 + if (*n == '\0')
52934 + return 1;
52935 + else if (*n == '/')
52936 + return 1;
52937 + break;
52938 + case '\\':
52939 + if (*n != c)
52940 + return 1;
52941 + break;
52942 + case '*':
52943 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52944 + if (*n == '/')
52945 + return 1;
52946 + else if (c == '?') {
52947 + if (*n == '\0')
52948 + return 1;
52949 + else
52950 + ++n;
52951 + }
52952 + }
52953 + if (c == '\0') {
52954 + return 0;
52955 + } else {
52956 + const char *endp;
52957 +
52958 + if ((endp = strchr(n, '/')) == NULL)
52959 + endp = n + strlen(n);
52960 +
52961 + if (c == '[') {
52962 + for (--p; n < endp; ++n)
52963 + if (!glob_match(p, n))
52964 + return 0;
52965 + } else if (c == '/') {
52966 + while (*n != '\0' && *n != '/')
52967 + ++n;
52968 + if (*n == '/' && !glob_match(p, n + 1))
52969 + return 0;
52970 + } else {
52971 + for (--p; n < endp; ++n)
52972 + if (*n == c && !glob_match(p, n))
52973 + return 0;
52974 + }
52975 +
52976 + return 1;
52977 + }
52978 + case '[':
52979 + {
52980 + int not;
52981 + char cold;
52982 +
52983 + if (*n == '\0' || *n == '/')
52984 + return 1;
52985 +
52986 + not = (*p == '!' || *p == '^');
52987 + if (not)
52988 + ++p;
52989 +
52990 + c = *p++;
52991 + for (;;) {
52992 + unsigned char fn = (unsigned char)*n;
52993 +
52994 + if (c == '\0')
52995 + return 1;
52996 + else {
52997 + if (c == fn)
52998 + goto matched;
52999 + cold = c;
53000 + c = *p++;
53001 +
53002 + if (c == '-' && *p != ']') {
53003 + unsigned char cend = *p++;
53004 +
53005 + if (cend == '\0')
53006 + return 1;
53007 +
53008 + if (cold <= fn && fn <= cend)
53009 + goto matched;
53010 +
53011 + c = *p++;
53012 + }
53013 + }
53014 +
53015 + if (c == ']')
53016 + break;
53017 + }
53018 + if (!not)
53019 + return 1;
53020 + break;
53021 + matched:
53022 + while (c != ']') {
53023 + if (c == '\0')
53024 + return 1;
53025 +
53026 + c = *p++;
53027 + }
53028 + if (not)
53029 + return 1;
53030 + }
53031 + break;
53032 + default:
53033 + if (c != *n)
53034 + return 1;
53035 + }
53036 +
53037 + ++n;
53038 + }
53039 +
53040 + if (*n == '\0')
53041 + return 0;
53042 +
53043 + if (*n == '/')
53044 + return 0;
53045 +
53046 + return 1;
53047 +}
53048 +
53049 +static struct acl_object_label *
53050 +chk_glob_label(struct acl_object_label *globbed,
53051 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53052 +{
53053 + struct acl_object_label *tmp;
53054 +
53055 + if (*path == NULL)
53056 + *path = gr_to_filename_nolock(dentry, mnt);
53057 +
53058 + tmp = globbed;
53059 +
53060 + while (tmp) {
53061 + if (!glob_match(tmp->filename, *path))
53062 + return tmp;
53063 + tmp = tmp->next;
53064 + }
53065 +
53066 + return NULL;
53067 +}
53068 +
53069 +static struct acl_object_label *
53070 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53071 + const ino_t curr_ino, const dev_t curr_dev,
53072 + const struct acl_subject_label *subj, char **path, const int checkglob)
53073 +{
53074 + struct acl_subject_label *tmpsubj;
53075 + struct acl_object_label *retval;
53076 + struct acl_object_label *retval2;
53077 +
53078 + tmpsubj = (struct acl_subject_label *) subj;
53079 + read_lock(&gr_inode_lock);
53080 + do {
53081 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53082 + if (retval) {
53083 + if (checkglob && retval->globbed) {
53084 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53085 + if (retval2)
53086 + retval = retval2;
53087 + }
53088 + break;
53089 + }
53090 + } while ((tmpsubj = tmpsubj->parent_subject));
53091 + read_unlock(&gr_inode_lock);
53092 +
53093 + return retval;
53094 +}
53095 +
53096 +static __inline__ struct acl_object_label *
53097 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53098 + struct dentry *curr_dentry,
53099 + const struct acl_subject_label *subj, char **path, const int checkglob)
53100 +{
53101 + int newglob = checkglob;
53102 + ino_t inode;
53103 + dev_t device;
53104 +
53105 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53106 + as we don't want a / * rule to match instead of the / object
53107 + don't do this for create lookups that call this function though, since they're looking up
53108 + on the parent and thus need globbing checks on all paths
53109 + */
53110 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53111 + newglob = GR_NO_GLOB;
53112 +
53113 + spin_lock(&curr_dentry->d_lock);
53114 + inode = curr_dentry->d_inode->i_ino;
53115 + device = __get_dev(curr_dentry);
53116 + spin_unlock(&curr_dentry->d_lock);
53117 +
53118 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53119 +}
53120 +
53121 +static struct acl_object_label *
53122 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53123 + const struct acl_subject_label *subj, char *path, const int checkglob)
53124 +{
53125 + struct dentry *dentry = (struct dentry *) l_dentry;
53126 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53127 + struct mount *real_mnt = real_mount(mnt);
53128 + struct acl_object_label *retval;
53129 + struct dentry *parent;
53130 +
53131 + write_seqlock(&rename_lock);
53132 + br_read_lock(&vfsmount_lock);
53133 +
53134 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53135 +#ifdef CONFIG_NET
53136 + mnt == sock_mnt ||
53137 +#endif
53138 +#ifdef CONFIG_HUGETLBFS
53139 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53140 +#endif
53141 + /* ignore Eric Biederman */
53142 + IS_PRIVATE(l_dentry->d_inode))) {
53143 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53144 + goto out;
53145 + }
53146 +
53147 + for (;;) {
53148 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53149 + break;
53150 +
53151 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53152 + if (!mnt_has_parent(real_mnt))
53153 + break;
53154 +
53155 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53156 + if (retval != NULL)
53157 + goto out;
53158 +
53159 + dentry = real_mnt->mnt_mountpoint;
53160 + real_mnt = real_mnt->mnt_parent;
53161 + mnt = &real_mnt->mnt;
53162 + continue;
53163 + }
53164 +
53165 + parent = dentry->d_parent;
53166 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53167 + if (retval != NULL)
53168 + goto out;
53169 +
53170 + dentry = parent;
53171 + }
53172 +
53173 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53174 +
53175 + /* real_root is pinned so we don't have to hold a reference */
53176 + if (retval == NULL)
53177 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53178 +out:
53179 + br_read_unlock(&vfsmount_lock);
53180 + write_sequnlock(&rename_lock);
53181 +
53182 + BUG_ON(retval == NULL);
53183 +
53184 + return retval;
53185 +}
53186 +
53187 +static __inline__ struct acl_object_label *
53188 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53189 + const struct acl_subject_label *subj)
53190 +{
53191 + char *path = NULL;
53192 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53193 +}
53194 +
53195 +static __inline__ struct acl_object_label *
53196 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53197 + const struct acl_subject_label *subj)
53198 +{
53199 + char *path = NULL;
53200 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53201 +}
53202 +
53203 +static __inline__ struct acl_object_label *
53204 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53205 + const struct acl_subject_label *subj, char *path)
53206 +{
53207 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53208 +}
53209 +
53210 +static struct acl_subject_label *
53211 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53212 + const struct acl_role_label *role)
53213 +{
53214 + struct dentry *dentry = (struct dentry *) l_dentry;
53215 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53216 + struct mount *real_mnt = real_mount(mnt);
53217 + struct acl_subject_label *retval;
53218 + struct dentry *parent;
53219 +
53220 + write_seqlock(&rename_lock);
53221 + br_read_lock(&vfsmount_lock);
53222 +
53223 + for (;;) {
53224 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53225 + break;
53226 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53227 + if (!mnt_has_parent(real_mnt))
53228 + break;
53229 +
53230 + spin_lock(&dentry->d_lock);
53231 + read_lock(&gr_inode_lock);
53232 + retval =
53233 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53234 + __get_dev(dentry), role);
53235 + read_unlock(&gr_inode_lock);
53236 + spin_unlock(&dentry->d_lock);
53237 + if (retval != NULL)
53238 + goto out;
53239 +
53240 + dentry = real_mnt->mnt_mountpoint;
53241 + real_mnt = real_mnt->mnt_parent;
53242 + mnt = &real_mnt->mnt;
53243 + continue;
53244 + }
53245 +
53246 + spin_lock(&dentry->d_lock);
53247 + read_lock(&gr_inode_lock);
53248 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53249 + __get_dev(dentry), role);
53250 + read_unlock(&gr_inode_lock);
53251 + parent = dentry->d_parent;
53252 + spin_unlock(&dentry->d_lock);
53253 +
53254 + if (retval != NULL)
53255 + goto out;
53256 +
53257 + dentry = parent;
53258 + }
53259 +
53260 + spin_lock(&dentry->d_lock);
53261 + read_lock(&gr_inode_lock);
53262 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53263 + __get_dev(dentry), role);
53264 + read_unlock(&gr_inode_lock);
53265 + spin_unlock(&dentry->d_lock);
53266 +
53267 + if (unlikely(retval == NULL)) {
53268 + /* real_root is pinned, we don't need to hold a reference */
53269 + read_lock(&gr_inode_lock);
53270 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53271 + __get_dev(real_root.dentry), role);
53272 + read_unlock(&gr_inode_lock);
53273 + }
53274 +out:
53275 + br_read_unlock(&vfsmount_lock);
53276 + write_sequnlock(&rename_lock);
53277 +
53278 + BUG_ON(retval == NULL);
53279 +
53280 + return retval;
53281 +}
53282 +
53283 +static void
53284 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53285 +{
53286 + struct task_struct *task = current;
53287 + const struct cred *cred = current_cred();
53288 +
53289 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53290 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53291 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53292 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53293 +
53294 + return;
53295 +}
53296 +
53297 +static void
53298 +gr_log_learn_id_change(const char type, const unsigned int real,
53299 + const unsigned int effective, const unsigned int fs)
53300 +{
53301 + struct task_struct *task = current;
53302 + const struct cred *cred = current_cred();
53303 +
53304 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53305 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53306 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53307 + type, real, effective, fs, &task->signal->saved_ip);
53308 +
53309 + return;
53310 +}
53311 +
53312 +__u32
53313 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53314 + const struct vfsmount * mnt)
53315 +{
53316 + __u32 retval = mode;
53317 + struct acl_subject_label *curracl;
53318 + struct acl_object_label *currobj;
53319 +
53320 + if (unlikely(!(gr_status & GR_READY)))
53321 + return (mode & ~GR_AUDITS);
53322 +
53323 + curracl = current->acl;
53324 +
53325 + currobj = chk_obj_label(dentry, mnt, curracl);
53326 + retval = currobj->mode & mode;
53327 +
53328 + /* if we're opening a specified transfer file for writing
53329 + (e.g. /dev/initctl), then transfer our role to init
53330 + */
53331 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53332 + current->role->roletype & GR_ROLE_PERSIST)) {
53333 + struct task_struct *task = init_pid_ns.child_reaper;
53334 +
53335 + if (task->role != current->role) {
53336 + task->acl_sp_role = 0;
53337 + task->acl_role_id = current->acl_role_id;
53338 + task->role = current->role;
53339 + rcu_read_lock();
53340 + read_lock(&grsec_exec_file_lock);
53341 + gr_apply_subject_to_task(task);
53342 + read_unlock(&grsec_exec_file_lock);
53343 + rcu_read_unlock();
53344 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53345 + }
53346 + }
53347 +
53348 + if (unlikely
53349 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53350 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53351 + __u32 new_mode = mode;
53352 +
53353 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53354 +
53355 + retval = new_mode;
53356 +
53357 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53358 + new_mode |= GR_INHERIT;
53359 +
53360 + if (!(mode & GR_NOLEARN))
53361 + gr_log_learn(dentry, mnt, new_mode);
53362 + }
53363 +
53364 + return retval;
53365 +}
53366 +
53367 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53368 + const struct dentry *parent,
53369 + const struct vfsmount *mnt)
53370 +{
53371 + struct name_entry *match;
53372 + struct acl_object_label *matchpo;
53373 + struct acl_subject_label *curracl;
53374 + char *path;
53375 +
53376 + if (unlikely(!(gr_status & GR_READY)))
53377 + return NULL;
53378 +
53379 + preempt_disable();
53380 + path = gr_to_filename_rbac(new_dentry, mnt);
53381 + match = lookup_name_entry_create(path);
53382 +
53383 + curracl = current->acl;
53384 +
53385 + if (match) {
53386 + read_lock(&gr_inode_lock);
53387 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53388 + read_unlock(&gr_inode_lock);
53389 +
53390 + if (matchpo) {
53391 + preempt_enable();
53392 + return matchpo;
53393 + }
53394 + }
53395 +
53396 + // lookup parent
53397 +
53398 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53399 +
53400 + preempt_enable();
53401 + return matchpo;
53402 +}
53403 +
53404 +__u32
53405 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53406 + const struct vfsmount * mnt, const __u32 mode)
53407 +{
53408 + struct acl_object_label *matchpo;
53409 + __u32 retval;
53410 +
53411 + if (unlikely(!(gr_status & GR_READY)))
53412 + return (mode & ~GR_AUDITS);
53413 +
53414 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53415 +
53416 + retval = matchpo->mode & mode;
53417 +
53418 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53419 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53420 + __u32 new_mode = mode;
53421 +
53422 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53423 +
53424 + gr_log_learn(new_dentry, mnt, new_mode);
53425 + return new_mode;
53426 + }
53427 +
53428 + return retval;
53429 +}
53430 +
53431 +__u32
53432 +gr_check_link(const struct dentry * new_dentry,
53433 + const struct dentry * parent_dentry,
53434 + const struct vfsmount * parent_mnt,
53435 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53436 +{
53437 + struct acl_object_label *obj;
53438 + __u32 oldmode, newmode;
53439 + __u32 needmode;
53440 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53441 + GR_DELETE | GR_INHERIT;
53442 +
53443 + if (unlikely(!(gr_status & GR_READY)))
53444 + return (GR_CREATE | GR_LINK);
53445 +
53446 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53447 + oldmode = obj->mode;
53448 +
53449 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53450 + newmode = obj->mode;
53451 +
53452 + needmode = newmode & checkmodes;
53453 +
53454 + // old name for hardlink must have at least the permissions of the new name
53455 + if ((oldmode & needmode) != needmode)
53456 + goto bad;
53457 +
53458 + // if old name had restrictions/auditing, make sure the new name does as well
53459 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53460 +
53461 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53462 + if (is_privileged_binary(old_dentry))
53463 + needmode |= GR_SETID;
53464 +
53465 + if ((newmode & needmode) != needmode)
53466 + goto bad;
53467 +
53468 + // enforce minimum permissions
53469 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53470 + return newmode;
53471 +bad:
53472 + needmode = oldmode;
53473 + if (is_privileged_binary(old_dentry))
53474 + needmode |= GR_SETID;
53475 +
53476 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53477 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53478 + return (GR_CREATE | GR_LINK);
53479 + } else if (newmode & GR_SUPPRESS)
53480 + return GR_SUPPRESS;
53481 + else
53482 + return 0;
53483 +}
53484 +
53485 +int
53486 +gr_check_hidden_task(const struct task_struct *task)
53487 +{
53488 + if (unlikely(!(gr_status & GR_READY)))
53489 + return 0;
53490 +
53491 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53492 + return 1;
53493 +
53494 + return 0;
53495 +}
53496 +
53497 +int
53498 +gr_check_protected_task(const struct task_struct *task)
53499 +{
53500 + if (unlikely(!(gr_status & GR_READY) || !task))
53501 + return 0;
53502 +
53503 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53504 + task->acl != current->acl)
53505 + return 1;
53506 +
53507 + return 0;
53508 +}
53509 +
53510 +int
53511 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53512 +{
53513 + struct task_struct *p;
53514 + int ret = 0;
53515 +
53516 + if (unlikely(!(gr_status & GR_READY) || !pid))
53517 + return ret;
53518 +
53519 + read_lock(&tasklist_lock);
53520 + do_each_pid_task(pid, type, p) {
53521 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53522 + p->acl != current->acl) {
53523 + ret = 1;
53524 + goto out;
53525 + }
53526 + } while_each_pid_task(pid, type, p);
53527 +out:
53528 + read_unlock(&tasklist_lock);
53529 +
53530 + return ret;
53531 +}
53532 +
53533 +void
53534 +gr_copy_label(struct task_struct *tsk)
53535 +{
53536 + tsk->signal->used_accept = 0;
53537 + tsk->acl_sp_role = 0;
53538 + tsk->acl_role_id = current->acl_role_id;
53539 + tsk->acl = current->acl;
53540 + tsk->role = current->role;
53541 + tsk->signal->curr_ip = current->signal->curr_ip;
53542 + tsk->signal->saved_ip = current->signal->saved_ip;
53543 + if (current->exec_file)
53544 + get_file(current->exec_file);
53545 + tsk->exec_file = current->exec_file;
53546 + tsk->is_writable = current->is_writable;
53547 + if (unlikely(current->signal->used_accept)) {
53548 + current->signal->curr_ip = 0;
53549 + current->signal->saved_ip = 0;
53550 + }
53551 +
53552 + return;
53553 +}
53554 +
53555 +static void
53556 +gr_set_proc_res(struct task_struct *task)
53557 +{
53558 + struct acl_subject_label *proc;
53559 + unsigned short i;
53560 +
53561 + proc = task->acl;
53562 +
53563 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53564 + return;
53565 +
53566 + for (i = 0; i < RLIM_NLIMITS; i++) {
53567 + if (!(proc->resmask & (1 << i)))
53568 + continue;
53569 +
53570 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53571 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53572 + }
53573 +
53574 + return;
53575 +}
53576 +
53577 +extern int __gr_process_user_ban(struct user_struct *user);
53578 +
53579 +int
53580 +gr_check_user_change(int real, int effective, int fs)
53581 +{
53582 + unsigned int i;
53583 + __u16 num;
53584 + uid_t *uidlist;
53585 + int curuid;
53586 + int realok = 0;
53587 + int effectiveok = 0;
53588 + int fsok = 0;
53589 +
53590 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53591 + struct user_struct *user;
53592 +
53593 + if (real == -1)
53594 + goto skipit;
53595 +
53596 + user = find_user(real);
53597 + if (user == NULL)
53598 + goto skipit;
53599 +
53600 + if (__gr_process_user_ban(user)) {
53601 + /* for find_user */
53602 + free_uid(user);
53603 + return 1;
53604 + }
53605 +
53606 + /* for find_user */
53607 + free_uid(user);
53608 +
53609 +skipit:
53610 +#endif
53611 +
53612 + if (unlikely(!(gr_status & GR_READY)))
53613 + return 0;
53614 +
53615 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53616 + gr_log_learn_id_change('u', real, effective, fs);
53617 +
53618 + num = current->acl->user_trans_num;
53619 + uidlist = current->acl->user_transitions;
53620 +
53621 + if (uidlist == NULL)
53622 + return 0;
53623 +
53624 + if (real == -1)
53625 + realok = 1;
53626 + if (effective == -1)
53627 + effectiveok = 1;
53628 + if (fs == -1)
53629 + fsok = 1;
53630 +
53631 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53632 + for (i = 0; i < num; i++) {
53633 + curuid = (int)uidlist[i];
53634 + if (real == curuid)
53635 + realok = 1;
53636 + if (effective == curuid)
53637 + effectiveok = 1;
53638 + if (fs == curuid)
53639 + fsok = 1;
53640 + }
53641 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53642 + for (i = 0; i < num; i++) {
53643 + curuid = (int)uidlist[i];
53644 + if (real == curuid)
53645 + break;
53646 + if (effective == curuid)
53647 + break;
53648 + if (fs == curuid)
53649 + break;
53650 + }
53651 + /* not in deny list */
53652 + if (i == num) {
53653 + realok = 1;
53654 + effectiveok = 1;
53655 + fsok = 1;
53656 + }
53657 + }
53658 +
53659 + if (realok && effectiveok && fsok)
53660 + return 0;
53661 + else {
53662 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53663 + return 1;
53664 + }
53665 +}
53666 +
53667 +int
53668 +gr_check_group_change(int real, int effective, int fs)
53669 +{
53670 + unsigned int i;
53671 + __u16 num;
53672 + gid_t *gidlist;
53673 + int curgid;
53674 + int realok = 0;
53675 + int effectiveok = 0;
53676 + int fsok = 0;
53677 +
53678 + if (unlikely(!(gr_status & GR_READY)))
53679 + return 0;
53680 +
53681 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53682 + gr_log_learn_id_change('g', real, effective, fs);
53683 +
53684 + num = current->acl->group_trans_num;
53685 + gidlist = current->acl->group_transitions;
53686 +
53687 + if (gidlist == NULL)
53688 + return 0;
53689 +
53690 + if (real == -1)
53691 + realok = 1;
53692 + if (effective == -1)
53693 + effectiveok = 1;
53694 + if (fs == -1)
53695 + fsok = 1;
53696 +
53697 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53698 + for (i = 0; i < num; i++) {
53699 + curgid = (int)gidlist[i];
53700 + if (real == curgid)
53701 + realok = 1;
53702 + if (effective == curgid)
53703 + effectiveok = 1;
53704 + if (fs == curgid)
53705 + fsok = 1;
53706 + }
53707 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53708 + for (i = 0; i < num; i++) {
53709 + curgid = (int)gidlist[i];
53710 + if (real == curgid)
53711 + break;
53712 + if (effective == curgid)
53713 + break;
53714 + if (fs == curgid)
53715 + break;
53716 + }
53717 + /* not in deny list */
53718 + if (i == num) {
53719 + realok = 1;
53720 + effectiveok = 1;
53721 + fsok = 1;
53722 + }
53723 + }
53724 +
53725 + if (realok && effectiveok && fsok)
53726 + return 0;
53727 + else {
53728 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53729 + return 1;
53730 + }
53731 +}
53732 +
53733 +extern int gr_acl_is_capable(const int cap);
53734 +
53735 +void
53736 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53737 +{
53738 + struct acl_role_label *role = task->role;
53739 + struct acl_subject_label *subj = NULL;
53740 + struct acl_object_label *obj;
53741 + struct file *filp;
53742 +
53743 + if (unlikely(!(gr_status & GR_READY)))
53744 + return;
53745 +
53746 + filp = task->exec_file;
53747 +
53748 + /* kernel process, we'll give them the kernel role */
53749 + if (unlikely(!filp)) {
53750 + task->role = kernel_role;
53751 + task->acl = kernel_role->root_label;
53752 + return;
53753 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53754 + role = lookup_acl_role_label(task, uid, gid);
53755 +
53756 + /* don't change the role if we're not a privileged process */
53757 + if (role && task->role != role &&
53758 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53759 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53760 + return;
53761 +
53762 + /* perform subject lookup in possibly new role
53763 + we can use this result below in the case where role == task->role
53764 + */
53765 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53766 +
53767 + /* if we changed uid/gid, but result in the same role
53768 + and are using inheritance, don't lose the inherited subject
53769 + if current subject is other than what normal lookup
53770 + would result in, we arrived via inheritance, don't
53771 + lose subject
53772 + */
53773 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53774 + (subj == task->acl)))
53775 + task->acl = subj;
53776 +
53777 + task->role = role;
53778 +
53779 + task->is_writable = 0;
53780 +
53781 + /* ignore additional mmap checks for processes that are writable
53782 + by the default ACL */
53783 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53784 + if (unlikely(obj->mode & GR_WRITE))
53785 + task->is_writable = 1;
53786 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53787 + if (unlikely(obj->mode & GR_WRITE))
53788 + task->is_writable = 1;
53789 +
53790 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53791 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53792 +#endif
53793 +
53794 + gr_set_proc_res(task);
53795 +
53796 + return;
53797 +}
53798 +
53799 +int
53800 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53801 + const int unsafe_flags)
53802 +{
53803 + struct task_struct *task = current;
53804 + struct acl_subject_label *newacl;
53805 + struct acl_object_label *obj;
53806 + __u32 retmode;
53807 +
53808 + if (unlikely(!(gr_status & GR_READY)))
53809 + return 0;
53810 +
53811 + newacl = chk_subj_label(dentry, mnt, task->role);
53812 +
53813 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53814 + did an exec
53815 + */
53816 + rcu_read_lock();
53817 + read_lock(&tasklist_lock);
53818 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53819 + (task->parent->acl->mode & GR_POVERRIDE))) {
53820 + read_unlock(&tasklist_lock);
53821 + rcu_read_unlock();
53822 + goto skip_check;
53823 + }
53824 + read_unlock(&tasklist_lock);
53825 + rcu_read_unlock();
53826 +
53827 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53828 + !(task->role->roletype & GR_ROLE_GOD) &&
53829 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53830 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53831 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53832 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53833 + else
53834 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53835 + return -EACCES;
53836 + }
53837 +
53838 +skip_check:
53839 +
53840 + obj = chk_obj_label(dentry, mnt, task->acl);
53841 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53842 +
53843 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53844 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53845 + if (obj->nested)
53846 + task->acl = obj->nested;
53847 + else
53848 + task->acl = newacl;
53849 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53850 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53851 +
53852 + task->is_writable = 0;
53853 +
53854 + /* ignore additional mmap checks for processes that are writable
53855 + by the default ACL */
53856 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53857 + if (unlikely(obj->mode & GR_WRITE))
53858 + task->is_writable = 1;
53859 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53860 + if (unlikely(obj->mode & GR_WRITE))
53861 + task->is_writable = 1;
53862 +
53863 + gr_set_proc_res(task);
53864 +
53865 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53866 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53867 +#endif
53868 + return 0;
53869 +}
53870 +
53871 +/* always called with valid inodev ptr */
53872 +static void
53873 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53874 +{
53875 + struct acl_object_label *matchpo;
53876 + struct acl_subject_label *matchps;
53877 + struct acl_subject_label *subj;
53878 + struct acl_role_label *role;
53879 + unsigned int x;
53880 +
53881 + FOR_EACH_ROLE_START(role)
53882 + FOR_EACH_SUBJECT_START(role, subj, x)
53883 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53884 + matchpo->mode |= GR_DELETED;
53885 + FOR_EACH_SUBJECT_END(subj,x)
53886 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53887 + if (subj->inode == ino && subj->device == dev)
53888 + subj->mode |= GR_DELETED;
53889 + FOR_EACH_NESTED_SUBJECT_END(subj)
53890 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53891 + matchps->mode |= GR_DELETED;
53892 + FOR_EACH_ROLE_END(role)
53893 +
53894 + inodev->nentry->deleted = 1;
53895 +
53896 + return;
53897 +}
53898 +
53899 +void
53900 +gr_handle_delete(const ino_t ino, const dev_t dev)
53901 +{
53902 + struct inodev_entry *inodev;
53903 +
53904 + if (unlikely(!(gr_status & GR_READY)))
53905 + return;
53906 +
53907 + write_lock(&gr_inode_lock);
53908 + inodev = lookup_inodev_entry(ino, dev);
53909 + if (inodev != NULL)
53910 + do_handle_delete(inodev, ino, dev);
53911 + write_unlock(&gr_inode_lock);
53912 +
53913 + return;
53914 +}
53915 +
53916 +static void
53917 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53918 + const ino_t newinode, const dev_t newdevice,
53919 + struct acl_subject_label *subj)
53920 +{
53921 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53922 + struct acl_object_label *match;
53923 +
53924 + match = subj->obj_hash[index];
53925 +
53926 + while (match && (match->inode != oldinode ||
53927 + match->device != olddevice ||
53928 + !(match->mode & GR_DELETED)))
53929 + match = match->next;
53930 +
53931 + if (match && (match->inode == oldinode)
53932 + && (match->device == olddevice)
53933 + && (match->mode & GR_DELETED)) {
53934 + if (match->prev == NULL) {
53935 + subj->obj_hash[index] = match->next;
53936 + if (match->next != NULL)
53937 + match->next->prev = NULL;
53938 + } else {
53939 + match->prev->next = match->next;
53940 + if (match->next != NULL)
53941 + match->next->prev = match->prev;
53942 + }
53943 + match->prev = NULL;
53944 + match->next = NULL;
53945 + match->inode = newinode;
53946 + match->device = newdevice;
53947 + match->mode &= ~GR_DELETED;
53948 +
53949 + insert_acl_obj_label(match, subj);
53950 + }
53951 +
53952 + return;
53953 +}
53954 +
53955 +static void
53956 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53957 + const ino_t newinode, const dev_t newdevice,
53958 + struct acl_role_label *role)
53959 +{
53960 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53961 + struct acl_subject_label *match;
53962 +
53963 + match = role->subj_hash[index];
53964 +
53965 + while (match && (match->inode != oldinode ||
53966 + match->device != olddevice ||
53967 + !(match->mode & GR_DELETED)))
53968 + match = match->next;
53969 +
53970 + if (match && (match->inode == oldinode)
53971 + && (match->device == olddevice)
53972 + && (match->mode & GR_DELETED)) {
53973 + if (match->prev == NULL) {
53974 + role->subj_hash[index] = match->next;
53975 + if (match->next != NULL)
53976 + match->next->prev = NULL;
53977 + } else {
53978 + match->prev->next = match->next;
53979 + if (match->next != NULL)
53980 + match->next->prev = match->prev;
53981 + }
53982 + match->prev = NULL;
53983 + match->next = NULL;
53984 + match->inode = newinode;
53985 + match->device = newdevice;
53986 + match->mode &= ~GR_DELETED;
53987 +
53988 + insert_acl_subj_label(match, role);
53989 + }
53990 +
53991 + return;
53992 +}
53993 +
53994 +static void
53995 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53996 + const ino_t newinode, const dev_t newdevice)
53997 +{
53998 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53999 + struct inodev_entry *match;
54000 +
54001 + match = inodev_set.i_hash[index];
54002 +
54003 + while (match && (match->nentry->inode != oldinode ||
54004 + match->nentry->device != olddevice || !match->nentry->deleted))
54005 + match = match->next;
54006 +
54007 + if (match && (match->nentry->inode == oldinode)
54008 + && (match->nentry->device == olddevice) &&
54009 + match->nentry->deleted) {
54010 + if (match->prev == NULL) {
54011 + inodev_set.i_hash[index] = match->next;
54012 + if (match->next != NULL)
54013 + match->next->prev = NULL;
54014 + } else {
54015 + match->prev->next = match->next;
54016 + if (match->next != NULL)
54017 + match->next->prev = match->prev;
54018 + }
54019 + match->prev = NULL;
54020 + match->next = NULL;
54021 + match->nentry->inode = newinode;
54022 + match->nentry->device = newdevice;
54023 + match->nentry->deleted = 0;
54024 +
54025 + insert_inodev_entry(match);
54026 + }
54027 +
54028 + return;
54029 +}
54030 +
54031 +static void
54032 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54033 +{
54034 + struct acl_subject_label *subj;
54035 + struct acl_role_label *role;
54036 + unsigned int x;
54037 +
54038 + FOR_EACH_ROLE_START(role)
54039 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54040 +
54041 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54042 + if ((subj->inode == ino) && (subj->device == dev)) {
54043 + subj->inode = ino;
54044 + subj->device = dev;
54045 + }
54046 + FOR_EACH_NESTED_SUBJECT_END(subj)
54047 + FOR_EACH_SUBJECT_START(role, subj, x)
54048 + update_acl_obj_label(matchn->inode, matchn->device,
54049 + ino, dev, subj);
54050 + FOR_EACH_SUBJECT_END(subj,x)
54051 + FOR_EACH_ROLE_END(role)
54052 +
54053 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54054 +
54055 + return;
54056 +}
54057 +
54058 +static void
54059 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54060 + const struct vfsmount *mnt)
54061 +{
54062 + ino_t ino = dentry->d_inode->i_ino;
54063 + dev_t dev = __get_dev(dentry);
54064 +
54065 + __do_handle_create(matchn, ino, dev);
54066 +
54067 + return;
54068 +}
54069 +
54070 +void
54071 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54072 +{
54073 + struct name_entry *matchn;
54074 +
54075 + if (unlikely(!(gr_status & GR_READY)))
54076 + return;
54077 +
54078 + preempt_disable();
54079 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54080 +
54081 + if (unlikely((unsigned long)matchn)) {
54082 + write_lock(&gr_inode_lock);
54083 + do_handle_create(matchn, dentry, mnt);
54084 + write_unlock(&gr_inode_lock);
54085 + }
54086 + preempt_enable();
54087 +
54088 + return;
54089 +}
54090 +
54091 +void
54092 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54093 +{
54094 + struct name_entry *matchn;
54095 +
54096 + if (unlikely(!(gr_status & GR_READY)))
54097 + return;
54098 +
54099 + preempt_disable();
54100 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54101 +
54102 + if (unlikely((unsigned long)matchn)) {
54103 + write_lock(&gr_inode_lock);
54104 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54105 + write_unlock(&gr_inode_lock);
54106 + }
54107 + preempt_enable();
54108 +
54109 + return;
54110 +}
54111 +
54112 +void
54113 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54114 + struct dentry *old_dentry,
54115 + struct dentry *new_dentry,
54116 + struct vfsmount *mnt, const __u8 replace)
54117 +{
54118 + struct name_entry *matchn;
54119 + struct inodev_entry *inodev;
54120 + struct inode *inode = new_dentry->d_inode;
54121 + ino_t old_ino = old_dentry->d_inode->i_ino;
54122 + dev_t old_dev = __get_dev(old_dentry);
54123 +
54124 + /* vfs_rename swaps the name and parent link for old_dentry and
54125 + new_dentry
54126 + at this point, old_dentry has the new name, parent link, and inode
54127 + for the renamed file
54128 + if a file is being replaced by a rename, new_dentry has the inode
54129 + and name for the replaced file
54130 + */
54131 +
54132 + if (unlikely(!(gr_status & GR_READY)))
54133 + return;
54134 +
54135 + preempt_disable();
54136 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54137 +
54138 + /* we wouldn't have to check d_inode if it weren't for
54139 + NFS silly-renaming
54140 + */
54141 +
54142 + write_lock(&gr_inode_lock);
54143 + if (unlikely(replace && inode)) {
54144 + ino_t new_ino = inode->i_ino;
54145 + dev_t new_dev = __get_dev(new_dentry);
54146 +
54147 + inodev = lookup_inodev_entry(new_ino, new_dev);
54148 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54149 + do_handle_delete(inodev, new_ino, new_dev);
54150 + }
54151 +
54152 + inodev = lookup_inodev_entry(old_ino, old_dev);
54153 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54154 + do_handle_delete(inodev, old_ino, old_dev);
54155 +
54156 + if (unlikely((unsigned long)matchn))
54157 + do_handle_create(matchn, old_dentry, mnt);
54158 +
54159 + write_unlock(&gr_inode_lock);
54160 + preempt_enable();
54161 +
54162 + return;
54163 +}
54164 +
54165 +static int
54166 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54167 + unsigned char **sum)
54168 +{
54169 + struct acl_role_label *r;
54170 + struct role_allowed_ip *ipp;
54171 + struct role_transition *trans;
54172 + unsigned int i;
54173 + int found = 0;
54174 + u32 curr_ip = current->signal->curr_ip;
54175 +
54176 + current->signal->saved_ip = curr_ip;
54177 +
54178 + /* check transition table */
54179 +
54180 + for (trans = current->role->transitions; trans; trans = trans->next) {
54181 + if (!strcmp(rolename, trans->rolename)) {
54182 + found = 1;
54183 + break;
54184 + }
54185 + }
54186 +
54187 + if (!found)
54188 + return 0;
54189 +
54190 + /* handle special roles that do not require authentication
54191 + and check ip */
54192 +
54193 + FOR_EACH_ROLE_START(r)
54194 + if (!strcmp(rolename, r->rolename) &&
54195 + (r->roletype & GR_ROLE_SPECIAL)) {
54196 + found = 0;
54197 + if (r->allowed_ips != NULL) {
54198 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54199 + if ((ntohl(curr_ip) & ipp->netmask) ==
54200 + (ntohl(ipp->addr) & ipp->netmask))
54201 + found = 1;
54202 + }
54203 + } else
54204 + found = 2;
54205 + if (!found)
54206 + return 0;
54207 +
54208 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54209 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54210 + *salt = NULL;
54211 + *sum = NULL;
54212 + return 1;
54213 + }
54214 + }
54215 + FOR_EACH_ROLE_END(r)
54216 +
54217 + for (i = 0; i < num_sprole_pws; i++) {
54218 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54219 + *salt = acl_special_roles[i]->salt;
54220 + *sum = acl_special_roles[i]->sum;
54221 + return 1;
54222 + }
54223 + }
54224 +
54225 + return 0;
54226 +}
54227 +
54228 +static void
54229 +assign_special_role(char *rolename)
54230 +{
54231 + struct acl_object_label *obj;
54232 + struct acl_role_label *r;
54233 + struct acl_role_label *assigned = NULL;
54234 + struct task_struct *tsk;
54235 + struct file *filp;
54236 +
54237 + FOR_EACH_ROLE_START(r)
54238 + if (!strcmp(rolename, r->rolename) &&
54239 + (r->roletype & GR_ROLE_SPECIAL)) {
54240 + assigned = r;
54241 + break;
54242 + }
54243 + FOR_EACH_ROLE_END(r)
54244 +
54245 + if (!assigned)
54246 + return;
54247 +
54248 + read_lock(&tasklist_lock);
54249 + read_lock(&grsec_exec_file_lock);
54250 +
54251 + tsk = current->real_parent;
54252 + if (tsk == NULL)
54253 + goto out_unlock;
54254 +
54255 + filp = tsk->exec_file;
54256 + if (filp == NULL)
54257 + goto out_unlock;
54258 +
54259 + tsk->is_writable = 0;
54260 +
54261 + tsk->acl_sp_role = 1;
54262 + tsk->acl_role_id = ++acl_sp_role_value;
54263 + tsk->role = assigned;
54264 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54265 +
54266 + /* ignore additional mmap checks for processes that are writable
54267 + by the default ACL */
54268 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54269 + if (unlikely(obj->mode & GR_WRITE))
54270 + tsk->is_writable = 1;
54271 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54272 + if (unlikely(obj->mode & GR_WRITE))
54273 + tsk->is_writable = 1;
54274 +
54275 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54276 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54277 +#endif
54278 +
54279 +out_unlock:
54280 + read_unlock(&grsec_exec_file_lock);
54281 + read_unlock(&tasklist_lock);
54282 + return;
54283 +}
54284 +
54285 +int gr_check_secure_terminal(struct task_struct *task)
54286 +{
54287 + struct task_struct *p, *p2, *p3;
54288 + struct files_struct *files;
54289 + struct fdtable *fdt;
54290 + struct file *our_file = NULL, *file;
54291 + int i;
54292 +
54293 + if (task->signal->tty == NULL)
54294 + return 1;
54295 +
54296 + files = get_files_struct(task);
54297 + if (files != NULL) {
54298 + rcu_read_lock();
54299 + fdt = files_fdtable(files);
54300 + for (i=0; i < fdt->max_fds; i++) {
54301 + file = fcheck_files(files, i);
54302 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54303 + get_file(file);
54304 + our_file = file;
54305 + }
54306 + }
54307 + rcu_read_unlock();
54308 + put_files_struct(files);
54309 + }
54310 +
54311 + if (our_file == NULL)
54312 + return 1;
54313 +
54314 + read_lock(&tasklist_lock);
54315 + do_each_thread(p2, p) {
54316 + files = get_files_struct(p);
54317 + if (files == NULL ||
54318 + (p->signal && p->signal->tty == task->signal->tty)) {
54319 + if (files != NULL)
54320 + put_files_struct(files);
54321 + continue;
54322 + }
54323 + rcu_read_lock();
54324 + fdt = files_fdtable(files);
54325 + for (i=0; i < fdt->max_fds; i++) {
54326 + file = fcheck_files(files, i);
54327 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54328 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54329 + p3 = task;
54330 + while (p3->pid > 0) {
54331 + if (p3 == p)
54332 + break;
54333 + p3 = p3->real_parent;
54334 + }
54335 + if (p3 == p)
54336 + break;
54337 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54338 + gr_handle_alertkill(p);
54339 + rcu_read_unlock();
54340 + put_files_struct(files);
54341 + read_unlock(&tasklist_lock);
54342 + fput(our_file);
54343 + return 0;
54344 + }
54345 + }
54346 + rcu_read_unlock();
54347 + put_files_struct(files);
54348 + } while_each_thread(p2, p);
54349 + read_unlock(&tasklist_lock);
54350 +
54351 + fput(our_file);
54352 + return 1;
54353 +}
54354 +
54355 +static int gr_rbac_disable(void *unused)
54356 +{
54357 + pax_open_kernel();
54358 + gr_status &= ~GR_READY;
54359 + pax_close_kernel();
54360 +
54361 + return 0;
54362 +}
54363 +
54364 +ssize_t
54365 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54366 +{
54367 + struct gr_arg_wrapper uwrap;
54368 + unsigned char *sprole_salt = NULL;
54369 + unsigned char *sprole_sum = NULL;
54370 + int error = sizeof (struct gr_arg_wrapper);
54371 + int error2 = 0;
54372 +
54373 + mutex_lock(&gr_dev_mutex);
54374 +
54375 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54376 + error = -EPERM;
54377 + goto out;
54378 + }
54379 +
54380 + if (count != sizeof (struct gr_arg_wrapper)) {
54381 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54382 + error = -EINVAL;
54383 + goto out;
54384 + }
54385 +
54386 +
54387 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54388 + gr_auth_expires = 0;
54389 + gr_auth_attempts = 0;
54390 + }
54391 +
54392 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54393 + error = -EFAULT;
54394 + goto out;
54395 + }
54396 +
54397 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54398 + error = -EINVAL;
54399 + goto out;
54400 + }
54401 +
54402 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54403 + error = -EFAULT;
54404 + goto out;
54405 + }
54406 +
54407 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54408 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54409 + time_after(gr_auth_expires, get_seconds())) {
54410 + error = -EBUSY;
54411 + goto out;
54412 + }
54413 +
54414 + /* if non-root trying to do anything other than use a special role,
54415 + do not attempt authentication, do not count towards authentication
54416 + locking
54417 + */
54418 +
54419 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54420 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54421 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54422 + error = -EPERM;
54423 + goto out;
54424 + }
54425 +
54426 + /* ensure pw and special role name are null terminated */
54427 +
54428 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54429 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54430 +
54431 + /* Okay.
54432 + * We have our enough of the argument structure..(we have yet
54433 + * to copy_from_user the tables themselves) . Copy the tables
54434 + * only if we need them, i.e. for loading operations. */
54435 +
54436 + switch (gr_usermode->mode) {
54437 + case GR_STATUS:
54438 + if (gr_status & GR_READY) {
54439 + error = 1;
54440 + if (!gr_check_secure_terminal(current))
54441 + error = 3;
54442 + } else
54443 + error = 2;
54444 + goto out;
54445 + case GR_SHUTDOWN:
54446 + if ((gr_status & GR_READY)
54447 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54448 + stop_machine(gr_rbac_disable, NULL, NULL);
54449 + free_variables();
54450 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54451 + memset(gr_system_salt, 0, GR_SALT_LEN);
54452 + memset(gr_system_sum, 0, GR_SHA_LEN);
54453 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54454 + } else if (gr_status & GR_READY) {
54455 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54456 + error = -EPERM;
54457 + } else {
54458 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54459 + error = -EAGAIN;
54460 + }
54461 + break;
54462 + case GR_ENABLE:
54463 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54464 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54465 + else {
54466 + if (gr_status & GR_READY)
54467 + error = -EAGAIN;
54468 + else
54469 + error = error2;
54470 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54471 + }
54472 + break;
54473 + case GR_RELOAD:
54474 + if (!(gr_status & GR_READY)) {
54475 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54476 + error = -EAGAIN;
54477 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54478 + stop_machine(gr_rbac_disable, NULL, NULL);
54479 + free_variables();
54480 + error2 = gracl_init(gr_usermode);
54481 + if (!error2)
54482 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54483 + else {
54484 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54485 + error = error2;
54486 + }
54487 + } else {
54488 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54489 + error = -EPERM;
54490 + }
54491 + break;
54492 + case GR_SEGVMOD:
54493 + if (unlikely(!(gr_status & GR_READY))) {
54494 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54495 + error = -EAGAIN;
54496 + break;
54497 + }
54498 +
54499 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54500 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54501 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54502 + struct acl_subject_label *segvacl;
54503 + segvacl =
54504 + lookup_acl_subj_label(gr_usermode->segv_inode,
54505 + gr_usermode->segv_device,
54506 + current->role);
54507 + if (segvacl) {
54508 + segvacl->crashes = 0;
54509 + segvacl->expires = 0;
54510 + }
54511 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54512 + gr_remove_uid(gr_usermode->segv_uid);
54513 + }
54514 + } else {
54515 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54516 + error = -EPERM;
54517 + }
54518 + break;
54519 + case GR_SPROLE:
54520 + case GR_SPROLEPAM:
54521 + if (unlikely(!(gr_status & GR_READY))) {
54522 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54523 + error = -EAGAIN;
54524 + break;
54525 + }
54526 +
54527 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54528 + current->role->expires = 0;
54529 + current->role->auth_attempts = 0;
54530 + }
54531 +
54532 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54533 + time_after(current->role->expires, get_seconds())) {
54534 + error = -EBUSY;
54535 + goto out;
54536 + }
54537 +
54538 + if (lookup_special_role_auth
54539 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54540 + && ((!sprole_salt && !sprole_sum)
54541 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54542 + char *p = "";
54543 + assign_special_role(gr_usermode->sp_role);
54544 + read_lock(&tasklist_lock);
54545 + if (current->real_parent)
54546 + p = current->real_parent->role->rolename;
54547 + read_unlock(&tasklist_lock);
54548 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54549 + p, acl_sp_role_value);
54550 + } else {
54551 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54552 + error = -EPERM;
54553 + if(!(current->role->auth_attempts++))
54554 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54555 +
54556 + goto out;
54557 + }
54558 + break;
54559 + case GR_UNSPROLE:
54560 + if (unlikely(!(gr_status & GR_READY))) {
54561 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54562 + error = -EAGAIN;
54563 + break;
54564 + }
54565 +
54566 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54567 + char *p = "";
54568 + int i = 0;
54569 +
54570 + read_lock(&tasklist_lock);
54571 + if (current->real_parent) {
54572 + p = current->real_parent->role->rolename;
54573 + i = current->real_parent->acl_role_id;
54574 + }
54575 + read_unlock(&tasklist_lock);
54576 +
54577 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54578 + gr_set_acls(1);
54579 + } else {
54580 + error = -EPERM;
54581 + goto out;
54582 + }
54583 + break;
54584 + default:
54585 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54586 + error = -EINVAL;
54587 + break;
54588 + }
54589 +
54590 + if (error != -EPERM)
54591 + goto out;
54592 +
54593 + if(!(gr_auth_attempts++))
54594 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54595 +
54596 + out:
54597 + mutex_unlock(&gr_dev_mutex);
54598 + return error;
54599 +}
54600 +
54601 +/* must be called with
54602 + rcu_read_lock();
54603 + read_lock(&tasklist_lock);
54604 + read_lock(&grsec_exec_file_lock);
54605 +*/
54606 +int gr_apply_subject_to_task(struct task_struct *task)
54607 +{
54608 + struct acl_object_label *obj;
54609 + char *tmpname;
54610 + struct acl_subject_label *tmpsubj;
54611 + struct file *filp;
54612 + struct name_entry *nmatch;
54613 +
54614 + filp = task->exec_file;
54615 + if (filp == NULL)
54616 + return 0;
54617 +
54618 + /* the following is to apply the correct subject
54619 + on binaries running when the RBAC system
54620 + is enabled, when the binaries have been
54621 + replaced or deleted since their execution
54622 + -----
54623 + when the RBAC system starts, the inode/dev
54624 + from exec_file will be one the RBAC system
54625 + is unaware of. It only knows the inode/dev
54626 + of the present file on disk, or the absence
54627 + of it.
54628 + */
54629 + preempt_disable();
54630 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54631 +
54632 + nmatch = lookup_name_entry(tmpname);
54633 + preempt_enable();
54634 + tmpsubj = NULL;
54635 + if (nmatch) {
54636 + if (nmatch->deleted)
54637 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54638 + else
54639 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54640 + if (tmpsubj != NULL)
54641 + task->acl = tmpsubj;
54642 + }
54643 + if (tmpsubj == NULL)
54644 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54645 + task->role);
54646 + if (task->acl) {
54647 + task->is_writable = 0;
54648 + /* ignore additional mmap checks for processes that are writable
54649 + by the default ACL */
54650 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54651 + if (unlikely(obj->mode & GR_WRITE))
54652 + task->is_writable = 1;
54653 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54654 + if (unlikely(obj->mode & GR_WRITE))
54655 + task->is_writable = 1;
54656 +
54657 + gr_set_proc_res(task);
54658 +
54659 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54660 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54661 +#endif
54662 + } else {
54663 + return 1;
54664 + }
54665 +
54666 + return 0;
54667 +}
54668 +
54669 +int
54670 +gr_set_acls(const int type)
54671 +{
54672 + struct task_struct *task, *task2;
54673 + struct acl_role_label *role = current->role;
54674 + __u16 acl_role_id = current->acl_role_id;
54675 + const struct cred *cred;
54676 + int ret;
54677 +
54678 + rcu_read_lock();
54679 + read_lock(&tasklist_lock);
54680 + read_lock(&grsec_exec_file_lock);
54681 + do_each_thread(task2, task) {
54682 + /* check to see if we're called from the exit handler,
54683 + if so, only replace ACLs that have inherited the admin
54684 + ACL */
54685 +
54686 + if (type && (task->role != role ||
54687 + task->acl_role_id != acl_role_id))
54688 + continue;
54689 +
54690 + task->acl_role_id = 0;
54691 + task->acl_sp_role = 0;
54692 +
54693 + if (task->exec_file) {
54694 + cred = __task_cred(task);
54695 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54696 + ret = gr_apply_subject_to_task(task);
54697 + if (ret) {
54698 + read_unlock(&grsec_exec_file_lock);
54699 + read_unlock(&tasklist_lock);
54700 + rcu_read_unlock();
54701 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54702 + return ret;
54703 + }
54704 + } else {
54705 + // it's a kernel process
54706 + task->role = kernel_role;
54707 + task->acl = kernel_role->root_label;
54708 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54709 + task->acl->mode &= ~GR_PROCFIND;
54710 +#endif
54711 + }
54712 + } while_each_thread(task2, task);
54713 + read_unlock(&grsec_exec_file_lock);
54714 + read_unlock(&tasklist_lock);
54715 + rcu_read_unlock();
54716 +
54717 + return 0;
54718 +}
54719 +
54720 +void
54721 +gr_learn_resource(const struct task_struct *task,
54722 + const int res, const unsigned long wanted, const int gt)
54723 +{
54724 + struct acl_subject_label *acl;
54725 + const struct cred *cred;
54726 +
54727 + if (unlikely((gr_status & GR_READY) &&
54728 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54729 + goto skip_reslog;
54730 +
54731 +#ifdef CONFIG_GRKERNSEC_RESLOG
54732 + gr_log_resource(task, res, wanted, gt);
54733 +#endif
54734 + skip_reslog:
54735 +
54736 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54737 + return;
54738 +
54739 + acl = task->acl;
54740 +
54741 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54742 + !(acl->resmask & (1 << (unsigned short) res))))
54743 + return;
54744 +
54745 + if (wanted >= acl->res[res].rlim_cur) {
54746 + unsigned long res_add;
54747 +
54748 + res_add = wanted;
54749 + switch (res) {
54750 + case RLIMIT_CPU:
54751 + res_add += GR_RLIM_CPU_BUMP;
54752 + break;
54753 + case RLIMIT_FSIZE:
54754 + res_add += GR_RLIM_FSIZE_BUMP;
54755 + break;
54756 + case RLIMIT_DATA:
54757 + res_add += GR_RLIM_DATA_BUMP;
54758 + break;
54759 + case RLIMIT_STACK:
54760 + res_add += GR_RLIM_STACK_BUMP;
54761 + break;
54762 + case RLIMIT_CORE:
54763 + res_add += GR_RLIM_CORE_BUMP;
54764 + break;
54765 + case RLIMIT_RSS:
54766 + res_add += GR_RLIM_RSS_BUMP;
54767 + break;
54768 + case RLIMIT_NPROC:
54769 + res_add += GR_RLIM_NPROC_BUMP;
54770 + break;
54771 + case RLIMIT_NOFILE:
54772 + res_add += GR_RLIM_NOFILE_BUMP;
54773 + break;
54774 + case RLIMIT_MEMLOCK:
54775 + res_add += GR_RLIM_MEMLOCK_BUMP;
54776 + break;
54777 + case RLIMIT_AS:
54778 + res_add += GR_RLIM_AS_BUMP;
54779 + break;
54780 + case RLIMIT_LOCKS:
54781 + res_add += GR_RLIM_LOCKS_BUMP;
54782 + break;
54783 + case RLIMIT_SIGPENDING:
54784 + res_add += GR_RLIM_SIGPENDING_BUMP;
54785 + break;
54786 + case RLIMIT_MSGQUEUE:
54787 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54788 + break;
54789 + case RLIMIT_NICE:
54790 + res_add += GR_RLIM_NICE_BUMP;
54791 + break;
54792 + case RLIMIT_RTPRIO:
54793 + res_add += GR_RLIM_RTPRIO_BUMP;
54794 + break;
54795 + case RLIMIT_RTTIME:
54796 + res_add += GR_RLIM_RTTIME_BUMP;
54797 + break;
54798 + }
54799 +
54800 + acl->res[res].rlim_cur = res_add;
54801 +
54802 + if (wanted > acl->res[res].rlim_max)
54803 + acl->res[res].rlim_max = res_add;
54804 +
54805 + /* only log the subject filename, since resource logging is supported for
54806 + single-subject learning only */
54807 + rcu_read_lock();
54808 + cred = __task_cred(task);
54809 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54810 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54811 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54812 + "", (unsigned long) res, &task->signal->saved_ip);
54813 + rcu_read_unlock();
54814 + }
54815 +
54816 + return;
54817 +}
54818 +
54819 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54820 +void
54821 +pax_set_initial_flags(struct linux_binprm *bprm)
54822 +{
54823 + struct task_struct *task = current;
54824 + struct acl_subject_label *proc;
54825 + unsigned long flags;
54826 +
54827 + if (unlikely(!(gr_status & GR_READY)))
54828 + return;
54829 +
54830 + flags = pax_get_flags(task);
54831 +
54832 + proc = task->acl;
54833 +
54834 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54835 + flags &= ~MF_PAX_PAGEEXEC;
54836 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54837 + flags &= ~MF_PAX_SEGMEXEC;
54838 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54839 + flags &= ~MF_PAX_RANDMMAP;
54840 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54841 + flags &= ~MF_PAX_EMUTRAMP;
54842 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54843 + flags &= ~MF_PAX_MPROTECT;
54844 +
54845 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54846 + flags |= MF_PAX_PAGEEXEC;
54847 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54848 + flags |= MF_PAX_SEGMEXEC;
54849 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54850 + flags |= MF_PAX_RANDMMAP;
54851 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54852 + flags |= MF_PAX_EMUTRAMP;
54853 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54854 + flags |= MF_PAX_MPROTECT;
54855 +
54856 + pax_set_flags(task, flags);
54857 +
54858 + return;
54859 +}
54860 +#endif
54861 +
54862 +int
54863 +gr_handle_proc_ptrace(struct task_struct *task)
54864 +{
54865 + struct file *filp;
54866 + struct task_struct *tmp = task;
54867 + struct task_struct *curtemp = current;
54868 + __u32 retmode;
54869 +
54870 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54871 + if (unlikely(!(gr_status & GR_READY)))
54872 + return 0;
54873 +#endif
54874 +
54875 + read_lock(&tasklist_lock);
54876 + read_lock(&grsec_exec_file_lock);
54877 + filp = task->exec_file;
54878 +
54879 + while (tmp->pid > 0) {
54880 + if (tmp == curtemp)
54881 + break;
54882 + tmp = tmp->real_parent;
54883 + }
54884 +
54885 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54886 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54887 + read_unlock(&grsec_exec_file_lock);
54888 + read_unlock(&tasklist_lock);
54889 + return 1;
54890 + }
54891 +
54892 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54893 + if (!(gr_status & GR_READY)) {
54894 + read_unlock(&grsec_exec_file_lock);
54895 + read_unlock(&tasklist_lock);
54896 + return 0;
54897 + }
54898 +#endif
54899 +
54900 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54901 + read_unlock(&grsec_exec_file_lock);
54902 + read_unlock(&tasklist_lock);
54903 +
54904 + if (retmode & GR_NOPTRACE)
54905 + return 1;
54906 +
54907 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54908 + && (current->acl != task->acl || (current->acl != current->role->root_label
54909 + && current->pid != task->pid)))
54910 + return 1;
54911 +
54912 + return 0;
54913 +}
54914 +
54915 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54916 +{
54917 + if (unlikely(!(gr_status & GR_READY)))
54918 + return;
54919 +
54920 + if (!(current->role->roletype & GR_ROLE_GOD))
54921 + return;
54922 +
54923 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54924 + p->role->rolename, gr_task_roletype_to_char(p),
54925 + p->acl->filename);
54926 +}
54927 +
54928 +int
54929 +gr_handle_ptrace(struct task_struct *task, const long request)
54930 +{
54931 + struct task_struct *tmp = task;
54932 + struct task_struct *curtemp = current;
54933 + __u32 retmode;
54934 +
54935 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54936 + if (unlikely(!(gr_status & GR_READY)))
54937 + return 0;
54938 +#endif
54939 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54940 + read_lock(&tasklist_lock);
54941 + while (tmp->pid > 0) {
54942 + if (tmp == curtemp)
54943 + break;
54944 + tmp = tmp->real_parent;
54945 + }
54946 +
54947 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54948 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54949 + read_unlock(&tasklist_lock);
54950 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54951 + return 1;
54952 + }
54953 + read_unlock(&tasklist_lock);
54954 + }
54955 +
54956 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54957 + if (!(gr_status & GR_READY))
54958 + return 0;
54959 +#endif
54960 +
54961 + read_lock(&grsec_exec_file_lock);
54962 + if (unlikely(!task->exec_file)) {
54963 + read_unlock(&grsec_exec_file_lock);
54964 + return 0;
54965 + }
54966 +
54967 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54968 + read_unlock(&grsec_exec_file_lock);
54969 +
54970 + if (retmode & GR_NOPTRACE) {
54971 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54972 + return 1;
54973 + }
54974 +
54975 + if (retmode & GR_PTRACERD) {
54976 + switch (request) {
54977 + case PTRACE_SEIZE:
54978 + case PTRACE_POKETEXT:
54979 + case PTRACE_POKEDATA:
54980 + case PTRACE_POKEUSR:
54981 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54982 + case PTRACE_SETREGS:
54983 + case PTRACE_SETFPREGS:
54984 +#endif
54985 +#ifdef CONFIG_X86
54986 + case PTRACE_SETFPXREGS:
54987 +#endif
54988 +#ifdef CONFIG_ALTIVEC
54989 + case PTRACE_SETVRREGS:
54990 +#endif
54991 + return 1;
54992 + default:
54993 + return 0;
54994 + }
54995 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54996 + !(current->role->roletype & GR_ROLE_GOD) &&
54997 + (current->acl != task->acl)) {
54998 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54999 + return 1;
55000 + }
55001 +
55002 + return 0;
55003 +}
55004 +
55005 +static int is_writable_mmap(const struct file *filp)
55006 +{
55007 + struct task_struct *task = current;
55008 + struct acl_object_label *obj, *obj2;
55009 +
55010 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55011 + !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))) {
55012 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55013 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55014 + task->role->root_label);
55015 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55016 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55017 + return 1;
55018 + }
55019 + }
55020 + return 0;
55021 +}
55022 +
55023 +int
55024 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55025 +{
55026 + __u32 mode;
55027 +
55028 + if (unlikely(!file || !(prot & PROT_EXEC)))
55029 + return 1;
55030 +
55031 + if (is_writable_mmap(file))
55032 + return 0;
55033 +
55034 + mode =
55035 + gr_search_file(file->f_path.dentry,
55036 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55037 + file->f_path.mnt);
55038 +
55039 + if (!gr_tpe_allow(file))
55040 + return 0;
55041 +
55042 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55043 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55044 + return 0;
55045 + } else if (unlikely(!(mode & GR_EXEC))) {
55046 + return 0;
55047 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55048 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55049 + return 1;
55050 + }
55051 +
55052 + return 1;
55053 +}
55054 +
55055 +int
55056 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55057 +{
55058 + __u32 mode;
55059 +
55060 + if (unlikely(!file || !(prot & PROT_EXEC)))
55061 + return 1;
55062 +
55063 + if (is_writable_mmap(file))
55064 + return 0;
55065 +
55066 + mode =
55067 + gr_search_file(file->f_path.dentry,
55068 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55069 + file->f_path.mnt);
55070 +
55071 + if (!gr_tpe_allow(file))
55072 + return 0;
55073 +
55074 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55075 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55076 + return 0;
55077 + } else if (unlikely(!(mode & GR_EXEC))) {
55078 + return 0;
55079 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55080 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55081 + return 1;
55082 + }
55083 +
55084 + return 1;
55085 +}
55086 +
55087 +void
55088 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55089 +{
55090 + unsigned long runtime;
55091 + unsigned long cputime;
55092 + unsigned int wday, cday;
55093 + __u8 whr, chr;
55094 + __u8 wmin, cmin;
55095 + __u8 wsec, csec;
55096 + struct timespec timeval;
55097 +
55098 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55099 + !(task->acl->mode & GR_PROCACCT)))
55100 + return;
55101 +
55102 + do_posix_clock_monotonic_gettime(&timeval);
55103 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55104 + wday = runtime / (3600 * 24);
55105 + runtime -= wday * (3600 * 24);
55106 + whr = runtime / 3600;
55107 + runtime -= whr * 3600;
55108 + wmin = runtime / 60;
55109 + runtime -= wmin * 60;
55110 + wsec = runtime;
55111 +
55112 + cputime = (task->utime + task->stime) / HZ;
55113 + cday = cputime / (3600 * 24);
55114 + cputime -= cday * (3600 * 24);
55115 + chr = cputime / 3600;
55116 + cputime -= chr * 3600;
55117 + cmin = cputime / 60;
55118 + cputime -= cmin * 60;
55119 + csec = cputime;
55120 +
55121 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55122 +
55123 + return;
55124 +}
55125 +
55126 +void gr_set_kernel_label(struct task_struct *task)
55127 +{
55128 + if (gr_status & GR_READY) {
55129 + task->role = kernel_role;
55130 + task->acl = kernel_role->root_label;
55131 + }
55132 + return;
55133 +}
55134 +
55135 +#ifdef CONFIG_TASKSTATS
55136 +int gr_is_taskstats_denied(int pid)
55137 +{
55138 + struct task_struct *task;
55139 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55140 + const struct cred *cred;
55141 +#endif
55142 + int ret = 0;
55143 +
55144 + /* restrict taskstats viewing to un-chrooted root users
55145 + who have the 'view' subject flag if the RBAC system is enabled
55146 + */
55147 +
55148 + rcu_read_lock();
55149 + read_lock(&tasklist_lock);
55150 + task = find_task_by_vpid(pid);
55151 + if (task) {
55152 +#ifdef CONFIG_GRKERNSEC_CHROOT
55153 + if (proc_is_chrooted(task))
55154 + ret = -EACCES;
55155 +#endif
55156 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55157 + cred = __task_cred(task);
55158 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55159 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55160 + ret = -EACCES;
55161 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55162 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55163 + ret = -EACCES;
55164 +#endif
55165 +#endif
55166 + if (gr_status & GR_READY) {
55167 + if (!(task->acl->mode & GR_VIEW))
55168 + ret = -EACCES;
55169 + }
55170 + } else
55171 + ret = -ENOENT;
55172 +
55173 + read_unlock(&tasklist_lock);
55174 + rcu_read_unlock();
55175 +
55176 + return ret;
55177 +}
55178 +#endif
55179 +
55180 +/* AUXV entries are filled via a descendant of search_binary_handler
55181 + after we've already applied the subject for the target
55182 +*/
55183 +int gr_acl_enable_at_secure(void)
55184 +{
55185 + if (unlikely(!(gr_status & GR_READY)))
55186 + return 0;
55187 +
55188 + if (current->acl->mode & GR_ATSECURE)
55189 + return 1;
55190 +
55191 + return 0;
55192 +}
55193 +
55194 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55195 +{
55196 + struct task_struct *task = current;
55197 + struct dentry *dentry = file->f_path.dentry;
55198 + struct vfsmount *mnt = file->f_path.mnt;
55199 + struct acl_object_label *obj, *tmp;
55200 + struct acl_subject_label *subj;
55201 + unsigned int bufsize;
55202 + int is_not_root;
55203 + char *path;
55204 + dev_t dev = __get_dev(dentry);
55205 +
55206 + if (unlikely(!(gr_status & GR_READY)))
55207 + return 1;
55208 +
55209 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55210 + return 1;
55211 +
55212 + /* ignore Eric Biederman */
55213 + if (IS_PRIVATE(dentry->d_inode))
55214 + return 1;
55215 +
55216 + subj = task->acl;
55217 + read_lock(&gr_inode_lock);
55218 + do {
55219 + obj = lookup_acl_obj_label(ino, dev, subj);
55220 + if (obj != NULL) {
55221 + read_unlock(&gr_inode_lock);
55222 + return (obj->mode & GR_FIND) ? 1 : 0;
55223 + }
55224 + } while ((subj = subj->parent_subject));
55225 + read_unlock(&gr_inode_lock);
55226 +
55227 + /* this is purely an optimization since we're looking for an object
55228 + for the directory we're doing a readdir on
55229 + if it's possible for any globbed object to match the entry we're
55230 + filling into the directory, then the object we find here will be
55231 + an anchor point with attached globbed objects
55232 + */
55233 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55234 + if (obj->globbed == NULL)
55235 + return (obj->mode & GR_FIND) ? 1 : 0;
55236 +
55237 + is_not_root = ((obj->filename[0] == '/') &&
55238 + (obj->filename[1] == '\0')) ? 0 : 1;
55239 + bufsize = PAGE_SIZE - namelen - is_not_root;
55240 +
55241 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55242 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55243 + return 1;
55244 +
55245 + preempt_disable();
55246 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55247 + bufsize);
55248 +
55249 + bufsize = strlen(path);
55250 +
55251 + /* if base is "/", don't append an additional slash */
55252 + if (is_not_root)
55253 + *(path + bufsize) = '/';
55254 + memcpy(path + bufsize + is_not_root, name, namelen);
55255 + *(path + bufsize + namelen + is_not_root) = '\0';
55256 +
55257 + tmp = obj->globbed;
55258 + while (tmp) {
55259 + if (!glob_match(tmp->filename, path)) {
55260 + preempt_enable();
55261 + return (tmp->mode & GR_FIND) ? 1 : 0;
55262 + }
55263 + tmp = tmp->next;
55264 + }
55265 + preempt_enable();
55266 + return (obj->mode & GR_FIND) ? 1 : 0;
55267 +}
55268 +
55269 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55270 +EXPORT_SYMBOL(gr_acl_is_enabled);
55271 +#endif
55272 +EXPORT_SYMBOL(gr_learn_resource);
55273 +EXPORT_SYMBOL(gr_set_kernel_label);
55274 +#ifdef CONFIG_SECURITY
55275 +EXPORT_SYMBOL(gr_check_user_change);
55276 +EXPORT_SYMBOL(gr_check_group_change);
55277 +#endif
55278 +
55279 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55280 new file mode 100644
55281 index 0000000..34fefda
55282 --- /dev/null
55283 +++ b/grsecurity/gracl_alloc.c
55284 @@ -0,0 +1,105 @@
55285 +#include <linux/kernel.h>
55286 +#include <linux/mm.h>
55287 +#include <linux/slab.h>
55288 +#include <linux/vmalloc.h>
55289 +#include <linux/gracl.h>
55290 +#include <linux/grsecurity.h>
55291 +
55292 +static unsigned long alloc_stack_next = 1;
55293 +static unsigned long alloc_stack_size = 1;
55294 +static void **alloc_stack;
55295 +
55296 +static __inline__ int
55297 +alloc_pop(void)
55298 +{
55299 + if (alloc_stack_next == 1)
55300 + return 0;
55301 +
55302 + kfree(alloc_stack[alloc_stack_next - 2]);
55303 +
55304 + alloc_stack_next--;
55305 +
55306 + return 1;
55307 +}
55308 +
55309 +static __inline__ int
55310 +alloc_push(void *buf)
55311 +{
55312 + if (alloc_stack_next >= alloc_stack_size)
55313 + return 1;
55314 +
55315 + alloc_stack[alloc_stack_next - 1] = buf;
55316 +
55317 + alloc_stack_next++;
55318 +
55319 + return 0;
55320 +}
55321 +
55322 +void *
55323 +acl_alloc(unsigned long len)
55324 +{
55325 + void *ret = NULL;
55326 +
55327 + if (!len || len > PAGE_SIZE)
55328 + goto out;
55329 +
55330 + ret = kmalloc(len, GFP_KERNEL);
55331 +
55332 + if (ret) {
55333 + if (alloc_push(ret)) {
55334 + kfree(ret);
55335 + ret = NULL;
55336 + }
55337 + }
55338 +
55339 +out:
55340 + return ret;
55341 +}
55342 +
55343 +void *
55344 +acl_alloc_num(unsigned long num, unsigned long len)
55345 +{
55346 + if (!len || (num > (PAGE_SIZE / len)))
55347 + return NULL;
55348 +
55349 + return acl_alloc(num * len);
55350 +}
55351 +
55352 +void
55353 +acl_free_all(void)
55354 +{
55355 + if (gr_acl_is_enabled() || !alloc_stack)
55356 + return;
55357 +
55358 + while (alloc_pop()) ;
55359 +
55360 + if (alloc_stack) {
55361 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55362 + kfree(alloc_stack);
55363 + else
55364 + vfree(alloc_stack);
55365 + }
55366 +
55367 + alloc_stack = NULL;
55368 + alloc_stack_size = 1;
55369 + alloc_stack_next = 1;
55370 +
55371 + return;
55372 +}
55373 +
55374 +int
55375 +acl_alloc_stack_init(unsigned long size)
55376 +{
55377 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55378 + alloc_stack =
55379 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55380 + else
55381 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55382 +
55383 + alloc_stack_size = size;
55384 +
55385 + if (!alloc_stack)
55386 + return 0;
55387 + else
55388 + return 1;
55389 +}
55390 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55391 new file mode 100644
55392 index 0000000..6d21049
55393 --- /dev/null
55394 +++ b/grsecurity/gracl_cap.c
55395 @@ -0,0 +1,110 @@
55396 +#include <linux/kernel.h>
55397 +#include <linux/module.h>
55398 +#include <linux/sched.h>
55399 +#include <linux/gracl.h>
55400 +#include <linux/grsecurity.h>
55401 +#include <linux/grinternal.h>
55402 +
55403 +extern const char *captab_log[];
55404 +extern int captab_log_entries;
55405 +
55406 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55407 +{
55408 + struct acl_subject_label *curracl;
55409 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55410 + kernel_cap_t cap_audit = __cap_empty_set;
55411 +
55412 + if (!gr_acl_is_enabled())
55413 + return 1;
55414 +
55415 + curracl = task->acl;
55416 +
55417 + cap_drop = curracl->cap_lower;
55418 + cap_mask = curracl->cap_mask;
55419 + cap_audit = curracl->cap_invert_audit;
55420 +
55421 + while ((curracl = curracl->parent_subject)) {
55422 + /* if the cap isn't specified in the current computed mask but is specified in the
55423 + current level subject, and is lowered in the current level subject, then add
55424 + it to the set of dropped capabilities
55425 + otherwise, add the current level subject's mask to the current computed mask
55426 + */
55427 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55428 + cap_raise(cap_mask, cap);
55429 + if (cap_raised(curracl->cap_lower, cap))
55430 + cap_raise(cap_drop, cap);
55431 + if (cap_raised(curracl->cap_invert_audit, cap))
55432 + cap_raise(cap_audit, cap);
55433 + }
55434 + }
55435 +
55436 + if (!cap_raised(cap_drop, cap)) {
55437 + if (cap_raised(cap_audit, cap))
55438 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55439 + return 1;
55440 + }
55441 +
55442 + curracl = task->acl;
55443 +
55444 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55445 + && cap_raised(cred->cap_effective, cap)) {
55446 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55447 + task->role->roletype, cred->uid,
55448 + cred->gid, task->exec_file ?
55449 + gr_to_filename(task->exec_file->f_path.dentry,
55450 + task->exec_file->f_path.mnt) : curracl->filename,
55451 + curracl->filename, 0UL,
55452 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55453 + return 1;
55454 + }
55455 +
55456 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55457 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55458 +
55459 + return 0;
55460 +}
55461 +
55462 +int
55463 +gr_acl_is_capable(const int cap)
55464 +{
55465 + return gr_task_acl_is_capable(current, current_cred(), cap);
55466 +}
55467 +
55468 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55469 +{
55470 + struct acl_subject_label *curracl;
55471 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55472 +
55473 + if (!gr_acl_is_enabled())
55474 + return 1;
55475 +
55476 + curracl = task->acl;
55477 +
55478 + cap_drop = curracl->cap_lower;
55479 + cap_mask = curracl->cap_mask;
55480 +
55481 + while ((curracl = curracl->parent_subject)) {
55482 + /* if the cap isn't specified in the current computed mask but is specified in the
55483 + current level subject, and is lowered in the current level subject, then add
55484 + it to the set of dropped capabilities
55485 + otherwise, add the current level subject's mask to the current computed mask
55486 + */
55487 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55488 + cap_raise(cap_mask, cap);
55489 + if (cap_raised(curracl->cap_lower, cap))
55490 + cap_raise(cap_drop, cap);
55491 + }
55492 + }
55493 +
55494 + if (!cap_raised(cap_drop, cap))
55495 + return 1;
55496 +
55497 + return 0;
55498 +}
55499 +
55500 +int
55501 +gr_acl_is_capable_nolog(const int cap)
55502 +{
55503 + return gr_task_acl_is_capable_nolog(current, cap);
55504 +}
55505 +
55506 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55507 new file mode 100644
55508 index 0000000..d28e241
55509 --- /dev/null
55510 +++ b/grsecurity/gracl_fs.c
55511 @@ -0,0 +1,437 @@
55512 +#include <linux/kernel.h>
55513 +#include <linux/sched.h>
55514 +#include <linux/types.h>
55515 +#include <linux/fs.h>
55516 +#include <linux/file.h>
55517 +#include <linux/stat.h>
55518 +#include <linux/grsecurity.h>
55519 +#include <linux/grinternal.h>
55520 +#include <linux/gracl.h>
55521 +
55522 +umode_t
55523 +gr_acl_umask(void)
55524 +{
55525 + if (unlikely(!gr_acl_is_enabled()))
55526 + return 0;
55527 +
55528 + return current->role->umask;
55529 +}
55530 +
55531 +__u32
55532 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55533 + const struct vfsmount * mnt)
55534 +{
55535 + __u32 mode;
55536 +
55537 + if (unlikely(!dentry->d_inode))
55538 + return GR_FIND;
55539 +
55540 + mode =
55541 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55542 +
55543 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55544 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55545 + return mode;
55546 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55547 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55548 + return 0;
55549 + } else if (unlikely(!(mode & GR_FIND)))
55550 + return 0;
55551 +
55552 + return GR_FIND;
55553 +}
55554 +
55555 +__u32
55556 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55557 + int acc_mode)
55558 +{
55559 + __u32 reqmode = GR_FIND;
55560 + __u32 mode;
55561 +
55562 + if (unlikely(!dentry->d_inode))
55563 + return reqmode;
55564 +
55565 + if (acc_mode & MAY_APPEND)
55566 + reqmode |= GR_APPEND;
55567 + else if (acc_mode & MAY_WRITE)
55568 + reqmode |= GR_WRITE;
55569 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55570 + reqmode |= GR_READ;
55571 +
55572 + mode =
55573 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55574 + mnt);
55575 +
55576 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55577 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55578 + reqmode & GR_READ ? " reading" : "",
55579 + reqmode & GR_WRITE ? " writing" : reqmode &
55580 + GR_APPEND ? " appending" : "");
55581 + return reqmode;
55582 + } else
55583 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55584 + {
55585 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55586 + reqmode & GR_READ ? " reading" : "",
55587 + reqmode & GR_WRITE ? " writing" : reqmode &
55588 + GR_APPEND ? " appending" : "");
55589 + return 0;
55590 + } else if (unlikely((mode & reqmode) != reqmode))
55591 + return 0;
55592 +
55593 + return reqmode;
55594 +}
55595 +
55596 +__u32
55597 +gr_acl_handle_creat(const struct dentry * dentry,
55598 + const struct dentry * p_dentry,
55599 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55600 + const int imode)
55601 +{
55602 + __u32 reqmode = GR_WRITE | GR_CREATE;
55603 + __u32 mode;
55604 +
55605 + if (acc_mode & MAY_APPEND)
55606 + reqmode |= GR_APPEND;
55607 + // if a directory was required or the directory already exists, then
55608 + // don't count this open as a read
55609 + if ((acc_mode & MAY_READ) &&
55610 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55611 + reqmode |= GR_READ;
55612 + if ((open_flags & O_CREAT) &&
55613 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55614 + reqmode |= GR_SETID;
55615 +
55616 + mode =
55617 + gr_check_create(dentry, p_dentry, p_mnt,
55618 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55619 +
55620 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55621 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55622 + reqmode & GR_READ ? " reading" : "",
55623 + reqmode & GR_WRITE ? " writing" : reqmode &
55624 + GR_APPEND ? " appending" : "");
55625 + return reqmode;
55626 + } else
55627 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55628 + {
55629 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55630 + reqmode & GR_READ ? " reading" : "",
55631 + reqmode & GR_WRITE ? " writing" : reqmode &
55632 + GR_APPEND ? " appending" : "");
55633 + return 0;
55634 + } else if (unlikely((mode & reqmode) != reqmode))
55635 + return 0;
55636 +
55637 + return reqmode;
55638 +}
55639 +
55640 +__u32
55641 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55642 + const int fmode)
55643 +{
55644 + __u32 mode, reqmode = GR_FIND;
55645 +
55646 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55647 + reqmode |= GR_EXEC;
55648 + if (fmode & S_IWOTH)
55649 + reqmode |= GR_WRITE;
55650 + if (fmode & S_IROTH)
55651 + reqmode |= GR_READ;
55652 +
55653 + mode =
55654 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55655 + mnt);
55656 +
55657 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55658 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55659 + reqmode & GR_READ ? " reading" : "",
55660 + reqmode & GR_WRITE ? " writing" : "",
55661 + reqmode & GR_EXEC ? " executing" : "");
55662 + return reqmode;
55663 + } else
55664 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55665 + {
55666 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55667 + reqmode & GR_READ ? " reading" : "",
55668 + reqmode & GR_WRITE ? " writing" : "",
55669 + reqmode & GR_EXEC ? " executing" : "");
55670 + return 0;
55671 + } else if (unlikely((mode & reqmode) != reqmode))
55672 + return 0;
55673 +
55674 + return reqmode;
55675 +}
55676 +
55677 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55678 +{
55679 + __u32 mode;
55680 +
55681 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55682 +
55683 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55684 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55685 + return mode;
55686 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55687 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55688 + return 0;
55689 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55690 + return 0;
55691 +
55692 + return (reqmode);
55693 +}
55694 +
55695 +__u32
55696 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55697 +{
55698 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55699 +}
55700 +
55701 +__u32
55702 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55703 +{
55704 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55705 +}
55706 +
55707 +__u32
55708 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55709 +{
55710 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55711 +}
55712 +
55713 +__u32
55714 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55715 +{
55716 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55717 +}
55718 +
55719 +__u32
55720 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55721 + umode_t *modeptr)
55722 +{
55723 + umode_t mode;
55724 +
55725 + *modeptr &= ~gr_acl_umask();
55726 + mode = *modeptr;
55727 +
55728 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55729 + return 1;
55730 +
55731 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55732 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55733 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55734 + GR_CHMOD_ACL_MSG);
55735 + } else {
55736 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55737 + }
55738 +}
55739 +
55740 +__u32
55741 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55742 +{
55743 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55744 +}
55745 +
55746 +__u32
55747 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55748 +{
55749 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55750 +}
55751 +
55752 +__u32
55753 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55754 +{
55755 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55756 +}
55757 +
55758 +__u32
55759 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55760 +{
55761 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55762 + GR_UNIXCONNECT_ACL_MSG);
55763 +}
55764 +
55765 +/* hardlinks require at minimum create and link permission,
55766 + any additional privilege required is based on the
55767 + privilege of the file being linked to
55768 +*/
55769 +__u32
55770 +gr_acl_handle_link(const struct dentry * new_dentry,
55771 + const struct dentry * parent_dentry,
55772 + const struct vfsmount * parent_mnt,
55773 + const struct dentry * old_dentry,
55774 + const struct vfsmount * old_mnt, const char *to)
55775 +{
55776 + __u32 mode;
55777 + __u32 needmode = GR_CREATE | GR_LINK;
55778 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55779 +
55780 + mode =
55781 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55782 + old_mnt);
55783 +
55784 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55785 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55786 + return mode;
55787 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55788 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55789 + return 0;
55790 + } else if (unlikely((mode & needmode) != needmode))
55791 + return 0;
55792 +
55793 + return 1;
55794 +}
55795 +
55796 +__u32
55797 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55798 + const struct dentry * parent_dentry,
55799 + const struct vfsmount * parent_mnt, const char *from)
55800 +{
55801 + __u32 needmode = GR_WRITE | GR_CREATE;
55802 + __u32 mode;
55803 +
55804 + mode =
55805 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55806 + GR_CREATE | GR_AUDIT_CREATE |
55807 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55808 +
55809 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55810 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55811 + return mode;
55812 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55813 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55814 + return 0;
55815 + } else if (unlikely((mode & needmode) != needmode))
55816 + return 0;
55817 +
55818 + return (GR_WRITE | GR_CREATE);
55819 +}
55820 +
55821 +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)
55822 +{
55823 + __u32 mode;
55824 +
55825 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55826 +
55827 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55828 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55829 + return mode;
55830 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55831 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55832 + return 0;
55833 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55834 + return 0;
55835 +
55836 + return (reqmode);
55837 +}
55838 +
55839 +__u32
55840 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55841 + const struct dentry * parent_dentry,
55842 + const struct vfsmount * parent_mnt,
55843 + const int mode)
55844 +{
55845 + __u32 reqmode = GR_WRITE | GR_CREATE;
55846 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55847 + reqmode |= GR_SETID;
55848 +
55849 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55850 + reqmode, GR_MKNOD_ACL_MSG);
55851 +}
55852 +
55853 +__u32
55854 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55855 + const struct dentry *parent_dentry,
55856 + const struct vfsmount *parent_mnt)
55857 +{
55858 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55859 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55860 +}
55861 +
55862 +#define RENAME_CHECK_SUCCESS(old, new) \
55863 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55864 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55865 +
55866 +int
55867 +gr_acl_handle_rename(struct dentry *new_dentry,
55868 + struct dentry *parent_dentry,
55869 + const struct vfsmount *parent_mnt,
55870 + struct dentry *old_dentry,
55871 + struct inode *old_parent_inode,
55872 + struct vfsmount *old_mnt, const char *newname)
55873 +{
55874 + __u32 comp1, comp2;
55875 + int error = 0;
55876 +
55877 + if (unlikely(!gr_acl_is_enabled()))
55878 + return 0;
55879 +
55880 + if (!new_dentry->d_inode) {
55881 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55882 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55883 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55884 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55885 + GR_DELETE | GR_AUDIT_DELETE |
55886 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55887 + GR_SUPPRESS, old_mnt);
55888 + } else {
55889 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55890 + GR_CREATE | GR_DELETE |
55891 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55892 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55893 + GR_SUPPRESS, parent_mnt);
55894 + comp2 =
55895 + gr_search_file(old_dentry,
55896 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55897 + GR_DELETE | GR_AUDIT_DELETE |
55898 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55899 + }
55900 +
55901 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55902 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55903 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55904 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55905 + && !(comp2 & GR_SUPPRESS)) {
55906 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55907 + error = -EACCES;
55908 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55909 + error = -EACCES;
55910 +
55911 + return error;
55912 +}
55913 +
55914 +void
55915 +gr_acl_handle_exit(void)
55916 +{
55917 + u16 id;
55918 + char *rolename;
55919 + struct file *exec_file;
55920 +
55921 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55922 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55923 + id = current->acl_role_id;
55924 + rolename = current->role->rolename;
55925 + gr_set_acls(1);
55926 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55927 + }
55928 +
55929 + write_lock(&grsec_exec_file_lock);
55930 + exec_file = current->exec_file;
55931 + current->exec_file = NULL;
55932 + write_unlock(&grsec_exec_file_lock);
55933 +
55934 + if (exec_file)
55935 + fput(exec_file);
55936 +}
55937 +
55938 +int
55939 +gr_acl_handle_procpidmem(const struct task_struct *task)
55940 +{
55941 + if (unlikely(!gr_acl_is_enabled()))
55942 + return 0;
55943 +
55944 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55945 + return -EACCES;
55946 +
55947 + return 0;
55948 +}
55949 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55950 new file mode 100644
55951 index 0000000..58800a7
55952 --- /dev/null
55953 +++ b/grsecurity/gracl_ip.c
55954 @@ -0,0 +1,384 @@
55955 +#include <linux/kernel.h>
55956 +#include <asm/uaccess.h>
55957 +#include <asm/errno.h>
55958 +#include <net/sock.h>
55959 +#include <linux/file.h>
55960 +#include <linux/fs.h>
55961 +#include <linux/net.h>
55962 +#include <linux/in.h>
55963 +#include <linux/skbuff.h>
55964 +#include <linux/ip.h>
55965 +#include <linux/udp.h>
55966 +#include <linux/types.h>
55967 +#include <linux/sched.h>
55968 +#include <linux/netdevice.h>
55969 +#include <linux/inetdevice.h>
55970 +#include <linux/gracl.h>
55971 +#include <linux/grsecurity.h>
55972 +#include <linux/grinternal.h>
55973 +
55974 +#define GR_BIND 0x01
55975 +#define GR_CONNECT 0x02
55976 +#define GR_INVERT 0x04
55977 +#define GR_BINDOVERRIDE 0x08
55978 +#define GR_CONNECTOVERRIDE 0x10
55979 +#define GR_SOCK_FAMILY 0x20
55980 +
55981 +static const char * gr_protocols[IPPROTO_MAX] = {
55982 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55983 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55984 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55985 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55986 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55987 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55988 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55989 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55990 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55991 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55992 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55993 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55994 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55995 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55996 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55997 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55998 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55999 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56000 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56001 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56002 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56003 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56004 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56005 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56006 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56007 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56008 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56009 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56010 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56011 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56012 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56013 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56014 + };
56015 +
56016 +static const char * gr_socktypes[SOCK_MAX] = {
56017 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56018 + "unknown:7", "unknown:8", "unknown:9", "packet"
56019 + };
56020 +
56021 +static const char * gr_sockfamilies[AF_MAX+1] = {
56022 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56023 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56024 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56025 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56026 + };
56027 +
56028 +const char *
56029 +gr_proto_to_name(unsigned char proto)
56030 +{
56031 + return gr_protocols[proto];
56032 +}
56033 +
56034 +const char *
56035 +gr_socktype_to_name(unsigned char type)
56036 +{
56037 + return gr_socktypes[type];
56038 +}
56039 +
56040 +const char *
56041 +gr_sockfamily_to_name(unsigned char family)
56042 +{
56043 + return gr_sockfamilies[family];
56044 +}
56045 +
56046 +int
56047 +gr_search_socket(const int domain, const int type, const int protocol)
56048 +{
56049 + struct acl_subject_label *curr;
56050 + const struct cred *cred = current_cred();
56051 +
56052 + if (unlikely(!gr_acl_is_enabled()))
56053 + goto exit;
56054 +
56055 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56056 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56057 + goto exit; // let the kernel handle it
56058 +
56059 + curr = current->acl;
56060 +
56061 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56062 + /* the family is allowed, if this is PF_INET allow it only if
56063 + the extra sock type/protocol checks pass */
56064 + if (domain == PF_INET)
56065 + goto inet_check;
56066 + goto exit;
56067 + } else {
56068 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56069 + __u32 fakeip = 0;
56070 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56071 + current->role->roletype, cred->uid,
56072 + cred->gid, current->exec_file ?
56073 + gr_to_filename(current->exec_file->f_path.dentry,
56074 + current->exec_file->f_path.mnt) :
56075 + curr->filename, curr->filename,
56076 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56077 + &current->signal->saved_ip);
56078 + goto exit;
56079 + }
56080 + goto exit_fail;
56081 + }
56082 +
56083 +inet_check:
56084 + /* the rest of this checking is for IPv4 only */
56085 + if (!curr->ips)
56086 + goto exit;
56087 +
56088 + if ((curr->ip_type & (1 << type)) &&
56089 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56090 + goto exit;
56091 +
56092 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56093 + /* we don't place acls on raw sockets , and sometimes
56094 + dgram/ip sockets are opened for ioctl and not
56095 + bind/connect, so we'll fake a bind learn log */
56096 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56097 + __u32 fakeip = 0;
56098 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56099 + current->role->roletype, cred->uid,
56100 + cred->gid, current->exec_file ?
56101 + gr_to_filename(current->exec_file->f_path.dentry,
56102 + current->exec_file->f_path.mnt) :
56103 + curr->filename, curr->filename,
56104 + &fakeip, 0, type,
56105 + protocol, GR_CONNECT, &current->signal->saved_ip);
56106 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56107 + __u32 fakeip = 0;
56108 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56109 + current->role->roletype, cred->uid,
56110 + cred->gid, current->exec_file ?
56111 + gr_to_filename(current->exec_file->f_path.dentry,
56112 + current->exec_file->f_path.mnt) :
56113 + curr->filename, curr->filename,
56114 + &fakeip, 0, type,
56115 + protocol, GR_BIND, &current->signal->saved_ip);
56116 + }
56117 + /* we'll log when they use connect or bind */
56118 + goto exit;
56119 + }
56120 +
56121 +exit_fail:
56122 + if (domain == PF_INET)
56123 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56124 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56125 + else
56126 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56127 + gr_socktype_to_name(type), protocol);
56128 +
56129 + return 0;
56130 +exit:
56131 + return 1;
56132 +}
56133 +
56134 +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)
56135 +{
56136 + if ((ip->mode & mode) &&
56137 + (ip_port >= ip->low) &&
56138 + (ip_port <= ip->high) &&
56139 + ((ntohl(ip_addr) & our_netmask) ==
56140 + (ntohl(our_addr) & our_netmask))
56141 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56142 + && (ip->type & (1 << type))) {
56143 + if (ip->mode & GR_INVERT)
56144 + return 2; // specifically denied
56145 + else
56146 + return 1; // allowed
56147 + }
56148 +
56149 + return 0; // not specifically allowed, may continue parsing
56150 +}
56151 +
56152 +static int
56153 +gr_search_connectbind(const int full_mode, struct sock *sk,
56154 + struct sockaddr_in *addr, const int type)
56155 +{
56156 + char iface[IFNAMSIZ] = {0};
56157 + struct acl_subject_label *curr;
56158 + struct acl_ip_label *ip;
56159 + struct inet_sock *isk;
56160 + struct net_device *dev;
56161 + struct in_device *idev;
56162 + unsigned long i;
56163 + int ret;
56164 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56165 + __u32 ip_addr = 0;
56166 + __u32 our_addr;
56167 + __u32 our_netmask;
56168 + char *p;
56169 + __u16 ip_port = 0;
56170 + const struct cred *cred = current_cred();
56171 +
56172 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56173 + return 0;
56174 +
56175 + curr = current->acl;
56176 + isk = inet_sk(sk);
56177 +
56178 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56179 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56180 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56181 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56182 + struct sockaddr_in saddr;
56183 + int err;
56184 +
56185 + saddr.sin_family = AF_INET;
56186 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56187 + saddr.sin_port = isk->inet_sport;
56188 +
56189 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56190 + if (err)
56191 + return err;
56192 +
56193 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56194 + if (err)
56195 + return err;
56196 + }
56197 +
56198 + if (!curr->ips)
56199 + return 0;
56200 +
56201 + ip_addr = addr->sin_addr.s_addr;
56202 + ip_port = ntohs(addr->sin_port);
56203 +
56204 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56205 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56206 + current->role->roletype, cred->uid,
56207 + cred->gid, current->exec_file ?
56208 + gr_to_filename(current->exec_file->f_path.dentry,
56209 + current->exec_file->f_path.mnt) :
56210 + curr->filename, curr->filename,
56211 + &ip_addr, ip_port, type,
56212 + sk->sk_protocol, mode, &current->signal->saved_ip);
56213 + return 0;
56214 + }
56215 +
56216 + for (i = 0; i < curr->ip_num; i++) {
56217 + ip = *(curr->ips + i);
56218 + if (ip->iface != NULL) {
56219 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56220 + p = strchr(iface, ':');
56221 + if (p != NULL)
56222 + *p = '\0';
56223 + dev = dev_get_by_name(sock_net(sk), iface);
56224 + if (dev == NULL)
56225 + continue;
56226 + idev = in_dev_get(dev);
56227 + if (idev == NULL) {
56228 + dev_put(dev);
56229 + continue;
56230 + }
56231 + rcu_read_lock();
56232 + for_ifa(idev) {
56233 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56234 + our_addr = ifa->ifa_address;
56235 + our_netmask = 0xffffffff;
56236 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56237 + if (ret == 1) {
56238 + rcu_read_unlock();
56239 + in_dev_put(idev);
56240 + dev_put(dev);
56241 + return 0;
56242 + } else if (ret == 2) {
56243 + rcu_read_unlock();
56244 + in_dev_put(idev);
56245 + dev_put(dev);
56246 + goto denied;
56247 + }
56248 + }
56249 + } endfor_ifa(idev);
56250 + rcu_read_unlock();
56251 + in_dev_put(idev);
56252 + dev_put(dev);
56253 + } else {
56254 + our_addr = ip->addr;
56255 + our_netmask = ip->netmask;
56256 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56257 + if (ret == 1)
56258 + return 0;
56259 + else if (ret == 2)
56260 + goto denied;
56261 + }
56262 + }
56263 +
56264 +denied:
56265 + if (mode == GR_BIND)
56266 + 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));
56267 + else if (mode == GR_CONNECT)
56268 + 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));
56269 +
56270 + return -EACCES;
56271 +}
56272 +
56273 +int
56274 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56275 +{
56276 + /* always allow disconnection of dgram sockets with connect */
56277 + if (addr->sin_family == AF_UNSPEC)
56278 + return 0;
56279 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56280 +}
56281 +
56282 +int
56283 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56284 +{
56285 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56286 +}
56287 +
56288 +int gr_search_listen(struct socket *sock)
56289 +{
56290 + struct sock *sk = sock->sk;
56291 + struct sockaddr_in addr;
56292 +
56293 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56294 + addr.sin_port = inet_sk(sk)->inet_sport;
56295 +
56296 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56297 +}
56298 +
56299 +int gr_search_accept(struct socket *sock)
56300 +{
56301 + struct sock *sk = sock->sk;
56302 + struct sockaddr_in addr;
56303 +
56304 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56305 + addr.sin_port = inet_sk(sk)->inet_sport;
56306 +
56307 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56308 +}
56309 +
56310 +int
56311 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56312 +{
56313 + if (addr)
56314 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56315 + else {
56316 + struct sockaddr_in sin;
56317 + const struct inet_sock *inet = inet_sk(sk);
56318 +
56319 + sin.sin_addr.s_addr = inet->inet_daddr;
56320 + sin.sin_port = inet->inet_dport;
56321 +
56322 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56323 + }
56324 +}
56325 +
56326 +int
56327 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56328 +{
56329 + struct sockaddr_in sin;
56330 +
56331 + if (unlikely(skb->len < sizeof (struct udphdr)))
56332 + return 0; // skip this packet
56333 +
56334 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56335 + sin.sin_port = udp_hdr(skb)->source;
56336 +
56337 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56338 +}
56339 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56340 new file mode 100644
56341 index 0000000..25f54ef
56342 --- /dev/null
56343 +++ b/grsecurity/gracl_learn.c
56344 @@ -0,0 +1,207 @@
56345 +#include <linux/kernel.h>
56346 +#include <linux/mm.h>
56347 +#include <linux/sched.h>
56348 +#include <linux/poll.h>
56349 +#include <linux/string.h>
56350 +#include <linux/file.h>
56351 +#include <linux/types.h>
56352 +#include <linux/vmalloc.h>
56353 +#include <linux/grinternal.h>
56354 +
56355 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56356 + size_t count, loff_t *ppos);
56357 +extern int gr_acl_is_enabled(void);
56358 +
56359 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56360 +static int gr_learn_attached;
56361 +
56362 +/* use a 512k buffer */
56363 +#define LEARN_BUFFER_SIZE (512 * 1024)
56364 +
56365 +static DEFINE_SPINLOCK(gr_learn_lock);
56366 +static DEFINE_MUTEX(gr_learn_user_mutex);
56367 +
56368 +/* we need to maintain two buffers, so that the kernel context of grlearn
56369 + uses a semaphore around the userspace copying, and the other kernel contexts
56370 + use a spinlock when copying into the buffer, since they cannot sleep
56371 +*/
56372 +static char *learn_buffer;
56373 +static char *learn_buffer_user;
56374 +static int learn_buffer_len;
56375 +static int learn_buffer_user_len;
56376 +
56377 +static ssize_t
56378 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56379 +{
56380 + DECLARE_WAITQUEUE(wait, current);
56381 + ssize_t retval = 0;
56382 +
56383 + add_wait_queue(&learn_wait, &wait);
56384 + set_current_state(TASK_INTERRUPTIBLE);
56385 + do {
56386 + mutex_lock(&gr_learn_user_mutex);
56387 + spin_lock(&gr_learn_lock);
56388 + if (learn_buffer_len)
56389 + break;
56390 + spin_unlock(&gr_learn_lock);
56391 + mutex_unlock(&gr_learn_user_mutex);
56392 + if (file->f_flags & O_NONBLOCK) {
56393 + retval = -EAGAIN;
56394 + goto out;
56395 + }
56396 + if (signal_pending(current)) {
56397 + retval = -ERESTARTSYS;
56398 + goto out;
56399 + }
56400 +
56401 + schedule();
56402 + } while (1);
56403 +
56404 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56405 + learn_buffer_user_len = learn_buffer_len;
56406 + retval = learn_buffer_len;
56407 + learn_buffer_len = 0;
56408 +
56409 + spin_unlock(&gr_learn_lock);
56410 +
56411 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56412 + retval = -EFAULT;
56413 +
56414 + mutex_unlock(&gr_learn_user_mutex);
56415 +out:
56416 + set_current_state(TASK_RUNNING);
56417 + remove_wait_queue(&learn_wait, &wait);
56418 + return retval;
56419 +}
56420 +
56421 +static unsigned int
56422 +poll_learn(struct file * file, poll_table * wait)
56423 +{
56424 + poll_wait(file, &learn_wait, wait);
56425 +
56426 + if (learn_buffer_len)
56427 + return (POLLIN | POLLRDNORM);
56428 +
56429 + return 0;
56430 +}
56431 +
56432 +void
56433 +gr_clear_learn_entries(void)
56434 +{
56435 + char *tmp;
56436 +
56437 + mutex_lock(&gr_learn_user_mutex);
56438 + spin_lock(&gr_learn_lock);
56439 + tmp = learn_buffer;
56440 + learn_buffer = NULL;
56441 + spin_unlock(&gr_learn_lock);
56442 + if (tmp)
56443 + vfree(tmp);
56444 + if (learn_buffer_user != NULL) {
56445 + vfree(learn_buffer_user);
56446 + learn_buffer_user = NULL;
56447 + }
56448 + learn_buffer_len = 0;
56449 + mutex_unlock(&gr_learn_user_mutex);
56450 +
56451 + return;
56452 +}
56453 +
56454 +void
56455 +gr_add_learn_entry(const char *fmt, ...)
56456 +{
56457 + va_list args;
56458 + unsigned int len;
56459 +
56460 + if (!gr_learn_attached)
56461 + return;
56462 +
56463 + spin_lock(&gr_learn_lock);
56464 +
56465 + /* leave a gap at the end so we know when it's "full" but don't have to
56466 + compute the exact length of the string we're trying to append
56467 + */
56468 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56469 + spin_unlock(&gr_learn_lock);
56470 + wake_up_interruptible(&learn_wait);
56471 + return;
56472 + }
56473 + if (learn_buffer == NULL) {
56474 + spin_unlock(&gr_learn_lock);
56475 + return;
56476 + }
56477 +
56478 + va_start(args, fmt);
56479 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56480 + va_end(args);
56481 +
56482 + learn_buffer_len += len + 1;
56483 +
56484 + spin_unlock(&gr_learn_lock);
56485 + wake_up_interruptible(&learn_wait);
56486 +
56487 + return;
56488 +}
56489 +
56490 +static int
56491 +open_learn(struct inode *inode, struct file *file)
56492 +{
56493 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56494 + return -EBUSY;
56495 + if (file->f_mode & FMODE_READ) {
56496 + int retval = 0;
56497 + mutex_lock(&gr_learn_user_mutex);
56498 + if (learn_buffer == NULL)
56499 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56500 + if (learn_buffer_user == NULL)
56501 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56502 + if (learn_buffer == NULL) {
56503 + retval = -ENOMEM;
56504 + goto out_error;
56505 + }
56506 + if (learn_buffer_user == NULL) {
56507 + retval = -ENOMEM;
56508 + goto out_error;
56509 + }
56510 + learn_buffer_len = 0;
56511 + learn_buffer_user_len = 0;
56512 + gr_learn_attached = 1;
56513 +out_error:
56514 + mutex_unlock(&gr_learn_user_mutex);
56515 + return retval;
56516 + }
56517 + return 0;
56518 +}
56519 +
56520 +static int
56521 +close_learn(struct inode *inode, struct file *file)
56522 +{
56523 + if (file->f_mode & FMODE_READ) {
56524 + char *tmp = NULL;
56525 + mutex_lock(&gr_learn_user_mutex);
56526 + spin_lock(&gr_learn_lock);
56527 + tmp = learn_buffer;
56528 + learn_buffer = NULL;
56529 + spin_unlock(&gr_learn_lock);
56530 + if (tmp)
56531 + vfree(tmp);
56532 + if (learn_buffer_user != NULL) {
56533 + vfree(learn_buffer_user);
56534 + learn_buffer_user = NULL;
56535 + }
56536 + learn_buffer_len = 0;
56537 + learn_buffer_user_len = 0;
56538 + gr_learn_attached = 0;
56539 + mutex_unlock(&gr_learn_user_mutex);
56540 + }
56541 +
56542 + return 0;
56543 +}
56544 +
56545 +const struct file_operations grsec_fops = {
56546 + .read = read_learn,
56547 + .write = write_grsec_handler,
56548 + .open = open_learn,
56549 + .release = close_learn,
56550 + .poll = poll_learn,
56551 +};
56552 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56553 new file mode 100644
56554 index 0000000..39645c9
56555 --- /dev/null
56556 +++ b/grsecurity/gracl_res.c
56557 @@ -0,0 +1,68 @@
56558 +#include <linux/kernel.h>
56559 +#include <linux/sched.h>
56560 +#include <linux/gracl.h>
56561 +#include <linux/grinternal.h>
56562 +
56563 +static const char *restab_log[] = {
56564 + [RLIMIT_CPU] = "RLIMIT_CPU",
56565 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56566 + [RLIMIT_DATA] = "RLIMIT_DATA",
56567 + [RLIMIT_STACK] = "RLIMIT_STACK",
56568 + [RLIMIT_CORE] = "RLIMIT_CORE",
56569 + [RLIMIT_RSS] = "RLIMIT_RSS",
56570 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56571 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56572 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56573 + [RLIMIT_AS] = "RLIMIT_AS",
56574 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56575 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56576 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56577 + [RLIMIT_NICE] = "RLIMIT_NICE",
56578 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56579 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56580 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56581 +};
56582 +
56583 +void
56584 +gr_log_resource(const struct task_struct *task,
56585 + const int res, const unsigned long wanted, const int gt)
56586 +{
56587 + const struct cred *cred;
56588 + unsigned long rlim;
56589 +
56590 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56591 + return;
56592 +
56593 + // not yet supported resource
56594 + if (unlikely(!restab_log[res]))
56595 + return;
56596 +
56597 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56598 + rlim = task_rlimit_max(task, res);
56599 + else
56600 + rlim = task_rlimit(task, res);
56601 +
56602 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56603 + return;
56604 +
56605 + rcu_read_lock();
56606 + cred = __task_cred(task);
56607 +
56608 + if (res == RLIMIT_NPROC &&
56609 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56610 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56611 + goto out_rcu_unlock;
56612 + else if (res == RLIMIT_MEMLOCK &&
56613 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56614 + goto out_rcu_unlock;
56615 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56616 + goto out_rcu_unlock;
56617 + rcu_read_unlock();
56618 +
56619 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56620 +
56621 + return;
56622 +out_rcu_unlock:
56623 + rcu_read_unlock();
56624 + return;
56625 +}
56626 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56627 new file mode 100644
56628 index 0000000..25197e9
56629 --- /dev/null
56630 +++ b/grsecurity/gracl_segv.c
56631 @@ -0,0 +1,299 @@
56632 +#include <linux/kernel.h>
56633 +#include <linux/mm.h>
56634 +#include <asm/uaccess.h>
56635 +#include <asm/errno.h>
56636 +#include <asm/mman.h>
56637 +#include <net/sock.h>
56638 +#include <linux/file.h>
56639 +#include <linux/fs.h>
56640 +#include <linux/net.h>
56641 +#include <linux/in.h>
56642 +#include <linux/slab.h>
56643 +#include <linux/types.h>
56644 +#include <linux/sched.h>
56645 +#include <linux/timer.h>
56646 +#include <linux/gracl.h>
56647 +#include <linux/grsecurity.h>
56648 +#include <linux/grinternal.h>
56649 +
56650 +static struct crash_uid *uid_set;
56651 +static unsigned short uid_used;
56652 +static DEFINE_SPINLOCK(gr_uid_lock);
56653 +extern rwlock_t gr_inode_lock;
56654 +extern struct acl_subject_label *
56655 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56656 + struct acl_role_label *role);
56657 +
56658 +#ifdef CONFIG_BTRFS_FS
56659 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56660 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56661 +#endif
56662 +
56663 +static inline dev_t __get_dev(const struct dentry *dentry)
56664 +{
56665 +#ifdef CONFIG_BTRFS_FS
56666 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56667 + return get_btrfs_dev_from_inode(dentry->d_inode);
56668 + else
56669 +#endif
56670 + return dentry->d_inode->i_sb->s_dev;
56671 +}
56672 +
56673 +int
56674 +gr_init_uidset(void)
56675 +{
56676 + uid_set =
56677 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56678 + uid_used = 0;
56679 +
56680 + return uid_set ? 1 : 0;
56681 +}
56682 +
56683 +void
56684 +gr_free_uidset(void)
56685 +{
56686 + if (uid_set)
56687 + kfree(uid_set);
56688 +
56689 + return;
56690 +}
56691 +
56692 +int
56693 +gr_find_uid(const uid_t uid)
56694 +{
56695 + struct crash_uid *tmp = uid_set;
56696 + uid_t buid;
56697 + int low = 0, high = uid_used - 1, mid;
56698 +
56699 + while (high >= low) {
56700 + mid = (low + high) >> 1;
56701 + buid = tmp[mid].uid;
56702 + if (buid == uid)
56703 + return mid;
56704 + if (buid > uid)
56705 + high = mid - 1;
56706 + if (buid < uid)
56707 + low = mid + 1;
56708 + }
56709 +
56710 + return -1;
56711 +}
56712 +
56713 +static __inline__ void
56714 +gr_insertsort(void)
56715 +{
56716 + unsigned short i, j;
56717 + struct crash_uid index;
56718 +
56719 + for (i = 1; i < uid_used; i++) {
56720 + index = uid_set[i];
56721 + j = i;
56722 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56723 + uid_set[j] = uid_set[j - 1];
56724 + j--;
56725 + }
56726 + uid_set[j] = index;
56727 + }
56728 +
56729 + return;
56730 +}
56731 +
56732 +static __inline__ void
56733 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56734 +{
56735 + int loc;
56736 +
56737 + if (uid_used == GR_UIDTABLE_MAX)
56738 + return;
56739 +
56740 + loc = gr_find_uid(uid);
56741 +
56742 + if (loc >= 0) {
56743 + uid_set[loc].expires = expires;
56744 + return;
56745 + }
56746 +
56747 + uid_set[uid_used].uid = uid;
56748 + uid_set[uid_used].expires = expires;
56749 + uid_used++;
56750 +
56751 + gr_insertsort();
56752 +
56753 + return;
56754 +}
56755 +
56756 +void
56757 +gr_remove_uid(const unsigned short loc)
56758 +{
56759 + unsigned short i;
56760 +
56761 + for (i = loc + 1; i < uid_used; i++)
56762 + uid_set[i - 1] = uid_set[i];
56763 +
56764 + uid_used--;
56765 +
56766 + return;
56767 +}
56768 +
56769 +int
56770 +gr_check_crash_uid(const uid_t uid)
56771 +{
56772 + int loc;
56773 + int ret = 0;
56774 +
56775 + if (unlikely(!gr_acl_is_enabled()))
56776 + return 0;
56777 +
56778 + spin_lock(&gr_uid_lock);
56779 + loc = gr_find_uid(uid);
56780 +
56781 + if (loc < 0)
56782 + goto out_unlock;
56783 +
56784 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56785 + gr_remove_uid(loc);
56786 + else
56787 + ret = 1;
56788 +
56789 +out_unlock:
56790 + spin_unlock(&gr_uid_lock);
56791 + return ret;
56792 +}
56793 +
56794 +static __inline__ int
56795 +proc_is_setxid(const struct cred *cred)
56796 +{
56797 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56798 + !uid_eq(cred->uid, cred->fsuid))
56799 + return 1;
56800 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56801 + !uid_eq(cred->gid, cred->fsgid))
56802 + return 1;
56803 +
56804 + return 0;
56805 +}
56806 +
56807 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56808 +
56809 +void
56810 +gr_handle_crash(struct task_struct *task, const int sig)
56811 +{
56812 + struct acl_subject_label *curr;
56813 + struct task_struct *tsk, *tsk2;
56814 + const struct cred *cred;
56815 + const struct cred *cred2;
56816 +
56817 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56818 + return;
56819 +
56820 + if (unlikely(!gr_acl_is_enabled()))
56821 + return;
56822 +
56823 + curr = task->acl;
56824 +
56825 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56826 + return;
56827 +
56828 + if (time_before_eq(curr->expires, get_seconds())) {
56829 + curr->expires = 0;
56830 + curr->crashes = 0;
56831 + }
56832 +
56833 + curr->crashes++;
56834 +
56835 + if (!curr->expires)
56836 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56837 +
56838 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56839 + time_after(curr->expires, get_seconds())) {
56840 + rcu_read_lock();
56841 + cred = __task_cred(task);
56842 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56843 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56844 + spin_lock(&gr_uid_lock);
56845 + gr_insert_uid(cred->uid, curr->expires);
56846 + spin_unlock(&gr_uid_lock);
56847 + curr->expires = 0;
56848 + curr->crashes = 0;
56849 + read_lock(&tasklist_lock);
56850 + do_each_thread(tsk2, tsk) {
56851 + cred2 = __task_cred(tsk);
56852 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
56853 + gr_fake_force_sig(SIGKILL, tsk);
56854 + } while_each_thread(tsk2, tsk);
56855 + read_unlock(&tasklist_lock);
56856 + } else {
56857 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56858 + read_lock(&tasklist_lock);
56859 + read_lock(&grsec_exec_file_lock);
56860 + do_each_thread(tsk2, tsk) {
56861 + if (likely(tsk != task)) {
56862 + // if this thread has the same subject as the one that triggered
56863 + // RES_CRASH and it's the same binary, kill it
56864 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56865 + gr_fake_force_sig(SIGKILL, tsk);
56866 + }
56867 + } while_each_thread(tsk2, tsk);
56868 + read_unlock(&grsec_exec_file_lock);
56869 + read_unlock(&tasklist_lock);
56870 + }
56871 + rcu_read_unlock();
56872 + }
56873 +
56874 + return;
56875 +}
56876 +
56877 +int
56878 +gr_check_crash_exec(const struct file *filp)
56879 +{
56880 + struct acl_subject_label *curr;
56881 +
56882 + if (unlikely(!gr_acl_is_enabled()))
56883 + return 0;
56884 +
56885 + read_lock(&gr_inode_lock);
56886 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56887 + __get_dev(filp->f_path.dentry),
56888 + current->role);
56889 + read_unlock(&gr_inode_lock);
56890 +
56891 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56892 + (!curr->crashes && !curr->expires))
56893 + return 0;
56894 +
56895 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56896 + time_after(curr->expires, get_seconds()))
56897 + return 1;
56898 + else if (time_before_eq(curr->expires, get_seconds())) {
56899 + curr->crashes = 0;
56900 + curr->expires = 0;
56901 + }
56902 +
56903 + return 0;
56904 +}
56905 +
56906 +void
56907 +gr_handle_alertkill(struct task_struct *task)
56908 +{
56909 + struct acl_subject_label *curracl;
56910 + __u32 curr_ip;
56911 + struct task_struct *p, *p2;
56912 +
56913 + if (unlikely(!gr_acl_is_enabled()))
56914 + return;
56915 +
56916 + curracl = task->acl;
56917 + curr_ip = task->signal->curr_ip;
56918 +
56919 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56920 + read_lock(&tasklist_lock);
56921 + do_each_thread(p2, p) {
56922 + if (p->signal->curr_ip == curr_ip)
56923 + gr_fake_force_sig(SIGKILL, p);
56924 + } while_each_thread(p2, p);
56925 + read_unlock(&tasklist_lock);
56926 + } else if (curracl->mode & GR_KILLPROC)
56927 + gr_fake_force_sig(SIGKILL, task);
56928 +
56929 + return;
56930 +}
56931 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56932 new file mode 100644
56933 index 0000000..9d83a69
56934 --- /dev/null
56935 +++ b/grsecurity/gracl_shm.c
56936 @@ -0,0 +1,40 @@
56937 +#include <linux/kernel.h>
56938 +#include <linux/mm.h>
56939 +#include <linux/sched.h>
56940 +#include <linux/file.h>
56941 +#include <linux/ipc.h>
56942 +#include <linux/gracl.h>
56943 +#include <linux/grsecurity.h>
56944 +#include <linux/grinternal.h>
56945 +
56946 +int
56947 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56948 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56949 +{
56950 + struct task_struct *task;
56951 +
56952 + if (!gr_acl_is_enabled())
56953 + return 1;
56954 +
56955 + rcu_read_lock();
56956 + read_lock(&tasklist_lock);
56957 +
56958 + task = find_task_by_vpid(shm_cprid);
56959 +
56960 + if (unlikely(!task))
56961 + task = find_task_by_vpid(shm_lapid);
56962 +
56963 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56964 + (task->pid == shm_lapid)) &&
56965 + (task->acl->mode & GR_PROTSHM) &&
56966 + (task->acl != current->acl))) {
56967 + read_unlock(&tasklist_lock);
56968 + rcu_read_unlock();
56969 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56970 + return 0;
56971 + }
56972 + read_unlock(&tasklist_lock);
56973 + rcu_read_unlock();
56974 +
56975 + return 1;
56976 +}
56977 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56978 new file mode 100644
56979 index 0000000..bc0be01
56980 --- /dev/null
56981 +++ b/grsecurity/grsec_chdir.c
56982 @@ -0,0 +1,19 @@
56983 +#include <linux/kernel.h>
56984 +#include <linux/sched.h>
56985 +#include <linux/fs.h>
56986 +#include <linux/file.h>
56987 +#include <linux/grsecurity.h>
56988 +#include <linux/grinternal.h>
56989 +
56990 +void
56991 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56992 +{
56993 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56994 + if ((grsec_enable_chdir && grsec_enable_group &&
56995 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56996 + !grsec_enable_group)) {
56997 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56998 + }
56999 +#endif
57000 + return;
57001 +}
57002 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57003 new file mode 100644
57004 index 0000000..9807ee2
57005 --- /dev/null
57006 +++ b/grsecurity/grsec_chroot.c
57007 @@ -0,0 +1,368 @@
57008 +#include <linux/kernel.h>
57009 +#include <linux/module.h>
57010 +#include <linux/sched.h>
57011 +#include <linux/file.h>
57012 +#include <linux/fs.h>
57013 +#include <linux/mount.h>
57014 +#include <linux/types.h>
57015 +#include "../fs/mount.h"
57016 +#include <linux/grsecurity.h>
57017 +#include <linux/grinternal.h>
57018 +
57019 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57020 +{
57021 +#ifdef CONFIG_GRKERNSEC
57022 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57023 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57024 + task->gr_is_chrooted = 1;
57025 + else
57026 + task->gr_is_chrooted = 0;
57027 +
57028 + task->gr_chroot_dentry = path->dentry;
57029 +#endif
57030 + return;
57031 +}
57032 +
57033 +void gr_clear_chroot_entries(struct task_struct *task)
57034 +{
57035 +#ifdef CONFIG_GRKERNSEC
57036 + task->gr_is_chrooted = 0;
57037 + task->gr_chroot_dentry = NULL;
57038 +#endif
57039 + return;
57040 +}
57041 +
57042 +int
57043 +gr_handle_chroot_unix(const pid_t pid)
57044 +{
57045 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57046 + struct task_struct *p;
57047 +
57048 + if (unlikely(!grsec_enable_chroot_unix))
57049 + return 1;
57050 +
57051 + if (likely(!proc_is_chrooted(current)))
57052 + return 1;
57053 +
57054 + rcu_read_lock();
57055 + read_lock(&tasklist_lock);
57056 + p = find_task_by_vpid_unrestricted(pid);
57057 + if (unlikely(p && !have_same_root(current, p))) {
57058 + read_unlock(&tasklist_lock);
57059 + rcu_read_unlock();
57060 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57061 + return 0;
57062 + }
57063 + read_unlock(&tasklist_lock);
57064 + rcu_read_unlock();
57065 +#endif
57066 + return 1;
57067 +}
57068 +
57069 +int
57070 +gr_handle_chroot_nice(void)
57071 +{
57072 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57073 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57074 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57075 + return -EPERM;
57076 + }
57077 +#endif
57078 + return 0;
57079 +}
57080 +
57081 +int
57082 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57083 +{
57084 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57085 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57086 + && proc_is_chrooted(current)) {
57087 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57088 + return -EACCES;
57089 + }
57090 +#endif
57091 + return 0;
57092 +}
57093 +
57094 +int
57095 +gr_handle_chroot_rawio(const struct inode *inode)
57096 +{
57097 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57098 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57099 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57100 + return 1;
57101 +#endif
57102 + return 0;
57103 +}
57104 +
57105 +int
57106 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57107 +{
57108 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57109 + struct task_struct *p;
57110 + int ret = 0;
57111 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57112 + return ret;
57113 +
57114 + read_lock(&tasklist_lock);
57115 + do_each_pid_task(pid, type, p) {
57116 + if (!have_same_root(current, p)) {
57117 + ret = 1;
57118 + goto out;
57119 + }
57120 + } while_each_pid_task(pid, type, p);
57121 +out:
57122 + read_unlock(&tasklist_lock);
57123 + return ret;
57124 +#endif
57125 + return 0;
57126 +}
57127 +
57128 +int
57129 +gr_pid_is_chrooted(struct task_struct *p)
57130 +{
57131 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57132 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57133 + return 0;
57134 +
57135 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57136 + !have_same_root(current, p)) {
57137 + return 1;
57138 + }
57139 +#endif
57140 + return 0;
57141 +}
57142 +
57143 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57144 +
57145 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57146 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57147 +{
57148 + struct path path, currentroot;
57149 + int ret = 0;
57150 +
57151 + path.dentry = (struct dentry *)u_dentry;
57152 + path.mnt = (struct vfsmount *)u_mnt;
57153 + get_fs_root(current->fs, &currentroot);
57154 + if (path_is_under(&path, &currentroot))
57155 + ret = 1;
57156 + path_put(&currentroot);
57157 +
57158 + return ret;
57159 +}
57160 +#endif
57161 +
57162 +int
57163 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57164 +{
57165 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57166 + if (!grsec_enable_chroot_fchdir)
57167 + return 1;
57168 +
57169 + if (!proc_is_chrooted(current))
57170 + return 1;
57171 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57172 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57173 + return 0;
57174 + }
57175 +#endif
57176 + return 1;
57177 +}
57178 +
57179 +int
57180 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57181 + const time_t shm_createtime)
57182 +{
57183 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57184 + struct task_struct *p;
57185 + time_t starttime;
57186 +
57187 + if (unlikely(!grsec_enable_chroot_shmat))
57188 + return 1;
57189 +
57190 + if (likely(!proc_is_chrooted(current)))
57191 + return 1;
57192 +
57193 + rcu_read_lock();
57194 + read_lock(&tasklist_lock);
57195 +
57196 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57197 + starttime = p->start_time.tv_sec;
57198 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57199 + if (have_same_root(current, p)) {
57200 + goto allow;
57201 + } else {
57202 + read_unlock(&tasklist_lock);
57203 + rcu_read_unlock();
57204 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57205 + return 0;
57206 + }
57207 + }
57208 + /* creator exited, pid reuse, fall through to next check */
57209 + }
57210 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57211 + if (unlikely(!have_same_root(current, p))) {
57212 + read_unlock(&tasklist_lock);
57213 + rcu_read_unlock();
57214 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57215 + return 0;
57216 + }
57217 + }
57218 +
57219 +allow:
57220 + read_unlock(&tasklist_lock);
57221 + rcu_read_unlock();
57222 +#endif
57223 + return 1;
57224 +}
57225 +
57226 +void
57227 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57228 +{
57229 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57230 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57231 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57232 +#endif
57233 + return;
57234 +}
57235 +
57236 +int
57237 +gr_handle_chroot_mknod(const struct dentry *dentry,
57238 + const struct vfsmount *mnt, const int mode)
57239 +{
57240 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57241 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57242 + proc_is_chrooted(current)) {
57243 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57244 + return -EPERM;
57245 + }
57246 +#endif
57247 + return 0;
57248 +}
57249 +
57250 +int
57251 +gr_handle_chroot_mount(const struct dentry *dentry,
57252 + const struct vfsmount *mnt, const char *dev_name)
57253 +{
57254 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57255 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57256 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57257 + return -EPERM;
57258 + }
57259 +#endif
57260 + return 0;
57261 +}
57262 +
57263 +int
57264 +gr_handle_chroot_pivot(void)
57265 +{
57266 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57267 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57268 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57269 + return -EPERM;
57270 + }
57271 +#endif
57272 + return 0;
57273 +}
57274 +
57275 +int
57276 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57277 +{
57278 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57279 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57280 + !gr_is_outside_chroot(dentry, mnt)) {
57281 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57282 + return -EPERM;
57283 + }
57284 +#endif
57285 + return 0;
57286 +}
57287 +
57288 +extern const char *captab_log[];
57289 +extern int captab_log_entries;
57290 +
57291 +int
57292 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57293 +{
57294 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57295 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57296 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57297 + if (cap_raised(chroot_caps, cap)) {
57298 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57299 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57300 + }
57301 + return 0;
57302 + }
57303 + }
57304 +#endif
57305 + return 1;
57306 +}
57307 +
57308 +int
57309 +gr_chroot_is_capable(const int cap)
57310 +{
57311 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57312 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57313 +#endif
57314 + return 1;
57315 +}
57316 +
57317 +int
57318 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57319 +{
57320 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57321 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57322 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57323 + if (cap_raised(chroot_caps, cap)) {
57324 + return 0;
57325 + }
57326 + }
57327 +#endif
57328 + return 1;
57329 +}
57330 +
57331 +int
57332 +gr_chroot_is_capable_nolog(const int cap)
57333 +{
57334 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57335 + return gr_task_chroot_is_capable_nolog(current, cap);
57336 +#endif
57337 + return 1;
57338 +}
57339 +
57340 +int
57341 +gr_handle_chroot_sysctl(const int op)
57342 +{
57343 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57344 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57345 + proc_is_chrooted(current))
57346 + return -EACCES;
57347 +#endif
57348 + return 0;
57349 +}
57350 +
57351 +void
57352 +gr_handle_chroot_chdir(struct path *path)
57353 +{
57354 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57355 + if (grsec_enable_chroot_chdir)
57356 + set_fs_pwd(current->fs, path);
57357 +#endif
57358 + return;
57359 +}
57360 +
57361 +int
57362 +gr_handle_chroot_chmod(const struct dentry *dentry,
57363 + const struct vfsmount *mnt, const int mode)
57364 +{
57365 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57366 + /* allow chmod +s on directories, but not files */
57367 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57368 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57369 + proc_is_chrooted(current)) {
57370 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57371 + return -EPERM;
57372 + }
57373 +#endif
57374 + return 0;
57375 +}
57376 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57377 new file mode 100644
57378 index 0000000..213ad8b
57379 --- /dev/null
57380 +++ b/grsecurity/grsec_disabled.c
57381 @@ -0,0 +1,437 @@
57382 +#include <linux/kernel.h>
57383 +#include <linux/module.h>
57384 +#include <linux/sched.h>
57385 +#include <linux/file.h>
57386 +#include <linux/fs.h>
57387 +#include <linux/kdev_t.h>
57388 +#include <linux/net.h>
57389 +#include <linux/in.h>
57390 +#include <linux/ip.h>
57391 +#include <linux/skbuff.h>
57392 +#include <linux/sysctl.h>
57393 +
57394 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57395 +void
57396 +pax_set_initial_flags(struct linux_binprm *bprm)
57397 +{
57398 + return;
57399 +}
57400 +#endif
57401 +
57402 +#ifdef CONFIG_SYSCTL
57403 +__u32
57404 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57405 +{
57406 + return 0;
57407 +}
57408 +#endif
57409 +
57410 +#ifdef CONFIG_TASKSTATS
57411 +int gr_is_taskstats_denied(int pid)
57412 +{
57413 + return 0;
57414 +}
57415 +#endif
57416 +
57417 +int
57418 +gr_acl_is_enabled(void)
57419 +{
57420 + return 0;
57421 +}
57422 +
57423 +void
57424 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57425 +{
57426 + return;
57427 +}
57428 +
57429 +int
57430 +gr_handle_rawio(const struct inode *inode)
57431 +{
57432 + return 0;
57433 +}
57434 +
57435 +void
57436 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57437 +{
57438 + return;
57439 +}
57440 +
57441 +int
57442 +gr_handle_ptrace(struct task_struct *task, const long request)
57443 +{
57444 + return 0;
57445 +}
57446 +
57447 +int
57448 +gr_handle_proc_ptrace(struct task_struct *task)
57449 +{
57450 + return 0;
57451 +}
57452 +
57453 +void
57454 +gr_learn_resource(const struct task_struct *task,
57455 + const int res, const unsigned long wanted, const int gt)
57456 +{
57457 + return;
57458 +}
57459 +
57460 +int
57461 +gr_set_acls(const int type)
57462 +{
57463 + return 0;
57464 +}
57465 +
57466 +int
57467 +gr_check_hidden_task(const struct task_struct *tsk)
57468 +{
57469 + return 0;
57470 +}
57471 +
57472 +int
57473 +gr_check_protected_task(const struct task_struct *task)
57474 +{
57475 + return 0;
57476 +}
57477 +
57478 +int
57479 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57480 +{
57481 + return 0;
57482 +}
57483 +
57484 +void
57485 +gr_copy_label(struct task_struct *tsk)
57486 +{
57487 + return;
57488 +}
57489 +
57490 +void
57491 +gr_set_pax_flags(struct task_struct *task)
57492 +{
57493 + return;
57494 +}
57495 +
57496 +int
57497 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57498 + const int unsafe_share)
57499 +{
57500 + return 0;
57501 +}
57502 +
57503 +void
57504 +gr_handle_delete(const ino_t ino, const dev_t dev)
57505 +{
57506 + return;
57507 +}
57508 +
57509 +void
57510 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57511 +{
57512 + return;
57513 +}
57514 +
57515 +void
57516 +gr_handle_crash(struct task_struct *task, const int sig)
57517 +{
57518 + return;
57519 +}
57520 +
57521 +int
57522 +gr_check_crash_exec(const struct file *filp)
57523 +{
57524 + return 0;
57525 +}
57526 +
57527 +int
57528 +gr_check_crash_uid(const uid_t uid)
57529 +{
57530 + return 0;
57531 +}
57532 +
57533 +void
57534 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57535 + struct dentry *old_dentry,
57536 + struct dentry *new_dentry,
57537 + struct vfsmount *mnt, const __u8 replace)
57538 +{
57539 + return;
57540 +}
57541 +
57542 +int
57543 +gr_search_socket(const int family, const int type, const int protocol)
57544 +{
57545 + return 1;
57546 +}
57547 +
57548 +int
57549 +gr_search_connectbind(const int mode, const struct socket *sock,
57550 + const struct sockaddr_in *addr)
57551 +{
57552 + return 0;
57553 +}
57554 +
57555 +void
57556 +gr_handle_alertkill(struct task_struct *task)
57557 +{
57558 + return;
57559 +}
57560 +
57561 +__u32
57562 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57563 +{
57564 + return 1;
57565 +}
57566 +
57567 +__u32
57568 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57569 + const struct vfsmount * mnt)
57570 +{
57571 + return 1;
57572 +}
57573 +
57574 +__u32
57575 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57576 + int acc_mode)
57577 +{
57578 + return 1;
57579 +}
57580 +
57581 +__u32
57582 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57583 +{
57584 + return 1;
57585 +}
57586 +
57587 +__u32
57588 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57589 +{
57590 + return 1;
57591 +}
57592 +
57593 +int
57594 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57595 + unsigned int *vm_flags)
57596 +{
57597 + return 1;
57598 +}
57599 +
57600 +__u32
57601 +gr_acl_handle_truncate(const struct dentry * dentry,
57602 + const struct vfsmount * mnt)
57603 +{
57604 + return 1;
57605 +}
57606 +
57607 +__u32
57608 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57609 +{
57610 + return 1;
57611 +}
57612 +
57613 +__u32
57614 +gr_acl_handle_access(const struct dentry * dentry,
57615 + const struct vfsmount * mnt, const int fmode)
57616 +{
57617 + return 1;
57618 +}
57619 +
57620 +__u32
57621 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57622 + umode_t *mode)
57623 +{
57624 + return 1;
57625 +}
57626 +
57627 +__u32
57628 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57629 +{
57630 + return 1;
57631 +}
57632 +
57633 +__u32
57634 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57635 +{
57636 + return 1;
57637 +}
57638 +
57639 +void
57640 +grsecurity_init(void)
57641 +{
57642 + return;
57643 +}
57644 +
57645 +umode_t gr_acl_umask(void)
57646 +{
57647 + return 0;
57648 +}
57649 +
57650 +__u32
57651 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57652 + const struct dentry * parent_dentry,
57653 + const struct vfsmount * parent_mnt,
57654 + const int mode)
57655 +{
57656 + return 1;
57657 +}
57658 +
57659 +__u32
57660 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57661 + const struct dentry * parent_dentry,
57662 + const struct vfsmount * parent_mnt)
57663 +{
57664 + return 1;
57665 +}
57666 +
57667 +__u32
57668 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57669 + const struct dentry * parent_dentry,
57670 + const struct vfsmount * parent_mnt, const char *from)
57671 +{
57672 + return 1;
57673 +}
57674 +
57675 +__u32
57676 +gr_acl_handle_link(const struct dentry * new_dentry,
57677 + const struct dentry * parent_dentry,
57678 + const struct vfsmount * parent_mnt,
57679 + const struct dentry * old_dentry,
57680 + const struct vfsmount * old_mnt, const char *to)
57681 +{
57682 + return 1;
57683 +}
57684 +
57685 +int
57686 +gr_acl_handle_rename(const struct dentry *new_dentry,
57687 + const struct dentry *parent_dentry,
57688 + const struct vfsmount *parent_mnt,
57689 + const struct dentry *old_dentry,
57690 + const struct inode *old_parent_inode,
57691 + const struct vfsmount *old_mnt, const char *newname)
57692 +{
57693 + return 0;
57694 +}
57695 +
57696 +int
57697 +gr_acl_handle_filldir(const struct file *file, const char *name,
57698 + const int namelen, const ino_t ino)
57699 +{
57700 + return 1;
57701 +}
57702 +
57703 +int
57704 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57705 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57706 +{
57707 + return 1;
57708 +}
57709 +
57710 +int
57711 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57712 +{
57713 + return 0;
57714 +}
57715 +
57716 +int
57717 +gr_search_accept(const struct socket *sock)
57718 +{
57719 + return 0;
57720 +}
57721 +
57722 +int
57723 +gr_search_listen(const struct socket *sock)
57724 +{
57725 + return 0;
57726 +}
57727 +
57728 +int
57729 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57730 +{
57731 + return 0;
57732 +}
57733 +
57734 +__u32
57735 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57736 +{
57737 + return 1;
57738 +}
57739 +
57740 +__u32
57741 +gr_acl_handle_creat(const struct dentry * dentry,
57742 + const struct dentry * p_dentry,
57743 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57744 + const int imode)
57745 +{
57746 + return 1;
57747 +}
57748 +
57749 +void
57750 +gr_acl_handle_exit(void)
57751 +{
57752 + return;
57753 +}
57754 +
57755 +int
57756 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57757 +{
57758 + return 1;
57759 +}
57760 +
57761 +void
57762 +gr_set_role_label(const uid_t uid, const gid_t gid)
57763 +{
57764 + return;
57765 +}
57766 +
57767 +int
57768 +gr_acl_handle_procpidmem(const struct task_struct *task)
57769 +{
57770 + return 0;
57771 +}
57772 +
57773 +int
57774 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57775 +{
57776 + return 0;
57777 +}
57778 +
57779 +int
57780 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57781 +{
57782 + return 0;
57783 +}
57784 +
57785 +void
57786 +gr_set_kernel_label(struct task_struct *task)
57787 +{
57788 + return;
57789 +}
57790 +
57791 +int
57792 +gr_check_user_change(int real, int effective, int fs)
57793 +{
57794 + return 0;
57795 +}
57796 +
57797 +int
57798 +gr_check_group_change(int real, int effective, int fs)
57799 +{
57800 + return 0;
57801 +}
57802 +
57803 +int gr_acl_enable_at_secure(void)
57804 +{
57805 + return 0;
57806 +}
57807 +
57808 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57809 +{
57810 + return dentry->d_inode->i_sb->s_dev;
57811 +}
57812 +
57813 +EXPORT_SYMBOL(gr_learn_resource);
57814 +EXPORT_SYMBOL(gr_set_kernel_label);
57815 +#ifdef CONFIG_SECURITY
57816 +EXPORT_SYMBOL(gr_check_user_change);
57817 +EXPORT_SYMBOL(gr_check_group_change);
57818 +#endif
57819 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57820 new file mode 100644
57821 index 0000000..abfa971
57822 --- /dev/null
57823 +++ b/grsecurity/grsec_exec.c
57824 @@ -0,0 +1,174 @@
57825 +#include <linux/kernel.h>
57826 +#include <linux/sched.h>
57827 +#include <linux/file.h>
57828 +#include <linux/binfmts.h>
57829 +#include <linux/fs.h>
57830 +#include <linux/types.h>
57831 +#include <linux/grdefs.h>
57832 +#include <linux/grsecurity.h>
57833 +#include <linux/grinternal.h>
57834 +#include <linux/capability.h>
57835 +#include <linux/module.h>
57836 +
57837 +#include <asm/uaccess.h>
57838 +
57839 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57840 +static char gr_exec_arg_buf[132];
57841 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57842 +#endif
57843 +
57844 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57845 +
57846 +void
57847 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57848 +{
57849 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57850 + char *grarg = gr_exec_arg_buf;
57851 + unsigned int i, x, execlen = 0;
57852 + char c;
57853 +
57854 + if (!((grsec_enable_execlog && grsec_enable_group &&
57855 + in_group_p(grsec_audit_gid))
57856 + || (grsec_enable_execlog && !grsec_enable_group)))
57857 + return;
57858 +
57859 + mutex_lock(&gr_exec_arg_mutex);
57860 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57861 +
57862 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57863 + const char __user *p;
57864 + unsigned int len;
57865 +
57866 + p = get_user_arg_ptr(argv, i);
57867 + if (IS_ERR(p))
57868 + goto log;
57869 +
57870 + len = strnlen_user(p, 128 - execlen);
57871 + if (len > 128 - execlen)
57872 + len = 128 - execlen;
57873 + else if (len > 0)
57874 + len--;
57875 + if (copy_from_user(grarg + execlen, p, len))
57876 + goto log;
57877 +
57878 + /* rewrite unprintable characters */
57879 + for (x = 0; x < len; x++) {
57880 + c = *(grarg + execlen + x);
57881 + if (c < 32 || c > 126)
57882 + *(grarg + execlen + x) = ' ';
57883 + }
57884 +
57885 + execlen += len;
57886 + *(grarg + execlen) = ' ';
57887 + *(grarg + execlen + 1) = '\0';
57888 + execlen++;
57889 + }
57890 +
57891 + log:
57892 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57893 + bprm->file->f_path.mnt, grarg);
57894 + mutex_unlock(&gr_exec_arg_mutex);
57895 +#endif
57896 + return;
57897 +}
57898 +
57899 +#ifdef CONFIG_GRKERNSEC
57900 +extern int gr_acl_is_capable(const int cap);
57901 +extern int gr_acl_is_capable_nolog(const int cap);
57902 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57903 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57904 +extern int gr_chroot_is_capable(const int cap);
57905 +extern int gr_chroot_is_capable_nolog(const int cap);
57906 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57907 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57908 +#endif
57909 +
57910 +const char *captab_log[] = {
57911 + "CAP_CHOWN",
57912 + "CAP_DAC_OVERRIDE",
57913 + "CAP_DAC_READ_SEARCH",
57914 + "CAP_FOWNER",
57915 + "CAP_FSETID",
57916 + "CAP_KILL",
57917 + "CAP_SETGID",
57918 + "CAP_SETUID",
57919 + "CAP_SETPCAP",
57920 + "CAP_LINUX_IMMUTABLE",
57921 + "CAP_NET_BIND_SERVICE",
57922 + "CAP_NET_BROADCAST",
57923 + "CAP_NET_ADMIN",
57924 + "CAP_NET_RAW",
57925 + "CAP_IPC_LOCK",
57926 + "CAP_IPC_OWNER",
57927 + "CAP_SYS_MODULE",
57928 + "CAP_SYS_RAWIO",
57929 + "CAP_SYS_CHROOT",
57930 + "CAP_SYS_PTRACE",
57931 + "CAP_SYS_PACCT",
57932 + "CAP_SYS_ADMIN",
57933 + "CAP_SYS_BOOT",
57934 + "CAP_SYS_NICE",
57935 + "CAP_SYS_RESOURCE",
57936 + "CAP_SYS_TIME",
57937 + "CAP_SYS_TTY_CONFIG",
57938 + "CAP_MKNOD",
57939 + "CAP_LEASE",
57940 + "CAP_AUDIT_WRITE",
57941 + "CAP_AUDIT_CONTROL",
57942 + "CAP_SETFCAP",
57943 + "CAP_MAC_OVERRIDE",
57944 + "CAP_MAC_ADMIN",
57945 + "CAP_SYSLOG",
57946 + "CAP_WAKE_ALARM"
57947 +};
57948 +
57949 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57950 +
57951 +int gr_is_capable(const int cap)
57952 +{
57953 +#ifdef CONFIG_GRKERNSEC
57954 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57955 + return 1;
57956 + return 0;
57957 +#else
57958 + return 1;
57959 +#endif
57960 +}
57961 +
57962 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57963 +{
57964 +#ifdef CONFIG_GRKERNSEC
57965 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57966 + return 1;
57967 + return 0;
57968 +#else
57969 + return 1;
57970 +#endif
57971 +}
57972 +
57973 +int gr_is_capable_nolog(const int cap)
57974 +{
57975 +#ifdef CONFIG_GRKERNSEC
57976 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57977 + return 1;
57978 + return 0;
57979 +#else
57980 + return 1;
57981 +#endif
57982 +}
57983 +
57984 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57985 +{
57986 +#ifdef CONFIG_GRKERNSEC
57987 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57988 + return 1;
57989 + return 0;
57990 +#else
57991 + return 1;
57992 +#endif
57993 +}
57994 +
57995 +EXPORT_SYMBOL(gr_is_capable);
57996 +EXPORT_SYMBOL(gr_is_capable_nolog);
57997 +EXPORT_SYMBOL(gr_task_is_capable);
57998 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57999 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58000 new file mode 100644
58001 index 0000000..d3ee748
58002 --- /dev/null
58003 +++ b/grsecurity/grsec_fifo.c
58004 @@ -0,0 +1,24 @@
58005 +#include <linux/kernel.h>
58006 +#include <linux/sched.h>
58007 +#include <linux/fs.h>
58008 +#include <linux/file.h>
58009 +#include <linux/grinternal.h>
58010 +
58011 +int
58012 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58013 + const struct dentry *dir, const int flag, const int acc_mode)
58014 +{
58015 +#ifdef CONFIG_GRKERNSEC_FIFO
58016 + const struct cred *cred = current_cred();
58017 +
58018 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58019 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58020 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58021 + (cred->fsuid != dentry->d_inode->i_uid)) {
58022 + if (!inode_permission(dentry->d_inode, acc_mode))
58023 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58024 + return -EACCES;
58025 + }
58026 +#endif
58027 + return 0;
58028 +}
58029 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58030 new file mode 100644
58031 index 0000000..8ca18bf
58032 --- /dev/null
58033 +++ b/grsecurity/grsec_fork.c
58034 @@ -0,0 +1,23 @@
58035 +#include <linux/kernel.h>
58036 +#include <linux/sched.h>
58037 +#include <linux/grsecurity.h>
58038 +#include <linux/grinternal.h>
58039 +#include <linux/errno.h>
58040 +
58041 +void
58042 +gr_log_forkfail(const int retval)
58043 +{
58044 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58045 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58046 + switch (retval) {
58047 + case -EAGAIN:
58048 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58049 + break;
58050 + case -ENOMEM:
58051 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58052 + break;
58053 + }
58054 + }
58055 +#endif
58056 + return;
58057 +}
58058 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58059 new file mode 100644
58060 index 0000000..05a6015
58061 --- /dev/null
58062 +++ b/grsecurity/grsec_init.c
58063 @@ -0,0 +1,283 @@
58064 +#include <linux/kernel.h>
58065 +#include <linux/sched.h>
58066 +#include <linux/mm.h>
58067 +#include <linux/gracl.h>
58068 +#include <linux/slab.h>
58069 +#include <linux/vmalloc.h>
58070 +#include <linux/percpu.h>
58071 +#include <linux/module.h>
58072 +
58073 +int grsec_enable_ptrace_readexec;
58074 +int grsec_enable_setxid;
58075 +int grsec_enable_symlinkown;
58076 +int grsec_symlinkown_gid;
58077 +int grsec_enable_brute;
58078 +int grsec_enable_link;
58079 +int grsec_enable_dmesg;
58080 +int grsec_enable_harden_ptrace;
58081 +int grsec_enable_fifo;
58082 +int grsec_enable_execlog;
58083 +int grsec_enable_signal;
58084 +int grsec_enable_forkfail;
58085 +int grsec_enable_audit_ptrace;
58086 +int grsec_enable_time;
58087 +int grsec_enable_audit_textrel;
58088 +int grsec_enable_group;
58089 +int grsec_audit_gid;
58090 +int grsec_enable_chdir;
58091 +int grsec_enable_mount;
58092 +int grsec_enable_rofs;
58093 +int grsec_enable_chroot_findtask;
58094 +int grsec_enable_chroot_mount;
58095 +int grsec_enable_chroot_shmat;
58096 +int grsec_enable_chroot_fchdir;
58097 +int grsec_enable_chroot_double;
58098 +int grsec_enable_chroot_pivot;
58099 +int grsec_enable_chroot_chdir;
58100 +int grsec_enable_chroot_chmod;
58101 +int grsec_enable_chroot_mknod;
58102 +int grsec_enable_chroot_nice;
58103 +int grsec_enable_chroot_execlog;
58104 +int grsec_enable_chroot_caps;
58105 +int grsec_enable_chroot_sysctl;
58106 +int grsec_enable_chroot_unix;
58107 +int grsec_enable_tpe;
58108 +int grsec_tpe_gid;
58109 +int grsec_enable_blackhole;
58110 +#ifdef CONFIG_IPV6_MODULE
58111 +EXPORT_SYMBOL(grsec_enable_blackhole);
58112 +#endif
58113 +int grsec_lastack_retries;
58114 +int grsec_enable_tpe_all;
58115 +int grsec_enable_tpe_invert;
58116 +int grsec_enable_socket_all;
58117 +int grsec_socket_all_gid;
58118 +int grsec_enable_socket_client;
58119 +int grsec_socket_client_gid;
58120 +int grsec_enable_socket_server;
58121 +int grsec_socket_server_gid;
58122 +int grsec_resource_logging;
58123 +int grsec_disable_privio;
58124 +int grsec_enable_log_rwxmaps;
58125 +int grsec_lock;
58126 +
58127 +DEFINE_SPINLOCK(grsec_alert_lock);
58128 +unsigned long grsec_alert_wtime = 0;
58129 +unsigned long grsec_alert_fyet = 0;
58130 +
58131 +DEFINE_SPINLOCK(grsec_audit_lock);
58132 +
58133 +DEFINE_RWLOCK(grsec_exec_file_lock);
58134 +
58135 +char *gr_shared_page[4];
58136 +
58137 +char *gr_alert_log_fmt;
58138 +char *gr_audit_log_fmt;
58139 +char *gr_alert_log_buf;
58140 +char *gr_audit_log_buf;
58141 +
58142 +extern struct gr_arg *gr_usermode;
58143 +extern unsigned char *gr_system_salt;
58144 +extern unsigned char *gr_system_sum;
58145 +
58146 +void __init
58147 +grsecurity_init(void)
58148 +{
58149 + int j;
58150 + /* create the per-cpu shared pages */
58151 +
58152 +#ifdef CONFIG_X86
58153 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58154 +#endif
58155 +
58156 + for (j = 0; j < 4; j++) {
58157 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58158 + if (gr_shared_page[j] == NULL) {
58159 + panic("Unable to allocate grsecurity shared page");
58160 + return;
58161 + }
58162 + }
58163 +
58164 + /* allocate log buffers */
58165 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58166 + if (!gr_alert_log_fmt) {
58167 + panic("Unable to allocate grsecurity alert log format buffer");
58168 + return;
58169 + }
58170 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58171 + if (!gr_audit_log_fmt) {
58172 + panic("Unable to allocate grsecurity audit log format buffer");
58173 + return;
58174 + }
58175 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58176 + if (!gr_alert_log_buf) {
58177 + panic("Unable to allocate grsecurity alert log buffer");
58178 + return;
58179 + }
58180 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58181 + if (!gr_audit_log_buf) {
58182 + panic("Unable to allocate grsecurity audit log buffer");
58183 + return;
58184 + }
58185 +
58186 + /* allocate memory for authentication structure */
58187 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58188 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58189 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58190 +
58191 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58192 + panic("Unable to allocate grsecurity authentication structure");
58193 + return;
58194 + }
58195 +
58196 +
58197 +#ifdef CONFIG_GRKERNSEC_IO
58198 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58199 + grsec_disable_privio = 1;
58200 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58201 + grsec_disable_privio = 1;
58202 +#else
58203 + grsec_disable_privio = 0;
58204 +#endif
58205 +#endif
58206 +
58207 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58208 + /* for backward compatibility, tpe_invert always defaults to on if
58209 + enabled in the kernel
58210 + */
58211 + grsec_enable_tpe_invert = 1;
58212 +#endif
58213 +
58214 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58215 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58216 + grsec_lock = 1;
58217 +#endif
58218 +
58219 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58220 + grsec_enable_audit_textrel = 1;
58221 +#endif
58222 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58223 + grsec_enable_log_rwxmaps = 1;
58224 +#endif
58225 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58226 + grsec_enable_group = 1;
58227 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58228 +#endif
58229 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58230 + grsec_enable_ptrace_readexec = 1;
58231 +#endif
58232 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58233 + grsec_enable_chdir = 1;
58234 +#endif
58235 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58236 + grsec_enable_harden_ptrace = 1;
58237 +#endif
58238 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58239 + grsec_enable_mount = 1;
58240 +#endif
58241 +#ifdef CONFIG_GRKERNSEC_LINK
58242 + grsec_enable_link = 1;
58243 +#endif
58244 +#ifdef CONFIG_GRKERNSEC_BRUTE
58245 + grsec_enable_brute = 1;
58246 +#endif
58247 +#ifdef CONFIG_GRKERNSEC_DMESG
58248 + grsec_enable_dmesg = 1;
58249 +#endif
58250 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58251 + grsec_enable_blackhole = 1;
58252 + grsec_lastack_retries = 4;
58253 +#endif
58254 +#ifdef CONFIG_GRKERNSEC_FIFO
58255 + grsec_enable_fifo = 1;
58256 +#endif
58257 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58258 + grsec_enable_execlog = 1;
58259 +#endif
58260 +#ifdef CONFIG_GRKERNSEC_SETXID
58261 + grsec_enable_setxid = 1;
58262 +#endif
58263 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58264 + grsec_enable_signal = 1;
58265 +#endif
58266 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58267 + grsec_enable_forkfail = 1;
58268 +#endif
58269 +#ifdef CONFIG_GRKERNSEC_TIME
58270 + grsec_enable_time = 1;
58271 +#endif
58272 +#ifdef CONFIG_GRKERNSEC_RESLOG
58273 + grsec_resource_logging = 1;
58274 +#endif
58275 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58276 + grsec_enable_chroot_findtask = 1;
58277 +#endif
58278 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58279 + grsec_enable_chroot_unix = 1;
58280 +#endif
58281 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58282 + grsec_enable_chroot_mount = 1;
58283 +#endif
58284 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58285 + grsec_enable_chroot_fchdir = 1;
58286 +#endif
58287 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58288 + grsec_enable_chroot_shmat = 1;
58289 +#endif
58290 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58291 + grsec_enable_audit_ptrace = 1;
58292 +#endif
58293 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58294 + grsec_enable_chroot_double = 1;
58295 +#endif
58296 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58297 + grsec_enable_chroot_pivot = 1;
58298 +#endif
58299 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58300 + grsec_enable_chroot_chdir = 1;
58301 +#endif
58302 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58303 + grsec_enable_chroot_chmod = 1;
58304 +#endif
58305 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58306 + grsec_enable_chroot_mknod = 1;
58307 +#endif
58308 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58309 + grsec_enable_chroot_nice = 1;
58310 +#endif
58311 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58312 + grsec_enable_chroot_execlog = 1;
58313 +#endif
58314 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58315 + grsec_enable_chroot_caps = 1;
58316 +#endif
58317 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58318 + grsec_enable_chroot_sysctl = 1;
58319 +#endif
58320 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58321 + grsec_enable_symlinkown = 1;
58322 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58323 +#endif
58324 +#ifdef CONFIG_GRKERNSEC_TPE
58325 + grsec_enable_tpe = 1;
58326 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58327 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58328 + grsec_enable_tpe_all = 1;
58329 +#endif
58330 +#endif
58331 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58332 + grsec_enable_socket_all = 1;
58333 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58334 +#endif
58335 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58336 + grsec_enable_socket_client = 1;
58337 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58338 +#endif
58339 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58340 + grsec_enable_socket_server = 1;
58341 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58342 +#endif
58343 +#endif
58344 +
58345 + return;
58346 +}
58347 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58348 new file mode 100644
58349 index 0000000..589481f
58350 --- /dev/null
58351 +++ b/grsecurity/grsec_link.c
58352 @@ -0,0 +1,58 @@
58353 +#include <linux/kernel.h>
58354 +#include <linux/sched.h>
58355 +#include <linux/fs.h>
58356 +#include <linux/file.h>
58357 +#include <linux/grinternal.h>
58358 +
58359 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58360 +{
58361 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58362 + const struct inode *link_inode = link->dentry->d_inode;
58363 +
58364 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58365 + /* ignore root-owned links, e.g. /proc/self */
58366 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58367 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58368 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58369 + return 1;
58370 + }
58371 +#endif
58372 + return 0;
58373 +}
58374 +
58375 +int
58376 +gr_handle_follow_link(const struct inode *parent,
58377 + const struct inode *inode,
58378 + const struct dentry *dentry, const struct vfsmount *mnt)
58379 +{
58380 +#ifdef CONFIG_GRKERNSEC_LINK
58381 + const struct cred *cred = current_cred();
58382 +
58383 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58384 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58385 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58386 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58387 + return -EACCES;
58388 + }
58389 +#endif
58390 + return 0;
58391 +}
58392 +
58393 +int
58394 +gr_handle_hardlink(const struct dentry *dentry,
58395 + const struct vfsmount *mnt,
58396 + struct inode *inode, const int mode, const char *to)
58397 +{
58398 +#ifdef CONFIG_GRKERNSEC_LINK
58399 + const struct cred *cred = current_cred();
58400 +
58401 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58402 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58403 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58404 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58405 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58406 + return -EPERM;
58407 + }
58408 +#endif
58409 + return 0;
58410 +}
58411 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58412 new file mode 100644
58413 index 0000000..a45d2e9
58414 --- /dev/null
58415 +++ b/grsecurity/grsec_log.c
58416 @@ -0,0 +1,322 @@
58417 +#include <linux/kernel.h>
58418 +#include <linux/sched.h>
58419 +#include <linux/file.h>
58420 +#include <linux/tty.h>
58421 +#include <linux/fs.h>
58422 +#include <linux/grinternal.h>
58423 +
58424 +#ifdef CONFIG_TREE_PREEMPT_RCU
58425 +#define DISABLE_PREEMPT() preempt_disable()
58426 +#define ENABLE_PREEMPT() preempt_enable()
58427 +#else
58428 +#define DISABLE_PREEMPT()
58429 +#define ENABLE_PREEMPT()
58430 +#endif
58431 +
58432 +#define BEGIN_LOCKS(x) \
58433 + DISABLE_PREEMPT(); \
58434 + rcu_read_lock(); \
58435 + read_lock(&tasklist_lock); \
58436 + read_lock(&grsec_exec_file_lock); \
58437 + if (x != GR_DO_AUDIT) \
58438 + spin_lock(&grsec_alert_lock); \
58439 + else \
58440 + spin_lock(&grsec_audit_lock)
58441 +
58442 +#define END_LOCKS(x) \
58443 + if (x != GR_DO_AUDIT) \
58444 + spin_unlock(&grsec_alert_lock); \
58445 + else \
58446 + spin_unlock(&grsec_audit_lock); \
58447 + read_unlock(&grsec_exec_file_lock); \
58448 + read_unlock(&tasklist_lock); \
58449 + rcu_read_unlock(); \
58450 + ENABLE_PREEMPT(); \
58451 + if (x == GR_DONT_AUDIT) \
58452 + gr_handle_alertkill(current)
58453 +
58454 +enum {
58455 + FLOODING,
58456 + NO_FLOODING
58457 +};
58458 +
58459 +extern char *gr_alert_log_fmt;
58460 +extern char *gr_audit_log_fmt;
58461 +extern char *gr_alert_log_buf;
58462 +extern char *gr_audit_log_buf;
58463 +
58464 +static int gr_log_start(int audit)
58465 +{
58466 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58467 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58468 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58469 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58470 + unsigned long curr_secs = get_seconds();
58471 +
58472 + if (audit == GR_DO_AUDIT)
58473 + goto set_fmt;
58474 +
58475 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58476 + grsec_alert_wtime = curr_secs;
58477 + grsec_alert_fyet = 0;
58478 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58479 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58480 + grsec_alert_fyet++;
58481 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58482 + grsec_alert_wtime = curr_secs;
58483 + grsec_alert_fyet++;
58484 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58485 + return FLOODING;
58486 + }
58487 + else return FLOODING;
58488 +
58489 +set_fmt:
58490 +#endif
58491 + memset(buf, 0, PAGE_SIZE);
58492 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58493 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58494 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58495 + } else if (current->signal->curr_ip) {
58496 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58497 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58498 + } else if (gr_acl_is_enabled()) {
58499 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58500 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58501 + } else {
58502 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58503 + strcpy(buf, fmt);
58504 + }
58505 +
58506 + return NO_FLOODING;
58507 +}
58508 +
58509 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58510 + __attribute__ ((format (printf, 2, 0)));
58511 +
58512 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58513 +{
58514 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58515 + unsigned int len = strlen(buf);
58516 +
58517 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58518 +
58519 + return;
58520 +}
58521 +
58522 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58523 + __attribute__ ((format (printf, 2, 3)));
58524 +
58525 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58526 +{
58527 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58528 + unsigned int len = strlen(buf);
58529 + va_list ap;
58530 +
58531 + va_start(ap, msg);
58532 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58533 + va_end(ap);
58534 +
58535 + return;
58536 +}
58537 +
58538 +static void gr_log_end(int audit, int append_default)
58539 +{
58540 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58541 +
58542 + if (append_default) {
58543 + unsigned int len = strlen(buf);
58544 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58545 + }
58546 +
58547 + printk("%s\n", buf);
58548 +
58549 + return;
58550 +}
58551 +
58552 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58553 +{
58554 + int logtype;
58555 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58556 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58557 + void *voidptr = NULL;
58558 + int num1 = 0, num2 = 0;
58559 + unsigned long ulong1 = 0, ulong2 = 0;
58560 + struct dentry *dentry = NULL;
58561 + struct vfsmount *mnt = NULL;
58562 + struct file *file = NULL;
58563 + struct task_struct *task = NULL;
58564 + const struct cred *cred, *pcred;
58565 + va_list ap;
58566 +
58567 + BEGIN_LOCKS(audit);
58568 + logtype = gr_log_start(audit);
58569 + if (logtype == FLOODING) {
58570 + END_LOCKS(audit);
58571 + return;
58572 + }
58573 + va_start(ap, argtypes);
58574 + switch (argtypes) {
58575 + case GR_TTYSNIFF:
58576 + task = va_arg(ap, struct task_struct *);
58577 + 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);
58578 + break;
58579 + case GR_SYSCTL_HIDDEN:
58580 + str1 = va_arg(ap, char *);
58581 + gr_log_middle_varargs(audit, msg, result, str1);
58582 + break;
58583 + case GR_RBAC:
58584 + dentry = va_arg(ap, struct dentry *);
58585 + mnt = va_arg(ap, struct vfsmount *);
58586 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58587 + break;
58588 + case GR_RBAC_STR:
58589 + dentry = va_arg(ap, struct dentry *);
58590 + mnt = va_arg(ap, struct vfsmount *);
58591 + str1 = va_arg(ap, char *);
58592 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58593 + break;
58594 + case GR_STR_RBAC:
58595 + str1 = va_arg(ap, char *);
58596 + dentry = va_arg(ap, struct dentry *);
58597 + mnt = va_arg(ap, struct vfsmount *);
58598 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58599 + break;
58600 + case GR_RBAC_MODE2:
58601 + dentry = va_arg(ap, struct dentry *);
58602 + mnt = va_arg(ap, struct vfsmount *);
58603 + str1 = va_arg(ap, char *);
58604 + str2 = va_arg(ap, char *);
58605 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58606 + break;
58607 + case GR_RBAC_MODE3:
58608 + dentry = va_arg(ap, struct dentry *);
58609 + mnt = va_arg(ap, struct vfsmount *);
58610 + str1 = va_arg(ap, char *);
58611 + str2 = va_arg(ap, char *);
58612 + str3 = va_arg(ap, char *);
58613 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58614 + break;
58615 + case GR_FILENAME:
58616 + dentry = va_arg(ap, struct dentry *);
58617 + mnt = va_arg(ap, struct vfsmount *);
58618 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58619 + break;
58620 + case GR_STR_FILENAME:
58621 + str1 = va_arg(ap, char *);
58622 + dentry = va_arg(ap, struct dentry *);
58623 + mnt = va_arg(ap, struct vfsmount *);
58624 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58625 + break;
58626 + case GR_FILENAME_STR:
58627 + dentry = va_arg(ap, struct dentry *);
58628 + mnt = va_arg(ap, struct vfsmount *);
58629 + str1 = va_arg(ap, char *);
58630 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58631 + break;
58632 + case GR_FILENAME_TWO_INT:
58633 + dentry = va_arg(ap, struct dentry *);
58634 + mnt = va_arg(ap, struct vfsmount *);
58635 + num1 = va_arg(ap, int);
58636 + num2 = va_arg(ap, int);
58637 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58638 + break;
58639 + case GR_FILENAME_TWO_INT_STR:
58640 + dentry = va_arg(ap, struct dentry *);
58641 + mnt = va_arg(ap, struct vfsmount *);
58642 + num1 = va_arg(ap, int);
58643 + num2 = va_arg(ap, int);
58644 + str1 = va_arg(ap, char *);
58645 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58646 + break;
58647 + case GR_TEXTREL:
58648 + file = va_arg(ap, struct file *);
58649 + ulong1 = va_arg(ap, unsigned long);
58650 + ulong2 = va_arg(ap, unsigned long);
58651 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58652 + break;
58653 + case GR_PTRACE:
58654 + task = va_arg(ap, struct task_struct *);
58655 + 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);
58656 + break;
58657 + case GR_RESOURCE:
58658 + task = va_arg(ap, struct task_struct *);
58659 + cred = __task_cred(task);
58660 + pcred = __task_cred(task->real_parent);
58661 + ulong1 = va_arg(ap, unsigned long);
58662 + str1 = va_arg(ap, char *);
58663 + ulong2 = va_arg(ap, unsigned long);
58664 + 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);
58665 + break;
58666 + case GR_CAP:
58667 + task = va_arg(ap, struct task_struct *);
58668 + cred = __task_cred(task);
58669 + pcred = __task_cred(task->real_parent);
58670 + str1 = va_arg(ap, char *);
58671 + 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);
58672 + break;
58673 + case GR_SIG:
58674 + str1 = va_arg(ap, char *);
58675 + voidptr = va_arg(ap, void *);
58676 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58677 + break;
58678 + case GR_SIG2:
58679 + task = va_arg(ap, struct task_struct *);
58680 + cred = __task_cred(task);
58681 + pcred = __task_cred(task->real_parent);
58682 + num1 = va_arg(ap, int);
58683 + 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);
58684 + break;
58685 + case GR_CRASH1:
58686 + task = va_arg(ap, struct task_struct *);
58687 + cred = __task_cred(task);
58688 + pcred = __task_cred(task->real_parent);
58689 + ulong1 = va_arg(ap, unsigned long);
58690 + 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);
58691 + break;
58692 + case GR_CRASH2:
58693 + task = va_arg(ap, struct task_struct *);
58694 + cred = __task_cred(task);
58695 + pcred = __task_cred(task->real_parent);
58696 + ulong1 = va_arg(ap, unsigned long);
58697 + 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);
58698 + break;
58699 + case GR_RWXMAP:
58700 + file = va_arg(ap, struct file *);
58701 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58702 + break;
58703 + case GR_PSACCT:
58704 + {
58705 + unsigned int wday, cday;
58706 + __u8 whr, chr;
58707 + __u8 wmin, cmin;
58708 + __u8 wsec, csec;
58709 + char cur_tty[64] = { 0 };
58710 + char parent_tty[64] = { 0 };
58711 +
58712 + task = va_arg(ap, struct task_struct *);
58713 + wday = va_arg(ap, unsigned int);
58714 + cday = va_arg(ap, unsigned int);
58715 + whr = va_arg(ap, int);
58716 + chr = va_arg(ap, int);
58717 + wmin = va_arg(ap, int);
58718 + cmin = va_arg(ap, int);
58719 + wsec = va_arg(ap, int);
58720 + csec = va_arg(ap, int);
58721 + ulong1 = va_arg(ap, unsigned long);
58722 + cred = __task_cred(task);
58723 + pcred = __task_cred(task->real_parent);
58724 +
58725 + 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);
58726 + }
58727 + break;
58728 + default:
58729 + gr_log_middle(audit, msg, ap);
58730 + }
58731 + va_end(ap);
58732 + // these don't need DEFAULTSECARGS printed on the end
58733 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58734 + gr_log_end(audit, 0);
58735 + else
58736 + gr_log_end(audit, 1);
58737 + END_LOCKS(audit);
58738 +}
58739 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58740 new file mode 100644
58741 index 0000000..f536303
58742 --- /dev/null
58743 +++ b/grsecurity/grsec_mem.c
58744 @@ -0,0 +1,40 @@
58745 +#include <linux/kernel.h>
58746 +#include <linux/sched.h>
58747 +#include <linux/mm.h>
58748 +#include <linux/mman.h>
58749 +#include <linux/grinternal.h>
58750 +
58751 +void
58752 +gr_handle_ioperm(void)
58753 +{
58754 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58755 + return;
58756 +}
58757 +
58758 +void
58759 +gr_handle_iopl(void)
58760 +{
58761 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58762 + return;
58763 +}
58764 +
58765 +void
58766 +gr_handle_mem_readwrite(u64 from, u64 to)
58767 +{
58768 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58769 + return;
58770 +}
58771 +
58772 +void
58773 +gr_handle_vm86(void)
58774 +{
58775 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58776 + return;
58777 +}
58778 +
58779 +void
58780 +gr_log_badprocpid(const char *entry)
58781 +{
58782 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58783 + return;
58784 +}
58785 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58786 new file mode 100644
58787 index 0000000..2131422
58788 --- /dev/null
58789 +++ b/grsecurity/grsec_mount.c
58790 @@ -0,0 +1,62 @@
58791 +#include <linux/kernel.h>
58792 +#include <linux/sched.h>
58793 +#include <linux/mount.h>
58794 +#include <linux/grsecurity.h>
58795 +#include <linux/grinternal.h>
58796 +
58797 +void
58798 +gr_log_remount(const char *devname, const int retval)
58799 +{
58800 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58801 + if (grsec_enable_mount && (retval >= 0))
58802 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58803 +#endif
58804 + return;
58805 +}
58806 +
58807 +void
58808 +gr_log_unmount(const char *devname, const int retval)
58809 +{
58810 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58811 + if (grsec_enable_mount && (retval >= 0))
58812 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58813 +#endif
58814 + return;
58815 +}
58816 +
58817 +void
58818 +gr_log_mount(const char *from, const char *to, const int retval)
58819 +{
58820 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58821 + if (grsec_enable_mount && (retval >= 0))
58822 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58823 +#endif
58824 + return;
58825 +}
58826 +
58827 +int
58828 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58829 +{
58830 +#ifdef CONFIG_GRKERNSEC_ROFS
58831 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58832 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58833 + return -EPERM;
58834 + } else
58835 + return 0;
58836 +#endif
58837 + return 0;
58838 +}
58839 +
58840 +int
58841 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58842 +{
58843 +#ifdef CONFIG_GRKERNSEC_ROFS
58844 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58845 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58846 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58847 + return -EPERM;
58848 + } else
58849 + return 0;
58850 +#endif
58851 + return 0;
58852 +}
58853 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58854 new file mode 100644
58855 index 0000000..a3b12a0
58856 --- /dev/null
58857 +++ b/grsecurity/grsec_pax.c
58858 @@ -0,0 +1,36 @@
58859 +#include <linux/kernel.h>
58860 +#include <linux/sched.h>
58861 +#include <linux/mm.h>
58862 +#include <linux/file.h>
58863 +#include <linux/grinternal.h>
58864 +#include <linux/grsecurity.h>
58865 +
58866 +void
58867 +gr_log_textrel(struct vm_area_struct * vma)
58868 +{
58869 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58870 + if (grsec_enable_audit_textrel)
58871 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58872 +#endif
58873 + return;
58874 +}
58875 +
58876 +void
58877 +gr_log_rwxmmap(struct file *file)
58878 +{
58879 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58880 + if (grsec_enable_log_rwxmaps)
58881 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58882 +#endif
58883 + return;
58884 +}
58885 +
58886 +void
58887 +gr_log_rwxmprotect(struct file *file)
58888 +{
58889 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58890 + if (grsec_enable_log_rwxmaps)
58891 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58892 +#endif
58893 + return;
58894 +}
58895 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58896 new file mode 100644
58897 index 0000000..f7f29aa
58898 --- /dev/null
58899 +++ b/grsecurity/grsec_ptrace.c
58900 @@ -0,0 +1,30 @@
58901 +#include <linux/kernel.h>
58902 +#include <linux/sched.h>
58903 +#include <linux/grinternal.h>
58904 +#include <linux/security.h>
58905 +
58906 +void
58907 +gr_audit_ptrace(struct task_struct *task)
58908 +{
58909 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58910 + if (grsec_enable_audit_ptrace)
58911 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58912 +#endif
58913 + return;
58914 +}
58915 +
58916 +int
58917 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58918 +{
58919 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58920 + const struct dentry *dentry = file->f_path.dentry;
58921 + const struct vfsmount *mnt = file->f_path.mnt;
58922 +
58923 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58924 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58925 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58926 + return -EACCES;
58927 + }
58928 +#endif
58929 + return 0;
58930 +}
58931 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58932 new file mode 100644
58933 index 0000000..b4ac94c
58934 --- /dev/null
58935 +++ b/grsecurity/grsec_sig.c
58936 @@ -0,0 +1,209 @@
58937 +#include <linux/kernel.h>
58938 +#include <linux/sched.h>
58939 +#include <linux/delay.h>
58940 +#include <linux/grsecurity.h>
58941 +#include <linux/grinternal.h>
58942 +#include <linux/hardirq.h>
58943 +
58944 +char *signames[] = {
58945 + [SIGSEGV] = "Segmentation fault",
58946 + [SIGILL] = "Illegal instruction",
58947 + [SIGABRT] = "Abort",
58948 + [SIGBUS] = "Invalid alignment/Bus error"
58949 +};
58950 +
58951 +void
58952 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58953 +{
58954 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58955 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58956 + (sig == SIGABRT) || (sig == SIGBUS))) {
58957 + if (t->pid == current->pid) {
58958 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58959 + } else {
58960 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58961 + }
58962 + }
58963 +#endif
58964 + return;
58965 +}
58966 +
58967 +int
58968 +gr_handle_signal(const struct task_struct *p, const int sig)
58969 +{
58970 +#ifdef CONFIG_GRKERNSEC
58971 + /* ignore the 0 signal for protected task checks */
58972 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58973 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58974 + return -EPERM;
58975 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58976 + return -EPERM;
58977 + }
58978 +#endif
58979 + return 0;
58980 +}
58981 +
58982 +#ifdef CONFIG_GRKERNSEC
58983 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58984 +
58985 +int gr_fake_force_sig(int sig, struct task_struct *t)
58986 +{
58987 + unsigned long int flags;
58988 + int ret, blocked, ignored;
58989 + struct k_sigaction *action;
58990 +
58991 + spin_lock_irqsave(&t->sighand->siglock, flags);
58992 + action = &t->sighand->action[sig-1];
58993 + ignored = action->sa.sa_handler == SIG_IGN;
58994 + blocked = sigismember(&t->blocked, sig);
58995 + if (blocked || ignored) {
58996 + action->sa.sa_handler = SIG_DFL;
58997 + if (blocked) {
58998 + sigdelset(&t->blocked, sig);
58999 + recalc_sigpending_and_wake(t);
59000 + }
59001 + }
59002 + if (action->sa.sa_handler == SIG_DFL)
59003 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59004 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59005 +
59006 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59007 +
59008 + return ret;
59009 +}
59010 +#endif
59011 +
59012 +#ifdef CONFIG_GRKERNSEC_BRUTE
59013 +#define GR_USER_BAN_TIME (15 * 60)
59014 +
59015 +static int __get_dumpable(unsigned long mm_flags)
59016 +{
59017 + int ret;
59018 +
59019 + ret = mm_flags & MMF_DUMPABLE_MASK;
59020 + return (ret >= 2) ? 2 : ret;
59021 +}
59022 +#endif
59023 +
59024 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59025 +{
59026 +#ifdef CONFIG_GRKERNSEC_BRUTE
59027 + kuid_t uid = GLOBAL_ROOT_UID;
59028 +
59029 + if (!grsec_enable_brute)
59030 + return;
59031 +
59032 + rcu_read_lock();
59033 + read_lock(&tasklist_lock);
59034 + read_lock(&grsec_exec_file_lock);
59035 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59036 + p->real_parent->brute = 1;
59037 + else {
59038 + const struct cred *cred = __task_cred(p), *cred2;
59039 + struct task_struct *tsk, *tsk2;
59040 +
59041 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59042 + struct user_struct *user;
59043 +
59044 + uid = cred->uid;
59045 +
59046 + /* this is put upon execution past expiration */
59047 + user = find_user(uid);
59048 + if (user == NULL)
59049 + goto unlock;
59050 + user->banned = 1;
59051 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59052 + if (user->ban_expires == ~0UL)
59053 + user->ban_expires--;
59054 +
59055 + do_each_thread(tsk2, tsk) {
59056 + cred2 = __task_cred(tsk);
59057 + if (tsk != p && uid_eq(cred2->uid, uid))
59058 + gr_fake_force_sig(SIGKILL, tsk);
59059 + } while_each_thread(tsk2, tsk);
59060 + }
59061 + }
59062 +unlock:
59063 + read_unlock(&grsec_exec_file_lock);
59064 + read_unlock(&tasklist_lock);
59065 + rcu_read_unlock();
59066 +
59067 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59068 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59069 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59070 +
59071 +#endif
59072 + return;
59073 +}
59074 +
59075 +void gr_handle_brute_check(void)
59076 +{
59077 +#ifdef CONFIG_GRKERNSEC_BRUTE
59078 + if (current->brute)
59079 + msleep(30 * 1000);
59080 +#endif
59081 + return;
59082 +}
59083 +
59084 +void gr_handle_kernel_exploit(void)
59085 +{
59086 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59087 + const struct cred *cred;
59088 + struct task_struct *tsk, *tsk2;
59089 + struct user_struct *user;
59090 + kuid_t uid;
59091 +
59092 + if (in_irq() || in_serving_softirq() || in_nmi())
59093 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59094 +
59095 + uid = current_uid();
59096 +
59097 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59098 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59099 + else {
59100 + /* kill all the processes of this user, hold a reference
59101 + to their creds struct, and prevent them from creating
59102 + another process until system reset
59103 + */
59104 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59105 + from_kuid_munged(&init_user_ns, uid));
59106 + /* we intentionally leak this ref */
59107 + user = get_uid(current->cred->user);
59108 + if (user) {
59109 + user->banned = 1;
59110 + user->ban_expires = ~0UL;
59111 + }
59112 +
59113 + read_lock(&tasklist_lock);
59114 + do_each_thread(tsk2, tsk) {
59115 + cred = __task_cred(tsk);
59116 + if (uid_eq(cred->uid, uid))
59117 + gr_fake_force_sig(SIGKILL, tsk);
59118 + } while_each_thread(tsk2, tsk);
59119 + read_unlock(&tasklist_lock);
59120 + }
59121 +#endif
59122 +}
59123 +
59124 +int __gr_process_user_ban(struct user_struct *user)
59125 +{
59126 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59127 + if (unlikely(user->banned)) {
59128 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59129 + user->banned = 0;
59130 + user->ban_expires = 0;
59131 + free_uid(user);
59132 + } else
59133 + return -EPERM;
59134 + }
59135 +#endif
59136 + return 0;
59137 +}
59138 +
59139 +int gr_process_user_ban(void)
59140 +{
59141 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59142 + return __gr_process_user_ban(current->cred->user);
59143 +#endif
59144 + return 0;
59145 +}
59146 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59147 new file mode 100644
59148 index 0000000..4030d57
59149 --- /dev/null
59150 +++ b/grsecurity/grsec_sock.c
59151 @@ -0,0 +1,244 @@
59152 +#include <linux/kernel.h>
59153 +#include <linux/module.h>
59154 +#include <linux/sched.h>
59155 +#include <linux/file.h>
59156 +#include <linux/net.h>
59157 +#include <linux/in.h>
59158 +#include <linux/ip.h>
59159 +#include <net/sock.h>
59160 +#include <net/inet_sock.h>
59161 +#include <linux/grsecurity.h>
59162 +#include <linux/grinternal.h>
59163 +#include <linux/gracl.h>
59164 +
59165 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59166 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59167 +
59168 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59169 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59170 +
59171 +#ifdef CONFIG_UNIX_MODULE
59172 +EXPORT_SYMBOL(gr_acl_handle_unix);
59173 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59174 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59175 +EXPORT_SYMBOL(gr_handle_create);
59176 +#endif
59177 +
59178 +#ifdef CONFIG_GRKERNSEC
59179 +#define gr_conn_table_size 32749
59180 +struct conn_table_entry {
59181 + struct conn_table_entry *next;
59182 + struct signal_struct *sig;
59183 +};
59184 +
59185 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59186 +DEFINE_SPINLOCK(gr_conn_table_lock);
59187 +
59188 +extern const char * gr_socktype_to_name(unsigned char type);
59189 +extern const char * gr_proto_to_name(unsigned char proto);
59190 +extern const char * gr_sockfamily_to_name(unsigned char family);
59191 +
59192 +static __inline__ int
59193 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59194 +{
59195 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59196 +}
59197 +
59198 +static __inline__ int
59199 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59200 + __u16 sport, __u16 dport)
59201 +{
59202 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59203 + sig->gr_sport == sport && sig->gr_dport == dport))
59204 + return 1;
59205 + else
59206 + return 0;
59207 +}
59208 +
59209 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59210 +{
59211 + struct conn_table_entry **match;
59212 + unsigned int index;
59213 +
59214 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59215 + sig->gr_sport, sig->gr_dport,
59216 + gr_conn_table_size);
59217 +
59218 + newent->sig = sig;
59219 +
59220 + match = &gr_conn_table[index];
59221 + newent->next = *match;
59222 + *match = newent;
59223 +
59224 + return;
59225 +}
59226 +
59227 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59228 +{
59229 + struct conn_table_entry *match, *last = NULL;
59230 + unsigned int index;
59231 +
59232 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59233 + sig->gr_sport, sig->gr_dport,
59234 + gr_conn_table_size);
59235 +
59236 + match = gr_conn_table[index];
59237 + while (match && !conn_match(match->sig,
59238 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59239 + sig->gr_dport)) {
59240 + last = match;
59241 + match = match->next;
59242 + }
59243 +
59244 + if (match) {
59245 + if (last)
59246 + last->next = match->next;
59247 + else
59248 + gr_conn_table[index] = NULL;
59249 + kfree(match);
59250 + }
59251 +
59252 + return;
59253 +}
59254 +
59255 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59256 + __u16 sport, __u16 dport)
59257 +{
59258 + struct conn_table_entry *match;
59259 + unsigned int index;
59260 +
59261 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59262 +
59263 + match = gr_conn_table[index];
59264 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59265 + match = match->next;
59266 +
59267 + if (match)
59268 + return match->sig;
59269 + else
59270 + return NULL;
59271 +}
59272 +
59273 +#endif
59274 +
59275 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59276 +{
59277 +#ifdef CONFIG_GRKERNSEC
59278 + struct signal_struct *sig = task->signal;
59279 + struct conn_table_entry *newent;
59280 +
59281 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59282 + if (newent == NULL)
59283 + return;
59284 + /* no bh lock needed since we are called with bh disabled */
59285 + spin_lock(&gr_conn_table_lock);
59286 + gr_del_task_from_ip_table_nolock(sig);
59287 + sig->gr_saddr = inet->inet_rcv_saddr;
59288 + sig->gr_daddr = inet->inet_daddr;
59289 + sig->gr_sport = inet->inet_sport;
59290 + sig->gr_dport = inet->inet_dport;
59291 + gr_add_to_task_ip_table_nolock(sig, newent);
59292 + spin_unlock(&gr_conn_table_lock);
59293 +#endif
59294 + return;
59295 +}
59296 +
59297 +void gr_del_task_from_ip_table(struct task_struct *task)
59298 +{
59299 +#ifdef CONFIG_GRKERNSEC
59300 + spin_lock_bh(&gr_conn_table_lock);
59301 + gr_del_task_from_ip_table_nolock(task->signal);
59302 + spin_unlock_bh(&gr_conn_table_lock);
59303 +#endif
59304 + return;
59305 +}
59306 +
59307 +void
59308 +gr_attach_curr_ip(const struct sock *sk)
59309 +{
59310 +#ifdef CONFIG_GRKERNSEC
59311 + struct signal_struct *p, *set;
59312 + const struct inet_sock *inet = inet_sk(sk);
59313 +
59314 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59315 + return;
59316 +
59317 + set = current->signal;
59318 +
59319 + spin_lock_bh(&gr_conn_table_lock);
59320 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59321 + inet->inet_dport, inet->inet_sport);
59322 + if (unlikely(p != NULL)) {
59323 + set->curr_ip = p->curr_ip;
59324 + set->used_accept = 1;
59325 + gr_del_task_from_ip_table_nolock(p);
59326 + spin_unlock_bh(&gr_conn_table_lock);
59327 + return;
59328 + }
59329 + spin_unlock_bh(&gr_conn_table_lock);
59330 +
59331 + set->curr_ip = inet->inet_daddr;
59332 + set->used_accept = 1;
59333 +#endif
59334 + return;
59335 +}
59336 +
59337 +int
59338 +gr_handle_sock_all(const int family, const int type, const int protocol)
59339 +{
59340 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59341 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59342 + (family != AF_UNIX)) {
59343 + if (family == AF_INET)
59344 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59345 + else
59346 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59347 + return -EACCES;
59348 + }
59349 +#endif
59350 + return 0;
59351 +}
59352 +
59353 +int
59354 +gr_handle_sock_server(const struct sockaddr *sck)
59355 +{
59356 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59357 + if (grsec_enable_socket_server &&
59358 + in_group_p(grsec_socket_server_gid) &&
59359 + sck && (sck->sa_family != AF_UNIX) &&
59360 + (sck->sa_family != AF_LOCAL)) {
59361 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59362 + return -EACCES;
59363 + }
59364 +#endif
59365 + return 0;
59366 +}
59367 +
59368 +int
59369 +gr_handle_sock_server_other(const struct sock *sck)
59370 +{
59371 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59372 + if (grsec_enable_socket_server &&
59373 + in_group_p(grsec_socket_server_gid) &&
59374 + sck && (sck->sk_family != AF_UNIX) &&
59375 + (sck->sk_family != AF_LOCAL)) {
59376 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59377 + return -EACCES;
59378 + }
59379 +#endif
59380 + return 0;
59381 +}
59382 +
59383 +int
59384 +gr_handle_sock_client(const struct sockaddr *sck)
59385 +{
59386 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59387 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59388 + sck && (sck->sa_family != AF_UNIX) &&
59389 + (sck->sa_family != AF_LOCAL)) {
59390 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59391 + return -EACCES;
59392 + }
59393 +#endif
59394 + return 0;
59395 +}
59396 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59397 new file mode 100644
59398 index 0000000..f55ef0f
59399 --- /dev/null
59400 +++ b/grsecurity/grsec_sysctl.c
59401 @@ -0,0 +1,469 @@
59402 +#include <linux/kernel.h>
59403 +#include <linux/sched.h>
59404 +#include <linux/sysctl.h>
59405 +#include <linux/grsecurity.h>
59406 +#include <linux/grinternal.h>
59407 +
59408 +int
59409 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59410 +{
59411 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59412 + if (dirname == NULL || name == NULL)
59413 + return 0;
59414 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59415 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59416 + return -EACCES;
59417 + }
59418 +#endif
59419 + return 0;
59420 +}
59421 +
59422 +#ifdef CONFIG_GRKERNSEC_ROFS
59423 +static int __maybe_unused one = 1;
59424 +#endif
59425 +
59426 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59427 +struct ctl_table grsecurity_table[] = {
59428 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59429 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59430 +#ifdef CONFIG_GRKERNSEC_IO
59431 + {
59432 + .procname = "disable_priv_io",
59433 + .data = &grsec_disable_privio,
59434 + .maxlen = sizeof(int),
59435 + .mode = 0600,
59436 + .proc_handler = &proc_dointvec,
59437 + },
59438 +#endif
59439 +#endif
59440 +#ifdef CONFIG_GRKERNSEC_LINK
59441 + {
59442 + .procname = "linking_restrictions",
59443 + .data = &grsec_enable_link,
59444 + .maxlen = sizeof(int),
59445 + .mode = 0600,
59446 + .proc_handler = &proc_dointvec,
59447 + },
59448 +#endif
59449 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59450 + {
59451 + .procname = "enforce_symlinksifowner",
59452 + .data = &grsec_enable_symlinkown,
59453 + .maxlen = sizeof(int),
59454 + .mode = 0600,
59455 + .proc_handler = &proc_dointvec,
59456 + },
59457 + {
59458 + .procname = "symlinkown_gid",
59459 + .data = &grsec_symlinkown_gid,
59460 + .maxlen = sizeof(int),
59461 + .mode = 0600,
59462 + .proc_handler = &proc_dointvec,
59463 + },
59464 +#endif
59465 +#ifdef CONFIG_GRKERNSEC_BRUTE
59466 + {
59467 + .procname = "deter_bruteforce",
59468 + .data = &grsec_enable_brute,
59469 + .maxlen = sizeof(int),
59470 + .mode = 0600,
59471 + .proc_handler = &proc_dointvec,
59472 + },
59473 +#endif
59474 +#ifdef CONFIG_GRKERNSEC_FIFO
59475 + {
59476 + .procname = "fifo_restrictions",
59477 + .data = &grsec_enable_fifo,
59478 + .maxlen = sizeof(int),
59479 + .mode = 0600,
59480 + .proc_handler = &proc_dointvec,
59481 + },
59482 +#endif
59483 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59484 + {
59485 + .procname = "ptrace_readexec",
59486 + .data = &grsec_enable_ptrace_readexec,
59487 + .maxlen = sizeof(int),
59488 + .mode = 0600,
59489 + .proc_handler = &proc_dointvec,
59490 + },
59491 +#endif
59492 +#ifdef CONFIG_GRKERNSEC_SETXID
59493 + {
59494 + .procname = "consistent_setxid",
59495 + .data = &grsec_enable_setxid,
59496 + .maxlen = sizeof(int),
59497 + .mode = 0600,
59498 + .proc_handler = &proc_dointvec,
59499 + },
59500 +#endif
59501 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59502 + {
59503 + .procname = "ip_blackhole",
59504 + .data = &grsec_enable_blackhole,
59505 + .maxlen = sizeof(int),
59506 + .mode = 0600,
59507 + .proc_handler = &proc_dointvec,
59508 + },
59509 + {
59510 + .procname = "lastack_retries",
59511 + .data = &grsec_lastack_retries,
59512 + .maxlen = sizeof(int),
59513 + .mode = 0600,
59514 + .proc_handler = &proc_dointvec,
59515 + },
59516 +#endif
59517 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59518 + {
59519 + .procname = "exec_logging",
59520 + .data = &grsec_enable_execlog,
59521 + .maxlen = sizeof(int),
59522 + .mode = 0600,
59523 + .proc_handler = &proc_dointvec,
59524 + },
59525 +#endif
59526 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59527 + {
59528 + .procname = "rwxmap_logging",
59529 + .data = &grsec_enable_log_rwxmaps,
59530 + .maxlen = sizeof(int),
59531 + .mode = 0600,
59532 + .proc_handler = &proc_dointvec,
59533 + },
59534 +#endif
59535 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59536 + {
59537 + .procname = "signal_logging",
59538 + .data = &grsec_enable_signal,
59539 + .maxlen = sizeof(int),
59540 + .mode = 0600,
59541 + .proc_handler = &proc_dointvec,
59542 + },
59543 +#endif
59544 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59545 + {
59546 + .procname = "forkfail_logging",
59547 + .data = &grsec_enable_forkfail,
59548 + .maxlen = sizeof(int),
59549 + .mode = 0600,
59550 + .proc_handler = &proc_dointvec,
59551 + },
59552 +#endif
59553 +#ifdef CONFIG_GRKERNSEC_TIME
59554 + {
59555 + .procname = "timechange_logging",
59556 + .data = &grsec_enable_time,
59557 + .maxlen = sizeof(int),
59558 + .mode = 0600,
59559 + .proc_handler = &proc_dointvec,
59560 + },
59561 +#endif
59562 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59563 + {
59564 + .procname = "chroot_deny_shmat",
59565 + .data = &grsec_enable_chroot_shmat,
59566 + .maxlen = sizeof(int),
59567 + .mode = 0600,
59568 + .proc_handler = &proc_dointvec,
59569 + },
59570 +#endif
59571 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59572 + {
59573 + .procname = "chroot_deny_unix",
59574 + .data = &grsec_enable_chroot_unix,
59575 + .maxlen = sizeof(int),
59576 + .mode = 0600,
59577 + .proc_handler = &proc_dointvec,
59578 + },
59579 +#endif
59580 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59581 + {
59582 + .procname = "chroot_deny_mount",
59583 + .data = &grsec_enable_chroot_mount,
59584 + .maxlen = sizeof(int),
59585 + .mode = 0600,
59586 + .proc_handler = &proc_dointvec,
59587 + },
59588 +#endif
59589 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59590 + {
59591 + .procname = "chroot_deny_fchdir",
59592 + .data = &grsec_enable_chroot_fchdir,
59593 + .maxlen = sizeof(int),
59594 + .mode = 0600,
59595 + .proc_handler = &proc_dointvec,
59596 + },
59597 +#endif
59598 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59599 + {
59600 + .procname = "chroot_deny_chroot",
59601 + .data = &grsec_enable_chroot_double,
59602 + .maxlen = sizeof(int),
59603 + .mode = 0600,
59604 + .proc_handler = &proc_dointvec,
59605 + },
59606 +#endif
59607 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59608 + {
59609 + .procname = "chroot_deny_pivot",
59610 + .data = &grsec_enable_chroot_pivot,
59611 + .maxlen = sizeof(int),
59612 + .mode = 0600,
59613 + .proc_handler = &proc_dointvec,
59614 + },
59615 +#endif
59616 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59617 + {
59618 + .procname = "chroot_enforce_chdir",
59619 + .data = &grsec_enable_chroot_chdir,
59620 + .maxlen = sizeof(int),
59621 + .mode = 0600,
59622 + .proc_handler = &proc_dointvec,
59623 + },
59624 +#endif
59625 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59626 + {
59627 + .procname = "chroot_deny_chmod",
59628 + .data = &grsec_enable_chroot_chmod,
59629 + .maxlen = sizeof(int),
59630 + .mode = 0600,
59631 + .proc_handler = &proc_dointvec,
59632 + },
59633 +#endif
59634 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59635 + {
59636 + .procname = "chroot_deny_mknod",
59637 + .data = &grsec_enable_chroot_mknod,
59638 + .maxlen = sizeof(int),
59639 + .mode = 0600,
59640 + .proc_handler = &proc_dointvec,
59641 + },
59642 +#endif
59643 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59644 + {
59645 + .procname = "chroot_restrict_nice",
59646 + .data = &grsec_enable_chroot_nice,
59647 + .maxlen = sizeof(int),
59648 + .mode = 0600,
59649 + .proc_handler = &proc_dointvec,
59650 + },
59651 +#endif
59652 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59653 + {
59654 + .procname = "chroot_execlog",
59655 + .data = &grsec_enable_chroot_execlog,
59656 + .maxlen = sizeof(int),
59657 + .mode = 0600,
59658 + .proc_handler = &proc_dointvec,
59659 + },
59660 +#endif
59661 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59662 + {
59663 + .procname = "chroot_caps",
59664 + .data = &grsec_enable_chroot_caps,
59665 + .maxlen = sizeof(int),
59666 + .mode = 0600,
59667 + .proc_handler = &proc_dointvec,
59668 + },
59669 +#endif
59670 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59671 + {
59672 + .procname = "chroot_deny_sysctl",
59673 + .data = &grsec_enable_chroot_sysctl,
59674 + .maxlen = sizeof(int),
59675 + .mode = 0600,
59676 + .proc_handler = &proc_dointvec,
59677 + },
59678 +#endif
59679 +#ifdef CONFIG_GRKERNSEC_TPE
59680 + {
59681 + .procname = "tpe",
59682 + .data = &grsec_enable_tpe,
59683 + .maxlen = sizeof(int),
59684 + .mode = 0600,
59685 + .proc_handler = &proc_dointvec,
59686 + },
59687 + {
59688 + .procname = "tpe_gid",
59689 + .data = &grsec_tpe_gid,
59690 + .maxlen = sizeof(int),
59691 + .mode = 0600,
59692 + .proc_handler = &proc_dointvec,
59693 + },
59694 +#endif
59695 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59696 + {
59697 + .procname = "tpe_invert",
59698 + .data = &grsec_enable_tpe_invert,
59699 + .maxlen = sizeof(int),
59700 + .mode = 0600,
59701 + .proc_handler = &proc_dointvec,
59702 + },
59703 +#endif
59704 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59705 + {
59706 + .procname = "tpe_restrict_all",
59707 + .data = &grsec_enable_tpe_all,
59708 + .maxlen = sizeof(int),
59709 + .mode = 0600,
59710 + .proc_handler = &proc_dointvec,
59711 + },
59712 +#endif
59713 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59714 + {
59715 + .procname = "socket_all",
59716 + .data = &grsec_enable_socket_all,
59717 + .maxlen = sizeof(int),
59718 + .mode = 0600,
59719 + .proc_handler = &proc_dointvec,
59720 + },
59721 + {
59722 + .procname = "socket_all_gid",
59723 + .data = &grsec_socket_all_gid,
59724 + .maxlen = sizeof(int),
59725 + .mode = 0600,
59726 + .proc_handler = &proc_dointvec,
59727 + },
59728 +#endif
59729 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59730 + {
59731 + .procname = "socket_client",
59732 + .data = &grsec_enable_socket_client,
59733 + .maxlen = sizeof(int),
59734 + .mode = 0600,
59735 + .proc_handler = &proc_dointvec,
59736 + },
59737 + {
59738 + .procname = "socket_client_gid",
59739 + .data = &grsec_socket_client_gid,
59740 + .maxlen = sizeof(int),
59741 + .mode = 0600,
59742 + .proc_handler = &proc_dointvec,
59743 + },
59744 +#endif
59745 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59746 + {
59747 + .procname = "socket_server",
59748 + .data = &grsec_enable_socket_server,
59749 + .maxlen = sizeof(int),
59750 + .mode = 0600,
59751 + .proc_handler = &proc_dointvec,
59752 + },
59753 + {
59754 + .procname = "socket_server_gid",
59755 + .data = &grsec_socket_server_gid,
59756 + .maxlen = sizeof(int),
59757 + .mode = 0600,
59758 + .proc_handler = &proc_dointvec,
59759 + },
59760 +#endif
59761 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59762 + {
59763 + .procname = "audit_group",
59764 + .data = &grsec_enable_group,
59765 + .maxlen = sizeof(int),
59766 + .mode = 0600,
59767 + .proc_handler = &proc_dointvec,
59768 + },
59769 + {
59770 + .procname = "audit_gid",
59771 + .data = &grsec_audit_gid,
59772 + .maxlen = sizeof(int),
59773 + .mode = 0600,
59774 + .proc_handler = &proc_dointvec,
59775 + },
59776 +#endif
59777 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59778 + {
59779 + .procname = "audit_chdir",
59780 + .data = &grsec_enable_chdir,
59781 + .maxlen = sizeof(int),
59782 + .mode = 0600,
59783 + .proc_handler = &proc_dointvec,
59784 + },
59785 +#endif
59786 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59787 + {
59788 + .procname = "audit_mount",
59789 + .data = &grsec_enable_mount,
59790 + .maxlen = sizeof(int),
59791 + .mode = 0600,
59792 + .proc_handler = &proc_dointvec,
59793 + },
59794 +#endif
59795 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59796 + {
59797 + .procname = "audit_textrel",
59798 + .data = &grsec_enable_audit_textrel,
59799 + .maxlen = sizeof(int),
59800 + .mode = 0600,
59801 + .proc_handler = &proc_dointvec,
59802 + },
59803 +#endif
59804 +#ifdef CONFIG_GRKERNSEC_DMESG
59805 + {
59806 + .procname = "dmesg",
59807 + .data = &grsec_enable_dmesg,
59808 + .maxlen = sizeof(int),
59809 + .mode = 0600,
59810 + .proc_handler = &proc_dointvec,
59811 + },
59812 +#endif
59813 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59814 + {
59815 + .procname = "chroot_findtask",
59816 + .data = &grsec_enable_chroot_findtask,
59817 + .maxlen = sizeof(int),
59818 + .mode = 0600,
59819 + .proc_handler = &proc_dointvec,
59820 + },
59821 +#endif
59822 +#ifdef CONFIG_GRKERNSEC_RESLOG
59823 + {
59824 + .procname = "resource_logging",
59825 + .data = &grsec_resource_logging,
59826 + .maxlen = sizeof(int),
59827 + .mode = 0600,
59828 + .proc_handler = &proc_dointvec,
59829 + },
59830 +#endif
59831 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59832 + {
59833 + .procname = "audit_ptrace",
59834 + .data = &grsec_enable_audit_ptrace,
59835 + .maxlen = sizeof(int),
59836 + .mode = 0600,
59837 + .proc_handler = &proc_dointvec,
59838 + },
59839 +#endif
59840 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59841 + {
59842 + .procname = "harden_ptrace",
59843 + .data = &grsec_enable_harden_ptrace,
59844 + .maxlen = sizeof(int),
59845 + .mode = 0600,
59846 + .proc_handler = &proc_dointvec,
59847 + },
59848 +#endif
59849 + {
59850 + .procname = "grsec_lock",
59851 + .data = &grsec_lock,
59852 + .maxlen = sizeof(int),
59853 + .mode = 0600,
59854 + .proc_handler = &proc_dointvec,
59855 + },
59856 +#endif
59857 +#ifdef CONFIG_GRKERNSEC_ROFS
59858 + {
59859 + .procname = "romount_protect",
59860 + .data = &grsec_enable_rofs,
59861 + .maxlen = sizeof(int),
59862 + .mode = 0600,
59863 + .proc_handler = &proc_dointvec_minmax,
59864 + .extra1 = &one,
59865 + .extra2 = &one,
59866 + },
59867 +#endif
59868 + { }
59869 +};
59870 +#endif
59871 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59872 new file mode 100644
59873 index 0000000..0dc13c3
59874 --- /dev/null
59875 +++ b/grsecurity/grsec_time.c
59876 @@ -0,0 +1,16 @@
59877 +#include <linux/kernel.h>
59878 +#include <linux/sched.h>
59879 +#include <linux/grinternal.h>
59880 +#include <linux/module.h>
59881 +
59882 +void
59883 +gr_log_timechange(void)
59884 +{
59885 +#ifdef CONFIG_GRKERNSEC_TIME
59886 + if (grsec_enable_time)
59887 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59888 +#endif
59889 + return;
59890 +}
59891 +
59892 +EXPORT_SYMBOL(gr_log_timechange);
59893 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59894 new file mode 100644
59895 index 0000000..07e0dc0
59896 --- /dev/null
59897 +++ b/grsecurity/grsec_tpe.c
59898 @@ -0,0 +1,73 @@
59899 +#include <linux/kernel.h>
59900 +#include <linux/sched.h>
59901 +#include <linux/file.h>
59902 +#include <linux/fs.h>
59903 +#include <linux/grinternal.h>
59904 +
59905 +extern int gr_acl_tpe_check(void);
59906 +
59907 +int
59908 +gr_tpe_allow(const struct file *file)
59909 +{
59910 +#ifdef CONFIG_GRKERNSEC
59911 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59912 + const struct cred *cred = current_cred();
59913 + char *msg = NULL;
59914 + char *msg2 = NULL;
59915 +
59916 + // never restrict root
59917 + if (!cred->uid)
59918 + return 1;
59919 +
59920 + if (grsec_enable_tpe) {
59921 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59922 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59923 + msg = "not being in trusted group";
59924 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59925 + msg = "being in untrusted group";
59926 +#else
59927 + if (in_group_p(grsec_tpe_gid))
59928 + msg = "being in untrusted group";
59929 +#endif
59930 + }
59931 + if (!msg && gr_acl_tpe_check())
59932 + msg = "being in untrusted role";
59933 +
59934 + // not in any affected group/role
59935 + if (!msg)
59936 + goto next_check;
59937 +
59938 + if (inode->i_uid)
59939 + msg2 = "file in non-root-owned directory";
59940 + else if (inode->i_mode & S_IWOTH)
59941 + msg2 = "file in world-writable directory";
59942 + else if (inode->i_mode & S_IWGRP)
59943 + msg2 = "file in group-writable directory";
59944 +
59945 + if (msg && msg2) {
59946 + char fullmsg[70] = {0};
59947 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59948 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59949 + return 0;
59950 + }
59951 + msg = NULL;
59952 +next_check:
59953 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59954 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59955 + return 1;
59956 +
59957 + if (inode->i_uid && (inode->i_uid != cred->uid))
59958 + msg = "directory not owned by user";
59959 + else if (inode->i_mode & S_IWOTH)
59960 + msg = "file in world-writable directory";
59961 + else if (inode->i_mode & S_IWGRP)
59962 + msg = "file in group-writable directory";
59963 +
59964 + if (msg) {
59965 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59966 + return 0;
59967 + }
59968 +#endif
59969 +#endif
59970 + return 1;
59971 +}
59972 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59973 new file mode 100644
59974 index 0000000..9f7b1ac
59975 --- /dev/null
59976 +++ b/grsecurity/grsum.c
59977 @@ -0,0 +1,61 @@
59978 +#include <linux/err.h>
59979 +#include <linux/kernel.h>
59980 +#include <linux/sched.h>
59981 +#include <linux/mm.h>
59982 +#include <linux/scatterlist.h>
59983 +#include <linux/crypto.h>
59984 +#include <linux/gracl.h>
59985 +
59986 +
59987 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59988 +#error "crypto and sha256 must be built into the kernel"
59989 +#endif
59990 +
59991 +int
59992 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59993 +{
59994 + char *p;
59995 + struct crypto_hash *tfm;
59996 + struct hash_desc desc;
59997 + struct scatterlist sg;
59998 + unsigned char temp_sum[GR_SHA_LEN];
59999 + volatile int retval = 0;
60000 + volatile int dummy = 0;
60001 + unsigned int i;
60002 +
60003 + sg_init_table(&sg, 1);
60004 +
60005 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60006 + if (IS_ERR(tfm)) {
60007 + /* should never happen, since sha256 should be built in */
60008 + return 1;
60009 + }
60010 +
60011 + desc.tfm = tfm;
60012 + desc.flags = 0;
60013 +
60014 + crypto_hash_init(&desc);
60015 +
60016 + p = salt;
60017 + sg_set_buf(&sg, p, GR_SALT_LEN);
60018 + crypto_hash_update(&desc, &sg, sg.length);
60019 +
60020 + p = entry->pw;
60021 + sg_set_buf(&sg, p, strlen(p));
60022 +
60023 + crypto_hash_update(&desc, &sg, sg.length);
60024 +
60025 + crypto_hash_final(&desc, temp_sum);
60026 +
60027 + memset(entry->pw, 0, GR_PW_LEN);
60028 +
60029 + for (i = 0; i < GR_SHA_LEN; i++)
60030 + if (sum[i] != temp_sum[i])
60031 + retval = 1;
60032 + else
60033 + dummy = 1; // waste a cycle
60034 +
60035 + crypto_free_hash(tfm);
60036 +
60037 + return retval;
60038 +}
60039 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60040 index 9e6e1c6..d47b906 100644
60041 --- a/include/acpi/acpi_bus.h
60042 +++ b/include/acpi/acpi_bus.h
60043 @@ -138,7 +138,7 @@ struct acpi_device_ops {
60044 acpi_op_bind bind;
60045 acpi_op_unbind unbind;
60046 acpi_op_notify notify;
60047 -};
60048 +} __no_const;
60049
60050 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60051
60052 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60053 index 77ff547..181834f 100644
60054 --- a/include/asm-generic/4level-fixup.h
60055 +++ b/include/asm-generic/4level-fixup.h
60056 @@ -13,8 +13,10 @@
60057 #define pmd_alloc(mm, pud, address) \
60058 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60059 NULL: pmd_offset(pud, address))
60060 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60061
60062 #define pud_alloc(mm, pgd, address) (pgd)
60063 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60064 #define pud_offset(pgd, start) (pgd)
60065 #define pud_none(pud) 0
60066 #define pud_bad(pud) 0
60067 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60068 index b7babf0..3ba8aee 100644
60069 --- a/include/asm-generic/atomic-long.h
60070 +++ b/include/asm-generic/atomic-long.h
60071 @@ -22,6 +22,12 @@
60072
60073 typedef atomic64_t atomic_long_t;
60074
60075 +#ifdef CONFIG_PAX_REFCOUNT
60076 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60077 +#else
60078 +typedef atomic64_t atomic_long_unchecked_t;
60079 +#endif
60080 +
60081 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60082
60083 static inline long atomic_long_read(atomic_long_t *l)
60084 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60085 return (long)atomic64_read(v);
60086 }
60087
60088 +#ifdef CONFIG_PAX_REFCOUNT
60089 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60090 +{
60091 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60092 +
60093 + return (long)atomic64_read_unchecked(v);
60094 +}
60095 +#endif
60096 +
60097 static inline void atomic_long_set(atomic_long_t *l, long i)
60098 {
60099 atomic64_t *v = (atomic64_t *)l;
60100 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60101 atomic64_set(v, i);
60102 }
60103
60104 +#ifdef CONFIG_PAX_REFCOUNT
60105 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60106 +{
60107 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60108 +
60109 + atomic64_set_unchecked(v, i);
60110 +}
60111 +#endif
60112 +
60113 static inline void atomic_long_inc(atomic_long_t *l)
60114 {
60115 atomic64_t *v = (atomic64_t *)l;
60116 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60117 atomic64_inc(v);
60118 }
60119
60120 +#ifdef CONFIG_PAX_REFCOUNT
60121 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60122 +{
60123 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60124 +
60125 + atomic64_inc_unchecked(v);
60126 +}
60127 +#endif
60128 +
60129 static inline void atomic_long_dec(atomic_long_t *l)
60130 {
60131 atomic64_t *v = (atomic64_t *)l;
60132 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60133 atomic64_dec(v);
60134 }
60135
60136 +#ifdef CONFIG_PAX_REFCOUNT
60137 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60138 +{
60139 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60140 +
60141 + atomic64_dec_unchecked(v);
60142 +}
60143 +#endif
60144 +
60145 static inline void atomic_long_add(long i, atomic_long_t *l)
60146 {
60147 atomic64_t *v = (atomic64_t *)l;
60148 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60149 atomic64_add(i, v);
60150 }
60151
60152 +#ifdef CONFIG_PAX_REFCOUNT
60153 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60154 +{
60155 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60156 +
60157 + atomic64_add_unchecked(i, v);
60158 +}
60159 +#endif
60160 +
60161 static inline void atomic_long_sub(long i, atomic_long_t *l)
60162 {
60163 atomic64_t *v = (atomic64_t *)l;
60164 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60165 atomic64_sub(i, v);
60166 }
60167
60168 +#ifdef CONFIG_PAX_REFCOUNT
60169 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60170 +{
60171 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60172 +
60173 + atomic64_sub_unchecked(i, v);
60174 +}
60175 +#endif
60176 +
60177 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60178 {
60179 atomic64_t *v = (atomic64_t *)l;
60180 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60181 return (long)atomic64_inc_return(v);
60182 }
60183
60184 +#ifdef CONFIG_PAX_REFCOUNT
60185 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60186 +{
60187 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60188 +
60189 + return (long)atomic64_inc_return_unchecked(v);
60190 +}
60191 +#endif
60192 +
60193 static inline long atomic_long_dec_return(atomic_long_t *l)
60194 {
60195 atomic64_t *v = (atomic64_t *)l;
60196 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60197
60198 typedef atomic_t atomic_long_t;
60199
60200 +#ifdef CONFIG_PAX_REFCOUNT
60201 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60202 +#else
60203 +typedef atomic_t atomic_long_unchecked_t;
60204 +#endif
60205 +
60206 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60207 static inline long atomic_long_read(atomic_long_t *l)
60208 {
60209 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60210 return (long)atomic_read(v);
60211 }
60212
60213 +#ifdef CONFIG_PAX_REFCOUNT
60214 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60215 +{
60216 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60217 +
60218 + return (long)atomic_read_unchecked(v);
60219 +}
60220 +#endif
60221 +
60222 static inline void atomic_long_set(atomic_long_t *l, long i)
60223 {
60224 atomic_t *v = (atomic_t *)l;
60225 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60226 atomic_set(v, i);
60227 }
60228
60229 +#ifdef CONFIG_PAX_REFCOUNT
60230 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60231 +{
60232 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60233 +
60234 + atomic_set_unchecked(v, i);
60235 +}
60236 +#endif
60237 +
60238 static inline void atomic_long_inc(atomic_long_t *l)
60239 {
60240 atomic_t *v = (atomic_t *)l;
60241 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60242 atomic_inc(v);
60243 }
60244
60245 +#ifdef CONFIG_PAX_REFCOUNT
60246 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60247 +{
60248 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60249 +
60250 + atomic_inc_unchecked(v);
60251 +}
60252 +#endif
60253 +
60254 static inline void atomic_long_dec(atomic_long_t *l)
60255 {
60256 atomic_t *v = (atomic_t *)l;
60257 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60258 atomic_dec(v);
60259 }
60260
60261 +#ifdef CONFIG_PAX_REFCOUNT
60262 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60263 +{
60264 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60265 +
60266 + atomic_dec_unchecked(v);
60267 +}
60268 +#endif
60269 +
60270 static inline void atomic_long_add(long i, atomic_long_t *l)
60271 {
60272 atomic_t *v = (atomic_t *)l;
60273 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60274 atomic_add(i, v);
60275 }
60276
60277 +#ifdef CONFIG_PAX_REFCOUNT
60278 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60279 +{
60280 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60281 +
60282 + atomic_add_unchecked(i, v);
60283 +}
60284 +#endif
60285 +
60286 static inline void atomic_long_sub(long i, atomic_long_t *l)
60287 {
60288 atomic_t *v = (atomic_t *)l;
60289 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60290 atomic_sub(i, v);
60291 }
60292
60293 +#ifdef CONFIG_PAX_REFCOUNT
60294 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60295 +{
60296 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60297 +
60298 + atomic_sub_unchecked(i, v);
60299 +}
60300 +#endif
60301 +
60302 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60303 {
60304 atomic_t *v = (atomic_t *)l;
60305 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60306 return (long)atomic_inc_return(v);
60307 }
60308
60309 +#ifdef CONFIG_PAX_REFCOUNT
60310 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60311 +{
60312 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60313 +
60314 + return (long)atomic_inc_return_unchecked(v);
60315 +}
60316 +#endif
60317 +
60318 static inline long atomic_long_dec_return(atomic_long_t *l)
60319 {
60320 atomic_t *v = (atomic_t *)l;
60321 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60322
60323 #endif /* BITS_PER_LONG == 64 */
60324
60325 +#ifdef CONFIG_PAX_REFCOUNT
60326 +static inline void pax_refcount_needs_these_functions(void)
60327 +{
60328 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60329 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60330 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60331 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60332 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60333 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60334 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60335 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60336 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60337 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60338 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60339 +#ifdef CONFIG_X86
60340 + atomic_clear_mask_unchecked(0, NULL);
60341 + atomic_set_mask_unchecked(0, NULL);
60342 +#endif
60343 +
60344 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60345 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60346 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60347 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60348 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60349 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60350 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60351 +}
60352 +#else
60353 +#define atomic_read_unchecked(v) atomic_read(v)
60354 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60355 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60356 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60357 +#define atomic_inc_unchecked(v) atomic_inc(v)
60358 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60359 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60360 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60361 +#define atomic_dec_unchecked(v) atomic_dec(v)
60362 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60363 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60364 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60365 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60366 +
60367 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60368 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60369 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60370 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60371 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60372 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60373 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60374 +#endif
60375 +
60376 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60377 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60378 index 1ced641..c896ee8 100644
60379 --- a/include/asm-generic/atomic.h
60380 +++ b/include/asm-generic/atomic.h
60381 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60382 * Atomically clears the bits set in @mask from @v
60383 */
60384 #ifndef atomic_clear_mask
60385 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60386 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60387 {
60388 unsigned long flags;
60389
60390 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60391 index b18ce4f..2ee2843 100644
60392 --- a/include/asm-generic/atomic64.h
60393 +++ b/include/asm-generic/atomic64.h
60394 @@ -16,6 +16,8 @@ typedef struct {
60395 long long counter;
60396 } atomic64_t;
60397
60398 +typedef atomic64_t atomic64_unchecked_t;
60399 +
60400 #define ATOMIC64_INIT(i) { (i) }
60401
60402 extern long long atomic64_read(const atomic64_t *v);
60403 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60404 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60405 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60406
60407 +#define atomic64_read_unchecked(v) atomic64_read(v)
60408 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60409 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60410 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60411 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60412 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60413 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60414 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60415 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60416 +
60417 #endif /* _ASM_GENERIC_ATOMIC64_H */
60418 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60419 index 1bfcfe5..e04c5c9 100644
60420 --- a/include/asm-generic/cache.h
60421 +++ b/include/asm-generic/cache.h
60422 @@ -6,7 +6,7 @@
60423 * cache lines need to provide their own cache.h.
60424 */
60425
60426 -#define L1_CACHE_SHIFT 5
60427 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60428 +#define L1_CACHE_SHIFT 5UL
60429 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60430
60431 #endif /* __ASM_GENERIC_CACHE_H */
60432 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60433 index 0d68a1e..b74a761 100644
60434 --- a/include/asm-generic/emergency-restart.h
60435 +++ b/include/asm-generic/emergency-restart.h
60436 @@ -1,7 +1,7 @@
60437 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60438 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60439
60440 -static inline void machine_emergency_restart(void)
60441 +static inline __noreturn void machine_emergency_restart(void)
60442 {
60443 machine_restart(NULL);
60444 }
60445 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60446 index 0232ccb..13d9165 100644
60447 --- a/include/asm-generic/kmap_types.h
60448 +++ b/include/asm-generic/kmap_types.h
60449 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60450 KMAP_D(17) KM_NMI,
60451 KMAP_D(18) KM_NMI_PTE,
60452 KMAP_D(19) KM_KDB,
60453 +KMAP_D(20) KM_CLEARPAGE,
60454 /*
60455 * Remember to update debug_kmap_atomic() when adding new kmap types!
60456 */
60457 -KMAP_D(20) KM_TYPE_NR
60458 +KMAP_D(21) KM_TYPE_NR
60459 };
60460
60461 #undef KMAP_D
60462 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60463 index 9ceb03b..2efbcbd 100644
60464 --- a/include/asm-generic/local.h
60465 +++ b/include/asm-generic/local.h
60466 @@ -39,6 +39,7 @@ typedef struct
60467 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60468 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60469 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60470 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60471
60472 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60473 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60474 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60475 index 725612b..9cc513a 100644
60476 --- a/include/asm-generic/pgtable-nopmd.h
60477 +++ b/include/asm-generic/pgtable-nopmd.h
60478 @@ -1,14 +1,19 @@
60479 #ifndef _PGTABLE_NOPMD_H
60480 #define _PGTABLE_NOPMD_H
60481
60482 -#ifndef __ASSEMBLY__
60483 -
60484 #include <asm-generic/pgtable-nopud.h>
60485
60486 -struct mm_struct;
60487 -
60488 #define __PAGETABLE_PMD_FOLDED
60489
60490 +#define PMD_SHIFT PUD_SHIFT
60491 +#define PTRS_PER_PMD 1
60492 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60493 +#define PMD_MASK (~(PMD_SIZE-1))
60494 +
60495 +#ifndef __ASSEMBLY__
60496 +
60497 +struct mm_struct;
60498 +
60499 /*
60500 * Having the pmd type consist of a pud gets the size right, and allows
60501 * us to conceptually access the pud entry that this pmd is folded into
60502 @@ -16,11 +21,6 @@ struct mm_struct;
60503 */
60504 typedef struct { pud_t pud; } pmd_t;
60505
60506 -#define PMD_SHIFT PUD_SHIFT
60507 -#define PTRS_PER_PMD 1
60508 -#define PMD_SIZE (1UL << PMD_SHIFT)
60509 -#define PMD_MASK (~(PMD_SIZE-1))
60510 -
60511 /*
60512 * The "pud_xxx()" functions here are trivial for a folded two-level
60513 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60514 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60515 index 810431d..0ec4804f 100644
60516 --- a/include/asm-generic/pgtable-nopud.h
60517 +++ b/include/asm-generic/pgtable-nopud.h
60518 @@ -1,10 +1,15 @@
60519 #ifndef _PGTABLE_NOPUD_H
60520 #define _PGTABLE_NOPUD_H
60521
60522 -#ifndef __ASSEMBLY__
60523 -
60524 #define __PAGETABLE_PUD_FOLDED
60525
60526 +#define PUD_SHIFT PGDIR_SHIFT
60527 +#define PTRS_PER_PUD 1
60528 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60529 +#define PUD_MASK (~(PUD_SIZE-1))
60530 +
60531 +#ifndef __ASSEMBLY__
60532 +
60533 /*
60534 * Having the pud type consist of a pgd gets the size right, and allows
60535 * us to conceptually access the pgd entry that this pud is folded into
60536 @@ -12,11 +17,6 @@
60537 */
60538 typedef struct { pgd_t pgd; } pud_t;
60539
60540 -#define PUD_SHIFT PGDIR_SHIFT
60541 -#define PTRS_PER_PUD 1
60542 -#define PUD_SIZE (1UL << PUD_SHIFT)
60543 -#define PUD_MASK (~(PUD_SIZE-1))
60544 -
60545 /*
60546 * The "pgd_xxx()" functions here are trivial for a folded two-level
60547 * setup: the pud is never bad, and a pud always exists (as it's folded
60548 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60549 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60550
60551 #define pgd_populate(mm, pgd, pud) do { } while (0)
60552 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60553 /*
60554 * (puds are folded into pgds so this doesn't get actually called,
60555 * but the define is needed for a generic inline function.)
60556 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60557 index ff4947b..f48183f 100644
60558 --- a/include/asm-generic/pgtable.h
60559 +++ b/include/asm-generic/pgtable.h
60560 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60561 #endif
60562 }
60563
60564 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60565 +static inline unsigned long pax_open_kernel(void) { return 0; }
60566 +#endif
60567 +
60568 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60569 +static inline unsigned long pax_close_kernel(void) { return 0; }
60570 +#endif
60571 +
60572 #endif /* CONFIG_MMU */
60573
60574 #endif /* !__ASSEMBLY__ */
60575 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60576 index 4e2e1cc..12c266b 100644
60577 --- a/include/asm-generic/vmlinux.lds.h
60578 +++ b/include/asm-generic/vmlinux.lds.h
60579 @@ -218,6 +218,7 @@
60580 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60581 VMLINUX_SYMBOL(__start_rodata) = .; \
60582 *(.rodata) *(.rodata.*) \
60583 + *(.data..read_only) \
60584 *(__vermagic) /* Kernel version magic */ \
60585 . = ALIGN(8); \
60586 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60587 @@ -716,17 +717,18 @@
60588 * section in the linker script will go there too. @phdr should have
60589 * a leading colon.
60590 *
60591 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60592 + * Note that this macros defines per_cpu_load as an absolute symbol.
60593 * If there is no need to put the percpu section at a predetermined
60594 * address, use PERCPU_SECTION.
60595 */
60596 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60597 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60598 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60599 + per_cpu_load = .; \
60600 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60601 - LOAD_OFFSET) { \
60602 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60603 PERCPU_INPUT(cacheline) \
60604 } phdr \
60605 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60606 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60607
60608 /**
60609 * PERCPU_SECTION - define output section for percpu area, simple version
60610 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60611 index 31ad880..4e79884 100644
60612 --- a/include/drm/drmP.h
60613 +++ b/include/drm/drmP.h
60614 @@ -72,6 +72,7 @@
60615 #include <linux/workqueue.h>
60616 #include <linux/poll.h>
60617 #include <asm/pgalloc.h>
60618 +#include <asm/local.h>
60619 #include "drm.h"
60620
60621 #include <linux/idr.h>
60622 @@ -1074,7 +1075,7 @@ struct drm_device {
60623
60624 /** \name Usage Counters */
60625 /*@{ */
60626 - int open_count; /**< Outstanding files open */
60627 + local_t open_count; /**< Outstanding files open */
60628 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60629 atomic_t vma_count; /**< Outstanding vma areas open */
60630 int buf_use; /**< Buffers in use -- cannot alloc */
60631 @@ -1085,7 +1086,7 @@ struct drm_device {
60632 /*@{ */
60633 unsigned long counters;
60634 enum drm_stat_type types[15];
60635 - atomic_t counts[15];
60636 + atomic_unchecked_t counts[15];
60637 /*@} */
60638
60639 struct list_head filelist;
60640 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60641 index 7988e55..ec974c9 100644
60642 --- a/include/drm/drm_crtc_helper.h
60643 +++ b/include/drm/drm_crtc_helper.h
60644 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60645
60646 /* disable crtc when not in use - more explicit than dpms off */
60647 void (*disable)(struct drm_crtc *crtc);
60648 -};
60649 +} __no_const;
60650
60651 /**
60652 * drm_encoder_helper_funcs - helper operations for encoders
60653 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60654 struct drm_connector *connector);
60655 /* disable encoder when not in use - more explicit than dpms off */
60656 void (*disable)(struct drm_encoder *encoder);
60657 -};
60658 +} __no_const;
60659
60660 /**
60661 * drm_connector_helper_funcs - helper operations for connectors
60662 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60663 index d6d1da4..fdd1ac5 100644
60664 --- a/include/drm/ttm/ttm_memory.h
60665 +++ b/include/drm/ttm/ttm_memory.h
60666 @@ -48,7 +48,7 @@
60667
60668 struct ttm_mem_shrink {
60669 int (*do_shrink) (struct ttm_mem_shrink *);
60670 -};
60671 +} __no_const;
60672
60673 /**
60674 * struct ttm_mem_global - Global memory accounting structure.
60675 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60676 index e86dfca..40cc55f 100644
60677 --- a/include/linux/a.out.h
60678 +++ b/include/linux/a.out.h
60679 @@ -39,6 +39,14 @@ enum machine_type {
60680 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60681 };
60682
60683 +/* Constants for the N_FLAGS field */
60684 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60685 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60686 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60687 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60688 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60689 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60690 +
60691 #if !defined (N_MAGIC)
60692 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60693 #endif
60694 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60695 index 06fd4bb..1caec0d 100644
60696 --- a/include/linux/atmdev.h
60697 +++ b/include/linux/atmdev.h
60698 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60699 #endif
60700
60701 struct k_atm_aal_stats {
60702 -#define __HANDLE_ITEM(i) atomic_t i
60703 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60704 __AAL_STAT_ITEMS
60705 #undef __HANDLE_ITEM
60706 };
60707 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60708 index 366422b..1fa7f84 100644
60709 --- a/include/linux/binfmts.h
60710 +++ b/include/linux/binfmts.h
60711 @@ -89,6 +89,7 @@ struct linux_binfmt {
60712 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60713 int (*load_shlib)(struct file *);
60714 int (*core_dump)(struct coredump_params *cprm);
60715 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60716 unsigned long min_coredump; /* minimal dump size */
60717 };
60718
60719 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60720 index 07954b0..cb2ae71 100644
60721 --- a/include/linux/blkdev.h
60722 +++ b/include/linux/blkdev.h
60723 @@ -1393,7 +1393,7 @@ struct block_device_operations {
60724 /* this callback is with swap_lock and sometimes page table lock held */
60725 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60726 struct module *owner;
60727 -};
60728 +} __do_const;
60729
60730 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60731 unsigned long);
60732 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60733 index 4d1a074..88f929a 100644
60734 --- a/include/linux/blktrace_api.h
60735 +++ b/include/linux/blktrace_api.h
60736 @@ -162,7 +162,7 @@ struct blk_trace {
60737 struct dentry *dir;
60738 struct dentry *dropped_file;
60739 struct dentry *msg_file;
60740 - atomic_t dropped;
60741 + atomic_unchecked_t dropped;
60742 };
60743
60744 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60745 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60746 index 83195fb..0b0f77d 100644
60747 --- a/include/linux/byteorder/little_endian.h
60748 +++ b/include/linux/byteorder/little_endian.h
60749 @@ -42,51 +42,51 @@
60750
60751 static inline __le64 __cpu_to_le64p(const __u64 *p)
60752 {
60753 - return (__force __le64)*p;
60754 + return (__force const __le64)*p;
60755 }
60756 static inline __u64 __le64_to_cpup(const __le64 *p)
60757 {
60758 - return (__force __u64)*p;
60759 + return (__force const __u64)*p;
60760 }
60761 static inline __le32 __cpu_to_le32p(const __u32 *p)
60762 {
60763 - return (__force __le32)*p;
60764 + return (__force const __le32)*p;
60765 }
60766 static inline __u32 __le32_to_cpup(const __le32 *p)
60767 {
60768 - return (__force __u32)*p;
60769 + return (__force const __u32)*p;
60770 }
60771 static inline __le16 __cpu_to_le16p(const __u16 *p)
60772 {
60773 - return (__force __le16)*p;
60774 + return (__force const __le16)*p;
60775 }
60776 static inline __u16 __le16_to_cpup(const __le16 *p)
60777 {
60778 - return (__force __u16)*p;
60779 + return (__force const __u16)*p;
60780 }
60781 static inline __be64 __cpu_to_be64p(const __u64 *p)
60782 {
60783 - return (__force __be64)__swab64p(p);
60784 + return (__force const __be64)__swab64p(p);
60785 }
60786 static inline __u64 __be64_to_cpup(const __be64 *p)
60787 {
60788 - return __swab64p((__u64 *)p);
60789 + return __swab64p((const __u64 *)p);
60790 }
60791 static inline __be32 __cpu_to_be32p(const __u32 *p)
60792 {
60793 - return (__force __be32)__swab32p(p);
60794 + return (__force const __be32)__swab32p(p);
60795 }
60796 static inline __u32 __be32_to_cpup(const __be32 *p)
60797 {
60798 - return __swab32p((__u32 *)p);
60799 + return __swab32p((const __u32 *)p);
60800 }
60801 static inline __be16 __cpu_to_be16p(const __u16 *p)
60802 {
60803 - return (__force __be16)__swab16p(p);
60804 + return (__force const __be16)__swab16p(p);
60805 }
60806 static inline __u16 __be16_to_cpup(const __be16 *p)
60807 {
60808 - return __swab16p((__u16 *)p);
60809 + return __swab16p((const __u16 *)p);
60810 }
60811 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60812 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60813 diff --git a/include/linux/cache.h b/include/linux/cache.h
60814 index 4c57065..4307975 100644
60815 --- a/include/linux/cache.h
60816 +++ b/include/linux/cache.h
60817 @@ -16,6 +16,10 @@
60818 #define __read_mostly
60819 #endif
60820
60821 +#ifndef __read_only
60822 +#define __read_only __read_mostly
60823 +#endif
60824 +
60825 #ifndef ____cacheline_aligned
60826 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60827 #endif
60828 diff --git a/include/linux/capability.h b/include/linux/capability.h
60829 index d10b7ed..0288b79 100644
60830 --- a/include/linux/capability.h
60831 +++ b/include/linux/capability.h
60832 @@ -553,10 +553,15 @@ extern bool capable(int cap);
60833 extern bool ns_capable(struct user_namespace *ns, int cap);
60834 extern bool nsown_capable(int cap);
60835 extern bool inode_capable(const struct inode *inode, int cap);
60836 +extern bool capable_nolog(int cap);
60837 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60838 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
60839
60840 /* audit system wants to get cap info from files as well */
60841 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60842
60843 +extern int is_privileged_binary(const struct dentry *dentry);
60844 +
60845 #endif /* __KERNEL__ */
60846
60847 #endif /* !_LINUX_CAPABILITY_H */
60848 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60849 index 42e55de..1cd0e66 100644
60850 --- a/include/linux/cleancache.h
60851 +++ b/include/linux/cleancache.h
60852 @@ -31,7 +31,7 @@ struct cleancache_ops {
60853 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60854 void (*invalidate_inode)(int, struct cleancache_filekey);
60855 void (*invalidate_fs)(int);
60856 -};
60857 +} __no_const;
60858
60859 extern struct cleancache_ops
60860 cleancache_register_ops(struct cleancache_ops *ops);
60861 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60862 index 4a0b483..f1f70ba 100644
60863 --- a/include/linux/clk-provider.h
60864 +++ b/include/linux/clk-provider.h
60865 @@ -110,6 +110,7 @@ struct clk_ops {
60866 unsigned long);
60867 void (*init)(struct clk_hw *hw);
60868 };
60869 +typedef struct clk_ops __no_const clk_ops_no_const;
60870
60871 /**
60872 * struct clk_init_data - holds init data that's common to all clocks and is
60873 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60874 index 2f40791..9c9e13c 100644
60875 --- a/include/linux/compiler-gcc4.h
60876 +++ b/include/linux/compiler-gcc4.h
60877 @@ -32,6 +32,20 @@
60878 #define __linktime_error(message) __attribute__((__error__(message)))
60879
60880 #if __GNUC_MINOR__ >= 5
60881 +
60882 +#ifdef CONSTIFY_PLUGIN
60883 +#define __no_const __attribute__((no_const))
60884 +#define __do_const __attribute__((do_const))
60885 +#endif
60886 +
60887 +#ifdef SIZE_OVERFLOW_PLUGIN
60888 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60889 +#endif
60890 +
60891 +#ifdef LATENT_ENTROPY_PLUGIN
60892 +#define __latent_entropy __attribute__((latent_entropy))
60893 +#endif
60894 +
60895 /*
60896 * Mark a position in code as unreachable. This can be used to
60897 * suppress control flow warnings after asm blocks that transfer
60898 @@ -47,6 +61,11 @@
60899 #define __noclone __attribute__((__noclone__))
60900
60901 #endif
60902 +
60903 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60904 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60905 +#define __bos0(ptr) __bos((ptr), 0)
60906 +#define __bos1(ptr) __bos((ptr), 1)
60907 #endif
60908
60909 #if __GNUC_MINOR__ > 0
60910 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60911 index 923d093..1fef491 100644
60912 --- a/include/linux/compiler.h
60913 +++ b/include/linux/compiler.h
60914 @@ -5,31 +5,62 @@
60915
60916 #ifdef __CHECKER__
60917 # define __user __attribute__((noderef, address_space(1)))
60918 +# define __force_user __force __user
60919 # define __kernel __attribute__((address_space(0)))
60920 +# define __force_kernel __force __kernel
60921 # define __safe __attribute__((safe))
60922 # define __force __attribute__((force))
60923 # define __nocast __attribute__((nocast))
60924 # define __iomem __attribute__((noderef, address_space(2)))
60925 +# define __force_iomem __force __iomem
60926 # define __acquires(x) __attribute__((context(x,0,1)))
60927 # define __releases(x) __attribute__((context(x,1,0)))
60928 # define __acquire(x) __context__(x,1)
60929 # define __release(x) __context__(x,-1)
60930 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60931 # define __percpu __attribute__((noderef, address_space(3)))
60932 +# define __force_percpu __force __percpu
60933 #ifdef CONFIG_SPARSE_RCU_POINTER
60934 # define __rcu __attribute__((noderef, address_space(4)))
60935 +# define __force_rcu __force __rcu
60936 #else
60937 # define __rcu
60938 +# define __force_rcu
60939 #endif
60940 extern void __chk_user_ptr(const volatile void __user *);
60941 extern void __chk_io_ptr(const volatile void __iomem *);
60942 +#elif defined(CHECKER_PLUGIN)
60943 +//# define __user
60944 +//# define __force_user
60945 +//# define __kernel
60946 +//# define __force_kernel
60947 +# define __safe
60948 +# define __force
60949 +# define __nocast
60950 +# define __iomem
60951 +# define __force_iomem
60952 +# define __chk_user_ptr(x) (void)0
60953 +# define __chk_io_ptr(x) (void)0
60954 +# define __builtin_warning(x, y...) (1)
60955 +# define __acquires(x)
60956 +# define __releases(x)
60957 +# define __acquire(x) (void)0
60958 +# define __release(x) (void)0
60959 +# define __cond_lock(x,c) (c)
60960 +# define __percpu
60961 +# define __force_percpu
60962 +# define __rcu
60963 +# define __force_rcu
60964 #else
60965 # define __user
60966 +# define __force_user
60967 # define __kernel
60968 +# define __force_kernel
60969 # define __safe
60970 # define __force
60971 # define __nocast
60972 # define __iomem
60973 +# define __force_iomem
60974 # define __chk_user_ptr(x) (void)0
60975 # define __chk_io_ptr(x) (void)0
60976 # define __builtin_warning(x, y...) (1)
60977 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60978 # define __release(x) (void)0
60979 # define __cond_lock(x,c) (c)
60980 # define __percpu
60981 +# define __force_percpu
60982 # define __rcu
60983 +# define __force_rcu
60984 #endif
60985
60986 #ifdef __KERNEL__
60987 @@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60988 # define __attribute_const__ /* unimplemented */
60989 #endif
60990
60991 +#ifndef __no_const
60992 +# define __no_const
60993 +#endif
60994 +
60995 +#ifndef __do_const
60996 +# define __do_const
60997 +#endif
60998 +
60999 +#ifndef __size_overflow
61000 +# define __size_overflow(...)
61001 +#endif
61002 +
61003 +#ifndef __latent_entropy
61004 +# define __latent_entropy
61005 +#endif
61006 +
61007 /*
61008 * Tell gcc if a function is cold. The compiler will assume any path
61009 * directly leading to the call is unlikely.
61010 @@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61011 #define __cold
61012 #endif
61013
61014 +#ifndef __alloc_size
61015 +#define __alloc_size(...)
61016 +#endif
61017 +
61018 +#ifndef __bos
61019 +#define __bos(ptr, arg)
61020 +#endif
61021 +
61022 +#ifndef __bos0
61023 +#define __bos0(ptr)
61024 +#endif
61025 +
61026 +#ifndef __bos1
61027 +#define __bos1(ptr)
61028 +#endif
61029 +
61030 /* Simple shorthand for a section definition */
61031 #ifndef __section
61032 # define __section(S) __attribute__ ((__section__(#S)))
61033 @@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61034 * use is to mediate communication between process-level code and irq/NMI
61035 * handlers, all running on the same CPU.
61036 */
61037 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61038 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61039 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61040
61041 #endif /* __LINUX_COMPILER_H */
61042 diff --git a/include/linux/cred.h b/include/linux/cred.h
61043 index ebbed2c..908cc2c 100644
61044 --- a/include/linux/cred.h
61045 +++ b/include/linux/cred.h
61046 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61047 static inline void validate_process_creds(void)
61048 {
61049 }
61050 +static inline void validate_task_creds(struct task_struct *task)
61051 +{
61052 +}
61053 #endif
61054
61055 /**
61056 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61057 index b92eadf..b4ecdc1 100644
61058 --- a/include/linux/crypto.h
61059 +++ b/include/linux/crypto.h
61060 @@ -373,7 +373,7 @@ struct cipher_tfm {
61061 const u8 *key, unsigned int keylen);
61062 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61063 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61064 -};
61065 +} __no_const;
61066
61067 struct hash_tfm {
61068 int (*init)(struct hash_desc *desc);
61069 @@ -394,13 +394,13 @@ struct compress_tfm {
61070 int (*cot_decompress)(struct crypto_tfm *tfm,
61071 const u8 *src, unsigned int slen,
61072 u8 *dst, unsigned int *dlen);
61073 -};
61074 +} __no_const;
61075
61076 struct rng_tfm {
61077 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61078 unsigned int dlen);
61079 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61080 -};
61081 +} __no_const;
61082
61083 #define crt_ablkcipher crt_u.ablkcipher
61084 #define crt_aead crt_u.aead
61085 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61086 index 7925bf0..d5143d2 100644
61087 --- a/include/linux/decompress/mm.h
61088 +++ b/include/linux/decompress/mm.h
61089 @@ -77,7 +77,7 @@ static void free(void *where)
61090 * warnings when not needed (indeed large_malloc / large_free are not
61091 * needed by inflate */
61092
61093 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61094 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61095 #define free(a) kfree(a)
61096
61097 #define large_malloc(a) vmalloc(a)
61098 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61099 index dfc099e..e583e66 100644
61100 --- a/include/linux/dma-mapping.h
61101 +++ b/include/linux/dma-mapping.h
61102 @@ -51,7 +51,7 @@ struct dma_map_ops {
61103 u64 (*get_required_mask)(struct device *dev);
61104 #endif
61105 int is_phys;
61106 -};
61107 +} __do_const;
61108
61109 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61110
61111 diff --git a/include/linux/efi.h b/include/linux/efi.h
61112 index ec45ccd..9923c32 100644
61113 --- a/include/linux/efi.h
61114 +++ b/include/linux/efi.h
61115 @@ -635,7 +635,7 @@ struct efivar_operations {
61116 efi_get_variable_t *get_variable;
61117 efi_get_next_variable_t *get_next_variable;
61118 efi_set_variable_t *set_variable;
61119 -};
61120 +} __no_const;
61121
61122 struct efivars {
61123 /*
61124 diff --git a/include/linux/elf.h b/include/linux/elf.h
61125 index 999b4f5..57753b4 100644
61126 --- a/include/linux/elf.h
61127 +++ b/include/linux/elf.h
61128 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61129 #define PT_GNU_EH_FRAME 0x6474e550
61130
61131 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61132 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61133 +
61134 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61135 +
61136 +/* Constants for the e_flags field */
61137 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61138 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61139 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61140 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61141 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61142 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61143
61144 /*
61145 * Extended Numbering
61146 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61147 #define DT_DEBUG 21
61148 #define DT_TEXTREL 22
61149 #define DT_JMPREL 23
61150 +#define DT_FLAGS 30
61151 + #define DF_TEXTREL 0x00000004
61152 #define DT_ENCODING 32
61153 #define OLD_DT_LOOS 0x60000000
61154 #define DT_LOOS 0x6000000d
61155 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61156 #define PF_W 0x2
61157 #define PF_X 0x1
61158
61159 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61160 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61161 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61162 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61163 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61164 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61165 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61166 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61167 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61168 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61169 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61170 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61171 +
61172 typedef struct elf32_phdr{
61173 Elf32_Word p_type;
61174 Elf32_Off p_offset;
61175 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61176 #define EI_OSABI 7
61177 #define EI_PAD 8
61178
61179 +#define EI_PAX 14
61180 +
61181 #define ELFMAG0 0x7f /* EI_MAG */
61182 #define ELFMAG1 'E'
61183 #define ELFMAG2 'L'
61184 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61185 #define elf_note elf32_note
61186 #define elf_addr_t Elf32_Off
61187 #define Elf_Half Elf32_Half
61188 +#define elf_dyn Elf32_Dyn
61189
61190 #else
61191
61192 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61193 #define elf_note elf64_note
61194 #define elf_addr_t Elf64_Off
61195 #define Elf_Half Elf64_Half
61196 +#define elf_dyn Elf64_Dyn
61197
61198 #endif
61199
61200 diff --git a/include/linux/filter.h b/include/linux/filter.h
61201 index 82b0135..917914d 100644
61202 --- a/include/linux/filter.h
61203 +++ b/include/linux/filter.h
61204 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61205
61206 struct sk_buff;
61207 struct sock;
61208 +struct bpf_jit_work;
61209
61210 struct sk_filter
61211 {
61212 @@ -153,6 +154,9 @@ struct sk_filter
61213 unsigned int len; /* Number of filter blocks */
61214 unsigned int (*bpf_func)(const struct sk_buff *skb,
61215 const struct sock_filter *filter);
61216 +#ifdef CONFIG_BPF_JIT
61217 + struct bpf_jit_work *work;
61218 +#endif
61219 struct rcu_head rcu;
61220 struct sock_filter insns[0];
61221 };
61222 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61223 index 7edcf10..714d5e8 100644
61224 --- a/include/linux/firewire.h
61225 +++ b/include/linux/firewire.h
61226 @@ -430,7 +430,7 @@ struct fw_iso_context {
61227 union {
61228 fw_iso_callback_t sc;
61229 fw_iso_mc_callback_t mc;
61230 - } callback;
61231 + } __no_const callback;
61232 void *callback_data;
61233 };
61234
61235 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61236 index 0e4e2ee..4ff4312 100644
61237 --- a/include/linux/frontswap.h
61238 +++ b/include/linux/frontswap.h
61239 @@ -11,7 +11,7 @@ struct frontswap_ops {
61240 int (*load)(unsigned, pgoff_t, struct page *);
61241 void (*invalidate_page)(unsigned, pgoff_t);
61242 void (*invalidate_area)(unsigned);
61243 -};
61244 +} __no_const;
61245
61246 extern bool frontswap_enabled;
61247 extern struct frontswap_ops
61248 diff --git a/include/linux/fs.h b/include/linux/fs.h
61249 index 17fd887..8eebca0 100644
61250 --- a/include/linux/fs.h
61251 +++ b/include/linux/fs.h
61252 @@ -1663,7 +1663,8 @@ struct file_operations {
61253 int (*setlease)(struct file *, long, struct file_lock **);
61254 long (*fallocate)(struct file *file, int mode, loff_t offset,
61255 loff_t len);
61256 -};
61257 +} __do_const;
61258 +typedef struct file_operations __no_const file_operations_no_const;
61259
61260 struct inode_operations {
61261 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61262 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61263 index 003dc0f..3c4ea97 100644
61264 --- a/include/linux/fs_struct.h
61265 +++ b/include/linux/fs_struct.h
61266 @@ -6,7 +6,7 @@
61267 #include <linux/seqlock.h>
61268
61269 struct fs_struct {
61270 - int users;
61271 + atomic_t users;
61272 spinlock_t lock;
61273 seqcount_t seq;
61274 int umask;
61275 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61276 index ce31408..b1ad003 100644
61277 --- a/include/linux/fscache-cache.h
61278 +++ b/include/linux/fscache-cache.h
61279 @@ -102,7 +102,7 @@ struct fscache_operation {
61280 fscache_operation_release_t release;
61281 };
61282
61283 -extern atomic_t fscache_op_debug_id;
61284 +extern atomic_unchecked_t fscache_op_debug_id;
61285 extern void fscache_op_work_func(struct work_struct *work);
61286
61287 extern void fscache_enqueue_operation(struct fscache_operation *);
61288 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61289 {
61290 INIT_WORK(&op->work, fscache_op_work_func);
61291 atomic_set(&op->usage, 1);
61292 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61293 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61294 op->processor = processor;
61295 op->release = release;
61296 INIT_LIST_HEAD(&op->pend_link);
61297 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61298 index a6dfe69..569586df 100644
61299 --- a/include/linux/fsnotify.h
61300 +++ b/include/linux/fsnotify.h
61301 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61302 */
61303 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61304 {
61305 - return kstrdup(name, GFP_KERNEL);
61306 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61307 }
61308
61309 /*
61310 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61311 index 63d966d..cdcb717 100644
61312 --- a/include/linux/fsnotify_backend.h
61313 +++ b/include/linux/fsnotify_backend.h
61314 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61315 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61316 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61317 };
61318 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61319
61320 /*
61321 * A group is a "thing" that wants to receive notification about filesystem
61322 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61323 index 176a939..1462211 100644
61324 --- a/include/linux/ftrace_event.h
61325 +++ b/include/linux/ftrace_event.h
61326 @@ -97,7 +97,7 @@ struct trace_event_functions {
61327 trace_print_func raw;
61328 trace_print_func hex;
61329 trace_print_func binary;
61330 -};
61331 +} __no_const;
61332
61333 struct trace_event {
61334 struct hlist_node node;
61335 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61336 extern int trace_add_event_call(struct ftrace_event_call *call);
61337 extern void trace_remove_event_call(struct ftrace_event_call *call);
61338
61339 -#define is_signed_type(type) (((type)(-1)) < 0)
61340 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61341
61342 int trace_set_clr_event(const char *system, const char *event, int set);
61343
61344 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61345 index 017a7fb..33a8507 100644
61346 --- a/include/linux/genhd.h
61347 +++ b/include/linux/genhd.h
61348 @@ -185,7 +185,7 @@ struct gendisk {
61349 struct kobject *slave_dir;
61350
61351 struct timer_rand_state *random;
61352 - atomic_t sync_io; /* RAID */
61353 + atomic_unchecked_t sync_io; /* RAID */
61354 struct disk_events *ev;
61355 #ifdef CONFIG_BLK_DEV_INTEGRITY
61356 struct blk_integrity *integrity;
61357 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61358 index 1e49be4..b8a9305 100644
61359 --- a/include/linux/gfp.h
61360 +++ b/include/linux/gfp.h
61361 @@ -38,6 +38,12 @@ struct vm_area_struct;
61362 #define ___GFP_OTHER_NODE 0x800000u
61363 #define ___GFP_WRITE 0x1000000u
61364
61365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61366 +#define ___GFP_USERCOPY 0x2000000u
61367 +#else
61368 +#define ___GFP_USERCOPY 0
61369 +#endif
61370 +
61371 /*
61372 * GFP bitmasks..
61373 *
61374 @@ -87,6 +93,7 @@ struct vm_area_struct;
61375 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61376 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61377 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61378 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61379
61380 /*
61381 * This may seem redundant, but it's a way of annotating false positives vs.
61382 @@ -94,7 +101,7 @@ struct vm_area_struct;
61383 */
61384 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61385
61386 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61387 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61388 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61389
61390 /* This equals 0, but use constants in case they ever change */
61391 @@ -148,6 +155,8 @@ struct vm_area_struct;
61392 /* 4GB DMA on some platforms */
61393 #define GFP_DMA32 __GFP_DMA32
61394
61395 +#define GFP_USERCOPY __GFP_USERCOPY
61396 +
61397 /* Convert GFP flags to their corresponding migrate type */
61398 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61399 {
61400 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61401 new file mode 100644
61402 index 0000000..c938b1f
61403 --- /dev/null
61404 +++ b/include/linux/gracl.h
61405 @@ -0,0 +1,319 @@
61406 +#ifndef GR_ACL_H
61407 +#define GR_ACL_H
61408 +
61409 +#include <linux/grdefs.h>
61410 +#include <linux/resource.h>
61411 +#include <linux/capability.h>
61412 +#include <linux/dcache.h>
61413 +#include <asm/resource.h>
61414 +
61415 +/* Major status information */
61416 +
61417 +#define GR_VERSION "grsecurity 2.9.1"
61418 +#define GRSECURITY_VERSION 0x2901
61419 +
61420 +enum {
61421 + GR_SHUTDOWN = 0,
61422 + GR_ENABLE = 1,
61423 + GR_SPROLE = 2,
61424 + GR_RELOAD = 3,
61425 + GR_SEGVMOD = 4,
61426 + GR_STATUS = 5,
61427 + GR_UNSPROLE = 6,
61428 + GR_PASSSET = 7,
61429 + GR_SPROLEPAM = 8,
61430 +};
61431 +
61432 +/* Password setup definitions
61433 + * kernel/grhash.c */
61434 +enum {
61435 + GR_PW_LEN = 128,
61436 + GR_SALT_LEN = 16,
61437 + GR_SHA_LEN = 32,
61438 +};
61439 +
61440 +enum {
61441 + GR_SPROLE_LEN = 64,
61442 +};
61443 +
61444 +enum {
61445 + GR_NO_GLOB = 0,
61446 + GR_REG_GLOB,
61447 + GR_CREATE_GLOB
61448 +};
61449 +
61450 +#define GR_NLIMITS 32
61451 +
61452 +/* Begin Data Structures */
61453 +
61454 +struct sprole_pw {
61455 + unsigned char *rolename;
61456 + unsigned char salt[GR_SALT_LEN];
61457 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61458 +};
61459 +
61460 +struct name_entry {
61461 + __u32 key;
61462 + ino_t inode;
61463 + dev_t device;
61464 + char *name;
61465 + __u16 len;
61466 + __u8 deleted;
61467 + struct name_entry *prev;
61468 + struct name_entry *next;
61469 +};
61470 +
61471 +struct inodev_entry {
61472 + struct name_entry *nentry;
61473 + struct inodev_entry *prev;
61474 + struct inodev_entry *next;
61475 +};
61476 +
61477 +struct acl_role_db {
61478 + struct acl_role_label **r_hash;
61479 + __u32 r_size;
61480 +};
61481 +
61482 +struct inodev_db {
61483 + struct inodev_entry **i_hash;
61484 + __u32 i_size;
61485 +};
61486 +
61487 +struct name_db {
61488 + struct name_entry **n_hash;
61489 + __u32 n_size;
61490 +};
61491 +
61492 +struct crash_uid {
61493 + uid_t uid;
61494 + unsigned long expires;
61495 +};
61496 +
61497 +struct gr_hash_struct {
61498 + void **table;
61499 + void **nametable;
61500 + void *first;
61501 + __u32 table_size;
61502 + __u32 used_size;
61503 + int type;
61504 +};
61505 +
61506 +/* Userspace Grsecurity ACL data structures */
61507 +
61508 +struct acl_subject_label {
61509 + char *filename;
61510 + ino_t inode;
61511 + dev_t device;
61512 + __u32 mode;
61513 + kernel_cap_t cap_mask;
61514 + kernel_cap_t cap_lower;
61515 + kernel_cap_t cap_invert_audit;
61516 +
61517 + struct rlimit res[GR_NLIMITS];
61518 + __u32 resmask;
61519 +
61520 + __u8 user_trans_type;
61521 + __u8 group_trans_type;
61522 + uid_t *user_transitions;
61523 + gid_t *group_transitions;
61524 + __u16 user_trans_num;
61525 + __u16 group_trans_num;
61526 +
61527 + __u32 sock_families[2];
61528 + __u32 ip_proto[8];
61529 + __u32 ip_type;
61530 + struct acl_ip_label **ips;
61531 + __u32 ip_num;
61532 + __u32 inaddr_any_override;
61533 +
61534 + __u32 crashes;
61535 + unsigned long expires;
61536 +
61537 + struct acl_subject_label *parent_subject;
61538 + struct gr_hash_struct *hash;
61539 + struct acl_subject_label *prev;
61540 + struct acl_subject_label *next;
61541 +
61542 + struct acl_object_label **obj_hash;
61543 + __u32 obj_hash_size;
61544 + __u16 pax_flags;
61545 +};
61546 +
61547 +struct role_allowed_ip {
61548 + __u32 addr;
61549 + __u32 netmask;
61550 +
61551 + struct role_allowed_ip *prev;
61552 + struct role_allowed_ip *next;
61553 +};
61554 +
61555 +struct role_transition {
61556 + char *rolename;
61557 +
61558 + struct role_transition *prev;
61559 + struct role_transition *next;
61560 +};
61561 +
61562 +struct acl_role_label {
61563 + char *rolename;
61564 + uid_t uidgid;
61565 + __u16 roletype;
61566 +
61567 + __u16 auth_attempts;
61568 + unsigned long expires;
61569 +
61570 + struct acl_subject_label *root_label;
61571 + struct gr_hash_struct *hash;
61572 +
61573 + struct acl_role_label *prev;
61574 + struct acl_role_label *next;
61575 +
61576 + struct role_transition *transitions;
61577 + struct role_allowed_ip *allowed_ips;
61578 + uid_t *domain_children;
61579 + __u16 domain_child_num;
61580 +
61581 + umode_t umask;
61582 +
61583 + struct acl_subject_label **subj_hash;
61584 + __u32 subj_hash_size;
61585 +};
61586 +
61587 +struct user_acl_role_db {
61588 + struct acl_role_label **r_table;
61589 + __u32 num_pointers; /* Number of allocations to track */
61590 + __u32 num_roles; /* Number of roles */
61591 + __u32 num_domain_children; /* Number of domain children */
61592 + __u32 num_subjects; /* Number of subjects */
61593 + __u32 num_objects; /* Number of objects */
61594 +};
61595 +
61596 +struct acl_object_label {
61597 + char *filename;
61598 + ino_t inode;
61599 + dev_t device;
61600 + __u32 mode;
61601 +
61602 + struct acl_subject_label *nested;
61603 + struct acl_object_label *globbed;
61604 +
61605 + /* next two structures not used */
61606 +
61607 + struct acl_object_label *prev;
61608 + struct acl_object_label *next;
61609 +};
61610 +
61611 +struct acl_ip_label {
61612 + char *iface;
61613 + __u32 addr;
61614 + __u32 netmask;
61615 + __u16 low, high;
61616 + __u8 mode;
61617 + __u32 type;
61618 + __u32 proto[8];
61619 +
61620 + /* next two structures not used */
61621 +
61622 + struct acl_ip_label *prev;
61623 + struct acl_ip_label *next;
61624 +};
61625 +
61626 +struct gr_arg {
61627 + struct user_acl_role_db role_db;
61628 + unsigned char pw[GR_PW_LEN];
61629 + unsigned char salt[GR_SALT_LEN];
61630 + unsigned char sum[GR_SHA_LEN];
61631 + unsigned char sp_role[GR_SPROLE_LEN];
61632 + struct sprole_pw *sprole_pws;
61633 + dev_t segv_device;
61634 + ino_t segv_inode;
61635 + uid_t segv_uid;
61636 + __u16 num_sprole_pws;
61637 + __u16 mode;
61638 +};
61639 +
61640 +struct gr_arg_wrapper {
61641 + struct gr_arg *arg;
61642 + __u32 version;
61643 + __u32 size;
61644 +};
61645 +
61646 +struct subject_map {
61647 + struct acl_subject_label *user;
61648 + struct acl_subject_label *kernel;
61649 + struct subject_map *prev;
61650 + struct subject_map *next;
61651 +};
61652 +
61653 +struct acl_subj_map_db {
61654 + struct subject_map **s_hash;
61655 + __u32 s_size;
61656 +};
61657 +
61658 +/* End Data Structures Section */
61659 +
61660 +/* Hash functions generated by empirical testing by Brad Spengler
61661 + Makes good use of the low bits of the inode. Generally 0-1 times
61662 + in loop for successful match. 0-3 for unsuccessful match.
61663 + Shift/add algorithm with modulus of table size and an XOR*/
61664 +
61665 +static __inline__ unsigned int
61666 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61667 +{
61668 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61669 +}
61670 +
61671 + static __inline__ unsigned int
61672 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61673 +{
61674 + return ((const unsigned long)userp % sz);
61675 +}
61676 +
61677 +static __inline__ unsigned int
61678 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61679 +{
61680 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61681 +}
61682 +
61683 +static __inline__ unsigned int
61684 +nhash(const char *name, const __u16 len, const unsigned int sz)
61685 +{
61686 + return full_name_hash((const unsigned char *)name, len) % sz;
61687 +}
61688 +
61689 +#define FOR_EACH_ROLE_START(role) \
61690 + role = role_list; \
61691 + while (role) {
61692 +
61693 +#define FOR_EACH_ROLE_END(role) \
61694 + role = role->prev; \
61695 + }
61696 +
61697 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61698 + subj = NULL; \
61699 + iter = 0; \
61700 + while (iter < role->subj_hash_size) { \
61701 + if (subj == NULL) \
61702 + subj = role->subj_hash[iter]; \
61703 + if (subj == NULL) { \
61704 + iter++; \
61705 + continue; \
61706 + }
61707 +
61708 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61709 + subj = subj->next; \
61710 + if (subj == NULL) \
61711 + iter++; \
61712 + }
61713 +
61714 +
61715 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61716 + subj = role->hash->first; \
61717 + while (subj != NULL) {
61718 +
61719 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61720 + subj = subj->next; \
61721 + }
61722 +
61723 +#endif
61724 +
61725 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61726 new file mode 100644
61727 index 0000000..323ecf2
61728 --- /dev/null
61729 +++ b/include/linux/gralloc.h
61730 @@ -0,0 +1,9 @@
61731 +#ifndef __GRALLOC_H
61732 +#define __GRALLOC_H
61733 +
61734 +void acl_free_all(void);
61735 +int acl_alloc_stack_init(unsigned long size);
61736 +void *acl_alloc(unsigned long len);
61737 +void *acl_alloc_num(unsigned long num, unsigned long len);
61738 +
61739 +#endif
61740 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61741 new file mode 100644
61742 index 0000000..b30e9bc
61743 --- /dev/null
61744 +++ b/include/linux/grdefs.h
61745 @@ -0,0 +1,140 @@
61746 +#ifndef GRDEFS_H
61747 +#define GRDEFS_H
61748 +
61749 +/* Begin grsecurity status declarations */
61750 +
61751 +enum {
61752 + GR_READY = 0x01,
61753 + GR_STATUS_INIT = 0x00 // disabled state
61754 +};
61755 +
61756 +/* Begin ACL declarations */
61757 +
61758 +/* Role flags */
61759 +
61760 +enum {
61761 + GR_ROLE_USER = 0x0001,
61762 + GR_ROLE_GROUP = 0x0002,
61763 + GR_ROLE_DEFAULT = 0x0004,
61764 + GR_ROLE_SPECIAL = 0x0008,
61765 + GR_ROLE_AUTH = 0x0010,
61766 + GR_ROLE_NOPW = 0x0020,
61767 + GR_ROLE_GOD = 0x0040,
61768 + GR_ROLE_LEARN = 0x0080,
61769 + GR_ROLE_TPE = 0x0100,
61770 + GR_ROLE_DOMAIN = 0x0200,
61771 + GR_ROLE_PAM = 0x0400,
61772 + GR_ROLE_PERSIST = 0x0800
61773 +};
61774 +
61775 +/* ACL Subject and Object mode flags */
61776 +enum {
61777 + GR_DELETED = 0x80000000
61778 +};
61779 +
61780 +/* ACL Object-only mode flags */
61781 +enum {
61782 + GR_READ = 0x00000001,
61783 + GR_APPEND = 0x00000002,
61784 + GR_WRITE = 0x00000004,
61785 + GR_EXEC = 0x00000008,
61786 + GR_FIND = 0x00000010,
61787 + GR_INHERIT = 0x00000020,
61788 + GR_SETID = 0x00000040,
61789 + GR_CREATE = 0x00000080,
61790 + GR_DELETE = 0x00000100,
61791 + GR_LINK = 0x00000200,
61792 + GR_AUDIT_READ = 0x00000400,
61793 + GR_AUDIT_APPEND = 0x00000800,
61794 + GR_AUDIT_WRITE = 0x00001000,
61795 + GR_AUDIT_EXEC = 0x00002000,
61796 + GR_AUDIT_FIND = 0x00004000,
61797 + GR_AUDIT_INHERIT= 0x00008000,
61798 + GR_AUDIT_SETID = 0x00010000,
61799 + GR_AUDIT_CREATE = 0x00020000,
61800 + GR_AUDIT_DELETE = 0x00040000,
61801 + GR_AUDIT_LINK = 0x00080000,
61802 + GR_PTRACERD = 0x00100000,
61803 + GR_NOPTRACE = 0x00200000,
61804 + GR_SUPPRESS = 0x00400000,
61805 + GR_NOLEARN = 0x00800000,
61806 + GR_INIT_TRANSFER= 0x01000000
61807 +};
61808 +
61809 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61810 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61811 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61812 +
61813 +/* ACL subject-only mode flags */
61814 +enum {
61815 + GR_KILL = 0x00000001,
61816 + GR_VIEW = 0x00000002,
61817 + GR_PROTECTED = 0x00000004,
61818 + GR_LEARN = 0x00000008,
61819 + GR_OVERRIDE = 0x00000010,
61820 + /* just a placeholder, this mode is only used in userspace */
61821 + GR_DUMMY = 0x00000020,
61822 + GR_PROTSHM = 0x00000040,
61823 + GR_KILLPROC = 0x00000080,
61824 + GR_KILLIPPROC = 0x00000100,
61825 + /* just a placeholder, this mode is only used in userspace */
61826 + GR_NOTROJAN = 0x00000200,
61827 + GR_PROTPROCFD = 0x00000400,
61828 + GR_PROCACCT = 0x00000800,
61829 + GR_RELAXPTRACE = 0x00001000,
61830 + GR_NESTED = 0x00002000,
61831 + GR_INHERITLEARN = 0x00004000,
61832 + GR_PROCFIND = 0x00008000,
61833 + GR_POVERRIDE = 0x00010000,
61834 + GR_KERNELAUTH = 0x00020000,
61835 + GR_ATSECURE = 0x00040000,
61836 + GR_SHMEXEC = 0x00080000
61837 +};
61838 +
61839 +enum {
61840 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61841 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61842 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61843 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61844 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61845 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61846 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61847 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61848 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61849 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61850 +};
61851 +
61852 +enum {
61853 + GR_ID_USER = 0x01,
61854 + GR_ID_GROUP = 0x02,
61855 +};
61856 +
61857 +enum {
61858 + GR_ID_ALLOW = 0x01,
61859 + GR_ID_DENY = 0x02,
61860 +};
61861 +
61862 +#define GR_CRASH_RES 31
61863 +#define GR_UIDTABLE_MAX 500
61864 +
61865 +/* begin resource learning section */
61866 +enum {
61867 + GR_RLIM_CPU_BUMP = 60,
61868 + GR_RLIM_FSIZE_BUMP = 50000,
61869 + GR_RLIM_DATA_BUMP = 10000,
61870 + GR_RLIM_STACK_BUMP = 1000,
61871 + GR_RLIM_CORE_BUMP = 10000,
61872 + GR_RLIM_RSS_BUMP = 500000,
61873 + GR_RLIM_NPROC_BUMP = 1,
61874 + GR_RLIM_NOFILE_BUMP = 5,
61875 + GR_RLIM_MEMLOCK_BUMP = 50000,
61876 + GR_RLIM_AS_BUMP = 500000,
61877 + GR_RLIM_LOCKS_BUMP = 2,
61878 + GR_RLIM_SIGPENDING_BUMP = 5,
61879 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61880 + GR_RLIM_NICE_BUMP = 1,
61881 + GR_RLIM_RTPRIO_BUMP = 1,
61882 + GR_RLIM_RTTIME_BUMP = 1000000
61883 +};
61884 +
61885 +#endif
61886 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61887 new file mode 100644
61888 index 0000000..c9292f7
61889 --- /dev/null
61890 +++ b/include/linux/grinternal.h
61891 @@ -0,0 +1,223 @@
61892 +#ifndef __GRINTERNAL_H
61893 +#define __GRINTERNAL_H
61894 +
61895 +#ifdef CONFIG_GRKERNSEC
61896 +
61897 +#include <linux/fs.h>
61898 +#include <linux/mnt_namespace.h>
61899 +#include <linux/nsproxy.h>
61900 +#include <linux/gracl.h>
61901 +#include <linux/grdefs.h>
61902 +#include <linux/grmsg.h>
61903 +
61904 +void gr_add_learn_entry(const char *fmt, ...)
61905 + __attribute__ ((format (printf, 1, 2)));
61906 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61907 + const struct vfsmount *mnt);
61908 +__u32 gr_check_create(const struct dentry *new_dentry,
61909 + const struct dentry *parent,
61910 + const struct vfsmount *mnt, const __u32 mode);
61911 +int gr_check_protected_task(const struct task_struct *task);
61912 +__u32 to_gr_audit(const __u32 reqmode);
61913 +int gr_set_acls(const int type);
61914 +int gr_apply_subject_to_task(struct task_struct *task);
61915 +int gr_acl_is_enabled(void);
61916 +char gr_roletype_to_char(void);
61917 +
61918 +void gr_handle_alertkill(struct task_struct *task);
61919 +char *gr_to_filename(const struct dentry *dentry,
61920 + const struct vfsmount *mnt);
61921 +char *gr_to_filename1(const struct dentry *dentry,
61922 + const struct vfsmount *mnt);
61923 +char *gr_to_filename2(const struct dentry *dentry,
61924 + const struct vfsmount *mnt);
61925 +char *gr_to_filename3(const struct dentry *dentry,
61926 + const struct vfsmount *mnt);
61927 +
61928 +extern int grsec_enable_ptrace_readexec;
61929 +extern int grsec_enable_harden_ptrace;
61930 +extern int grsec_enable_link;
61931 +extern int grsec_enable_fifo;
61932 +extern int grsec_enable_execve;
61933 +extern int grsec_enable_shm;
61934 +extern int grsec_enable_execlog;
61935 +extern int grsec_enable_signal;
61936 +extern int grsec_enable_audit_ptrace;
61937 +extern int grsec_enable_forkfail;
61938 +extern int grsec_enable_time;
61939 +extern int grsec_enable_rofs;
61940 +extern int grsec_enable_chroot_shmat;
61941 +extern int grsec_enable_chroot_mount;
61942 +extern int grsec_enable_chroot_double;
61943 +extern int grsec_enable_chroot_pivot;
61944 +extern int grsec_enable_chroot_chdir;
61945 +extern int grsec_enable_chroot_chmod;
61946 +extern int grsec_enable_chroot_mknod;
61947 +extern int grsec_enable_chroot_fchdir;
61948 +extern int grsec_enable_chroot_nice;
61949 +extern int grsec_enable_chroot_execlog;
61950 +extern int grsec_enable_chroot_caps;
61951 +extern int grsec_enable_chroot_sysctl;
61952 +extern int grsec_enable_chroot_unix;
61953 +extern int grsec_enable_symlinkown;
61954 +extern int grsec_symlinkown_gid;
61955 +extern int grsec_enable_tpe;
61956 +extern int grsec_tpe_gid;
61957 +extern int grsec_enable_tpe_all;
61958 +extern int grsec_enable_tpe_invert;
61959 +extern int grsec_enable_socket_all;
61960 +extern int grsec_socket_all_gid;
61961 +extern int grsec_enable_socket_client;
61962 +extern int grsec_socket_client_gid;
61963 +extern int grsec_enable_socket_server;
61964 +extern int grsec_socket_server_gid;
61965 +extern int grsec_audit_gid;
61966 +extern int grsec_enable_group;
61967 +extern int grsec_enable_audit_textrel;
61968 +extern int grsec_enable_log_rwxmaps;
61969 +extern int grsec_enable_mount;
61970 +extern int grsec_enable_chdir;
61971 +extern int grsec_resource_logging;
61972 +extern int grsec_enable_blackhole;
61973 +extern int grsec_lastack_retries;
61974 +extern int grsec_enable_brute;
61975 +extern int grsec_lock;
61976 +
61977 +extern spinlock_t grsec_alert_lock;
61978 +extern unsigned long grsec_alert_wtime;
61979 +extern unsigned long grsec_alert_fyet;
61980 +
61981 +extern spinlock_t grsec_audit_lock;
61982 +
61983 +extern rwlock_t grsec_exec_file_lock;
61984 +
61985 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61986 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61987 + (tsk)->exec_file->f_vfsmnt) : "/")
61988 +
61989 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61990 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61991 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61992 +
61993 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61994 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61995 + (tsk)->exec_file->f_vfsmnt) : "/")
61996 +
61997 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61998 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61999 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62000 +
62001 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62002 +
62003 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62004 +
62005 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62006 + (task)->pid, (cred)->uid, \
62007 + (cred)->euid, (cred)->gid, (cred)->egid, \
62008 + gr_parent_task_fullpath(task), \
62009 + (task)->real_parent->comm, (task)->real_parent->pid, \
62010 + (pcred)->uid, (pcred)->euid, \
62011 + (pcred)->gid, (pcred)->egid
62012 +
62013 +#define GR_CHROOT_CAPS {{ \
62014 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62015 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62016 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62017 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62018 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62019 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62020 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62021 +
62022 +#define security_learn(normal_msg,args...) \
62023 +({ \
62024 + read_lock(&grsec_exec_file_lock); \
62025 + gr_add_learn_entry(normal_msg "\n", ## args); \
62026 + read_unlock(&grsec_exec_file_lock); \
62027 +})
62028 +
62029 +enum {
62030 + GR_DO_AUDIT,
62031 + GR_DONT_AUDIT,
62032 + /* used for non-audit messages that we shouldn't kill the task on */
62033 + GR_DONT_AUDIT_GOOD
62034 +};
62035 +
62036 +enum {
62037 + GR_TTYSNIFF,
62038 + GR_RBAC,
62039 + GR_RBAC_STR,
62040 + GR_STR_RBAC,
62041 + GR_RBAC_MODE2,
62042 + GR_RBAC_MODE3,
62043 + GR_FILENAME,
62044 + GR_SYSCTL_HIDDEN,
62045 + GR_NOARGS,
62046 + GR_ONE_INT,
62047 + GR_ONE_INT_TWO_STR,
62048 + GR_ONE_STR,
62049 + GR_STR_INT,
62050 + GR_TWO_STR_INT,
62051 + GR_TWO_INT,
62052 + GR_TWO_U64,
62053 + GR_THREE_INT,
62054 + GR_FIVE_INT_TWO_STR,
62055 + GR_TWO_STR,
62056 + GR_THREE_STR,
62057 + GR_FOUR_STR,
62058 + GR_STR_FILENAME,
62059 + GR_FILENAME_STR,
62060 + GR_FILENAME_TWO_INT,
62061 + GR_FILENAME_TWO_INT_STR,
62062 + GR_TEXTREL,
62063 + GR_PTRACE,
62064 + GR_RESOURCE,
62065 + GR_CAP,
62066 + GR_SIG,
62067 + GR_SIG2,
62068 + GR_CRASH1,
62069 + GR_CRASH2,
62070 + GR_PSACCT,
62071 + GR_RWXMAP
62072 +};
62073 +
62074 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62075 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62076 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62077 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62078 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62079 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62080 +#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)
62081 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62082 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62083 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62084 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62085 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62086 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62087 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62088 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62089 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62090 +#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)
62091 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62092 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62093 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62094 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62095 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62096 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62097 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62098 +#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)
62099 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62100 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62101 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62102 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62103 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62104 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62105 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62106 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62107 +#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)
62108 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62109 +
62110 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62111 +
62112 +#endif
62113 +
62114 +#endif
62115 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62116 new file mode 100644
62117 index 0000000..54f4e85
62118 --- /dev/null
62119 +++ b/include/linux/grmsg.h
62120 @@ -0,0 +1,110 @@
62121 +#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"
62122 +#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"
62123 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62124 +#define GR_STOPMOD_MSG "denied modification of module state by "
62125 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62126 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62127 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62128 +#define GR_IOPL_MSG "denied use of iopl() by "
62129 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62130 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62131 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62132 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62133 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62134 +#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"
62135 +#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"
62136 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62137 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62138 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62139 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62140 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62141 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62142 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62143 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62144 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62145 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62146 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62147 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62148 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62149 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62150 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62151 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62152 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62153 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62154 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62155 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62156 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62157 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62158 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62159 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62160 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62161 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62162 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62163 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62164 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62165 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62166 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62167 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62168 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62169 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62170 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62171 +#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"
62172 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62173 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62174 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62175 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62176 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62177 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62178 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62179 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62180 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62181 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62182 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62183 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62184 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62185 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62186 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62187 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62188 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62189 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62190 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62191 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62192 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62193 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62194 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62195 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62196 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62197 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62198 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62199 +#define GR_TIME_MSG "time set by "
62200 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62201 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62202 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62203 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62204 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62205 +#define GR_BIND_MSG "denied bind() by "
62206 +#define GR_CONNECT_MSG "denied connect() by "
62207 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62208 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62209 +#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"
62210 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62211 +#define GR_CAP_ACL_MSG "use of %s denied for "
62212 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62213 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62214 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62215 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62216 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62217 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62218 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62219 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62220 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62221 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62222 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62223 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62224 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62225 +#define GR_VM86_MSG "denied use of vm86 by "
62226 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62227 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62228 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62229 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62230 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62231 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62232 new file mode 100644
62233 index 0000000..38bfb04
62234 --- /dev/null
62235 +++ b/include/linux/grsecurity.h
62236 @@ -0,0 +1,233 @@
62237 +#ifndef GR_SECURITY_H
62238 +#define GR_SECURITY_H
62239 +#include <linux/fs.h>
62240 +#include <linux/fs_struct.h>
62241 +#include <linux/binfmts.h>
62242 +#include <linux/gracl.h>
62243 +
62244 +/* notify of brain-dead configs */
62245 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62246 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62247 +#endif
62248 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62249 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62250 +#endif
62251 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62252 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62253 +#endif
62254 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62255 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62256 +#endif
62257 +
62258 +#include <linux/compat.h>
62259 +
62260 +struct user_arg_ptr {
62261 +#ifdef CONFIG_COMPAT
62262 + bool is_compat;
62263 +#endif
62264 + union {
62265 + const char __user *const __user *native;
62266 +#ifdef CONFIG_COMPAT
62267 + compat_uptr_t __user *compat;
62268 +#endif
62269 + } ptr;
62270 +};
62271 +
62272 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62273 +void gr_handle_brute_check(void);
62274 +void gr_handle_kernel_exploit(void);
62275 +int gr_process_user_ban(void);
62276 +
62277 +char gr_roletype_to_char(void);
62278 +
62279 +int gr_acl_enable_at_secure(void);
62280 +
62281 +int gr_check_user_change(int real, int effective, int fs);
62282 +int gr_check_group_change(int real, int effective, int fs);
62283 +
62284 +void gr_del_task_from_ip_table(struct task_struct *p);
62285 +
62286 +int gr_pid_is_chrooted(struct task_struct *p);
62287 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62288 +int gr_handle_chroot_nice(void);
62289 +int gr_handle_chroot_sysctl(const int op);
62290 +int gr_handle_chroot_setpriority(struct task_struct *p,
62291 + const int niceval);
62292 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62293 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62294 + const struct vfsmount *mnt);
62295 +void gr_handle_chroot_chdir(struct path *path);
62296 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62297 + const struct vfsmount *mnt, const int mode);
62298 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62299 + const struct vfsmount *mnt, const int mode);
62300 +int gr_handle_chroot_mount(const struct dentry *dentry,
62301 + const struct vfsmount *mnt,
62302 + const char *dev_name);
62303 +int gr_handle_chroot_pivot(void);
62304 +int gr_handle_chroot_unix(const pid_t pid);
62305 +
62306 +int gr_handle_rawio(const struct inode *inode);
62307 +
62308 +void gr_handle_ioperm(void);
62309 +void gr_handle_iopl(void);
62310 +
62311 +umode_t gr_acl_umask(void);
62312 +
62313 +int gr_tpe_allow(const struct file *file);
62314 +
62315 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62316 +void gr_clear_chroot_entries(struct task_struct *task);
62317 +
62318 +void gr_log_forkfail(const int retval);
62319 +void gr_log_timechange(void);
62320 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62321 +void gr_log_chdir(const struct dentry *dentry,
62322 + const struct vfsmount *mnt);
62323 +void gr_log_chroot_exec(const struct dentry *dentry,
62324 + const struct vfsmount *mnt);
62325 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62326 +void gr_log_remount(const char *devname, const int retval);
62327 +void gr_log_unmount(const char *devname, const int retval);
62328 +void gr_log_mount(const char *from, const char *to, const int retval);
62329 +void gr_log_textrel(struct vm_area_struct *vma);
62330 +void gr_log_rwxmmap(struct file *file);
62331 +void gr_log_rwxmprotect(struct file *file);
62332 +
62333 +int gr_handle_follow_link(const struct inode *parent,
62334 + const struct inode *inode,
62335 + const struct dentry *dentry,
62336 + const struct vfsmount *mnt);
62337 +int gr_handle_fifo(const struct dentry *dentry,
62338 + const struct vfsmount *mnt,
62339 + const struct dentry *dir, const int flag,
62340 + const int acc_mode);
62341 +int gr_handle_hardlink(const struct dentry *dentry,
62342 + const struct vfsmount *mnt,
62343 + struct inode *inode,
62344 + const int mode, const char *to);
62345 +
62346 +int gr_is_capable(const int cap);
62347 +int gr_is_capable_nolog(const int cap);
62348 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62349 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62350 +
62351 +void gr_learn_resource(const struct task_struct *task, const int limit,
62352 + const unsigned long wanted, const int gt);
62353 +void gr_copy_label(struct task_struct *tsk);
62354 +void gr_handle_crash(struct task_struct *task, const int sig);
62355 +int gr_handle_signal(const struct task_struct *p, const int sig);
62356 +int gr_check_crash_uid(const uid_t uid);
62357 +int gr_check_protected_task(const struct task_struct *task);
62358 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62359 +int gr_acl_handle_mmap(const struct file *file,
62360 + const unsigned long prot);
62361 +int gr_acl_handle_mprotect(const struct file *file,
62362 + const unsigned long prot);
62363 +int gr_check_hidden_task(const struct task_struct *tsk);
62364 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62365 + const struct vfsmount *mnt);
62366 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62367 + const struct vfsmount *mnt);
62368 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62369 + const struct vfsmount *mnt, const int fmode);
62370 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62371 + const struct vfsmount *mnt, umode_t *mode);
62372 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62373 + const struct vfsmount *mnt);
62374 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62375 + const struct vfsmount *mnt);
62376 +int gr_handle_ptrace(struct task_struct *task, const long request);
62377 +int gr_handle_proc_ptrace(struct task_struct *task);
62378 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62379 + const struct vfsmount *mnt);
62380 +int gr_check_crash_exec(const struct file *filp);
62381 +int gr_acl_is_enabled(void);
62382 +void gr_set_kernel_label(struct task_struct *task);
62383 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62384 + const gid_t gid);
62385 +int gr_set_proc_label(const struct dentry *dentry,
62386 + const struct vfsmount *mnt,
62387 + const int unsafe_flags);
62388 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62389 + const struct vfsmount *mnt);
62390 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62391 + const struct vfsmount *mnt, int acc_mode);
62392 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62393 + const struct dentry *p_dentry,
62394 + const struct vfsmount *p_mnt,
62395 + int open_flags, int acc_mode, const int imode);
62396 +void gr_handle_create(const struct dentry *dentry,
62397 + const struct vfsmount *mnt);
62398 +void gr_handle_proc_create(const struct dentry *dentry,
62399 + const struct inode *inode);
62400 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62401 + const struct dentry *parent_dentry,
62402 + const struct vfsmount *parent_mnt,
62403 + const int mode);
62404 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62405 + const struct dentry *parent_dentry,
62406 + const struct vfsmount *parent_mnt);
62407 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62408 + const struct vfsmount *mnt);
62409 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62410 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62411 + const struct vfsmount *mnt);
62412 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62413 + const struct dentry *parent_dentry,
62414 + const struct vfsmount *parent_mnt,
62415 + const char *from);
62416 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62417 + const struct dentry *parent_dentry,
62418 + const struct vfsmount *parent_mnt,
62419 + const struct dentry *old_dentry,
62420 + const struct vfsmount *old_mnt, const char *to);
62421 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62422 +int gr_acl_handle_rename(struct dentry *new_dentry,
62423 + struct dentry *parent_dentry,
62424 + const struct vfsmount *parent_mnt,
62425 + struct dentry *old_dentry,
62426 + struct inode *old_parent_inode,
62427 + struct vfsmount *old_mnt, const char *newname);
62428 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62429 + struct dentry *old_dentry,
62430 + struct dentry *new_dentry,
62431 + struct vfsmount *mnt, const __u8 replace);
62432 +__u32 gr_check_link(const struct dentry *new_dentry,
62433 + const struct dentry *parent_dentry,
62434 + const struct vfsmount *parent_mnt,
62435 + const struct dentry *old_dentry,
62436 + const struct vfsmount *old_mnt);
62437 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62438 + const unsigned int namelen, const ino_t ino);
62439 +
62440 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62441 + const struct vfsmount *mnt);
62442 +void gr_acl_handle_exit(void);
62443 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62444 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62445 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62446 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62447 +void gr_audit_ptrace(struct task_struct *task);
62448 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62449 +
62450 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62451 +
62452 +#ifdef CONFIG_GRKERNSEC
62453 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62454 +void gr_handle_vm86(void);
62455 +void gr_handle_mem_readwrite(u64 from, u64 to);
62456 +
62457 +void gr_log_badprocpid(const char *entry);
62458 +
62459 +extern int grsec_enable_dmesg;
62460 +extern int grsec_disable_privio;
62461 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62462 +extern int grsec_enable_chroot_findtask;
62463 +#endif
62464 +#ifdef CONFIG_GRKERNSEC_SETXID
62465 +extern int grsec_enable_setxid;
62466 +#endif
62467 +#endif
62468 +
62469 +#endif
62470 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62471 new file mode 100644
62472 index 0000000..e7ffaaf
62473 --- /dev/null
62474 +++ b/include/linux/grsock.h
62475 @@ -0,0 +1,19 @@
62476 +#ifndef __GRSOCK_H
62477 +#define __GRSOCK_H
62478 +
62479 +extern void gr_attach_curr_ip(const struct sock *sk);
62480 +extern int gr_handle_sock_all(const int family, const int type,
62481 + const int protocol);
62482 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62483 +extern int gr_handle_sock_server_other(const struct sock *sck);
62484 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62485 +extern int gr_search_connect(struct socket * sock,
62486 + struct sockaddr_in * addr);
62487 +extern int gr_search_bind(struct socket * sock,
62488 + struct sockaddr_in * addr);
62489 +extern int gr_search_listen(struct socket * sock);
62490 +extern int gr_search_accept(struct socket * sock);
62491 +extern int gr_search_socket(const int domain, const int type,
62492 + const int protocol);
62493 +
62494 +#endif
62495 diff --git a/include/linux/hid.h b/include/linux/hid.h
62496 index 449fa38..b37c8cc 100644
62497 --- a/include/linux/hid.h
62498 +++ b/include/linux/hid.h
62499 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62500 unsigned int code, int value);
62501
62502 int (*parse)(struct hid_device *hdev);
62503 -};
62504 +} __no_const;
62505
62506 #define PM_HINT_FULLON 1<<5
62507 #define PM_HINT_NORMAL 1<<1
62508 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62509 index d3999b4..1304cb4 100644
62510 --- a/include/linux/highmem.h
62511 +++ b/include/linux/highmem.h
62512 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62513 kunmap_atomic(kaddr);
62514 }
62515
62516 +static inline void sanitize_highpage(struct page *page)
62517 +{
62518 + void *kaddr;
62519 + unsigned long flags;
62520 +
62521 + local_irq_save(flags);
62522 + kaddr = kmap_atomic(page);
62523 + clear_page(kaddr);
62524 + kunmap_atomic(kaddr);
62525 + local_irq_restore(flags);
62526 +}
62527 +
62528 static inline void zero_user_segments(struct page *page,
62529 unsigned start1, unsigned end1,
62530 unsigned start2, unsigned end2)
62531 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62532 index ddfa041..a44cfff 100644
62533 --- a/include/linux/i2c.h
62534 +++ b/include/linux/i2c.h
62535 @@ -366,6 +366,7 @@ struct i2c_algorithm {
62536 /* To determine what the adapter supports */
62537 u32 (*functionality) (struct i2c_adapter *);
62538 };
62539 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62540
62541 /*
62542 * i2c_adapter is the structure used to identify a physical i2c bus along
62543 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62544 index d23c3c2..eb63c81 100644
62545 --- a/include/linux/i2o.h
62546 +++ b/include/linux/i2o.h
62547 @@ -565,7 +565,7 @@ struct i2o_controller {
62548 struct i2o_device *exec; /* Executive */
62549 #if BITS_PER_LONG == 64
62550 spinlock_t context_list_lock; /* lock for context_list */
62551 - atomic_t context_list_counter; /* needed for unique contexts */
62552 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62553 struct list_head context_list; /* list of context id's
62554 and pointers */
62555 #endif
62556 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62557 index 8185f57..7b2d222 100644
62558 --- a/include/linux/if_team.h
62559 +++ b/include/linux/if_team.h
62560 @@ -74,6 +74,7 @@ struct team_mode_ops {
62561 void (*port_leave)(struct team *team, struct team_port *port);
62562 void (*port_change_mac)(struct team *team, struct team_port *port);
62563 };
62564 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62565
62566 enum team_option_type {
62567 TEAM_OPTION_TYPE_U32,
62568 @@ -136,7 +137,7 @@ struct team {
62569 struct list_head option_inst_list; /* list of option instances */
62570
62571 const struct team_mode *mode;
62572 - struct team_mode_ops ops;
62573 + team_mode_ops_no_const ops;
62574 long mode_priv[TEAM_MODE_PRIV_LONGS];
62575 };
62576
62577 diff --git a/include/linux/init.h b/include/linux/init.h
62578 index 6b95109..7616d09 100644
62579 --- a/include/linux/init.h
62580 +++ b/include/linux/init.h
62581 @@ -39,9 +39,15 @@
62582 * Also note, that this data cannot be "const".
62583 */
62584
62585 +#ifdef MODULE
62586 +#define add_latent_entropy
62587 +#else
62588 +#define add_latent_entropy __latent_entropy
62589 +#endif
62590 +
62591 /* These are for everybody (although not all archs will actually
62592 discard it in modules) */
62593 -#define __init __section(.init.text) __cold notrace
62594 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62595 #define __initdata __section(.init.data)
62596 #define __initconst __section(.init.rodata)
62597 #define __exitdata __section(.exit.data)
62598 @@ -83,7 +89,7 @@
62599 #define __exit __section(.exit.text) __exitused __cold notrace
62600
62601 /* Used for HOTPLUG */
62602 -#define __devinit __section(.devinit.text) __cold notrace
62603 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62604 #define __devinitdata __section(.devinit.data)
62605 #define __devinitconst __section(.devinit.rodata)
62606 #define __devexit __section(.devexit.text) __exitused __cold notrace
62607 @@ -91,7 +97,7 @@
62608 #define __devexitconst __section(.devexit.rodata)
62609
62610 /* Used for HOTPLUG_CPU */
62611 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62612 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62613 #define __cpuinitdata __section(.cpuinit.data)
62614 #define __cpuinitconst __section(.cpuinit.rodata)
62615 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62616 @@ -99,7 +105,7 @@
62617 #define __cpuexitconst __section(.cpuexit.rodata)
62618
62619 /* Used for MEMORY_HOTPLUG */
62620 -#define __meminit __section(.meminit.text) __cold notrace
62621 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62622 #define __meminitdata __section(.meminit.data)
62623 #define __meminitconst __section(.meminit.rodata)
62624 #define __memexit __section(.memexit.text) __exitused __cold notrace
62625 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62626 index 9e65eff..b131e8b 100644
62627 --- a/include/linux/init_task.h
62628 +++ b/include/linux/init_task.h
62629 @@ -134,6 +134,12 @@ extern struct cred init_cred;
62630
62631 #define INIT_TASK_COMM "swapper"
62632
62633 +#ifdef CONFIG_X86
62634 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62635 +#else
62636 +#define INIT_TASK_THREAD_INFO
62637 +#endif
62638 +
62639 /*
62640 * INIT_TASK is used to set up the first task table, touch at
62641 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62642 @@ -172,6 +178,7 @@ extern struct cred init_cred;
62643 RCU_INIT_POINTER(.cred, &init_cred), \
62644 .comm = INIT_TASK_COMM, \
62645 .thread = INIT_THREAD, \
62646 + INIT_TASK_THREAD_INFO \
62647 .fs = &init_fs, \
62648 .files = &init_files, \
62649 .signal = &init_signals, \
62650 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62651 index e6ca56d..8583707 100644
62652 --- a/include/linux/intel-iommu.h
62653 +++ b/include/linux/intel-iommu.h
62654 @@ -296,7 +296,7 @@ struct iommu_flush {
62655 u8 fm, u64 type);
62656 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62657 unsigned int size_order, u64 type);
62658 -};
62659 +} __no_const;
62660
62661 enum {
62662 SR_DMAR_FECTL_REG,
62663 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62664 index e68a8e5..811b9af 100644
62665 --- a/include/linux/interrupt.h
62666 +++ b/include/linux/interrupt.h
62667 @@ -435,7 +435,7 @@ enum
62668 /* map softirq index to softirq name. update 'softirq_to_name' in
62669 * kernel/softirq.c when adding a new softirq.
62670 */
62671 -extern char *softirq_to_name[NR_SOFTIRQS];
62672 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62673
62674 /* softirq mask and active fields moved to irq_cpustat_t in
62675 * asm/hardirq.h to get better cache usage. KAO
62676 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62677
62678 struct softirq_action
62679 {
62680 - void (*action)(struct softirq_action *);
62681 + void (*action)(void);
62682 };
62683
62684 asmlinkage void do_softirq(void);
62685 asmlinkage void __do_softirq(void);
62686 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62687 +extern void open_softirq(int nr, void (*action)(void));
62688 extern void softirq_init(void);
62689 extern void __raise_softirq_irqoff(unsigned int nr);
62690
62691 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62692 index 6883e19..06992b1 100644
62693 --- a/include/linux/kallsyms.h
62694 +++ b/include/linux/kallsyms.h
62695 @@ -15,7 +15,8 @@
62696
62697 struct module;
62698
62699 -#ifdef CONFIG_KALLSYMS
62700 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62701 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62702 /* Lookup the address for a symbol. Returns 0 if not found. */
62703 unsigned long kallsyms_lookup_name(const char *name);
62704
62705 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62706 /* Stupid that this does nothing, but I didn't create this mess. */
62707 #define __print_symbol(fmt, addr)
62708 #endif /*CONFIG_KALLSYMS*/
62709 +#else /* when included by kallsyms.c, vsnprintf.c, or
62710 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62711 +extern void __print_symbol(const char *fmt, unsigned long address);
62712 +extern int sprint_backtrace(char *buffer, unsigned long address);
62713 +extern int sprint_symbol(char *buffer, unsigned long address);
62714 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62715 +const char *kallsyms_lookup(unsigned long addr,
62716 + unsigned long *symbolsize,
62717 + unsigned long *offset,
62718 + char **modname, char *namebuf);
62719 +#endif
62720
62721 /* This macro allows us to keep printk typechecking */
62722 static __printf(1, 2)
62723 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62724 index c4d2fc1..5df9c19 100644
62725 --- a/include/linux/kgdb.h
62726 +++ b/include/linux/kgdb.h
62727 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62728 extern int kgdb_io_module_registered;
62729
62730 extern atomic_t kgdb_setting_breakpoint;
62731 -extern atomic_t kgdb_cpu_doing_single_step;
62732 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62733
62734 extern struct task_struct *kgdb_usethread;
62735 extern struct task_struct *kgdb_contthread;
62736 @@ -252,7 +252,7 @@ struct kgdb_arch {
62737 void (*disable_hw_break)(struct pt_regs *regs);
62738 void (*remove_all_hw_break)(void);
62739 void (*correct_hw_break)(void);
62740 -};
62741 +} __do_const;
62742
62743 /**
62744 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62745 @@ -277,7 +277,7 @@ struct kgdb_io {
62746 void (*pre_exception) (void);
62747 void (*post_exception) (void);
62748 int is_console;
62749 -};
62750 +} __do_const;
62751
62752 extern struct kgdb_arch arch_kgdb_ops;
62753
62754 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62755 index 5398d58..5883a34 100644
62756 --- a/include/linux/kmod.h
62757 +++ b/include/linux/kmod.h
62758 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62759 * usually useless though. */
62760 extern __printf(2, 3)
62761 int __request_module(bool wait, const char *name, ...);
62762 +extern __printf(3, 4)
62763 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62764 #define request_module(mod...) __request_module(true, mod)
62765 #define request_module_nowait(mod...) __request_module(false, mod)
62766 #define try_then_request_module(x, mod...) \
62767 diff --git a/include/linux/kref.h b/include/linux/kref.h
62768 index 9c07dce..a92fa71 100644
62769 --- a/include/linux/kref.h
62770 +++ b/include/linux/kref.h
62771 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62772 static inline int kref_sub(struct kref *kref, unsigned int count,
62773 void (*release)(struct kref *kref))
62774 {
62775 - WARN_ON(release == NULL);
62776 + BUG_ON(release == NULL);
62777
62778 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62779 release(kref);
62780 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62781 index 96c158a..1864db5 100644
62782 --- a/include/linux/kvm_host.h
62783 +++ b/include/linux/kvm_host.h
62784 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62785 void vcpu_load(struct kvm_vcpu *vcpu);
62786 void vcpu_put(struct kvm_vcpu *vcpu);
62787
62788 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62789 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62790 struct module *module);
62791 void kvm_exit(void);
62792
62793 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62794 struct kvm_guest_debug *dbg);
62795 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62796
62797 -int kvm_arch_init(void *opaque);
62798 +int kvm_arch_init(const void *opaque);
62799 void kvm_arch_exit(void);
62800
62801 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62802 diff --git a/include/linux/libata.h b/include/linux/libata.h
62803 index 6e887c7..4539601 100644
62804 --- a/include/linux/libata.h
62805 +++ b/include/linux/libata.h
62806 @@ -910,7 +910,7 @@ struct ata_port_operations {
62807 * fields must be pointers.
62808 */
62809 const struct ata_port_operations *inherits;
62810 -};
62811 +} __do_const;
62812
62813 struct ata_port_info {
62814 unsigned long flags;
62815 diff --git a/include/linux/memory.h b/include/linux/memory.h
62816 index 1ac7f6e..a5794d0 100644
62817 --- a/include/linux/memory.h
62818 +++ b/include/linux/memory.h
62819 @@ -143,7 +143,7 @@ struct memory_accessor {
62820 size_t count);
62821 ssize_t (*write)(struct memory_accessor *, const char *buf,
62822 off_t offset, size_t count);
62823 -};
62824 +} __no_const;
62825
62826 /*
62827 * Kernel text modification mutex, used for code patching. Users of this lock
62828 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62829 index 1318ca6..7521340 100644
62830 --- a/include/linux/mfd/abx500.h
62831 +++ b/include/linux/mfd/abx500.h
62832 @@ -452,6 +452,7 @@ struct abx500_ops {
62833 int (*event_registers_startup_state_get) (struct device *, u8 *);
62834 int (*startup_irq_enabled) (struct device *, unsigned int);
62835 };
62836 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62837
62838 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62839 void abx500_remove_ops(struct device *dev);
62840 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62841 index 9b07725..3d55001 100644
62842 --- a/include/linux/mfd/abx500/ux500_chargalg.h
62843 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
62844 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
62845 int (*enable) (struct ux500_charger *, int, int, int);
62846 int (*kick_wd) (struct ux500_charger *);
62847 int (*update_curr) (struct ux500_charger *, int);
62848 -};
62849 +} __no_const;
62850
62851 /**
62852 * struct ux500_charger - power supply ux500 charger sub class
62853 diff --git a/include/linux/mm.h b/include/linux/mm.h
62854 index f9f279c..198da78 100644
62855 --- a/include/linux/mm.h
62856 +++ b/include/linux/mm.h
62857 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62858
62859 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62860 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62861 +
62862 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62863 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62864 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62865 +#else
62866 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62867 +#endif
62868 +
62869 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62870 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62871
62872 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62873 int set_page_dirty_lock(struct page *page);
62874 int clear_page_dirty_for_io(struct page *page);
62875
62876 -/* Is the vma a continuation of the stack vma above it? */
62877 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62878 -{
62879 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62880 -}
62881 -
62882 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62883 - unsigned long addr)
62884 -{
62885 - return (vma->vm_flags & VM_GROWSDOWN) &&
62886 - (vma->vm_start == addr) &&
62887 - !vma_growsdown(vma->vm_prev, addr);
62888 -}
62889 -
62890 -/* Is the vma a continuation of the stack vma below it? */
62891 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62892 -{
62893 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62894 -}
62895 -
62896 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62897 - unsigned long addr)
62898 -{
62899 - return (vma->vm_flags & VM_GROWSUP) &&
62900 - (vma->vm_end == addr) &&
62901 - !vma_growsup(vma->vm_next, addr);
62902 -}
62903 -
62904 extern pid_t
62905 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62906
62907 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62908 }
62909 #endif
62910
62911 +#ifdef CONFIG_MMU
62912 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62913 +#else
62914 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62915 +{
62916 + return __pgprot(0);
62917 +}
62918 +#endif
62919 +
62920 int vma_wants_writenotify(struct vm_area_struct *vma);
62921
62922 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62923 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62924 {
62925 return 0;
62926 }
62927 +
62928 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62929 + unsigned long address)
62930 +{
62931 + return 0;
62932 +}
62933 #else
62934 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62935 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62936 #endif
62937
62938 #ifdef __PAGETABLE_PMD_FOLDED
62939 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62940 {
62941 return 0;
62942 }
62943 +
62944 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62945 + unsigned long address)
62946 +{
62947 + return 0;
62948 +}
62949 #else
62950 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62951 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62952 #endif
62953
62954 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62955 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62956 NULL: pud_offset(pgd, address);
62957 }
62958
62959 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62960 +{
62961 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62962 + NULL: pud_offset(pgd, address);
62963 +}
62964 +
62965 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62966 {
62967 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62968 NULL: pmd_offset(pud, address);
62969 }
62970 +
62971 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62972 +{
62973 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62974 + NULL: pmd_offset(pud, address);
62975 +}
62976 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62977
62978 #if USE_SPLIT_PTLOCKS
62979 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62980 unsigned long, unsigned long,
62981 unsigned long, unsigned long);
62982 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62983 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62984
62985 /* These take the mm semaphore themselves */
62986 extern unsigned long vm_brk(unsigned long, unsigned long);
62987 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62988 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62989 struct vm_area_struct **pprev);
62990
62991 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62992 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62993 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62994 +
62995 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62996 NULL if none. Assume start_addr < end_addr. */
62997 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62998 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62999 return vma;
63000 }
63001
63002 -#ifdef CONFIG_MMU
63003 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63004 -#else
63005 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63006 -{
63007 - return __pgprot(0);
63008 -}
63009 -#endif
63010 -
63011 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63012 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63013 unsigned long pfn, unsigned long size, pgprot_t);
63014 @@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
63015 extern int sysctl_memory_failure_early_kill;
63016 extern int sysctl_memory_failure_recovery;
63017 extern void shake_page(struct page *p, int access);
63018 -extern atomic_long_t mce_bad_pages;
63019 +extern atomic_long_unchecked_t mce_bad_pages;
63020 extern int soft_offline_page(struct page *page, int flags);
63021
63022 extern void dump_page(struct page *page);
63023 @@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63024 static inline bool page_is_guard(struct page *page) { return false; }
63025 #endif /* CONFIG_DEBUG_PAGEALLOC */
63026
63027 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63028 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63029 +#else
63030 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63031 +#endif
63032 +
63033 #endif /* __KERNEL__ */
63034 #endif /* _LINUX_MM_H */
63035 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63036 index 704a626..bb0705a 100644
63037 --- a/include/linux/mm_types.h
63038 +++ b/include/linux/mm_types.h
63039 @@ -263,6 +263,8 @@ struct vm_area_struct {
63040 #ifdef CONFIG_NUMA
63041 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63042 #endif
63043 +
63044 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63045 };
63046
63047 struct core_thread {
63048 @@ -337,7 +339,7 @@ struct mm_struct {
63049 unsigned long def_flags;
63050 unsigned long nr_ptes; /* Page table pages */
63051 unsigned long start_code, end_code, start_data, end_data;
63052 - unsigned long start_brk, brk, start_stack;
63053 + unsigned long brk_gap, start_brk, brk, start_stack;
63054 unsigned long arg_start, arg_end, env_start, env_end;
63055
63056 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63057 @@ -389,6 +391,24 @@ struct mm_struct {
63058 struct cpumask cpumask_allocation;
63059 #endif
63060 struct uprobes_state uprobes_state;
63061 +
63062 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63063 + unsigned long pax_flags;
63064 +#endif
63065 +
63066 +#ifdef CONFIG_PAX_DLRESOLVE
63067 + unsigned long call_dl_resolve;
63068 +#endif
63069 +
63070 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63071 + unsigned long call_syscall;
63072 +#endif
63073 +
63074 +#ifdef CONFIG_PAX_ASLR
63075 + unsigned long delta_mmap; /* randomized offset */
63076 + unsigned long delta_stack; /* randomized offset */
63077 +#endif
63078 +
63079 };
63080
63081 static inline void mm_init_cpumask(struct mm_struct *mm)
63082 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63083 index 1d1b1e1..2a13c78 100644
63084 --- a/include/linux/mmu_notifier.h
63085 +++ b/include/linux/mmu_notifier.h
63086 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63087 */
63088 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63089 ({ \
63090 - pte_t __pte; \
63091 + pte_t ___pte; \
63092 struct vm_area_struct *___vma = __vma; \
63093 unsigned long ___address = __address; \
63094 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63095 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63096 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63097 - __pte; \
63098 + ___pte; \
63099 })
63100
63101 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63102 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63103 index 68c569f..5f43753 100644
63104 --- a/include/linux/mmzone.h
63105 +++ b/include/linux/mmzone.h
63106 @@ -411,7 +411,7 @@ struct zone {
63107 unsigned long flags; /* zone flags, see below */
63108
63109 /* Zone statistics */
63110 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63111 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63112
63113 /*
63114 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63115 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63116 index 5db9382..50e801d 100644
63117 --- a/include/linux/mod_devicetable.h
63118 +++ b/include/linux/mod_devicetable.h
63119 @@ -12,7 +12,7 @@
63120 typedef unsigned long kernel_ulong_t;
63121 #endif
63122
63123 -#define PCI_ANY_ID (~0)
63124 +#define PCI_ANY_ID ((__u16)~0)
63125
63126 struct pci_device_id {
63127 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63128 @@ -131,7 +131,7 @@ struct usb_device_id {
63129 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63130 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63131
63132 -#define HID_ANY_ID (~0)
63133 +#define HID_ANY_ID (~0U)
63134 #define HID_BUS_ANY 0xffff
63135 #define HID_GROUP_ANY 0x0000
63136
63137 diff --git a/include/linux/module.h b/include/linux/module.h
63138 index fbcafe2..e5d9587 100644
63139 --- a/include/linux/module.h
63140 +++ b/include/linux/module.h
63141 @@ -17,6 +17,7 @@
63142 #include <linux/moduleparam.h>
63143 #include <linux/tracepoint.h>
63144 #include <linux/export.h>
63145 +#include <linux/fs.h>
63146
63147 #include <linux/percpu.h>
63148 #include <asm/module.h>
63149 @@ -273,19 +274,16 @@ struct module
63150 int (*init)(void);
63151
63152 /* If this is non-NULL, vfree after init() returns */
63153 - void *module_init;
63154 + void *module_init_rx, *module_init_rw;
63155
63156 /* Here is the actual code + data, vfree'd on unload. */
63157 - void *module_core;
63158 + void *module_core_rx, *module_core_rw;
63159
63160 /* Here are the sizes of the init and core sections */
63161 - unsigned int init_size, core_size;
63162 + unsigned int init_size_rw, core_size_rw;
63163
63164 /* The size of the executable code in each section. */
63165 - unsigned int init_text_size, core_text_size;
63166 -
63167 - /* Size of RO sections of the module (text+rodata) */
63168 - unsigned int init_ro_size, core_ro_size;
63169 + unsigned int init_size_rx, core_size_rx;
63170
63171 /* Arch-specific module values */
63172 struct mod_arch_specific arch;
63173 @@ -341,6 +339,10 @@ struct module
63174 #ifdef CONFIG_EVENT_TRACING
63175 struct ftrace_event_call **trace_events;
63176 unsigned int num_trace_events;
63177 + struct file_operations trace_id;
63178 + struct file_operations trace_enable;
63179 + struct file_operations trace_format;
63180 + struct file_operations trace_filter;
63181 #endif
63182 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63183 unsigned int num_ftrace_callsites;
63184 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63185 bool is_module_percpu_address(unsigned long addr);
63186 bool is_module_text_address(unsigned long addr);
63187
63188 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63189 +{
63190 +
63191 +#ifdef CONFIG_PAX_KERNEXEC
63192 + if (ktla_ktva(addr) >= (unsigned long)start &&
63193 + ktla_ktva(addr) < (unsigned long)start + size)
63194 + return 1;
63195 +#endif
63196 +
63197 + return ((void *)addr >= start && (void *)addr < start + size);
63198 +}
63199 +
63200 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63201 +{
63202 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63203 +}
63204 +
63205 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63206 +{
63207 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63208 +}
63209 +
63210 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63211 +{
63212 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63213 +}
63214 +
63215 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63216 +{
63217 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63218 +}
63219 +
63220 static inline int within_module_core(unsigned long addr, struct module *mod)
63221 {
63222 - return (unsigned long)mod->module_core <= addr &&
63223 - addr < (unsigned long)mod->module_core + mod->core_size;
63224 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63225 }
63226
63227 static inline int within_module_init(unsigned long addr, struct module *mod)
63228 {
63229 - return (unsigned long)mod->module_init <= addr &&
63230 - addr < (unsigned long)mod->module_init + mod->init_size;
63231 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63232 }
63233
63234 /* Search for module by name: must hold module_mutex. */
63235 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63236 index b2be02e..72d2f78 100644
63237 --- a/include/linux/moduleloader.h
63238 +++ b/include/linux/moduleloader.h
63239 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63240
63241 /* Allocator used for allocating struct module, core sections and init
63242 sections. Returns NULL on failure. */
63243 -void *module_alloc(unsigned long size);
63244 +void *module_alloc(unsigned long size) __size_overflow(1);
63245 +
63246 +#ifdef CONFIG_PAX_KERNEXEC
63247 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63248 +#else
63249 +#define module_alloc_exec(x) module_alloc(x)
63250 +#endif
63251
63252 /* Free memory returned from module_alloc. */
63253 void module_free(struct module *mod, void *module_region);
63254
63255 +#ifdef CONFIG_PAX_KERNEXEC
63256 +void module_free_exec(struct module *mod, void *module_region);
63257 +#else
63258 +#define module_free_exec(x, y) module_free((x), (y))
63259 +#endif
63260 +
63261 /* Apply the given relocation to the (simplified) ELF. Return -error
63262 or 0. */
63263 int apply_relocate(Elf_Shdr *sechdrs,
63264 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63265 index d6a5806..7c13347 100644
63266 --- a/include/linux/moduleparam.h
63267 +++ b/include/linux/moduleparam.h
63268 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63269 * @len is usually just sizeof(string).
63270 */
63271 #define module_param_string(name, string, len, perm) \
63272 - static const struct kparam_string __param_string_##name \
63273 + static const struct kparam_string __param_string_##name __used \
63274 = { len, string }; \
63275 __module_param_call(MODULE_PARAM_PREFIX, name, \
63276 &param_ops_string, \
63277 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63278 */
63279 #define module_param_array_named(name, array, type, nump, perm) \
63280 param_check_##type(name, &(array)[0]); \
63281 - static const struct kparam_array __param_arr_##name \
63282 + static const struct kparam_array __param_arr_##name __used \
63283 = { .max = ARRAY_SIZE(array), .num = nump, \
63284 .ops = &param_ops_##type, \
63285 .elemsize = sizeof(array[0]), .elem = array }; \
63286 diff --git a/include/linux/namei.h b/include/linux/namei.h
63287 index ffc0213..2c1f2cb 100644
63288 --- a/include/linux/namei.h
63289 +++ b/include/linux/namei.h
63290 @@ -24,7 +24,7 @@ struct nameidata {
63291 unsigned seq;
63292 int last_type;
63293 unsigned depth;
63294 - char *saved_names[MAX_NESTED_LINKS + 1];
63295 + const char *saved_names[MAX_NESTED_LINKS + 1];
63296
63297 /* Intent data */
63298 union {
63299 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63300 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63301 extern void unlock_rename(struct dentry *, struct dentry *);
63302
63303 -static inline void nd_set_link(struct nameidata *nd, char *path)
63304 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63305 {
63306 nd->saved_names[nd->depth] = path;
63307 }
63308
63309 -static inline char *nd_get_link(struct nameidata *nd)
63310 +static inline const char *nd_get_link(const struct nameidata *nd)
63311 {
63312 return nd->saved_names[nd->depth];
63313 }
63314 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63315 index d94cb14..e64c951 100644
63316 --- a/include/linux/netdevice.h
63317 +++ b/include/linux/netdevice.h
63318 @@ -1026,6 +1026,7 @@ struct net_device_ops {
63319 struct net_device *dev,
63320 int idx);
63321 };
63322 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63323
63324 /*
63325 * The DEVICE structure.
63326 @@ -1087,7 +1088,7 @@ struct net_device {
63327 int iflink;
63328
63329 struct net_device_stats stats;
63330 - atomic_long_t rx_dropped; /* dropped packets by core network
63331 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63332 * Do not use this in drivers.
63333 */
63334
63335 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63336 new file mode 100644
63337 index 0000000..33f4af8
63338 --- /dev/null
63339 +++ b/include/linux/netfilter/xt_gradm.h
63340 @@ -0,0 +1,9 @@
63341 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63342 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63343 +
63344 +struct xt_gradm_mtinfo {
63345 + __u16 flags;
63346 + __u16 invflags;
63347 +};
63348 +
63349 +#endif
63350 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63351 index c65a18a..0c05f3a 100644
63352 --- a/include/linux/of_pdt.h
63353 +++ b/include/linux/of_pdt.h
63354 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63355
63356 /* return 0 on success; fill in 'len' with number of bytes in path */
63357 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63358 -};
63359 +} __no_const;
63360
63361 extern void *prom_early_alloc(unsigned long size);
63362
63363 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63364 index a4c5624..79d6d88 100644
63365 --- a/include/linux/oprofile.h
63366 +++ b/include/linux/oprofile.h
63367 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63368 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63369 char const * name, ulong * val);
63370
63371 -/** Create a file for read-only access to an atomic_t. */
63372 +/** Create a file for read-only access to an atomic_unchecked_t. */
63373 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63374 - char const * name, atomic_t * val);
63375 + char const * name, atomic_unchecked_t * val);
63376
63377 /** create a directory */
63378 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63379 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63380 index 45db49f..386788e 100644
63381 --- a/include/linux/perf_event.h
63382 +++ b/include/linux/perf_event.h
63383 @@ -879,8 +879,8 @@ struct perf_event {
63384
63385 enum perf_event_active_state state;
63386 unsigned int attach_state;
63387 - local64_t count;
63388 - atomic64_t child_count;
63389 + local64_t count; /* PaX: fix it one day */
63390 + atomic64_unchecked_t child_count;
63391
63392 /*
63393 * These are the total time in nanoseconds that the event
63394 @@ -931,8 +931,8 @@ struct perf_event {
63395 * These accumulate total time (in nanoseconds) that children
63396 * events have been enabled and running, respectively.
63397 */
63398 - atomic64_t child_total_time_enabled;
63399 - atomic64_t child_total_time_running;
63400 + atomic64_unchecked_t child_total_time_enabled;
63401 + atomic64_unchecked_t child_total_time_running;
63402
63403 /*
63404 * Protect attach/detach and child_list:
63405 diff --git a/include/linux/personality.h b/include/linux/personality.h
63406 index 8fc7dd1a..c19d89e 100644
63407 --- a/include/linux/personality.h
63408 +++ b/include/linux/personality.h
63409 @@ -44,6 +44,7 @@ enum {
63410 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63411 ADDR_NO_RANDOMIZE | \
63412 ADDR_COMPAT_LAYOUT | \
63413 + ADDR_LIMIT_3GB | \
63414 MMAP_PAGE_ZERO)
63415
63416 /*
63417 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63418 index e1ac1ce..0675fed 100644
63419 --- a/include/linux/pipe_fs_i.h
63420 +++ b/include/linux/pipe_fs_i.h
63421 @@ -45,9 +45,9 @@ struct pipe_buffer {
63422 struct pipe_inode_info {
63423 wait_queue_head_t wait;
63424 unsigned int nrbufs, curbuf, buffers;
63425 - unsigned int readers;
63426 - unsigned int writers;
63427 - unsigned int waiting_writers;
63428 + atomic_t readers;
63429 + atomic_t writers;
63430 + atomic_t waiting_writers;
63431 unsigned int r_counter;
63432 unsigned int w_counter;
63433 struct page *tmp_page;
63434 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63435 index f271860..6b3bec5 100644
63436 --- a/include/linux/pm_runtime.h
63437 +++ b/include/linux/pm_runtime.h
63438 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63439
63440 static inline void pm_runtime_mark_last_busy(struct device *dev)
63441 {
63442 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63443 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63444 }
63445
63446 #else /* !CONFIG_PM_RUNTIME */
63447 diff --git a/include/linux/poison.h b/include/linux/poison.h
63448 index 2110a81..13a11bb 100644
63449 --- a/include/linux/poison.h
63450 +++ b/include/linux/poison.h
63451 @@ -19,8 +19,8 @@
63452 * under normal circumstances, used to verify that nobody uses
63453 * non-initialized list entries.
63454 */
63455 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63456 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63457 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63458 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63459
63460 /********** include/linux/timer.h **********/
63461 /*
63462 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63463 index 5a710b9..0b0dab9 100644
63464 --- a/include/linux/preempt.h
63465 +++ b/include/linux/preempt.h
63466 @@ -126,7 +126,7 @@ struct preempt_ops {
63467 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63468 void (*sched_out)(struct preempt_notifier *notifier,
63469 struct task_struct *next);
63470 -};
63471 +} __no_const;
63472
63473 /**
63474 * preempt_notifier - key for installing preemption notifiers
63475 diff --git a/include/linux/printk.h b/include/linux/printk.h
63476 index 1bec2f7..b66e833 100644
63477 --- a/include/linux/printk.h
63478 +++ b/include/linux/printk.h
63479 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63480 extern int printk_needs_cpu(int cpu);
63481 extern void printk_tick(void);
63482
63483 +extern int kptr_restrict;
63484 +
63485 #ifdef CONFIG_PRINTK
63486 asmlinkage __printf(5, 0)
63487 int vprintk_emit(int facility, int level,
63488 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63489
63490 extern int printk_delay_msec;
63491 extern int dmesg_restrict;
63492 -extern int kptr_restrict;
63493
63494 void log_buf_kexec_setup(void);
63495 void __init setup_log_buf(int early);
63496 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63497 index 3fd2e87..d93a721 100644
63498 --- a/include/linux/proc_fs.h
63499 +++ b/include/linux/proc_fs.h
63500 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63501 return proc_create_data(name, mode, parent, proc_fops, NULL);
63502 }
63503
63504 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63505 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63506 +{
63507 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63508 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63509 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63510 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63511 +#else
63512 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63513 +#endif
63514 +}
63515 +
63516 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63517 umode_t mode, struct proc_dir_entry *base,
63518 read_proc_t *read_proc, void * data)
63519 @@ -258,7 +270,7 @@ union proc_op {
63520 int (*proc_show)(struct seq_file *m,
63521 struct pid_namespace *ns, struct pid *pid,
63522 struct task_struct *task);
63523 -};
63524 +} __no_const;
63525
63526 struct ctl_table_header;
63527 struct ctl_table;
63528 diff --git a/include/linux/random.h b/include/linux/random.h
63529 index ac621ce..c1215f3 100644
63530 --- a/include/linux/random.h
63531 +++ b/include/linux/random.h
63532 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63533 unsigned int value);
63534 extern void add_interrupt_randomness(int irq, int irq_flags);
63535
63536 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63537 +extern void transfer_latent_entropy(void);
63538 +#endif
63539 +
63540 extern void get_random_bytes(void *buf, int nbytes);
63541 extern void get_random_bytes_arch(void *buf, int nbytes);
63542 void generate_random_uuid(unsigned char uuid_out[16]);
63543 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63544
63545 u32 prandom32(struct rnd_state *);
63546
63547 +static inline unsigned long pax_get_random_long(void)
63548 +{
63549 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63550 +}
63551 +
63552 /*
63553 * Handle minimum values for seeds
63554 */
63555 static inline u32 __seed(u32 x, u32 m)
63556 {
63557 - return (x < m) ? x + m : x;
63558 + return (x <= m) ? x + m + 1 : x;
63559 }
63560
63561 /**
63562 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63563 index e0879a7..a12f962 100644
63564 --- a/include/linux/reboot.h
63565 +++ b/include/linux/reboot.h
63566 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63567 * Architecture-specific implementations of sys_reboot commands.
63568 */
63569
63570 -extern void machine_restart(char *cmd);
63571 -extern void machine_halt(void);
63572 -extern void machine_power_off(void);
63573 +extern void machine_restart(char *cmd) __noreturn;
63574 +extern void machine_halt(void) __noreturn;
63575 +extern void machine_power_off(void) __noreturn;
63576
63577 extern void machine_shutdown(void);
63578 struct pt_regs;
63579 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63580 */
63581
63582 extern void kernel_restart_prepare(char *cmd);
63583 -extern void kernel_restart(char *cmd);
63584 -extern void kernel_halt(void);
63585 -extern void kernel_power_off(void);
63586 +extern void kernel_restart(char *cmd) __noreturn;
63587 +extern void kernel_halt(void) __noreturn;
63588 +extern void kernel_power_off(void) __noreturn;
63589
63590 extern int C_A_D; /* for sysctl */
63591 void ctrl_alt_del(void);
63592 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63593 * Emergency restart, callable from an interrupt handler.
63594 */
63595
63596 -extern void emergency_restart(void);
63597 +extern void emergency_restart(void) __noreturn;
63598 #include <asm/emergency-restart.h>
63599
63600 #endif
63601 diff --git a/include/linux/relay.h b/include/linux/relay.h
63602 index 91cacc3..b55ff74 100644
63603 --- a/include/linux/relay.h
63604 +++ b/include/linux/relay.h
63605 @@ -160,7 +160,7 @@ struct rchan_callbacks
63606 * The callback should return 0 if successful, negative if not.
63607 */
63608 int (*remove_buf_file)(struct dentry *dentry);
63609 -};
63610 +} __no_const;
63611
63612 /*
63613 * CONFIG_RELAY kernel API, kernel/relay.c
63614 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63615 index 6fdf027..ff72610 100644
63616 --- a/include/linux/rfkill.h
63617 +++ b/include/linux/rfkill.h
63618 @@ -147,6 +147,7 @@ struct rfkill_ops {
63619 void (*query)(struct rfkill *rfkill, void *data);
63620 int (*set_block)(void *data, bool blocked);
63621 };
63622 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63623
63624 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63625 /**
63626 diff --git a/include/linux/rio.h b/include/linux/rio.h
63627 index a90ebad..fd87b5d 100644
63628 --- a/include/linux/rio.h
63629 +++ b/include/linux/rio.h
63630 @@ -321,7 +321,7 @@ struct rio_ops {
63631 int mbox, void *buffer, size_t len);
63632 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63633 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63634 -};
63635 +} __no_const;
63636
63637 #define RIO_RESOURCE_MEM 0x00000100
63638 #define RIO_RESOURCE_DOORBELL 0x00000200
63639 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63640 index 3fce545..b4fed6e 100644
63641 --- a/include/linux/rmap.h
63642 +++ b/include/linux/rmap.h
63643 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63644 void anon_vma_init(void); /* create anon_vma_cachep */
63645 int anon_vma_prepare(struct vm_area_struct *);
63646 void unlink_anon_vmas(struct vm_area_struct *);
63647 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63648 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63649 void anon_vma_moveto_tail(struct vm_area_struct *);
63650 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63651 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63652
63653 static inline void anon_vma_merge(struct vm_area_struct *vma,
63654 struct vm_area_struct *next)
63655 diff --git a/include/linux/sched.h b/include/linux/sched.h
63656 index 4a1f493..5812aeb 100644
63657 --- a/include/linux/sched.h
63658 +++ b/include/linux/sched.h
63659 @@ -101,6 +101,7 @@ struct bio_list;
63660 struct fs_struct;
63661 struct perf_event_context;
63662 struct blk_plug;
63663 +struct linux_binprm;
63664
63665 /*
63666 * List of flags we want to share for kernel threads,
63667 @@ -384,10 +385,13 @@ struct user_namespace;
63668 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63669
63670 extern int sysctl_max_map_count;
63671 +extern unsigned long sysctl_heap_stack_gap;
63672
63673 #include <linux/aio.h>
63674
63675 #ifdef CONFIG_MMU
63676 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63677 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63678 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63679 extern unsigned long
63680 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63681 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63682 extern void set_dumpable(struct mm_struct *mm, int value);
63683 extern int get_dumpable(struct mm_struct *mm);
63684
63685 +/* get/set_dumpable() values */
63686 +#define SUID_DUMPABLE_DISABLED 0
63687 +#define SUID_DUMPABLE_ENABLED 1
63688 +#define SUID_DUMPABLE_SAFE 2
63689 +
63690 /* mm flags */
63691 /* dumpable bits */
63692 #define MMF_DUMPABLE 0 /* core dump is permitted */
63693 @@ -646,6 +655,17 @@ struct signal_struct {
63694 #ifdef CONFIG_TASKSTATS
63695 struct taskstats *stats;
63696 #endif
63697 +
63698 +#ifdef CONFIG_GRKERNSEC
63699 + u32 curr_ip;
63700 + u32 saved_ip;
63701 + u32 gr_saddr;
63702 + u32 gr_daddr;
63703 + u16 gr_sport;
63704 + u16 gr_dport;
63705 + u8 used_accept:1;
63706 +#endif
63707 +
63708 #ifdef CONFIG_AUDIT
63709 unsigned audit_tty;
63710 struct tty_audit_buf *tty_audit_buf;
63711 @@ -729,6 +749,11 @@ struct user_struct {
63712 struct key *session_keyring; /* UID's default session keyring */
63713 #endif
63714
63715 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63716 + unsigned int banned;
63717 + unsigned long ban_expires;
63718 +#endif
63719 +
63720 /* Hash table maintenance information */
63721 struct hlist_node uidhash_node;
63722 kuid_t uid;
63723 @@ -1348,8 +1373,8 @@ struct task_struct {
63724 struct list_head thread_group;
63725
63726 struct completion *vfork_done; /* for vfork() */
63727 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63728 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63729 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63730 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63731
63732 cputime_t utime, stime, utimescaled, stimescaled;
63733 cputime_t gtime;
63734 @@ -1365,11 +1390,6 @@ struct task_struct {
63735 struct task_cputime cputime_expires;
63736 struct list_head cpu_timers[3];
63737
63738 -/* process credentials */
63739 - const struct cred __rcu *real_cred; /* objective and real subjective task
63740 - * credentials (COW) */
63741 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63742 - * credentials (COW) */
63743 char comm[TASK_COMM_LEN]; /* executable name excluding path
63744 - access with [gs]et_task_comm (which lock
63745 it with task_lock())
63746 @@ -1386,8 +1406,16 @@ struct task_struct {
63747 #endif
63748 /* CPU-specific state of this task */
63749 struct thread_struct thread;
63750 +/* thread_info moved to task_struct */
63751 +#ifdef CONFIG_X86
63752 + struct thread_info tinfo;
63753 +#endif
63754 /* filesystem information */
63755 struct fs_struct *fs;
63756 +
63757 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63758 + * credentials (COW) */
63759 +
63760 /* open file information */
63761 struct files_struct *files;
63762 /* namespaces */
63763 @@ -1431,6 +1459,11 @@ struct task_struct {
63764 struct rt_mutex_waiter *pi_blocked_on;
63765 #endif
63766
63767 +/* process credentials */
63768 + const struct cred __rcu *real_cred; /* objective and real subjective task
63769 + * credentials (COW) */
63770 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63771 +
63772 #ifdef CONFIG_DEBUG_MUTEXES
63773 /* mutex deadlock detection */
63774 struct mutex_waiter *blocked_on;
63775 @@ -1547,6 +1580,27 @@ struct task_struct {
63776 unsigned long default_timer_slack_ns;
63777
63778 struct list_head *scm_work_list;
63779 +
63780 +#ifdef CONFIG_GRKERNSEC
63781 + /* grsecurity */
63782 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63783 + u64 exec_id;
63784 +#endif
63785 +#ifdef CONFIG_GRKERNSEC_SETXID
63786 + const struct cred *delayed_cred;
63787 +#endif
63788 + struct dentry *gr_chroot_dentry;
63789 + struct acl_subject_label *acl;
63790 + struct acl_role_label *role;
63791 + struct file *exec_file;
63792 + u16 acl_role_id;
63793 + /* is this the task that authenticated to the special role */
63794 + u8 acl_sp_role;
63795 + u8 is_writable;
63796 + u8 brute;
63797 + u8 gr_is_chrooted;
63798 +#endif
63799 +
63800 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63801 /* Index of current stored address in ret_stack */
63802 int curr_ret_stack;
63803 @@ -1585,6 +1639,51 @@ struct task_struct {
63804 #endif
63805 };
63806
63807 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63808 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63809 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63810 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63811 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63812 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63813 +
63814 +#ifdef CONFIG_PAX_SOFTMODE
63815 +extern int pax_softmode;
63816 +#endif
63817 +
63818 +extern int pax_check_flags(unsigned long *);
63819 +
63820 +/* if tsk != current then task_lock must be held on it */
63821 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63822 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63823 +{
63824 + if (likely(tsk->mm))
63825 + return tsk->mm->pax_flags;
63826 + else
63827 + return 0UL;
63828 +}
63829 +
63830 +/* if tsk != current then task_lock must be held on it */
63831 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63832 +{
63833 + if (likely(tsk->mm)) {
63834 + tsk->mm->pax_flags = flags;
63835 + return 0;
63836 + }
63837 + return -EINVAL;
63838 +}
63839 +#endif
63840 +
63841 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63842 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63843 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63844 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63845 +#endif
63846 +
63847 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63848 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63849 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63850 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
63851 +
63852 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63853 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63854
63855 @@ -2112,7 +2211,9 @@ void yield(void);
63856 extern struct exec_domain default_exec_domain;
63857
63858 union thread_union {
63859 +#ifndef CONFIG_X86
63860 struct thread_info thread_info;
63861 +#endif
63862 unsigned long stack[THREAD_SIZE/sizeof(long)];
63863 };
63864
63865 @@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63866 */
63867
63868 extern struct task_struct *find_task_by_vpid(pid_t nr);
63869 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63870 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63871 struct pid_namespace *ns);
63872
63873 @@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63874 extern void exit_itimers(struct signal_struct *);
63875 extern void flush_itimer_signals(void);
63876
63877 -extern void do_group_exit(int);
63878 +extern __noreturn void do_group_exit(int);
63879
63880 extern void daemonize(const char *, ...);
63881 extern int allow_signal(int);
63882 @@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63883
63884 #endif
63885
63886 -static inline int object_is_on_stack(void *obj)
63887 +static inline int object_starts_on_stack(void *obj)
63888 {
63889 - void *stack = task_stack_page(current);
63890 + const void *stack = task_stack_page(current);
63891
63892 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63893 }
63894 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63895 index 899fbb4..1cb4138 100644
63896 --- a/include/linux/screen_info.h
63897 +++ b/include/linux/screen_info.h
63898 @@ -43,7 +43,8 @@ struct screen_info {
63899 __u16 pages; /* 0x32 */
63900 __u16 vesa_attributes; /* 0x34 */
63901 __u32 capabilities; /* 0x36 */
63902 - __u8 _reserved[6]; /* 0x3a */
63903 + __u16 vesapm_size; /* 0x3a */
63904 + __u8 _reserved[4]; /* 0x3c */
63905 } __attribute__((packed));
63906
63907 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63908 diff --git a/include/linux/security.h b/include/linux/security.h
63909 index 3dea6a9..81fd81f 100644
63910 --- a/include/linux/security.h
63911 +++ b/include/linux/security.h
63912 @@ -26,6 +26,7 @@
63913 #include <linux/capability.h>
63914 #include <linux/slab.h>
63915 #include <linux/err.h>
63916 +#include <linux/grsecurity.h>
63917
63918 struct linux_binprm;
63919 struct cred;
63920 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63921 index fc61854..d7c490b 100644
63922 --- a/include/linux/seq_file.h
63923 +++ b/include/linux/seq_file.h
63924 @@ -25,6 +25,9 @@ struct seq_file {
63925 struct mutex lock;
63926 const struct seq_operations *op;
63927 int poll_event;
63928 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63929 + u64 exec_id;
63930 +#endif
63931 void *private;
63932 };
63933
63934 @@ -34,6 +37,7 @@ struct seq_operations {
63935 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63936 int (*show) (struct seq_file *m, void *v);
63937 };
63938 +typedef struct seq_operations __no_const seq_operations_no_const;
63939
63940 #define SEQ_SKIP 1
63941
63942 diff --git a/include/linux/shm.h b/include/linux/shm.h
63943 index 92808b8..c28cac4 100644
63944 --- a/include/linux/shm.h
63945 +++ b/include/linux/shm.h
63946 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63947
63948 /* The task created the shm object. NULL if the task is dead. */
63949 struct task_struct *shm_creator;
63950 +#ifdef CONFIG_GRKERNSEC
63951 + time_t shm_createtime;
63952 + pid_t shm_lapid;
63953 +#endif
63954 };
63955
63956 /* shm_mode upper byte flags */
63957 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63958 index 642cb73..7ff7f9f 100644
63959 --- a/include/linux/skbuff.h
63960 +++ b/include/linux/skbuff.h
63961 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63962 */
63963 static inline int skb_queue_empty(const struct sk_buff_head *list)
63964 {
63965 - return list->next == (struct sk_buff *)list;
63966 + return list->next == (const struct sk_buff *)list;
63967 }
63968
63969 /**
63970 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63971 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63972 const struct sk_buff *skb)
63973 {
63974 - return skb->next == (struct sk_buff *)list;
63975 + return skb->next == (const struct sk_buff *)list;
63976 }
63977
63978 /**
63979 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63980 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63981 const struct sk_buff *skb)
63982 {
63983 - return skb->prev == (struct sk_buff *)list;
63984 + return skb->prev == (const struct sk_buff *)list;
63985 }
63986
63987 /**
63988 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63989 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63990 */
63991 #ifndef NET_SKB_PAD
63992 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63993 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63994 #endif
63995
63996 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63997 diff --git a/include/linux/slab.h b/include/linux/slab.h
63998 index 67d5d94..bbd740b 100644
63999 --- a/include/linux/slab.h
64000 +++ b/include/linux/slab.h
64001 @@ -11,12 +11,20 @@
64002
64003 #include <linux/gfp.h>
64004 #include <linux/types.h>
64005 +#include <linux/err.h>
64006
64007 /*
64008 * Flags to pass to kmem_cache_create().
64009 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64010 */
64011 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64012 +
64013 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64014 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64015 +#else
64016 +#define SLAB_USERCOPY 0x00000000UL
64017 +#endif
64018 +
64019 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64020 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64021 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64022 @@ -87,10 +95,13 @@
64023 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64024 * Both make kfree a no-op.
64025 */
64026 -#define ZERO_SIZE_PTR ((void *)16)
64027 +#define ZERO_SIZE_PTR \
64028 +({ \
64029 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64030 + (void *)(-MAX_ERRNO-1L); \
64031 +})
64032
64033 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64034 - (unsigned long)ZERO_SIZE_PTR)
64035 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64036
64037 /*
64038 * struct kmem_cache related prototypes
64039 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64040 void kfree(const void *);
64041 void kzfree(const void *);
64042 size_t ksize(const void *);
64043 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64044 +bool is_usercopy_object(const void *ptr);
64045
64046 /*
64047 * Allocator specific definitions. These are mainly used to establish optimized
64048 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64049 */
64050 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64051 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64052 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64053 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64054 #define kmalloc_track_caller(size, flags) \
64055 __kmalloc_track_caller(size, flags, _RET_IP_)
64056 #else
64057 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64058 */
64059 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64060 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64061 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64062 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64063 #define kmalloc_node_track_caller(size, flags, node) \
64064 __kmalloc_node_track_caller(size, flags, node, \
64065 _RET_IP_)
64066 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64067 index fbd1117..0a3d314 100644
64068 --- a/include/linux/slab_def.h
64069 +++ b/include/linux/slab_def.h
64070 @@ -66,10 +66,10 @@ struct kmem_cache {
64071 unsigned long node_allocs;
64072 unsigned long node_frees;
64073 unsigned long node_overflow;
64074 - atomic_t allochit;
64075 - atomic_t allocmiss;
64076 - atomic_t freehit;
64077 - atomic_t freemiss;
64078 + atomic_unchecked_t allochit;
64079 + atomic_unchecked_t allocmiss;
64080 + atomic_unchecked_t freehit;
64081 + atomic_unchecked_t freemiss;
64082
64083 /*
64084 * If debugging is enabled, then the allocator can add additional
64085 @@ -103,11 +103,16 @@ struct cache_sizes {
64086 #ifdef CONFIG_ZONE_DMA
64087 struct kmem_cache *cs_dmacachep;
64088 #endif
64089 +
64090 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64091 + struct kmem_cache *cs_usercopycachep;
64092 +#endif
64093 +
64094 };
64095 extern struct cache_sizes malloc_sizes[];
64096
64097 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64098 -void *__kmalloc(size_t size, gfp_t flags);
64099 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64100
64101 #ifdef CONFIG_TRACING
64102 extern void *kmem_cache_alloc_trace(size_t size,
64103 @@ -150,6 +155,13 @@ found:
64104 cachep = malloc_sizes[i].cs_dmacachep;
64105 else
64106 #endif
64107 +
64108 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64109 + if (flags & GFP_USERCOPY)
64110 + cachep = malloc_sizes[i].cs_usercopycachep;
64111 + else
64112 +#endif
64113 +
64114 cachep = malloc_sizes[i].cs_cachep;
64115
64116 ret = kmem_cache_alloc_trace(size, cachep, flags);
64117 @@ -160,7 +172,7 @@ found:
64118 }
64119
64120 #ifdef CONFIG_NUMA
64121 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64122 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64123 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64124
64125 #ifdef CONFIG_TRACING
64126 @@ -203,6 +215,13 @@ found:
64127 cachep = malloc_sizes[i].cs_dmacachep;
64128 else
64129 #endif
64130 +
64131 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64132 + if (flags & GFP_USERCOPY)
64133 + cachep = malloc_sizes[i].cs_usercopycachep;
64134 + else
64135 +#endif
64136 +
64137 cachep = malloc_sizes[i].cs_cachep;
64138
64139 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64140 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64141 index 0ec00b3..22b4715 100644
64142 --- a/include/linux/slob_def.h
64143 +++ b/include/linux/slob_def.h
64144 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64145 return kmem_cache_alloc_node(cachep, flags, -1);
64146 }
64147
64148 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64149 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64150
64151 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64152 {
64153 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64154 return __kmalloc_node(size, flags, -1);
64155 }
64156
64157 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64158 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64159 {
64160 return kmalloc(size, flags);
64161 }
64162 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64163 index c2f8c8b..d992a41 100644
64164 --- a/include/linux/slub_def.h
64165 +++ b/include/linux/slub_def.h
64166 @@ -92,7 +92,7 @@ struct kmem_cache {
64167 struct kmem_cache_order_objects max;
64168 struct kmem_cache_order_objects min;
64169 gfp_t allocflags; /* gfp flags to use on each alloc */
64170 - int refcount; /* Refcount for slab cache destroy */
64171 + atomic_t refcount; /* Refcount for slab cache destroy */
64172 void (*ctor)(void *);
64173 int inuse; /* Offset to metadata */
64174 int align; /* Alignment */
64175 @@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64176 * Sorry that the following has to be that ugly but some versions of GCC
64177 * have trouble with constant propagation and loops.
64178 */
64179 -static __always_inline int kmalloc_index(size_t size)
64180 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64181 {
64182 if (!size)
64183 return 0;
64184 @@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64185 }
64186
64187 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64188 -void *__kmalloc(size_t size, gfp_t flags);
64189 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64190
64191 static __always_inline void *
64192 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64193 @@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64194 }
64195 #endif
64196
64197 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64198 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64199 {
64200 unsigned int order = get_order(size);
64201 return kmalloc_order_trace(size, flags, order);
64202 @@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64203 }
64204
64205 #ifdef CONFIG_NUMA
64206 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64207 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64208 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64209
64210 #ifdef CONFIG_TRACING
64211 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64212 index de8832d..0147b46 100644
64213 --- a/include/linux/sonet.h
64214 +++ b/include/linux/sonet.h
64215 @@ -61,7 +61,7 @@ struct sonet_stats {
64216 #include <linux/atomic.h>
64217
64218 struct k_sonet_stats {
64219 -#define __HANDLE_ITEM(i) atomic_t i
64220 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64221 __SONET_ITEMS
64222 #undef __HANDLE_ITEM
64223 };
64224 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64225 index 523547e..2cb7140 100644
64226 --- a/include/linux/sunrpc/clnt.h
64227 +++ b/include/linux/sunrpc/clnt.h
64228 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64229 {
64230 switch (sap->sa_family) {
64231 case AF_INET:
64232 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64233 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64234 case AF_INET6:
64235 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64236 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64237 }
64238 return 0;
64239 }
64240 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64241 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64242 const struct sockaddr *src)
64243 {
64244 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64245 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64246 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64247
64248 dsin->sin_family = ssin->sin_family;
64249 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64250 if (sa->sa_family != AF_INET6)
64251 return 0;
64252
64253 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64254 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64255 }
64256
64257 #endif /* __KERNEL__ */
64258 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64259 index dc0c3cc..8503fb6 100644
64260 --- a/include/linux/sunrpc/sched.h
64261 +++ b/include/linux/sunrpc/sched.h
64262 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64263 void (*rpc_count_stats)(struct rpc_task *, void *);
64264 void (*rpc_release)(void *);
64265 };
64266 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64267
64268 struct rpc_task_setup {
64269 struct rpc_task *task;
64270 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64271 index 0b8e3e6..33e0a01 100644
64272 --- a/include/linux/sunrpc/svc_rdma.h
64273 +++ b/include/linux/sunrpc/svc_rdma.h
64274 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64275 extern unsigned int svcrdma_max_requests;
64276 extern unsigned int svcrdma_max_req_size;
64277
64278 -extern atomic_t rdma_stat_recv;
64279 -extern atomic_t rdma_stat_read;
64280 -extern atomic_t rdma_stat_write;
64281 -extern atomic_t rdma_stat_sq_starve;
64282 -extern atomic_t rdma_stat_rq_starve;
64283 -extern atomic_t rdma_stat_rq_poll;
64284 -extern atomic_t rdma_stat_rq_prod;
64285 -extern atomic_t rdma_stat_sq_poll;
64286 -extern atomic_t rdma_stat_sq_prod;
64287 +extern atomic_unchecked_t rdma_stat_recv;
64288 +extern atomic_unchecked_t rdma_stat_read;
64289 +extern atomic_unchecked_t rdma_stat_write;
64290 +extern atomic_unchecked_t rdma_stat_sq_starve;
64291 +extern atomic_unchecked_t rdma_stat_rq_starve;
64292 +extern atomic_unchecked_t rdma_stat_rq_poll;
64293 +extern atomic_unchecked_t rdma_stat_rq_prod;
64294 +extern atomic_unchecked_t rdma_stat_sq_poll;
64295 +extern atomic_unchecked_t rdma_stat_sq_prod;
64296
64297 #define RPCRDMA_VERSION 1
64298
64299 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64300 index c34b4c8..a65b67d 100644
64301 --- a/include/linux/sysctl.h
64302 +++ b/include/linux/sysctl.h
64303 @@ -155,7 +155,11 @@ enum
64304 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64305 };
64306
64307 -
64308 +#ifdef CONFIG_PAX_SOFTMODE
64309 +enum {
64310 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64311 +};
64312 +#endif
64313
64314 /* CTL_VM names: */
64315 enum
64316 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64317
64318 extern int proc_dostring(struct ctl_table *, int,
64319 void __user *, size_t *, loff_t *);
64320 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64321 + void __user *, size_t *, loff_t *);
64322 extern int proc_dointvec(struct ctl_table *, int,
64323 void __user *, size_t *, loff_t *);
64324 extern int proc_dointvec_minmax(struct ctl_table *, int,
64325 diff --git a/include/linux/tty.h b/include/linux/tty.h
64326 index 9f47ab5..73da944 100644
64327 --- a/include/linux/tty.h
64328 +++ b/include/linux/tty.h
64329 @@ -225,7 +225,7 @@ struct tty_port {
64330 const struct tty_port_operations *ops; /* Port operations */
64331 spinlock_t lock; /* Lock protecting tty field */
64332 int blocked_open; /* Waiting to open */
64333 - int count; /* Usage count */
64334 + atomic_t count; /* Usage count */
64335 wait_queue_head_t open_wait; /* Open waiters */
64336 wait_queue_head_t close_wait; /* Close waiters */
64337 wait_queue_head_t delta_msr_wait; /* Modem status change */
64338 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64339 struct tty_struct *tty, struct file *filp);
64340 static inline int tty_port_users(struct tty_port *port)
64341 {
64342 - return port->count + port->blocked_open;
64343 + return atomic_read(&port->count) + port->blocked_open;
64344 }
64345
64346 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64347 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64348 index fb79dd8d..07d4773 100644
64349 --- a/include/linux/tty_ldisc.h
64350 +++ b/include/linux/tty_ldisc.h
64351 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64352
64353 struct module *owner;
64354
64355 - int refcount;
64356 + atomic_t refcount;
64357 };
64358
64359 struct tty_ldisc {
64360 diff --git a/include/linux/types.h b/include/linux/types.h
64361 index 9c1bd53..c2370f6 100644
64362 --- a/include/linux/types.h
64363 +++ b/include/linux/types.h
64364 @@ -220,10 +220,26 @@ typedef struct {
64365 int counter;
64366 } atomic_t;
64367
64368 +#ifdef CONFIG_PAX_REFCOUNT
64369 +typedef struct {
64370 + int counter;
64371 +} atomic_unchecked_t;
64372 +#else
64373 +typedef atomic_t atomic_unchecked_t;
64374 +#endif
64375 +
64376 #ifdef CONFIG_64BIT
64377 typedef struct {
64378 long counter;
64379 } atomic64_t;
64380 +
64381 +#ifdef CONFIG_PAX_REFCOUNT
64382 +typedef struct {
64383 + long counter;
64384 +} atomic64_unchecked_t;
64385 +#else
64386 +typedef atomic64_t atomic64_unchecked_t;
64387 +#endif
64388 #endif
64389
64390 struct list_head {
64391 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64392 index 5ca0951..ab496a5 100644
64393 --- a/include/linux/uaccess.h
64394 +++ b/include/linux/uaccess.h
64395 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64396 long ret; \
64397 mm_segment_t old_fs = get_fs(); \
64398 \
64399 - set_fs(KERNEL_DS); \
64400 pagefault_disable(); \
64401 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64402 - pagefault_enable(); \
64403 + set_fs(KERNEL_DS); \
64404 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64405 set_fs(old_fs); \
64406 + pagefault_enable(); \
64407 ret; \
64408 })
64409
64410 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64411 index 99c1b4d..bb94261 100644
64412 --- a/include/linux/unaligned/access_ok.h
64413 +++ b/include/linux/unaligned/access_ok.h
64414 @@ -6,32 +6,32 @@
64415
64416 static inline u16 get_unaligned_le16(const void *p)
64417 {
64418 - return le16_to_cpup((__le16 *)p);
64419 + return le16_to_cpup((const __le16 *)p);
64420 }
64421
64422 static inline u32 get_unaligned_le32(const void *p)
64423 {
64424 - return le32_to_cpup((__le32 *)p);
64425 + return le32_to_cpup((const __le32 *)p);
64426 }
64427
64428 static inline u64 get_unaligned_le64(const void *p)
64429 {
64430 - return le64_to_cpup((__le64 *)p);
64431 + return le64_to_cpup((const __le64 *)p);
64432 }
64433
64434 static inline u16 get_unaligned_be16(const void *p)
64435 {
64436 - return be16_to_cpup((__be16 *)p);
64437 + return be16_to_cpup((const __be16 *)p);
64438 }
64439
64440 static inline u32 get_unaligned_be32(const void *p)
64441 {
64442 - return be32_to_cpup((__be32 *)p);
64443 + return be32_to_cpup((const __be32 *)p);
64444 }
64445
64446 static inline u64 get_unaligned_be64(const void *p)
64447 {
64448 - return be64_to_cpup((__be64 *)p);
64449 + return be64_to_cpup((const __be64 *)p);
64450 }
64451
64452 static inline void put_unaligned_le16(u16 val, void *p)
64453 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64454 index 547e59c..db6ad19 100644
64455 --- a/include/linux/usb/renesas_usbhs.h
64456 +++ b/include/linux/usb/renesas_usbhs.h
64457 @@ -39,7 +39,7 @@ enum {
64458 */
64459 struct renesas_usbhs_driver_callback {
64460 int (*notify_hotplug)(struct platform_device *pdev);
64461 -};
64462 +} __no_const;
64463
64464 /*
64465 * callback functions for platform
64466 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64467 * VBUS control is needed for Host
64468 */
64469 int (*set_vbus)(struct platform_device *pdev, int enable);
64470 -};
64471 +} __no_const;
64472
64473 /*
64474 * parameters for renesas usbhs
64475 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64476 index 6f8fbcf..8259001 100644
64477 --- a/include/linux/vermagic.h
64478 +++ b/include/linux/vermagic.h
64479 @@ -25,9 +25,35 @@
64480 #define MODULE_ARCH_VERMAGIC ""
64481 #endif
64482
64483 +#ifdef CONFIG_PAX_REFCOUNT
64484 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64485 +#else
64486 +#define MODULE_PAX_REFCOUNT ""
64487 +#endif
64488 +
64489 +#ifdef CONSTIFY_PLUGIN
64490 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64491 +#else
64492 +#define MODULE_CONSTIFY_PLUGIN ""
64493 +#endif
64494 +
64495 +#ifdef STACKLEAK_PLUGIN
64496 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64497 +#else
64498 +#define MODULE_STACKLEAK_PLUGIN ""
64499 +#endif
64500 +
64501 +#ifdef CONFIG_GRKERNSEC
64502 +#define MODULE_GRSEC "GRSEC "
64503 +#else
64504 +#define MODULE_GRSEC ""
64505 +#endif
64506 +
64507 #define VERMAGIC_STRING \
64508 UTS_RELEASE " " \
64509 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64510 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64511 - MODULE_ARCH_VERMAGIC
64512 + MODULE_ARCH_VERMAGIC \
64513 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64514 + MODULE_GRSEC
64515
64516 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64517 index dcdfc2b..ec79ab5 100644
64518 --- a/include/linux/vmalloc.h
64519 +++ b/include/linux/vmalloc.h
64520 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64521 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64522 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64523 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64524 +
64525 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64526 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64527 +#endif
64528 +
64529 /* bits [20..32] reserved for arch specific ioremap internals */
64530
64531 /*
64532 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64533 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64534 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64535 unsigned long start, unsigned long end, gfp_t gfp_mask,
64536 - pgprot_t prot, int node, void *caller);
64537 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64538 extern void vfree(const void *addr);
64539
64540 extern void *vmap(struct page **pages, unsigned int count,
64541 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64542 extern void free_vm_area(struct vm_struct *area);
64543
64544 /* for /dev/kmem */
64545 -extern long vread(char *buf, char *addr, unsigned long count);
64546 -extern long vwrite(char *buf, char *addr, unsigned long count);
64547 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64548 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64549
64550 /*
64551 * Internals. Dont't use..
64552 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64553 index 65efb92..137adbb 100644
64554 --- a/include/linux/vmstat.h
64555 +++ b/include/linux/vmstat.h
64556 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64557 /*
64558 * Zone based page accounting with per cpu differentials.
64559 */
64560 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64561 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64562
64563 static inline void zone_page_state_add(long x, struct zone *zone,
64564 enum zone_stat_item item)
64565 {
64566 - atomic_long_add(x, &zone->vm_stat[item]);
64567 - atomic_long_add(x, &vm_stat[item]);
64568 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64569 + atomic_long_add_unchecked(x, &vm_stat[item]);
64570 }
64571
64572 static inline unsigned long global_page_state(enum zone_stat_item item)
64573 {
64574 - long x = atomic_long_read(&vm_stat[item]);
64575 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64576 #ifdef CONFIG_SMP
64577 if (x < 0)
64578 x = 0;
64579 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64580 static inline unsigned long zone_page_state(struct zone *zone,
64581 enum zone_stat_item item)
64582 {
64583 - long x = atomic_long_read(&zone->vm_stat[item]);
64584 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64585 #ifdef CONFIG_SMP
64586 if (x < 0)
64587 x = 0;
64588 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64589 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64590 enum zone_stat_item item)
64591 {
64592 - long x = atomic_long_read(&zone->vm_stat[item]);
64593 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64594
64595 #ifdef CONFIG_SMP
64596 int cpu;
64597 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64598
64599 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64600 {
64601 - atomic_long_inc(&zone->vm_stat[item]);
64602 - atomic_long_inc(&vm_stat[item]);
64603 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64604 + atomic_long_inc_unchecked(&vm_stat[item]);
64605 }
64606
64607 static inline void __inc_zone_page_state(struct page *page,
64608 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64609
64610 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64611 {
64612 - atomic_long_dec(&zone->vm_stat[item]);
64613 - atomic_long_dec(&vm_stat[item]);
64614 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64615 + atomic_long_dec_unchecked(&vm_stat[item]);
64616 }
64617
64618 static inline void __dec_zone_page_state(struct page *page,
64619 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64620 index e5d1220..ef6e406 100644
64621 --- a/include/linux/xattr.h
64622 +++ b/include/linux/xattr.h
64623 @@ -57,6 +57,11 @@
64624 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64625 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64626
64627 +/* User namespace */
64628 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64629 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64630 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64631 +
64632 #ifdef __KERNEL__
64633
64634 #include <linux/types.h>
64635 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64636 index 944ecdf..a3994fc 100644
64637 --- a/include/media/saa7146_vv.h
64638 +++ b/include/media/saa7146_vv.h
64639 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64640 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64641
64642 /* the extension can override this */
64643 - struct v4l2_ioctl_ops vid_ops;
64644 - struct v4l2_ioctl_ops vbi_ops;
64645 + v4l2_ioctl_ops_no_const vid_ops;
64646 + v4l2_ioctl_ops_no_const vbi_ops;
64647 /* pointer to the saa7146 core ops */
64648 const struct v4l2_ioctl_ops *core_ops;
64649
64650 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64651 index a056e6e..31023a5 100644
64652 --- a/include/media/v4l2-dev.h
64653 +++ b/include/media/v4l2-dev.h
64654 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64655 int (*mmap) (struct file *, struct vm_area_struct *);
64656 int (*open) (struct file *);
64657 int (*release) (struct file *);
64658 -};
64659 +} __do_const;
64660 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64661
64662 /*
64663 * Newer version of video_device, handled by videodev2.c
64664 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64665 index d8b76f7..7d5aa18 100644
64666 --- a/include/media/v4l2-ioctl.h
64667 +++ b/include/media/v4l2-ioctl.h
64668 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64669 long (*vidioc_default) (struct file *file, void *fh,
64670 bool valid_prio, int cmd, void *arg);
64671 };
64672 -
64673 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64674
64675 /* v4l debugging and diagnostics */
64676
64677 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64678 index 439dadc..1c67e3f 100644
64679 --- a/include/net/caif/caif_hsi.h
64680 +++ b/include/net/caif/caif_hsi.h
64681 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64682 void (*rx_done_cb) (struct cfhsi_drv *drv);
64683 void (*wake_up_cb) (struct cfhsi_drv *drv);
64684 void (*wake_down_cb) (struct cfhsi_drv *drv);
64685 -};
64686 +} __no_const;
64687
64688 /* Structure implemented by HSI device. */
64689 struct cfhsi_dev {
64690 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64691 index 9e5425b..8136ffc 100644
64692 --- a/include/net/caif/cfctrl.h
64693 +++ b/include/net/caif/cfctrl.h
64694 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64695 void (*radioset_rsp)(void);
64696 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64697 struct cflayer *client_layer);
64698 -};
64699 +} __no_const;
64700
64701 /* Link Setup Parameters for CAIF-Links. */
64702 struct cfctrl_link_param {
64703 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64704 struct cfctrl {
64705 struct cfsrvl serv;
64706 struct cfctrl_rsp res;
64707 - atomic_t req_seq_no;
64708 - atomic_t rsp_seq_no;
64709 + atomic_unchecked_t req_seq_no;
64710 + atomic_unchecked_t rsp_seq_no;
64711 struct list_head list;
64712 /* Protects from simultaneous access to first_req list */
64713 spinlock_t info_list_lock;
64714 diff --git a/include/net/flow.h b/include/net/flow.h
64715 index 6c469db..7743b8e 100644
64716 --- a/include/net/flow.h
64717 +++ b/include/net/flow.h
64718 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64719
64720 extern void flow_cache_flush(void);
64721 extern void flow_cache_flush_deferred(void);
64722 -extern atomic_t flow_cache_genid;
64723 +extern atomic_unchecked_t flow_cache_genid;
64724
64725 #endif
64726 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64727 index 2040bff..f4c0733 100644
64728 --- a/include/net/inetpeer.h
64729 +++ b/include/net/inetpeer.h
64730 @@ -51,8 +51,8 @@ struct inet_peer {
64731 */
64732 union {
64733 struct {
64734 - atomic_t rid; /* Frag reception counter */
64735 - atomic_t ip_id_count; /* IP ID for the next packet */
64736 + atomic_unchecked_t rid; /* Frag reception counter */
64737 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64738 __u32 tcp_ts;
64739 __u32 tcp_ts_stamp;
64740 };
64741 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64742 more++;
64743 inet_peer_refcheck(p);
64744 do {
64745 - old = atomic_read(&p->ip_id_count);
64746 + old = atomic_read_unchecked(&p->ip_id_count);
64747 new = old + more;
64748 if (!new)
64749 new = 1;
64750 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64751 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64752 return new;
64753 }
64754
64755 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64756 index 78df0866..00e5c9b 100644
64757 --- a/include/net/ip_fib.h
64758 +++ b/include/net/ip_fib.h
64759 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64760
64761 #define FIB_RES_SADDR(net, res) \
64762 ((FIB_RES_NH(res).nh_saddr_genid == \
64763 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64764 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64765 FIB_RES_NH(res).nh_saddr : \
64766 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64767 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64768 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64769 index 95374d1..2300e36 100644
64770 --- a/include/net/ip_vs.h
64771 +++ b/include/net/ip_vs.h
64772 @@ -510,7 +510,7 @@ struct ip_vs_conn {
64773 struct ip_vs_conn *control; /* Master control connection */
64774 atomic_t n_control; /* Number of controlled ones */
64775 struct ip_vs_dest *dest; /* real server */
64776 - atomic_t in_pkts; /* incoming packet counter */
64777 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64778
64779 /* packet transmitter for different forwarding methods. If it
64780 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64781 @@ -648,7 +648,7 @@ struct ip_vs_dest {
64782 __be16 port; /* port number of the server */
64783 union nf_inet_addr addr; /* IP address of the server */
64784 volatile unsigned int flags; /* dest status flags */
64785 - atomic_t conn_flags; /* flags to copy to conn */
64786 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64787 atomic_t weight; /* server weight */
64788
64789 atomic_t refcnt; /* reference counter */
64790 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64791 index 69b610a..fe3962c 100644
64792 --- a/include/net/irda/ircomm_core.h
64793 +++ b/include/net/irda/ircomm_core.h
64794 @@ -51,7 +51,7 @@ typedef struct {
64795 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64796 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64797 struct ircomm_info *);
64798 -} call_t;
64799 +} __no_const call_t;
64800
64801 struct ircomm_cb {
64802 irda_queue_t queue;
64803 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64804 index 59ba38bc..d515662 100644
64805 --- a/include/net/irda/ircomm_tty.h
64806 +++ b/include/net/irda/ircomm_tty.h
64807 @@ -35,6 +35,7 @@
64808 #include <linux/termios.h>
64809 #include <linux/timer.h>
64810 #include <linux/tty.h> /* struct tty_struct */
64811 +#include <asm/local.h>
64812
64813 #include <net/irda/irias_object.h>
64814 #include <net/irda/ircomm_core.h>
64815 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64816 unsigned short close_delay;
64817 unsigned short closing_wait; /* time to wait before closing */
64818
64819 - int open_count;
64820 - int blocked_open; /* # of blocked opens */
64821 + local_t open_count;
64822 + local_t blocked_open; /* # of blocked opens */
64823
64824 /* Protect concurent access to :
64825 * o self->open_count
64826 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64827 index cc7c197..9f2da2a 100644
64828 --- a/include/net/iucv/af_iucv.h
64829 +++ b/include/net/iucv/af_iucv.h
64830 @@ -141,7 +141,7 @@ struct iucv_sock {
64831 struct iucv_sock_list {
64832 struct hlist_head head;
64833 rwlock_t lock;
64834 - atomic_t autobind_name;
64835 + atomic_unchecked_t autobind_name;
64836 };
64837
64838 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64839 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64840 index 6cdfeed..55a0256 100644
64841 --- a/include/net/neighbour.h
64842 +++ b/include/net/neighbour.h
64843 @@ -123,7 +123,7 @@ struct neigh_ops {
64844 void (*error_report)(struct neighbour *, struct sk_buff *);
64845 int (*output)(struct neighbour *, struct sk_buff *);
64846 int (*connected_output)(struct neighbour *, struct sk_buff *);
64847 -};
64848 +} __do_const;
64849
64850 struct pneigh_entry {
64851 struct pneigh_entry *next;
64852 diff --git a/include/net/netlink.h b/include/net/netlink.h
64853 index 785f37a..c81dc0c 100644
64854 --- a/include/net/netlink.h
64855 +++ b/include/net/netlink.h
64856 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64857 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64858 {
64859 if (mark)
64860 - skb_trim(skb, (unsigned char *) mark - skb->data);
64861 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64862 }
64863
64864 /**
64865 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64866 index bbd023a..97c6d0d 100644
64867 --- a/include/net/netns/ipv4.h
64868 +++ b/include/net/netns/ipv4.h
64869 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64870 unsigned int sysctl_ping_group_range[2];
64871 long sysctl_tcp_mem[3];
64872
64873 - atomic_t rt_genid;
64874 - atomic_t dev_addr_genid;
64875 + atomic_unchecked_t rt_genid;
64876 + atomic_unchecked_t dev_addr_genid;
64877
64878 #ifdef CONFIG_IP_MROUTE
64879 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64880 diff --git a/include/net/scm.h b/include/net/scm.h
64881 index d456f4c..0c0017c 100644
64882 --- a/include/net/scm.h
64883 +++ b/include/net/scm.h
64884 @@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
64885 }
64886
64887 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
64888 - struct scm_cookie *scm)
64889 + struct scm_cookie *scm, bool forcecreds)
64890 {
64891 memset(scm, 0, sizeof(*scm));
64892 + if (forcecreds)
64893 + scm_set_cred(scm, task_tgid(current), current_cred());
64894 unix_get_peersec_dgram(sock, scm);
64895 if (msg->msg_controllen <= 0)
64896 return 0;
64897 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64898 index a2ef814..31a8e3f 100644
64899 --- a/include/net/sctp/sctp.h
64900 +++ b/include/net/sctp/sctp.h
64901 @@ -318,9 +318,9 @@ do { \
64902
64903 #else /* SCTP_DEBUG */
64904
64905 -#define SCTP_DEBUG_PRINTK(whatever...)
64906 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64907 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64908 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64909 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64910 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64911 #define SCTP_ENABLE_DEBUG
64912 #define SCTP_DISABLE_DEBUG
64913 #define SCTP_ASSERT(expr, str, func)
64914 diff --git a/include/net/sock.h b/include/net/sock.h
64915 index 4a45216..7af2578 100644
64916 --- a/include/net/sock.h
64917 +++ b/include/net/sock.h
64918 @@ -303,7 +303,7 @@ struct sock {
64919 #ifdef CONFIG_RPS
64920 __u32 sk_rxhash;
64921 #endif
64922 - atomic_t sk_drops;
64923 + atomic_unchecked_t sk_drops;
64924 int sk_rcvbuf;
64925
64926 struct sk_filter __rcu *sk_filter;
64927 @@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64928 }
64929
64930 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64931 - char __user *from, char *to,
64932 + char __user *from, unsigned char *to,
64933 int copy, int offset)
64934 {
64935 if (skb->ip_summed == CHECKSUM_NONE) {
64936 diff --git a/include/net/tcp.h b/include/net/tcp.h
64937 index e79aa48..9929421 100644
64938 --- a/include/net/tcp.h
64939 +++ b/include/net/tcp.h
64940 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64941 char *name;
64942 sa_family_t family;
64943 const struct file_operations *seq_fops;
64944 - struct seq_operations seq_ops;
64945 + seq_operations_no_const seq_ops;
64946 };
64947
64948 struct tcp_iter_state {
64949 diff --git a/include/net/udp.h b/include/net/udp.h
64950 index 065f379..b661b40 100644
64951 --- a/include/net/udp.h
64952 +++ b/include/net/udp.h
64953 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64954 sa_family_t family;
64955 struct udp_table *udp_table;
64956 const struct file_operations *seq_fops;
64957 - struct seq_operations seq_ops;
64958 + seq_operations_no_const seq_ops;
64959 };
64960
64961 struct udp_iter_state {
64962 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64963 index e0a55df..5890bca07 100644
64964 --- a/include/net/xfrm.h
64965 +++ b/include/net/xfrm.h
64966 @@ -505,7 +505,7 @@ struct xfrm_policy {
64967 struct timer_list timer;
64968
64969 struct flow_cache_object flo;
64970 - atomic_t genid;
64971 + atomic_unchecked_t genid;
64972 u32 priority;
64973 u32 index;
64974 struct xfrm_mark mark;
64975 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64976 index 1a046b1..ee0bef0 100644
64977 --- a/include/rdma/iw_cm.h
64978 +++ b/include/rdma/iw_cm.h
64979 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64980 int backlog);
64981
64982 int (*destroy_listen)(struct iw_cm_id *cm_id);
64983 -};
64984 +} __no_const;
64985
64986 /**
64987 * iw_create_cm_id - Create an IW CM identifier.
64988 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64989 index 8f9dfba..610ab6c 100644
64990 --- a/include/scsi/libfc.h
64991 +++ b/include/scsi/libfc.h
64992 @@ -756,6 +756,7 @@ struct libfc_function_template {
64993 */
64994 void (*disc_stop_final) (struct fc_lport *);
64995 };
64996 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64997
64998 /**
64999 * struct fc_disc - Discovery context
65000 @@ -861,7 +862,7 @@ struct fc_lport {
65001 struct fc_vport *vport;
65002
65003 /* Operational Information */
65004 - struct libfc_function_template tt;
65005 + libfc_function_template_no_const tt;
65006 u8 link_up;
65007 u8 qfull;
65008 enum fc_lport_state state;
65009 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65010 index ba96988..ecf2eb9 100644
65011 --- a/include/scsi/scsi_device.h
65012 +++ b/include/scsi/scsi_device.h
65013 @@ -163,9 +163,9 @@ struct scsi_device {
65014 unsigned int max_device_blocked; /* what device_blocked counts down from */
65015 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65016
65017 - atomic_t iorequest_cnt;
65018 - atomic_t iodone_cnt;
65019 - atomic_t ioerr_cnt;
65020 + atomic_unchecked_t iorequest_cnt;
65021 + atomic_unchecked_t iodone_cnt;
65022 + atomic_unchecked_t ioerr_cnt;
65023
65024 struct device sdev_gendev,
65025 sdev_dev;
65026 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65027 index 719faf1..07b6728 100644
65028 --- a/include/scsi/scsi_transport_fc.h
65029 +++ b/include/scsi/scsi_transport_fc.h
65030 @@ -739,7 +739,8 @@ struct fc_function_template {
65031 unsigned long show_host_system_hostname:1;
65032
65033 unsigned long disable_target_scan:1;
65034 -};
65035 +} __do_const;
65036 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65037
65038
65039 /**
65040 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65041 index 030b87c..98a6954 100644
65042 --- a/include/sound/ak4xxx-adda.h
65043 +++ b/include/sound/ak4xxx-adda.h
65044 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65045 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65046 unsigned char val);
65047 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65048 -};
65049 +} __no_const;
65050
65051 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65052
65053 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65054 index 8c05e47..2b5df97 100644
65055 --- a/include/sound/hwdep.h
65056 +++ b/include/sound/hwdep.h
65057 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65058 struct snd_hwdep_dsp_status *status);
65059 int (*dsp_load)(struct snd_hwdep *hw,
65060 struct snd_hwdep_dsp_image *image);
65061 -};
65062 +} __no_const;
65063
65064 struct snd_hwdep {
65065 struct snd_card *card;
65066 diff --git a/include/sound/info.h b/include/sound/info.h
65067 index 9ca1a49..aba1728 100644
65068 --- a/include/sound/info.h
65069 +++ b/include/sound/info.h
65070 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65071 struct snd_info_buffer *buffer);
65072 void (*write)(struct snd_info_entry *entry,
65073 struct snd_info_buffer *buffer);
65074 -};
65075 +} __no_const;
65076
65077 struct snd_info_entry_ops {
65078 int (*open)(struct snd_info_entry *entry,
65079 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65080 index 0d11128..814178e 100644
65081 --- a/include/sound/pcm.h
65082 +++ b/include/sound/pcm.h
65083 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65084 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65085 int (*ack)(struct snd_pcm_substream *substream);
65086 };
65087 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65088
65089 /*
65090 *
65091 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65092 index af1b49e..a5d55a5 100644
65093 --- a/include/sound/sb16_csp.h
65094 +++ b/include/sound/sb16_csp.h
65095 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65096 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65097 int (*csp_stop) (struct snd_sb_csp * p);
65098 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65099 -};
65100 +} __no_const;
65101
65102 /*
65103 * CSP private data
65104 diff --git a/include/sound/soc.h b/include/sound/soc.h
65105 index c703871..f7fbbbd 100644
65106 --- a/include/sound/soc.h
65107 +++ b/include/sound/soc.h
65108 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
65109 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65110 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65111 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65112 -};
65113 +} __do_const;
65114
65115 struct snd_soc_platform {
65116 const char *name;
65117 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
65118 struct snd_soc_dai_link *dai_link;
65119 struct mutex pcm_mutex;
65120 enum snd_soc_pcm_subclass pcm_subclass;
65121 - struct snd_pcm_ops ops;
65122 + snd_pcm_ops_no_const ops;
65123
65124 unsigned int dev_registered:1;
65125
65126 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65127 index 0c3c2fb..d9d9990 100644
65128 --- a/include/sound/tea575x-tuner.h
65129 +++ b/include/sound/tea575x-tuner.h
65130 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65131
65132 struct snd_tea575x {
65133 struct v4l2_device *v4l2_dev;
65134 - struct v4l2_file_operations fops;
65135 + v4l2_file_operations_no_const fops;
65136 struct video_device vd; /* video device */
65137 int radio_nr; /* radio_nr */
65138 bool tea5759; /* 5759 chip is present */
65139 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65140 index 4119966..1a4671c 100644
65141 --- a/include/sound/ymfpci.h
65142 +++ b/include/sound/ymfpci.h
65143 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65144 spinlock_t reg_lock;
65145 spinlock_t voice_lock;
65146 wait_queue_head_t interrupt_sleep;
65147 - atomic_t interrupt_sleep_count;
65148 + atomic_unchecked_t interrupt_sleep_count;
65149 struct snd_info_entry *proc_entry;
65150 const struct firmware *dsp_microcode;
65151 const struct firmware *controller_microcode;
65152 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65153 index 362e0d9..36b9a83 100644
65154 --- a/include/target/target_core_base.h
65155 +++ b/include/target/target_core_base.h
65156 @@ -441,7 +441,7 @@ struct t10_reservation_ops {
65157 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65158 int (*t10_pr_register)(struct se_cmd *);
65159 int (*t10_pr_clear)(struct se_cmd *);
65160 -};
65161 +} __no_const;
65162
65163 struct t10_reservation {
65164 /* Reservation effects all target ports */
65165 @@ -780,7 +780,7 @@ struct se_device {
65166 spinlock_t stats_lock;
65167 /* Active commands on this virtual SE device */
65168 atomic_t simple_cmds;
65169 - atomic_t dev_ordered_id;
65170 + atomic_unchecked_t dev_ordered_id;
65171 atomic_t execute_tasks;
65172 atomic_t dev_ordered_sync;
65173 atomic_t dev_qf_count;
65174 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65175 new file mode 100644
65176 index 0000000..2efe49d
65177 --- /dev/null
65178 +++ b/include/trace/events/fs.h
65179 @@ -0,0 +1,53 @@
65180 +#undef TRACE_SYSTEM
65181 +#define TRACE_SYSTEM fs
65182 +
65183 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65184 +#define _TRACE_FS_H
65185 +
65186 +#include <linux/fs.h>
65187 +#include <linux/tracepoint.h>
65188 +
65189 +TRACE_EVENT(do_sys_open,
65190 +
65191 + TP_PROTO(char *filename, int flags, int mode),
65192 +
65193 + TP_ARGS(filename, flags, mode),
65194 +
65195 + TP_STRUCT__entry(
65196 + __string( filename, filename )
65197 + __field( int, flags )
65198 + __field( int, mode )
65199 + ),
65200 +
65201 + TP_fast_assign(
65202 + __assign_str(filename, filename);
65203 + __entry->flags = flags;
65204 + __entry->mode = mode;
65205 + ),
65206 +
65207 + TP_printk("\"%s\" %x %o",
65208 + __get_str(filename), __entry->flags, __entry->mode)
65209 +);
65210 +
65211 +TRACE_EVENT(open_exec,
65212 +
65213 + TP_PROTO(const char *filename),
65214 +
65215 + TP_ARGS(filename),
65216 +
65217 + TP_STRUCT__entry(
65218 + __string( filename, filename )
65219 + ),
65220 +
65221 + TP_fast_assign(
65222 + __assign_str(filename, filename);
65223 + ),
65224 +
65225 + TP_printk("\"%s\"",
65226 + __get_str(filename))
65227 +);
65228 +
65229 +#endif /* _TRACE_FS_H */
65230 +
65231 +/* This part must be outside protection */
65232 +#include <trace/define_trace.h>
65233 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65234 index 1c09820..7f5ec79 100644
65235 --- a/include/trace/events/irq.h
65236 +++ b/include/trace/events/irq.h
65237 @@ -36,7 +36,7 @@ struct softirq_action;
65238 */
65239 TRACE_EVENT(irq_handler_entry,
65240
65241 - TP_PROTO(int irq, struct irqaction *action),
65242 + TP_PROTO(int irq, const struct irqaction *action),
65243
65244 TP_ARGS(irq, action),
65245
65246 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65247 */
65248 TRACE_EVENT(irq_handler_exit,
65249
65250 - TP_PROTO(int irq, struct irqaction *action, int ret),
65251 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65252
65253 TP_ARGS(irq, action, ret),
65254
65255 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65256 index f9466fa..f4e2b81 100644
65257 --- a/include/video/udlfb.h
65258 +++ b/include/video/udlfb.h
65259 @@ -53,10 +53,10 @@ struct dlfb_data {
65260 u32 pseudo_palette[256];
65261 int blank_mode; /*one of FB_BLANK_ */
65262 /* blit-only rendering path metrics, exposed through sysfs */
65263 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65264 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65265 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65266 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65267 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65268 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65269 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65270 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65271 };
65272
65273 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65274 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65275 index 0993a22..32ba2fe 100644
65276 --- a/include/video/uvesafb.h
65277 +++ b/include/video/uvesafb.h
65278 @@ -177,6 +177,7 @@ struct uvesafb_par {
65279 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65280 u8 pmi_setpal; /* PMI for palette changes */
65281 u16 *pmi_base; /* protected mode interface location */
65282 + u8 *pmi_code; /* protected mode code location */
65283 void *pmi_start;
65284 void *pmi_pal;
65285 u8 *vbe_state_orig; /*
65286 diff --git a/init/Kconfig b/init/Kconfig
65287 index d07dcf9..fa47d0e 100644
65288 --- a/init/Kconfig
65289 +++ b/init/Kconfig
65290 @@ -835,6 +835,7 @@ endif # CGROUPS
65291
65292 config CHECKPOINT_RESTORE
65293 bool "Checkpoint/restore support" if EXPERT
65294 + depends on !GRKERNSEC
65295 default n
65296 help
65297 Enables additional kernel features in a sake of checkpoint/restore.
65298 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65299 # Security modules
65300 depends on SECURITY_TOMOYO = n
65301 depends on SECURITY_APPARMOR = n
65302 + depends on GRKERNSEC = n
65303
65304 config UIDGID_STRICT_TYPE_CHECKS
65305 bool "Require conversions between uid/gids and their internal representation"
65306 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65307
65308 config COMPAT_BRK
65309 bool "Disable heap randomization"
65310 - default y
65311 + default n
65312 help
65313 Randomizing heap placement makes heap exploits harder, but it
65314 also breaks ancient binaries (including anything libc5 based).
65315 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65316 config STOP_MACHINE
65317 bool
65318 default y
65319 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65320 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65321 help
65322 Need stop_machine() primitive.
65323
65324 diff --git a/init/Makefile b/init/Makefile
65325 index 7bc47ee..6da2dc7 100644
65326 --- a/init/Makefile
65327 +++ b/init/Makefile
65328 @@ -2,6 +2,9 @@
65329 # Makefile for the linux kernel.
65330 #
65331
65332 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65333 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65334 +
65335 obj-y := main.o version.o mounts.o
65336 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65337 obj-y += noinitramfs.o
65338 diff --git a/init/do_mounts.c b/init/do_mounts.c
65339 index d3f0aee..c9322f5 100644
65340 --- a/init/do_mounts.c
65341 +++ b/init/do_mounts.c
65342 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65343 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65344 {
65345 struct super_block *s;
65346 - int err = sys_mount(name, "/root", fs, flags, data);
65347 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65348 if (err)
65349 return err;
65350
65351 - sys_chdir("/root");
65352 + sys_chdir((const char __force_user *)"/root");
65353 s = current->fs->pwd.dentry->d_sb;
65354 ROOT_DEV = s->s_dev;
65355 printk(KERN_INFO
65356 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65357 va_start(args, fmt);
65358 vsprintf(buf, fmt, args);
65359 va_end(args);
65360 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65361 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65362 if (fd >= 0) {
65363 sys_ioctl(fd, FDEJECT, 0);
65364 sys_close(fd);
65365 }
65366 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65367 - fd = sys_open("/dev/console", O_RDWR, 0);
65368 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65369 if (fd >= 0) {
65370 sys_ioctl(fd, TCGETS, (long)&termios);
65371 termios.c_lflag &= ~ICANON;
65372 sys_ioctl(fd, TCSETSF, (long)&termios);
65373 - sys_read(fd, &c, 1);
65374 + sys_read(fd, (char __user *)&c, 1);
65375 termios.c_lflag |= ICANON;
65376 sys_ioctl(fd, TCSETSF, (long)&termios);
65377 sys_close(fd);
65378 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65379 mount_root();
65380 out:
65381 devtmpfs_mount("dev");
65382 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65383 - sys_chroot(".");
65384 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65385 + sys_chroot((const char __force_user *)".");
65386 }
65387 diff --git a/init/do_mounts.h b/init/do_mounts.h
65388 index f5b978a..69dbfe8 100644
65389 --- a/init/do_mounts.h
65390 +++ b/init/do_mounts.h
65391 @@ -15,15 +15,15 @@ extern int root_mountflags;
65392
65393 static inline int create_dev(char *name, dev_t dev)
65394 {
65395 - sys_unlink(name);
65396 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65397 + sys_unlink((char __force_user *)name);
65398 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65399 }
65400
65401 #if BITS_PER_LONG == 32
65402 static inline u32 bstat(char *name)
65403 {
65404 struct stat64 stat;
65405 - if (sys_stat64(name, &stat) != 0)
65406 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65407 return 0;
65408 if (!S_ISBLK(stat.st_mode))
65409 return 0;
65410 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65411 static inline u32 bstat(char *name)
65412 {
65413 struct stat stat;
65414 - if (sys_newstat(name, &stat) != 0)
65415 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65416 return 0;
65417 if (!S_ISBLK(stat.st_mode))
65418 return 0;
65419 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65420 index 135959a2..28a3f43 100644
65421 --- a/init/do_mounts_initrd.c
65422 +++ b/init/do_mounts_initrd.c
65423 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65424 create_dev("/dev/root.old", Root_RAM0);
65425 /* mount initrd on rootfs' /root */
65426 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65427 - sys_mkdir("/old", 0700);
65428 - root_fd = sys_open("/", 0, 0);
65429 - old_fd = sys_open("/old", 0, 0);
65430 + sys_mkdir((const char __force_user *)"/old", 0700);
65431 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65432 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65433 /* move initrd over / and chdir/chroot in initrd root */
65434 - sys_chdir("/root");
65435 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65436 - sys_chroot(".");
65437 + sys_chdir((const char __force_user *)"/root");
65438 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65439 + sys_chroot((const char __force_user *)".");
65440
65441 /*
65442 * In case that a resume from disk is carried out by linuxrc or one of
65443 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65444
65445 /* move initrd to rootfs' /old */
65446 sys_fchdir(old_fd);
65447 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65448 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65449 /* switch root and cwd back to / of rootfs */
65450 sys_fchdir(root_fd);
65451 - sys_chroot(".");
65452 + sys_chroot((const char __force_user *)".");
65453 sys_close(old_fd);
65454 sys_close(root_fd);
65455
65456 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65457 - sys_chdir("/old");
65458 + sys_chdir((const char __force_user *)"/old");
65459 return;
65460 }
65461
65462 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65463 mount_root();
65464
65465 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65466 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65467 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65468 if (!error)
65469 printk("okay\n");
65470 else {
65471 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65472 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65473 if (error == -ENOENT)
65474 printk("/initrd does not exist. Ignored.\n");
65475 else
65476 printk("failed\n");
65477 printk(KERN_NOTICE "Unmounting old root\n");
65478 - sys_umount("/old", MNT_DETACH);
65479 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65480 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65481 if (fd < 0) {
65482 error = fd;
65483 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65484 * mounted in the normal path.
65485 */
65486 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65487 - sys_unlink("/initrd.image");
65488 + sys_unlink((const char __force_user *)"/initrd.image");
65489 handle_initrd();
65490 return 1;
65491 }
65492 }
65493 - sys_unlink("/initrd.image");
65494 + sys_unlink((const char __force_user *)"/initrd.image");
65495 return 0;
65496 }
65497 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65498 index 8cb6db5..d729f50 100644
65499 --- a/init/do_mounts_md.c
65500 +++ b/init/do_mounts_md.c
65501 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65502 partitioned ? "_d" : "", minor,
65503 md_setup_args[ent].device_names);
65504
65505 - fd = sys_open(name, 0, 0);
65506 + fd = sys_open((char __force_user *)name, 0, 0);
65507 if (fd < 0) {
65508 printk(KERN_ERR "md: open failed - cannot start "
65509 "array %s\n", name);
65510 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65511 * array without it
65512 */
65513 sys_close(fd);
65514 - fd = sys_open(name, 0, 0);
65515 + fd = sys_open((char __force_user *)name, 0, 0);
65516 sys_ioctl(fd, BLKRRPART, 0);
65517 }
65518 sys_close(fd);
65519 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65520
65521 wait_for_device_probe();
65522
65523 - fd = sys_open("/dev/md0", 0, 0);
65524 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65525 if (fd >= 0) {
65526 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65527 sys_close(fd);
65528 diff --git a/init/init_task.c b/init/init_task.c
65529 index 8b2f399..f0797c9 100644
65530 --- a/init/init_task.c
65531 +++ b/init/init_task.c
65532 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65533 * Initial thread structure. Alignment of this is handled by a special
65534 * linker map entry.
65535 */
65536 +#ifdef CONFIG_X86
65537 +union thread_union init_thread_union __init_task_data;
65538 +#else
65539 union thread_union init_thread_union __init_task_data =
65540 { INIT_THREAD_INFO(init_task) };
65541 +#endif
65542 diff --git a/init/initramfs.c b/init/initramfs.c
65543 index 84c6bf1..8899338 100644
65544 --- a/init/initramfs.c
65545 +++ b/init/initramfs.c
65546 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65547 }
65548 }
65549
65550 -static long __init do_utime(char *filename, time_t mtime)
65551 +static long __init do_utime(char __force_user *filename, time_t mtime)
65552 {
65553 struct timespec t[2];
65554
65555 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65556 struct dir_entry *de, *tmp;
65557 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65558 list_del(&de->list);
65559 - do_utime(de->name, de->mtime);
65560 + do_utime((char __force_user *)de->name, de->mtime);
65561 kfree(de->name);
65562 kfree(de);
65563 }
65564 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65565 if (nlink >= 2) {
65566 char *old = find_link(major, minor, ino, mode, collected);
65567 if (old)
65568 - return (sys_link(old, collected) < 0) ? -1 : 1;
65569 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65570 }
65571 return 0;
65572 }
65573 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65574 {
65575 struct stat st;
65576
65577 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65578 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65579 if (S_ISDIR(st.st_mode))
65580 - sys_rmdir(path);
65581 + sys_rmdir((char __force_user *)path);
65582 else
65583 - sys_unlink(path);
65584 + sys_unlink((char __force_user *)path);
65585 }
65586 }
65587
65588 @@ -315,7 +315,7 @@ static int __init do_name(void)
65589 int openflags = O_WRONLY|O_CREAT;
65590 if (ml != 1)
65591 openflags |= O_TRUNC;
65592 - wfd = sys_open(collected, openflags, mode);
65593 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65594
65595 if (wfd >= 0) {
65596 sys_fchown(wfd, uid, gid);
65597 @@ -327,17 +327,17 @@ static int __init do_name(void)
65598 }
65599 }
65600 } else if (S_ISDIR(mode)) {
65601 - sys_mkdir(collected, mode);
65602 - sys_chown(collected, uid, gid);
65603 - sys_chmod(collected, mode);
65604 + sys_mkdir((char __force_user *)collected, mode);
65605 + sys_chown((char __force_user *)collected, uid, gid);
65606 + sys_chmod((char __force_user *)collected, mode);
65607 dir_add(collected, mtime);
65608 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65609 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65610 if (maybe_link() == 0) {
65611 - sys_mknod(collected, mode, rdev);
65612 - sys_chown(collected, uid, gid);
65613 - sys_chmod(collected, mode);
65614 - do_utime(collected, mtime);
65615 + sys_mknod((char __force_user *)collected, mode, rdev);
65616 + sys_chown((char __force_user *)collected, uid, gid);
65617 + sys_chmod((char __force_user *)collected, mode);
65618 + do_utime((char __force_user *)collected, mtime);
65619 }
65620 }
65621 return 0;
65622 @@ -346,15 +346,15 @@ static int __init do_name(void)
65623 static int __init do_copy(void)
65624 {
65625 if (count >= body_len) {
65626 - sys_write(wfd, victim, body_len);
65627 + sys_write(wfd, (char __force_user *)victim, body_len);
65628 sys_close(wfd);
65629 - do_utime(vcollected, mtime);
65630 + do_utime((char __force_user *)vcollected, mtime);
65631 kfree(vcollected);
65632 eat(body_len);
65633 state = SkipIt;
65634 return 0;
65635 } else {
65636 - sys_write(wfd, victim, count);
65637 + sys_write(wfd, (char __force_user *)victim, count);
65638 body_len -= count;
65639 eat(count);
65640 return 1;
65641 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
65642 {
65643 collected[N_ALIGN(name_len) + body_len] = '\0';
65644 clean_path(collected, 0);
65645 - sys_symlink(collected + N_ALIGN(name_len), collected);
65646 - sys_lchown(collected, uid, gid);
65647 - do_utime(collected, mtime);
65648 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65649 + sys_lchown((char __force_user *)collected, uid, gid);
65650 + do_utime((char __force_user *)collected, mtime);
65651 state = SkipIt;
65652 next_state = Reset;
65653 return 0;
65654 diff --git a/init/main.c b/init/main.c
65655 index b5cc0a7..5605c91 100644
65656 --- a/init/main.c
65657 +++ b/init/main.c
65658 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65659 extern void tc_init(void);
65660 #endif
65661
65662 +extern void grsecurity_init(void);
65663 +
65664 /*
65665 * Debug helper: via this flag we know that we are in 'early bootup code'
65666 * where only the boot processor is running with IRQ disabled. This means
65667 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65668
65669 __setup("reset_devices", set_reset_devices);
65670
65671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65672 +extern char pax_enter_kernel_user[];
65673 +extern char pax_exit_kernel_user[];
65674 +extern pgdval_t clone_pgd_mask;
65675 +#endif
65676 +
65677 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65678 +static int __init setup_pax_nouderef(char *str)
65679 +{
65680 +#ifdef CONFIG_X86_32
65681 + unsigned int cpu;
65682 + struct desc_struct *gdt;
65683 +
65684 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65685 + gdt = get_cpu_gdt_table(cpu);
65686 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65687 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65688 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65689 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65690 + }
65691 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65692 +#else
65693 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65694 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65695 + clone_pgd_mask = ~(pgdval_t)0UL;
65696 +#endif
65697 +
65698 + return 0;
65699 +}
65700 +early_param("pax_nouderef", setup_pax_nouderef);
65701 +#endif
65702 +
65703 +#ifdef CONFIG_PAX_SOFTMODE
65704 +int pax_softmode;
65705 +
65706 +static int __init setup_pax_softmode(char *str)
65707 +{
65708 + get_option(&str, &pax_softmode);
65709 + return 1;
65710 +}
65711 +__setup("pax_softmode=", setup_pax_softmode);
65712 +#endif
65713 +
65714 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65715 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65716 static const char *panic_later, *panic_param;
65717 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65718 {
65719 int count = preempt_count();
65720 int ret;
65721 + const char *msg1 = "", *msg2 = "";
65722
65723 if (initcall_debug)
65724 ret = do_one_initcall_debug(fn);
65725 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65726 sprintf(msgbuf, "error code %d ", ret);
65727
65728 if (preempt_count() != count) {
65729 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65730 + msg1 = " preemption imbalance";
65731 preempt_count() = count;
65732 }
65733 if (irqs_disabled()) {
65734 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65735 + msg2 = " disabled interrupts";
65736 local_irq_enable();
65737 }
65738 - if (msgbuf[0]) {
65739 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65740 + if (msgbuf[0] || *msg1 || *msg2) {
65741 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65742 }
65743
65744 return ret;
65745 @@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65746 level, level,
65747 &repair_env_string);
65748
65749 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65750 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65751 do_one_initcall(*fn);
65752 +
65753 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65754 + transfer_latent_entropy();
65755 +#endif
65756 +
65757 + }
65758 }
65759
65760 static void __init do_initcalls(void)
65761 @@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65762 {
65763 initcall_t *fn;
65764
65765 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
65766 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65767 do_one_initcall(*fn);
65768 +
65769 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65770 + transfer_latent_entropy();
65771 +#endif
65772 +
65773 + }
65774 }
65775
65776 static void run_init_process(const char *init_filename)
65777 @@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65778 do_basic_setup();
65779
65780 /* Open the /dev/console on the rootfs, this should never fail */
65781 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65782 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65783 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65784
65785 (void) sys_dup(0);
65786 @@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65787 if (!ramdisk_execute_command)
65788 ramdisk_execute_command = "/init";
65789
65790 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65791 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65792 ramdisk_execute_command = NULL;
65793 prepare_namespace();
65794 }
65795
65796 + grsecurity_init();
65797 +
65798 /*
65799 * Ok, we have completed the initial bootup, and
65800 * we're essentially up and running. Get rid of the
65801 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65802 index 8ce5769..4666884 100644
65803 --- a/ipc/mqueue.c
65804 +++ b/ipc/mqueue.c
65805 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65806 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65807 info->attr.mq_msgsize);
65808
65809 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65810 spin_lock(&mq_lock);
65811 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65812 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65813 diff --git a/ipc/msg.c b/ipc/msg.c
65814 index 7385de2..a8180e08 100644
65815 --- a/ipc/msg.c
65816 +++ b/ipc/msg.c
65817 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65818 return security_msg_queue_associate(msq, msgflg);
65819 }
65820
65821 +static struct ipc_ops msg_ops = {
65822 + .getnew = newque,
65823 + .associate = msg_security,
65824 + .more_checks = NULL
65825 +};
65826 +
65827 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65828 {
65829 struct ipc_namespace *ns;
65830 - struct ipc_ops msg_ops;
65831 struct ipc_params msg_params;
65832
65833 ns = current->nsproxy->ipc_ns;
65834
65835 - msg_ops.getnew = newque;
65836 - msg_ops.associate = msg_security;
65837 - msg_ops.more_checks = NULL;
65838 -
65839 msg_params.key = key;
65840 msg_params.flg = msgflg;
65841
65842 diff --git a/ipc/sem.c b/ipc/sem.c
65843 index 5215a81..cfc0cac 100644
65844 --- a/ipc/sem.c
65845 +++ b/ipc/sem.c
65846 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65847 return 0;
65848 }
65849
65850 +static struct ipc_ops sem_ops = {
65851 + .getnew = newary,
65852 + .associate = sem_security,
65853 + .more_checks = sem_more_checks
65854 +};
65855 +
65856 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65857 {
65858 struct ipc_namespace *ns;
65859 - struct ipc_ops sem_ops;
65860 struct ipc_params sem_params;
65861
65862 ns = current->nsproxy->ipc_ns;
65863 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65864 if (nsems < 0 || nsems > ns->sc_semmsl)
65865 return -EINVAL;
65866
65867 - sem_ops.getnew = newary;
65868 - sem_ops.associate = sem_security;
65869 - sem_ops.more_checks = sem_more_checks;
65870 -
65871 sem_params.key = key;
65872 sem_params.flg = semflg;
65873 sem_params.u.nsems = nsems;
65874 diff --git a/ipc/shm.c b/ipc/shm.c
65875 index 41c1285..cf6404c 100644
65876 --- a/ipc/shm.c
65877 +++ b/ipc/shm.c
65878 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65879 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65880 #endif
65881
65882 +#ifdef CONFIG_GRKERNSEC
65883 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65884 + const time_t shm_createtime, const uid_t cuid,
65885 + const int shmid);
65886 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65887 + const time_t shm_createtime);
65888 +#endif
65889 +
65890 void shm_init_ns(struct ipc_namespace *ns)
65891 {
65892 ns->shm_ctlmax = SHMMAX;
65893 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65894 shp->shm_lprid = 0;
65895 shp->shm_atim = shp->shm_dtim = 0;
65896 shp->shm_ctim = get_seconds();
65897 +#ifdef CONFIG_GRKERNSEC
65898 + {
65899 + struct timespec timeval;
65900 + do_posix_clock_monotonic_gettime(&timeval);
65901 +
65902 + shp->shm_createtime = timeval.tv_sec;
65903 + }
65904 +#endif
65905 shp->shm_segsz = size;
65906 shp->shm_nattch = 0;
65907 shp->shm_file = file;
65908 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65909 return 0;
65910 }
65911
65912 +static struct ipc_ops shm_ops = {
65913 + .getnew = newseg,
65914 + .associate = shm_security,
65915 + .more_checks = shm_more_checks
65916 +};
65917 +
65918 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65919 {
65920 struct ipc_namespace *ns;
65921 - struct ipc_ops shm_ops;
65922 struct ipc_params shm_params;
65923
65924 ns = current->nsproxy->ipc_ns;
65925
65926 - shm_ops.getnew = newseg;
65927 - shm_ops.associate = shm_security;
65928 - shm_ops.more_checks = shm_more_checks;
65929 -
65930 shm_params.key = key;
65931 shm_params.flg = shmflg;
65932 shm_params.u.size = size;
65933 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65934 f_mode = FMODE_READ | FMODE_WRITE;
65935 }
65936 if (shmflg & SHM_EXEC) {
65937 +
65938 +#ifdef CONFIG_PAX_MPROTECT
65939 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65940 + goto out;
65941 +#endif
65942 +
65943 prot |= PROT_EXEC;
65944 acc_mode |= S_IXUGO;
65945 }
65946 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65947 if (err)
65948 goto out_unlock;
65949
65950 +#ifdef CONFIG_GRKERNSEC
65951 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65952 + shp->shm_perm.cuid, shmid) ||
65953 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65954 + err = -EACCES;
65955 + goto out_unlock;
65956 + }
65957 +#endif
65958 +
65959 path = shp->shm_file->f_path;
65960 path_get(&path);
65961 shp->shm_nattch++;
65962 +#ifdef CONFIG_GRKERNSEC
65963 + shp->shm_lapid = current->pid;
65964 +#endif
65965 size = i_size_read(path.dentry->d_inode);
65966 shm_unlock(shp);
65967
65968 diff --git a/kernel/acct.c b/kernel/acct.c
65969 index 02e6167..54824f7 100644
65970 --- a/kernel/acct.c
65971 +++ b/kernel/acct.c
65972 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65973 */
65974 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65975 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65976 - file->f_op->write(file, (char *)&ac,
65977 + file->f_op->write(file, (char __force_user *)&ac,
65978 sizeof(acct_t), &file->f_pos);
65979 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65980 set_fs(fs);
65981 diff --git a/kernel/audit.c b/kernel/audit.c
65982 index 1c7f2c6..9ba5359 100644
65983 --- a/kernel/audit.c
65984 +++ b/kernel/audit.c
65985 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65986 3) suppressed due to audit_rate_limit
65987 4) suppressed due to audit_backlog_limit
65988 */
65989 -static atomic_t audit_lost = ATOMIC_INIT(0);
65990 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65991
65992 /* The netlink socket. */
65993 static struct sock *audit_sock;
65994 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65995 unsigned long now;
65996 int print;
65997
65998 - atomic_inc(&audit_lost);
65999 + atomic_inc_unchecked(&audit_lost);
66000
66001 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66002
66003 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66004 printk(KERN_WARNING
66005 "audit: audit_lost=%d audit_rate_limit=%d "
66006 "audit_backlog_limit=%d\n",
66007 - atomic_read(&audit_lost),
66008 + atomic_read_unchecked(&audit_lost),
66009 audit_rate_limit,
66010 audit_backlog_limit);
66011 audit_panic(message);
66012 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66013 status_set.pid = audit_pid;
66014 status_set.rate_limit = audit_rate_limit;
66015 status_set.backlog_limit = audit_backlog_limit;
66016 - status_set.lost = atomic_read(&audit_lost);
66017 + status_set.lost = atomic_read_unchecked(&audit_lost);
66018 status_set.backlog = skb_queue_len(&audit_skb_queue);
66019 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66020 &status_set, sizeof(status_set));
66021 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66022 index 4b96415..d8c16ee 100644
66023 --- a/kernel/auditsc.c
66024 +++ b/kernel/auditsc.c
66025 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66026 }
66027
66028 /* global counter which is incremented every time something logs in */
66029 -static atomic_t session_id = ATOMIC_INIT(0);
66030 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66031
66032 /**
66033 * audit_set_loginuid - set current task's audit_context loginuid
66034 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66035 return -EPERM;
66036 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66037
66038 - sessionid = atomic_inc_return(&session_id);
66039 + sessionid = atomic_inc_return_unchecked(&session_id);
66040 if (context && context->in_syscall) {
66041 struct audit_buffer *ab;
66042
66043 diff --git a/kernel/capability.c b/kernel/capability.c
66044 index 493d972..ea17248 100644
66045 --- a/kernel/capability.c
66046 +++ b/kernel/capability.c
66047 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66048 * before modification is attempted and the application
66049 * fails.
66050 */
66051 + if (tocopy > ARRAY_SIZE(kdata))
66052 + return -EFAULT;
66053 +
66054 if (copy_to_user(dataptr, kdata, tocopy
66055 * sizeof(struct __user_cap_data_struct))) {
66056 return -EFAULT;
66057 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66058 int ret;
66059
66060 rcu_read_lock();
66061 - ret = security_capable(__task_cred(t), ns, cap);
66062 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66063 + gr_task_is_capable(t, __task_cred(t), cap);
66064 rcu_read_unlock();
66065
66066 - return (ret == 0);
66067 + return ret;
66068 }
66069
66070 /**
66071 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66072 int ret;
66073
66074 rcu_read_lock();
66075 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66076 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66077 rcu_read_unlock();
66078
66079 - return (ret == 0);
66080 + return ret;
66081 }
66082
66083 /**
66084 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66085 BUG();
66086 }
66087
66088 - if (security_capable(current_cred(), ns, cap) == 0) {
66089 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66090 current->flags |= PF_SUPERPRIV;
66091 return true;
66092 }
66093 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66094 }
66095 EXPORT_SYMBOL(ns_capable);
66096
66097 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66098 +{
66099 + if (unlikely(!cap_valid(cap))) {
66100 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66101 + BUG();
66102 + }
66103 +
66104 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66105 + current->flags |= PF_SUPERPRIV;
66106 + return true;
66107 + }
66108 + return false;
66109 +}
66110 +EXPORT_SYMBOL(ns_capable_nolog);
66111 +
66112 /**
66113 * capable - Determine if the current task has a superior capability in effect
66114 * @cap: The capability to be tested for
66115 @@ -408,6 +427,12 @@ bool capable(int cap)
66116 }
66117 EXPORT_SYMBOL(capable);
66118
66119 +bool capable_nolog(int cap)
66120 +{
66121 + return ns_capable_nolog(&init_user_ns, cap);
66122 +}
66123 +EXPORT_SYMBOL(capable_nolog);
66124 +
66125 /**
66126 * nsown_capable - Check superior capability to one's own user_ns
66127 * @cap: The capability in question
66128 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66129
66130 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66131 }
66132 +
66133 +bool inode_capable_nolog(const struct inode *inode, int cap)
66134 +{
66135 + struct user_namespace *ns = current_user_ns();
66136 +
66137 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66138 +}
66139 diff --git a/kernel/compat.c b/kernel/compat.c
66140 index c28a306..b4d0cf3 100644
66141 --- a/kernel/compat.c
66142 +++ b/kernel/compat.c
66143 @@ -13,6 +13,7 @@
66144
66145 #include <linux/linkage.h>
66146 #include <linux/compat.h>
66147 +#include <linux/module.h>
66148 #include <linux/errno.h>
66149 #include <linux/time.h>
66150 #include <linux/signal.h>
66151 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66152 mm_segment_t oldfs;
66153 long ret;
66154
66155 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66156 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66157 oldfs = get_fs();
66158 set_fs(KERNEL_DS);
66159 ret = hrtimer_nanosleep_restart(restart);
66160 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66161 oldfs = get_fs();
66162 set_fs(KERNEL_DS);
66163 ret = hrtimer_nanosleep(&tu,
66164 - rmtp ? (struct timespec __user *)&rmt : NULL,
66165 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66166 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66167 set_fs(oldfs);
66168
66169 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66170 mm_segment_t old_fs = get_fs();
66171
66172 set_fs(KERNEL_DS);
66173 - ret = sys_sigpending((old_sigset_t __user *) &s);
66174 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66175 set_fs(old_fs);
66176 if (ret == 0)
66177 ret = put_user(s, set);
66178 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66179 mm_segment_t old_fs = get_fs();
66180
66181 set_fs(KERNEL_DS);
66182 - ret = sys_old_getrlimit(resource, &r);
66183 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66184 set_fs(old_fs);
66185
66186 if (!ret) {
66187 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66188 mm_segment_t old_fs = get_fs();
66189
66190 set_fs(KERNEL_DS);
66191 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66192 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66193 set_fs(old_fs);
66194
66195 if (ret)
66196 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66197 set_fs (KERNEL_DS);
66198 ret = sys_wait4(pid,
66199 (stat_addr ?
66200 - (unsigned int __user *) &status : NULL),
66201 - options, (struct rusage __user *) &r);
66202 + (unsigned int __force_user *) &status : NULL),
66203 + options, (struct rusage __force_user *) &r);
66204 set_fs (old_fs);
66205
66206 if (ret > 0) {
66207 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66208 memset(&info, 0, sizeof(info));
66209
66210 set_fs(KERNEL_DS);
66211 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66212 - uru ? (struct rusage __user *)&ru : NULL);
66213 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66214 + uru ? (struct rusage __force_user *)&ru : NULL);
66215 set_fs(old_fs);
66216
66217 if ((ret < 0) || (info.si_signo == 0))
66218 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66219 oldfs = get_fs();
66220 set_fs(KERNEL_DS);
66221 err = sys_timer_settime(timer_id, flags,
66222 - (struct itimerspec __user *) &newts,
66223 - (struct itimerspec __user *) &oldts);
66224 + (struct itimerspec __force_user *) &newts,
66225 + (struct itimerspec __force_user *) &oldts);
66226 set_fs(oldfs);
66227 if (!err && old && put_compat_itimerspec(old, &oldts))
66228 return -EFAULT;
66229 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66230 oldfs = get_fs();
66231 set_fs(KERNEL_DS);
66232 err = sys_timer_gettime(timer_id,
66233 - (struct itimerspec __user *) &ts);
66234 + (struct itimerspec __force_user *) &ts);
66235 set_fs(oldfs);
66236 if (!err && put_compat_itimerspec(setting, &ts))
66237 return -EFAULT;
66238 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66239 oldfs = get_fs();
66240 set_fs(KERNEL_DS);
66241 err = sys_clock_settime(which_clock,
66242 - (struct timespec __user *) &ts);
66243 + (struct timespec __force_user *) &ts);
66244 set_fs(oldfs);
66245 return err;
66246 }
66247 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66248 oldfs = get_fs();
66249 set_fs(KERNEL_DS);
66250 err = sys_clock_gettime(which_clock,
66251 - (struct timespec __user *) &ts);
66252 + (struct timespec __force_user *) &ts);
66253 set_fs(oldfs);
66254 if (!err && put_compat_timespec(&ts, tp))
66255 return -EFAULT;
66256 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66257
66258 oldfs = get_fs();
66259 set_fs(KERNEL_DS);
66260 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66261 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66262 set_fs(oldfs);
66263
66264 err = compat_put_timex(utp, &txc);
66265 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66266 oldfs = get_fs();
66267 set_fs(KERNEL_DS);
66268 err = sys_clock_getres(which_clock,
66269 - (struct timespec __user *) &ts);
66270 + (struct timespec __force_user *) &ts);
66271 set_fs(oldfs);
66272 if (!err && tp && put_compat_timespec(&ts, tp))
66273 return -EFAULT;
66274 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66275 long err;
66276 mm_segment_t oldfs;
66277 struct timespec tu;
66278 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66279 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66280
66281 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66282 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66283 oldfs = get_fs();
66284 set_fs(KERNEL_DS);
66285 err = clock_nanosleep_restart(restart);
66286 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66287 oldfs = get_fs();
66288 set_fs(KERNEL_DS);
66289 err = sys_clock_nanosleep(which_clock, flags,
66290 - (struct timespec __user *) &in,
66291 - (struct timespec __user *) &out);
66292 + (struct timespec __force_user *) &in,
66293 + (struct timespec __force_user *) &out);
66294 set_fs(oldfs);
66295
66296 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66297 diff --git a/kernel/configs.c b/kernel/configs.c
66298 index 42e8fa0..9e7406b 100644
66299 --- a/kernel/configs.c
66300 +++ b/kernel/configs.c
66301 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66302 struct proc_dir_entry *entry;
66303
66304 /* create the current config file */
66305 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66306 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66307 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66308 + &ikconfig_file_ops);
66309 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66310 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66311 + &ikconfig_file_ops);
66312 +#endif
66313 +#else
66314 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66315 &ikconfig_file_ops);
66316 +#endif
66317 +
66318 if (!entry)
66319 return -ENOMEM;
66320
66321 diff --git a/kernel/cred.c b/kernel/cred.c
66322 index de728ac..e3c267c 100644
66323 --- a/kernel/cred.c
66324 +++ b/kernel/cred.c
66325 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66326 validate_creds(cred);
66327 alter_cred_subscribers(cred, -1);
66328 put_cred(cred);
66329 +
66330 +#ifdef CONFIG_GRKERNSEC_SETXID
66331 + cred = (struct cred *) tsk->delayed_cred;
66332 + if (cred != NULL) {
66333 + tsk->delayed_cred = NULL;
66334 + validate_creds(cred);
66335 + alter_cred_subscribers(cred, -1);
66336 + put_cred(cred);
66337 + }
66338 +#endif
66339 }
66340
66341 /**
66342 @@ -469,7 +479,7 @@ error_put:
66343 * Always returns 0 thus allowing this function to be tail-called at the end
66344 * of, say, sys_setgid().
66345 */
66346 -int commit_creds(struct cred *new)
66347 +static int __commit_creds(struct cred *new)
66348 {
66349 struct task_struct *task = current;
66350 const struct cred *old = task->real_cred;
66351 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66352
66353 get_cred(new); /* we will require a ref for the subj creds too */
66354
66355 + gr_set_role_label(task, new->uid, new->gid);
66356 +
66357 /* dumpability changes */
66358 if (!uid_eq(old->euid, new->euid) ||
66359 !gid_eq(old->egid, new->egid) ||
66360 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66361 put_cred(old);
66362 return 0;
66363 }
66364 +#ifdef CONFIG_GRKERNSEC_SETXID
66365 +extern int set_user(struct cred *new);
66366 +
66367 +void gr_delayed_cred_worker(void)
66368 +{
66369 + const struct cred *new = current->delayed_cred;
66370 + struct cred *ncred;
66371 +
66372 + current->delayed_cred = NULL;
66373 +
66374 + if (current_uid() && new != NULL) {
66375 + // from doing get_cred on it when queueing this
66376 + put_cred(new);
66377 + return;
66378 + } else if (new == NULL)
66379 + return;
66380 +
66381 + ncred = prepare_creds();
66382 + if (!ncred)
66383 + goto die;
66384 + // uids
66385 + ncred->uid = new->uid;
66386 + ncred->euid = new->euid;
66387 + ncred->suid = new->suid;
66388 + ncred->fsuid = new->fsuid;
66389 + // gids
66390 + ncred->gid = new->gid;
66391 + ncred->egid = new->egid;
66392 + ncred->sgid = new->sgid;
66393 + ncred->fsgid = new->fsgid;
66394 + // groups
66395 + if (set_groups(ncred, new->group_info) < 0) {
66396 + abort_creds(ncred);
66397 + goto die;
66398 + }
66399 + // caps
66400 + ncred->securebits = new->securebits;
66401 + ncred->cap_inheritable = new->cap_inheritable;
66402 + ncred->cap_permitted = new->cap_permitted;
66403 + ncred->cap_effective = new->cap_effective;
66404 + ncred->cap_bset = new->cap_bset;
66405 +
66406 + if (set_user(ncred)) {
66407 + abort_creds(ncred);
66408 + goto die;
66409 + }
66410 +
66411 + // from doing get_cred on it when queueing this
66412 + put_cred(new);
66413 +
66414 + __commit_creds(ncred);
66415 + return;
66416 +die:
66417 + // from doing get_cred on it when queueing this
66418 + put_cred(new);
66419 + do_group_exit(SIGKILL);
66420 +}
66421 +#endif
66422 +
66423 +int commit_creds(struct cred *new)
66424 +{
66425 +#ifdef CONFIG_GRKERNSEC_SETXID
66426 + int ret;
66427 + int schedule_it = 0;
66428 + struct task_struct *t;
66429 +
66430 + /* we won't get called with tasklist_lock held for writing
66431 + and interrupts disabled as the cred struct in that case is
66432 + init_cred
66433 + */
66434 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66435 + !current_uid() && new->uid) {
66436 + schedule_it = 1;
66437 + }
66438 + ret = __commit_creds(new);
66439 + if (schedule_it) {
66440 + rcu_read_lock();
66441 + read_lock(&tasklist_lock);
66442 + for (t = next_thread(current); t != current;
66443 + t = next_thread(t)) {
66444 + if (t->delayed_cred == NULL) {
66445 + t->delayed_cred = get_cred(new);
66446 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66447 + set_tsk_need_resched(t);
66448 + }
66449 + }
66450 + read_unlock(&tasklist_lock);
66451 + rcu_read_unlock();
66452 + }
66453 + return ret;
66454 +#else
66455 + return __commit_creds(new);
66456 +#endif
66457 +}
66458 +
66459 EXPORT_SYMBOL(commit_creds);
66460
66461 /**
66462 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66463 index 0557f24..1a00d9a 100644
66464 --- a/kernel/debug/debug_core.c
66465 +++ b/kernel/debug/debug_core.c
66466 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66467 */
66468 static atomic_t masters_in_kgdb;
66469 static atomic_t slaves_in_kgdb;
66470 -static atomic_t kgdb_break_tasklet_var;
66471 +static atomic_unchecked_t kgdb_break_tasklet_var;
66472 atomic_t kgdb_setting_breakpoint;
66473
66474 struct task_struct *kgdb_usethread;
66475 @@ -132,7 +132,7 @@ int kgdb_single_step;
66476 static pid_t kgdb_sstep_pid;
66477
66478 /* to keep track of the CPU which is doing the single stepping*/
66479 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66480 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66481
66482 /*
66483 * If you are debugging a problem where roundup (the collection of
66484 @@ -540,7 +540,7 @@ return_normal:
66485 * kernel will only try for the value of sstep_tries before
66486 * giving up and continuing on.
66487 */
66488 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66489 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66490 (kgdb_info[cpu].task &&
66491 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66492 atomic_set(&kgdb_active, -1);
66493 @@ -634,8 +634,8 @@ cpu_master_loop:
66494 }
66495
66496 kgdb_restore:
66497 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66498 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66499 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66500 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66501 if (kgdb_info[sstep_cpu].task)
66502 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66503 else
66504 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66505 static void kgdb_tasklet_bpt(unsigned long ing)
66506 {
66507 kgdb_breakpoint();
66508 - atomic_set(&kgdb_break_tasklet_var, 0);
66509 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66510 }
66511
66512 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66513
66514 void kgdb_schedule_breakpoint(void)
66515 {
66516 - if (atomic_read(&kgdb_break_tasklet_var) ||
66517 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66518 atomic_read(&kgdb_active) != -1 ||
66519 atomic_read(&kgdb_setting_breakpoint))
66520 return;
66521 - atomic_inc(&kgdb_break_tasklet_var);
66522 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66523 tasklet_schedule(&kgdb_tasklet_breakpoint);
66524 }
66525 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66526 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66527 index 1f91413..362a0a1 100644
66528 --- a/kernel/debug/kdb/kdb_main.c
66529 +++ b/kernel/debug/kdb/kdb_main.c
66530 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66531 list_for_each_entry(mod, kdb_modules, list) {
66532
66533 kdb_printf("%-20s%8u 0x%p ", mod->name,
66534 - mod->core_size, (void *)mod);
66535 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66536 #ifdef CONFIG_MODULE_UNLOAD
66537 kdb_printf("%4ld ", module_refcount(mod));
66538 #endif
66539 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66540 kdb_printf(" (Loading)");
66541 else
66542 kdb_printf(" (Live)");
66543 - kdb_printf(" 0x%p", mod->module_core);
66544 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66545
66546 #ifdef CONFIG_MODULE_UNLOAD
66547 {
66548 diff --git a/kernel/events/core.c b/kernel/events/core.c
66549 index d7d71d6..f54b76f 100644
66550 --- a/kernel/events/core.c
66551 +++ b/kernel/events/core.c
66552 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66553 return 0;
66554 }
66555
66556 -static atomic64_t perf_event_id;
66557 +static atomic64_unchecked_t perf_event_id;
66558
66559 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66560 enum event_type_t event_type);
66561 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66562
66563 static inline u64 perf_event_count(struct perf_event *event)
66564 {
66565 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66566 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66567 }
66568
66569 static u64 perf_event_read(struct perf_event *event)
66570 @@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66571 mutex_lock(&event->child_mutex);
66572 total += perf_event_read(event);
66573 *enabled += event->total_time_enabled +
66574 - atomic64_read(&event->child_total_time_enabled);
66575 + atomic64_read_unchecked(&event->child_total_time_enabled);
66576 *running += event->total_time_running +
66577 - atomic64_read(&event->child_total_time_running);
66578 + atomic64_read_unchecked(&event->child_total_time_running);
66579
66580 list_for_each_entry(child, &event->child_list, child_list) {
66581 total += perf_event_read(child);
66582 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66583 userpg->offset -= local64_read(&event->hw.prev_count);
66584
66585 userpg->time_enabled = enabled +
66586 - atomic64_read(&event->child_total_time_enabled);
66587 + atomic64_read_unchecked(&event->child_total_time_enabled);
66588
66589 userpg->time_running = running +
66590 - atomic64_read(&event->child_total_time_running);
66591 + atomic64_read_unchecked(&event->child_total_time_running);
66592
66593 arch_perf_update_userpage(userpg, now);
66594
66595 @@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66596 values[n++] = perf_event_count(event);
66597 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66598 values[n++] = enabled +
66599 - atomic64_read(&event->child_total_time_enabled);
66600 + atomic64_read_unchecked(&event->child_total_time_enabled);
66601 }
66602 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66603 values[n++] = running +
66604 - atomic64_read(&event->child_total_time_running);
66605 + atomic64_read_unchecked(&event->child_total_time_running);
66606 }
66607 if (read_format & PERF_FORMAT_ID)
66608 values[n++] = primary_event_id(event);
66609 @@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66610 * need to add enough zero bytes after the string to handle
66611 * the 64bit alignment we do later.
66612 */
66613 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66614 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66615 if (!buf) {
66616 name = strncpy(tmp, "//enomem", sizeof(tmp));
66617 goto got_name;
66618 }
66619 - name = d_path(&file->f_path, buf, PATH_MAX);
66620 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66621 if (IS_ERR(name)) {
66622 name = strncpy(tmp, "//toolong", sizeof(tmp));
66623 goto got_name;
66624 @@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66625 event->parent = parent_event;
66626
66627 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66628 - event->id = atomic64_inc_return(&perf_event_id);
66629 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66630
66631 event->state = PERF_EVENT_STATE_INACTIVE;
66632
66633 @@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66634 /*
66635 * Add back the child's count to the parent's count:
66636 */
66637 - atomic64_add(child_val, &parent_event->child_count);
66638 - atomic64_add(child_event->total_time_enabled,
66639 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66640 + atomic64_add_unchecked(child_event->total_time_enabled,
66641 &parent_event->child_total_time_enabled);
66642 - atomic64_add(child_event->total_time_running,
66643 + atomic64_add_unchecked(child_event->total_time_running,
66644 &parent_event->child_total_time_running);
66645
66646 /*
66647 diff --git a/kernel/exit.c b/kernel/exit.c
66648 index 46ce8da..c648f3a 100644
66649 --- a/kernel/exit.c
66650 +++ b/kernel/exit.c
66651 @@ -59,6 +59,10 @@
66652 #include <asm/pgtable.h>
66653 #include <asm/mmu_context.h>
66654
66655 +#ifdef CONFIG_GRKERNSEC
66656 +extern rwlock_t grsec_exec_file_lock;
66657 +#endif
66658 +
66659 static void exit_mm(struct task_struct * tsk);
66660
66661 static void __unhash_process(struct task_struct *p, bool group_dead)
66662 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66663 struct task_struct *leader;
66664 int zap_leader;
66665 repeat:
66666 +#ifdef CONFIG_NET
66667 + gr_del_task_from_ip_table(p);
66668 +#endif
66669 +
66670 /* don't need to get the RCU readlock here - the process is dead and
66671 * can't be modifying its own credentials. But shut RCU-lockdep up */
66672 rcu_read_lock();
66673 @@ -394,7 +402,7 @@ int allow_signal(int sig)
66674 * know it'll be handled, so that they don't get converted to
66675 * SIGKILL or just silently dropped.
66676 */
66677 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66678 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66679 recalc_sigpending();
66680 spin_unlock_irq(&current->sighand->siglock);
66681 return 0;
66682 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66683 vsnprintf(current->comm, sizeof(current->comm), name, args);
66684 va_end(args);
66685
66686 +#ifdef CONFIG_GRKERNSEC
66687 + write_lock(&grsec_exec_file_lock);
66688 + if (current->exec_file) {
66689 + fput(current->exec_file);
66690 + current->exec_file = NULL;
66691 + }
66692 + write_unlock(&grsec_exec_file_lock);
66693 +#endif
66694 +
66695 + gr_set_kernel_label(current);
66696 +
66697 /*
66698 * If we were started as result of loading a module, close all of the
66699 * user space pages. We don't need them, and if we didn't close them
66700 @@ -907,6 +926,8 @@ void do_exit(long code)
66701 struct task_struct *tsk = current;
66702 int group_dead;
66703
66704 + set_fs(USER_DS);
66705 +
66706 profile_task_exit(tsk);
66707
66708 WARN_ON(blk_needs_flush_plug(tsk));
66709 @@ -923,7 +944,6 @@ void do_exit(long code)
66710 * mm_release()->clear_child_tid() from writing to a user-controlled
66711 * kernel address.
66712 */
66713 - set_fs(USER_DS);
66714
66715 ptrace_event(PTRACE_EVENT_EXIT, code);
66716
66717 @@ -985,6 +1005,9 @@ void do_exit(long code)
66718 tsk->exit_code = code;
66719 taskstats_exit(tsk, group_dead);
66720
66721 + gr_acl_handle_psacct(tsk, code);
66722 + gr_acl_handle_exit();
66723 +
66724 exit_mm(tsk);
66725
66726 if (group_dead)
66727 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66728 * Take down every thread in the group. This is called by fatal signals
66729 * as well as by sys_exit_group (below).
66730 */
66731 -void
66732 +__noreturn void
66733 do_group_exit(int exit_code)
66734 {
66735 struct signal_struct *sig = current->signal;
66736 diff --git a/kernel/fork.c b/kernel/fork.c
66737 index f00e319..c212fbc 100644
66738 --- a/kernel/fork.c
66739 +++ b/kernel/fork.c
66740 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66741 *stackend = STACK_END_MAGIC; /* for overflow detection */
66742
66743 #ifdef CONFIG_CC_STACKPROTECTOR
66744 - tsk->stack_canary = get_random_int();
66745 + tsk->stack_canary = pax_get_random_long();
66746 #endif
66747
66748 /*
66749 @@ -345,13 +345,78 @@ out:
66750 }
66751
66752 #ifdef CONFIG_MMU
66753 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66754 +{
66755 + struct vm_area_struct *tmp;
66756 + unsigned long charge;
66757 + struct mempolicy *pol;
66758 + struct file *file;
66759 +
66760 + charge = 0;
66761 + if (mpnt->vm_flags & VM_ACCOUNT) {
66762 + unsigned long len;
66763 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66764 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66765 + goto fail_nomem;
66766 + charge = len;
66767 + }
66768 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66769 + if (!tmp)
66770 + goto fail_nomem;
66771 + *tmp = *mpnt;
66772 + tmp->vm_mm = mm;
66773 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66774 + pol = mpol_dup(vma_policy(mpnt));
66775 + if (IS_ERR(pol))
66776 + goto fail_nomem_policy;
66777 + vma_set_policy(tmp, pol);
66778 + if (anon_vma_fork(tmp, mpnt))
66779 + goto fail_nomem_anon_vma_fork;
66780 + tmp->vm_flags &= ~VM_LOCKED;
66781 + tmp->vm_next = tmp->vm_prev = NULL;
66782 + tmp->vm_mirror = NULL;
66783 + file = tmp->vm_file;
66784 + if (file) {
66785 + struct inode *inode = file->f_path.dentry->d_inode;
66786 + struct address_space *mapping = file->f_mapping;
66787 +
66788 + get_file(file);
66789 + if (tmp->vm_flags & VM_DENYWRITE)
66790 + atomic_dec(&inode->i_writecount);
66791 + mutex_lock(&mapping->i_mmap_mutex);
66792 + if (tmp->vm_flags & VM_SHARED)
66793 + mapping->i_mmap_writable++;
66794 + flush_dcache_mmap_lock(mapping);
66795 + /* insert tmp into the share list, just after mpnt */
66796 + vma_prio_tree_add(tmp, mpnt);
66797 + flush_dcache_mmap_unlock(mapping);
66798 + mutex_unlock(&mapping->i_mmap_mutex);
66799 + }
66800 +
66801 + /*
66802 + * Clear hugetlb-related page reserves for children. This only
66803 + * affects MAP_PRIVATE mappings. Faults generated by the child
66804 + * are not guaranteed to succeed, even if read-only
66805 + */
66806 + if (is_vm_hugetlb_page(tmp))
66807 + reset_vma_resv_huge_pages(tmp);
66808 +
66809 + return tmp;
66810 +
66811 +fail_nomem_anon_vma_fork:
66812 + mpol_put(pol);
66813 +fail_nomem_policy:
66814 + kmem_cache_free(vm_area_cachep, tmp);
66815 +fail_nomem:
66816 + vm_unacct_memory(charge);
66817 + return NULL;
66818 +}
66819 +
66820 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66821 {
66822 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66823 struct rb_node **rb_link, *rb_parent;
66824 int retval;
66825 - unsigned long charge;
66826 - struct mempolicy *pol;
66827
66828 down_write(&oldmm->mmap_sem);
66829 flush_cache_dup_mm(oldmm);
66830 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66831 mm->locked_vm = 0;
66832 mm->mmap = NULL;
66833 mm->mmap_cache = NULL;
66834 - mm->free_area_cache = oldmm->mmap_base;
66835 - mm->cached_hole_size = ~0UL;
66836 + mm->free_area_cache = oldmm->free_area_cache;
66837 + mm->cached_hole_size = oldmm->cached_hole_size;
66838 mm->map_count = 0;
66839 cpumask_clear(mm_cpumask(mm));
66840 mm->mm_rb = RB_ROOT;
66841 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66842
66843 prev = NULL;
66844 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66845 - struct file *file;
66846 -
66847 if (mpnt->vm_flags & VM_DONTCOPY) {
66848 long pages = vma_pages(mpnt);
66849 mm->total_vm -= pages;
66850 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66851 -pages);
66852 continue;
66853 }
66854 - charge = 0;
66855 - if (mpnt->vm_flags & VM_ACCOUNT) {
66856 - unsigned long len;
66857 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66858 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66859 - goto fail_nomem;
66860 - charge = len;
66861 + tmp = dup_vma(mm, oldmm, mpnt);
66862 + if (!tmp) {
66863 + retval = -ENOMEM;
66864 + goto out;
66865 }
66866 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66867 - if (!tmp)
66868 - goto fail_nomem;
66869 - *tmp = *mpnt;
66870 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66871 - pol = mpol_dup(vma_policy(mpnt));
66872 - retval = PTR_ERR(pol);
66873 - if (IS_ERR(pol))
66874 - goto fail_nomem_policy;
66875 - vma_set_policy(tmp, pol);
66876 - tmp->vm_mm = mm;
66877 - if (anon_vma_fork(tmp, mpnt))
66878 - goto fail_nomem_anon_vma_fork;
66879 - tmp->vm_flags &= ~VM_LOCKED;
66880 - tmp->vm_next = tmp->vm_prev = NULL;
66881 - file = tmp->vm_file;
66882 - if (file) {
66883 - struct inode *inode = file->f_path.dentry->d_inode;
66884 - struct address_space *mapping = file->f_mapping;
66885 -
66886 - get_file(file);
66887 - if (tmp->vm_flags & VM_DENYWRITE)
66888 - atomic_dec(&inode->i_writecount);
66889 - mutex_lock(&mapping->i_mmap_mutex);
66890 - if (tmp->vm_flags & VM_SHARED)
66891 - mapping->i_mmap_writable++;
66892 - flush_dcache_mmap_lock(mapping);
66893 - /* insert tmp into the share list, just after mpnt */
66894 - vma_prio_tree_add(tmp, mpnt);
66895 - flush_dcache_mmap_unlock(mapping);
66896 - mutex_unlock(&mapping->i_mmap_mutex);
66897 - }
66898 -
66899 - /*
66900 - * Clear hugetlb-related page reserves for children. This only
66901 - * affects MAP_PRIVATE mappings. Faults generated by the child
66902 - * are not guaranteed to succeed, even if read-only
66903 - */
66904 - if (is_vm_hugetlb_page(tmp))
66905 - reset_vma_resv_huge_pages(tmp);
66906
66907 /*
66908 * Link in the new vma and copy the page table entries.
66909 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66910 if (retval)
66911 goto out;
66912
66913 - if (file && uprobe_mmap(tmp))
66914 + if (tmp->vm_file && uprobe_mmap(tmp))
66915 goto out;
66916 }
66917 +
66918 +#ifdef CONFIG_PAX_SEGMEXEC
66919 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66920 + struct vm_area_struct *mpnt_m;
66921 +
66922 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66923 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66924 +
66925 + if (!mpnt->vm_mirror)
66926 + continue;
66927 +
66928 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66929 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66930 + mpnt->vm_mirror = mpnt_m;
66931 + } else {
66932 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66933 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66934 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66935 + mpnt->vm_mirror->vm_mirror = mpnt;
66936 + }
66937 + }
66938 + BUG_ON(mpnt_m);
66939 + }
66940 +#endif
66941 +
66942 /* a new mm has just been created */
66943 arch_dup_mmap(oldmm, mm);
66944 retval = 0;
66945 @@ -470,14 +515,6 @@ out:
66946 flush_tlb_mm(oldmm);
66947 up_write(&oldmm->mmap_sem);
66948 return retval;
66949 -fail_nomem_anon_vma_fork:
66950 - mpol_put(pol);
66951 -fail_nomem_policy:
66952 - kmem_cache_free(vm_area_cachep, tmp);
66953 -fail_nomem:
66954 - retval = -ENOMEM;
66955 - vm_unacct_memory(charge);
66956 - goto out;
66957 }
66958
66959 static inline int mm_alloc_pgd(struct mm_struct *mm)
66960 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66961 return ERR_PTR(err);
66962
66963 mm = get_task_mm(task);
66964 - if (mm && mm != current->mm &&
66965 - !ptrace_may_access(task, mode)) {
66966 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66967 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66968 mmput(mm);
66969 mm = ERR_PTR(-EACCES);
66970 }
66971 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66972 spin_unlock(&fs->lock);
66973 return -EAGAIN;
66974 }
66975 - fs->users++;
66976 + atomic_inc(&fs->users);
66977 spin_unlock(&fs->lock);
66978 return 0;
66979 }
66980 tsk->fs = copy_fs_struct(fs);
66981 if (!tsk->fs)
66982 return -ENOMEM;
66983 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66984 return 0;
66985 }
66986
66987 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66988 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66989 #endif
66990 retval = -EAGAIN;
66991 +
66992 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66993 +
66994 if (atomic_read(&p->real_cred->user->processes) >=
66995 task_rlimit(p, RLIMIT_NPROC)) {
66996 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66997 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66998 /* Need tasklist lock for parent etc handling! */
66999 write_lock_irq(&tasklist_lock);
67000
67001 + /* synchronizes with gr_set_acls() */
67002 + gr_copy_label(p);
67003 +
67004 /* CLONE_PARENT re-uses the old parent */
67005 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67006 p->real_parent = current->real_parent;
67007 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
67008 bad_fork_free:
67009 free_task(p);
67010 fork_out:
67011 + gr_log_forkfail(retval);
67012 +
67013 return ERR_PTR(retval);
67014 }
67015
67016 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
67017 if (clone_flags & CLONE_PARENT_SETTID)
67018 put_user(nr, parent_tidptr);
67019
67020 + gr_handle_brute_check();
67021 +
67022 if (clone_flags & CLONE_VFORK) {
67023 p->vfork_done = &vfork;
67024 init_completion(&vfork);
67025 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67026 return 0;
67027
67028 /* don't need lock here; in the worst case we'll do useless copy */
67029 - if (fs->users == 1)
67030 + if (atomic_read(&fs->users) == 1)
67031 return 0;
67032
67033 *new_fsp = copy_fs_struct(fs);
67034 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67035 fs = current->fs;
67036 spin_lock(&fs->lock);
67037 current->fs = new_fs;
67038 - if (--fs->users)
67039 + gr_set_chroot_entries(current, &current->fs->root);
67040 + if (atomic_dec_return(&fs->users))
67041 new_fs = NULL;
67042 else
67043 new_fs = fs;
67044 diff --git a/kernel/futex.c b/kernel/futex.c
67045 index 3717e7b..473c750 100644
67046 --- a/kernel/futex.c
67047 +++ b/kernel/futex.c
67048 @@ -54,6 +54,7 @@
67049 #include <linux/mount.h>
67050 #include <linux/pagemap.h>
67051 #include <linux/syscalls.h>
67052 +#include <linux/ptrace.h>
67053 #include <linux/signal.h>
67054 #include <linux/export.h>
67055 #include <linux/magic.h>
67056 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67057 struct page *page, *page_head;
67058 int err, ro = 0;
67059
67060 +#ifdef CONFIG_PAX_SEGMEXEC
67061 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67062 + return -EFAULT;
67063 +#endif
67064 +
67065 /*
67066 * The futex address must be "naturally" aligned.
67067 */
67068 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67069 {
67070 u32 curval;
67071 int i;
67072 + mm_segment_t oldfs;
67073
67074 /*
67075 * This will fail and we want it. Some arch implementations do
67076 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67077 * implementation, the non-functional ones will return
67078 * -ENOSYS.
67079 */
67080 + oldfs = get_fs();
67081 + set_fs(USER_DS);
67082 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67083 futex_cmpxchg_enabled = 1;
67084 + set_fs(oldfs);
67085
67086 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67087 plist_head_init(&futex_queues[i].chain);
67088 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67089 index 9b22d03..6295b62 100644
67090 --- a/kernel/gcov/base.c
67091 +++ b/kernel/gcov/base.c
67092 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67093 }
67094
67095 #ifdef CONFIG_MODULES
67096 -static inline int within(void *addr, void *start, unsigned long size)
67097 -{
67098 - return ((addr >= start) && (addr < start + size));
67099 -}
67100 -
67101 /* Update list and generate events when modules are unloaded. */
67102 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67103 void *data)
67104 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67105 prev = NULL;
67106 /* Remove entries located in module from linked list. */
67107 for (info = gcov_info_head; info; info = info->next) {
67108 - if (within(info, mod->module_core, mod->core_size)) {
67109 + if (within_module_core_rw((unsigned long)info, mod)) {
67110 if (prev)
67111 prev->next = info->next;
67112 else
67113 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67114 index 6db7a5e..25b6648 100644
67115 --- a/kernel/hrtimer.c
67116 +++ b/kernel/hrtimer.c
67117 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67118 local_irq_restore(flags);
67119 }
67120
67121 -static void run_hrtimer_softirq(struct softirq_action *h)
67122 +static void run_hrtimer_softirq(void)
67123 {
67124 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67125
67126 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67127 index 4304919..408c4c0 100644
67128 --- a/kernel/jump_label.c
67129 +++ b/kernel/jump_label.c
67130 @@ -13,6 +13,7 @@
67131 #include <linux/sort.h>
67132 #include <linux/err.h>
67133 #include <linux/static_key.h>
67134 +#include <linux/mm.h>
67135
67136 #ifdef HAVE_JUMP_LABEL
67137
67138 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67139
67140 size = (((unsigned long)stop - (unsigned long)start)
67141 / sizeof(struct jump_entry));
67142 + pax_open_kernel();
67143 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67144 + pax_close_kernel();
67145 }
67146
67147 static void jump_label_update(struct static_key *key, int enable);
67148 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67149 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67150 struct jump_entry *iter;
67151
67152 + pax_open_kernel();
67153 for (iter = iter_start; iter < iter_stop; iter++) {
67154 if (within_module_init(iter->code, mod))
67155 iter->code = 0;
67156 }
67157 + pax_close_kernel();
67158 }
67159
67160 static int
67161 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67162 index 2169fee..45c017a 100644
67163 --- a/kernel/kallsyms.c
67164 +++ b/kernel/kallsyms.c
67165 @@ -11,6 +11,9 @@
67166 * Changed the compression method from stem compression to "table lookup"
67167 * compression (see scripts/kallsyms.c for a more complete description)
67168 */
67169 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67170 +#define __INCLUDED_BY_HIDESYM 1
67171 +#endif
67172 #include <linux/kallsyms.h>
67173 #include <linux/module.h>
67174 #include <linux/init.h>
67175 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67176
67177 static inline int is_kernel_inittext(unsigned long addr)
67178 {
67179 + if (system_state != SYSTEM_BOOTING)
67180 + return 0;
67181 +
67182 if (addr >= (unsigned long)_sinittext
67183 && addr <= (unsigned long)_einittext)
67184 return 1;
67185 return 0;
67186 }
67187
67188 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67189 +#ifdef CONFIG_MODULES
67190 +static inline int is_module_text(unsigned long addr)
67191 +{
67192 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67193 + return 1;
67194 +
67195 + addr = ktla_ktva(addr);
67196 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67197 +}
67198 +#else
67199 +static inline int is_module_text(unsigned long addr)
67200 +{
67201 + return 0;
67202 +}
67203 +#endif
67204 +#endif
67205 +
67206 static inline int is_kernel_text(unsigned long addr)
67207 {
67208 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67209 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67210
67211 static inline int is_kernel(unsigned long addr)
67212 {
67213 +
67214 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67215 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67216 + return 1;
67217 +
67218 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67219 +#else
67220 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67221 +#endif
67222 +
67223 return 1;
67224 return in_gate_area_no_mm(addr);
67225 }
67226
67227 static int is_ksym_addr(unsigned long addr)
67228 {
67229 +
67230 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67231 + if (is_module_text(addr))
67232 + return 0;
67233 +#endif
67234 +
67235 if (all_var)
67236 return is_kernel(addr);
67237
67238 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67239
67240 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67241 {
67242 - iter->name[0] = '\0';
67243 iter->nameoff = get_symbol_offset(new_pos);
67244 iter->pos = new_pos;
67245 }
67246 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67247 {
67248 struct kallsym_iter *iter = m->private;
67249
67250 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67251 + if (current_uid())
67252 + return 0;
67253 +#endif
67254 +
67255 /* Some debugging symbols have no name. Ignore them. */
67256 if (!iter->name[0])
67257 return 0;
67258 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67259 */
67260 type = iter->exported ? toupper(iter->type) :
67261 tolower(iter->type);
67262 +
67263 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67264 type, iter->name, iter->module_name);
67265 } else
67266 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67267 struct kallsym_iter *iter;
67268 int ret;
67269
67270 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67271 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67272 if (!iter)
67273 return -ENOMEM;
67274 reset_iter(iter, 0);
67275 diff --git a/kernel/kexec.c b/kernel/kexec.c
67276 index 4e2e472..cd0c7ae 100644
67277 --- a/kernel/kexec.c
67278 +++ b/kernel/kexec.c
67279 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67280 unsigned long flags)
67281 {
67282 struct compat_kexec_segment in;
67283 - struct kexec_segment out, __user *ksegments;
67284 + struct kexec_segment out;
67285 + struct kexec_segment __user *ksegments;
67286 unsigned long i, result;
67287
67288 /* Don't allow clients that don't understand the native
67289 diff --git a/kernel/kmod.c b/kernel/kmod.c
67290 index ff2c7cb..085d7af 100644
67291 --- a/kernel/kmod.c
67292 +++ b/kernel/kmod.c
67293 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67294 kfree(info->argv);
67295 }
67296
67297 -static int call_modprobe(char *module_name, int wait)
67298 +static int call_modprobe(char *module_name, char *module_param, int wait)
67299 {
67300 static char *envp[] = {
67301 "HOME=/",
67302 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67303 NULL
67304 };
67305
67306 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67307 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67308 if (!argv)
67309 goto out;
67310
67311 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67312 argv[1] = "-q";
67313 argv[2] = "--";
67314 argv[3] = module_name; /* check free_modprobe_argv() */
67315 - argv[4] = NULL;
67316 + argv[4] = module_param;
67317 + argv[5] = NULL;
67318
67319 return call_usermodehelper_fns(modprobe_path, argv, envp,
67320 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67321 @@ -112,9 +113,8 @@ out:
67322 * If module auto-loading support is disabled then this function
67323 * becomes a no-operation.
67324 */
67325 -int __request_module(bool wait, const char *fmt, ...)
67326 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67327 {
67328 - va_list args;
67329 char module_name[MODULE_NAME_LEN];
67330 unsigned int max_modprobes;
67331 int ret;
67332 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67333 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67334 static int kmod_loop_msg;
67335
67336 - va_start(args, fmt);
67337 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67338 - va_end(args);
67339 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67340 if (ret >= MODULE_NAME_LEN)
67341 return -ENAMETOOLONG;
67342
67343 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67344 if (ret)
67345 return ret;
67346
67347 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67348 + if (!current_uid()) {
67349 + /* hack to workaround consolekit/udisks stupidity */
67350 + read_lock(&tasklist_lock);
67351 + if (!strcmp(current->comm, "mount") &&
67352 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67353 + read_unlock(&tasklist_lock);
67354 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67355 + return -EPERM;
67356 + }
67357 + read_unlock(&tasklist_lock);
67358 + }
67359 +#endif
67360 +
67361 /* If modprobe needs a service that is in a module, we get a recursive
67362 * loop. Limit the number of running kmod threads to max_threads/2 or
67363 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67364 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67365
67366 trace_module_request(module_name, wait, _RET_IP_);
67367
67368 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67369 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67370
67371 atomic_dec(&kmod_concurrent);
67372 return ret;
67373 }
67374 +
67375 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67376 +{
67377 + va_list args;
67378 + int ret;
67379 +
67380 + va_start(args, fmt);
67381 + ret = ____request_module(wait, module_param, fmt, args);
67382 + va_end(args);
67383 +
67384 + return ret;
67385 +}
67386 +
67387 +int __request_module(bool wait, const char *fmt, ...)
67388 +{
67389 + va_list args;
67390 + int ret;
67391 +
67392 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67393 + if (current_uid()) {
67394 + char module_param[MODULE_NAME_LEN];
67395 +
67396 + memset(module_param, 0, sizeof(module_param));
67397 +
67398 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67399 +
67400 + va_start(args, fmt);
67401 + ret = ____request_module(wait, module_param, fmt, args);
67402 + va_end(args);
67403 +
67404 + return ret;
67405 + }
67406 +#endif
67407 +
67408 + va_start(args, fmt);
67409 + ret = ____request_module(wait, NULL, fmt, args);
67410 + va_end(args);
67411 +
67412 + return ret;
67413 +}
67414 +
67415 EXPORT_SYMBOL(__request_module);
67416 #endif /* CONFIG_MODULES */
67417
67418 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67419 *
67420 * Thus the __user pointer cast is valid here.
67421 */
67422 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67423 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67424
67425 /*
67426 * If ret is 0, either ____call_usermodehelper failed and the
67427 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67428 index c62b854..cb67968 100644
67429 --- a/kernel/kprobes.c
67430 +++ b/kernel/kprobes.c
67431 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67432 * kernel image and loaded module images reside. This is required
67433 * so x86_64 can correctly handle the %rip-relative fixups.
67434 */
67435 - kip->insns = module_alloc(PAGE_SIZE);
67436 + kip->insns = module_alloc_exec(PAGE_SIZE);
67437 if (!kip->insns) {
67438 kfree(kip);
67439 return NULL;
67440 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67441 */
67442 if (!list_is_singular(&kip->list)) {
67443 list_del(&kip->list);
67444 - module_free(NULL, kip->insns);
67445 + module_free_exec(NULL, kip->insns);
67446 kfree(kip);
67447 }
67448 return 1;
67449 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67450 {
67451 int i, err = 0;
67452 unsigned long offset = 0, size = 0;
67453 - char *modname, namebuf[128];
67454 + char *modname, namebuf[KSYM_NAME_LEN];
67455 const char *symbol_name;
67456 void *addr;
67457 struct kprobe_blackpoint *kb;
67458 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67459 const char *sym = NULL;
67460 unsigned int i = *(loff_t *) v;
67461 unsigned long offset = 0;
67462 - char *modname, namebuf[128];
67463 + char *modname, namebuf[KSYM_NAME_LEN];
67464
67465 head = &kprobe_table[i];
67466 preempt_disable();
67467 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67468 index 4e316e1..5501eef 100644
67469 --- a/kernel/ksysfs.c
67470 +++ b/kernel/ksysfs.c
67471 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67472 {
67473 if (count+1 > UEVENT_HELPER_PATH_LEN)
67474 return -ENOENT;
67475 + if (!capable(CAP_SYS_ADMIN))
67476 + return -EPERM;
67477 memcpy(uevent_helper, buf, count);
67478 uevent_helper[count] = '\0';
67479 if (count && uevent_helper[count-1] == '\n')
67480 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67481 index ea9ee45..67ebc8f 100644
67482 --- a/kernel/lockdep.c
67483 +++ b/kernel/lockdep.c
67484 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67485 end = (unsigned long) &_end,
67486 addr = (unsigned long) obj;
67487
67488 +#ifdef CONFIG_PAX_KERNEXEC
67489 + start = ktla_ktva(start);
67490 +#endif
67491 +
67492 /*
67493 * static variable?
67494 */
67495 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67496 if (!static_obj(lock->key)) {
67497 debug_locks_off();
67498 printk("INFO: trying to register non-static key.\n");
67499 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67500 printk("the code is fine but needs lockdep annotation.\n");
67501 printk("turning off the locking correctness validator.\n");
67502 dump_stack();
67503 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67504 if (!class)
67505 return 0;
67506 }
67507 - atomic_inc((atomic_t *)&class->ops);
67508 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67509 if (very_verbose(class)) {
67510 printk("\nacquire class [%p] %s", class->key, class->name);
67511 if (class->name_version > 1)
67512 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67513 index 91c32a0..b2c71c5 100644
67514 --- a/kernel/lockdep_proc.c
67515 +++ b/kernel/lockdep_proc.c
67516 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67517
67518 static void print_name(struct seq_file *m, struct lock_class *class)
67519 {
67520 - char str[128];
67521 + char str[KSYM_NAME_LEN];
67522 const char *name = class->name;
67523
67524 if (!name) {
67525 diff --git a/kernel/module.c b/kernel/module.c
67526 index 4edbd9c..165e780 100644
67527 --- a/kernel/module.c
67528 +++ b/kernel/module.c
67529 @@ -58,6 +58,7 @@
67530 #include <linux/jump_label.h>
67531 #include <linux/pfn.h>
67532 #include <linux/bsearch.h>
67533 +#include <linux/grsecurity.h>
67534
67535 #define CREATE_TRACE_POINTS
67536 #include <trace/events/module.h>
67537 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67538
67539 /* Bounds of module allocation, for speeding __module_address.
67540 * Protected by module_mutex. */
67541 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67542 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67543 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67544
67545 int register_module_notifier(struct notifier_block * nb)
67546 {
67547 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67548 return true;
67549
67550 list_for_each_entry_rcu(mod, &modules, list) {
67551 - struct symsearch arr[] = {
67552 + struct symsearch modarr[] = {
67553 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67554 NOT_GPL_ONLY, false },
67555 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67556 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67557 #endif
67558 };
67559
67560 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67561 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67562 return true;
67563 }
67564 return false;
67565 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67566 static int percpu_modalloc(struct module *mod,
67567 unsigned long size, unsigned long align)
67568 {
67569 - if (align > PAGE_SIZE) {
67570 + if (align-1 >= PAGE_SIZE) {
67571 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67572 mod->name, align, PAGE_SIZE);
67573 align = PAGE_SIZE;
67574 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67575 static ssize_t show_coresize(struct module_attribute *mattr,
67576 struct module_kobject *mk, char *buffer)
67577 {
67578 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67579 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67580 }
67581
67582 static struct module_attribute modinfo_coresize =
67583 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67584 static ssize_t show_initsize(struct module_attribute *mattr,
67585 struct module_kobject *mk, char *buffer)
67586 {
67587 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67588 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67589 }
67590
67591 static struct module_attribute modinfo_initsize =
67592 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67593 */
67594 #ifdef CONFIG_SYSFS
67595
67596 -#ifdef CONFIG_KALLSYMS
67597 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67598 static inline bool sect_empty(const Elf_Shdr *sect)
67599 {
67600 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67601 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67602
67603 static void unset_module_core_ro_nx(struct module *mod)
67604 {
67605 - set_page_attributes(mod->module_core + mod->core_text_size,
67606 - mod->module_core + mod->core_size,
67607 + set_page_attributes(mod->module_core_rw,
67608 + mod->module_core_rw + mod->core_size_rw,
67609 set_memory_x);
67610 - set_page_attributes(mod->module_core,
67611 - mod->module_core + mod->core_ro_size,
67612 + set_page_attributes(mod->module_core_rx,
67613 + mod->module_core_rx + mod->core_size_rx,
67614 set_memory_rw);
67615 }
67616
67617 static void unset_module_init_ro_nx(struct module *mod)
67618 {
67619 - set_page_attributes(mod->module_init + mod->init_text_size,
67620 - mod->module_init + mod->init_size,
67621 + set_page_attributes(mod->module_init_rw,
67622 + mod->module_init_rw + mod->init_size_rw,
67623 set_memory_x);
67624 - set_page_attributes(mod->module_init,
67625 - mod->module_init + mod->init_ro_size,
67626 + set_page_attributes(mod->module_init_rx,
67627 + mod->module_init_rx + mod->init_size_rx,
67628 set_memory_rw);
67629 }
67630
67631 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67632
67633 mutex_lock(&module_mutex);
67634 list_for_each_entry_rcu(mod, &modules, list) {
67635 - if ((mod->module_core) && (mod->core_text_size)) {
67636 - set_page_attributes(mod->module_core,
67637 - mod->module_core + mod->core_text_size,
67638 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67639 + set_page_attributes(mod->module_core_rx,
67640 + mod->module_core_rx + mod->core_size_rx,
67641 set_memory_rw);
67642 }
67643 - if ((mod->module_init) && (mod->init_text_size)) {
67644 - set_page_attributes(mod->module_init,
67645 - mod->module_init + mod->init_text_size,
67646 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67647 + set_page_attributes(mod->module_init_rx,
67648 + mod->module_init_rx + mod->init_size_rx,
67649 set_memory_rw);
67650 }
67651 }
67652 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67653
67654 mutex_lock(&module_mutex);
67655 list_for_each_entry_rcu(mod, &modules, list) {
67656 - if ((mod->module_core) && (mod->core_text_size)) {
67657 - set_page_attributes(mod->module_core,
67658 - mod->module_core + mod->core_text_size,
67659 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67660 + set_page_attributes(mod->module_core_rx,
67661 + mod->module_core_rx + mod->core_size_rx,
67662 set_memory_ro);
67663 }
67664 - if ((mod->module_init) && (mod->init_text_size)) {
67665 - set_page_attributes(mod->module_init,
67666 - mod->module_init + mod->init_text_size,
67667 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67668 + set_page_attributes(mod->module_init_rx,
67669 + mod->module_init_rx + mod->init_size_rx,
67670 set_memory_ro);
67671 }
67672 }
67673 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67674
67675 /* This may be NULL, but that's OK */
67676 unset_module_init_ro_nx(mod);
67677 - module_free(mod, mod->module_init);
67678 + module_free(mod, mod->module_init_rw);
67679 + module_free_exec(mod, mod->module_init_rx);
67680 kfree(mod->args);
67681 percpu_modfree(mod);
67682
67683 /* Free lock-classes: */
67684 - lockdep_free_key_range(mod->module_core, mod->core_size);
67685 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67686 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67687
67688 /* Finally, free the core (containing the module structure) */
67689 unset_module_core_ro_nx(mod);
67690 - module_free(mod, mod->module_core);
67691 + module_free_exec(mod, mod->module_core_rx);
67692 + module_free(mod, mod->module_core_rw);
67693
67694 #ifdef CONFIG_MPU
67695 update_protections(current->mm);
67696 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67697 int ret = 0;
67698 const struct kernel_symbol *ksym;
67699
67700 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67701 + int is_fs_load = 0;
67702 + int register_filesystem_found = 0;
67703 + char *p;
67704 +
67705 + p = strstr(mod->args, "grsec_modharden_fs");
67706 + if (p) {
67707 + char *endptr = p + strlen("grsec_modharden_fs");
67708 + /* copy \0 as well */
67709 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67710 + is_fs_load = 1;
67711 + }
67712 +#endif
67713 +
67714 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67715 const char *name = info->strtab + sym[i].st_name;
67716
67717 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67718 + /* it's a real shame this will never get ripped and copied
67719 + upstream! ;(
67720 + */
67721 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67722 + register_filesystem_found = 1;
67723 +#endif
67724 +
67725 switch (sym[i].st_shndx) {
67726 case SHN_COMMON:
67727 /* We compiled with -fno-common. These are not
67728 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67729 ksym = resolve_symbol_wait(mod, info, name);
67730 /* Ok if resolved. */
67731 if (ksym && !IS_ERR(ksym)) {
67732 + pax_open_kernel();
67733 sym[i].st_value = ksym->value;
67734 + pax_close_kernel();
67735 break;
67736 }
67737
67738 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67739 secbase = (unsigned long)mod_percpu(mod);
67740 else
67741 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67742 + pax_open_kernel();
67743 sym[i].st_value += secbase;
67744 + pax_close_kernel();
67745 break;
67746 }
67747 }
67748
67749 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67750 + if (is_fs_load && !register_filesystem_found) {
67751 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67752 + ret = -EPERM;
67753 + }
67754 +#endif
67755 +
67756 return ret;
67757 }
67758
67759 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67760 || s->sh_entsize != ~0UL
67761 || strstarts(sname, ".init"))
67762 continue;
67763 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67764 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67765 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67766 + else
67767 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67768 pr_debug("\t%s\n", sname);
67769 }
67770 - switch (m) {
67771 - case 0: /* executable */
67772 - mod->core_size = debug_align(mod->core_size);
67773 - mod->core_text_size = mod->core_size;
67774 - break;
67775 - case 1: /* RO: text and ro-data */
67776 - mod->core_size = debug_align(mod->core_size);
67777 - mod->core_ro_size = mod->core_size;
67778 - break;
67779 - case 3: /* whole core */
67780 - mod->core_size = debug_align(mod->core_size);
67781 - break;
67782 - }
67783 }
67784
67785 pr_debug("Init section allocation order:\n");
67786 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67787 || s->sh_entsize != ~0UL
67788 || !strstarts(sname, ".init"))
67789 continue;
67790 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67791 - | INIT_OFFSET_MASK);
67792 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67793 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67794 + else
67795 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67796 + s->sh_entsize |= INIT_OFFSET_MASK;
67797 pr_debug("\t%s\n", sname);
67798 }
67799 - switch (m) {
67800 - case 0: /* executable */
67801 - mod->init_size = debug_align(mod->init_size);
67802 - mod->init_text_size = mod->init_size;
67803 - break;
67804 - case 1: /* RO: text and ro-data */
67805 - mod->init_size = debug_align(mod->init_size);
67806 - mod->init_ro_size = mod->init_size;
67807 - break;
67808 - case 3: /* whole init */
67809 - mod->init_size = debug_align(mod->init_size);
67810 - break;
67811 - }
67812 }
67813 }
67814
67815 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67816
67817 /* Put symbol section at end of init part of module. */
67818 symsect->sh_flags |= SHF_ALLOC;
67819 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67820 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67821 info->index.sym) | INIT_OFFSET_MASK;
67822 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67823
67824 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67825 }
67826
67827 /* Append room for core symbols at end of core part. */
67828 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67829 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67830 - mod->core_size += strtab_size;
67831 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67832 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67833 + mod->core_size_rx += strtab_size;
67834
67835 /* Put string table section at end of init part of module. */
67836 strsect->sh_flags |= SHF_ALLOC;
67837 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67838 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67839 info->index.str) | INIT_OFFSET_MASK;
67840 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67841 }
67842 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67843 /* Make sure we get permanent strtab: don't use info->strtab. */
67844 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67845
67846 + pax_open_kernel();
67847 +
67848 /* Set types up while we still have access to sections. */
67849 for (i = 0; i < mod->num_symtab; i++)
67850 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67851
67852 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67853 - mod->core_strtab = s = mod->module_core + info->stroffs;
67854 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67855 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67856 src = mod->symtab;
67857 *dst = *src;
67858 *s++ = 0;
67859 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67860 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67861 }
67862 mod->core_num_syms = ndst;
67863 +
67864 + pax_close_kernel();
67865 }
67866 #else
67867 static inline void layout_symtab(struct module *mod, struct load_info *info)
67868 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67869 return size == 0 ? NULL : vmalloc_exec(size);
67870 }
67871
67872 -static void *module_alloc_update_bounds(unsigned long size)
67873 +static void *module_alloc_update_bounds_rw(unsigned long size)
67874 {
67875 void *ret = module_alloc(size);
67876
67877 if (ret) {
67878 mutex_lock(&module_mutex);
67879 /* Update module bounds. */
67880 - if ((unsigned long)ret < module_addr_min)
67881 - module_addr_min = (unsigned long)ret;
67882 - if ((unsigned long)ret + size > module_addr_max)
67883 - module_addr_max = (unsigned long)ret + size;
67884 + if ((unsigned long)ret < module_addr_min_rw)
67885 + module_addr_min_rw = (unsigned long)ret;
67886 + if ((unsigned long)ret + size > module_addr_max_rw)
67887 + module_addr_max_rw = (unsigned long)ret + size;
67888 + mutex_unlock(&module_mutex);
67889 + }
67890 + return ret;
67891 +}
67892 +
67893 +static void *module_alloc_update_bounds_rx(unsigned long size)
67894 +{
67895 + void *ret = module_alloc_exec(size);
67896 +
67897 + if (ret) {
67898 + mutex_lock(&module_mutex);
67899 + /* Update module bounds. */
67900 + if ((unsigned long)ret < module_addr_min_rx)
67901 + module_addr_min_rx = (unsigned long)ret;
67902 + if ((unsigned long)ret + size > module_addr_max_rx)
67903 + module_addr_max_rx = (unsigned long)ret + size;
67904 mutex_unlock(&module_mutex);
67905 }
67906 return ret;
67907 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67908 static int check_modinfo(struct module *mod, struct load_info *info)
67909 {
67910 const char *modmagic = get_modinfo(info, "vermagic");
67911 + const char *license = get_modinfo(info, "license");
67912 int err;
67913
67914 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67915 + if (!license || !license_is_gpl_compatible(license))
67916 + return -ENOEXEC;
67917 +#endif
67918 +
67919 /* This is allowed: modprobe --force will invalidate it. */
67920 if (!modmagic) {
67921 err = try_to_force_load(mod, "bad vermagic");
67922 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67923 }
67924
67925 /* Set up license info based on the info section */
67926 - set_license(mod, get_modinfo(info, "license"));
67927 + set_license(mod, license);
67928
67929 return 0;
67930 }
67931 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67932 void *ptr;
67933
67934 /* Do the allocs. */
67935 - ptr = module_alloc_update_bounds(mod->core_size);
67936 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67937 /*
67938 * The pointer to this block is stored in the module structure
67939 * which is inside the block. Just mark it as not being a
67940 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67941 if (!ptr)
67942 return -ENOMEM;
67943
67944 - memset(ptr, 0, mod->core_size);
67945 - mod->module_core = ptr;
67946 + memset(ptr, 0, mod->core_size_rw);
67947 + mod->module_core_rw = ptr;
67948
67949 - ptr = module_alloc_update_bounds(mod->init_size);
67950 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67951 /*
67952 * The pointer to this block is stored in the module structure
67953 * which is inside the block. This block doesn't need to be
67954 * scanned as it contains data and code that will be freed
67955 * after the module is initialized.
67956 */
67957 - kmemleak_ignore(ptr);
67958 - if (!ptr && mod->init_size) {
67959 - module_free(mod, mod->module_core);
67960 + kmemleak_not_leak(ptr);
67961 + if (!ptr && mod->init_size_rw) {
67962 + module_free(mod, mod->module_core_rw);
67963 return -ENOMEM;
67964 }
67965 - memset(ptr, 0, mod->init_size);
67966 - mod->module_init = ptr;
67967 + memset(ptr, 0, mod->init_size_rw);
67968 + mod->module_init_rw = ptr;
67969 +
67970 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67971 + kmemleak_not_leak(ptr);
67972 + if (!ptr) {
67973 + module_free(mod, mod->module_init_rw);
67974 + module_free(mod, mod->module_core_rw);
67975 + return -ENOMEM;
67976 + }
67977 +
67978 + pax_open_kernel();
67979 + memset(ptr, 0, mod->core_size_rx);
67980 + pax_close_kernel();
67981 + mod->module_core_rx = ptr;
67982 +
67983 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67984 + kmemleak_not_leak(ptr);
67985 + if (!ptr && mod->init_size_rx) {
67986 + module_free_exec(mod, mod->module_core_rx);
67987 + module_free(mod, mod->module_init_rw);
67988 + module_free(mod, mod->module_core_rw);
67989 + return -ENOMEM;
67990 + }
67991 +
67992 + pax_open_kernel();
67993 + memset(ptr, 0, mod->init_size_rx);
67994 + pax_close_kernel();
67995 + mod->module_init_rx = ptr;
67996
67997 /* Transfer each section which specifies SHF_ALLOC */
67998 pr_debug("final section addresses:\n");
67999 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68000 if (!(shdr->sh_flags & SHF_ALLOC))
68001 continue;
68002
68003 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68004 - dest = mod->module_init
68005 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68006 - else
68007 - dest = mod->module_core + shdr->sh_entsize;
68008 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68009 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68010 + dest = mod->module_init_rw
68011 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68012 + else
68013 + dest = mod->module_init_rx
68014 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68015 + } else {
68016 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68017 + dest = mod->module_core_rw + shdr->sh_entsize;
68018 + else
68019 + dest = mod->module_core_rx + shdr->sh_entsize;
68020 + }
68021 +
68022 + if (shdr->sh_type != SHT_NOBITS) {
68023 +
68024 +#ifdef CONFIG_PAX_KERNEXEC
68025 +#ifdef CONFIG_X86_64
68026 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68027 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68028 +#endif
68029 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68030 + pax_open_kernel();
68031 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68032 + pax_close_kernel();
68033 + } else
68034 +#endif
68035
68036 - if (shdr->sh_type != SHT_NOBITS)
68037 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68038 + }
68039 /* Update sh_addr to point to copy in image. */
68040 - shdr->sh_addr = (unsigned long)dest;
68041 +
68042 +#ifdef CONFIG_PAX_KERNEXEC
68043 + if (shdr->sh_flags & SHF_EXECINSTR)
68044 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68045 + else
68046 +#endif
68047 +
68048 + shdr->sh_addr = (unsigned long)dest;
68049 pr_debug("\t0x%lx %s\n",
68050 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68051 }
68052 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68053 * Do it before processing of module parameters, so the module
68054 * can provide parameter accessor functions of its own.
68055 */
68056 - if (mod->module_init)
68057 - flush_icache_range((unsigned long)mod->module_init,
68058 - (unsigned long)mod->module_init
68059 - + mod->init_size);
68060 - flush_icache_range((unsigned long)mod->module_core,
68061 - (unsigned long)mod->module_core + mod->core_size);
68062 + if (mod->module_init_rx)
68063 + flush_icache_range((unsigned long)mod->module_init_rx,
68064 + (unsigned long)mod->module_init_rx
68065 + + mod->init_size_rx);
68066 + flush_icache_range((unsigned long)mod->module_core_rx,
68067 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68068
68069 set_fs(old_fs);
68070 }
68071 @@ -2834,8 +2934,10 @@ out:
68072 static void module_deallocate(struct module *mod, struct load_info *info)
68073 {
68074 percpu_modfree(mod);
68075 - module_free(mod, mod->module_init);
68076 - module_free(mod, mod->module_core);
68077 + module_free_exec(mod, mod->module_init_rx);
68078 + module_free_exec(mod, mod->module_core_rx);
68079 + module_free(mod, mod->module_init_rw);
68080 + module_free(mod, mod->module_core_rw);
68081 }
68082
68083 int __weak module_finalize(const Elf_Ehdr *hdr,
68084 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68085 static int post_relocation(struct module *mod, const struct load_info *info)
68086 {
68087 /* Sort exception table now relocations are done. */
68088 + pax_open_kernel();
68089 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68090 + pax_close_kernel();
68091
68092 /* Copy relocated percpu area over. */
68093 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68094 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68095 if (err)
68096 goto free_unload;
68097
68098 + /* Now copy in args */
68099 + mod->args = strndup_user(uargs, ~0UL >> 1);
68100 + if (IS_ERR(mod->args)) {
68101 + err = PTR_ERR(mod->args);
68102 + goto free_unload;
68103 + }
68104 +
68105 /* Set up MODINFO_ATTR fields */
68106 setup_modinfo(mod, &info);
68107
68108 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68109 + {
68110 + char *p, *p2;
68111 +
68112 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68113 + 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);
68114 + err = -EPERM;
68115 + goto free_modinfo;
68116 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68117 + p += strlen("grsec_modharden_normal");
68118 + p2 = strstr(p, "_");
68119 + if (p2) {
68120 + *p2 = '\0';
68121 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68122 + *p2 = '_';
68123 + }
68124 + err = -EPERM;
68125 + goto free_modinfo;
68126 + }
68127 + }
68128 +#endif
68129 +
68130 /* Fix up syms, so that st_value is a pointer to location. */
68131 err = simplify_symbols(mod, &info);
68132 if (err < 0)
68133 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68134
68135 flush_module_icache(mod);
68136
68137 - /* Now copy in args */
68138 - mod->args = strndup_user(uargs, ~0UL >> 1);
68139 - if (IS_ERR(mod->args)) {
68140 - err = PTR_ERR(mod->args);
68141 - goto free_arch_cleanup;
68142 - }
68143 -
68144 /* Mark state as coming so strong_try_module_get() ignores us. */
68145 mod->state = MODULE_STATE_COMING;
68146
68147 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68148 unlock:
68149 mutex_unlock(&module_mutex);
68150 synchronize_sched();
68151 - kfree(mod->args);
68152 - free_arch_cleanup:
68153 module_arch_cleanup(mod);
68154 free_modinfo:
68155 free_modinfo(mod);
68156 + kfree(mod->args);
68157 free_unload:
68158 module_unload_free(mod);
68159 free_module:
68160 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68161 MODULE_STATE_COMING, mod);
68162
68163 /* Set RO and NX regions for core */
68164 - set_section_ro_nx(mod->module_core,
68165 - mod->core_text_size,
68166 - mod->core_ro_size,
68167 - mod->core_size);
68168 + set_section_ro_nx(mod->module_core_rx,
68169 + mod->core_size_rx,
68170 + mod->core_size_rx,
68171 + mod->core_size_rx);
68172
68173 /* Set RO and NX regions for init */
68174 - set_section_ro_nx(mod->module_init,
68175 - mod->init_text_size,
68176 - mod->init_ro_size,
68177 - mod->init_size);
68178 + set_section_ro_nx(mod->module_init_rx,
68179 + mod->init_size_rx,
68180 + mod->init_size_rx,
68181 + mod->init_size_rx);
68182
68183 do_mod_ctors(mod);
68184 /* Start the module */
68185 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68186 mod->strtab = mod->core_strtab;
68187 #endif
68188 unset_module_init_ro_nx(mod);
68189 - module_free(mod, mod->module_init);
68190 - mod->module_init = NULL;
68191 - mod->init_size = 0;
68192 - mod->init_ro_size = 0;
68193 - mod->init_text_size = 0;
68194 + module_free(mod, mod->module_init_rw);
68195 + module_free_exec(mod, mod->module_init_rx);
68196 + mod->module_init_rw = NULL;
68197 + mod->module_init_rx = NULL;
68198 + mod->init_size_rw = 0;
68199 + mod->init_size_rx = 0;
68200 mutex_unlock(&module_mutex);
68201
68202 return 0;
68203 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68204 unsigned long nextval;
68205
68206 /* At worse, next value is at end of module */
68207 - if (within_module_init(addr, mod))
68208 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68209 + if (within_module_init_rx(addr, mod))
68210 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68211 + else if (within_module_init_rw(addr, mod))
68212 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68213 + else if (within_module_core_rx(addr, mod))
68214 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68215 + else if (within_module_core_rw(addr, mod))
68216 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68217 else
68218 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68219 + return NULL;
68220
68221 /* Scan for closest preceding symbol, and next symbol. (ELF
68222 starts real symbols at 1). */
68223 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68224 char buf[8];
68225
68226 seq_printf(m, "%s %u",
68227 - mod->name, mod->init_size + mod->core_size);
68228 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68229 print_unload_info(m, mod);
68230
68231 /* Informative for users. */
68232 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68233 mod->state == MODULE_STATE_COMING ? "Loading":
68234 "Live");
68235 /* Used by oprofile and other similar tools. */
68236 - seq_printf(m, " 0x%pK", mod->module_core);
68237 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68238
68239 /* Taints info */
68240 if (mod->taints)
68241 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68242
68243 static int __init proc_modules_init(void)
68244 {
68245 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68246 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68247 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68248 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68249 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68250 +#else
68251 proc_create("modules", 0, NULL, &proc_modules_operations);
68252 +#endif
68253 +#else
68254 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68255 +#endif
68256 return 0;
68257 }
68258 module_init(proc_modules_init);
68259 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68260 {
68261 struct module *mod;
68262
68263 - if (addr < module_addr_min || addr > module_addr_max)
68264 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68265 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68266 return NULL;
68267
68268 list_for_each_entry_rcu(mod, &modules, list)
68269 - if (within_module_core(addr, mod)
68270 - || within_module_init(addr, mod))
68271 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68272 return mod;
68273 return NULL;
68274 }
68275 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68276 */
68277 struct module *__module_text_address(unsigned long addr)
68278 {
68279 - struct module *mod = __module_address(addr);
68280 + struct module *mod;
68281 +
68282 +#ifdef CONFIG_X86_32
68283 + addr = ktla_ktva(addr);
68284 +#endif
68285 +
68286 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68287 + return NULL;
68288 +
68289 + mod = __module_address(addr);
68290 +
68291 if (mod) {
68292 /* Make sure it's within the text section. */
68293 - if (!within(addr, mod->module_init, mod->init_text_size)
68294 - && !within(addr, mod->module_core, mod->core_text_size))
68295 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68296 mod = NULL;
68297 }
68298 return mod;
68299 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68300 index 7e3443f..b2a1e6b 100644
68301 --- a/kernel/mutex-debug.c
68302 +++ b/kernel/mutex-debug.c
68303 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68304 }
68305
68306 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68307 - struct thread_info *ti)
68308 + struct task_struct *task)
68309 {
68310 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68311
68312 /* Mark the current thread as blocked on the lock: */
68313 - ti->task->blocked_on = waiter;
68314 + task->blocked_on = waiter;
68315 }
68316
68317 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68318 - struct thread_info *ti)
68319 + struct task_struct *task)
68320 {
68321 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68322 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68323 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68324 - ti->task->blocked_on = NULL;
68325 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68326 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68327 + task->blocked_on = NULL;
68328
68329 list_del_init(&waiter->list);
68330 waiter->task = NULL;
68331 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68332 index 0799fd3..d06ae3b 100644
68333 --- a/kernel/mutex-debug.h
68334 +++ b/kernel/mutex-debug.h
68335 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68336 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68337 extern void debug_mutex_add_waiter(struct mutex *lock,
68338 struct mutex_waiter *waiter,
68339 - struct thread_info *ti);
68340 + struct task_struct *task);
68341 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68342 - struct thread_info *ti);
68343 + struct task_struct *task);
68344 extern void debug_mutex_unlock(struct mutex *lock);
68345 extern void debug_mutex_init(struct mutex *lock, const char *name,
68346 struct lock_class_key *key);
68347 diff --git a/kernel/mutex.c b/kernel/mutex.c
68348 index a307cc9..27fd2e9 100644
68349 --- a/kernel/mutex.c
68350 +++ b/kernel/mutex.c
68351 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68352 spin_lock_mutex(&lock->wait_lock, flags);
68353
68354 debug_mutex_lock_common(lock, &waiter);
68355 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68356 + debug_mutex_add_waiter(lock, &waiter, task);
68357
68358 /* add waiting tasks to the end of the waitqueue (FIFO): */
68359 list_add_tail(&waiter.list, &lock->wait_list);
68360 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68361 * TASK_UNINTERRUPTIBLE case.)
68362 */
68363 if (unlikely(signal_pending_state(state, task))) {
68364 - mutex_remove_waiter(lock, &waiter,
68365 - task_thread_info(task));
68366 + mutex_remove_waiter(lock, &waiter, task);
68367 mutex_release(&lock->dep_map, 1, ip);
68368 spin_unlock_mutex(&lock->wait_lock, flags);
68369
68370 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68371 done:
68372 lock_acquired(&lock->dep_map, ip);
68373 /* got the lock - rejoice! */
68374 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68375 + mutex_remove_waiter(lock, &waiter, task);
68376 mutex_set_owner(lock);
68377
68378 /* set it to 0 if there are no waiters left: */
68379 diff --git a/kernel/panic.c b/kernel/panic.c
68380 index d2a5f4e..5edc1d9 100644
68381 --- a/kernel/panic.c
68382 +++ b/kernel/panic.c
68383 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68384 int state = 0;
68385
68386 /*
68387 + * Disable local interrupts. This will prevent panic_smp_self_stop
68388 + * from deadlocking the first cpu that invokes the panic, since
68389 + * there is nothing to prevent an interrupt handler (that runs
68390 + * after the panic_lock is acquired) from invoking panic again.
68391 + */
68392 + local_irq_disable();
68393 +
68394 + /*
68395 * It's possible to come here directly from a panic-assertion and
68396 * not have preempt disabled. Some functions called from here want
68397 * preempt to be disabled. No point enabling it later though...
68398 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68399 const char *board;
68400
68401 printk(KERN_WARNING "------------[ cut here ]------------\n");
68402 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68403 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68404 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68405 if (board)
68406 printk(KERN_WARNING "Hardware name: %s\n", board);
68407 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68408 */
68409 void __stack_chk_fail(void)
68410 {
68411 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68412 + dump_stack();
68413 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68414 __builtin_return_address(0));
68415 }
68416 EXPORT_SYMBOL(__stack_chk_fail);
68417 diff --git a/kernel/pid.c b/kernel/pid.c
68418 index e86b291a..e8b0fb5 100644
68419 --- a/kernel/pid.c
68420 +++ b/kernel/pid.c
68421 @@ -33,6 +33,7 @@
68422 #include <linux/rculist.h>
68423 #include <linux/bootmem.h>
68424 #include <linux/hash.h>
68425 +#include <linux/security.h>
68426 #include <linux/pid_namespace.h>
68427 #include <linux/init_task.h>
68428 #include <linux/syscalls.h>
68429 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68430
68431 int pid_max = PID_MAX_DEFAULT;
68432
68433 -#define RESERVED_PIDS 300
68434 +#define RESERVED_PIDS 500
68435
68436 int pid_max_min = RESERVED_PIDS + 1;
68437 int pid_max_max = PID_MAX_LIMIT;
68438 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68439 */
68440 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68441 {
68442 + struct task_struct *task;
68443 +
68444 rcu_lockdep_assert(rcu_read_lock_held(),
68445 "find_task_by_pid_ns() needs rcu_read_lock()"
68446 " protection");
68447 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68448 +
68449 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68450 +
68451 + if (gr_pid_is_chrooted(task))
68452 + return NULL;
68453 +
68454 + return task;
68455 }
68456
68457 struct task_struct *find_task_by_vpid(pid_t vnr)
68458 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68459 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68460 }
68461
68462 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68463 +{
68464 + rcu_lockdep_assert(rcu_read_lock_held(),
68465 + "find_task_by_pid_ns() needs rcu_read_lock()"
68466 + " protection");
68467 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68468 +}
68469 +
68470 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68471 {
68472 struct pid *pid;
68473 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68474 index 125cb67..a4d1c30 100644
68475 --- a/kernel/posix-cpu-timers.c
68476 +++ b/kernel/posix-cpu-timers.c
68477 @@ -6,6 +6,7 @@
68478 #include <linux/posix-timers.h>
68479 #include <linux/errno.h>
68480 #include <linux/math64.h>
68481 +#include <linux/security.h>
68482 #include <asm/uaccess.h>
68483 #include <linux/kernel_stat.h>
68484 #include <trace/events/timer.h>
68485 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68486
68487 static __init int init_posix_cpu_timers(void)
68488 {
68489 - struct k_clock process = {
68490 + static struct k_clock process = {
68491 .clock_getres = process_cpu_clock_getres,
68492 .clock_get = process_cpu_clock_get,
68493 .timer_create = process_cpu_timer_create,
68494 .nsleep = process_cpu_nsleep,
68495 .nsleep_restart = process_cpu_nsleep_restart,
68496 };
68497 - struct k_clock thread = {
68498 + static struct k_clock thread = {
68499 .clock_getres = thread_cpu_clock_getres,
68500 .clock_get = thread_cpu_clock_get,
68501 .timer_create = thread_cpu_timer_create,
68502 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68503 index 69185ae..cc2847a 100644
68504 --- a/kernel/posix-timers.c
68505 +++ b/kernel/posix-timers.c
68506 @@ -43,6 +43,7 @@
68507 #include <linux/idr.h>
68508 #include <linux/posix-clock.h>
68509 #include <linux/posix-timers.h>
68510 +#include <linux/grsecurity.h>
68511 #include <linux/syscalls.h>
68512 #include <linux/wait.h>
68513 #include <linux/workqueue.h>
68514 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68515 * which we beg off on and pass to do_sys_settimeofday().
68516 */
68517
68518 -static struct k_clock posix_clocks[MAX_CLOCKS];
68519 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68520
68521 /*
68522 * These ones are defined below.
68523 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68524 */
68525 static __init int init_posix_timers(void)
68526 {
68527 - struct k_clock clock_realtime = {
68528 + static struct k_clock clock_realtime = {
68529 .clock_getres = hrtimer_get_res,
68530 .clock_get = posix_clock_realtime_get,
68531 .clock_set = posix_clock_realtime_set,
68532 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68533 .timer_get = common_timer_get,
68534 .timer_del = common_timer_del,
68535 };
68536 - struct k_clock clock_monotonic = {
68537 + static struct k_clock clock_monotonic = {
68538 .clock_getres = hrtimer_get_res,
68539 .clock_get = posix_ktime_get_ts,
68540 .nsleep = common_nsleep,
68541 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68542 .timer_get = common_timer_get,
68543 .timer_del = common_timer_del,
68544 };
68545 - struct k_clock clock_monotonic_raw = {
68546 + static struct k_clock clock_monotonic_raw = {
68547 .clock_getres = hrtimer_get_res,
68548 .clock_get = posix_get_monotonic_raw,
68549 };
68550 - struct k_clock clock_realtime_coarse = {
68551 + static struct k_clock clock_realtime_coarse = {
68552 .clock_getres = posix_get_coarse_res,
68553 .clock_get = posix_get_realtime_coarse,
68554 };
68555 - struct k_clock clock_monotonic_coarse = {
68556 + static struct k_clock clock_monotonic_coarse = {
68557 .clock_getres = posix_get_coarse_res,
68558 .clock_get = posix_get_monotonic_coarse,
68559 };
68560 - struct k_clock clock_boottime = {
68561 + static struct k_clock clock_boottime = {
68562 .clock_getres = hrtimer_get_res,
68563 .clock_get = posix_get_boottime,
68564 .nsleep = common_nsleep,
68565 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68566 return;
68567 }
68568
68569 - posix_clocks[clock_id] = *new_clock;
68570 + posix_clocks[clock_id] = new_clock;
68571 }
68572 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68573
68574 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68575 return (id & CLOCKFD_MASK) == CLOCKFD ?
68576 &clock_posix_dynamic : &clock_posix_cpu;
68577
68578 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68579 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68580 return NULL;
68581 - return &posix_clocks[id];
68582 + return posix_clocks[id];
68583 }
68584
68585 static int common_timer_create(struct k_itimer *new_timer)
68586 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68587 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68588 return -EFAULT;
68589
68590 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68591 + have their clock_set fptr set to a nosettime dummy function
68592 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68593 + call common_clock_set, which calls do_sys_settimeofday, which
68594 + we hook
68595 + */
68596 +
68597 return kc->clock_set(which_clock, &new_tp);
68598 }
68599
68600 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68601 index d523593..68197a4 100644
68602 --- a/kernel/power/poweroff.c
68603 +++ b/kernel/power/poweroff.c
68604 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68605 .enable_mask = SYSRQ_ENABLE_BOOT,
68606 };
68607
68608 -static int pm_sysrq_init(void)
68609 +static int __init pm_sysrq_init(void)
68610 {
68611 register_sysrq_key('o', &sysrq_poweroff_op);
68612 return 0;
68613 diff --git a/kernel/power/process.c b/kernel/power/process.c
68614 index 19db29f..33b52b6 100644
68615 --- a/kernel/power/process.c
68616 +++ b/kernel/power/process.c
68617 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68618 u64 elapsed_csecs64;
68619 unsigned int elapsed_csecs;
68620 bool wakeup = false;
68621 + bool timedout = false;
68622
68623 do_gettimeofday(&start);
68624
68625 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68626
68627 while (true) {
68628 todo = 0;
68629 + if (time_after(jiffies, end_time))
68630 + timedout = true;
68631 read_lock(&tasklist_lock);
68632 do_each_thread(g, p) {
68633 if (p == current || !freeze_task(p))
68634 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68635 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68636 * transition can't race with task state testing here.
68637 */
68638 - if (!task_is_stopped_or_traced(p) &&
68639 - !freezer_should_skip(p))
68640 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68641 todo++;
68642 + if (timedout) {
68643 + printk(KERN_ERR "Task refusing to freeze:\n");
68644 + sched_show_task(p);
68645 + }
68646 + }
68647 } while_each_thread(g, p);
68648 read_unlock(&tasklist_lock);
68649
68650 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68651 todo += wq_busy;
68652 }
68653
68654 - if (!todo || time_after(jiffies, end_time))
68655 + if (!todo || timedout)
68656 break;
68657
68658 if (pm_wakeup_pending()) {
68659 diff --git a/kernel/printk.c b/kernel/printk.c
68660 index 146827f..a501fec 100644
68661 --- a/kernel/printk.c
68662 +++ b/kernel/printk.c
68663 @@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68664 if (from_file && type != SYSLOG_ACTION_OPEN)
68665 return 0;
68666
68667 +#ifdef CONFIG_GRKERNSEC_DMESG
68668 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68669 + return -EPERM;
68670 +#endif
68671 +
68672 if (syslog_action_restricted(type)) {
68673 if (capable(CAP_SYSLOG))
68674 return 0;
68675 diff --git a/kernel/profile.c b/kernel/profile.c
68676 index 76b8e77..a2930e8 100644
68677 --- a/kernel/profile.c
68678 +++ b/kernel/profile.c
68679 @@ -39,7 +39,7 @@ struct profile_hit {
68680 /* Oprofile timer tick hook */
68681 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68682
68683 -static atomic_t *prof_buffer;
68684 +static atomic_unchecked_t *prof_buffer;
68685 static unsigned long prof_len, prof_shift;
68686
68687 int prof_on __read_mostly;
68688 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68689 hits[i].pc = 0;
68690 continue;
68691 }
68692 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68693 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68694 hits[i].hits = hits[i].pc = 0;
68695 }
68696 }
68697 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68698 * Add the current hit(s) and flush the write-queue out
68699 * to the global buffer:
68700 */
68701 - atomic_add(nr_hits, &prof_buffer[pc]);
68702 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68703 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68704 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68705 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68706 hits[i].pc = hits[i].hits = 0;
68707 }
68708 out:
68709 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68710 {
68711 unsigned long pc;
68712 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68713 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68714 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68715 }
68716 #endif /* !CONFIG_SMP */
68717
68718 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68719 return -EFAULT;
68720 buf++; p++; count--; read++;
68721 }
68722 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68723 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68724 if (copy_to_user(buf, (void *)pnt, count))
68725 return -EFAULT;
68726 read += count;
68727 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68728 }
68729 #endif
68730 profile_discard_flip_buffers();
68731 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68732 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68733 return count;
68734 }
68735
68736 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68737 index a232bb5..2a65ef9 100644
68738 --- a/kernel/ptrace.c
68739 +++ b/kernel/ptrace.c
68740 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68741
68742 if (seize)
68743 flags |= PT_SEIZED;
68744 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68745 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68746 flags |= PT_PTRACE_CAP;
68747 task->ptrace = flags;
68748
68749 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68750 break;
68751 return -EIO;
68752 }
68753 - if (copy_to_user(dst, buf, retval))
68754 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68755 return -EFAULT;
68756 copied += retval;
68757 src += retval;
68758 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68759 bool seized = child->ptrace & PT_SEIZED;
68760 int ret = -EIO;
68761 siginfo_t siginfo, *si;
68762 - void __user *datavp = (void __user *) data;
68763 + void __user *datavp = (__force void __user *) data;
68764 unsigned long __user *datalp = datavp;
68765 unsigned long flags;
68766
68767 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68768 goto out;
68769 }
68770
68771 + if (gr_handle_ptrace(child, request)) {
68772 + ret = -EPERM;
68773 + goto out_put_task_struct;
68774 + }
68775 +
68776 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68777 ret = ptrace_attach(child, request, addr, data);
68778 /*
68779 * Some architectures need to do book-keeping after
68780 * a ptrace attach.
68781 */
68782 - if (!ret)
68783 + if (!ret) {
68784 arch_ptrace_attach(child);
68785 + gr_audit_ptrace(child);
68786 + }
68787 goto out_put_task_struct;
68788 }
68789
68790 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68791 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68792 if (copied != sizeof(tmp))
68793 return -EIO;
68794 - return put_user(tmp, (unsigned long __user *)data);
68795 + return put_user(tmp, (__force unsigned long __user *)data);
68796 }
68797
68798 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68799 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68800 goto out;
68801 }
68802
68803 + if (gr_handle_ptrace(child, request)) {
68804 + ret = -EPERM;
68805 + goto out_put_task_struct;
68806 + }
68807 +
68808 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68809 ret = ptrace_attach(child, request, addr, data);
68810 /*
68811 * Some architectures need to do book-keeping after
68812 * a ptrace attach.
68813 */
68814 - if (!ret)
68815 + if (!ret) {
68816 arch_ptrace_attach(child);
68817 + gr_audit_ptrace(child);
68818 + }
68819 goto out_put_task_struct;
68820 }
68821
68822 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68823 index 37a5444..eec170a 100644
68824 --- a/kernel/rcutiny.c
68825 +++ b/kernel/rcutiny.c
68826 @@ -46,7 +46,7 @@
68827 struct rcu_ctrlblk;
68828 static void invoke_rcu_callbacks(void);
68829 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68830 -static void rcu_process_callbacks(struct softirq_action *unused);
68831 +static void rcu_process_callbacks(void);
68832 static void __call_rcu(struct rcu_head *head,
68833 void (*func)(struct rcu_head *rcu),
68834 struct rcu_ctrlblk *rcp);
68835 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68836 rcu_is_callbacks_kthread()));
68837 }
68838
68839 -static void rcu_process_callbacks(struct softirq_action *unused)
68840 +static void rcu_process_callbacks(void)
68841 {
68842 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68843 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68844 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68845 index fc31a2d..be2ec04 100644
68846 --- a/kernel/rcutiny_plugin.h
68847 +++ b/kernel/rcutiny_plugin.h
68848 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68849 have_rcu_kthread_work = morework;
68850 local_irq_restore(flags);
68851 if (work)
68852 - rcu_process_callbacks(NULL);
68853 + rcu_process_callbacks();
68854 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68855 }
68856
68857 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68858 index e66b34a..4b8b626 100644
68859 --- a/kernel/rcutorture.c
68860 +++ b/kernel/rcutorture.c
68861 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68862 { 0 };
68863 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68864 { 0 };
68865 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68866 -static atomic_t n_rcu_torture_alloc;
68867 -static atomic_t n_rcu_torture_alloc_fail;
68868 -static atomic_t n_rcu_torture_free;
68869 -static atomic_t n_rcu_torture_mberror;
68870 -static atomic_t n_rcu_torture_error;
68871 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68872 +static atomic_unchecked_t n_rcu_torture_alloc;
68873 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68874 +static atomic_unchecked_t n_rcu_torture_free;
68875 +static atomic_unchecked_t n_rcu_torture_mberror;
68876 +static atomic_unchecked_t n_rcu_torture_error;
68877 static long n_rcu_torture_barrier_error;
68878 static long n_rcu_torture_boost_ktrerror;
68879 static long n_rcu_torture_boost_rterror;
68880 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68881
68882 spin_lock_bh(&rcu_torture_lock);
68883 if (list_empty(&rcu_torture_freelist)) {
68884 - atomic_inc(&n_rcu_torture_alloc_fail);
68885 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68886 spin_unlock_bh(&rcu_torture_lock);
68887 return NULL;
68888 }
68889 - atomic_inc(&n_rcu_torture_alloc);
68890 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68891 p = rcu_torture_freelist.next;
68892 list_del_init(p);
68893 spin_unlock_bh(&rcu_torture_lock);
68894 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68895 static void
68896 rcu_torture_free(struct rcu_torture *p)
68897 {
68898 - atomic_inc(&n_rcu_torture_free);
68899 + atomic_inc_unchecked(&n_rcu_torture_free);
68900 spin_lock_bh(&rcu_torture_lock);
68901 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68902 spin_unlock_bh(&rcu_torture_lock);
68903 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68904 i = rp->rtort_pipe_count;
68905 if (i > RCU_TORTURE_PIPE_LEN)
68906 i = RCU_TORTURE_PIPE_LEN;
68907 - atomic_inc(&rcu_torture_wcount[i]);
68908 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68909 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68910 rp->rtort_mbtest = 0;
68911 rcu_torture_free(rp);
68912 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68913 i = rp->rtort_pipe_count;
68914 if (i > RCU_TORTURE_PIPE_LEN)
68915 i = RCU_TORTURE_PIPE_LEN;
68916 - atomic_inc(&rcu_torture_wcount[i]);
68917 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68918 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68919 rp->rtort_mbtest = 0;
68920 list_del(&rp->rtort_free);
68921 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68922 i = old_rp->rtort_pipe_count;
68923 if (i > RCU_TORTURE_PIPE_LEN)
68924 i = RCU_TORTURE_PIPE_LEN;
68925 - atomic_inc(&rcu_torture_wcount[i]);
68926 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68927 old_rp->rtort_pipe_count++;
68928 cur_ops->deferred_free(old_rp);
68929 }
68930 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68931 }
68932 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68933 if (p->rtort_mbtest == 0)
68934 - atomic_inc(&n_rcu_torture_mberror);
68935 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68936 spin_lock(&rand_lock);
68937 cur_ops->read_delay(&rand);
68938 n_rcu_torture_timers++;
68939 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68940 }
68941 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68942 if (p->rtort_mbtest == 0)
68943 - atomic_inc(&n_rcu_torture_mberror);
68944 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68945 cur_ops->read_delay(&rand);
68946 preempt_disable();
68947 pipe_count = p->rtort_pipe_count;
68948 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68949 rcu_torture_current,
68950 rcu_torture_current_version,
68951 list_empty(&rcu_torture_freelist),
68952 - atomic_read(&n_rcu_torture_alloc),
68953 - atomic_read(&n_rcu_torture_alloc_fail),
68954 - atomic_read(&n_rcu_torture_free),
68955 - atomic_read(&n_rcu_torture_mberror),
68956 + atomic_read_unchecked(&n_rcu_torture_alloc),
68957 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68958 + atomic_read_unchecked(&n_rcu_torture_free),
68959 + atomic_read_unchecked(&n_rcu_torture_mberror),
68960 n_rcu_torture_boost_ktrerror,
68961 n_rcu_torture_boost_rterror,
68962 n_rcu_torture_boost_failure,
68963 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68964 n_barrier_attempts,
68965 n_rcu_torture_barrier_error);
68966 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68967 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68968 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68969 n_rcu_torture_barrier_error != 0 ||
68970 n_rcu_torture_boost_ktrerror != 0 ||
68971 n_rcu_torture_boost_rterror != 0 ||
68972 n_rcu_torture_boost_failure != 0 ||
68973 i > 1) {
68974 cnt += sprintf(&page[cnt], "!!! ");
68975 - atomic_inc(&n_rcu_torture_error);
68976 + atomic_inc_unchecked(&n_rcu_torture_error);
68977 WARN_ON_ONCE(1);
68978 }
68979 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68980 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68981 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68982 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68983 cnt += sprintf(&page[cnt], " %d",
68984 - atomic_read(&rcu_torture_wcount[i]));
68985 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68986 }
68987 cnt += sprintf(&page[cnt], "\n");
68988 if (cur_ops->stats)
68989 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68990
68991 if (cur_ops->cleanup)
68992 cur_ops->cleanup();
68993 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68994 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68995 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68996 else if (n_online_successes != n_online_attempts ||
68997 n_offline_successes != n_offline_attempts)
68998 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68999
69000 rcu_torture_current = NULL;
69001 rcu_torture_current_version = 0;
69002 - atomic_set(&n_rcu_torture_alloc, 0);
69003 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69004 - atomic_set(&n_rcu_torture_free, 0);
69005 - atomic_set(&n_rcu_torture_mberror, 0);
69006 - atomic_set(&n_rcu_torture_error, 0);
69007 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69008 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69009 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69010 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69011 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69012 n_rcu_torture_barrier_error = 0;
69013 n_rcu_torture_boost_ktrerror = 0;
69014 n_rcu_torture_boost_rterror = 0;
69015 n_rcu_torture_boost_failure = 0;
69016 n_rcu_torture_boosts = 0;
69017 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69018 - atomic_set(&rcu_torture_wcount[i], 0);
69019 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69020 for_each_possible_cpu(cpu) {
69021 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69022 per_cpu(rcu_torture_count, cpu)[i] = 0;
69023 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69024 index 4b97bba..b92c9d2 100644
69025 --- a/kernel/rcutree.c
69026 +++ b/kernel/rcutree.c
69027 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69028 rcu_prepare_for_idle(smp_processor_id());
69029 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69030 smp_mb__before_atomic_inc(); /* See above. */
69031 - atomic_inc(&rdtp->dynticks);
69032 + atomic_inc_unchecked(&rdtp->dynticks);
69033 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69034 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69035 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69036
69037 /*
69038 * The idle task is not permitted to enter the idle loop while
69039 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
69040 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69041 {
69042 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69043 - atomic_inc(&rdtp->dynticks);
69044 + atomic_inc_unchecked(&rdtp->dynticks);
69045 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69046 smp_mb__after_atomic_inc(); /* See above. */
69047 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69048 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69049 rcu_cleanup_after_idle(smp_processor_id());
69050 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69051 if (!is_idle_task(current)) {
69052 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
69053 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69054
69055 if (rdtp->dynticks_nmi_nesting == 0 &&
69056 - (atomic_read(&rdtp->dynticks) & 0x1))
69057 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69058 return;
69059 rdtp->dynticks_nmi_nesting++;
69060 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69061 - atomic_inc(&rdtp->dynticks);
69062 + atomic_inc_unchecked(&rdtp->dynticks);
69063 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69064 smp_mb__after_atomic_inc(); /* See above. */
69065 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69066 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69067 }
69068
69069 /**
69070 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
69071 return;
69072 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69073 smp_mb__before_atomic_inc(); /* See above. */
69074 - atomic_inc(&rdtp->dynticks);
69075 + atomic_inc_unchecked(&rdtp->dynticks);
69076 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69077 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69078 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69079 }
69080
69081 #ifdef CONFIG_PROVE_RCU
69082 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
69083 int ret;
69084
69085 preempt_disable();
69086 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69087 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69088 preempt_enable();
69089 return ret;
69090 }
69091 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69092 */
69093 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69094 {
69095 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69096 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69097 return (rdp->dynticks_snap & 0x1) == 0;
69098 }
69099
69100 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69101 unsigned int curr;
69102 unsigned int snap;
69103
69104 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69105 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69106 snap = (unsigned int)rdp->dynticks_snap;
69107
69108 /*
69109 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
69110 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69111 */
69112 if (till_stall_check < 3) {
69113 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69114 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69115 till_stall_check = 3;
69116 } else if (till_stall_check > 300) {
69117 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69118 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69119 till_stall_check = 300;
69120 }
69121 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69122 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69123 /*
69124 * Do RCU core processing for the current CPU.
69125 */
69126 -static void rcu_process_callbacks(struct softirq_action *unused)
69127 +static void rcu_process_callbacks(void)
69128 {
69129 trace_rcu_utilization("Start RCU core");
69130 __rcu_process_callbacks(&rcu_sched_state,
69131 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69132 }
69133 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69134
69135 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69136 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69137 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69138 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69139
69140 static int synchronize_sched_expedited_cpu_stop(void *data)
69141 {
69142 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69143 int firstsnap, s, snap, trycount = 0;
69144
69145 /* Note that atomic_inc_return() implies full memory barrier. */
69146 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69147 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69148 get_online_cpus();
69149 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69150
69151 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69152 }
69153
69154 /* Check to see if someone else did our work for us. */
69155 - s = atomic_read(&sync_sched_expedited_done);
69156 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69157 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69158 smp_mb(); /* ensure test happens before caller kfree */
69159 return;
69160 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69161 * grace period works for us.
69162 */
69163 get_online_cpus();
69164 - snap = atomic_read(&sync_sched_expedited_started);
69165 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69166 smp_mb(); /* ensure read is before try_stop_cpus(). */
69167 }
69168
69169 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69170 * than we did beat us to the punch.
69171 */
69172 do {
69173 - s = atomic_read(&sync_sched_expedited_done);
69174 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69175 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69176 smp_mb(); /* ensure test happens before caller kfree */
69177 break;
69178 }
69179 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69180 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69181
69182 put_online_cpus();
69183 }
69184 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69185 rdp->qlen = 0;
69186 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69187 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69188 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69189 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69190 rdp->cpu = cpu;
69191 rdp->rsp = rsp;
69192 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69193 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69194 rdp->n_force_qs_snap = rsp->n_force_qs;
69195 rdp->blimit = blimit;
69196 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69197 - atomic_set(&rdp->dynticks->dynticks,
69198 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69199 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69200 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69201 rcu_prepare_for_idle_init(cpu);
69202 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69203
69204 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69205 index 19b61ac..5c60a94 100644
69206 --- a/kernel/rcutree.h
69207 +++ b/kernel/rcutree.h
69208 @@ -83,7 +83,7 @@ struct rcu_dynticks {
69209 long long dynticks_nesting; /* Track irq/process nesting level. */
69210 /* Process level is worth LLONG_MAX/2. */
69211 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69212 - atomic_t dynticks; /* Even value for idle, else odd. */
69213 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69214 #ifdef CONFIG_RCU_FAST_NO_HZ
69215 int dyntick_drain; /* Prepare-for-idle state variable. */
69216 unsigned long dyntick_holdoff;
69217 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69218 index 3e48994..d94f03a 100644
69219 --- a/kernel/rcutree_plugin.h
69220 +++ b/kernel/rcutree_plugin.h
69221 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69222
69223 /* Clean up and exit. */
69224 smp_mb(); /* ensure expedited GP seen before counter increment. */
69225 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69226 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69227 unlock_mb_ret:
69228 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69229 mb_ret:
69230 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69231 index d4bc16d..c234a5c 100644
69232 --- a/kernel/rcutree_trace.c
69233 +++ b/kernel/rcutree_trace.c
69234 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69235 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69236 rdp->qs_pending);
69237 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69238 - atomic_read(&rdp->dynticks->dynticks),
69239 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69240 rdp->dynticks->dynticks_nesting,
69241 rdp->dynticks->dynticks_nmi_nesting,
69242 rdp->dynticks_fqs);
69243 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69244 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69245 rdp->qs_pending);
69246 seq_printf(m, ",%d,%llx,%d,%lu",
69247 - atomic_read(&rdp->dynticks->dynticks),
69248 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69249 rdp->dynticks->dynticks_nesting,
69250 rdp->dynticks->dynticks_nmi_nesting,
69251 rdp->dynticks_fqs);
69252 diff --git a/kernel/resource.c b/kernel/resource.c
69253 index e1d2b8e..24820bb 100644
69254 --- a/kernel/resource.c
69255 +++ b/kernel/resource.c
69256 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69257
69258 static int __init ioresources_init(void)
69259 {
69260 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69261 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69262 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69263 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69264 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69265 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69266 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69267 +#endif
69268 +#else
69269 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69270 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69271 +#endif
69272 return 0;
69273 }
69274 __initcall(ioresources_init);
69275 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69276 index 98ec494..4241d6d 100644
69277 --- a/kernel/rtmutex-tester.c
69278 +++ b/kernel/rtmutex-tester.c
69279 @@ -20,7 +20,7 @@
69280 #define MAX_RT_TEST_MUTEXES 8
69281
69282 static spinlock_t rttest_lock;
69283 -static atomic_t rttest_event;
69284 +static atomic_unchecked_t rttest_event;
69285
69286 struct test_thread_data {
69287 int opcode;
69288 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69289
69290 case RTTEST_LOCKCONT:
69291 td->mutexes[td->opdata] = 1;
69292 - td->event = atomic_add_return(1, &rttest_event);
69293 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69294 return 0;
69295
69296 case RTTEST_RESET:
69297 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69298 return 0;
69299
69300 case RTTEST_RESETEVENT:
69301 - atomic_set(&rttest_event, 0);
69302 + atomic_set_unchecked(&rttest_event, 0);
69303 return 0;
69304
69305 default:
69306 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69307 return ret;
69308
69309 td->mutexes[id] = 1;
69310 - td->event = atomic_add_return(1, &rttest_event);
69311 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69312 rt_mutex_lock(&mutexes[id]);
69313 - td->event = atomic_add_return(1, &rttest_event);
69314 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69315 td->mutexes[id] = 4;
69316 return 0;
69317
69318 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69319 return ret;
69320
69321 td->mutexes[id] = 1;
69322 - td->event = atomic_add_return(1, &rttest_event);
69323 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69324 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69325 - td->event = atomic_add_return(1, &rttest_event);
69326 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69327 td->mutexes[id] = ret ? 0 : 4;
69328 return ret ? -EINTR : 0;
69329
69330 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69331 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69332 return ret;
69333
69334 - td->event = atomic_add_return(1, &rttest_event);
69335 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69336 rt_mutex_unlock(&mutexes[id]);
69337 - td->event = atomic_add_return(1, &rttest_event);
69338 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69339 td->mutexes[id] = 0;
69340 return 0;
69341
69342 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69343 break;
69344
69345 td->mutexes[dat] = 2;
69346 - td->event = atomic_add_return(1, &rttest_event);
69347 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69348 break;
69349
69350 default:
69351 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69352 return;
69353
69354 td->mutexes[dat] = 3;
69355 - td->event = atomic_add_return(1, &rttest_event);
69356 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69357 break;
69358
69359 case RTTEST_LOCKNOWAIT:
69360 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69361 return;
69362
69363 td->mutexes[dat] = 1;
69364 - td->event = atomic_add_return(1, &rttest_event);
69365 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69366 return;
69367
69368 default:
69369 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69370 index 0984a21..939f183 100644
69371 --- a/kernel/sched/auto_group.c
69372 +++ b/kernel/sched/auto_group.c
69373 @@ -11,7 +11,7 @@
69374
69375 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69376 static struct autogroup autogroup_default;
69377 -static atomic_t autogroup_seq_nr;
69378 +static atomic_unchecked_t autogroup_seq_nr;
69379
69380 void __init autogroup_init(struct task_struct *init_task)
69381 {
69382 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69383
69384 kref_init(&ag->kref);
69385 init_rwsem(&ag->lock);
69386 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69387 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69388 ag->tg = tg;
69389 #ifdef CONFIG_RT_GROUP_SCHED
69390 /*
69391 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69392 index 468bdd4..b941572 100644
69393 --- a/kernel/sched/core.c
69394 +++ b/kernel/sched/core.c
69395 @@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69396 /* convert nice value [19,-20] to rlimit style value [1,40] */
69397 int nice_rlim = 20 - nice;
69398
69399 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69400 +
69401 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69402 capable(CAP_SYS_NICE));
69403 }
69404 @@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69405 if (nice > 19)
69406 nice = 19;
69407
69408 - if (increment < 0 && !can_nice(current, nice))
69409 + if (increment < 0 && (!can_nice(current, nice) ||
69410 + gr_handle_chroot_nice()))
69411 return -EPERM;
69412
69413 retval = security_task_setnice(current, nice);
69414 @@ -4284,6 +4287,7 @@ recheck:
69415 unsigned long rlim_rtprio =
69416 task_rlimit(p, RLIMIT_RTPRIO);
69417
69418 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69419 /* can't set/change the rt policy */
69420 if (policy != p->policy && !rlim_rtprio)
69421 return -EPERM;
69422 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69423 index c099cc6..06aec4f 100644
69424 --- a/kernel/sched/fair.c
69425 +++ b/kernel/sched/fair.c
69426 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69427 * run_rebalance_domains is triggered when needed from the scheduler tick.
69428 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69429 */
69430 -static void run_rebalance_domains(struct softirq_action *h)
69431 +static void run_rebalance_domains(void)
69432 {
69433 int this_cpu = smp_processor_id();
69434 struct rq *this_rq = cpu_rq(this_cpu);
69435 diff --git a/kernel/signal.c b/kernel/signal.c
69436 index 6771027..763e51e 100644
69437 --- a/kernel/signal.c
69438 +++ b/kernel/signal.c
69439 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69440
69441 int print_fatal_signals __read_mostly;
69442
69443 -static void __user *sig_handler(struct task_struct *t, int sig)
69444 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69445 {
69446 return t->sighand->action[sig - 1].sa.sa_handler;
69447 }
69448
69449 -static int sig_handler_ignored(void __user *handler, int sig)
69450 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69451 {
69452 /* Is it explicitly or implicitly ignored? */
69453 return handler == SIG_IGN ||
69454 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69455
69456 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69457 {
69458 - void __user *handler;
69459 + __sighandler_t handler;
69460
69461 handler = sig_handler(t, sig);
69462
69463 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69464 atomic_inc(&user->sigpending);
69465 rcu_read_unlock();
69466
69467 + if (!override_rlimit)
69468 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69469 +
69470 if (override_rlimit ||
69471 atomic_read(&user->sigpending) <=
69472 task_rlimit(t, RLIMIT_SIGPENDING)) {
69473 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69474
69475 int unhandled_signal(struct task_struct *tsk, int sig)
69476 {
69477 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69478 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69479 if (is_global_init(tsk))
69480 return 1;
69481 if (handler != SIG_IGN && handler != SIG_DFL)
69482 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69483 }
69484 }
69485
69486 + /* allow glibc communication via tgkill to other threads in our
69487 + thread group */
69488 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69489 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69490 + && gr_handle_signal(t, sig))
69491 + return -EPERM;
69492 +
69493 return security_task_kill(t, info, sig, 0);
69494 }
69495
69496 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69497 return send_signal(sig, info, p, 1);
69498 }
69499
69500 -static int
69501 +int
69502 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69503 {
69504 return send_signal(sig, info, t, 0);
69505 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69506 unsigned long int flags;
69507 int ret, blocked, ignored;
69508 struct k_sigaction *action;
69509 + int is_unhandled = 0;
69510
69511 spin_lock_irqsave(&t->sighand->siglock, flags);
69512 action = &t->sighand->action[sig-1];
69513 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69514 }
69515 if (action->sa.sa_handler == SIG_DFL)
69516 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69517 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69518 + is_unhandled = 1;
69519 ret = specific_send_sig_info(sig, info, t);
69520 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69521
69522 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69523 + normal operation */
69524 + if (is_unhandled) {
69525 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69526 + gr_handle_crash(t, sig);
69527 + }
69528 +
69529 return ret;
69530 }
69531
69532 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69533 ret = check_kill_permission(sig, info, p);
69534 rcu_read_unlock();
69535
69536 - if (!ret && sig)
69537 + if (!ret && sig) {
69538 ret = do_send_sig_info(sig, info, p, true);
69539 + if (!ret)
69540 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69541 + }
69542
69543 return ret;
69544 }
69545 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69546 int error = -ESRCH;
69547
69548 rcu_read_lock();
69549 - p = find_task_by_vpid(pid);
69550 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69551 + /* allow glibc communication via tgkill to other threads in our
69552 + thread group */
69553 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69554 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69555 + p = find_task_by_vpid_unrestricted(pid);
69556 + else
69557 +#endif
69558 + p = find_task_by_vpid(pid);
69559 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69560 error = check_kill_permission(sig, info, p);
69561 /*
69562 diff --git a/kernel/smp.c b/kernel/smp.c
69563 index d0ae5b2..b87c5a8 100644
69564 --- a/kernel/smp.c
69565 +++ b/kernel/smp.c
69566 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69567 }
69568 EXPORT_SYMBOL(smp_call_function);
69569
69570 -void ipi_call_lock(void)
69571 +void ipi_call_lock(void) __acquires(call_function.lock)
69572 {
69573 raw_spin_lock(&call_function.lock);
69574 }
69575
69576 -void ipi_call_unlock(void)
69577 +void ipi_call_unlock(void) __releases(call_function.lock)
69578 {
69579 raw_spin_unlock(&call_function.lock);
69580 }
69581
69582 -void ipi_call_lock_irq(void)
69583 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69584 {
69585 raw_spin_lock_irq(&call_function.lock);
69586 }
69587
69588 -void ipi_call_unlock_irq(void)
69589 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69590 {
69591 raw_spin_unlock_irq(&call_function.lock);
69592 }
69593 diff --git a/kernel/softirq.c b/kernel/softirq.c
69594 index 671f959..91c51cb 100644
69595 --- a/kernel/softirq.c
69596 +++ b/kernel/softirq.c
69597 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69598
69599 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69600
69601 -char *softirq_to_name[NR_SOFTIRQS] = {
69602 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69603 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69604 "TASKLET", "SCHED", "HRTIMER", "RCU"
69605 };
69606 @@ -235,7 +235,7 @@ restart:
69607 kstat_incr_softirqs_this_cpu(vec_nr);
69608
69609 trace_softirq_entry(vec_nr);
69610 - h->action(h);
69611 + h->action();
69612 trace_softirq_exit(vec_nr);
69613 if (unlikely(prev_count != preempt_count())) {
69614 printk(KERN_ERR "huh, entered softirq %u %s %p"
69615 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69616 or_softirq_pending(1UL << nr);
69617 }
69618
69619 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69620 +void open_softirq(int nr, void (*action)(void))
69621 {
69622 - softirq_vec[nr].action = action;
69623 + pax_open_kernel();
69624 + *(void **)&softirq_vec[nr].action = action;
69625 + pax_close_kernel();
69626 }
69627
69628 /*
69629 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69630
69631 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69632
69633 -static void tasklet_action(struct softirq_action *a)
69634 +static void tasklet_action(void)
69635 {
69636 struct tasklet_struct *list;
69637
69638 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69639 }
69640 }
69641
69642 -static void tasklet_hi_action(struct softirq_action *a)
69643 +static void tasklet_hi_action(void)
69644 {
69645 struct tasklet_struct *list;
69646
69647 diff --git a/kernel/srcu.c b/kernel/srcu.c
69648 index 2095be3..9a5b89d 100644
69649 --- a/kernel/srcu.c
69650 +++ b/kernel/srcu.c
69651 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69652 preempt_disable();
69653 idx = rcu_dereference_index_check(sp->completed,
69654 rcu_read_lock_sched_held()) & 0x1;
69655 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69656 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69657 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69658 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69659 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69660 preempt_enable();
69661 return idx;
69662 }
69663 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69664 {
69665 preempt_disable();
69666 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69667 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69668 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69669 preempt_enable();
69670 }
69671 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69672 diff --git a/kernel/sys.c b/kernel/sys.c
69673 index 2d39a84..f778b49 100644
69674 --- a/kernel/sys.c
69675 +++ b/kernel/sys.c
69676 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69677 error = -EACCES;
69678 goto out;
69679 }
69680 +
69681 + if (gr_handle_chroot_setpriority(p, niceval)) {
69682 + error = -EACCES;
69683 + goto out;
69684 + }
69685 +
69686 no_nice = security_task_setnice(p, niceval);
69687 if (no_nice) {
69688 error = no_nice;
69689 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69690 goto error;
69691 }
69692
69693 + if (gr_check_group_change(new->gid, new->egid, -1))
69694 + goto error;
69695 +
69696 if (rgid != (gid_t) -1 ||
69697 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69698 new->sgid = new->egid;
69699 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69700 old = current_cred();
69701
69702 retval = -EPERM;
69703 +
69704 + if (gr_check_group_change(kgid, kgid, kgid))
69705 + goto error;
69706 +
69707 if (nsown_capable(CAP_SETGID))
69708 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69709 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69710 @@ -646,7 +659,7 @@ error:
69711 /*
69712 * change the user struct in a credentials set to match the new UID
69713 */
69714 -static int set_user(struct cred *new)
69715 +int set_user(struct cred *new)
69716 {
69717 struct user_struct *new_user;
69718
69719 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69720 goto error;
69721 }
69722
69723 + if (gr_check_user_change(new->uid, new->euid, -1))
69724 + goto error;
69725 +
69726 if (!uid_eq(new->uid, old->uid)) {
69727 retval = set_user(new);
69728 if (retval < 0)
69729 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69730 old = current_cred();
69731
69732 retval = -EPERM;
69733 +
69734 + if (gr_check_crash_uid(kuid))
69735 + goto error;
69736 + if (gr_check_user_change(kuid, kuid, kuid))
69737 + goto error;
69738 +
69739 if (nsown_capable(CAP_SETUID)) {
69740 new->suid = new->uid = kuid;
69741 if (!uid_eq(kuid, old->uid)) {
69742 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69743 goto error;
69744 }
69745
69746 + if (gr_check_user_change(kruid, keuid, -1))
69747 + goto error;
69748 +
69749 if (ruid != (uid_t) -1) {
69750 new->uid = kruid;
69751 if (!uid_eq(kruid, old->uid)) {
69752 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69753 goto error;
69754 }
69755
69756 + if (gr_check_group_change(krgid, kegid, -1))
69757 + goto error;
69758 +
69759 if (rgid != (gid_t) -1)
69760 new->gid = krgid;
69761 if (egid != (gid_t) -1)
69762 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69763 if (!uid_valid(kuid))
69764 return old_fsuid;
69765
69766 + if (gr_check_user_change(-1, -1, kuid))
69767 + goto error;
69768 +
69769 new = prepare_creds();
69770 if (!new)
69771 return old_fsuid;
69772 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69773 }
69774 }
69775
69776 +error:
69777 abort_creds(new);
69778 return old_fsuid;
69779
69780 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69781 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69782 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69783 nsown_capable(CAP_SETGID)) {
69784 + if (gr_check_group_change(-1, -1, kgid))
69785 + goto error;
69786 +
69787 if (!gid_eq(kgid, old->fsgid)) {
69788 new->fsgid = kgid;
69789 goto change_okay;
69790 }
69791 }
69792
69793 +error:
69794 abort_creds(new);
69795 return old_fsgid;
69796
69797 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69798 }
69799 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69800 snprintf(buf, len, "2.6.%u%s", v, rest);
69801 - ret = copy_to_user(release, buf, len);
69802 + if (len > sizeof(buf))
69803 + ret = -EFAULT;
69804 + else
69805 + ret = copy_to_user(release, buf, len);
69806 }
69807 return ret;
69808 }
69809 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69810 return -EFAULT;
69811
69812 down_read(&uts_sem);
69813 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69814 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69815 __OLD_UTS_LEN);
69816 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69817 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69818 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69819 __OLD_UTS_LEN);
69820 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69821 - error |= __copy_to_user(&name->release, &utsname()->release,
69822 + error |= __copy_to_user(name->release, &utsname()->release,
69823 __OLD_UTS_LEN);
69824 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69825 - error |= __copy_to_user(&name->version, &utsname()->version,
69826 + error |= __copy_to_user(name->version, &utsname()->version,
69827 __OLD_UTS_LEN);
69828 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69829 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69830 + error |= __copy_to_user(name->machine, &utsname()->machine,
69831 __OLD_UTS_LEN);
69832 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69833 up_read(&uts_sem);
69834 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69835 error = get_dumpable(me->mm);
69836 break;
69837 case PR_SET_DUMPABLE:
69838 - if (arg2 < 0 || arg2 > 1) {
69839 + if (arg2 > 1) {
69840 error = -EINVAL;
69841 break;
69842 }
69843 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69844 index 4ab1187..33f4f2b 100644
69845 --- a/kernel/sysctl.c
69846 +++ b/kernel/sysctl.c
69847 @@ -91,7 +91,6 @@
69848
69849
69850 #if defined(CONFIG_SYSCTL)
69851 -
69852 /* External variables not in a header file. */
69853 extern int sysctl_overcommit_memory;
69854 extern int sysctl_overcommit_ratio;
69855 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69856 void __user *buffer, size_t *lenp, loff_t *ppos);
69857 #endif
69858
69859 -#ifdef CONFIG_PRINTK
69860 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69861 void __user *buffer, size_t *lenp, loff_t *ppos);
69862 -#endif
69863 +
69864 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69865 + void __user *buffer, size_t *lenp, loff_t *ppos);
69866 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69867 + void __user *buffer, size_t *lenp, loff_t *ppos);
69868
69869 #ifdef CONFIG_MAGIC_SYSRQ
69870 /* Note: sysrq code uses it's own private copy */
69871 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69872
69873 #endif
69874
69875 +extern struct ctl_table grsecurity_table[];
69876 +
69877 static struct ctl_table kern_table[];
69878 static struct ctl_table vm_table[];
69879 static struct ctl_table fs_table[];
69880 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69881 int sysctl_legacy_va_layout;
69882 #endif
69883
69884 +#ifdef CONFIG_PAX_SOFTMODE
69885 +static ctl_table pax_table[] = {
69886 + {
69887 + .procname = "softmode",
69888 + .data = &pax_softmode,
69889 + .maxlen = sizeof(unsigned int),
69890 + .mode = 0600,
69891 + .proc_handler = &proc_dointvec,
69892 + },
69893 +
69894 + { }
69895 +};
69896 +#endif
69897 +
69898 /* The default sysctl tables: */
69899
69900 static struct ctl_table sysctl_base_table[] = {
69901 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69902 #endif
69903
69904 static struct ctl_table kern_table[] = {
69905 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69906 + {
69907 + .procname = "grsecurity",
69908 + .mode = 0500,
69909 + .child = grsecurity_table,
69910 + },
69911 +#endif
69912 +
69913 +#ifdef CONFIG_PAX_SOFTMODE
69914 + {
69915 + .procname = "pax",
69916 + .mode = 0500,
69917 + .child = pax_table,
69918 + },
69919 +#endif
69920 +
69921 {
69922 .procname = "sched_child_runs_first",
69923 .data = &sysctl_sched_child_runs_first,
69924 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69925 .data = core_pattern,
69926 .maxlen = CORENAME_MAX_SIZE,
69927 .mode = 0644,
69928 - .proc_handler = proc_dostring,
69929 + .proc_handler = proc_dostring_coredump,
69930 },
69931 {
69932 .procname = "core_pipe_limit",
69933 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69934 .data = &modprobe_path,
69935 .maxlen = KMOD_PATH_LEN,
69936 .mode = 0644,
69937 - .proc_handler = proc_dostring,
69938 + .proc_handler = proc_dostring_modpriv,
69939 },
69940 {
69941 .procname = "modules_disabled",
69942 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69943 .extra1 = &zero,
69944 .extra2 = &one,
69945 },
69946 +#endif
69947 {
69948 .procname = "kptr_restrict",
69949 .data = &kptr_restrict,
69950 .maxlen = sizeof(int),
69951 .mode = 0644,
69952 .proc_handler = proc_dointvec_minmax_sysadmin,
69953 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69954 + .extra1 = &two,
69955 +#else
69956 .extra1 = &zero,
69957 +#endif
69958 .extra2 = &two,
69959 },
69960 -#endif
69961 {
69962 .procname = "ngroups_max",
69963 .data = &ngroups_max,
69964 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69965 .proc_handler = proc_dointvec_minmax,
69966 .extra1 = &zero,
69967 },
69968 + {
69969 + .procname = "heap_stack_gap",
69970 + .data = &sysctl_heap_stack_gap,
69971 + .maxlen = sizeof(sysctl_heap_stack_gap),
69972 + .mode = 0644,
69973 + .proc_handler = proc_doulongvec_minmax,
69974 + },
69975 #else
69976 {
69977 .procname = "nr_trim_pages",
69978 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69979 .data = &suid_dumpable,
69980 .maxlen = sizeof(int),
69981 .mode = 0644,
69982 - .proc_handler = proc_dointvec_minmax,
69983 + .proc_handler = proc_dointvec_minmax_coredump,
69984 .extra1 = &zero,
69985 .extra2 = &two,
69986 },
69987 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69988 buffer, lenp, ppos);
69989 }
69990
69991 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69992 + void __user *buffer, size_t *lenp, loff_t *ppos)
69993 +{
69994 + if (write && !capable(CAP_SYS_MODULE))
69995 + return -EPERM;
69996 +
69997 + return _proc_do_string(table->data, table->maxlen, write,
69998 + buffer, lenp, ppos);
69999 +}
70000 +
70001 static size_t proc_skip_spaces(char **buf)
70002 {
70003 size_t ret;
70004 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70005 len = strlen(tmp);
70006 if (len > *size)
70007 len = *size;
70008 + if (len > sizeof(tmp))
70009 + len = sizeof(tmp);
70010 if (copy_to_user(*buf, tmp, len))
70011 return -EFAULT;
70012 *size -= len;
70013 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
70014 return err;
70015 }
70016
70017 -#ifdef CONFIG_PRINTK
70018 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70019 void __user *buffer, size_t *lenp, loff_t *ppos)
70020 {
70021 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70022
70023 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70024 }
70025 -#endif
70026
70027 struct do_proc_dointvec_minmax_conv_param {
70028 int *min;
70029 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
70030 do_proc_dointvec_minmax_conv, &param);
70031 }
70032
70033 +static void validate_coredump_safety(void)
70034 +{
70035 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
70036 + core_pattern[0] != '/' && core_pattern[0] != '|') {
70037 + printk(KERN_WARNING "Unsafe core_pattern used with "\
70038 + "suid_dumpable=2. Pipe handler or fully qualified "\
70039 + "core dump path required.\n");
70040 + }
70041 +}
70042 +
70043 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70044 + void __user *buffer, size_t *lenp, loff_t *ppos)
70045 +{
70046 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70047 + if (!error)
70048 + validate_coredump_safety();
70049 + return error;
70050 +}
70051 +
70052 +static int proc_dostring_coredump(struct ctl_table *table, int write,
70053 + void __user *buffer, size_t *lenp, loff_t *ppos)
70054 +{
70055 + int error = proc_dostring(table, write, buffer, lenp, ppos);
70056 + if (!error)
70057 + validate_coredump_safety();
70058 + return error;
70059 +}
70060 +
70061 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
70062 void __user *buffer,
70063 size_t *lenp, loff_t *ppos,
70064 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70065 *i = val;
70066 } else {
70067 val = convdiv * (*i) / convmul;
70068 - if (!first)
70069 + if (!first) {
70070 err = proc_put_char(&buffer, &left, '\t');
70071 + if (err)
70072 + break;
70073 + }
70074 err = proc_put_long(&buffer, &left, val, false);
70075 if (err)
70076 break;
70077 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
70078 return -ENOSYS;
70079 }
70080
70081 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70082 + void __user *buffer, size_t *lenp, loff_t *ppos)
70083 +{
70084 + return -ENOSYS;
70085 +}
70086 +
70087 int proc_dointvec(struct ctl_table *table, int write,
70088 void __user *buffer, size_t *lenp, loff_t *ppos)
70089 {
70090 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70091 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70092 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70093 EXPORT_SYMBOL(proc_dostring);
70094 +EXPORT_SYMBOL(proc_dostring_modpriv);
70095 EXPORT_SYMBOL(proc_doulongvec_minmax);
70096 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70097 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70098 index a650694..aaeeb20 100644
70099 --- a/kernel/sysctl_binary.c
70100 +++ b/kernel/sysctl_binary.c
70101 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70102 int i;
70103
70104 set_fs(KERNEL_DS);
70105 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70106 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70107 set_fs(old_fs);
70108 if (result < 0)
70109 goto out_kfree;
70110 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70111 }
70112
70113 set_fs(KERNEL_DS);
70114 - result = vfs_write(file, buffer, str - buffer, &pos);
70115 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70116 set_fs(old_fs);
70117 if (result < 0)
70118 goto out_kfree;
70119 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70120 int i;
70121
70122 set_fs(KERNEL_DS);
70123 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70124 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70125 set_fs(old_fs);
70126 if (result < 0)
70127 goto out_kfree;
70128 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70129 }
70130
70131 set_fs(KERNEL_DS);
70132 - result = vfs_write(file, buffer, str - buffer, &pos);
70133 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70134 set_fs(old_fs);
70135 if (result < 0)
70136 goto out_kfree;
70137 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70138 int i;
70139
70140 set_fs(KERNEL_DS);
70141 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70142 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70143 set_fs(old_fs);
70144 if (result < 0)
70145 goto out;
70146 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70147 __le16 dnaddr;
70148
70149 set_fs(KERNEL_DS);
70150 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70151 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70152 set_fs(old_fs);
70153 if (result < 0)
70154 goto out;
70155 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70156 le16_to_cpu(dnaddr) & 0x3ff);
70157
70158 set_fs(KERNEL_DS);
70159 - result = vfs_write(file, buf, len, &pos);
70160 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70161 set_fs(old_fs);
70162 if (result < 0)
70163 goto out;
70164 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70165 index e660464..c8b9e67 100644
70166 --- a/kernel/taskstats.c
70167 +++ b/kernel/taskstats.c
70168 @@ -27,9 +27,12 @@
70169 #include <linux/cgroup.h>
70170 #include <linux/fs.h>
70171 #include <linux/file.h>
70172 +#include <linux/grsecurity.h>
70173 #include <net/genetlink.h>
70174 #include <linux/atomic.h>
70175
70176 +extern int gr_is_taskstats_denied(int pid);
70177 +
70178 /*
70179 * Maximum length of a cpumask that can be specified in
70180 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70181 @@ -556,6 +559,9 @@ err:
70182
70183 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70184 {
70185 + if (gr_is_taskstats_denied(current->pid))
70186 + return -EACCES;
70187 +
70188 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70189 return cmd_attr_register_cpumask(info);
70190 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70191 diff --git a/kernel/time.c b/kernel/time.c
70192 index ba744cf..267b7c5 100644
70193 --- a/kernel/time.c
70194 +++ b/kernel/time.c
70195 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70196 return error;
70197
70198 if (tz) {
70199 + /* we log in do_settimeofday called below, so don't log twice
70200 + */
70201 + if (!tv)
70202 + gr_log_timechange();
70203 +
70204 sys_tz = *tz;
70205 update_vsyscall_tz();
70206 if (firsttime) {
70207 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70208 index aa27d39..34d221c 100644
70209 --- a/kernel/time/alarmtimer.c
70210 +++ b/kernel/time/alarmtimer.c
70211 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70212 struct platform_device *pdev;
70213 int error = 0;
70214 int i;
70215 - struct k_clock alarm_clock = {
70216 + static struct k_clock alarm_clock = {
70217 .clock_getres = alarm_clock_getres,
70218 .clock_get = alarm_clock_get,
70219 .timer_create = alarm_timer_create,
70220 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70221 index f113755..ec24223 100644
70222 --- a/kernel/time/tick-broadcast.c
70223 +++ b/kernel/time/tick-broadcast.c
70224 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70225 * then clear the broadcast bit.
70226 */
70227 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70228 - int cpu = smp_processor_id();
70229 + cpu = smp_processor_id();
70230
70231 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70232 tick_broadcast_clear_oneshot(cpu);
70233 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70234 index 3447cfa..291806b 100644
70235 --- a/kernel/time/timekeeping.c
70236 +++ b/kernel/time/timekeeping.c
70237 @@ -14,6 +14,7 @@
70238 #include <linux/init.h>
70239 #include <linux/mm.h>
70240 #include <linux/sched.h>
70241 +#include <linux/grsecurity.h>
70242 #include <linux/syscore_ops.h>
70243 #include <linux/clocksource.h>
70244 #include <linux/jiffies.h>
70245 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70246 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70247 return -EINVAL;
70248
70249 + gr_log_timechange();
70250 +
70251 write_seqlock_irqsave(&timekeeper.lock, flags);
70252
70253 timekeeping_forward_now();
70254 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70255 index 3258455..f35227d 100644
70256 --- a/kernel/time/timer_list.c
70257 +++ b/kernel/time/timer_list.c
70258 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70259
70260 static void print_name_offset(struct seq_file *m, void *sym)
70261 {
70262 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70263 + SEQ_printf(m, "<%p>", NULL);
70264 +#else
70265 char symname[KSYM_NAME_LEN];
70266
70267 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70268 SEQ_printf(m, "<%pK>", sym);
70269 else
70270 SEQ_printf(m, "%s", symname);
70271 +#endif
70272 }
70273
70274 static void
70275 @@ -112,7 +116,11 @@ next_one:
70276 static void
70277 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70278 {
70279 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70280 + SEQ_printf(m, " .base: %p\n", NULL);
70281 +#else
70282 SEQ_printf(m, " .base: %pK\n", base);
70283 +#endif
70284 SEQ_printf(m, " .index: %d\n",
70285 base->index);
70286 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70287 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70288 {
70289 struct proc_dir_entry *pe;
70290
70291 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70292 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70293 +#else
70294 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70295 +#endif
70296 if (!pe)
70297 return -ENOMEM;
70298 return 0;
70299 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70300 index 0b537f2..9e71eca 100644
70301 --- a/kernel/time/timer_stats.c
70302 +++ b/kernel/time/timer_stats.c
70303 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70304 static unsigned long nr_entries;
70305 static struct entry entries[MAX_ENTRIES];
70306
70307 -static atomic_t overflow_count;
70308 +static atomic_unchecked_t overflow_count;
70309
70310 /*
70311 * The entries are in a hash-table, for fast lookup:
70312 @@ -140,7 +140,7 @@ static void reset_entries(void)
70313 nr_entries = 0;
70314 memset(entries, 0, sizeof(entries));
70315 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70316 - atomic_set(&overflow_count, 0);
70317 + atomic_set_unchecked(&overflow_count, 0);
70318 }
70319
70320 static struct entry *alloc_entry(void)
70321 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70322 if (likely(entry))
70323 entry->count++;
70324 else
70325 - atomic_inc(&overflow_count);
70326 + atomic_inc_unchecked(&overflow_count);
70327
70328 out_unlock:
70329 raw_spin_unlock_irqrestore(lock, flags);
70330 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70331
70332 static void print_name_offset(struct seq_file *m, unsigned long addr)
70333 {
70334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70335 + seq_printf(m, "<%p>", NULL);
70336 +#else
70337 char symname[KSYM_NAME_LEN];
70338
70339 if (lookup_symbol_name(addr, symname) < 0)
70340 seq_printf(m, "<%p>", (void *)addr);
70341 else
70342 seq_printf(m, "%s", symname);
70343 +#endif
70344 }
70345
70346 static int tstats_show(struct seq_file *m, void *v)
70347 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70348
70349 seq_puts(m, "Timer Stats Version: v0.2\n");
70350 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70351 - if (atomic_read(&overflow_count))
70352 + if (atomic_read_unchecked(&overflow_count))
70353 seq_printf(m, "Overflow: %d entries\n",
70354 - atomic_read(&overflow_count));
70355 + atomic_read_unchecked(&overflow_count));
70356
70357 for (i = 0; i < nr_entries; i++) {
70358 entry = entries + i;
70359 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70360 {
70361 struct proc_dir_entry *pe;
70362
70363 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70364 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70365 +#else
70366 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70367 +#endif
70368 if (!pe)
70369 return -ENOMEM;
70370 return 0;
70371 diff --git a/kernel/timer.c b/kernel/timer.c
70372 index 6ec7e7e..cbc448b 100644
70373 --- a/kernel/timer.c
70374 +++ b/kernel/timer.c
70375 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70376 /*
70377 * This function runs timers and the timer-tq in bottom half context.
70378 */
70379 -static void run_timer_softirq(struct softirq_action *h)
70380 +static void run_timer_softirq(void)
70381 {
70382 struct tvec_base *base = __this_cpu_read(tvec_bases);
70383
70384 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70385 index c0bd030..62a1927 100644
70386 --- a/kernel/trace/blktrace.c
70387 +++ b/kernel/trace/blktrace.c
70388 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70389 struct blk_trace *bt = filp->private_data;
70390 char buf[16];
70391
70392 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70393 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70394
70395 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70396 }
70397 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70398 return 1;
70399
70400 bt = buf->chan->private_data;
70401 - atomic_inc(&bt->dropped);
70402 + atomic_inc_unchecked(&bt->dropped);
70403 return 0;
70404 }
70405
70406 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70407
70408 bt->dir = dir;
70409 bt->dev = dev;
70410 - atomic_set(&bt->dropped, 0);
70411 + atomic_set_unchecked(&bt->dropped, 0);
70412
70413 ret = -EIO;
70414 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70415 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70416 index a008663..30d7429 100644
70417 --- a/kernel/trace/ftrace.c
70418 +++ b/kernel/trace/ftrace.c
70419 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70420 if (unlikely(ftrace_disabled))
70421 return 0;
70422
70423 + ret = ftrace_arch_code_modify_prepare();
70424 + FTRACE_WARN_ON(ret);
70425 + if (ret)
70426 + return 0;
70427 +
70428 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70429 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70430 if (ret) {
70431 ftrace_bug(ret, ip);
70432 - return 0;
70433 }
70434 - return 1;
70435 + return ret ? 0 : 1;
70436 }
70437
70438 /*
70439 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70440
70441 int
70442 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70443 - void *data)
70444 + void *data)
70445 {
70446 struct ftrace_func_probe *entry;
70447 struct ftrace_page *pg;
70448 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70449 if (!count)
70450 return 0;
70451
70452 + pax_open_kernel();
70453 sort(start, count, sizeof(*start),
70454 ftrace_cmp_ips, ftrace_swap_ips);
70455 + pax_close_kernel();
70456
70457 start_pg = ftrace_allocate_pages(count);
70458 if (!start_pg)
70459 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70460 index a7fa070..403bc8d 100644
70461 --- a/kernel/trace/trace.c
70462 +++ b/kernel/trace/trace.c
70463 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70464 };
70465 #endif
70466
70467 -static struct dentry *d_tracer;
70468 -
70469 struct dentry *tracing_init_dentry(void)
70470 {
70471 + static struct dentry *d_tracer;
70472 static int once;
70473
70474 if (d_tracer)
70475 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70476 return d_tracer;
70477 }
70478
70479 -static struct dentry *d_percpu;
70480 -
70481 struct dentry *tracing_dentry_percpu(void)
70482 {
70483 + static struct dentry *d_percpu;
70484 static int once;
70485 struct dentry *d_tracer;
70486
70487 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70488 index 29111da..d190fe2 100644
70489 --- a/kernel/trace/trace_events.c
70490 +++ b/kernel/trace/trace_events.c
70491 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70492 struct ftrace_module_file_ops {
70493 struct list_head list;
70494 struct module *mod;
70495 - struct file_operations id;
70496 - struct file_operations enable;
70497 - struct file_operations format;
70498 - struct file_operations filter;
70499 };
70500
70501 static struct ftrace_module_file_ops *
70502 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70503
70504 file_ops->mod = mod;
70505
70506 - file_ops->id = ftrace_event_id_fops;
70507 - file_ops->id.owner = mod;
70508 -
70509 - file_ops->enable = ftrace_enable_fops;
70510 - file_ops->enable.owner = mod;
70511 -
70512 - file_ops->filter = ftrace_event_filter_fops;
70513 - file_ops->filter.owner = mod;
70514 -
70515 - file_ops->format = ftrace_event_format_fops;
70516 - file_ops->format.owner = mod;
70517 + pax_open_kernel();
70518 + *(void **)&mod->trace_id.owner = mod;
70519 + *(void **)&mod->trace_enable.owner = mod;
70520 + *(void **)&mod->trace_filter.owner = mod;
70521 + *(void **)&mod->trace_format.owner = mod;
70522 + pax_close_kernel();
70523
70524 list_add(&file_ops->list, &ftrace_module_file_list);
70525
70526 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70527
70528 for_each_event(call, start, end) {
70529 __trace_add_event_call(*call, mod,
70530 - &file_ops->id, &file_ops->enable,
70531 - &file_ops->filter, &file_ops->format);
70532 + &mod->trace_id, &mod->trace_enable,
70533 + &mod->trace_filter, &mod->trace_format);
70534 }
70535 }
70536
70537 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70538 index fd3c8aa..5f324a6 100644
70539 --- a/kernel/trace/trace_mmiotrace.c
70540 +++ b/kernel/trace/trace_mmiotrace.c
70541 @@ -24,7 +24,7 @@ struct header_iter {
70542 static struct trace_array *mmio_trace_array;
70543 static bool overrun_detected;
70544 static unsigned long prev_overruns;
70545 -static atomic_t dropped_count;
70546 +static atomic_unchecked_t dropped_count;
70547
70548 static void mmio_reset_data(struct trace_array *tr)
70549 {
70550 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70551
70552 static unsigned long count_overruns(struct trace_iterator *iter)
70553 {
70554 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70555 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70556 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70557
70558 if (over > prev_overruns)
70559 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70560 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70561 sizeof(*entry), 0, pc);
70562 if (!event) {
70563 - atomic_inc(&dropped_count);
70564 + atomic_inc_unchecked(&dropped_count);
70565 return;
70566 }
70567 entry = ring_buffer_event_data(event);
70568 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70569 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70570 sizeof(*entry), 0, pc);
70571 if (!event) {
70572 - atomic_inc(&dropped_count);
70573 + atomic_inc_unchecked(&dropped_count);
70574 return;
70575 }
70576 entry = ring_buffer_event_data(event);
70577 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70578 index df611a0..10d8b32 100644
70579 --- a/kernel/trace/trace_output.c
70580 +++ b/kernel/trace/trace_output.c
70581 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70582
70583 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70584 if (!IS_ERR(p)) {
70585 - p = mangle_path(s->buffer + s->len, p, "\n");
70586 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70587 if (p) {
70588 s->len = p - s->buffer;
70589 return 1;
70590 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70591 index d4545f4..a9010a1 100644
70592 --- a/kernel/trace/trace_stack.c
70593 +++ b/kernel/trace/trace_stack.c
70594 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70595 return;
70596
70597 /* we do not handle interrupt stacks yet */
70598 - if (!object_is_on_stack(&this_size))
70599 + if (!object_starts_on_stack(&this_size))
70600 return;
70601
70602 local_irq_save(flags);
70603 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70604 index ff5bdee..3eaeba6 100644
70605 --- a/lib/Kconfig.debug
70606 +++ b/lib/Kconfig.debug
70607 @@ -1165,6 +1165,7 @@ config LATENCYTOP
70608 depends on DEBUG_KERNEL
70609 depends on STACKTRACE_SUPPORT
70610 depends on PROC_FS
70611 + depends on !GRKERNSEC_HIDESYM
70612 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70613 select KALLSYMS
70614 select KALLSYMS_ALL
70615 diff --git a/lib/bitmap.c b/lib/bitmap.c
70616 index 06fdfa1..97c5c7d 100644
70617 --- a/lib/bitmap.c
70618 +++ b/lib/bitmap.c
70619 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70620 {
70621 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70622 u32 chunk;
70623 - const char __user __force *ubuf = (const char __user __force *)buf;
70624 + const char __user *ubuf = (const char __force_user *)buf;
70625
70626 bitmap_zero(maskp, nmaskbits);
70627
70628 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70629 {
70630 if (!access_ok(VERIFY_READ, ubuf, ulen))
70631 return -EFAULT;
70632 - return __bitmap_parse((const char __force *)ubuf,
70633 + return __bitmap_parse((const char __force_kernel *)ubuf,
70634 ulen, 1, maskp, nmaskbits);
70635
70636 }
70637 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70638 {
70639 unsigned a, b;
70640 int c, old_c, totaldigits;
70641 - const char __user __force *ubuf = (const char __user __force *)buf;
70642 + const char __user *ubuf = (const char __force_user *)buf;
70643 int exp_digit, in_range;
70644
70645 totaldigits = c = 0;
70646 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70647 {
70648 if (!access_ok(VERIFY_READ, ubuf, ulen))
70649 return -EFAULT;
70650 - return __bitmap_parselist((const char __force *)ubuf,
70651 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70652 ulen, 1, maskp, nmaskbits);
70653 }
70654 EXPORT_SYMBOL(bitmap_parselist_user);
70655 diff --git a/lib/bug.c b/lib/bug.c
70656 index a28c141..2bd3d95 100644
70657 --- a/lib/bug.c
70658 +++ b/lib/bug.c
70659 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70660 return BUG_TRAP_TYPE_NONE;
70661
70662 bug = find_bug(bugaddr);
70663 + if (!bug)
70664 + return BUG_TRAP_TYPE_NONE;
70665
70666 file = NULL;
70667 line = 0;
70668 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70669 index d11808c..dc2d6f8 100644
70670 --- a/lib/debugobjects.c
70671 +++ b/lib/debugobjects.c
70672 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70673 if (limit > 4)
70674 return;
70675
70676 - is_on_stack = object_is_on_stack(addr);
70677 + is_on_stack = object_starts_on_stack(addr);
70678 if (is_on_stack == onstack)
70679 return;
70680
70681 diff --git a/lib/devres.c b/lib/devres.c
70682 index 80b9c76..9e32279 100644
70683 --- a/lib/devres.c
70684 +++ b/lib/devres.c
70685 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70686 void devm_iounmap(struct device *dev, void __iomem *addr)
70687 {
70688 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70689 - (void *)addr));
70690 + (void __force *)addr));
70691 iounmap(addr);
70692 }
70693 EXPORT_SYMBOL(devm_iounmap);
70694 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70695 {
70696 ioport_unmap(addr);
70697 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70698 - devm_ioport_map_match, (void *)addr));
70699 + devm_ioport_map_match, (void __force *)addr));
70700 }
70701 EXPORT_SYMBOL(devm_ioport_unmap);
70702
70703 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70704 index 66ce414..6f0a0dd 100644
70705 --- a/lib/dma-debug.c
70706 +++ b/lib/dma-debug.c
70707 @@ -924,7 +924,7 @@ out:
70708
70709 static void check_for_stack(struct device *dev, void *addr)
70710 {
70711 - if (object_is_on_stack(addr))
70712 + if (object_starts_on_stack(addr))
70713 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70714 "stack [addr=%p]\n", addr);
70715 }
70716 diff --git a/lib/inflate.c b/lib/inflate.c
70717 index 013a761..c28f3fc 100644
70718 --- a/lib/inflate.c
70719 +++ b/lib/inflate.c
70720 @@ -269,7 +269,7 @@ static void free(void *where)
70721 malloc_ptr = free_mem_ptr;
70722 }
70723 #else
70724 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70725 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70726 #define free(a) kfree(a)
70727 #endif
70728
70729 diff --git a/lib/ioremap.c b/lib/ioremap.c
70730 index 0c9216c..863bd89 100644
70731 --- a/lib/ioremap.c
70732 +++ b/lib/ioremap.c
70733 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70734 unsigned long next;
70735
70736 phys_addr -= addr;
70737 - pmd = pmd_alloc(&init_mm, pud, addr);
70738 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70739 if (!pmd)
70740 return -ENOMEM;
70741 do {
70742 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70743 unsigned long next;
70744
70745 phys_addr -= addr;
70746 - pud = pud_alloc(&init_mm, pgd, addr);
70747 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70748 if (!pud)
70749 return -ENOMEM;
70750 do {
70751 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70752 index bd2bea9..6b3c95e 100644
70753 --- a/lib/is_single_threaded.c
70754 +++ b/lib/is_single_threaded.c
70755 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70756 struct task_struct *p, *t;
70757 bool ret;
70758
70759 + if (!mm)
70760 + return true;
70761 +
70762 if (atomic_read(&task->signal->live) != 1)
70763 return false;
70764
70765 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70766 index e796429..6e38f9f 100644
70767 --- a/lib/radix-tree.c
70768 +++ b/lib/radix-tree.c
70769 @@ -92,7 +92,7 @@ struct radix_tree_preload {
70770 int nr;
70771 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70772 };
70773 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70774 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70775
70776 static inline void *ptr_to_indirect(void *ptr)
70777 {
70778 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70779 index 598a73e..5c5aeb5 100644
70780 --- a/lib/vsprintf.c
70781 +++ b/lib/vsprintf.c
70782 @@ -16,6 +16,9 @@
70783 * - scnprintf and vscnprintf
70784 */
70785
70786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70787 +#define __INCLUDED_BY_HIDESYM 1
70788 +#endif
70789 #include <stdarg.h>
70790 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70791 #include <linux/types.h>
70792 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70793 char sym[KSYM_SYMBOL_LEN];
70794 if (ext == 'B')
70795 sprint_backtrace(sym, value);
70796 - else if (ext != 'f' && ext != 's')
70797 + else if (ext != 'f' && ext != 's' && ext != 'a')
70798 sprint_symbol(sym, value);
70799 else
70800 sprint_symbol_no_offset(sym, value);
70801 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70802 return number(buf, end, *(const netdev_features_t *)addr, spec);
70803 }
70804
70805 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70806 +int kptr_restrict __read_mostly = 2;
70807 +#else
70808 int kptr_restrict __read_mostly;
70809 +#endif
70810
70811 /*
70812 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70813 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70814 * - 'S' For symbolic direct pointers with offset
70815 * - 's' For symbolic direct pointers without offset
70816 * - 'B' For backtraced symbolic direct pointers with offset
70817 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70818 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70819 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70820 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70821 * - 'M' For a 6-byte MAC address, it prints the address in the
70822 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70823
70824 if (!ptr && *fmt != 'K') {
70825 /*
70826 - * Print (null) with the same width as a pointer so it makes
70827 + * Print (nil) with the same width as a pointer so it makes
70828 * tabular output look nice.
70829 */
70830 if (spec.field_width == -1)
70831 spec.field_width = default_width;
70832 - return string(buf, end, "(null)", spec);
70833 + return string(buf, end, "(nil)", spec);
70834 }
70835
70836 switch (*fmt) {
70837 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70838 /* Fallthrough */
70839 case 'S':
70840 case 's':
70841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70842 + break;
70843 +#else
70844 + return symbol_string(buf, end, ptr, spec, *fmt);
70845 +#endif
70846 + case 'A':
70847 + case 'a':
70848 case 'B':
70849 return symbol_string(buf, end, ptr, spec, *fmt);
70850 case 'R':
70851 @@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70852 va_end(va);
70853 return buf;
70854 }
70855 + case 'P':
70856 + break;
70857 case 'K':
70858 /*
70859 * %pK cannot be used in IRQ context because its test
70860 @@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70861 }
70862 break;
70863 }
70864 +
70865 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70866 + /* 'P' = approved pointers to copy to userland,
70867 + as in the /proc/kallsyms case, as we make it display nothing
70868 + for non-root users, and the real contents for root users
70869 + Also ignore 'K' pointers, since we force their NULLing for non-root users
70870 + above
70871 + */
70872 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70873 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70874 + dump_stack();
70875 + ptr = NULL;
70876 + }
70877 +#endif
70878 +
70879 spec.flags |= SMALL;
70880 if (spec.field_width == -1) {
70881 spec.field_width = default_width;
70882 @@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70883 typeof(type) value; \
70884 if (sizeof(type) == 8) { \
70885 args = PTR_ALIGN(args, sizeof(u32)); \
70886 - *(u32 *)&value = *(u32 *)args; \
70887 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70888 + *(u32 *)&value = *(const u32 *)args; \
70889 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70890 } else { \
70891 args = PTR_ALIGN(args, sizeof(type)); \
70892 - value = *(typeof(type) *)args; \
70893 + value = *(const typeof(type) *)args; \
70894 } \
70895 args += sizeof(type); \
70896 value; \
70897 @@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70898 case FORMAT_TYPE_STR: {
70899 const char *str_arg = args;
70900 args += strlen(str_arg) + 1;
70901 - str = string(str, end, (char *)str_arg, spec);
70902 + str = string(str, end, str_arg, spec);
70903 break;
70904 }
70905
70906 diff --git a/localversion-grsec b/localversion-grsec
70907 new file mode 100644
70908 index 0000000..7cd6065
70909 --- /dev/null
70910 +++ b/localversion-grsec
70911 @@ -0,0 +1 @@
70912 +-grsec
70913 diff --git a/mm/Kconfig b/mm/Kconfig
70914 index 82fed4e..979e814 100644
70915 --- a/mm/Kconfig
70916 +++ b/mm/Kconfig
70917 @@ -247,10 +247,10 @@ config KSM
70918 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70919
70920 config DEFAULT_MMAP_MIN_ADDR
70921 - int "Low address space to protect from user allocation"
70922 + int "Low address space to protect from user allocation"
70923 depends on MMU
70924 - default 4096
70925 - help
70926 + default 65536
70927 + help
70928 This is the portion of low virtual memory which should be protected
70929 from userspace allocation. Keeping a user from writing to low pages
70930 can help reduce the impact of kernel NULL pointer bugs.
70931 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70932
70933 config HWPOISON_INJECT
70934 tristate "HWPoison pages injector"
70935 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70936 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70937 select PROC_PAGE_MONITOR
70938
70939 config NOMMU_INITIAL_TRIM_EXCESS
70940 diff --git a/mm/filemap.c b/mm/filemap.c
70941 index a4a5260..6151dc5 100644
70942 --- a/mm/filemap.c
70943 +++ b/mm/filemap.c
70944 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70945 struct address_space *mapping = file->f_mapping;
70946
70947 if (!mapping->a_ops->readpage)
70948 - return -ENOEXEC;
70949 + return -ENODEV;
70950 file_accessed(file);
70951 vma->vm_ops = &generic_file_vm_ops;
70952 vma->vm_flags |= VM_CAN_NONLINEAR;
70953 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70954 *pos = i_size_read(inode);
70955
70956 if (limit != RLIM_INFINITY) {
70957 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70958 if (*pos >= limit) {
70959 send_sig(SIGXFSZ, current, 0);
70960 return -EFBIG;
70961 diff --git a/mm/fremap.c b/mm/fremap.c
70962 index 9ed4fd4..c42648d 100644
70963 --- a/mm/fremap.c
70964 +++ b/mm/fremap.c
70965 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70966 retry:
70967 vma = find_vma(mm, start);
70968
70969 +#ifdef CONFIG_PAX_SEGMEXEC
70970 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70971 + goto out;
70972 +#endif
70973 +
70974 /*
70975 * Make sure the vma is shared, that it supports prefaulting,
70976 * and that the remapped range is valid and fully within
70977 diff --git a/mm/highmem.c b/mm/highmem.c
70978 index 57d82c6..e9e0552 100644
70979 --- a/mm/highmem.c
70980 +++ b/mm/highmem.c
70981 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70982 * So no dangers, even with speculative execution.
70983 */
70984 page = pte_page(pkmap_page_table[i]);
70985 + pax_open_kernel();
70986 pte_clear(&init_mm, (unsigned long)page_address(page),
70987 &pkmap_page_table[i]);
70988 -
70989 + pax_close_kernel();
70990 set_page_address(page, NULL);
70991 need_flush = 1;
70992 }
70993 @@ -186,9 +187,11 @@ start:
70994 }
70995 }
70996 vaddr = PKMAP_ADDR(last_pkmap_nr);
70997 +
70998 + pax_open_kernel();
70999 set_pte_at(&init_mm, vaddr,
71000 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71001 -
71002 + pax_close_kernel();
71003 pkmap_count[last_pkmap_nr] = 1;
71004 set_page_address(page, (void *)vaddr);
71005
71006 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71007 index 57c4b93..24b8f59 100644
71008 --- a/mm/huge_memory.c
71009 +++ b/mm/huge_memory.c
71010 @@ -735,7 +735,7 @@ out:
71011 * run pte_offset_map on the pmd, if an huge pmd could
71012 * materialize from under us from a different thread.
71013 */
71014 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71015 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71016 return VM_FAULT_OOM;
71017 /* if an huge pmd materialized from under us just retry later */
71018 if (unlikely(pmd_trans_huge(*pmd)))
71019 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71020 index 19558df..f7743b3 100644
71021 --- a/mm/hugetlb.c
71022 +++ b/mm/hugetlb.c
71023 @@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71024 return 1;
71025 }
71026
71027 +#ifdef CONFIG_PAX_SEGMEXEC
71028 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71029 +{
71030 + struct mm_struct *mm = vma->vm_mm;
71031 + struct vm_area_struct *vma_m;
71032 + unsigned long address_m;
71033 + pte_t *ptep_m;
71034 +
71035 + vma_m = pax_find_mirror_vma(vma);
71036 + if (!vma_m)
71037 + return;
71038 +
71039 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71040 + address_m = address + SEGMEXEC_TASK_SIZE;
71041 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71042 + get_page(page_m);
71043 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71044 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71045 +}
71046 +#endif
71047 +
71048 /*
71049 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71050 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71051 @@ -2575,6 +2596,11 @@ retry_avoidcopy:
71052 make_huge_pte(vma, new_page, 1));
71053 page_remove_rmap(old_page);
71054 hugepage_add_new_anon_rmap(new_page, vma, address);
71055 +
71056 +#ifdef CONFIG_PAX_SEGMEXEC
71057 + pax_mirror_huge_pte(vma, address, new_page);
71058 +#endif
71059 +
71060 /* Make the old page be freed below */
71061 new_page = old_page;
71062 mmu_notifier_invalidate_range_end(mm,
71063 @@ -2729,6 +2755,10 @@ retry:
71064 && (vma->vm_flags & VM_SHARED)));
71065 set_huge_pte_at(mm, address, ptep, new_pte);
71066
71067 +#ifdef CONFIG_PAX_SEGMEXEC
71068 + pax_mirror_huge_pte(vma, address, page);
71069 +#endif
71070 +
71071 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71072 /* Optimization, do the COW without a second fault */
71073 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71074 @@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71075 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71076 struct hstate *h = hstate_vma(vma);
71077
71078 +#ifdef CONFIG_PAX_SEGMEXEC
71079 + struct vm_area_struct *vma_m;
71080 +#endif
71081 +
71082 address &= huge_page_mask(h);
71083
71084 ptep = huge_pte_offset(mm, address);
71085 @@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71086 VM_FAULT_SET_HINDEX(h - hstates);
71087 }
71088
71089 +#ifdef CONFIG_PAX_SEGMEXEC
71090 + vma_m = pax_find_mirror_vma(vma);
71091 + if (vma_m) {
71092 + unsigned long address_m;
71093 +
71094 + if (vma->vm_start > vma_m->vm_start) {
71095 + address_m = address;
71096 + address -= SEGMEXEC_TASK_SIZE;
71097 + vma = vma_m;
71098 + h = hstate_vma(vma);
71099 + } else
71100 + address_m = address + SEGMEXEC_TASK_SIZE;
71101 +
71102 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71103 + return VM_FAULT_OOM;
71104 + address_m &= HPAGE_MASK;
71105 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71106 + }
71107 +#endif
71108 +
71109 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71110 if (!ptep)
71111 return VM_FAULT_OOM;
71112 diff --git a/mm/internal.h b/mm/internal.h
71113 index 8052379..47029d1 100644
71114 --- a/mm/internal.h
71115 +++ b/mm/internal.h
71116 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71117 * in mm/page_alloc.c
71118 */
71119 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71120 +extern void free_compound_page(struct page *page);
71121 extern void prep_compound_page(struct page *page, unsigned long order);
71122 #ifdef CONFIG_MEMORY_FAILURE
71123 extern bool is_free_buddy_page(struct page *page);
71124 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71125 index 45eb621..6ccd8ea 100644
71126 --- a/mm/kmemleak.c
71127 +++ b/mm/kmemleak.c
71128 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71129
71130 for (i = 0; i < object->trace_len; i++) {
71131 void *ptr = (void *)object->trace[i];
71132 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71133 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71134 }
71135 }
71136
71137 diff --git a/mm/maccess.c b/mm/maccess.c
71138 index d53adf9..03a24bf 100644
71139 --- a/mm/maccess.c
71140 +++ b/mm/maccess.c
71141 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71142 set_fs(KERNEL_DS);
71143 pagefault_disable();
71144 ret = __copy_from_user_inatomic(dst,
71145 - (__force const void __user *)src, size);
71146 + (const void __force_user *)src, size);
71147 pagefault_enable();
71148 set_fs(old_fs);
71149
71150 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71151
71152 set_fs(KERNEL_DS);
71153 pagefault_disable();
71154 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71155 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71156 pagefault_enable();
71157 set_fs(old_fs);
71158
71159 diff --git a/mm/madvise.c b/mm/madvise.c
71160 index 14d260f..b2a80fd 100644
71161 --- a/mm/madvise.c
71162 +++ b/mm/madvise.c
71163 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71164 pgoff_t pgoff;
71165 unsigned long new_flags = vma->vm_flags;
71166
71167 +#ifdef CONFIG_PAX_SEGMEXEC
71168 + struct vm_area_struct *vma_m;
71169 +#endif
71170 +
71171 switch (behavior) {
71172 case MADV_NORMAL:
71173 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71174 @@ -119,6 +123,13 @@ success:
71175 /*
71176 * vm_flags is protected by the mmap_sem held in write mode.
71177 */
71178 +
71179 +#ifdef CONFIG_PAX_SEGMEXEC
71180 + vma_m = pax_find_mirror_vma(vma);
71181 + if (vma_m)
71182 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71183 +#endif
71184 +
71185 vma->vm_flags = new_flags;
71186
71187 out:
71188 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71189 struct vm_area_struct ** prev,
71190 unsigned long start, unsigned long end)
71191 {
71192 +
71193 +#ifdef CONFIG_PAX_SEGMEXEC
71194 + struct vm_area_struct *vma_m;
71195 +#endif
71196 +
71197 *prev = vma;
71198 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71199 return -EINVAL;
71200 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71201 zap_page_range(vma, start, end - start, &details);
71202 } else
71203 zap_page_range(vma, start, end - start, NULL);
71204 +
71205 +#ifdef CONFIG_PAX_SEGMEXEC
71206 + vma_m = pax_find_mirror_vma(vma);
71207 + if (vma_m) {
71208 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71209 + struct zap_details details = {
71210 + .nonlinear_vma = vma_m,
71211 + .last_index = ULONG_MAX,
71212 + };
71213 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71214 + } else
71215 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71216 + }
71217 +#endif
71218 +
71219 return 0;
71220 }
71221
71222 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71223 if (end < start)
71224 goto out;
71225
71226 +#ifdef CONFIG_PAX_SEGMEXEC
71227 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71228 + if (end > SEGMEXEC_TASK_SIZE)
71229 + goto out;
71230 + } else
71231 +#endif
71232 +
71233 + if (end > TASK_SIZE)
71234 + goto out;
71235 +
71236 error = 0;
71237 if (end == start)
71238 goto out;
71239 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71240 index 6de0d61..da836cf 100644
71241 --- a/mm/memory-failure.c
71242 +++ b/mm/memory-failure.c
71243 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71244
71245 int sysctl_memory_failure_recovery __read_mostly = 1;
71246
71247 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71248 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71249
71250 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71251
71252 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71253 pfn, t->comm, t->pid);
71254 si.si_signo = SIGBUS;
71255 si.si_errno = 0;
71256 - si.si_addr = (void *)addr;
71257 + si.si_addr = (void __user *)addr;
71258 #ifdef __ARCH_SI_TRAPNO
71259 si.si_trapno = trapno;
71260 #endif
71261 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71262 }
71263
71264 nr_pages = 1 << compound_trans_order(hpage);
71265 - atomic_long_add(nr_pages, &mce_bad_pages);
71266 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71267
71268 /*
71269 * We need/can do nothing about count=0 pages.
71270 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71271 if (!PageHWPoison(hpage)
71272 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71273 || (p != hpage && TestSetPageHWPoison(hpage))) {
71274 - atomic_long_sub(nr_pages, &mce_bad_pages);
71275 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71276 return 0;
71277 }
71278 set_page_hwpoison_huge_page(hpage);
71279 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71280 }
71281 if (hwpoison_filter(p)) {
71282 if (TestClearPageHWPoison(p))
71283 - atomic_long_sub(nr_pages, &mce_bad_pages);
71284 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71285 unlock_page(hpage);
71286 put_page(hpage);
71287 return 0;
71288 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71289 return 0;
71290 }
71291 if (TestClearPageHWPoison(p))
71292 - atomic_long_sub(nr_pages, &mce_bad_pages);
71293 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71294 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71295 return 0;
71296 }
71297 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71298 */
71299 if (TestClearPageHWPoison(page)) {
71300 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71301 - atomic_long_sub(nr_pages, &mce_bad_pages);
71302 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71303 freeit = 1;
71304 if (PageHuge(page))
71305 clear_page_hwpoison_huge_page(page);
71306 @@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71307 }
71308 done:
71309 if (!PageHWPoison(hpage))
71310 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71311 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71312 set_page_hwpoison_huge_page(hpage);
71313 dequeue_hwpoisoned_huge_page(hpage);
71314 /* keep elevated page count for bad page */
71315 @@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71316 return ret;
71317
71318 done:
71319 - atomic_long_add(1, &mce_bad_pages);
71320 + atomic_long_add_unchecked(1, &mce_bad_pages);
71321 SetPageHWPoison(page);
71322 /* keep elevated page count for bad page */
71323 return ret;
71324 diff --git a/mm/memory.c b/mm/memory.c
71325 index 2466d12..08be4f6 100644
71326 --- a/mm/memory.c
71327 +++ b/mm/memory.c
71328 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71329 return;
71330
71331 pmd = pmd_offset(pud, start);
71332 +
71333 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71334 pud_clear(pud);
71335 pmd_free_tlb(tlb, pmd, start);
71336 +#endif
71337 +
71338 }
71339
71340 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71341 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71342 if (end - 1 > ceiling - 1)
71343 return;
71344
71345 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71346 pud = pud_offset(pgd, start);
71347 pgd_clear(pgd);
71348 pud_free_tlb(tlb, pud, start);
71349 +#endif
71350 +
71351 }
71352
71353 /*
71354 @@ -1602,12 +1609,6 @@ no_page_table:
71355 return page;
71356 }
71357
71358 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71359 -{
71360 - return stack_guard_page_start(vma, addr) ||
71361 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71362 -}
71363 -
71364 /**
71365 * __get_user_pages() - pin user pages in memory
71366 * @tsk: task_struct of target task
71367 @@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71368 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71369 i = 0;
71370
71371 - do {
71372 + while (nr_pages) {
71373 struct vm_area_struct *vma;
71374
71375 - vma = find_extend_vma(mm, start);
71376 + vma = find_vma(mm, start);
71377 if (!vma && in_gate_area(mm, start)) {
71378 unsigned long pg = start & PAGE_MASK;
71379 pgd_t *pgd;
71380 @@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71381 goto next_page;
71382 }
71383
71384 - if (!vma ||
71385 + if (!vma || start < vma->vm_start ||
71386 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71387 !(vm_flags & vma->vm_flags))
71388 return i ? : -EFAULT;
71389 @@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71390 int ret;
71391 unsigned int fault_flags = 0;
71392
71393 - /* For mlock, just skip the stack guard page. */
71394 - if (foll_flags & FOLL_MLOCK) {
71395 - if (stack_guard_page(vma, start))
71396 - goto next_page;
71397 - }
71398 if (foll_flags & FOLL_WRITE)
71399 fault_flags |= FAULT_FLAG_WRITE;
71400 if (nonblocking)
71401 @@ -1836,7 +1832,7 @@ next_page:
71402 start += PAGE_SIZE;
71403 nr_pages--;
71404 } while (nr_pages && start < vma->vm_end);
71405 - } while (nr_pages);
71406 + }
71407 return i;
71408 }
71409 EXPORT_SYMBOL(__get_user_pages);
71410 @@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71411 page_add_file_rmap(page);
71412 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71413
71414 +#ifdef CONFIG_PAX_SEGMEXEC
71415 + pax_mirror_file_pte(vma, addr, page, ptl);
71416 +#endif
71417 +
71418 retval = 0;
71419 pte_unmap_unlock(pte, ptl);
71420 return retval;
71421 @@ -2077,10 +2077,22 @@ out:
71422 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71423 struct page *page)
71424 {
71425 +
71426 +#ifdef CONFIG_PAX_SEGMEXEC
71427 + struct vm_area_struct *vma_m;
71428 +#endif
71429 +
71430 if (addr < vma->vm_start || addr >= vma->vm_end)
71431 return -EFAULT;
71432 if (!page_count(page))
71433 return -EINVAL;
71434 +
71435 +#ifdef CONFIG_PAX_SEGMEXEC
71436 + vma_m = pax_find_mirror_vma(vma);
71437 + if (vma_m)
71438 + vma_m->vm_flags |= VM_INSERTPAGE;
71439 +#endif
71440 +
71441 vma->vm_flags |= VM_INSERTPAGE;
71442 return insert_page(vma, addr, page, vma->vm_page_prot);
71443 }
71444 @@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71445 unsigned long pfn)
71446 {
71447 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71448 + BUG_ON(vma->vm_mirror);
71449
71450 if (addr < vma->vm_start || addr >= vma->vm_end)
71451 return -EFAULT;
71452 @@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71453
71454 BUG_ON(pud_huge(*pud));
71455
71456 - pmd = pmd_alloc(mm, pud, addr);
71457 + pmd = (mm == &init_mm) ?
71458 + pmd_alloc_kernel(mm, pud, addr) :
71459 + pmd_alloc(mm, pud, addr);
71460 if (!pmd)
71461 return -ENOMEM;
71462 do {
71463 @@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71464 unsigned long next;
71465 int err;
71466
71467 - pud = pud_alloc(mm, pgd, addr);
71468 + pud = (mm == &init_mm) ?
71469 + pud_alloc_kernel(mm, pgd, addr) :
71470 + pud_alloc(mm, pgd, addr);
71471 if (!pud)
71472 return -ENOMEM;
71473 do {
71474 @@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71475 copy_user_highpage(dst, src, va, vma);
71476 }
71477
71478 +#ifdef CONFIG_PAX_SEGMEXEC
71479 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71480 +{
71481 + struct mm_struct *mm = vma->vm_mm;
71482 + spinlock_t *ptl;
71483 + pte_t *pte, entry;
71484 +
71485 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71486 + entry = *pte;
71487 + if (!pte_present(entry)) {
71488 + if (!pte_none(entry)) {
71489 + BUG_ON(pte_file(entry));
71490 + free_swap_and_cache(pte_to_swp_entry(entry));
71491 + pte_clear_not_present_full(mm, address, pte, 0);
71492 + }
71493 + } else {
71494 + struct page *page;
71495 +
71496 + flush_cache_page(vma, address, pte_pfn(entry));
71497 + entry = ptep_clear_flush(vma, address, pte);
71498 + BUG_ON(pte_dirty(entry));
71499 + page = vm_normal_page(vma, address, entry);
71500 + if (page) {
71501 + update_hiwater_rss(mm);
71502 + if (PageAnon(page))
71503 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71504 + else
71505 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71506 + page_remove_rmap(page);
71507 + page_cache_release(page);
71508 + }
71509 + }
71510 + pte_unmap_unlock(pte, ptl);
71511 +}
71512 +
71513 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71514 + *
71515 + * the ptl of the lower mapped page is held on entry and is not released on exit
71516 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71517 + */
71518 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71519 +{
71520 + struct mm_struct *mm = vma->vm_mm;
71521 + unsigned long address_m;
71522 + spinlock_t *ptl_m;
71523 + struct vm_area_struct *vma_m;
71524 + pmd_t *pmd_m;
71525 + pte_t *pte_m, entry_m;
71526 +
71527 + BUG_ON(!page_m || !PageAnon(page_m));
71528 +
71529 + vma_m = pax_find_mirror_vma(vma);
71530 + if (!vma_m)
71531 + return;
71532 +
71533 + BUG_ON(!PageLocked(page_m));
71534 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71535 + address_m = address + SEGMEXEC_TASK_SIZE;
71536 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71537 + pte_m = pte_offset_map(pmd_m, address_m);
71538 + ptl_m = pte_lockptr(mm, pmd_m);
71539 + if (ptl != ptl_m) {
71540 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71541 + if (!pte_none(*pte_m))
71542 + goto out;
71543 + }
71544 +
71545 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71546 + page_cache_get(page_m);
71547 + page_add_anon_rmap(page_m, vma_m, address_m);
71548 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71549 + set_pte_at(mm, address_m, pte_m, entry_m);
71550 + update_mmu_cache(vma_m, address_m, entry_m);
71551 +out:
71552 + if (ptl != ptl_m)
71553 + spin_unlock(ptl_m);
71554 + pte_unmap(pte_m);
71555 + unlock_page(page_m);
71556 +}
71557 +
71558 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71559 +{
71560 + struct mm_struct *mm = vma->vm_mm;
71561 + unsigned long address_m;
71562 + spinlock_t *ptl_m;
71563 + struct vm_area_struct *vma_m;
71564 + pmd_t *pmd_m;
71565 + pte_t *pte_m, entry_m;
71566 +
71567 + BUG_ON(!page_m || PageAnon(page_m));
71568 +
71569 + vma_m = pax_find_mirror_vma(vma);
71570 + if (!vma_m)
71571 + return;
71572 +
71573 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71574 + address_m = address + SEGMEXEC_TASK_SIZE;
71575 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71576 + pte_m = pte_offset_map(pmd_m, address_m);
71577 + ptl_m = pte_lockptr(mm, pmd_m);
71578 + if (ptl != ptl_m) {
71579 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71580 + if (!pte_none(*pte_m))
71581 + goto out;
71582 + }
71583 +
71584 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71585 + page_cache_get(page_m);
71586 + page_add_file_rmap(page_m);
71587 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71588 + set_pte_at(mm, address_m, pte_m, entry_m);
71589 + update_mmu_cache(vma_m, address_m, entry_m);
71590 +out:
71591 + if (ptl != ptl_m)
71592 + spin_unlock(ptl_m);
71593 + pte_unmap(pte_m);
71594 +}
71595 +
71596 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71597 +{
71598 + struct mm_struct *mm = vma->vm_mm;
71599 + unsigned long address_m;
71600 + spinlock_t *ptl_m;
71601 + struct vm_area_struct *vma_m;
71602 + pmd_t *pmd_m;
71603 + pte_t *pte_m, entry_m;
71604 +
71605 + vma_m = pax_find_mirror_vma(vma);
71606 + if (!vma_m)
71607 + return;
71608 +
71609 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71610 + address_m = address + SEGMEXEC_TASK_SIZE;
71611 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71612 + pte_m = pte_offset_map(pmd_m, address_m);
71613 + ptl_m = pte_lockptr(mm, pmd_m);
71614 + if (ptl != ptl_m) {
71615 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71616 + if (!pte_none(*pte_m))
71617 + goto out;
71618 + }
71619 +
71620 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71621 + set_pte_at(mm, address_m, pte_m, entry_m);
71622 +out:
71623 + if (ptl != ptl_m)
71624 + spin_unlock(ptl_m);
71625 + pte_unmap(pte_m);
71626 +}
71627 +
71628 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71629 +{
71630 + struct page *page_m;
71631 + pte_t entry;
71632 +
71633 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71634 + goto out;
71635 +
71636 + entry = *pte;
71637 + page_m = vm_normal_page(vma, address, entry);
71638 + if (!page_m)
71639 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71640 + else if (PageAnon(page_m)) {
71641 + if (pax_find_mirror_vma(vma)) {
71642 + pte_unmap_unlock(pte, ptl);
71643 + lock_page(page_m);
71644 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71645 + if (pte_same(entry, *pte))
71646 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71647 + else
71648 + unlock_page(page_m);
71649 + }
71650 + } else
71651 + pax_mirror_file_pte(vma, address, page_m, ptl);
71652 +
71653 +out:
71654 + pte_unmap_unlock(pte, ptl);
71655 +}
71656 +#endif
71657 +
71658 /*
71659 * This routine handles present pages, when users try to write
71660 * to a shared page. It is done by copying the page to a new address
71661 @@ -2692,6 +2889,12 @@ gotten:
71662 */
71663 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71664 if (likely(pte_same(*page_table, orig_pte))) {
71665 +
71666 +#ifdef CONFIG_PAX_SEGMEXEC
71667 + if (pax_find_mirror_vma(vma))
71668 + BUG_ON(!trylock_page(new_page));
71669 +#endif
71670 +
71671 if (old_page) {
71672 if (!PageAnon(old_page)) {
71673 dec_mm_counter_fast(mm, MM_FILEPAGES);
71674 @@ -2743,6 +2946,10 @@ gotten:
71675 page_remove_rmap(old_page);
71676 }
71677
71678 +#ifdef CONFIG_PAX_SEGMEXEC
71679 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71680 +#endif
71681 +
71682 /* Free the old page.. */
71683 new_page = old_page;
71684 ret |= VM_FAULT_WRITE;
71685 @@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71686 swap_free(entry);
71687 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71688 try_to_free_swap(page);
71689 +
71690 +#ifdef CONFIG_PAX_SEGMEXEC
71691 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71692 +#endif
71693 +
71694 unlock_page(page);
71695 if (swapcache) {
71696 /*
71697 @@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71698
71699 /* No need to invalidate - it was non-present before */
71700 update_mmu_cache(vma, address, page_table);
71701 +
71702 +#ifdef CONFIG_PAX_SEGMEXEC
71703 + pax_mirror_anon_pte(vma, address, page, ptl);
71704 +#endif
71705 +
71706 unlock:
71707 pte_unmap_unlock(page_table, ptl);
71708 out:
71709 @@ -3064,40 +3281,6 @@ out_release:
71710 }
71711
71712 /*
71713 - * This is like a special single-page "expand_{down|up}wards()",
71714 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71715 - * doesn't hit another vma.
71716 - */
71717 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71718 -{
71719 - address &= PAGE_MASK;
71720 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71721 - struct vm_area_struct *prev = vma->vm_prev;
71722 -
71723 - /*
71724 - * Is there a mapping abutting this one below?
71725 - *
71726 - * That's only ok if it's the same stack mapping
71727 - * that has gotten split..
71728 - */
71729 - if (prev && prev->vm_end == address)
71730 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71731 -
71732 - expand_downwards(vma, address - PAGE_SIZE);
71733 - }
71734 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71735 - struct vm_area_struct *next = vma->vm_next;
71736 -
71737 - /* As VM_GROWSDOWN but s/below/above/ */
71738 - if (next && next->vm_start == address + PAGE_SIZE)
71739 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71740 -
71741 - expand_upwards(vma, address + PAGE_SIZE);
71742 - }
71743 - return 0;
71744 -}
71745 -
71746 -/*
71747 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71748 * but allow concurrent faults), and pte mapped but not yet locked.
71749 * We return with mmap_sem still held, but pte unmapped and unlocked.
71750 @@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71751 unsigned long address, pte_t *page_table, pmd_t *pmd,
71752 unsigned int flags)
71753 {
71754 - struct page *page;
71755 + struct page *page = NULL;
71756 spinlock_t *ptl;
71757 pte_t entry;
71758
71759 - pte_unmap(page_table);
71760 -
71761 - /* Check if we need to add a guard page to the stack */
71762 - if (check_stack_guard_page(vma, address) < 0)
71763 - return VM_FAULT_SIGBUS;
71764 -
71765 - /* Use the zero-page for reads */
71766 if (!(flags & FAULT_FLAG_WRITE)) {
71767 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71768 vma->vm_page_prot));
71769 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71770 + ptl = pte_lockptr(mm, pmd);
71771 + spin_lock(ptl);
71772 if (!pte_none(*page_table))
71773 goto unlock;
71774 goto setpte;
71775 }
71776
71777 /* Allocate our own private page. */
71778 + pte_unmap(page_table);
71779 +
71780 if (unlikely(anon_vma_prepare(vma)))
71781 goto oom;
71782 page = alloc_zeroed_user_highpage_movable(vma, address);
71783 @@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71784 if (!pte_none(*page_table))
71785 goto release;
71786
71787 +#ifdef CONFIG_PAX_SEGMEXEC
71788 + if (pax_find_mirror_vma(vma))
71789 + BUG_ON(!trylock_page(page));
71790 +#endif
71791 +
71792 inc_mm_counter_fast(mm, MM_ANONPAGES);
71793 page_add_new_anon_rmap(page, vma, address);
71794 setpte:
71795 @@ -3152,6 +3336,12 @@ setpte:
71796
71797 /* No need to invalidate - it was non-present before */
71798 update_mmu_cache(vma, address, page_table);
71799 +
71800 +#ifdef CONFIG_PAX_SEGMEXEC
71801 + if (page)
71802 + pax_mirror_anon_pte(vma, address, page, ptl);
71803 +#endif
71804 +
71805 unlock:
71806 pte_unmap_unlock(page_table, ptl);
71807 return 0;
71808 @@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71809 */
71810 /* Only go through if we didn't race with anybody else... */
71811 if (likely(pte_same(*page_table, orig_pte))) {
71812 +
71813 +#ifdef CONFIG_PAX_SEGMEXEC
71814 + if (anon && pax_find_mirror_vma(vma))
71815 + BUG_ON(!trylock_page(page));
71816 +#endif
71817 +
71818 flush_icache_page(vma, page);
71819 entry = mk_pte(page, vma->vm_page_prot);
71820 if (flags & FAULT_FLAG_WRITE)
71821 @@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71822
71823 /* no need to invalidate: a not-present page won't be cached */
71824 update_mmu_cache(vma, address, page_table);
71825 +
71826 +#ifdef CONFIG_PAX_SEGMEXEC
71827 + if (anon)
71828 + pax_mirror_anon_pte(vma, address, page, ptl);
71829 + else
71830 + pax_mirror_file_pte(vma, address, page, ptl);
71831 +#endif
71832 +
71833 } else {
71834 if (cow_page)
71835 mem_cgroup_uncharge_page(cow_page);
71836 @@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71837 if (flags & FAULT_FLAG_WRITE)
71838 flush_tlb_fix_spurious_fault(vma, address);
71839 }
71840 +
71841 +#ifdef CONFIG_PAX_SEGMEXEC
71842 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71843 + return 0;
71844 +#endif
71845 +
71846 unlock:
71847 pte_unmap_unlock(pte, ptl);
71848 return 0;
71849 @@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71850 pmd_t *pmd;
71851 pte_t *pte;
71852
71853 +#ifdef CONFIG_PAX_SEGMEXEC
71854 + struct vm_area_struct *vma_m;
71855 +#endif
71856 +
71857 __set_current_state(TASK_RUNNING);
71858
71859 count_vm_event(PGFAULT);
71860 @@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71861 if (unlikely(is_vm_hugetlb_page(vma)))
71862 return hugetlb_fault(mm, vma, address, flags);
71863
71864 +#ifdef CONFIG_PAX_SEGMEXEC
71865 + vma_m = pax_find_mirror_vma(vma);
71866 + if (vma_m) {
71867 + unsigned long address_m;
71868 + pgd_t *pgd_m;
71869 + pud_t *pud_m;
71870 + pmd_t *pmd_m;
71871 +
71872 + if (vma->vm_start > vma_m->vm_start) {
71873 + address_m = address;
71874 + address -= SEGMEXEC_TASK_SIZE;
71875 + vma = vma_m;
71876 + } else
71877 + address_m = address + SEGMEXEC_TASK_SIZE;
71878 +
71879 + pgd_m = pgd_offset(mm, address_m);
71880 + pud_m = pud_alloc(mm, pgd_m, address_m);
71881 + if (!pud_m)
71882 + return VM_FAULT_OOM;
71883 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71884 + if (!pmd_m)
71885 + return VM_FAULT_OOM;
71886 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71887 + return VM_FAULT_OOM;
71888 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71889 + }
71890 +#endif
71891 +
71892 retry:
71893 pgd = pgd_offset(mm, address);
71894 pud = pud_alloc(mm, pgd, address);
71895 @@ -3535,7 +3777,7 @@ retry:
71896 * run pte_offset_map on the pmd, if an huge pmd could
71897 * materialize from under us from a different thread.
71898 */
71899 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71900 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71901 return VM_FAULT_OOM;
71902 /* if an huge pmd materialized from under us just retry later */
71903 if (unlikely(pmd_trans_huge(*pmd)))
71904 @@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71905 spin_unlock(&mm->page_table_lock);
71906 return 0;
71907 }
71908 +
71909 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71910 +{
71911 + pud_t *new = pud_alloc_one(mm, address);
71912 + if (!new)
71913 + return -ENOMEM;
71914 +
71915 + smp_wmb(); /* See comment in __pte_alloc */
71916 +
71917 + spin_lock(&mm->page_table_lock);
71918 + if (pgd_present(*pgd)) /* Another has populated it */
71919 + pud_free(mm, new);
71920 + else
71921 + pgd_populate_kernel(mm, pgd, new);
71922 + spin_unlock(&mm->page_table_lock);
71923 + return 0;
71924 +}
71925 #endif /* __PAGETABLE_PUD_FOLDED */
71926
71927 #ifndef __PAGETABLE_PMD_FOLDED
71928 @@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71929 spin_unlock(&mm->page_table_lock);
71930 return 0;
71931 }
71932 +
71933 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71934 +{
71935 + pmd_t *new = pmd_alloc_one(mm, address);
71936 + if (!new)
71937 + return -ENOMEM;
71938 +
71939 + smp_wmb(); /* See comment in __pte_alloc */
71940 +
71941 + spin_lock(&mm->page_table_lock);
71942 +#ifndef __ARCH_HAS_4LEVEL_HACK
71943 + if (pud_present(*pud)) /* Another has populated it */
71944 + pmd_free(mm, new);
71945 + else
71946 + pud_populate_kernel(mm, pud, new);
71947 +#else
71948 + if (pgd_present(*pud)) /* Another has populated it */
71949 + pmd_free(mm, new);
71950 + else
71951 + pgd_populate_kernel(mm, pud, new);
71952 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71953 + spin_unlock(&mm->page_table_lock);
71954 + return 0;
71955 +}
71956 #endif /* __PAGETABLE_PMD_FOLDED */
71957
71958 int make_pages_present(unsigned long addr, unsigned long end)
71959 @@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71960 gate_vma.vm_start = FIXADDR_USER_START;
71961 gate_vma.vm_end = FIXADDR_USER_END;
71962 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71963 - gate_vma.vm_page_prot = __P101;
71964 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71965
71966 return 0;
71967 }
71968 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71969 index 1d771e4..64b57d0 100644
71970 --- a/mm/mempolicy.c
71971 +++ b/mm/mempolicy.c
71972 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71973 unsigned long vmstart;
71974 unsigned long vmend;
71975
71976 +#ifdef CONFIG_PAX_SEGMEXEC
71977 + struct vm_area_struct *vma_m;
71978 +#endif
71979 +
71980 vma = find_vma(mm, start);
71981 if (!vma || vma->vm_start > start)
71982 return -EFAULT;
71983 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71984 if (err)
71985 goto out;
71986 }
71987 +
71988 +#ifdef CONFIG_PAX_SEGMEXEC
71989 + vma_m = pax_find_mirror_vma(vma);
71990 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71991 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71992 + if (err)
71993 + goto out;
71994 + }
71995 +#endif
71996 +
71997 }
71998
71999 out:
72000 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72001
72002 if (end < start)
72003 return -EINVAL;
72004 +
72005 +#ifdef CONFIG_PAX_SEGMEXEC
72006 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72007 + if (end > SEGMEXEC_TASK_SIZE)
72008 + return -EINVAL;
72009 + } else
72010 +#endif
72011 +
72012 + if (end > TASK_SIZE)
72013 + return -EINVAL;
72014 +
72015 if (end == start)
72016 return 0;
72017
72018 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72019 */
72020 tcred = __task_cred(task);
72021 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72022 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72023 - !capable(CAP_SYS_NICE)) {
72024 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72025 rcu_read_unlock();
72026 err = -EPERM;
72027 goto out_put;
72028 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72029 goto out;
72030 }
72031
72032 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72033 + if (mm != current->mm &&
72034 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72035 + mmput(mm);
72036 + err = -EPERM;
72037 + goto out;
72038 + }
72039 +#endif
72040 +
72041 err = do_migrate_pages(mm, old, new,
72042 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72043
72044 @@ -2556,7 +2589,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
72045 break;
72046
72047 default:
72048 - BUG();
72049 + return -EINVAL;
72050 }
72051
72052 l = strlen(policy_modes[mode]);
72053 diff --git a/mm/mlock.c b/mm/mlock.c
72054 index ef726e8..cd7f1ec 100644
72055 --- a/mm/mlock.c
72056 +++ b/mm/mlock.c
72057 @@ -13,6 +13,7 @@
72058 #include <linux/pagemap.h>
72059 #include <linux/mempolicy.h>
72060 #include <linux/syscalls.h>
72061 +#include <linux/security.h>
72062 #include <linux/sched.h>
72063 #include <linux/export.h>
72064 #include <linux/rmap.h>
72065 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72066 {
72067 unsigned long nstart, end, tmp;
72068 struct vm_area_struct * vma, * prev;
72069 - int error;
72070 + int error = 0;
72071
72072 VM_BUG_ON(start & ~PAGE_MASK);
72073 VM_BUG_ON(len != PAGE_ALIGN(len));
72074 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72075 return -EINVAL;
72076 if (end == start)
72077 return 0;
72078 + if (end > TASK_SIZE)
72079 + return -EINVAL;
72080 +
72081 vma = find_vma(current->mm, start);
72082 if (!vma || vma->vm_start > start)
72083 return -ENOMEM;
72084 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72085 for (nstart = start ; ; ) {
72086 vm_flags_t newflags;
72087
72088 +#ifdef CONFIG_PAX_SEGMEXEC
72089 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72090 + break;
72091 +#endif
72092 +
72093 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72094
72095 newflags = vma->vm_flags | VM_LOCKED;
72096 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72097 lock_limit >>= PAGE_SHIFT;
72098
72099 /* check against resource limits */
72100 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72101 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72102 error = do_mlock(start, len, 1);
72103 up_write(&current->mm->mmap_sem);
72104 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72105 static int do_mlockall(int flags)
72106 {
72107 struct vm_area_struct * vma, * prev = NULL;
72108 - unsigned int def_flags = 0;
72109
72110 if (flags & MCL_FUTURE)
72111 - def_flags = VM_LOCKED;
72112 - current->mm->def_flags = def_flags;
72113 + current->mm->def_flags |= VM_LOCKED;
72114 + else
72115 + current->mm->def_flags &= ~VM_LOCKED;
72116 if (flags == MCL_FUTURE)
72117 goto out;
72118
72119 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72120 vm_flags_t newflags;
72121
72122 +#ifdef CONFIG_PAX_SEGMEXEC
72123 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72124 + break;
72125 +#endif
72126 +
72127 + BUG_ON(vma->vm_end > TASK_SIZE);
72128 newflags = vma->vm_flags | VM_LOCKED;
72129 if (!(flags & MCL_CURRENT))
72130 newflags &= ~VM_LOCKED;
72131 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72132 lock_limit >>= PAGE_SHIFT;
72133
72134 ret = -ENOMEM;
72135 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72136 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72137 capable(CAP_IPC_LOCK))
72138 ret = do_mlockall(flags);
72139 diff --git a/mm/mmap.c b/mm/mmap.c
72140 index 3edfcdf..4a27ae9 100644
72141 --- a/mm/mmap.c
72142 +++ b/mm/mmap.c
72143 @@ -47,6 +47,16 @@
72144 #define arch_rebalance_pgtables(addr, len) (addr)
72145 #endif
72146
72147 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72148 +{
72149 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72150 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72151 + up_read(&mm->mmap_sem);
72152 + BUG();
72153 + }
72154 +#endif
72155 +}
72156 +
72157 static void unmap_region(struct mm_struct *mm,
72158 struct vm_area_struct *vma, struct vm_area_struct *prev,
72159 unsigned long start, unsigned long end);
72160 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72161 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72162 *
72163 */
72164 -pgprot_t protection_map[16] = {
72165 +pgprot_t protection_map[16] __read_only = {
72166 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72167 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72168 };
72169
72170 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72171 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72172 {
72173 - return __pgprot(pgprot_val(protection_map[vm_flags &
72174 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72175 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72176 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72177 +
72178 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72179 + if (!(__supported_pte_mask & _PAGE_NX) &&
72180 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72181 + (vm_flags & (VM_READ | VM_WRITE)))
72182 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72183 +#endif
72184 +
72185 + return prot;
72186 }
72187 EXPORT_SYMBOL(vm_get_page_prot);
72188
72189 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72190 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72191 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72192 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72193 /*
72194 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72195 * other variables. It can be updated by several CPUs frequently.
72196 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72197 struct vm_area_struct *next = vma->vm_next;
72198
72199 might_sleep();
72200 + BUG_ON(vma->vm_mirror);
72201 if (vma->vm_ops && vma->vm_ops->close)
72202 vma->vm_ops->close(vma);
72203 if (vma->vm_file) {
72204 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72205 * not page aligned -Ram Gupta
72206 */
72207 rlim = rlimit(RLIMIT_DATA);
72208 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72209 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72210 (mm->end_data - mm->start_data) > rlim)
72211 goto out;
72212 @@ -708,6 +730,12 @@ static int
72213 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72214 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72215 {
72216 +
72217 +#ifdef CONFIG_PAX_SEGMEXEC
72218 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72219 + return 0;
72220 +#endif
72221 +
72222 if (is_mergeable_vma(vma, file, vm_flags) &&
72223 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72224 if (vma->vm_pgoff == vm_pgoff)
72225 @@ -727,6 +755,12 @@ static int
72226 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72227 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72228 {
72229 +
72230 +#ifdef CONFIG_PAX_SEGMEXEC
72231 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72232 + return 0;
72233 +#endif
72234 +
72235 if (is_mergeable_vma(vma, file, vm_flags) &&
72236 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72237 pgoff_t vm_pglen;
72238 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72239 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72240 struct vm_area_struct *prev, unsigned long addr,
72241 unsigned long end, unsigned long vm_flags,
72242 - struct anon_vma *anon_vma, struct file *file,
72243 + struct anon_vma *anon_vma, struct file *file,
72244 pgoff_t pgoff, struct mempolicy *policy)
72245 {
72246 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72247 struct vm_area_struct *area, *next;
72248 int err;
72249
72250 +#ifdef CONFIG_PAX_SEGMEXEC
72251 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72252 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72253 +
72254 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72255 +#endif
72256 +
72257 /*
72258 * We later require that vma->vm_flags == vm_flags,
72259 * so this tests vma->vm_flags & VM_SPECIAL, too.
72260 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72261 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72262 next = next->vm_next;
72263
72264 +#ifdef CONFIG_PAX_SEGMEXEC
72265 + if (prev)
72266 + prev_m = pax_find_mirror_vma(prev);
72267 + if (area)
72268 + area_m = pax_find_mirror_vma(area);
72269 + if (next)
72270 + next_m = pax_find_mirror_vma(next);
72271 +#endif
72272 +
72273 /*
72274 * Can it merge with the predecessor?
72275 */
72276 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72277 /* cases 1, 6 */
72278 err = vma_adjust(prev, prev->vm_start,
72279 next->vm_end, prev->vm_pgoff, NULL);
72280 - } else /* cases 2, 5, 7 */
72281 +
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + if (!err && prev_m)
72284 + err = vma_adjust(prev_m, prev_m->vm_start,
72285 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72286 +#endif
72287 +
72288 + } else { /* cases 2, 5, 7 */
72289 err = vma_adjust(prev, prev->vm_start,
72290 end, prev->vm_pgoff, NULL);
72291 +
72292 +#ifdef CONFIG_PAX_SEGMEXEC
72293 + if (!err && prev_m)
72294 + err = vma_adjust(prev_m, prev_m->vm_start,
72295 + end_m, prev_m->vm_pgoff, NULL);
72296 +#endif
72297 +
72298 + }
72299 if (err)
72300 return NULL;
72301 khugepaged_enter_vma_merge(prev);
72302 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72303 mpol_equal(policy, vma_policy(next)) &&
72304 can_vma_merge_before(next, vm_flags,
72305 anon_vma, file, pgoff+pglen)) {
72306 - if (prev && addr < prev->vm_end) /* case 4 */
72307 + if (prev && addr < prev->vm_end) { /* case 4 */
72308 err = vma_adjust(prev, prev->vm_start,
72309 addr, prev->vm_pgoff, NULL);
72310 - else /* cases 3, 8 */
72311 +
72312 +#ifdef CONFIG_PAX_SEGMEXEC
72313 + if (!err && prev_m)
72314 + err = vma_adjust(prev_m, prev_m->vm_start,
72315 + addr_m, prev_m->vm_pgoff, NULL);
72316 +#endif
72317 +
72318 + } else { /* cases 3, 8 */
72319 err = vma_adjust(area, addr, next->vm_end,
72320 next->vm_pgoff - pglen, NULL);
72321 +
72322 +#ifdef CONFIG_PAX_SEGMEXEC
72323 + if (!err && area_m)
72324 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72325 + next_m->vm_pgoff - pglen, NULL);
72326 +#endif
72327 +
72328 + }
72329 if (err)
72330 return NULL;
72331 khugepaged_enter_vma_merge(area);
72332 @@ -940,14 +1020,11 @@ none:
72333 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72334 struct file *file, long pages)
72335 {
72336 - const unsigned long stack_flags
72337 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72338 -
72339 if (file) {
72340 mm->shared_vm += pages;
72341 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72342 mm->exec_vm += pages;
72343 - } else if (flags & stack_flags)
72344 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72345 mm->stack_vm += pages;
72346 if (flags & (VM_RESERVED|VM_IO))
72347 mm->reserved_vm += pages;
72348 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72349 * (the exception is when the underlying filesystem is noexec
72350 * mounted, in which case we dont add PROT_EXEC.)
72351 */
72352 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72353 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72354 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72355 prot |= PROT_EXEC;
72356
72357 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72358 /* Obtain the address to map to. we verify (or select) it and ensure
72359 * that it represents a valid section of the address space.
72360 */
72361 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72362 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72363 if (addr & ~PAGE_MASK)
72364 return addr;
72365
72366 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72367 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72368 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72369
72370 +#ifdef CONFIG_PAX_MPROTECT
72371 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72372 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72373 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72374 + gr_log_rwxmmap(file);
72375 +
72376 +#ifdef CONFIG_PAX_EMUPLT
72377 + vm_flags &= ~VM_EXEC;
72378 +#else
72379 + return -EPERM;
72380 +#endif
72381 +
72382 + }
72383 +
72384 + if (!(vm_flags & VM_EXEC))
72385 + vm_flags &= ~VM_MAYEXEC;
72386 +#else
72387 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72388 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72389 +#endif
72390 + else
72391 + vm_flags &= ~VM_MAYWRITE;
72392 + }
72393 +#endif
72394 +
72395 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72396 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72397 + vm_flags &= ~VM_PAGEEXEC;
72398 +#endif
72399 +
72400 if (flags & MAP_LOCKED)
72401 if (!can_do_mlock())
72402 return -EPERM;
72403 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72404 locked += mm->locked_vm;
72405 lock_limit = rlimit(RLIMIT_MEMLOCK);
72406 lock_limit >>= PAGE_SHIFT;
72407 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72408 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72409 return -EAGAIN;
72410 }
72411 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72412 }
72413 }
72414
72415 + if (!gr_acl_handle_mmap(file, prot))
72416 + return -EACCES;
72417 +
72418 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72419 }
72420
72421 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72422 vm_flags_t vm_flags = vma->vm_flags;
72423
72424 /* If it was private or non-writable, the write bit is already clear */
72425 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72426 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72427 return 0;
72428
72429 /* The backer wishes to know when pages are first written to? */
72430 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72431 unsigned long charged = 0;
72432 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72433
72434 +#ifdef CONFIG_PAX_SEGMEXEC
72435 + struct vm_area_struct *vma_m = NULL;
72436 +#endif
72437 +
72438 + /*
72439 + * mm->mmap_sem is required to protect against another thread
72440 + * changing the mappings in case we sleep.
72441 + */
72442 + verify_mm_writelocked(mm);
72443 +
72444 /* Clear old maps */
72445 error = -ENOMEM;
72446 -munmap_back:
72447 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72448 if (vma && vma->vm_start < addr + len) {
72449 if (do_munmap(mm, addr, len))
72450 return -ENOMEM;
72451 - goto munmap_back;
72452 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72453 + BUG_ON(vma && vma->vm_start < addr + len);
72454 }
72455
72456 /* Check against address space limit. */
72457 @@ -1280,6 +1401,16 @@ munmap_back:
72458 goto unacct_error;
72459 }
72460
72461 +#ifdef CONFIG_PAX_SEGMEXEC
72462 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72463 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72464 + if (!vma_m) {
72465 + error = -ENOMEM;
72466 + goto free_vma;
72467 + }
72468 + }
72469 +#endif
72470 +
72471 vma->vm_mm = mm;
72472 vma->vm_start = addr;
72473 vma->vm_end = addr + len;
72474 @@ -1304,6 +1435,19 @@ munmap_back:
72475 error = file->f_op->mmap(file, vma);
72476 if (error)
72477 goto unmap_and_free_vma;
72478 +
72479 +#ifdef CONFIG_PAX_SEGMEXEC
72480 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72481 + added_exe_file_vma(mm);
72482 +#endif
72483 +
72484 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72485 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72486 + vma->vm_flags |= VM_PAGEEXEC;
72487 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72488 + }
72489 +#endif
72490 +
72491 if (vm_flags & VM_EXECUTABLE)
72492 added_exe_file_vma(mm);
72493
72494 @@ -1341,6 +1485,11 @@ munmap_back:
72495 vma_link(mm, vma, prev, rb_link, rb_parent);
72496 file = vma->vm_file;
72497
72498 +#ifdef CONFIG_PAX_SEGMEXEC
72499 + if (vma_m)
72500 + BUG_ON(pax_mirror_vma(vma_m, vma));
72501 +#endif
72502 +
72503 /* Once vma denies write, undo our temporary denial count */
72504 if (correct_wcount)
72505 atomic_inc(&inode->i_writecount);
72506 @@ -1349,6 +1498,7 @@ out:
72507
72508 mm->total_vm += len >> PAGE_SHIFT;
72509 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72510 + track_exec_limit(mm, addr, addr + len, vm_flags);
72511 if (vm_flags & VM_LOCKED) {
72512 if (!mlock_vma_pages_range(vma, addr, addr + len))
72513 mm->locked_vm += (len >> PAGE_SHIFT);
72514 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72515 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72516 charged = 0;
72517 free_vma:
72518 +
72519 +#ifdef CONFIG_PAX_SEGMEXEC
72520 + if (vma_m)
72521 + kmem_cache_free(vm_area_cachep, vma_m);
72522 +#endif
72523 +
72524 kmem_cache_free(vm_area_cachep, vma);
72525 unacct_error:
72526 if (charged)
72527 @@ -1378,6 +1534,44 @@ unacct_error:
72528 return error;
72529 }
72530
72531 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72532 +{
72533 + if (!vma) {
72534 +#ifdef CONFIG_STACK_GROWSUP
72535 + if (addr > sysctl_heap_stack_gap)
72536 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72537 + else
72538 + vma = find_vma(current->mm, 0);
72539 + if (vma && (vma->vm_flags & VM_GROWSUP))
72540 + return false;
72541 +#endif
72542 + return true;
72543 + }
72544 +
72545 + if (addr + len > vma->vm_start)
72546 + return false;
72547 +
72548 + if (vma->vm_flags & VM_GROWSDOWN)
72549 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72550 +#ifdef CONFIG_STACK_GROWSUP
72551 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72552 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72553 +#endif
72554 +
72555 + return true;
72556 +}
72557 +
72558 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72559 +{
72560 + if (vma->vm_start < len)
72561 + return -ENOMEM;
72562 + if (!(vma->vm_flags & VM_GROWSDOWN))
72563 + return vma->vm_start - len;
72564 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72565 + return vma->vm_start - len - sysctl_heap_stack_gap;
72566 + return -ENOMEM;
72567 +}
72568 +
72569 /* Get an address range which is currently unmapped.
72570 * For shmat() with addr=0.
72571 *
72572 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72573 if (flags & MAP_FIXED)
72574 return addr;
72575
72576 +#ifdef CONFIG_PAX_RANDMMAP
72577 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72578 +#endif
72579 +
72580 if (addr) {
72581 addr = PAGE_ALIGN(addr);
72582 - vma = find_vma(mm, addr);
72583 - if (TASK_SIZE - len >= addr &&
72584 - (!vma || addr + len <= vma->vm_start))
72585 - return addr;
72586 + if (TASK_SIZE - len >= addr) {
72587 + vma = find_vma(mm, addr);
72588 + if (check_heap_stack_gap(vma, addr, len))
72589 + return addr;
72590 + }
72591 }
72592 if (len > mm->cached_hole_size) {
72593 - start_addr = addr = mm->free_area_cache;
72594 + start_addr = addr = mm->free_area_cache;
72595 } else {
72596 - start_addr = addr = TASK_UNMAPPED_BASE;
72597 - mm->cached_hole_size = 0;
72598 + start_addr = addr = mm->mmap_base;
72599 + mm->cached_hole_size = 0;
72600 }
72601
72602 full_search:
72603 @@ -1426,34 +1625,40 @@ full_search:
72604 * Start a new search - just in case we missed
72605 * some holes.
72606 */
72607 - if (start_addr != TASK_UNMAPPED_BASE) {
72608 - addr = TASK_UNMAPPED_BASE;
72609 - start_addr = addr;
72610 + if (start_addr != mm->mmap_base) {
72611 + start_addr = addr = mm->mmap_base;
72612 mm->cached_hole_size = 0;
72613 goto full_search;
72614 }
72615 return -ENOMEM;
72616 }
72617 - if (!vma || addr + len <= vma->vm_start) {
72618 - /*
72619 - * Remember the place where we stopped the search:
72620 - */
72621 - mm->free_area_cache = addr + len;
72622 - return addr;
72623 - }
72624 + if (check_heap_stack_gap(vma, addr, len))
72625 + break;
72626 if (addr + mm->cached_hole_size < vma->vm_start)
72627 mm->cached_hole_size = vma->vm_start - addr;
72628 addr = vma->vm_end;
72629 }
72630 +
72631 + /*
72632 + * Remember the place where we stopped the search:
72633 + */
72634 + mm->free_area_cache = addr + len;
72635 + return addr;
72636 }
72637 #endif
72638
72639 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72640 {
72641 +
72642 +#ifdef CONFIG_PAX_SEGMEXEC
72643 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72644 + return;
72645 +#endif
72646 +
72647 /*
72648 * Is this a new hole at the lowest possible address?
72649 */
72650 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72651 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72652 mm->free_area_cache = addr;
72653 }
72654
72655 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72656 {
72657 struct vm_area_struct *vma;
72658 struct mm_struct *mm = current->mm;
72659 - unsigned long addr = addr0, start_addr;
72660 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72661
72662 /* requested length too big for entire address space */
72663 if (len > TASK_SIZE)
72664 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72665 if (flags & MAP_FIXED)
72666 return addr;
72667
72668 +#ifdef CONFIG_PAX_RANDMMAP
72669 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72670 +#endif
72671 +
72672 /* requesting a specific address */
72673 if (addr) {
72674 addr = PAGE_ALIGN(addr);
72675 - vma = find_vma(mm, addr);
72676 - if (TASK_SIZE - len >= addr &&
72677 - (!vma || addr + len <= vma->vm_start))
72678 - return addr;
72679 + if (TASK_SIZE - len >= addr) {
72680 + vma = find_vma(mm, addr);
72681 + if (check_heap_stack_gap(vma, addr, len))
72682 + return addr;
72683 + }
72684 }
72685
72686 /* check if free_area_cache is useful for us */
72687 @@ -1508,7 +1718,7 @@ try_again:
72688 * return with success:
72689 */
72690 vma = find_vma(mm, addr);
72691 - if (!vma || addr+len <= vma->vm_start)
72692 + if (check_heap_stack_gap(vma, addr, len))
72693 /* remember the address as a hint for next time */
72694 return (mm->free_area_cache = addr);
72695
72696 @@ -1517,8 +1727,8 @@ try_again:
72697 mm->cached_hole_size = vma->vm_start - addr;
72698
72699 /* try just below the current vma->vm_start */
72700 - addr = vma->vm_start-len;
72701 - } while (len < vma->vm_start);
72702 + addr = skip_heap_stack_gap(vma, len);
72703 + } while (!IS_ERR_VALUE(addr));
72704
72705 fail:
72706 /*
72707 @@ -1541,13 +1751,21 @@ fail:
72708 * can happen with large stack limits and large mmap()
72709 * allocations.
72710 */
72711 + mm->mmap_base = TASK_UNMAPPED_BASE;
72712 +
72713 +#ifdef CONFIG_PAX_RANDMMAP
72714 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72715 + mm->mmap_base += mm->delta_mmap;
72716 +#endif
72717 +
72718 + mm->free_area_cache = mm->mmap_base;
72719 mm->cached_hole_size = ~0UL;
72720 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72721 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72722 /*
72723 * Restore the topdown base:
72724 */
72725 - mm->free_area_cache = mm->mmap_base;
72726 + mm->mmap_base = base;
72727 + mm->free_area_cache = base;
72728 mm->cached_hole_size = ~0UL;
72729
72730 return addr;
72731 @@ -1556,6 +1774,12 @@ fail:
72732
72733 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72734 {
72735 +
72736 +#ifdef CONFIG_PAX_SEGMEXEC
72737 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72738 + return;
72739 +#endif
72740 +
72741 /*
72742 * Is this a new hole at the highest possible address?
72743 */
72744 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72745 mm->free_area_cache = addr;
72746
72747 /* dont allow allocations above current base */
72748 - if (mm->free_area_cache > mm->mmap_base)
72749 + if (mm->free_area_cache > mm->mmap_base) {
72750 mm->free_area_cache = mm->mmap_base;
72751 + mm->cached_hole_size = ~0UL;
72752 + }
72753 }
72754
72755 unsigned long
72756 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72757 return vma;
72758 }
72759
72760 +#ifdef CONFIG_PAX_SEGMEXEC
72761 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72762 +{
72763 + struct vm_area_struct *vma_m;
72764 +
72765 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72766 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72767 + BUG_ON(vma->vm_mirror);
72768 + return NULL;
72769 + }
72770 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72771 + vma_m = vma->vm_mirror;
72772 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72773 + BUG_ON(vma->vm_file != vma_m->vm_file);
72774 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72775 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72776 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72777 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72778 + return vma_m;
72779 +}
72780 +#endif
72781 +
72782 /*
72783 * Verify that the stack growth is acceptable and
72784 * update accounting. This is shared with both the
72785 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72786 return -ENOMEM;
72787
72788 /* Stack limit test */
72789 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72790 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72791 return -ENOMEM;
72792
72793 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72794 locked = mm->locked_vm + grow;
72795 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72796 limit >>= PAGE_SHIFT;
72797 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72798 if (locked > limit && !capable(CAP_IPC_LOCK))
72799 return -ENOMEM;
72800 }
72801 @@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72802 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72803 * vma is the last one with address > vma->vm_end. Have to extend vma.
72804 */
72805 +#ifndef CONFIG_IA64
72806 +static
72807 +#endif
72808 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72809 {
72810 int error;
72811 + bool locknext;
72812
72813 if (!(vma->vm_flags & VM_GROWSUP))
72814 return -EFAULT;
72815
72816 + /* Also guard against wrapping around to address 0. */
72817 + if (address < PAGE_ALIGN(address+1))
72818 + address = PAGE_ALIGN(address+1);
72819 + else
72820 + return -ENOMEM;
72821 +
72822 /*
72823 * We must make sure the anon_vma is allocated
72824 * so that the anon_vma locking is not a noop.
72825 */
72826 if (unlikely(anon_vma_prepare(vma)))
72827 return -ENOMEM;
72828 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72829 + if (locknext && anon_vma_prepare(vma->vm_next))
72830 + return -ENOMEM;
72831 vma_lock_anon_vma(vma);
72832 + if (locknext)
72833 + vma_lock_anon_vma(vma->vm_next);
72834
72835 /*
72836 * vma->vm_start/vm_end cannot change under us because the caller
72837 * is required to hold the mmap_sem in read mode. We need the
72838 - * anon_vma lock to serialize against concurrent expand_stacks.
72839 - * Also guard against wrapping around to address 0.
72840 + * anon_vma locks to serialize against concurrent expand_stacks
72841 + * and expand_upwards.
72842 */
72843 - if (address < PAGE_ALIGN(address+4))
72844 - address = PAGE_ALIGN(address+4);
72845 - else {
72846 - vma_unlock_anon_vma(vma);
72847 - return -ENOMEM;
72848 - }
72849 error = 0;
72850
72851 /* Somebody else might have raced and expanded it already */
72852 - if (address > vma->vm_end) {
72853 + 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)
72854 + error = -ENOMEM;
72855 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72856 unsigned long size, grow;
72857
72858 size = address - vma->vm_start;
72859 @@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72860 }
72861 }
72862 }
72863 + if (locknext)
72864 + vma_unlock_anon_vma(vma->vm_next);
72865 vma_unlock_anon_vma(vma);
72866 khugepaged_enter_vma_merge(vma);
72867 return error;
72868 @@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72869 unsigned long address)
72870 {
72871 int error;
72872 + bool lockprev = false;
72873 + struct vm_area_struct *prev;
72874
72875 /*
72876 * We must make sure the anon_vma is allocated
72877 @@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72878 if (error)
72879 return error;
72880
72881 + prev = vma->vm_prev;
72882 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72883 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72884 +#endif
72885 + if (lockprev && anon_vma_prepare(prev))
72886 + return -ENOMEM;
72887 + if (lockprev)
72888 + vma_lock_anon_vma(prev);
72889 +
72890 vma_lock_anon_vma(vma);
72891
72892 /*
72893 @@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72894 */
72895
72896 /* Somebody else might have raced and expanded it already */
72897 - if (address < vma->vm_start) {
72898 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72899 + error = -ENOMEM;
72900 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72901 unsigned long size, grow;
72902
72903 +#ifdef CONFIG_PAX_SEGMEXEC
72904 + struct vm_area_struct *vma_m;
72905 +
72906 + vma_m = pax_find_mirror_vma(vma);
72907 +#endif
72908 +
72909 size = vma->vm_end - address;
72910 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72911
72912 @@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72913 if (!error) {
72914 vma->vm_start = address;
72915 vma->vm_pgoff -= grow;
72916 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72917 +
72918 +#ifdef CONFIG_PAX_SEGMEXEC
72919 + if (vma_m) {
72920 + vma_m->vm_start -= grow << PAGE_SHIFT;
72921 + vma_m->vm_pgoff -= grow;
72922 + }
72923 +#endif
72924 +
72925 perf_event_mmap(vma);
72926 }
72927 }
72928 }
72929 vma_unlock_anon_vma(vma);
72930 + if (lockprev)
72931 + vma_unlock_anon_vma(prev);
72932 khugepaged_enter_vma_merge(vma);
72933 return error;
72934 }
72935 @@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72936 do {
72937 long nrpages = vma_pages(vma);
72938
72939 +#ifdef CONFIG_PAX_SEGMEXEC
72940 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72941 + vma = remove_vma(vma);
72942 + continue;
72943 + }
72944 +#endif
72945 +
72946 if (vma->vm_flags & VM_ACCOUNT)
72947 nr_accounted += nrpages;
72948 mm->total_vm -= nrpages;
72949 @@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72950 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72951 vma->vm_prev = NULL;
72952 do {
72953 +
72954 +#ifdef CONFIG_PAX_SEGMEXEC
72955 + if (vma->vm_mirror) {
72956 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72957 + vma->vm_mirror->vm_mirror = NULL;
72958 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72959 + vma->vm_mirror = NULL;
72960 + }
72961 +#endif
72962 +
72963 rb_erase(&vma->vm_rb, &mm->mm_rb);
72964 mm->map_count--;
72965 tail_vma = vma;
72966 @@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72967 struct vm_area_struct *new;
72968 int err = -ENOMEM;
72969
72970 +#ifdef CONFIG_PAX_SEGMEXEC
72971 + struct vm_area_struct *vma_m, *new_m = NULL;
72972 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72973 +#endif
72974 +
72975 if (is_vm_hugetlb_page(vma) && (addr &
72976 ~(huge_page_mask(hstate_vma(vma)))))
72977 return -EINVAL;
72978
72979 +#ifdef CONFIG_PAX_SEGMEXEC
72980 + vma_m = pax_find_mirror_vma(vma);
72981 +#endif
72982 +
72983 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72984 if (!new)
72985 goto out_err;
72986
72987 +#ifdef CONFIG_PAX_SEGMEXEC
72988 + if (vma_m) {
72989 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72990 + if (!new_m) {
72991 + kmem_cache_free(vm_area_cachep, new);
72992 + goto out_err;
72993 + }
72994 + }
72995 +#endif
72996 +
72997 /* most fields are the same, copy all, and then fixup */
72998 *new = *vma;
72999
73000 @@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73001 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73002 }
73003
73004 +#ifdef CONFIG_PAX_SEGMEXEC
73005 + if (vma_m) {
73006 + *new_m = *vma_m;
73007 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73008 + new_m->vm_mirror = new;
73009 + new->vm_mirror = new_m;
73010 +
73011 + if (new_below)
73012 + new_m->vm_end = addr_m;
73013 + else {
73014 + new_m->vm_start = addr_m;
73015 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73016 + }
73017 + }
73018 +#endif
73019 +
73020 pol = mpol_dup(vma_policy(vma));
73021 if (IS_ERR(pol)) {
73022 err = PTR_ERR(pol);
73023 @@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73024 else
73025 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73026
73027 +#ifdef CONFIG_PAX_SEGMEXEC
73028 + if (!err && vma_m) {
73029 + if (anon_vma_clone(new_m, vma_m))
73030 + goto out_free_mpol;
73031 +
73032 + mpol_get(pol);
73033 + vma_set_policy(new_m, pol);
73034 +
73035 + if (new_m->vm_file) {
73036 + get_file(new_m->vm_file);
73037 + if (vma_m->vm_flags & VM_EXECUTABLE)
73038 + added_exe_file_vma(mm);
73039 + }
73040 +
73041 + if (new_m->vm_ops && new_m->vm_ops->open)
73042 + new_m->vm_ops->open(new_m);
73043 +
73044 + if (new_below)
73045 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73046 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73047 + else
73048 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73049 +
73050 + if (err) {
73051 + if (new_m->vm_ops && new_m->vm_ops->close)
73052 + new_m->vm_ops->close(new_m);
73053 + if (new_m->vm_file) {
73054 + if (vma_m->vm_flags & VM_EXECUTABLE)
73055 + removed_exe_file_vma(mm);
73056 + fput(new_m->vm_file);
73057 + }
73058 + mpol_put(pol);
73059 + }
73060 + }
73061 +#endif
73062 +
73063 /* Success. */
73064 if (!err)
73065 return 0;
73066 @@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73067 removed_exe_file_vma(mm);
73068 fput(new->vm_file);
73069 }
73070 - unlink_anon_vmas(new);
73071 out_free_mpol:
73072 mpol_put(pol);
73073 out_free_vma:
73074 +
73075 +#ifdef CONFIG_PAX_SEGMEXEC
73076 + if (new_m) {
73077 + unlink_anon_vmas(new_m);
73078 + kmem_cache_free(vm_area_cachep, new_m);
73079 + }
73080 +#endif
73081 +
73082 + unlink_anon_vmas(new);
73083 kmem_cache_free(vm_area_cachep, new);
73084 out_err:
73085 return err;
73086 @@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73087 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73088 unsigned long addr, int new_below)
73089 {
73090 +
73091 +#ifdef CONFIG_PAX_SEGMEXEC
73092 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73093 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73094 + if (mm->map_count >= sysctl_max_map_count-1)
73095 + return -ENOMEM;
73096 + } else
73097 +#endif
73098 +
73099 if (mm->map_count >= sysctl_max_map_count)
73100 return -ENOMEM;
73101
73102 @@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73103 * work. This now handles partial unmappings.
73104 * Jeremy Fitzhardinge <jeremy@goop.org>
73105 */
73106 +#ifdef CONFIG_PAX_SEGMEXEC
73107 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73108 {
73109 + int ret = __do_munmap(mm, start, len);
73110 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73111 + return ret;
73112 +
73113 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73114 +}
73115 +
73116 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73117 +#else
73118 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73119 +#endif
73120 +{
73121 unsigned long end;
73122 struct vm_area_struct *vma, *prev, *last;
73123
73124 + /*
73125 + * mm->mmap_sem is required to protect against another thread
73126 + * changing the mappings in case we sleep.
73127 + */
73128 + verify_mm_writelocked(mm);
73129 +
73130 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73131 return -EINVAL;
73132
73133 @@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73134 /* Fix up all other VM information */
73135 remove_vma_list(mm, vma);
73136
73137 + track_exec_limit(mm, start, end, 0UL);
73138 +
73139 return 0;
73140 }
73141
73142 @@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
73143 int ret;
73144 struct mm_struct *mm = current->mm;
73145
73146 +
73147 +#ifdef CONFIG_PAX_SEGMEXEC
73148 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73149 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73150 + return -EINVAL;
73151 +#endif
73152 +
73153 down_write(&mm->mmap_sem);
73154 ret = do_munmap(mm, start, len);
73155 up_write(&mm->mmap_sem);
73156 @@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73157 return vm_munmap(addr, len);
73158 }
73159
73160 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73161 -{
73162 -#ifdef CONFIG_DEBUG_VM
73163 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73164 - WARN_ON(1);
73165 - up_read(&mm->mmap_sem);
73166 - }
73167 -#endif
73168 -}
73169 -
73170 /*
73171 * this is really a simplified "do_mmap". it only handles
73172 * anonymous maps. eventually we may be able to do some
73173 @@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73174 struct rb_node ** rb_link, * rb_parent;
73175 pgoff_t pgoff = addr >> PAGE_SHIFT;
73176 int error;
73177 + unsigned long charged;
73178
73179 len = PAGE_ALIGN(len);
73180 if (!len)
73181 @@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73182
73183 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73184
73185 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73186 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73187 + flags &= ~VM_EXEC;
73188 +
73189 +#ifdef CONFIG_PAX_MPROTECT
73190 + if (mm->pax_flags & MF_PAX_MPROTECT)
73191 + flags &= ~VM_MAYEXEC;
73192 +#endif
73193 +
73194 + }
73195 +#endif
73196 +
73197 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73198 if (error & ~PAGE_MASK)
73199 return error;
73200
73201 + charged = len >> PAGE_SHIFT;
73202 +
73203 /*
73204 * mlock MCL_FUTURE?
73205 */
73206 if (mm->def_flags & VM_LOCKED) {
73207 unsigned long locked, lock_limit;
73208 - locked = len >> PAGE_SHIFT;
73209 + locked = charged;
73210 locked += mm->locked_vm;
73211 lock_limit = rlimit(RLIMIT_MEMLOCK);
73212 lock_limit >>= PAGE_SHIFT;
73213 @@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73214 /*
73215 * Clear old maps. this also does some error checking for us
73216 */
73217 - munmap_back:
73218 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73219 if (vma && vma->vm_start < addr + len) {
73220 if (do_munmap(mm, addr, len))
73221 return -ENOMEM;
73222 - goto munmap_back;
73223 - }
73224 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73225 + BUG_ON(vma && vma->vm_start < addr + len);
73226 + }
73227
73228 /* Check against address space limits *after* clearing old maps... */
73229 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73230 + if (!may_expand_vm(mm, charged))
73231 return -ENOMEM;
73232
73233 if (mm->map_count > sysctl_max_map_count)
73234 return -ENOMEM;
73235
73236 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73237 + if (security_vm_enough_memory_mm(mm, charged))
73238 return -ENOMEM;
73239
73240 /* Can we just expand an old private anonymous mapping? */
73241 @@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73242 */
73243 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73244 if (!vma) {
73245 - vm_unacct_memory(len >> PAGE_SHIFT);
73246 + vm_unacct_memory(charged);
73247 return -ENOMEM;
73248 }
73249
73250 @@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73251 vma_link(mm, vma, prev, rb_link, rb_parent);
73252 out:
73253 perf_event_mmap(vma);
73254 - mm->total_vm += len >> PAGE_SHIFT;
73255 + mm->total_vm += charged;
73256 if (flags & VM_LOCKED) {
73257 if (!mlock_vma_pages_range(vma, addr, addr + len))
73258 - mm->locked_vm += (len >> PAGE_SHIFT);
73259 + mm->locked_vm += charged;
73260 }
73261 + track_exec_limit(mm, addr, addr + len, flags);
73262 return addr;
73263 }
73264
73265 @@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73266 while (vma) {
73267 if (vma->vm_flags & VM_ACCOUNT)
73268 nr_accounted += vma_pages(vma);
73269 + vma->vm_mirror = NULL;
73270 vma = remove_vma(vma);
73271 }
73272 vm_unacct_memory(nr_accounted);
73273 @@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73274 struct vm_area_struct * __vma, * prev;
73275 struct rb_node ** rb_link, * rb_parent;
73276
73277 +#ifdef CONFIG_PAX_SEGMEXEC
73278 + struct vm_area_struct *vma_m = NULL;
73279 +#endif
73280 +
73281 + if (security_mmap_addr(vma->vm_start))
73282 + return -EPERM;
73283 +
73284 /*
73285 * The vm_pgoff of a purely anonymous vma should be irrelevant
73286 * until its first write fault, when page's anon_vma and index
73287 @@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73288 if (vma->vm_file && uprobe_mmap(vma))
73289 return -EINVAL;
73290
73291 +#ifdef CONFIG_PAX_SEGMEXEC
73292 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73293 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73294 + if (!vma_m)
73295 + return -ENOMEM;
73296 + }
73297 +#endif
73298 +
73299 vma_link(mm, vma, prev, rb_link, rb_parent);
73300 +
73301 +#ifdef CONFIG_PAX_SEGMEXEC
73302 + if (vma_m)
73303 + BUG_ON(pax_mirror_vma(vma_m, vma));
73304 +#endif
73305 +
73306 return 0;
73307 }
73308
73309 @@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73310 struct mempolicy *pol;
73311 bool faulted_in_anon_vma = true;
73312
73313 + BUG_ON(vma->vm_mirror);
73314 +
73315 /*
73316 * If anonymous vma has not yet been faulted, update new pgoff
73317 * to match new location, to increase its chance of merging.
73318 @@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73319 return NULL;
73320 }
73321
73322 +#ifdef CONFIG_PAX_SEGMEXEC
73323 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73324 +{
73325 + struct vm_area_struct *prev_m;
73326 + struct rb_node **rb_link_m, *rb_parent_m;
73327 + struct mempolicy *pol_m;
73328 +
73329 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73330 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73331 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73332 + *vma_m = *vma;
73333 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73334 + if (anon_vma_clone(vma_m, vma))
73335 + return -ENOMEM;
73336 + pol_m = vma_policy(vma_m);
73337 + mpol_get(pol_m);
73338 + vma_set_policy(vma_m, pol_m);
73339 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73340 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73341 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73342 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73343 + if (vma_m->vm_file)
73344 + get_file(vma_m->vm_file);
73345 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73346 + vma_m->vm_ops->open(vma_m);
73347 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73348 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73349 + vma_m->vm_mirror = vma;
73350 + vma->vm_mirror = vma_m;
73351 + return 0;
73352 +}
73353 +#endif
73354 +
73355 /*
73356 * Return true if the calling process may expand its vm space by the passed
73357 * number of pages
73358 @@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73359
73360 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73361
73362 +#ifdef CONFIG_PAX_RANDMMAP
73363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73364 + cur -= mm->brk_gap;
73365 +#endif
73366 +
73367 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73368 if (cur + npages > lim)
73369 return 0;
73370 return 1;
73371 @@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73372 vma->vm_start = addr;
73373 vma->vm_end = addr + len;
73374
73375 +#ifdef CONFIG_PAX_MPROTECT
73376 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73377 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73378 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73379 + return -EPERM;
73380 + if (!(vm_flags & VM_EXEC))
73381 + vm_flags &= ~VM_MAYEXEC;
73382 +#else
73383 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73384 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73385 +#endif
73386 + else
73387 + vm_flags &= ~VM_MAYWRITE;
73388 + }
73389 +#endif
73390 +
73391 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73392 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73393
73394 diff --git a/mm/mprotect.c b/mm/mprotect.c
73395 index a409926..8b32e6d 100644
73396 --- a/mm/mprotect.c
73397 +++ b/mm/mprotect.c
73398 @@ -23,10 +23,17 @@
73399 #include <linux/mmu_notifier.h>
73400 #include <linux/migrate.h>
73401 #include <linux/perf_event.h>
73402 +
73403 +#ifdef CONFIG_PAX_MPROTECT
73404 +#include <linux/elf.h>
73405 +#include <linux/binfmts.h>
73406 +#endif
73407 +
73408 #include <asm/uaccess.h>
73409 #include <asm/pgtable.h>
73410 #include <asm/cacheflush.h>
73411 #include <asm/tlbflush.h>
73412 +#include <asm/mmu_context.h>
73413
73414 #ifndef pgprot_modify
73415 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73416 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73417 flush_tlb_range(vma, start, end);
73418 }
73419
73420 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73421 +/* called while holding the mmap semaphor for writing except stack expansion */
73422 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73423 +{
73424 + unsigned long oldlimit, newlimit = 0UL;
73425 +
73426 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73427 + return;
73428 +
73429 + spin_lock(&mm->page_table_lock);
73430 + oldlimit = mm->context.user_cs_limit;
73431 + if ((prot & VM_EXEC) && oldlimit < end)
73432 + /* USER_CS limit moved up */
73433 + newlimit = end;
73434 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73435 + /* USER_CS limit moved down */
73436 + newlimit = start;
73437 +
73438 + if (newlimit) {
73439 + mm->context.user_cs_limit = newlimit;
73440 +
73441 +#ifdef CONFIG_SMP
73442 + wmb();
73443 + cpus_clear(mm->context.cpu_user_cs_mask);
73444 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73445 +#endif
73446 +
73447 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73448 + }
73449 + spin_unlock(&mm->page_table_lock);
73450 + if (newlimit == end) {
73451 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73452 +
73453 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73454 + if (is_vm_hugetlb_page(vma))
73455 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73456 + else
73457 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73458 + }
73459 +}
73460 +#endif
73461 +
73462 int
73463 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73464 unsigned long start, unsigned long end, unsigned long newflags)
73465 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73466 int error;
73467 int dirty_accountable = 0;
73468
73469 +#ifdef CONFIG_PAX_SEGMEXEC
73470 + struct vm_area_struct *vma_m = NULL;
73471 + unsigned long start_m, end_m;
73472 +
73473 + start_m = start + SEGMEXEC_TASK_SIZE;
73474 + end_m = end + SEGMEXEC_TASK_SIZE;
73475 +#endif
73476 +
73477 if (newflags == oldflags) {
73478 *pprev = vma;
73479 return 0;
73480 }
73481
73482 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73483 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73484 +
73485 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73486 + return -ENOMEM;
73487 +
73488 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73489 + return -ENOMEM;
73490 + }
73491 +
73492 /*
73493 * If we make a private mapping writable we increase our commit;
73494 * but (without finer accounting) cannot reduce our commit if we
73495 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73496 }
73497 }
73498
73499 +#ifdef CONFIG_PAX_SEGMEXEC
73500 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73501 + if (start != vma->vm_start) {
73502 + error = split_vma(mm, vma, start, 1);
73503 + if (error)
73504 + goto fail;
73505 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73506 + *pprev = (*pprev)->vm_next;
73507 + }
73508 +
73509 + if (end != vma->vm_end) {
73510 + error = split_vma(mm, vma, end, 0);
73511 + if (error)
73512 + goto fail;
73513 + }
73514 +
73515 + if (pax_find_mirror_vma(vma)) {
73516 + error = __do_munmap(mm, start_m, end_m - start_m);
73517 + if (error)
73518 + goto fail;
73519 + } else {
73520 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73521 + if (!vma_m) {
73522 + error = -ENOMEM;
73523 + goto fail;
73524 + }
73525 + vma->vm_flags = newflags;
73526 + error = pax_mirror_vma(vma_m, vma);
73527 + if (error) {
73528 + vma->vm_flags = oldflags;
73529 + goto fail;
73530 + }
73531 + }
73532 + }
73533 +#endif
73534 +
73535 /*
73536 * First try to merge with previous and/or next vma.
73537 */
73538 @@ -204,9 +307,21 @@ success:
73539 * vm_flags and vm_page_prot are protected by the mmap_sem
73540 * held in write mode.
73541 */
73542 +
73543 +#ifdef CONFIG_PAX_SEGMEXEC
73544 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73545 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73546 +#endif
73547 +
73548 vma->vm_flags = newflags;
73549 +
73550 +#ifdef CONFIG_PAX_MPROTECT
73551 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73552 + mm->binfmt->handle_mprotect(vma, newflags);
73553 +#endif
73554 +
73555 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73556 - vm_get_page_prot(newflags));
73557 + vm_get_page_prot(vma->vm_flags));
73558
73559 if (vma_wants_writenotify(vma)) {
73560 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73561 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73562 end = start + len;
73563 if (end <= start)
73564 return -ENOMEM;
73565 +
73566 +#ifdef CONFIG_PAX_SEGMEXEC
73567 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73568 + if (end > SEGMEXEC_TASK_SIZE)
73569 + return -EINVAL;
73570 + } else
73571 +#endif
73572 +
73573 + if (end > TASK_SIZE)
73574 + return -EINVAL;
73575 +
73576 if (!arch_validate_prot(prot))
73577 return -EINVAL;
73578
73579 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73580 /*
73581 * Does the application expect PROT_READ to imply PROT_EXEC:
73582 */
73583 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73584 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73585 prot |= PROT_EXEC;
73586
73587 vm_flags = calc_vm_prot_bits(prot);
73588 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73589 if (start > vma->vm_start)
73590 prev = vma;
73591
73592 +#ifdef CONFIG_PAX_MPROTECT
73593 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73594 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73595 +#endif
73596 +
73597 for (nstart = start ; ; ) {
73598 unsigned long newflags;
73599
73600 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73601
73602 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73603 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73604 + if (prot & (PROT_WRITE | PROT_EXEC))
73605 + gr_log_rwxmprotect(vma->vm_file);
73606 +
73607 + error = -EACCES;
73608 + goto out;
73609 + }
73610 +
73611 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73612 error = -EACCES;
73613 goto out;
73614 }
73615 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73616 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73617 if (error)
73618 goto out;
73619 +
73620 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73621 +
73622 nstart = tmp;
73623
73624 if (nstart < prev->vm_end)
73625 diff --git a/mm/mremap.c b/mm/mremap.c
73626 index 21fed20..6822658 100644
73627 --- a/mm/mremap.c
73628 +++ b/mm/mremap.c
73629 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73630 continue;
73631 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73632 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73633 +
73634 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73635 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73636 + pte = pte_exprotect(pte);
73637 +#endif
73638 +
73639 set_pte_at(mm, new_addr, new_pte, pte);
73640 }
73641
73642 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73643 if (is_vm_hugetlb_page(vma))
73644 goto Einval;
73645
73646 +#ifdef CONFIG_PAX_SEGMEXEC
73647 + if (pax_find_mirror_vma(vma))
73648 + goto Einval;
73649 +#endif
73650 +
73651 /* We can't remap across vm area boundaries */
73652 if (old_len > vma->vm_end - addr)
73653 goto Efault;
73654 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73655 unsigned long ret = -EINVAL;
73656 unsigned long charged = 0;
73657 unsigned long map_flags;
73658 + unsigned long pax_task_size = TASK_SIZE;
73659
73660 if (new_addr & ~PAGE_MASK)
73661 goto out;
73662
73663 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73664 +#ifdef CONFIG_PAX_SEGMEXEC
73665 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73666 + pax_task_size = SEGMEXEC_TASK_SIZE;
73667 +#endif
73668 +
73669 + pax_task_size -= PAGE_SIZE;
73670 +
73671 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73672 goto out;
73673
73674 /* Check if the location we're moving into overlaps the
73675 * old location at all, and fail if it does.
73676 */
73677 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73678 - goto out;
73679 -
73680 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73681 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73682 goto out;
73683
73684 ret = do_munmap(mm, new_addr, new_len);
73685 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73686 struct vm_area_struct *vma;
73687 unsigned long ret = -EINVAL;
73688 unsigned long charged = 0;
73689 + unsigned long pax_task_size = TASK_SIZE;
73690
73691 down_write(&current->mm->mmap_sem);
73692
73693 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73694 if (!new_len)
73695 goto out;
73696
73697 +#ifdef CONFIG_PAX_SEGMEXEC
73698 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73699 + pax_task_size = SEGMEXEC_TASK_SIZE;
73700 +#endif
73701 +
73702 + pax_task_size -= PAGE_SIZE;
73703 +
73704 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73705 + old_len > pax_task_size || addr > pax_task_size-old_len)
73706 + goto out;
73707 +
73708 if (flags & MREMAP_FIXED) {
73709 if (flags & MREMAP_MAYMOVE)
73710 ret = mremap_to(addr, old_len, new_addr, new_len);
73711 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73712 addr + new_len);
73713 }
73714 ret = addr;
73715 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73716 goto out;
73717 }
73718 }
73719 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73720 goto out;
73721 }
73722
73723 + map_flags = vma->vm_flags;
73724 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73725 + if (!(ret & ~PAGE_MASK)) {
73726 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73727 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73728 + }
73729 }
73730 out:
73731 if (ret & ~PAGE_MASK)
73732 diff --git a/mm/nommu.c b/mm/nommu.c
73733 index d4b0c10..ed421b5 100644
73734 --- a/mm/nommu.c
73735 +++ b/mm/nommu.c
73736 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73737 int sysctl_overcommit_ratio = 50; /* default is 50% */
73738 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73739 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73740 -int heap_stack_gap = 0;
73741
73742 atomic_long_t mmap_pages_allocated;
73743
73744 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73745 EXPORT_SYMBOL(find_vma);
73746
73747 /*
73748 - * find a VMA
73749 - * - we don't extend stack VMAs under NOMMU conditions
73750 - */
73751 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73752 -{
73753 - return find_vma(mm, addr);
73754 -}
73755 -
73756 -/*
73757 * expand a stack to a given address
73758 * - not supported under NOMMU conditions
73759 */
73760 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73761
73762 /* most fields are the same, copy all, and then fixup */
73763 *new = *vma;
73764 + INIT_LIST_HEAD(&new->anon_vma_chain);
73765 *region = *vma->vm_region;
73766 new->vm_region = region;
73767
73768 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73769 index 201b508..1fb51ca 100644
73770 --- a/mm/page_alloc.c
73771 +++ b/mm/page_alloc.c
73772 @@ -336,7 +336,7 @@ out:
73773 * This usage means that zero-order pages may not be compound.
73774 */
73775
73776 -static void free_compound_page(struct page *page)
73777 +void free_compound_page(struct page *page)
73778 {
73779 __free_pages_ok(page, compound_order(page));
73780 }
73781 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73782 int i;
73783 int bad = 0;
73784
73785 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73786 + unsigned long index = 1UL << order;
73787 +#endif
73788 +
73789 trace_mm_page_free(page, order);
73790 kmemcheck_free_shadow(page, order);
73791
73792 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73793 debug_check_no_obj_freed(page_address(page),
73794 PAGE_SIZE << order);
73795 }
73796 +
73797 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73798 + for (; index; --index)
73799 + sanitize_highpage(page + index - 1);
73800 +#endif
73801 +
73802 arch_free_page(page, order);
73803 kernel_map_pages(page, 1 << order, 0);
73804
73805 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73806 arch_alloc_page(page, order);
73807 kernel_map_pages(page, 1 << order, 1);
73808
73809 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73810 if (gfp_flags & __GFP_ZERO)
73811 prep_zero_page(page, order, gfp_flags);
73812 +#endif
73813
73814 if (order && (gfp_flags & __GFP_COMP))
73815 prep_compound_page(page, order);
73816 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73817 unsigned long pfn;
73818
73819 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73820 +#ifdef CONFIG_X86_32
73821 + /* boot failures in VMware 8 on 32bit vanilla since
73822 + this change */
73823 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73824 +#else
73825 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73826 +#endif
73827 return 1;
73828 }
73829 return 0;
73830 diff --git a/mm/percpu.c b/mm/percpu.c
73831 index bb4be74..a43ea85 100644
73832 --- a/mm/percpu.c
73833 +++ b/mm/percpu.c
73834 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73835 static unsigned int pcpu_high_unit_cpu __read_mostly;
73836
73837 /* the address of the first chunk which starts with the kernel static area */
73838 -void *pcpu_base_addr __read_mostly;
73839 +void *pcpu_base_addr __read_only;
73840 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73841
73842 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73843 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73844 index 926b466..b23df53 100644
73845 --- a/mm/process_vm_access.c
73846 +++ b/mm/process_vm_access.c
73847 @@ -13,6 +13,7 @@
73848 #include <linux/uio.h>
73849 #include <linux/sched.h>
73850 #include <linux/highmem.h>
73851 +#include <linux/security.h>
73852 #include <linux/ptrace.h>
73853 #include <linux/slab.h>
73854 #include <linux/syscalls.h>
73855 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73856 size_t iov_l_curr_offset = 0;
73857 ssize_t iov_len;
73858
73859 + return -ENOSYS; // PaX: until properly audited
73860 +
73861 /*
73862 * Work out how many pages of struct pages we're going to need
73863 * when eventually calling get_user_pages
73864 */
73865 for (i = 0; i < riovcnt; i++) {
73866 iov_len = rvec[i].iov_len;
73867 - if (iov_len > 0) {
73868 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73869 - + iov_len)
73870 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73871 - / PAGE_SIZE + 1;
73872 - nr_pages = max(nr_pages, nr_pages_iov);
73873 - }
73874 + if (iov_len <= 0)
73875 + continue;
73876 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73877 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73878 + nr_pages = max(nr_pages, nr_pages_iov);
73879 }
73880
73881 if (nr_pages == 0)
73882 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73883 goto free_proc_pages;
73884 }
73885
73886 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73887 + rc = -EPERM;
73888 + goto put_task_struct;
73889 + }
73890 +
73891 mm = mm_access(task, PTRACE_MODE_ATTACH);
73892 if (!mm || IS_ERR(mm)) {
73893 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73894 diff --git a/mm/rmap.c b/mm/rmap.c
73895 index 0f3b7cd..c5652b6 100644
73896 --- a/mm/rmap.c
73897 +++ b/mm/rmap.c
73898 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73899 struct anon_vma *anon_vma = vma->anon_vma;
73900 struct anon_vma_chain *avc;
73901
73902 +#ifdef CONFIG_PAX_SEGMEXEC
73903 + struct anon_vma_chain *avc_m = NULL;
73904 +#endif
73905 +
73906 might_sleep();
73907 if (unlikely(!anon_vma)) {
73908 struct mm_struct *mm = vma->vm_mm;
73909 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73910 if (!avc)
73911 goto out_enomem;
73912
73913 +#ifdef CONFIG_PAX_SEGMEXEC
73914 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73915 + if (!avc_m)
73916 + goto out_enomem_free_avc;
73917 +#endif
73918 +
73919 anon_vma = find_mergeable_anon_vma(vma);
73920 allocated = NULL;
73921 if (!anon_vma) {
73922 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73923 /* page_table_lock to protect against threads */
73924 spin_lock(&mm->page_table_lock);
73925 if (likely(!vma->anon_vma)) {
73926 +
73927 +#ifdef CONFIG_PAX_SEGMEXEC
73928 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73929 +
73930 + if (vma_m) {
73931 + BUG_ON(vma_m->anon_vma);
73932 + vma_m->anon_vma = anon_vma;
73933 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
73934 + avc_m = NULL;
73935 + }
73936 +#endif
73937 +
73938 vma->anon_vma = anon_vma;
73939 anon_vma_chain_link(vma, avc, anon_vma);
73940 allocated = NULL;
73941 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73942
73943 if (unlikely(allocated))
73944 put_anon_vma(allocated);
73945 +
73946 +#ifdef CONFIG_PAX_SEGMEXEC
73947 + if (unlikely(avc_m))
73948 + anon_vma_chain_free(avc_m);
73949 +#endif
73950 +
73951 if (unlikely(avc))
73952 anon_vma_chain_free(avc);
73953 }
73954 return 0;
73955
73956 out_enomem_free_avc:
73957 +
73958 +#ifdef CONFIG_PAX_SEGMEXEC
73959 + if (avc_m)
73960 + anon_vma_chain_free(avc_m);
73961 +#endif
73962 +
73963 anon_vma_chain_free(avc);
73964 out_enomem:
73965 return -ENOMEM;
73966 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73967 * Attach the anon_vmas from src to dst.
73968 * Returns 0 on success, -ENOMEM on failure.
73969 */
73970 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73971 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73972 {
73973 struct anon_vma_chain *avc, *pavc;
73974 struct anon_vma *root = NULL;
73975 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73976 * the corresponding VMA in the parent process is attached to.
73977 * Returns 0 on success, non-zero on failure.
73978 */
73979 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73980 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73981 {
73982 struct anon_vma_chain *avc;
73983 struct anon_vma *anon_vma;
73984 diff --git a/mm/shmem.c b/mm/shmem.c
73985 index bd10636..5c16d49 100644
73986 --- a/mm/shmem.c
73987 +++ b/mm/shmem.c
73988 @@ -31,7 +31,7 @@
73989 #include <linux/export.h>
73990 #include <linux/swap.h>
73991
73992 -static struct vfsmount *shm_mnt;
73993 +struct vfsmount *shm_mnt;
73994
73995 #ifdef CONFIG_SHMEM
73996 /*
73997 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73998 #define BOGO_DIRENT_SIZE 20
73999
74000 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74001 -#define SHORT_SYMLINK_LEN 128
74002 +#define SHORT_SYMLINK_LEN 64
74003
74004 struct shmem_xattr {
74005 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74006 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74007 int err = -ENOMEM;
74008
74009 /* Round up to L1_CACHE_BYTES to resist false sharing */
74010 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74011 - L1_CACHE_BYTES), GFP_KERNEL);
74012 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74013 if (!sbinfo)
74014 return -ENOMEM;
74015
74016 diff --git a/mm/slab.c b/mm/slab.c
74017 index e901a36..9ff3f90 100644
74018 --- a/mm/slab.c
74019 +++ b/mm/slab.c
74020 @@ -153,7 +153,7 @@
74021
74022 /* Legal flag mask for kmem_cache_create(). */
74023 #if DEBUG
74024 -# define CREATE_MASK (SLAB_RED_ZONE | \
74025 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74026 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74027 SLAB_CACHE_DMA | \
74028 SLAB_STORE_USER | \
74029 @@ -161,7 +161,7 @@
74030 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74031 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74032 #else
74033 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74034 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74035 SLAB_CACHE_DMA | \
74036 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74037 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74038 @@ -290,7 +290,7 @@ struct kmem_list3 {
74039 * Need this for bootstrapping a per node allocator.
74040 */
74041 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74042 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74043 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74044 #define CACHE_CACHE 0
74045 #define SIZE_AC MAX_NUMNODES
74046 #define SIZE_L3 (2 * MAX_NUMNODES)
74047 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74048 if ((x)->max_freeable < i) \
74049 (x)->max_freeable = i; \
74050 } while (0)
74051 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74052 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74053 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74054 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74055 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74056 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74057 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74058 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74059 #else
74060 #define STATS_INC_ACTIVE(x) do { } while (0)
74061 #define STATS_DEC_ACTIVE(x) do { } while (0)
74062 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74063 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74064 */
74065 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74066 - const struct slab *slab, void *obj)
74067 + const struct slab *slab, const void *obj)
74068 {
74069 u32 offset = (obj - slab->s_mem);
74070 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74071 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
74072 struct cache_names {
74073 char *name;
74074 char *name_dma;
74075 + char *name_usercopy;
74076 };
74077
74078 static struct cache_names __initdata cache_names[] = {
74079 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74080 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74081 #include <linux/kmalloc_sizes.h>
74082 - {NULL,}
74083 + {NULL}
74084 #undef CACHE
74085 };
74086
74087 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74088 if (unlikely(gfpflags & GFP_DMA))
74089 return csizep->cs_dmacachep;
74090 #endif
74091 +
74092 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74093 + if (unlikely(gfpflags & GFP_USERCOPY))
74094 + return csizep->cs_usercopycachep;
74095 +#endif
74096 +
74097 return csizep->cs_cachep;
74098 }
74099
74100 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
74101 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74102 sizes[INDEX_AC].cs_size,
74103 ARCH_KMALLOC_MINALIGN,
74104 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74105 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74106 NULL);
74107
74108 if (INDEX_AC != INDEX_L3) {
74109 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
74110 kmem_cache_create(names[INDEX_L3].name,
74111 sizes[INDEX_L3].cs_size,
74112 ARCH_KMALLOC_MINALIGN,
74113 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74114 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74115 NULL);
74116 }
74117
74118 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
74119 sizes->cs_cachep = kmem_cache_create(names->name,
74120 sizes->cs_size,
74121 ARCH_KMALLOC_MINALIGN,
74122 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74123 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74124 NULL);
74125 }
74126 #ifdef CONFIG_ZONE_DMA
74127 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
74128 SLAB_PANIC,
74129 NULL);
74130 #endif
74131 +
74132 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74133 + sizes->cs_usercopycachep = kmem_cache_create(
74134 + names->name_usercopy,
74135 + sizes->cs_size,
74136 + ARCH_KMALLOC_MINALIGN,
74137 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74138 + NULL);
74139 +#endif
74140 +
74141 sizes++;
74142 names++;
74143 }
74144 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74145 }
74146 /* cpu stats */
74147 {
74148 - unsigned long allochit = atomic_read(&cachep->allochit);
74149 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74150 - unsigned long freehit = atomic_read(&cachep->freehit);
74151 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74152 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74153 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74154 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74155 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74156
74157 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74158 allochit, allocmiss, freehit, freemiss);
74159 @@ -4652,13 +4669,71 @@ static int __init slab_proc_init(void)
74160 {
74161 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74162 #ifdef CONFIG_DEBUG_SLAB_LEAK
74163 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74164 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74165 #endif
74166 return 0;
74167 }
74168 module_init(slab_proc_init);
74169 #endif
74170
74171 +bool is_usercopy_object(const void *ptr)
74172 +{
74173 + struct page *page;
74174 + struct kmem_cache *cachep;
74175 +
74176 + if (ZERO_OR_NULL_PTR(ptr))
74177 + return false;
74178 +
74179 + if (!slab_is_available())
74180 + return false;
74181 +
74182 + if (!virt_addr_valid(ptr))
74183 + return false;
74184 +
74185 + page = virt_to_head_page(ptr);
74186 +
74187 + if (!PageSlab(page))
74188 + return false;
74189 +
74190 + cachep = page_get_cache(page);
74191 + return cachep->flags & SLAB_USERCOPY;
74192 +}
74193 +
74194 +#ifdef CONFIG_PAX_USERCOPY
74195 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74196 +{
74197 + struct page *page;
74198 + struct kmem_cache *cachep;
74199 + struct slab *slabp;
74200 + unsigned int objnr;
74201 + unsigned long offset;
74202 +
74203 + if (ZERO_OR_NULL_PTR(ptr))
74204 + return "<null>";
74205 +
74206 + if (!virt_addr_valid(ptr))
74207 + return NULL;
74208 +
74209 + page = virt_to_head_page(ptr);
74210 +
74211 + if (!PageSlab(page))
74212 + return NULL;
74213 +
74214 + cachep = page_get_cache(page);
74215 + if (!(cachep->flags & SLAB_USERCOPY))
74216 + return cachep->name;
74217 +
74218 + slabp = page_get_slab(page);
74219 + objnr = obj_to_index(cachep, slabp, ptr);
74220 + BUG_ON(objnr >= cachep->num);
74221 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74222 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74223 + return NULL;
74224 +
74225 + return cachep->name;
74226 +}
74227 +#endif
74228 +
74229 /**
74230 * ksize - get the actual amount of memory allocated for a given object
74231 * @objp: Pointer to the object
74232 diff --git a/mm/slob.c b/mm/slob.c
74233 index 8105be4..3e3e9cd 100644
74234 --- a/mm/slob.c
74235 +++ b/mm/slob.c
74236 @@ -29,7 +29,7 @@
74237 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74238 * alloc_pages() directly, allocating compound pages so the page order
74239 * does not have to be separately tracked, and also stores the exact
74240 - * allocation size in page->private so that it can be used to accurately
74241 + * allocation size in slob_page->size so that it can be used to accurately
74242 * provide ksize(). These objects are detected in kfree() because slob_page()
74243 * is false for them.
74244 *
74245 @@ -58,6 +58,7 @@
74246 */
74247
74248 #include <linux/kernel.h>
74249 +#include <linux/sched.h>
74250 #include <linux/slab.h>
74251 #include <linux/mm.h>
74252 #include <linux/swap.h> /* struct reclaim_state */
74253 @@ -102,7 +103,8 @@ struct slob_page {
74254 unsigned long flags; /* mandatory */
74255 atomic_t _count; /* mandatory */
74256 slobidx_t units; /* free units left in page */
74257 - unsigned long pad[2];
74258 + unsigned long pad[1];
74259 + unsigned long size; /* size when >=PAGE_SIZE */
74260 slob_t *free; /* first free slob_t in page */
74261 struct list_head list; /* linked list of free pages */
74262 };
74263 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74264 */
74265 static inline int is_slob_page(struct slob_page *sp)
74266 {
74267 - return PageSlab((struct page *)sp);
74268 + return PageSlab((struct page *)sp) && !sp->size;
74269 }
74270
74271 static inline void set_slob_page(struct slob_page *sp)
74272 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74273
74274 static inline struct slob_page *slob_page(const void *addr)
74275 {
74276 - return (struct slob_page *)virt_to_page(addr);
74277 + return (struct slob_page *)virt_to_head_page(addr);
74278 }
74279
74280 /*
74281 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74282 /*
74283 * Return the size of a slob block.
74284 */
74285 -static slobidx_t slob_units(slob_t *s)
74286 +static slobidx_t slob_units(const slob_t *s)
74287 {
74288 if (s->units > 0)
74289 return s->units;
74290 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74291 /*
74292 * Return the next free slob block pointer after this one.
74293 */
74294 -static slob_t *slob_next(slob_t *s)
74295 +static slob_t *slob_next(const slob_t *s)
74296 {
74297 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74298 slobidx_t next;
74299 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74300 /*
74301 * Returns true if s is the last free block in its page.
74302 */
74303 -static int slob_last(slob_t *s)
74304 +static int slob_last(const slob_t *s)
74305 {
74306 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74307 }
74308 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74309 if (!page)
74310 return NULL;
74311
74312 + set_slob_page(page);
74313 return page_address(page);
74314 }
74315
74316 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74317 if (!b)
74318 return NULL;
74319 sp = slob_page(b);
74320 - set_slob_page(sp);
74321
74322 spin_lock_irqsave(&slob_lock, flags);
74323 sp->units = SLOB_UNITS(PAGE_SIZE);
74324 sp->free = b;
74325 + sp->size = 0;
74326 INIT_LIST_HEAD(&sp->list);
74327 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74328 set_slob_page_free(sp, slob_list);
74329 @@ -476,10 +479,9 @@ out:
74330 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74331 */
74332
74333 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74334 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74335 {
74336 - unsigned int *m;
74337 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74338 + slob_t *m;
74339 void *ret;
74340
74341 gfp &= gfp_allowed_mask;
74342 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74343
74344 if (!m)
74345 return NULL;
74346 - *m = size;
74347 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74348 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74349 + m[0].units = size;
74350 + m[1].units = align;
74351 ret = (void *)m + align;
74352
74353 trace_kmalloc_node(_RET_IP_, ret,
74354 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74355 gfp |= __GFP_COMP;
74356 ret = slob_new_pages(gfp, order, node);
74357 if (ret) {
74358 - struct page *page;
74359 - page = virt_to_page(ret);
74360 - page->private = size;
74361 + struct slob_page *sp;
74362 + sp = slob_page(ret);
74363 + sp->size = size;
74364 }
74365
74366 trace_kmalloc_node(_RET_IP_, ret,
74367 size, PAGE_SIZE << order, gfp, node);
74368 }
74369
74370 - kmemleak_alloc(ret, size, 1, gfp);
74371 + return ret;
74372 +}
74373 +
74374 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74375 +{
74376 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74377 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74378 +
74379 + if (!ZERO_OR_NULL_PTR(ret))
74380 + kmemleak_alloc(ret, size, 1, gfp);
74381 return ret;
74382 }
74383 EXPORT_SYMBOL(__kmalloc_node);
74384 @@ -533,13 +547,88 @@ void kfree(const void *block)
74385 sp = slob_page(block);
74386 if (is_slob_page(sp)) {
74387 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74388 - unsigned int *m = (unsigned int *)(block - align);
74389 - slob_free(m, *m + align);
74390 - } else
74391 + slob_t *m = (slob_t *)(block - align);
74392 + slob_free(m, m[0].units + align);
74393 + } else {
74394 + clear_slob_page(sp);
74395 + free_slob_page(sp);
74396 + sp->size = 0;
74397 put_page(&sp->page);
74398 + }
74399 }
74400 EXPORT_SYMBOL(kfree);
74401
74402 +bool is_usercopy_object(const void *ptr)
74403 +{
74404 + if (!slab_is_available())
74405 + return false;
74406 +
74407 + // PAX: TODO
74408 +
74409 + return false;
74410 +}
74411 +
74412 +#ifdef CONFIG_PAX_USERCOPY
74413 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74414 +{
74415 + struct slob_page *sp;
74416 + const slob_t *free;
74417 + const void *base;
74418 + unsigned long flags;
74419 +
74420 + if (ZERO_OR_NULL_PTR(ptr))
74421 + return "<null>";
74422 +
74423 + if (!virt_addr_valid(ptr))
74424 + return NULL;
74425 +
74426 + sp = slob_page(ptr);
74427 + if (!PageSlab((struct page *)sp))
74428 + return NULL;
74429 +
74430 + if (sp->size) {
74431 + base = page_address(&sp->page);
74432 + if (base <= ptr && n <= sp->size - (ptr - base))
74433 + return NULL;
74434 + return "<slob>";
74435 + }
74436 +
74437 + /* some tricky double walking to find the chunk */
74438 + spin_lock_irqsave(&slob_lock, flags);
74439 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74440 + free = sp->free;
74441 +
74442 + while (!slob_last(free) && (void *)free <= ptr) {
74443 + base = free + slob_units(free);
74444 + free = slob_next(free);
74445 + }
74446 +
74447 + while (base < (void *)free) {
74448 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74449 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74450 + int offset;
74451 +
74452 + if (ptr < base + align)
74453 + break;
74454 +
74455 + offset = ptr - base - align;
74456 + if (offset >= m) {
74457 + base += size;
74458 + continue;
74459 + }
74460 +
74461 + if (n > m - offset)
74462 + break;
74463 +
74464 + spin_unlock_irqrestore(&slob_lock, flags);
74465 + return NULL;
74466 + }
74467 +
74468 + spin_unlock_irqrestore(&slob_lock, flags);
74469 + return "<slob>";
74470 +}
74471 +#endif
74472 +
74473 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74474 size_t ksize(const void *block)
74475 {
74476 @@ -552,10 +641,10 @@ size_t ksize(const void *block)
74477 sp = slob_page(block);
74478 if (is_slob_page(sp)) {
74479 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74480 - unsigned int *m = (unsigned int *)(block - align);
74481 - return SLOB_UNITS(*m) * SLOB_UNIT;
74482 + slob_t *m = (slob_t *)(block - align);
74483 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74484 } else
74485 - return sp->page.private;
74486 + return sp->size;
74487 }
74488 EXPORT_SYMBOL(ksize);
74489
74490 @@ -571,8 +660,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74491 {
74492 struct kmem_cache *c;
74493
74494 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74495 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74496 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74497 +#else
74498 c = slob_alloc(sizeof(struct kmem_cache),
74499 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74500 +#endif
74501
74502 if (c) {
74503 c->name = name;
74504 @@ -614,17 +708,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74505
74506 lockdep_trace_alloc(flags);
74507
74508 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74509 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74510 +#else
74511 if (c->size < PAGE_SIZE) {
74512 b = slob_alloc(c->size, flags, c->align, node);
74513 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74514 SLOB_UNITS(c->size) * SLOB_UNIT,
74515 flags, node);
74516 } else {
74517 + struct slob_page *sp;
74518 +
74519 b = slob_new_pages(flags, get_order(c->size), node);
74520 + sp = slob_page(b);
74521 + sp->size = c->size;
74522 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74523 PAGE_SIZE << get_order(c->size),
74524 flags, node);
74525 }
74526 +#endif
74527
74528 if (c->ctor)
74529 c->ctor(b);
74530 @@ -636,10 +738,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74531
74532 static void __kmem_cache_free(void *b, int size)
74533 {
74534 - if (size < PAGE_SIZE)
74535 + struct slob_page *sp = slob_page(b);
74536 +
74537 + if (is_slob_page(sp))
74538 slob_free(b, size);
74539 - else
74540 + else {
74541 + clear_slob_page(sp);
74542 + free_slob_page(sp);
74543 + sp->size = 0;
74544 slob_free_pages(b, get_order(size));
74545 + }
74546 }
74547
74548 static void kmem_rcu_free(struct rcu_head *head)
74549 @@ -652,17 +760,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74550
74551 void kmem_cache_free(struct kmem_cache *c, void *b)
74552 {
74553 + int size = c->size;
74554 +
74555 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74556 + if (size + c->align < PAGE_SIZE) {
74557 + size += c->align;
74558 + b -= c->align;
74559 + }
74560 +#endif
74561 +
74562 kmemleak_free_recursive(b, c->flags);
74563 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74564 struct slob_rcu *slob_rcu;
74565 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74566 - slob_rcu->size = c->size;
74567 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74568 + slob_rcu->size = size;
74569 call_rcu(&slob_rcu->head, kmem_rcu_free);
74570 } else {
74571 - __kmem_cache_free(b, c->size);
74572 + __kmem_cache_free(b, size);
74573 }
74574
74575 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74576 + trace_kfree(_RET_IP_, b);
74577 +#else
74578 trace_kmem_cache_free(_RET_IP_, b);
74579 +#endif
74580 +
74581 }
74582 EXPORT_SYMBOL(kmem_cache_free);
74583
74584 diff --git a/mm/slub.c b/mm/slub.c
74585 index 8c691fa..2993c2b 100644
74586 --- a/mm/slub.c
74587 +++ b/mm/slub.c
74588 @@ -209,7 +209,7 @@ struct track {
74589
74590 enum track_item { TRACK_ALLOC, TRACK_FREE };
74591
74592 -#ifdef CONFIG_SYSFS
74593 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74594 static int sysfs_slab_add(struct kmem_cache *);
74595 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74596 static void sysfs_slab_remove(struct kmem_cache *);
74597 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74598 if (!t->addr)
74599 return;
74600
74601 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74602 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74603 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74604 #ifdef CONFIG_STACKTRACE
74605 {
74606 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74607
74608 page = virt_to_head_page(x);
74609
74610 + BUG_ON(!PageSlab(page));
74611 +
74612 slab_free(s, page, x, _RET_IP_);
74613
74614 trace_kmem_cache_free(_RET_IP_, x);
74615 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
74616 * Merge control. If this is set then no merging of slab caches will occur.
74617 * (Could be removed. This was introduced to pacify the merge skeptics.)
74618 */
74619 -static int slub_nomerge;
74620 +static int slub_nomerge = 1;
74621
74622 /*
74623 * Calculate the order of allocation given an slab object size.
74624 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74625 else
74626 s->cpu_partial = 30;
74627
74628 - s->refcount = 1;
74629 + atomic_set(&s->refcount, 1);
74630 #ifdef CONFIG_NUMA
74631 s->remote_node_defrag_ratio = 1000;
74632 #endif
74633 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74634 void kmem_cache_destroy(struct kmem_cache *s)
74635 {
74636 down_write(&slub_lock);
74637 - s->refcount--;
74638 - if (!s->refcount) {
74639 + if (atomic_dec_and_test(&s->refcount)) {
74640 list_del(&s->list);
74641 up_write(&slub_lock);
74642 if (kmem_cache_close(s)) {
74643 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74644 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74645 #endif
74646
74647 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74648 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74649 +#endif
74650 +
74651 static int __init setup_slub_min_order(char *str)
74652 {
74653 get_option(&str, &slub_min_order);
74654 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74655 return kmalloc_dma_caches[index];
74656
74657 #endif
74658 +
74659 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74660 + if (flags & SLAB_USERCOPY)
74661 + return kmalloc_usercopy_caches[index];
74662 +
74663 +#endif
74664 +
74665 return kmalloc_caches[index];
74666 }
74667
74668 @@ -3405,6 +3417,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74669 EXPORT_SYMBOL(__kmalloc_node);
74670 #endif
74671
74672 +bool is_usercopy_object(const void *ptr)
74673 +{
74674 + struct page *page;
74675 + struct kmem_cache *s;
74676 +
74677 + if (ZERO_OR_NULL_PTR(ptr))
74678 + return false;
74679 +
74680 + if (!slab_is_available())
74681 + return false;
74682 +
74683 + if (!virt_addr_valid(ptr))
74684 + return false;
74685 +
74686 + page = virt_to_head_page(ptr);
74687 +
74688 + if (!PageSlab(page))
74689 + return false;
74690 +
74691 + s = page->slab;
74692 + return s->flags & SLAB_USERCOPY;
74693 +}
74694 +
74695 +#ifdef CONFIG_PAX_USERCOPY
74696 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74697 +{
74698 + struct page *page;
74699 + struct kmem_cache *s;
74700 + unsigned long offset;
74701 +
74702 + if (ZERO_OR_NULL_PTR(ptr))
74703 + return "<null>";
74704 +
74705 + if (!virt_addr_valid(ptr))
74706 + return NULL;
74707 +
74708 + page = virt_to_head_page(ptr);
74709 +
74710 + if (!PageSlab(page))
74711 + return NULL;
74712 +
74713 + s = page->slab;
74714 + if (!(s->flags & SLAB_USERCOPY))
74715 + return s->name;
74716 +
74717 + offset = (ptr - page_address(page)) % s->size;
74718 + if (offset <= s->objsize && n <= s->objsize - offset)
74719 + return NULL;
74720 +
74721 + return s->name;
74722 +}
74723 +#endif
74724 +
74725 size_t ksize(const void *object)
74726 {
74727 struct page *page;
74728 @@ -3679,7 +3744,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74729 int node;
74730
74731 list_add(&s->list, &slab_caches);
74732 - s->refcount = -1;
74733 + atomic_set(&s->refcount, -1);
74734
74735 for_each_node_state(node, N_NORMAL_MEMORY) {
74736 struct kmem_cache_node *n = get_node(s, node);
74737 @@ -3799,17 +3864,17 @@ void __init kmem_cache_init(void)
74738
74739 /* Caches that are not of the two-to-the-power-of size */
74740 if (KMALLOC_MIN_SIZE <= 32) {
74741 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74742 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74743 caches++;
74744 }
74745
74746 if (KMALLOC_MIN_SIZE <= 64) {
74747 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74748 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74749 caches++;
74750 }
74751
74752 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74753 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74754 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74755 caches++;
74756 }
74757
74758 @@ -3851,6 +3916,22 @@ void __init kmem_cache_init(void)
74759 }
74760 }
74761 #endif
74762 +
74763 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74764 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74765 + struct kmem_cache *s = kmalloc_caches[i];
74766 +
74767 + if (s && s->size) {
74768 + char *name = kasprintf(GFP_NOWAIT,
74769 + "usercopy-kmalloc-%d", s->objsize);
74770 +
74771 + BUG_ON(!name);
74772 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74773 + s->objsize, SLAB_USERCOPY);
74774 + }
74775 + }
74776 +#endif
74777 +
74778 printk(KERN_INFO
74779 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74780 " CPUs=%d, Nodes=%d\n",
74781 @@ -3877,7 +3958,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74782 /*
74783 * We may have set a slab to be unmergeable during bootstrap.
74784 */
74785 - if (s->refcount < 0)
74786 + if (atomic_read(&s->refcount) < 0)
74787 return 1;
74788
74789 return 0;
74790 @@ -3936,7 +4017,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74791 down_write(&slub_lock);
74792 s = find_mergeable(size, align, flags, name, ctor);
74793 if (s) {
74794 - s->refcount++;
74795 + atomic_inc(&s->refcount);
74796 /*
74797 * Adjust the object sizes so that we clear
74798 * the complete object on kzalloc.
74799 @@ -3945,7 +4026,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74800 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74801
74802 if (sysfs_slab_alias(s, name)) {
74803 - s->refcount--;
74804 + atomic_dec(&s->refcount);
74805 goto err;
74806 }
74807 up_write(&slub_lock);
74808 @@ -4074,7 +4155,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74809 }
74810 #endif
74811
74812 -#ifdef CONFIG_SYSFS
74813 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74814 static int count_inuse(struct page *page)
74815 {
74816 return page->inuse;
74817 @@ -4461,12 +4542,12 @@ static void resiliency_test(void)
74818 validate_slab_cache(kmalloc_caches[9]);
74819 }
74820 #else
74821 -#ifdef CONFIG_SYSFS
74822 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74823 static void resiliency_test(void) {};
74824 #endif
74825 #endif
74826
74827 -#ifdef CONFIG_SYSFS
74828 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74829 enum slab_stat_type {
74830 SL_ALL, /* All slabs */
74831 SL_PARTIAL, /* Only partially allocated slabs */
74832 @@ -4709,7 +4790,7 @@ SLAB_ATTR_RO(ctor);
74833
74834 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74835 {
74836 - return sprintf(buf, "%d\n", s->refcount - 1);
74837 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74838 }
74839 SLAB_ATTR_RO(aliases);
74840
74841 @@ -5280,6 +5361,7 @@ static char *create_unique_id(struct kmem_cache *s)
74842 return name;
74843 }
74844
74845 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74846 static int sysfs_slab_add(struct kmem_cache *s)
74847 {
74848 int err;
74849 @@ -5342,6 +5424,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74850 kobject_del(&s->kobj);
74851 kobject_put(&s->kobj);
74852 }
74853 +#endif
74854
74855 /*
74856 * Need to buffer aliases during bootup until sysfs becomes
74857 @@ -5355,6 +5438,7 @@ struct saved_alias {
74858
74859 static struct saved_alias *alias_list;
74860
74861 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74862 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74863 {
74864 struct saved_alias *al;
74865 @@ -5377,6 +5461,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74866 alias_list = al;
74867 return 0;
74868 }
74869 +#endif
74870
74871 static int __init slab_sysfs_init(void)
74872 {
74873 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74874 index 1b7e22a..3fcd4f3 100644
74875 --- a/mm/sparse-vmemmap.c
74876 +++ b/mm/sparse-vmemmap.c
74877 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74878 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74879 if (!p)
74880 return NULL;
74881 - pud_populate(&init_mm, pud, p);
74882 + pud_populate_kernel(&init_mm, pud, p);
74883 }
74884 return pud;
74885 }
74886 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74887 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74888 if (!p)
74889 return NULL;
74890 - pgd_populate(&init_mm, pgd, p);
74891 + pgd_populate_kernel(&init_mm, pgd, p);
74892 }
74893 return pgd;
74894 }
74895 diff --git a/mm/swap.c b/mm/swap.c
74896 index 4e7e2ec..0c57830 100644
74897 --- a/mm/swap.c
74898 +++ b/mm/swap.c
74899 @@ -30,6 +30,7 @@
74900 #include <linux/backing-dev.h>
74901 #include <linux/memcontrol.h>
74902 #include <linux/gfp.h>
74903 +#include <linux/hugetlb.h>
74904
74905 #include "internal.h"
74906
74907 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74908
74909 __page_cache_release(page);
74910 dtor = get_compound_page_dtor(page);
74911 + if (!PageHuge(page))
74912 + BUG_ON(dtor != free_compound_page);
74913 (*dtor)(page);
74914 }
74915
74916 diff --git a/mm/swapfile.c b/mm/swapfile.c
74917 index 71373d0..11fa7d9 100644
74918 --- a/mm/swapfile.c
74919 +++ b/mm/swapfile.c
74920 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74921
74922 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74923 /* Activity counter to indicate that a swapon or swapoff has occurred */
74924 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74925 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74926
74927 static inline unsigned char swap_count(unsigned char ent)
74928 {
74929 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74930 }
74931 filp_close(swap_file, NULL);
74932 err = 0;
74933 - atomic_inc(&proc_poll_event);
74934 + atomic_inc_unchecked(&proc_poll_event);
74935 wake_up_interruptible(&proc_poll_wait);
74936
74937 out_dput:
74938 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74939
74940 poll_wait(file, &proc_poll_wait, wait);
74941
74942 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74943 - seq->poll_event = atomic_read(&proc_poll_event);
74944 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74945 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74946 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74947 }
74948
74949 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74950 return ret;
74951
74952 seq = file->private_data;
74953 - seq->poll_event = atomic_read(&proc_poll_event);
74954 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74955 return 0;
74956 }
74957
74958 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74959 (frontswap_map) ? "FS" : "");
74960
74961 mutex_unlock(&swapon_mutex);
74962 - atomic_inc(&proc_poll_event);
74963 + atomic_inc_unchecked(&proc_poll_event);
74964 wake_up_interruptible(&proc_poll_wait);
74965
74966 if (S_ISREG(inode->i_mode))
74967 diff --git a/mm/util.c b/mm/util.c
74968 index 8c7265a..c96d884 100644
74969 --- a/mm/util.c
74970 +++ b/mm/util.c
74971 @@ -285,6 +285,12 @@ done:
74972 void arch_pick_mmap_layout(struct mm_struct *mm)
74973 {
74974 mm->mmap_base = TASK_UNMAPPED_BASE;
74975 +
74976 +#ifdef CONFIG_PAX_RANDMMAP
74977 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74978 + mm->mmap_base += mm->delta_mmap;
74979 +#endif
74980 +
74981 mm->get_unmapped_area = arch_get_unmapped_area;
74982 mm->unmap_area = arch_unmap_area;
74983 }
74984 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74985 index 2aad499..4006a74 100644
74986 --- a/mm/vmalloc.c
74987 +++ b/mm/vmalloc.c
74988 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74989
74990 pte = pte_offset_kernel(pmd, addr);
74991 do {
74992 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74993 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74994 +
74995 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74996 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74997 + BUG_ON(!pte_exec(*pte));
74998 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74999 + continue;
75000 + }
75001 +#endif
75002 +
75003 + {
75004 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75005 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75006 + }
75007 } while (pte++, addr += PAGE_SIZE, addr != end);
75008 }
75009
75010 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75011 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75012 {
75013 pte_t *pte;
75014 + int ret = -ENOMEM;
75015
75016 /*
75017 * nr is a running index into the array which helps higher level
75018 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75019 pte = pte_alloc_kernel(pmd, addr);
75020 if (!pte)
75021 return -ENOMEM;
75022 +
75023 + pax_open_kernel();
75024 do {
75025 struct page *page = pages[*nr];
75026
75027 - if (WARN_ON(!pte_none(*pte)))
75028 - return -EBUSY;
75029 - if (WARN_ON(!page))
75030 - return -ENOMEM;
75031 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75032 + if (pgprot_val(prot) & _PAGE_NX)
75033 +#endif
75034 +
75035 + if (WARN_ON(!pte_none(*pte))) {
75036 + ret = -EBUSY;
75037 + goto out;
75038 + }
75039 + if (WARN_ON(!page)) {
75040 + ret = -ENOMEM;
75041 + goto out;
75042 + }
75043 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75044 (*nr)++;
75045 } while (pte++, addr += PAGE_SIZE, addr != end);
75046 - return 0;
75047 + ret = 0;
75048 +out:
75049 + pax_close_kernel();
75050 + return ret;
75051 }
75052
75053 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75054 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75055 pmd_t *pmd;
75056 unsigned long next;
75057
75058 - pmd = pmd_alloc(&init_mm, pud, addr);
75059 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75060 if (!pmd)
75061 return -ENOMEM;
75062 do {
75063 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75064 pud_t *pud;
75065 unsigned long next;
75066
75067 - pud = pud_alloc(&init_mm, pgd, addr);
75068 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75069 if (!pud)
75070 return -ENOMEM;
75071 do {
75072 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75073 * and fall back on vmalloc() if that fails. Others
75074 * just put it in the vmalloc space.
75075 */
75076 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75077 +#ifdef CONFIG_MODULES
75078 +#ifdef MODULES_VADDR
75079 unsigned long addr = (unsigned long)x;
75080 if (addr >= MODULES_VADDR && addr < MODULES_END)
75081 return 1;
75082 #endif
75083 +
75084 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75085 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75086 + return 1;
75087 +#endif
75088 +
75089 +#endif
75090 +
75091 return is_vmalloc_addr(x);
75092 }
75093
75094 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75095
75096 if (!pgd_none(*pgd)) {
75097 pud_t *pud = pud_offset(pgd, addr);
75098 +#ifdef CONFIG_X86
75099 + if (!pud_large(*pud))
75100 +#endif
75101 if (!pud_none(*pud)) {
75102 pmd_t *pmd = pmd_offset(pud, addr);
75103 +#ifdef CONFIG_X86
75104 + if (!pmd_large(*pmd))
75105 +#endif
75106 if (!pmd_none(*pmd)) {
75107 pte_t *ptep, pte;
75108
75109 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75110 * Allocate a region of KVA of the specified size and alignment, within the
75111 * vstart and vend.
75112 */
75113 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75114 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75115 unsigned long align,
75116 unsigned long vstart, unsigned long vend,
75117 int node, gfp_t gfp_mask)
75118 @@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75119 struct vm_struct *area;
75120
75121 BUG_ON(in_interrupt());
75122 +
75123 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75124 + if (flags & VM_KERNEXEC) {
75125 + if (start != VMALLOC_START || end != VMALLOC_END)
75126 + return NULL;
75127 + start = (unsigned long)MODULES_EXEC_VADDR;
75128 + end = (unsigned long)MODULES_EXEC_END;
75129 + }
75130 +#endif
75131 +
75132 if (flags & VM_IOREMAP) {
75133 int bit = fls(size);
75134
75135 @@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
75136 if (count > totalram_pages)
75137 return NULL;
75138
75139 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75140 + if (!(pgprot_val(prot) & _PAGE_NX))
75141 + flags |= VM_KERNEXEC;
75142 +#endif
75143 +
75144 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75145 __builtin_return_address(0));
75146 if (!area)
75147 @@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75148 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75149 goto fail;
75150
75151 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75152 + if (!(pgprot_val(prot) & _PAGE_NX))
75153 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75154 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75155 + else
75156 +#endif
75157 +
75158 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75159 start, end, node, gfp_mask, caller);
75160 if (!area)
75161 @@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75162 * For tight control over page level allocator and protection flags
75163 * use __vmalloc() instead.
75164 */
75165 -
75166 void *vmalloc_exec(unsigned long size)
75167 {
75168 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75169 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75170 -1, __builtin_return_address(0));
75171 }
75172
75173 @@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75174 unsigned long uaddr = vma->vm_start;
75175 unsigned long usize = vma->vm_end - vma->vm_start;
75176
75177 + BUG_ON(vma->vm_mirror);
75178 +
75179 if ((PAGE_SIZE-1) & (unsigned long)addr)
75180 return -EINVAL;
75181
75182 diff --git a/mm/vmstat.c b/mm/vmstat.c
75183 index 1bbbbd9..ff35669 100644
75184 --- a/mm/vmstat.c
75185 +++ b/mm/vmstat.c
75186 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75187 *
75188 * vm_stat contains the global counters
75189 */
75190 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75191 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75192 EXPORT_SYMBOL(vm_stat);
75193
75194 #ifdef CONFIG_SMP
75195 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75196 v = p->vm_stat_diff[i];
75197 p->vm_stat_diff[i] = 0;
75198 local_irq_restore(flags);
75199 - atomic_long_add(v, &zone->vm_stat[i]);
75200 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75201 global_diff[i] += v;
75202 #ifdef CONFIG_NUMA
75203 /* 3 seconds idle till flush */
75204 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75205
75206 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75207 if (global_diff[i])
75208 - atomic_long_add(global_diff[i], &vm_stat[i]);
75209 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75210 }
75211
75212 #endif
75213 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75214 start_cpu_timer(cpu);
75215 #endif
75216 #ifdef CONFIG_PROC_FS
75217 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75218 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75219 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75220 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75221 + {
75222 + mode_t gr_mode = S_IRUGO;
75223 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75224 + gr_mode = S_IRUSR;
75225 +#endif
75226 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75227 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75228 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75229 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75230 +#else
75231 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75232 +#endif
75233 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75234 + }
75235 #endif
75236 return 0;
75237 }
75238 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75239 index 9096bcb..43ed7bb 100644
75240 --- a/net/8021q/vlan.c
75241 +++ b/net/8021q/vlan.c
75242 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75243 err = -EPERM;
75244 if (!capable(CAP_NET_ADMIN))
75245 break;
75246 - if ((args.u.name_type >= 0) &&
75247 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75248 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75249 struct vlan_net *vn;
75250
75251 vn = net_generic(net, vlan_net_id);
75252 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75253 index 6449bae..8c1f454 100644
75254 --- a/net/9p/trans_fd.c
75255 +++ b/net/9p/trans_fd.c
75256 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75257 oldfs = get_fs();
75258 set_fs(get_ds());
75259 /* The cast to a user pointer is valid due to the set_fs() */
75260 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75261 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75262 set_fs(oldfs);
75263
75264 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75265 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75266 index 876fbe8..8bbea9f 100644
75267 --- a/net/atm/atm_misc.c
75268 +++ b/net/atm/atm_misc.c
75269 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75270 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75271 return 1;
75272 atm_return(vcc, truesize);
75273 - atomic_inc(&vcc->stats->rx_drop);
75274 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75275 return 0;
75276 }
75277 EXPORT_SYMBOL(atm_charge);
75278 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75279 }
75280 }
75281 atm_return(vcc, guess);
75282 - atomic_inc(&vcc->stats->rx_drop);
75283 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75284 return NULL;
75285 }
75286 EXPORT_SYMBOL(atm_alloc_charge);
75287 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75288
75289 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75290 {
75291 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75292 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75293 __SONET_ITEMS
75294 #undef __HANDLE_ITEM
75295 }
75296 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75297
75298 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75299 {
75300 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75301 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75302 __SONET_ITEMS
75303 #undef __HANDLE_ITEM
75304 }
75305 diff --git a/net/atm/common.c b/net/atm/common.c
75306 index b4b44db..0c0ad93 100644
75307 --- a/net/atm/common.c
75308 +++ b/net/atm/common.c
75309 @@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
75310
75311 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
75312 return -ENOTCONN;
75313 + memset(&pvc, 0, sizeof(pvc));
75314 pvc.sap_family = AF_ATMPVC;
75315 pvc.sap_addr.itf = vcc->dev->number;
75316 pvc.sap_addr.vpi = vcc->vpi;
75317 diff --git a/net/atm/lec.h b/net/atm/lec.h
75318 index a86aff9..3a0d6f6 100644
75319 --- a/net/atm/lec.h
75320 +++ b/net/atm/lec.h
75321 @@ -48,7 +48,7 @@ struct lane2_ops {
75322 const u8 *tlvs, u32 sizeoftlvs);
75323 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75324 const u8 *tlvs, u32 sizeoftlvs);
75325 -};
75326 +} __no_const;
75327
75328 /*
75329 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75330 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75331 index 0919a88..a23d54e 100644
75332 --- a/net/atm/mpc.h
75333 +++ b/net/atm/mpc.h
75334 @@ -33,7 +33,7 @@ struct mpoa_client {
75335 struct mpc_parameters parameters; /* parameters for this client */
75336
75337 const struct net_device_ops *old_ops;
75338 - struct net_device_ops new_ops;
75339 + net_device_ops_no_const new_ops;
75340 };
75341
75342
75343 diff --git a/net/atm/proc.c b/net/atm/proc.c
75344 index 0d020de..011c7bb 100644
75345 --- a/net/atm/proc.c
75346 +++ b/net/atm/proc.c
75347 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75348 const struct k_atm_aal_stats *stats)
75349 {
75350 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75351 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75352 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75353 - atomic_read(&stats->rx_drop));
75354 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75355 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75356 + atomic_read_unchecked(&stats->rx_drop));
75357 }
75358
75359 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75360 diff --git a/net/atm/pvc.c b/net/atm/pvc.c
75361 index 3a73491..ae03240 100644
75362 --- a/net/atm/pvc.c
75363 +++ b/net/atm/pvc.c
75364 @@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
75365 return -ENOTCONN;
75366 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
75367 addr = (struct sockaddr_atmpvc *)sockaddr;
75368 + memset(addr, 0, sizeof(*addr));
75369 addr->sap_family = AF_ATMPVC;
75370 addr->sap_addr.itf = vcc->dev->number;
75371 addr->sap_addr.vpi = vcc->vpi;
75372 diff --git a/net/atm/resources.c b/net/atm/resources.c
75373 index 23f45ce..c748f1a 100644
75374 --- a/net/atm/resources.c
75375 +++ b/net/atm/resources.c
75376 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75377 static void copy_aal_stats(struct k_atm_aal_stats *from,
75378 struct atm_aal_stats *to)
75379 {
75380 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75381 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75382 __AAL_STAT_ITEMS
75383 #undef __HANDLE_ITEM
75384 }
75385 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75386 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75387 struct atm_aal_stats *to)
75388 {
75389 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75390 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75391 __AAL_STAT_ITEMS
75392 #undef __HANDLE_ITEM
75393 }
75394 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75395 index dc53798..dc66333 100644
75396 --- a/net/batman-adv/bat_iv_ogm.c
75397 +++ b/net/batman-adv/bat_iv_ogm.c
75398 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75399
75400 /* randomize initial seqno to avoid collision */
75401 get_random_bytes(&random_seqno, sizeof(random_seqno));
75402 - atomic_set(&hard_iface->seqno, random_seqno);
75403 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75404
75405 hard_iface->packet_len = BATMAN_OGM_HLEN;
75406 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75407 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75408
75409 /* change sequence number to network order */
75410 batman_ogm_packet->seqno =
75411 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75412 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75413
75414 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75415 batman_ogm_packet->tt_crc = htons((uint16_t)
75416 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75417 else
75418 batman_ogm_packet->gw_flags = NO_FLAGS;
75419
75420 - atomic_inc(&hard_iface->seqno);
75421 + atomic_inc_unchecked(&hard_iface->seqno);
75422
75423 slide_own_bcast_window(hard_iface);
75424 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75425 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75426 return;
75427
75428 /* could be changed by schedule_own_packet() */
75429 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75430 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75431
75432 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75433
75434 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75435 index dc334fa..766a01a 100644
75436 --- a/net/batman-adv/hard-interface.c
75437 +++ b/net/batman-adv/hard-interface.c
75438 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75439 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75440 dev_add_pack(&hard_iface->batman_adv_ptype);
75441
75442 - atomic_set(&hard_iface->frag_seqno, 1);
75443 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75444 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75445 hard_iface->net_dev->name);
75446
75447 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75448 * This can't be called via a bat_priv callback because
75449 * we have no bat_priv yet.
75450 */
75451 - atomic_set(&hard_iface->seqno, 1);
75452 + atomic_set_unchecked(&hard_iface->seqno, 1);
75453 hard_iface->packet_buff = NULL;
75454
75455 return hard_iface;
75456 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75457 index a0ec0e4..7beb587 100644
75458 --- a/net/batman-adv/soft-interface.c
75459 +++ b/net/batman-adv/soft-interface.c
75460 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75461
75462 /* set broadcast sequence number */
75463 bcast_packet->seqno =
75464 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75465 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75466
75467 add_bcast_packet_to_list(bat_priv, skb, 1);
75468
75469 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75470 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75471
75472 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75473 - atomic_set(&bat_priv->bcast_seqno, 1);
75474 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75475 atomic_set(&bat_priv->ttvn, 0);
75476 atomic_set(&bat_priv->tt_local_changes, 0);
75477 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75478 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75479 index 61308e8..2e142b2 100644
75480 --- a/net/batman-adv/types.h
75481 +++ b/net/batman-adv/types.h
75482 @@ -38,8 +38,8 @@ struct hard_iface {
75483 int16_t if_num;
75484 char if_status;
75485 struct net_device *net_dev;
75486 - atomic_t seqno;
75487 - atomic_t frag_seqno;
75488 + atomic_unchecked_t seqno;
75489 + atomic_unchecked_t frag_seqno;
75490 unsigned char *packet_buff;
75491 int packet_len;
75492 struct kobject *hardif_obj;
75493 @@ -163,7 +163,7 @@ struct bat_priv {
75494 atomic_t orig_interval; /* uint */
75495 atomic_t hop_penalty; /* uint */
75496 atomic_t log_level; /* uint */
75497 - atomic_t bcast_seqno;
75498 + atomic_unchecked_t bcast_seqno;
75499 atomic_t bcast_queue_left;
75500 atomic_t batman_queue_left;
75501 atomic_t ttvn; /* translation table version number */
75502 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75503 index 74175c2..32f8901 100644
75504 --- a/net/batman-adv/unicast.c
75505 +++ b/net/batman-adv/unicast.c
75506 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75507 frag1->flags = UNI_FRAG_HEAD | large_tail;
75508 frag2->flags = large_tail;
75509
75510 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75511 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75512 frag1->seqno = htons(seqno - 1);
75513 frag2->seqno = htons(seqno);
75514
75515 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75516 index 5914623..bedc768 100644
75517 --- a/net/bluetooth/hci_sock.c
75518 +++ b/net/bluetooth/hci_sock.c
75519 @@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
75520 *addr_len = sizeof(*haddr);
75521 haddr->hci_family = AF_BLUETOOTH;
75522 haddr->hci_dev = hdev->id;
75523 + haddr->hci_channel= 0;
75524
75525 release_sock(sk);
75526 return 0;
75527 @@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
75528 {
75529 struct hci_filter *f = &hci_pi(sk)->filter;
75530
75531 + memset(&uf, 0, sizeof(uf));
75532 uf.type_mask = f->type_mask;
75533 uf.opcode = f->opcode;
75534 uf.event_mask[0] = *((u32 *) f->event_mask + 0);
75535 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75536 index 4554e80..b778671 100644
75537 --- a/net/bluetooth/l2cap_core.c
75538 +++ b/net/bluetooth/l2cap_core.c
75539 @@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75540 break;
75541
75542 case L2CAP_CONF_RFC:
75543 - if (olen == sizeof(rfc))
75544 - memcpy(&rfc, (void *)val, olen);
75545 + if (olen != sizeof(rfc))
75546 + break;
75547 +
75548 + memcpy(&rfc, (void *)val, olen);
75549
75550 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75551 rfc.mode != chan->mode)
75552 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75553 index 3bb1611..fcf656b 100644
75554 --- a/net/bluetooth/l2cap_sock.c
75555 +++ b/net/bluetooth/l2cap_sock.c
75556 @@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
75557
75558 BT_DBG("sock %p, sk %p", sock, sk);
75559
75560 + memset(la, 0, sizeof(struct sockaddr_l2));
75561 addr->sa_family = AF_BLUETOOTH;
75562 *len = sizeof(struct sockaddr_l2);
75563
75564 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
75565 index e8707de..2df6956 100644
75566 --- a/net/bluetooth/rfcomm/sock.c
75567 +++ b/net/bluetooth/rfcomm/sock.c
75568 @@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
75569
75570 BT_DBG("sock %p, sk %p", sock, sk);
75571
75572 + memset(sa, 0, sizeof(*sa));
75573 sa->rc_family = AF_BLUETOOTH;
75574 sa->rc_channel = rfcomm_pi(sk)->channel;
75575 if (peer)
75576 @@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
75577 }
75578
75579 sec.level = rfcomm_pi(sk)->sec_level;
75580 + sec.key_size = 0;
75581
75582 len = min_t(unsigned int, len, sizeof(sec));
75583 if (copy_to_user(optval, (char *) &sec, len))
75584 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75585 index d1820ff..4f8c8f6 100644
75586 --- a/net/bluetooth/rfcomm/tty.c
75587 +++ b/net/bluetooth/rfcomm/tty.c
75588 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75589 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75590
75591 spin_lock_irqsave(&dev->port.lock, flags);
75592 - if (dev->port.count > 0) {
75593 + if (atomic_read(&dev->port.count) > 0) {
75594 spin_unlock_irqrestore(&dev->port.lock, flags);
75595 return;
75596 }
75597 @@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg)
75598
75599 size = sizeof(*dl) + dev_num * sizeof(*di);
75600
75601 - dl = kmalloc(size, GFP_KERNEL);
75602 + dl = kzalloc(size, GFP_KERNEL);
75603 if (!dl)
75604 return -ENOMEM;
75605
75606 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75607 return -ENODEV;
75608
75609 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75610 - dev->channel, dev->port.count);
75611 + dev->channel, atomic_read(&dev->port.count));
75612
75613 spin_lock_irqsave(&dev->port.lock, flags);
75614 - if (++dev->port.count > 1) {
75615 + if (atomic_inc_return(&dev->port.count) > 1) {
75616 spin_unlock_irqrestore(&dev->port.lock, flags);
75617 return 0;
75618 }
75619 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75620 return;
75621
75622 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75623 - dev->port.count);
75624 + atomic_read(&dev->port.count));
75625
75626 spin_lock_irqsave(&dev->port.lock, flags);
75627 - if (!--dev->port.count) {
75628 + if (!atomic_dec_return(&dev->port.count)) {
75629 spin_unlock_irqrestore(&dev->port.lock, flags);
75630 if (dev->tty_dev->parent)
75631 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75632 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75633 index 5fe2ff3..10968b5 100644
75634 --- a/net/bridge/netfilter/ebtables.c
75635 +++ b/net/bridge/netfilter/ebtables.c
75636 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75637 tmp.valid_hooks = t->table->valid_hooks;
75638 }
75639 mutex_unlock(&ebt_mutex);
75640 - if (copy_to_user(user, &tmp, *len) != 0){
75641 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75642 BUGPRINT("c2u Didn't work\n");
75643 ret = -EFAULT;
75644 break;
75645 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75646 index 047cd0e..461fd28 100644
75647 --- a/net/caif/cfctrl.c
75648 +++ b/net/caif/cfctrl.c
75649 @@ -10,6 +10,7 @@
75650 #include <linux/spinlock.h>
75651 #include <linux/slab.h>
75652 #include <linux/pkt_sched.h>
75653 +#include <linux/sched.h>
75654 #include <net/caif/caif_layer.h>
75655 #include <net/caif/cfpkt.h>
75656 #include <net/caif/cfctrl.h>
75657 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75658 memset(&dev_info, 0, sizeof(dev_info));
75659 dev_info.id = 0xff;
75660 cfsrvl_init(&this->serv, 0, &dev_info, false);
75661 - atomic_set(&this->req_seq_no, 1);
75662 - atomic_set(&this->rsp_seq_no, 1);
75663 + atomic_set_unchecked(&this->req_seq_no, 1);
75664 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75665 this->serv.layer.receive = cfctrl_recv;
75666 sprintf(this->serv.layer.name, "ctrl");
75667 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75668 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75669 struct cfctrl_request_info *req)
75670 {
75671 spin_lock_bh(&ctrl->info_list_lock);
75672 - atomic_inc(&ctrl->req_seq_no);
75673 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75674 + atomic_inc_unchecked(&ctrl->req_seq_no);
75675 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75676 list_add_tail(&req->list, &ctrl->list);
75677 spin_unlock_bh(&ctrl->info_list_lock);
75678 }
75679 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75680 if (p != first)
75681 pr_warn("Requests are not received in order\n");
75682
75683 - atomic_set(&ctrl->rsp_seq_no,
75684 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75685 p->sequence_no);
75686 list_del(&p->list);
75687 goto out;
75688 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
75689 index 69771c0..e597733 100644
75690 --- a/net/caif/chnl_net.c
75691 +++ b/net/caif/chnl_net.c
75692 @@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
75693
75694 /* check the version of IP */
75695 ip_version = skb_header_pointer(skb, 0, 1, &buf);
75696 + if (!ip_version) {
75697 + kfree_skb(skb);
75698 + return -EINVAL;
75699 + }
75700
75701 switch (*ip_version >> 4) {
75702 case 4:
75703 diff --git a/net/can/gw.c b/net/can/gw.c
75704 index b41acf2..3affb3a 100644
75705 --- a/net/can/gw.c
75706 +++ b/net/can/gw.c
75707 @@ -96,7 +96,7 @@ struct cf_mod {
75708 struct {
75709 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75710 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75711 - } csumfunc;
75712 + } __no_const csumfunc;
75713 };
75714
75715
75716 diff --git a/net/compat.c b/net/compat.c
75717 index 74ed1d7..62f7ea6 100644
75718 --- a/net/compat.c
75719 +++ b/net/compat.c
75720 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75721 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75722 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75723 return -EFAULT;
75724 - kmsg->msg_name = compat_ptr(tmp1);
75725 - kmsg->msg_iov = compat_ptr(tmp2);
75726 - kmsg->msg_control = compat_ptr(tmp3);
75727 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75728 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75729 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75730 return 0;
75731 }
75732
75733 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75734
75735 if (kern_msg->msg_namelen) {
75736 if (mode == VERIFY_READ) {
75737 - int err = move_addr_to_kernel(kern_msg->msg_name,
75738 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75739 kern_msg->msg_namelen,
75740 kern_address);
75741 if (err < 0)
75742 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75743 kern_msg->msg_name = NULL;
75744
75745 tot_len = iov_from_user_compat_to_kern(kern_iov,
75746 - (struct compat_iovec __user *)kern_msg->msg_iov,
75747 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75748 kern_msg->msg_iovlen);
75749 if (tot_len >= 0)
75750 kern_msg->msg_iov = kern_iov;
75751 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75752
75753 #define CMSG_COMPAT_FIRSTHDR(msg) \
75754 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75755 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75756 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75757 (struct compat_cmsghdr __user *)NULL)
75758
75759 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75760 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75761 (ucmlen) <= (unsigned long) \
75762 ((mhdr)->msg_controllen - \
75763 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75764 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75765
75766 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75767 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75768 {
75769 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75770 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75771 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75772 msg->msg_controllen)
75773 return NULL;
75774 return (struct compat_cmsghdr __user *)ptr;
75775 @@ -219,7 +219,7 @@ Efault:
75776
75777 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75778 {
75779 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75780 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75781 struct compat_cmsghdr cmhdr;
75782 struct compat_timeval ctv;
75783 struct compat_timespec cts[3];
75784 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75785
75786 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75787 {
75788 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75789 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75790 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75791 int fdnum = scm->fp->count;
75792 struct file **fp = scm->fp->fp;
75793 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75794 return -EFAULT;
75795 old_fs = get_fs();
75796 set_fs(KERNEL_DS);
75797 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75798 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75799 set_fs(old_fs);
75800
75801 return err;
75802 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75803 len = sizeof(ktime);
75804 old_fs = get_fs();
75805 set_fs(KERNEL_DS);
75806 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75807 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75808 set_fs(old_fs);
75809
75810 if (!err) {
75811 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75812 case MCAST_JOIN_GROUP:
75813 case MCAST_LEAVE_GROUP:
75814 {
75815 - struct compat_group_req __user *gr32 = (void *)optval;
75816 + struct compat_group_req __user *gr32 = (void __user *)optval;
75817 struct group_req __user *kgr =
75818 compat_alloc_user_space(sizeof(struct group_req));
75819 u32 interface;
75820 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75821 case MCAST_BLOCK_SOURCE:
75822 case MCAST_UNBLOCK_SOURCE:
75823 {
75824 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75825 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75826 struct group_source_req __user *kgsr = compat_alloc_user_space(
75827 sizeof(struct group_source_req));
75828 u32 interface;
75829 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75830 }
75831 case MCAST_MSFILTER:
75832 {
75833 - struct compat_group_filter __user *gf32 = (void *)optval;
75834 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75835 struct group_filter __user *kgf;
75836 u32 interface, fmode, numsrc;
75837
75838 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75839 char __user *optval, int __user *optlen,
75840 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75841 {
75842 - struct compat_group_filter __user *gf32 = (void *)optval;
75843 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75844 struct group_filter __user *kgf;
75845 int __user *koptlen;
75846 u32 interface, fmode, numsrc;
75847 diff --git a/net/core/datagram.c b/net/core/datagram.c
75848 index ae6acf6..d5c8f66 100644
75849 --- a/net/core/datagram.c
75850 +++ b/net/core/datagram.c
75851 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75852 }
75853
75854 kfree_skb(skb);
75855 - atomic_inc(&sk->sk_drops);
75856 + atomic_inc_unchecked(&sk->sk_drops);
75857 sk_mem_reclaim_partial(sk);
75858
75859 return err;
75860 diff --git a/net/core/dev.c b/net/core/dev.c
75861 index a000840..566cee1 100644
75862 --- a/net/core/dev.c
75863 +++ b/net/core/dev.c
75864 @@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75865 if (no_module && capable(CAP_NET_ADMIN))
75866 no_module = request_module("netdev-%s", name);
75867 if (no_module && capable(CAP_SYS_MODULE)) {
75868 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75869 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75870 +#else
75871 if (!request_module("%s", name))
75872 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75873 name);
75874 +#endif
75875 }
75876 }
75877 EXPORT_SYMBOL(dev_load);
75878 @@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75879 {
75880 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75881 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75882 - atomic_long_inc(&dev->rx_dropped);
75883 + atomic_long_inc_unchecked(&dev->rx_dropped);
75884 kfree_skb(skb);
75885 return NET_RX_DROP;
75886 }
75887 @@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75888 nf_reset(skb);
75889
75890 if (unlikely(!is_skb_forwardable(dev, skb))) {
75891 - atomic_long_inc(&dev->rx_dropped);
75892 + atomic_long_inc_unchecked(&dev->rx_dropped);
75893 kfree_skb(skb);
75894 return NET_RX_DROP;
75895 }
75896 @@ -2041,7 +2045,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75897
75898 struct dev_gso_cb {
75899 void (*destructor)(struct sk_buff *skb);
75900 -};
75901 +} __no_const;
75902
75903 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75904
75905 @@ -2876,7 +2880,7 @@ enqueue:
75906
75907 local_irq_restore(flags);
75908
75909 - atomic_long_inc(&skb->dev->rx_dropped);
75910 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75911 kfree_skb(skb);
75912 return NET_RX_DROP;
75913 }
75914 @@ -2948,7 +2952,7 @@ int netif_rx_ni(struct sk_buff *skb)
75915 }
75916 EXPORT_SYMBOL(netif_rx_ni);
75917
75918 -static void net_tx_action(struct softirq_action *h)
75919 +static void net_tx_action(void)
75920 {
75921 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75922
75923 @@ -3235,7 +3239,7 @@ ncls:
75924 if (pt_prev) {
75925 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75926 } else {
75927 - atomic_long_inc(&skb->dev->rx_dropped);
75928 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75929 kfree_skb(skb);
75930 /* Jamal, now you will not able to escape explaining
75931 * me how you were going to use this. :-)
75932 @@ -3800,7 +3804,7 @@ void netif_napi_del(struct napi_struct *napi)
75933 }
75934 EXPORT_SYMBOL(netif_napi_del);
75935
75936 -static void net_rx_action(struct softirq_action *h)
75937 +static void net_rx_action(void)
75938 {
75939 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75940 unsigned long time_limit = jiffies + 2;
75941 @@ -4270,8 +4274,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75942 else
75943 seq_printf(seq, "%04x", ntohs(pt->type));
75944
75945 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75946 + seq_printf(seq, " %-8s %p\n",
75947 + pt->dev ? pt->dev->name : "", NULL);
75948 +#else
75949 seq_printf(seq, " %-8s %pF\n",
75950 pt->dev ? pt->dev->name : "", pt->func);
75951 +#endif
75952 }
75953
75954 return 0;
75955 @@ -5823,7 +5832,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75956 } else {
75957 netdev_stats_to_stats64(storage, &dev->stats);
75958 }
75959 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75960 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75961 return storage;
75962 }
75963 EXPORT_SYMBOL(dev_get_stats);
75964 diff --git a/net/core/flow.c b/net/core/flow.c
75965 index e318c7e..168b1d0 100644
75966 --- a/net/core/flow.c
75967 +++ b/net/core/flow.c
75968 @@ -61,7 +61,7 @@ struct flow_cache {
75969 struct timer_list rnd_timer;
75970 };
75971
75972 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75973 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75974 EXPORT_SYMBOL(flow_cache_genid);
75975 static struct flow_cache flow_cache_global;
75976 static struct kmem_cache *flow_cachep __read_mostly;
75977 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75978
75979 static int flow_entry_valid(struct flow_cache_entry *fle)
75980 {
75981 - if (atomic_read(&flow_cache_genid) != fle->genid)
75982 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75983 return 0;
75984 if (fle->object && !fle->object->ops->check(fle->object))
75985 return 0;
75986 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75987 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75988 fcp->hash_count++;
75989 }
75990 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75991 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75992 flo = fle->object;
75993 if (!flo)
75994 goto ret_object;
75995 @@ -280,7 +280,7 @@ nocache:
75996 }
75997 flo = resolver(net, key, family, dir, flo, ctx);
75998 if (fle) {
75999 - fle->genid = atomic_read(&flow_cache_genid);
76000 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76001 if (!IS_ERR(flo))
76002 fle->object = flo;
76003 else
76004 diff --git a/net/core/iovec.c b/net/core/iovec.c
76005 index 7e7aeb0..2a998cb 100644
76006 --- a/net/core/iovec.c
76007 +++ b/net/core/iovec.c
76008 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76009 if (m->msg_namelen) {
76010 if (mode == VERIFY_READ) {
76011 void __user *namep;
76012 - namep = (void __user __force *) m->msg_name;
76013 + namep = (void __force_user *) m->msg_name;
76014 err = move_addr_to_kernel(namep, m->msg_namelen,
76015 address);
76016 if (err < 0)
76017 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76018 }
76019
76020 size = m->msg_iovlen * sizeof(struct iovec);
76021 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76022 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76023 return -EFAULT;
76024
76025 m->msg_iov = iov;
76026 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76027 index 6c50ac0..6b4c038 100644
76028 --- a/net/core/rtnetlink.c
76029 +++ b/net/core/rtnetlink.c
76030 @@ -58,7 +58,7 @@ struct rtnl_link {
76031 rtnl_doit_func doit;
76032 rtnl_dumpit_func dumpit;
76033 rtnl_calcit_func calcit;
76034 -};
76035 +} __no_const;
76036
76037 static DEFINE_MUTEX(rtnl_mutex);
76038
76039 diff --git a/net/core/scm.c b/net/core/scm.c
76040 index 611c5ef..88f6d6d 100644
76041 --- a/net/core/scm.c
76042 +++ b/net/core/scm.c
76043 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
76044 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76045 {
76046 struct cmsghdr __user *cm
76047 - = (__force struct cmsghdr __user *)msg->msg_control;
76048 + = (struct cmsghdr __force_user *)msg->msg_control;
76049 struct cmsghdr cmhdr;
76050 int cmlen = CMSG_LEN(len);
76051 int err;
76052 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76053 err = -EFAULT;
76054 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76055 goto out;
76056 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76057 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76058 goto out;
76059 cmlen = CMSG_SPACE(len);
76060 if (msg->msg_controllen < cmlen)
76061 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
76062 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76063 {
76064 struct cmsghdr __user *cm
76065 - = (__force struct cmsghdr __user*)msg->msg_control;
76066 + = (struct cmsghdr __force_user *)msg->msg_control;
76067
76068 int fdmax = 0;
76069 int fdnum = scm->fp->count;
76070 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76071 if (fdnum < fdmax)
76072 fdmax = fdnum;
76073
76074 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76075 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76076 i++, cmfptr++)
76077 {
76078 int new_fd;
76079 diff --git a/net/core/sock.c b/net/core/sock.c
76080 index 9e5b71f..66dec30 100644
76081 --- a/net/core/sock.c
76082 +++ b/net/core/sock.c
76083 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76084 struct sk_buff_head *list = &sk->sk_receive_queue;
76085
76086 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76087 - atomic_inc(&sk->sk_drops);
76088 + atomic_inc_unchecked(&sk->sk_drops);
76089 trace_sock_rcvqueue_full(sk, skb);
76090 return -ENOMEM;
76091 }
76092 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76093 return err;
76094
76095 if (!sk_rmem_schedule(sk, skb->truesize)) {
76096 - atomic_inc(&sk->sk_drops);
76097 + atomic_inc_unchecked(&sk->sk_drops);
76098 return -ENOBUFS;
76099 }
76100
76101 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76102 skb_dst_force(skb);
76103
76104 spin_lock_irqsave(&list->lock, flags);
76105 - skb->dropcount = atomic_read(&sk->sk_drops);
76106 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76107 __skb_queue_tail(list, skb);
76108 spin_unlock_irqrestore(&list->lock, flags);
76109
76110 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76111 skb->dev = NULL;
76112
76113 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76114 - atomic_inc(&sk->sk_drops);
76115 + atomic_inc_unchecked(&sk->sk_drops);
76116 goto discard_and_relse;
76117 }
76118 if (nested)
76119 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76120 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76121 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76122 bh_unlock_sock(sk);
76123 - atomic_inc(&sk->sk_drops);
76124 + atomic_inc_unchecked(&sk->sk_drops);
76125 goto discard_and_relse;
76126 }
76127
76128 @@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76129 if (len > sizeof(peercred))
76130 len = sizeof(peercred);
76131 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76132 - if (copy_to_user(optval, &peercred, len))
76133 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76134 return -EFAULT;
76135 goto lenout;
76136 }
76137 @@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76138 return -ENOTCONN;
76139 if (lv < len)
76140 return -EINVAL;
76141 - if (copy_to_user(optval, address, len))
76142 + if (len > sizeof(address) || copy_to_user(optval, address, len))
76143 return -EFAULT;
76144 goto lenout;
76145 }
76146 @@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76147
76148 if (len > lv)
76149 len = lv;
76150 - if (copy_to_user(optval, &v, len))
76151 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76152 return -EFAULT;
76153 lenout:
76154 if (put_user(len, optlen))
76155 @@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76156 */
76157 smp_wmb();
76158 atomic_set(&sk->sk_refcnt, 1);
76159 - atomic_set(&sk->sk_drops, 0);
76160 + atomic_set_unchecked(&sk->sk_drops, 0);
76161 }
76162 EXPORT_SYMBOL(sock_init_data);
76163
76164 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76165 index 5fd1467..8b70900 100644
76166 --- a/net/core/sock_diag.c
76167 +++ b/net/core/sock_diag.c
76168 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76169
76170 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76171 {
76172 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76173 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76174 cookie[1] != INET_DIAG_NOCOOKIE) &&
76175 ((u32)(unsigned long)sk != cookie[0] ||
76176 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76177 return -ESTALE;
76178 else
76179 +#endif
76180 return 0;
76181 }
76182 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76183
76184 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76185 {
76186 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76187 + cookie[0] = 0;
76188 + cookie[1] = 0;
76189 +#else
76190 cookie[0] = (u32)(unsigned long)sk;
76191 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76192 +#endif
76193 }
76194 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76195
76196 diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
76197 index 75c3582..fb85d37 100644
76198 --- a/net/dccp/ccid.h
76199 +++ b/net/dccp/ccid.h
76200 @@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
76201 u32 __user *optval, int __user *optlen)
76202 {
76203 int rc = -ENOPROTOOPT;
76204 - if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76205 + if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76206 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
76207 optval, optlen);
76208 return rc;
76209 @@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
76210 u32 __user *optval, int __user *optlen)
76211 {
76212 int rc = -ENOPROTOOPT;
76213 - if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76214 + if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76215 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
76216 optval, optlen);
76217 return rc;
76218 diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
76219 index 8c67bed..ce0d140 100644
76220 --- a/net/dccp/ccids/ccid3.c
76221 +++ b/net/dccp/ccids/ccid3.c
76222 @@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
76223 case DCCP_SOCKOPT_CCID_TX_INFO:
76224 if (len < sizeof(tfrc))
76225 return -EINVAL;
76226 + memset(&tfrc, 0, sizeof(tfrc));
76227 tfrc.tfrctx_x = hc->tx_x;
76228 tfrc.tfrctx_x_recv = hc->tx_x_recv;
76229 tfrc.tfrctx_x_calc = hc->tx_x_calc;
76230 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76231 index a55eecc..dd8428c 100644
76232 --- a/net/decnet/sysctl_net_decnet.c
76233 +++ b/net/decnet/sysctl_net_decnet.c
76234 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76235
76236 if (len > *lenp) len = *lenp;
76237
76238 - if (copy_to_user(buffer, addr, len))
76239 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76240 return -EFAULT;
76241
76242 *lenp = len;
76243 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76244
76245 if (len > *lenp) len = *lenp;
76246
76247 - if (copy_to_user(buffer, devname, len))
76248 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76249 return -EFAULT;
76250
76251 *lenp = len;
76252 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76253 index 3854411..2201a94 100644
76254 --- a/net/ipv4/fib_frontend.c
76255 +++ b/net/ipv4/fib_frontend.c
76256 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76257 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76258 fib_sync_up(dev);
76259 #endif
76260 - atomic_inc(&net->ipv4.dev_addr_genid);
76261 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76262 rt_cache_flush(dev_net(dev), -1);
76263 break;
76264 case NETDEV_DOWN:
76265 fib_del_ifaddr(ifa, NULL);
76266 - atomic_inc(&net->ipv4.dev_addr_genid);
76267 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76268 if (ifa->ifa_dev->ifa_list == NULL) {
76269 /* Last address was deleted from this interface.
76270 * Disable IP.
76271 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76272 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76273 fib_sync_up(dev);
76274 #endif
76275 - atomic_inc(&net->ipv4.dev_addr_genid);
76276 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76277 rt_cache_flush(dev_net(dev), -1);
76278 break;
76279 case NETDEV_DOWN:
76280 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76281 index e5b7182..570a90e 100644
76282 --- a/net/ipv4/fib_semantics.c
76283 +++ b/net/ipv4/fib_semantics.c
76284 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76285 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76286 nh->nh_gw,
76287 nh->nh_parent->fib_scope);
76288 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76289 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76290
76291 return nh->nh_saddr;
76292 }
76293 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76294 index 7880af9..70f92a3 100644
76295 --- a/net/ipv4/inet_hashtables.c
76296 +++ b/net/ipv4/inet_hashtables.c
76297 @@ -18,12 +18,15 @@
76298 #include <linux/sched.h>
76299 #include <linux/slab.h>
76300 #include <linux/wait.h>
76301 +#include <linux/security.h>
76302
76303 #include <net/inet_connection_sock.h>
76304 #include <net/inet_hashtables.h>
76305 #include <net/secure_seq.h>
76306 #include <net/ip.h>
76307
76308 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76309 +
76310 /*
76311 * Allocate and initialize a new local port bind bucket.
76312 * The bindhash mutex for snum's hash chain must be held here.
76313 @@ -530,6 +533,8 @@ ok:
76314 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76315 spin_unlock(&head->lock);
76316
76317 + gr_update_task_in_ip_table(current, inet_sk(sk));
76318 +
76319 if (tw) {
76320 inet_twsk_deschedule(tw, death_row);
76321 while (twrefcnt) {
76322 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76323 index dfba343..c827d50 100644
76324 --- a/net/ipv4/inetpeer.c
76325 +++ b/net/ipv4/inetpeer.c
76326 @@ -487,8 +487,8 @@ relookup:
76327 if (p) {
76328 p->daddr = *daddr;
76329 atomic_set(&p->refcnt, 1);
76330 - atomic_set(&p->rid, 0);
76331 - atomic_set(&p->ip_id_count,
76332 + atomic_set_unchecked(&p->rid, 0);
76333 + atomic_set_unchecked(&p->ip_id_count,
76334 (daddr->family == AF_INET) ?
76335 secure_ip_id(daddr->addr.a4) :
76336 secure_ipv6_id(daddr->addr.a6));
76337 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76338 index 9dbd3dd..0c59fb2 100644
76339 --- a/net/ipv4/ip_fragment.c
76340 +++ b/net/ipv4/ip_fragment.c
76341 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76342 return 0;
76343
76344 start = qp->rid;
76345 - end = atomic_inc_return(&peer->rid);
76346 + end = atomic_inc_return_unchecked(&peer->rid);
76347 qp->rid = end;
76348
76349 rc = qp->q.fragments && (end - start) > max;
76350 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76351 index 0d11f23..2bb3f64 100644
76352 --- a/net/ipv4/ip_sockglue.c
76353 +++ b/net/ipv4/ip_sockglue.c
76354 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76355 len = min_t(unsigned int, len, opt->optlen);
76356 if (put_user(len, optlen))
76357 return -EFAULT;
76358 - if (copy_to_user(optval, opt->__data, len))
76359 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76360 + copy_to_user(optval, opt->__data, len))
76361 return -EFAULT;
76362 return 0;
76363 }
76364 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76365 if (sk->sk_type != SOCK_STREAM)
76366 return -ENOPROTOOPT;
76367
76368 - msg.msg_control = optval;
76369 + msg.msg_control = (void __force_kernel *)optval;
76370 msg.msg_controllen = len;
76371 msg.msg_flags = flags;
76372
76373 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76374 index 67e8a6b..386764d 100644
76375 --- a/net/ipv4/ipconfig.c
76376 +++ b/net/ipv4/ipconfig.c
76377 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76378
76379 mm_segment_t oldfs = get_fs();
76380 set_fs(get_ds());
76381 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76382 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76383 set_fs(oldfs);
76384 return res;
76385 }
76386 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76387
76388 mm_segment_t oldfs = get_fs();
76389 set_fs(get_ds());
76390 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76391 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76392 set_fs(oldfs);
76393 return res;
76394 }
76395 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76396
76397 mm_segment_t oldfs = get_fs();
76398 set_fs(get_ds());
76399 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76400 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76401 set_fs(oldfs);
76402 return res;
76403 }
76404 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76405 index 2c00e8b..45b3bdd 100644
76406 --- a/net/ipv4/ping.c
76407 +++ b/net/ipv4/ping.c
76408 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76409 sk_rmem_alloc_get(sp),
76410 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76411 atomic_read(&sp->sk_refcnt), sp,
76412 - atomic_read(&sp->sk_drops), len);
76413 + atomic_read_unchecked(&sp->sk_drops), len);
76414 }
76415
76416 static int ping_seq_show(struct seq_file *seq, void *v)
76417 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76418 index 4032b81..625143c 100644
76419 --- a/net/ipv4/raw.c
76420 +++ b/net/ipv4/raw.c
76421 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76422 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76423 {
76424 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76425 - atomic_inc(&sk->sk_drops);
76426 + atomic_inc_unchecked(&sk->sk_drops);
76427 kfree_skb(skb);
76428 return NET_RX_DROP;
76429 }
76430 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76431
76432 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76433 {
76434 + struct icmp_filter filter;
76435 +
76436 if (optlen > sizeof(struct icmp_filter))
76437 optlen = sizeof(struct icmp_filter);
76438 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76439 + if (copy_from_user(&filter, optval, optlen))
76440 return -EFAULT;
76441 + raw_sk(sk)->filter = filter;
76442 return 0;
76443 }
76444
76445 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76446 {
76447 int len, ret = -EFAULT;
76448 + struct icmp_filter filter;
76449
76450 if (get_user(len, optlen))
76451 goto out;
76452 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76453 if (len > sizeof(struct icmp_filter))
76454 len = sizeof(struct icmp_filter);
76455 ret = -EFAULT;
76456 - if (put_user(len, optlen) ||
76457 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76458 + filter = raw_sk(sk)->filter;
76459 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76460 goto out;
76461 ret = 0;
76462 out: return ret;
76463 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76464 sk_wmem_alloc_get(sp),
76465 sk_rmem_alloc_get(sp),
76466 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76467 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76468 + atomic_read(&sp->sk_refcnt),
76469 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76470 + NULL,
76471 +#else
76472 + sp,
76473 +#endif
76474 + atomic_read_unchecked(&sp->sk_drops));
76475 }
76476
76477 static int raw_seq_show(struct seq_file *seq, void *v)
76478 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76479 index 98b30d0..cfa3cf7 100644
76480 --- a/net/ipv4/route.c
76481 +++ b/net/ipv4/route.c
76482 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76483
76484 static inline int rt_genid(struct net *net)
76485 {
76486 - return atomic_read(&net->ipv4.rt_genid);
76487 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76488 }
76489
76490 #ifdef CONFIG_PROC_FS
76491 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76492 unsigned char shuffle;
76493
76494 get_random_bytes(&shuffle, sizeof(shuffle));
76495 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76496 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76497 inetpeer_invalidate_tree(AF_INET);
76498 }
76499
76500 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76501 error = rt->dst.error;
76502 if (peer) {
76503 inet_peer_refcheck(rt->peer);
76504 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76505 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76506 if (peer->tcp_ts_stamp) {
76507 ts = peer->tcp_ts;
76508 tsage = get_seconds() - peer->tcp_ts_stamp;
76509 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76510 index c8d28c4..e40f75a 100644
76511 --- a/net/ipv4/tcp_ipv4.c
76512 +++ b/net/ipv4/tcp_ipv4.c
76513 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76514 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76515
76516
76517 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76518 +extern int grsec_enable_blackhole;
76519 +#endif
76520 +
76521 #ifdef CONFIG_TCP_MD5SIG
76522 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76523 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76524 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76525 return 0;
76526
76527 reset:
76528 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76529 + if (!grsec_enable_blackhole)
76530 +#endif
76531 tcp_v4_send_reset(rsk, skb);
76532 discard:
76533 kfree_skb(skb);
76534 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76535 TCP_SKB_CB(skb)->sacked = 0;
76536
76537 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76538 - if (!sk)
76539 + if (!sk) {
76540 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76541 + ret = 1;
76542 +#endif
76543 goto no_tcp_socket;
76544 -
76545 + }
76546 process:
76547 - if (sk->sk_state == TCP_TIME_WAIT)
76548 + if (sk->sk_state == TCP_TIME_WAIT) {
76549 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76550 + ret = 2;
76551 +#endif
76552 goto do_time_wait;
76553 + }
76554
76555 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76556 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76557 @@ -1774,6 +1788,10 @@ no_tcp_socket:
76558 bad_packet:
76559 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76560 } else {
76561 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76562 + if (!grsec_enable_blackhole || (ret == 1 &&
76563 + (skb->dev->flags & IFF_LOOPBACK)))
76564 +#endif
76565 tcp_v4_send_reset(NULL, skb);
76566 }
76567
76568 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76569 0, /* non standard timer */
76570 0, /* open_requests have no inode */
76571 atomic_read(&sk->sk_refcnt),
76572 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76573 + NULL,
76574 +#else
76575 req,
76576 +#endif
76577 len);
76578 }
76579
76580 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76581 sock_i_uid(sk),
76582 icsk->icsk_probes_out,
76583 sock_i_ino(sk),
76584 - atomic_read(&sk->sk_refcnt), sk,
76585 + atomic_read(&sk->sk_refcnt),
76586 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76587 + NULL,
76588 +#else
76589 + sk,
76590 +#endif
76591 jiffies_to_clock_t(icsk->icsk_rto),
76592 jiffies_to_clock_t(icsk->icsk_ack.ato),
76593 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76594 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76595 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76596 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76597 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76598 - atomic_read(&tw->tw_refcnt), tw, len);
76599 + atomic_read(&tw->tw_refcnt),
76600 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76601 + NULL,
76602 +#else
76603 + tw,
76604 +#endif
76605 + len);
76606 }
76607
76608 #define TMPSZ 150
76609 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76610 index b85d9fe..4b0eed9 100644
76611 --- a/net/ipv4/tcp_minisocks.c
76612 +++ b/net/ipv4/tcp_minisocks.c
76613 @@ -27,6 +27,10 @@
76614 #include <net/inet_common.h>
76615 #include <net/xfrm.h>
76616
76617 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76618 +extern int grsec_enable_blackhole;
76619 +#endif
76620 +
76621 int sysctl_tcp_syncookies __read_mostly = 1;
76622 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76623
76624 @@ -754,6 +758,10 @@ listen_overflow:
76625
76626 embryonic_reset:
76627 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76628 +
76629 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76630 + if (!grsec_enable_blackhole)
76631 +#endif
76632 if (!(flg & TCP_FLAG_RST))
76633 req->rsk_ops->send_reset(sk, skb);
76634
76635 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76636 index 4526fe6..1a34e43 100644
76637 --- a/net/ipv4/tcp_probe.c
76638 +++ b/net/ipv4/tcp_probe.c
76639 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76640 if (cnt + width >= len)
76641 break;
76642
76643 - if (copy_to_user(buf + cnt, tbuf, width))
76644 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76645 return -EFAULT;
76646 cnt += width;
76647 }
76648 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76649 index e911e6c..d0a9356 100644
76650 --- a/net/ipv4/tcp_timer.c
76651 +++ b/net/ipv4/tcp_timer.c
76652 @@ -22,6 +22,10 @@
76653 #include <linux/gfp.h>
76654 #include <net/tcp.h>
76655
76656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76657 +extern int grsec_lastack_retries;
76658 +#endif
76659 +
76660 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76661 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76662 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76663 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76664 }
76665 }
76666
76667 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76668 + if ((sk->sk_state == TCP_LAST_ACK) &&
76669 + (grsec_lastack_retries > 0) &&
76670 + (grsec_lastack_retries < retry_until))
76671 + retry_until = grsec_lastack_retries;
76672 +#endif
76673 +
76674 if (retransmits_timed_out(sk, retry_until,
76675 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76676 /* Has it gone just too far? */
76677 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76678 index eaca736..60488ae 100644
76679 --- a/net/ipv4/udp.c
76680 +++ b/net/ipv4/udp.c
76681 @@ -87,6 +87,7 @@
76682 #include <linux/types.h>
76683 #include <linux/fcntl.h>
76684 #include <linux/module.h>
76685 +#include <linux/security.h>
76686 #include <linux/socket.h>
76687 #include <linux/sockios.h>
76688 #include <linux/igmp.h>
76689 @@ -110,6 +111,10 @@
76690 #include <linux/static_key.h>
76691 #include "udp_impl.h"
76692
76693 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76694 +extern int grsec_enable_blackhole;
76695 +#endif
76696 +
76697 struct udp_table udp_table __read_mostly;
76698 EXPORT_SYMBOL(udp_table);
76699
76700 @@ -568,6 +573,9 @@ found:
76701 return s;
76702 }
76703
76704 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76705 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76706 +
76707 /*
76708 * This routine is called by the ICMP module when it gets some
76709 * sort of error condition. If err < 0 then the socket should
76710 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76711 dport = usin->sin_port;
76712 if (dport == 0)
76713 return -EINVAL;
76714 +
76715 + err = gr_search_udp_sendmsg(sk, usin);
76716 + if (err)
76717 + return err;
76718 } else {
76719 if (sk->sk_state != TCP_ESTABLISHED)
76720 return -EDESTADDRREQ;
76721 +
76722 + err = gr_search_udp_sendmsg(sk, NULL);
76723 + if (err)
76724 + return err;
76725 +
76726 daddr = inet->inet_daddr;
76727 dport = inet->inet_dport;
76728 /* Open fast path for connected socket.
76729 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76730 udp_lib_checksum_complete(skb)) {
76731 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76732 IS_UDPLITE(sk));
76733 - atomic_inc(&sk->sk_drops);
76734 + atomic_inc_unchecked(&sk->sk_drops);
76735 __skb_unlink(skb, rcvq);
76736 __skb_queue_tail(&list_kill, skb);
76737 }
76738 @@ -1189,6 +1206,10 @@ try_again:
76739 if (!skb)
76740 goto out;
76741
76742 + err = gr_search_udp_recvmsg(sk, skb);
76743 + if (err)
76744 + goto out_free;
76745 +
76746 ulen = skb->len - sizeof(struct udphdr);
76747 copied = len;
76748 if (copied > ulen)
76749 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76750
76751 drop:
76752 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76753 - atomic_inc(&sk->sk_drops);
76754 + atomic_inc_unchecked(&sk->sk_drops);
76755 kfree_skb(skb);
76756 return -1;
76757 }
76758 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76759 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76760
76761 if (!skb1) {
76762 - atomic_inc(&sk->sk_drops);
76763 + atomic_inc_unchecked(&sk->sk_drops);
76764 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76765 IS_UDPLITE(sk));
76766 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76767 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76768 goto csum_error;
76769
76770 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76771 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76772 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76773 +#endif
76774 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76775
76776 /*
76777 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76778 sk_wmem_alloc_get(sp),
76779 sk_rmem_alloc_get(sp),
76780 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76781 - atomic_read(&sp->sk_refcnt), sp,
76782 - atomic_read(&sp->sk_drops), len);
76783 + atomic_read(&sp->sk_refcnt),
76784 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76785 + NULL,
76786 +#else
76787 + sp,
76788 +#endif
76789 + atomic_read_unchecked(&sp->sk_drops), len);
76790 }
76791
76792 int udp4_seq_show(struct seq_file *seq, void *v)
76793 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76794 index 8f6411c..5767579 100644
76795 --- a/net/ipv6/addrconf.c
76796 +++ b/net/ipv6/addrconf.c
76797 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76798 p.iph.ihl = 5;
76799 p.iph.protocol = IPPROTO_IPV6;
76800 p.iph.ttl = 64;
76801 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76802 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76803
76804 if (ops->ndo_do_ioctl) {
76805 mm_segment_t oldfs = get_fs();
76806 diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
76807 index db1521f..ebb3314 100644
76808 --- a/net/ipv6/esp6.c
76809 +++ b/net/ipv6/esp6.c
76810 @@ -166,8 +166,6 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
76811 struct esp_data *esp = x->data;
76812
76813 /* skb is pure payload to encrypt */
76814 - err = -ENOMEM;
76815 -
76816 aead = esp->aead;
76817 alen = crypto_aead_authsize(aead);
76818
76819 @@ -202,8 +200,10 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
76820 }
76821
76822 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
76823 - if (!tmp)
76824 + if (!tmp) {
76825 + err = -ENOMEM;
76826 goto error;
76827 + }
76828
76829 seqhi = esp_tmp_seqhi(tmp);
76830 iv = esp_tmp_iv(aead, tmp, seqhilen);
76831 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76832 index e6cee52..cf47476 100644
76833 --- a/net/ipv6/inet6_connection_sock.c
76834 +++ b/net/ipv6/inet6_connection_sock.c
76835 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76836 #ifdef CONFIG_XFRM
76837 {
76838 struct rt6_info *rt = (struct rt6_info *)dst;
76839 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76840 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76841 }
76842 #endif
76843 }
76844 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76845 #ifdef CONFIG_XFRM
76846 if (dst) {
76847 struct rt6_info *rt = (struct rt6_info *)dst;
76848 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76849 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76850 __sk_dst_reset(sk);
76851 dst = NULL;
76852 }
76853 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76854 index ba6d13d..6899122 100644
76855 --- a/net/ipv6/ipv6_sockglue.c
76856 +++ b/net/ipv6/ipv6_sockglue.c
76857 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76858 if (sk->sk_type != SOCK_STREAM)
76859 return -ENOPROTOOPT;
76860
76861 - msg.msg_control = optval;
76862 + msg.msg_control = (void __force_kernel *)optval;
76863 msg.msg_controllen = len;
76864 msg.msg_flags = flags;
76865
76866 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76867 index 93d6983..8e54c4d 100644
76868 --- a/net/ipv6/raw.c
76869 +++ b/net/ipv6/raw.c
76870 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76871 {
76872 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76873 skb_checksum_complete(skb)) {
76874 - atomic_inc(&sk->sk_drops);
76875 + atomic_inc_unchecked(&sk->sk_drops);
76876 kfree_skb(skb);
76877 return NET_RX_DROP;
76878 }
76879 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76880 struct raw6_sock *rp = raw6_sk(sk);
76881
76882 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76883 - atomic_inc(&sk->sk_drops);
76884 + atomic_inc_unchecked(&sk->sk_drops);
76885 kfree_skb(skb);
76886 return NET_RX_DROP;
76887 }
76888 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76889
76890 if (inet->hdrincl) {
76891 if (skb_checksum_complete(skb)) {
76892 - atomic_inc(&sk->sk_drops);
76893 + atomic_inc_unchecked(&sk->sk_drops);
76894 kfree_skb(skb);
76895 return NET_RX_DROP;
76896 }
76897 @@ -602,7 +602,7 @@ out:
76898 return err;
76899 }
76900
76901 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76902 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76903 struct flowi6 *fl6, struct dst_entry **dstp,
76904 unsigned int flags)
76905 {
76906 @@ -914,12 +914,15 @@ do_confirm:
76907 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76908 char __user *optval, int optlen)
76909 {
76910 + struct icmp6_filter filter;
76911 +
76912 switch (optname) {
76913 case ICMPV6_FILTER:
76914 if (optlen > sizeof(struct icmp6_filter))
76915 optlen = sizeof(struct icmp6_filter);
76916 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76917 + if (copy_from_user(&filter, optval, optlen))
76918 return -EFAULT;
76919 + raw6_sk(sk)->filter = filter;
76920 return 0;
76921 default:
76922 return -ENOPROTOOPT;
76923 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76924 char __user *optval, int __user *optlen)
76925 {
76926 int len;
76927 + struct icmp6_filter filter;
76928
76929 switch (optname) {
76930 case ICMPV6_FILTER:
76931 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76932 len = sizeof(struct icmp6_filter);
76933 if (put_user(len, optlen))
76934 return -EFAULT;
76935 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76936 + filter = raw6_sk(sk)->filter;
76937 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76938 return -EFAULT;
76939 return 0;
76940 default:
76941 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76942 0, 0L, 0,
76943 sock_i_uid(sp), 0,
76944 sock_i_ino(sp),
76945 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76946 + atomic_read(&sp->sk_refcnt),
76947 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76948 + NULL,
76949 +#else
76950 + sp,
76951 +#endif
76952 + atomic_read_unchecked(&sp->sk_drops));
76953 }
76954
76955 static int raw6_seq_show(struct seq_file *seq, void *v)
76956 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76957 index 9df64a5..39875da 100644
76958 --- a/net/ipv6/tcp_ipv6.c
76959 +++ b/net/ipv6/tcp_ipv6.c
76960 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76961 }
76962 #endif
76963
76964 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76965 +extern int grsec_enable_blackhole;
76966 +#endif
76967 +
76968 static void tcp_v6_hash(struct sock *sk)
76969 {
76970 if (sk->sk_state != TCP_CLOSE) {
76971 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76972 return 0;
76973
76974 reset:
76975 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76976 + if (!grsec_enable_blackhole)
76977 +#endif
76978 tcp_v6_send_reset(sk, skb);
76979 discard:
76980 if (opt_skb)
76981 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76982 TCP_SKB_CB(skb)->sacked = 0;
76983
76984 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76985 - if (!sk)
76986 + if (!sk) {
76987 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76988 + ret = 1;
76989 +#endif
76990 goto no_tcp_socket;
76991 + }
76992
76993 process:
76994 - if (sk->sk_state == TCP_TIME_WAIT)
76995 + if (sk->sk_state == TCP_TIME_WAIT) {
76996 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76997 + ret = 2;
76998 +#endif
76999 goto do_time_wait;
77000 + }
77001
77002 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77003 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77004 @@ -1679,6 +1694,10 @@ no_tcp_socket:
77005 bad_packet:
77006 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77007 } else {
77008 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77009 + if (!grsec_enable_blackhole || (ret == 1 &&
77010 + (skb->dev->flags & IFF_LOOPBACK)))
77011 +#endif
77012 tcp_v6_send_reset(NULL, skb);
77013 }
77014
77015 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
77016 uid,
77017 0, /* non standard timer */
77018 0, /* open_requests have no inode */
77019 - 0, req);
77020 + 0,
77021 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77022 + NULL
77023 +#else
77024 + req
77025 +#endif
77026 + );
77027 }
77028
77029 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77030 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77031 sock_i_uid(sp),
77032 icsk->icsk_probes_out,
77033 sock_i_ino(sp),
77034 - atomic_read(&sp->sk_refcnt), sp,
77035 + atomic_read(&sp->sk_refcnt),
77036 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77037 + NULL,
77038 +#else
77039 + sp,
77040 +#endif
77041 jiffies_to_clock_t(icsk->icsk_rto),
77042 jiffies_to_clock_t(icsk->icsk_ack.ato),
77043 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77044 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77045 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77046 tw->tw_substate, 0, 0,
77047 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77048 - atomic_read(&tw->tw_refcnt), tw);
77049 + atomic_read(&tw->tw_refcnt),
77050 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77051 + NULL
77052 +#else
77053 + tw
77054 +#endif
77055 + );
77056 }
77057
77058 static int tcp6_seq_show(struct seq_file *seq, void *v)
77059 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77060 index f05099f..ea613f0 100644
77061 --- a/net/ipv6/udp.c
77062 +++ b/net/ipv6/udp.c
77063 @@ -50,6 +50,10 @@
77064 #include <linux/seq_file.h>
77065 #include "udp_impl.h"
77066
77067 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77068 +extern int grsec_enable_blackhole;
77069 +#endif
77070 +
77071 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77072 {
77073 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77074 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77075 return rc;
77076 drop:
77077 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77078 - atomic_inc(&sk->sk_drops);
77079 + atomic_inc_unchecked(&sk->sk_drops);
77080 kfree_skb(skb);
77081 return -1;
77082 }
77083 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77084 if (likely(skb1 == NULL))
77085 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77086 if (!skb1) {
77087 - atomic_inc(&sk->sk_drops);
77088 + atomic_inc_unchecked(&sk->sk_drops);
77089 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77090 IS_UDPLITE(sk));
77091 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77092 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77093 goto discard;
77094
77095 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77096 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77097 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77098 +#endif
77099 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77100
77101 kfree_skb(skb);
77102 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77103 0, 0L, 0,
77104 sock_i_uid(sp), 0,
77105 sock_i_ino(sp),
77106 - atomic_read(&sp->sk_refcnt), sp,
77107 - atomic_read(&sp->sk_drops));
77108 + atomic_read(&sp->sk_refcnt),
77109 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77110 + NULL,
77111 +#else
77112 + sp,
77113 +#endif
77114 + atomic_read_unchecked(&sp->sk_drops));
77115 }
77116
77117 int udp6_seq_show(struct seq_file *seq, void *v)
77118 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77119 index 6b9d5a0..4dffaf1 100644
77120 --- a/net/irda/ircomm/ircomm_tty.c
77121 +++ b/net/irda/ircomm/ircomm_tty.c
77122 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77123 add_wait_queue(&self->open_wait, &wait);
77124
77125 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77126 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77127 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77128
77129 /* As far as I can see, we protect open_count - Jean II */
77130 spin_lock_irqsave(&self->spinlock, flags);
77131 if (!tty_hung_up_p(filp)) {
77132 extra_count = 1;
77133 - self->open_count--;
77134 + local_dec(&self->open_count);
77135 }
77136 spin_unlock_irqrestore(&self->spinlock, flags);
77137 - self->blocked_open++;
77138 + local_inc(&self->blocked_open);
77139
77140 while (1) {
77141 if (tty->termios->c_cflag & CBAUD) {
77142 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77143 }
77144
77145 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77146 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77147 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77148
77149 schedule();
77150 }
77151 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77152 if (extra_count) {
77153 /* ++ is not atomic, so this should be protected - Jean II */
77154 spin_lock_irqsave(&self->spinlock, flags);
77155 - self->open_count++;
77156 + local_inc(&self->open_count);
77157 spin_unlock_irqrestore(&self->spinlock, flags);
77158 }
77159 - self->blocked_open--;
77160 + local_dec(&self->blocked_open);
77161
77162 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77163 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77164 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77165
77166 if (!retval)
77167 self->flags |= ASYNC_NORMAL_ACTIVE;
77168 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77169 }
77170 /* ++ is not atomic, so this should be protected - Jean II */
77171 spin_lock_irqsave(&self->spinlock, flags);
77172 - self->open_count++;
77173 + local_inc(&self->open_count);
77174
77175 tty->driver_data = self;
77176 self->tty = tty;
77177 spin_unlock_irqrestore(&self->spinlock, flags);
77178
77179 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77180 - self->line, self->open_count);
77181 + self->line, local_read(&self->open_count));
77182
77183 /* Not really used by us, but lets do it anyway */
77184 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77185 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77186 return;
77187 }
77188
77189 - if ((tty->count == 1) && (self->open_count != 1)) {
77190 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77191 /*
77192 * Uh, oh. tty->count is 1, which means that the tty
77193 * structure will be freed. state->count should always
77194 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77195 */
77196 IRDA_DEBUG(0, "%s(), bad serial port count; "
77197 "tty->count is 1, state->count is %d\n", __func__ ,
77198 - self->open_count);
77199 - self->open_count = 1;
77200 + local_read(&self->open_count));
77201 + local_set(&self->open_count, 1);
77202 }
77203
77204 - if (--self->open_count < 0) {
77205 + if (local_dec_return(&self->open_count) < 0) {
77206 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77207 - __func__, self->line, self->open_count);
77208 - self->open_count = 0;
77209 + __func__, self->line, local_read(&self->open_count));
77210 + local_set(&self->open_count, 0);
77211 }
77212 - if (self->open_count) {
77213 + if (local_read(&self->open_count)) {
77214 spin_unlock_irqrestore(&self->spinlock, flags);
77215
77216 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77217 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77218 tty->closing = 0;
77219 self->tty = NULL;
77220
77221 - if (self->blocked_open) {
77222 + if (local_read(&self->blocked_open)) {
77223 if (self->close_delay)
77224 schedule_timeout_interruptible(self->close_delay);
77225 wake_up_interruptible(&self->open_wait);
77226 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77227 spin_lock_irqsave(&self->spinlock, flags);
77228 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77229 self->tty = NULL;
77230 - self->open_count = 0;
77231 + local_set(&self->open_count, 0);
77232 spin_unlock_irqrestore(&self->spinlock, flags);
77233
77234 wake_up_interruptible(&self->open_wait);
77235 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77236 seq_putc(m, '\n');
77237
77238 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77239 - seq_printf(m, "Open count: %d\n", self->open_count);
77240 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77241 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77242 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77243
77244 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77245 index cd6f7a9..e63fe89 100644
77246 --- a/net/iucv/af_iucv.c
77247 +++ b/net/iucv/af_iucv.c
77248 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77249
77250 write_lock_bh(&iucv_sk_list.lock);
77251
77252 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77253 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77254 while (__iucv_get_sock_by_name(name)) {
77255 sprintf(name, "%08x",
77256 - atomic_inc_return(&iucv_sk_list.autobind_name));
77257 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77258 }
77259
77260 write_unlock_bh(&iucv_sk_list.lock);
77261 diff --git a/net/key/af_key.c b/net/key/af_key.c
77262 index 34e4185..8823368 100644
77263 --- a/net/key/af_key.c
77264 +++ b/net/key/af_key.c
77265 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77266 static u32 get_acqseq(void)
77267 {
77268 u32 res;
77269 - static atomic_t acqseq;
77270 + static atomic_unchecked_t acqseq;
77271
77272 do {
77273 - res = atomic_inc_return(&acqseq);
77274 + res = atomic_inc_return_unchecked(&acqseq);
77275 } while (!res);
77276 return res;
77277 }
77278 diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
77279 index 35e1e4b..9275471 100644
77280 --- a/net/l2tp/l2tp_ip6.c
77281 +++ b/net/l2tp/l2tp_ip6.c
77282 @@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
77283 lsa->l2tp_family = AF_INET6;
77284 lsa->l2tp_flowinfo = 0;
77285 lsa->l2tp_scope_id = 0;
77286 + lsa->l2tp_unused = 0;
77287 if (peer) {
77288 if (!lsk->peer_conn_id)
77289 return -ENOTCONN;
77290 diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
77291 index fe5453c..a13c3e23 100644
77292 --- a/net/llc/af_llc.c
77293 +++ b/net/llc/af_llc.c
77294 @@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
77295 struct sockaddr_llc sllc;
77296 struct sock *sk = sock->sk;
77297 struct llc_sock *llc = llc_sk(sk);
77298 - int rc = 0;
77299 + int rc = -EBADF;
77300
77301 memset(&sllc, 0, sizeof(sllc));
77302 lock_sock(sk);
77303 if (sock_flag(sk, SOCK_ZAPPED))
77304 goto out;
77305 *uaddrlen = sizeof(sllc);
77306 - memset(uaddr, 0, *uaddrlen);
77307 if (peer) {
77308 rc = -ENOTCONN;
77309 if (sk->sk_state != TCP_ESTABLISHED)
77310 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77311 index 3f3cd50..d2cf249 100644
77312 --- a/net/mac80211/ieee80211_i.h
77313 +++ b/net/mac80211/ieee80211_i.h
77314 @@ -28,6 +28,7 @@
77315 #include <net/ieee80211_radiotap.h>
77316 #include <net/cfg80211.h>
77317 #include <net/mac80211.h>
77318 +#include <asm/local.h>
77319 #include "key.h"
77320 #include "sta_info.h"
77321
77322 @@ -863,7 +864,7 @@ struct ieee80211_local {
77323 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77324 spinlock_t queue_stop_reason_lock;
77325
77326 - int open_count;
77327 + local_t open_count;
77328 int monitors, cooked_mntrs;
77329 /* number of interfaces with corresponding FIF_ flags */
77330 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77331 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77332 index 8664111..1d6a065 100644
77333 --- a/net/mac80211/iface.c
77334 +++ b/net/mac80211/iface.c
77335 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77336 break;
77337 }
77338
77339 - if (local->open_count == 0) {
77340 + if (local_read(&local->open_count) == 0) {
77341 res = drv_start(local);
77342 if (res)
77343 goto err_del_bss;
77344 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77345 break;
77346 }
77347
77348 - if (local->monitors == 0 && local->open_count == 0) {
77349 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77350 res = ieee80211_add_virtual_monitor(local);
77351 if (res)
77352 goto err_stop;
77353 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77354 mutex_unlock(&local->mtx);
77355
77356 if (coming_up)
77357 - local->open_count++;
77358 + local_inc(&local->open_count);
77359
77360 if (hw_reconf_flags)
77361 ieee80211_hw_config(local, hw_reconf_flags);
77362 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77363 err_del_interface:
77364 drv_remove_interface(local, sdata);
77365 err_stop:
77366 - if (!local->open_count)
77367 + if (!local_read(&local->open_count))
77368 drv_stop(local);
77369 err_del_bss:
77370 sdata->bss = NULL;
77371 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77372 }
77373
77374 if (going_down)
77375 - local->open_count--;
77376 + local_dec(&local->open_count);
77377
77378 switch (sdata->vif.type) {
77379 case NL80211_IFTYPE_AP_VLAN:
77380 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77381
77382 ieee80211_recalc_ps(local, -1);
77383
77384 - if (local->open_count == 0) {
77385 + if (local_read(&local->open_count) == 0) {
77386 if (local->ops->napi_poll)
77387 napi_disable(&local->napi);
77388 ieee80211_clear_tx_pending(local);
77389 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77390 }
77391 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77392
77393 - if (local->monitors == local->open_count && local->monitors > 0)
77394 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77395 ieee80211_add_virtual_monitor(local);
77396 }
77397
77398 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77399 index f5548e9..474a15f 100644
77400 --- a/net/mac80211/main.c
77401 +++ b/net/mac80211/main.c
77402 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77403 local->hw.conf.power_level = power;
77404 }
77405
77406 - if (changed && local->open_count) {
77407 + if (changed && local_read(&local->open_count)) {
77408 ret = drv_config(local, changed);
77409 /*
77410 * Goal:
77411 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77412 index af1c4e2..24dbbe3 100644
77413 --- a/net/mac80211/pm.c
77414 +++ b/net/mac80211/pm.c
77415 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77416 struct ieee80211_sub_if_data *sdata;
77417 struct sta_info *sta;
77418
77419 - if (!local->open_count)
77420 + if (!local_read(&local->open_count))
77421 goto suspend;
77422
77423 ieee80211_scan_cancel(local);
77424 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77425 cancel_work_sync(&local->dynamic_ps_enable_work);
77426 del_timer_sync(&local->dynamic_ps_timer);
77427
77428 - local->wowlan = wowlan && local->open_count;
77429 + local->wowlan = wowlan && local_read(&local->open_count);
77430 if (local->wowlan) {
77431 int err = drv_suspend(local, wowlan);
77432 if (err < 0) {
77433 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77434 drv_remove_interface(local, sdata);
77435
77436 /* stop hardware - this must stop RX */
77437 - if (local->open_count)
77438 + if (local_read(&local->open_count))
77439 ieee80211_stop_device(local);
77440
77441 suspend:
77442 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77443 index 3313c11..bec9f17 100644
77444 --- a/net/mac80211/rate.c
77445 +++ b/net/mac80211/rate.c
77446 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77447
77448 ASSERT_RTNL();
77449
77450 - if (local->open_count)
77451 + if (local_read(&local->open_count))
77452 return -EBUSY;
77453
77454 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77455 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77456 index c97a065..ff61928 100644
77457 --- a/net/mac80211/rc80211_pid_debugfs.c
77458 +++ b/net/mac80211/rc80211_pid_debugfs.c
77459 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77460
77461 spin_unlock_irqrestore(&events->lock, status);
77462
77463 - if (copy_to_user(buf, pb, p))
77464 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77465 return -EFAULT;
77466
77467 return p;
77468 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77469 index f564b5e..22fee47 100644
77470 --- a/net/mac80211/util.c
77471 +++ b/net/mac80211/util.c
77472 @@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77473 }
77474 #endif
77475 /* everything else happens only if HW was up & running */
77476 - if (!local->open_count)
77477 + if (!local_read(&local->open_count))
77478 goto wake_up;
77479
77480 /*
77481 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77482 index 209c1ed..39484dc 100644
77483 --- a/net/netfilter/Kconfig
77484 +++ b/net/netfilter/Kconfig
77485 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77486
77487 To compile it as a module, choose M here. If unsure, say N.
77488
77489 +config NETFILTER_XT_MATCH_GRADM
77490 + tristate '"gradm" match support'
77491 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77492 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77493 + ---help---
77494 + The gradm match allows to match on grsecurity RBAC being enabled.
77495 + It is useful when iptables rules are applied early on bootup to
77496 + prevent connections to the machine (except from a trusted host)
77497 + while the RBAC system is disabled.
77498 +
77499 config NETFILTER_XT_MATCH_HASHLIMIT
77500 tristate '"hashlimit" match support'
77501 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77502 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77503 index 4e7960c..89e48d4 100644
77504 --- a/net/netfilter/Makefile
77505 +++ b/net/netfilter/Makefile
77506 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77507 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77508 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77509 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77510 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77511 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77512 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77513 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77514 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77515 index 1548df9..98ad9b4 100644
77516 --- a/net/netfilter/ipvs/ip_vs_conn.c
77517 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77518 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77519 /* Increase the refcnt counter of the dest */
77520 atomic_inc(&dest->refcnt);
77521
77522 - conn_flags = atomic_read(&dest->conn_flags);
77523 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77524 if (cp->protocol != IPPROTO_UDP)
77525 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77526 flags = cp->flags;
77527 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77528 atomic_set(&cp->refcnt, 1);
77529
77530 atomic_set(&cp->n_control, 0);
77531 - atomic_set(&cp->in_pkts, 0);
77532 + atomic_set_unchecked(&cp->in_pkts, 0);
77533
77534 atomic_inc(&ipvs->conn_count);
77535 if (flags & IP_VS_CONN_F_NO_CPORT)
77536 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77537
77538 /* Don't drop the entry if its number of incoming packets is not
77539 located in [0, 8] */
77540 - i = atomic_read(&cp->in_pkts);
77541 + i = atomic_read_unchecked(&cp->in_pkts);
77542 if (i > 8 || i < 0) return 0;
77543
77544 if (!todrop_rate[i]) return 0;
77545 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77546 index a54b018c..07e0120 100644
77547 --- a/net/netfilter/ipvs/ip_vs_core.c
77548 +++ b/net/netfilter/ipvs/ip_vs_core.c
77549 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77550 ret = cp->packet_xmit(skb, cp, pd->pp);
77551 /* do not touch skb anymore */
77552
77553 - atomic_inc(&cp->in_pkts);
77554 + atomic_inc_unchecked(&cp->in_pkts);
77555 ip_vs_conn_put(cp);
77556 return ret;
77557 }
77558 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77559 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77560 pkts = sysctl_sync_threshold(ipvs);
77561 else
77562 - pkts = atomic_add_return(1, &cp->in_pkts);
77563 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77564
77565 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77566 ip_vs_sync_conn(net, cp, pkts);
77567 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77568 index 84444dd..f91c066 100644
77569 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77570 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77571 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77572 ip_vs_rs_hash(ipvs, dest);
77573 write_unlock_bh(&ipvs->rs_lock);
77574 }
77575 - atomic_set(&dest->conn_flags, conn_flags);
77576 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77577
77578 /* bind the service */
77579 if (!dest->svc) {
77580 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77581 " %-7s %-6d %-10d %-10d\n",
77582 &dest->addr.in6,
77583 ntohs(dest->port),
77584 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77585 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77586 atomic_read(&dest->weight),
77587 atomic_read(&dest->activeconns),
77588 atomic_read(&dest->inactconns));
77589 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77590 "%-7s %-6d %-10d %-10d\n",
77591 ntohl(dest->addr.ip),
77592 ntohs(dest->port),
77593 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77594 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77595 atomic_read(&dest->weight),
77596 atomic_read(&dest->activeconns),
77597 atomic_read(&dest->inactconns));
77598 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77599
77600 entry.addr = dest->addr.ip;
77601 entry.port = dest->port;
77602 - entry.conn_flags = atomic_read(&dest->conn_flags);
77603 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77604 entry.weight = atomic_read(&dest->weight);
77605 entry.u_threshold = dest->u_threshold;
77606 entry.l_threshold = dest->l_threshold;
77607 @@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77608 {
77609 struct ip_vs_timeout_user t;
77610
77611 + memset(&t, 0, sizeof(t));
77612 __ip_vs_get_timeouts(net, &t);
77613 if (copy_to_user(user, &t, sizeof(t)) != 0)
77614 ret = -EFAULT;
77615 @@ -3089,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77616 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77617 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77618 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77619 - (atomic_read(&dest->conn_flags) &
77620 + (atomic_read_unchecked(&dest->conn_flags) &
77621 IP_VS_CONN_F_FWD_MASK)) ||
77622 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77623 atomic_read(&dest->weight)) ||
77624 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77625 index effa10c..9058928 100644
77626 --- a/net/netfilter/ipvs/ip_vs_sync.c
77627 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77628 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77629 cp = cp->control;
77630 if (cp) {
77631 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77632 - pkts = atomic_add_return(1, &cp->in_pkts);
77633 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77634 else
77635 pkts = sysctl_sync_threshold(ipvs);
77636 ip_vs_sync_conn(net, cp->control, pkts);
77637 @@ -758,7 +758,7 @@ control:
77638 if (!cp)
77639 return;
77640 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77641 - pkts = atomic_add_return(1, &cp->in_pkts);
77642 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77643 else
77644 pkts = sysctl_sync_threshold(ipvs);
77645 goto sloop;
77646 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77647
77648 if (opt)
77649 memcpy(&cp->in_seq, opt, sizeof(*opt));
77650 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77651 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77652 cp->state = state;
77653 cp->old_state = cp->state;
77654 /*
77655 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77656 index 7fd66de..e6fb361 100644
77657 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77658 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77659 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77660 else
77661 rc = NF_ACCEPT;
77662 /* do not touch skb anymore */
77663 - atomic_inc(&cp->in_pkts);
77664 + atomic_inc_unchecked(&cp->in_pkts);
77665 goto out;
77666 }
77667
77668 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77669 else
77670 rc = NF_ACCEPT;
77671 /* do not touch skb anymore */
77672 - atomic_inc(&cp->in_pkts);
77673 + atomic_inc_unchecked(&cp->in_pkts);
77674 goto out;
77675 }
77676
77677 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77678 index ac3af97..c134c21 100644
77679 --- a/net/netfilter/nf_conntrack_core.c
77680 +++ b/net/netfilter/nf_conntrack_core.c
77681 @@ -1530,6 +1530,10 @@ err_proto:
77682 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77683 #define DYING_NULLS_VAL ((1<<30)+1)
77684
77685 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77686 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77687 +#endif
77688 +
77689 static int nf_conntrack_init_net(struct net *net)
77690 {
77691 int ret;
77692 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77693 goto err_stat;
77694 }
77695
77696 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77697 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77698 +#else
77699 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77700 +#endif
77701 if (!net->ct.slabname) {
77702 ret = -ENOMEM;
77703 goto err_slabname;
77704 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77705 index 3c3cfc0..7a6ea1a 100644
77706 --- a/net/netfilter/nfnetlink_log.c
77707 +++ b/net/netfilter/nfnetlink_log.c
77708 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77709 };
77710
77711 static DEFINE_SPINLOCK(instances_lock);
77712 -static atomic_t global_seq;
77713 +static atomic_unchecked_t global_seq;
77714
77715 #define INSTANCE_BUCKETS 16
77716 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77717 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77718 /* global sequence number */
77719 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77720 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77721 - htonl(atomic_inc_return(&global_seq))))
77722 + htonl(atomic_inc_return_unchecked(&global_seq))))
77723 goto nla_put_failure;
77724
77725 if (data_len) {
77726 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77727 new file mode 100644
77728 index 0000000..6905327
77729 --- /dev/null
77730 +++ b/net/netfilter/xt_gradm.c
77731 @@ -0,0 +1,51 @@
77732 +/*
77733 + * gradm match for netfilter
77734 + * Copyright © Zbigniew Krzystolik, 2010
77735 + *
77736 + * This program is free software; you can redistribute it and/or modify
77737 + * it under the terms of the GNU General Public License; either version
77738 + * 2 or 3 as published by the Free Software Foundation.
77739 + */
77740 +#include <linux/module.h>
77741 +#include <linux/moduleparam.h>
77742 +#include <linux/skbuff.h>
77743 +#include <linux/netfilter/x_tables.h>
77744 +#include <linux/grsecurity.h>
77745 +#include <linux/netfilter/xt_gradm.h>
77746 +
77747 +static bool
77748 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77749 +{
77750 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77751 + bool retval = false;
77752 + if (gr_acl_is_enabled())
77753 + retval = true;
77754 + return retval ^ info->invflags;
77755 +}
77756 +
77757 +static struct xt_match gradm_mt_reg __read_mostly = {
77758 + .name = "gradm",
77759 + .revision = 0,
77760 + .family = NFPROTO_UNSPEC,
77761 + .match = gradm_mt,
77762 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77763 + .me = THIS_MODULE,
77764 +};
77765 +
77766 +static int __init gradm_mt_init(void)
77767 +{
77768 + return xt_register_match(&gradm_mt_reg);
77769 +}
77770 +
77771 +static void __exit gradm_mt_exit(void)
77772 +{
77773 + xt_unregister_match(&gradm_mt_reg);
77774 +}
77775 +
77776 +module_init(gradm_mt_init);
77777 +module_exit(gradm_mt_exit);
77778 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77779 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77780 +MODULE_LICENSE("GPL");
77781 +MODULE_ALIAS("ipt_gradm");
77782 +MODULE_ALIAS("ip6t_gradm");
77783 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77784 index 4fe4fb4..87a89e5 100644
77785 --- a/net/netfilter/xt_statistic.c
77786 +++ b/net/netfilter/xt_statistic.c
77787 @@ -19,7 +19,7 @@
77788 #include <linux/module.h>
77789
77790 struct xt_statistic_priv {
77791 - atomic_t count;
77792 + atomic_unchecked_t count;
77793 } ____cacheline_aligned_in_smp;
77794
77795 MODULE_LICENSE("GPL");
77796 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77797 break;
77798 case XT_STATISTIC_MODE_NTH:
77799 do {
77800 - oval = atomic_read(&info->master->count);
77801 + oval = atomic_read_unchecked(&info->master->count);
77802 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77803 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77804 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77805 if (nval == 0)
77806 ret = !ret;
77807 break;
77808 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77809 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77810 if (info->master == NULL)
77811 return -ENOMEM;
77812 - atomic_set(&info->master->count, info->u.nth.count);
77813 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77814
77815 return 0;
77816 }
77817 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77818 index b3025a6..e717db9 100644
77819 --- a/net/netlink/af_netlink.c
77820 +++ b/net/netlink/af_netlink.c
77821 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
77822 sk->sk_error_report(sk);
77823 }
77824 }
77825 - atomic_inc(&sk->sk_drops);
77826 + atomic_inc_unchecked(&sk->sk_drops);
77827 }
77828
77829 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77830 @@ -1344,7 +1344,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
77831 if (NULL == siocb->scm)
77832 siocb->scm = &scm;
77833
77834 - err = scm_send(sock, msg, siocb->scm);
77835 + err = scm_send(sock, msg, siocb->scm, true);
77836 if (err < 0)
77837 return err;
77838
77839 @@ -1355,7 +1355,8 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
77840 dst_pid = addr->nl_pid;
77841 dst_group = ffs(addr->nl_groups);
77842 err = -EPERM;
77843 - if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND))
77844 + if ((dst_group || dst_pid) &&
77845 + !netlink_capable(sock, NL_NONROOT_SEND))
77846 goto out;
77847 } else {
77848 dst_pid = nlk->dst_pid;
77849 @@ -2022,7 +2023,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77850 sk_wmem_alloc_get(s),
77851 nlk->cb,
77852 atomic_read(&s->sk_refcnt),
77853 - atomic_read(&s->sk_drops),
77854 + atomic_read_unchecked(&s->sk_drops),
77855 sock_i_ino(s)
77856 );
77857
77858 @@ -2124,6 +2125,7 @@ static void __init netlink_add_usersock_entry(void)
77859 rcu_assign_pointer(nl_table[NETLINK_USERSOCK].listeners, listeners);
77860 nl_table[NETLINK_USERSOCK].module = THIS_MODULE;
77861 nl_table[NETLINK_USERSOCK].registered = 1;
77862 + nl_table[NETLINK_USERSOCK].nl_nonroot = NL_NONROOT_SEND;
77863
77864 netlink_table_ungrab();
77865 }
77866 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77867 index 06592d8..64860f6 100644
77868 --- a/net/netrom/af_netrom.c
77869 +++ b/net/netrom/af_netrom.c
77870 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77871 struct sock *sk = sock->sk;
77872 struct nr_sock *nr = nr_sk(sk);
77873
77874 + memset(sax, 0, sizeof(*sax));
77875 lock_sock(sk);
77876 if (peer != 0) {
77877 if (sk->sk_state != TCP_ESTABLISHED) {
77878 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77879 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77880 } else {
77881 sax->fsa_ax25.sax25_family = AF_NETROM;
77882 - sax->fsa_ax25.sax25_ndigis = 0;
77883 sax->fsa_ax25.sax25_call = nr->source_addr;
77884 *uaddr_len = sizeof(struct sockaddr_ax25);
77885 }
77886 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77887 index 0f66174..e7cb04c 100644
77888 --- a/net/packet/af_packet.c
77889 +++ b/net/packet/af_packet.c
77890 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77891
77892 spin_lock(&sk->sk_receive_queue.lock);
77893 po->stats.tp_packets++;
77894 - skb->dropcount = atomic_read(&sk->sk_drops);
77895 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77896 __skb_queue_tail(&sk->sk_receive_queue, skb);
77897 spin_unlock(&sk->sk_receive_queue.lock);
77898 sk->sk_data_ready(sk, skb->len);
77899 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77900 drop_n_acct:
77901 spin_lock(&sk->sk_receive_queue.lock);
77902 po->stats.tp_drops++;
77903 - atomic_inc(&sk->sk_drops);
77904 + atomic_inc_unchecked(&sk->sk_drops);
77905 spin_unlock(&sk->sk_receive_queue.lock);
77906
77907 drop_n_restore:
77908 @@ -2641,6 +2641,7 @@ out:
77909
77910 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77911 {
77912 + struct sock_extended_err ee;
77913 struct sock_exterr_skb *serr;
77914 struct sk_buff *skb, *skb2;
77915 int copied, err;
77916 @@ -2662,8 +2663,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77917 sock_recv_timestamp(msg, sk, skb);
77918
77919 serr = SKB_EXT_ERR(skb);
77920 + ee = serr->ee;
77921 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
77922 - sizeof(serr->ee), &serr->ee);
77923 + sizeof ee, &ee);
77924
77925 msg->msg_flags |= MSG_ERRQUEUE;
77926 err = copied;
77927 @@ -3275,7 +3277,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77928 case PACKET_HDRLEN:
77929 if (len > sizeof(int))
77930 len = sizeof(int);
77931 - if (copy_from_user(&val, optval, len))
77932 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77933 return -EFAULT;
77934 switch (val) {
77935 case TPACKET_V1:
77936 @@ -3314,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77937 len = lv;
77938 if (put_user(len, optlen))
77939 return -EFAULT;
77940 - if (copy_to_user(optval, data, len))
77941 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77942 return -EFAULT;
77943 return 0;
77944 }
77945 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77946 index 5a940db..f0b9c12 100644
77947 --- a/net/phonet/af_phonet.c
77948 +++ b/net/phonet/af_phonet.c
77949 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77950 {
77951 struct phonet_protocol *pp;
77952
77953 - if (protocol >= PHONET_NPROTO)
77954 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77955 return NULL;
77956
77957 rcu_read_lock();
77958 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77959 {
77960 int err = 0;
77961
77962 - if (protocol >= PHONET_NPROTO)
77963 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77964 return -EINVAL;
77965
77966 err = proto_register(pp->prot, 1);
77967 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77968 index 576f22c..bc7a71b 100644
77969 --- a/net/phonet/pep.c
77970 +++ b/net/phonet/pep.c
77971 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77972
77973 case PNS_PEP_CTRL_REQ:
77974 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77975 - atomic_inc(&sk->sk_drops);
77976 + atomic_inc_unchecked(&sk->sk_drops);
77977 break;
77978 }
77979 __skb_pull(skb, 4);
77980 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77981 }
77982
77983 if (pn->rx_credits == 0) {
77984 - atomic_inc(&sk->sk_drops);
77985 + atomic_inc_unchecked(&sk->sk_drops);
77986 err = -ENOBUFS;
77987 break;
77988 }
77989 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77990 }
77991
77992 if (pn->rx_credits == 0) {
77993 - atomic_inc(&sk->sk_drops);
77994 + atomic_inc_unchecked(&sk->sk_drops);
77995 err = NET_RX_DROP;
77996 break;
77997 }
77998 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77999 index 0acc943..c727611 100644
78000 --- a/net/phonet/socket.c
78001 +++ b/net/phonet/socket.c
78002 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78003 pn->resource, sk->sk_state,
78004 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78005 sock_i_uid(sk), sock_i_ino(sk),
78006 - atomic_read(&sk->sk_refcnt), sk,
78007 - atomic_read(&sk->sk_drops), &len);
78008 + atomic_read(&sk->sk_refcnt),
78009 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78010 + NULL,
78011 +#else
78012 + sk,
78013 +#endif
78014 + atomic_read_unchecked(&sk->sk_drops), &len);
78015 }
78016 seq_printf(seq, "%*s\n", 127 - len, "");
78017 return 0;
78018 diff --git a/net/rds/cong.c b/net/rds/cong.c
78019 index e5b65ac..f3b6fb7 100644
78020 --- a/net/rds/cong.c
78021 +++ b/net/rds/cong.c
78022 @@ -78,7 +78,7 @@
78023 * finds that the saved generation number is smaller than the global generation
78024 * number, it wakes up the process.
78025 */
78026 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78027 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78028
78029 /*
78030 * Congestion monitoring
78031 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78032 rdsdebug("waking map %p for %pI4\n",
78033 map, &map->m_addr);
78034 rds_stats_inc(s_cong_update_received);
78035 - atomic_inc(&rds_cong_generation);
78036 + atomic_inc_unchecked(&rds_cong_generation);
78037 if (waitqueue_active(&map->m_waitq))
78038 wake_up(&map->m_waitq);
78039 if (waitqueue_active(&rds_poll_waitq))
78040 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78041
78042 int rds_cong_updated_since(unsigned long *recent)
78043 {
78044 - unsigned long gen = atomic_read(&rds_cong_generation);
78045 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78046
78047 if (likely(*recent == gen))
78048 return 0;
78049 diff --git a/net/rds/ib.h b/net/rds/ib.h
78050 index 8d2b3d5..227ec5b 100644
78051 --- a/net/rds/ib.h
78052 +++ b/net/rds/ib.h
78053 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78054 /* sending acks */
78055 unsigned long i_ack_flags;
78056 #ifdef KERNEL_HAS_ATOMIC64
78057 - atomic64_t i_ack_next; /* next ACK to send */
78058 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78059 #else
78060 spinlock_t i_ack_lock; /* protect i_ack_next */
78061 u64 i_ack_next; /* next ACK to send */
78062 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78063 index a1e1162..265e129 100644
78064 --- a/net/rds/ib_cm.c
78065 +++ b/net/rds/ib_cm.c
78066 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78067 /* Clear the ACK state */
78068 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78069 #ifdef KERNEL_HAS_ATOMIC64
78070 - atomic64_set(&ic->i_ack_next, 0);
78071 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78072 #else
78073 ic->i_ack_next = 0;
78074 #endif
78075 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78076 index 8d19491..05a3e65 100644
78077 --- a/net/rds/ib_recv.c
78078 +++ b/net/rds/ib_recv.c
78079 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78080 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78081 int ack_required)
78082 {
78083 - atomic64_set(&ic->i_ack_next, seq);
78084 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78085 if (ack_required) {
78086 smp_mb__before_clear_bit();
78087 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78088 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78089 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78090 smp_mb__after_clear_bit();
78091
78092 - return atomic64_read(&ic->i_ack_next);
78093 + return atomic64_read_unchecked(&ic->i_ack_next);
78094 }
78095 #endif
78096
78097 diff --git a/net/rds/iw.h b/net/rds/iw.h
78098 index 04ce3b1..48119a6 100644
78099 --- a/net/rds/iw.h
78100 +++ b/net/rds/iw.h
78101 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78102 /* sending acks */
78103 unsigned long i_ack_flags;
78104 #ifdef KERNEL_HAS_ATOMIC64
78105 - atomic64_t i_ack_next; /* next ACK to send */
78106 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78107 #else
78108 spinlock_t i_ack_lock; /* protect i_ack_next */
78109 u64 i_ack_next; /* next ACK to send */
78110 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78111 index a91e1db..cf3053f 100644
78112 --- a/net/rds/iw_cm.c
78113 +++ b/net/rds/iw_cm.c
78114 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78115 /* Clear the ACK state */
78116 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78117 #ifdef KERNEL_HAS_ATOMIC64
78118 - atomic64_set(&ic->i_ack_next, 0);
78119 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78120 #else
78121 ic->i_ack_next = 0;
78122 #endif
78123 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78124 index 4503335..db566b4 100644
78125 --- a/net/rds/iw_recv.c
78126 +++ b/net/rds/iw_recv.c
78127 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78128 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78129 int ack_required)
78130 {
78131 - atomic64_set(&ic->i_ack_next, seq);
78132 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78133 if (ack_required) {
78134 smp_mb__before_clear_bit();
78135 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78136 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78137 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78138 smp_mb__after_clear_bit();
78139
78140 - return atomic64_read(&ic->i_ack_next);
78141 + return atomic64_read_unchecked(&ic->i_ack_next);
78142 }
78143 #endif
78144
78145 diff --git a/net/rds/recv.c b/net/rds/recv.c
78146 index 5c6e9f1..9f0f17c 100644
78147 --- a/net/rds/recv.c
78148 +++ b/net/rds/recv.c
78149 @@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
78150
78151 rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
78152
78153 + msg->msg_namelen = 0;
78154 +
78155 if (msg_flags & MSG_OOB)
78156 goto out;
78157
78158 @@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
78159 sin->sin_port = inc->i_hdr.h_sport;
78160 sin->sin_addr.s_addr = inc->i_saddr;
78161 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
78162 + msg->msg_namelen = sizeof(*sin);
78163 }
78164 break;
78165 }
78166 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78167 index edac9ef..16bcb98 100644
78168 --- a/net/rds/tcp.c
78169 +++ b/net/rds/tcp.c
78170 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78171 int val = 1;
78172
78173 set_fs(KERNEL_DS);
78174 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78175 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78176 sizeof(val));
78177 set_fs(oldfs);
78178 }
78179 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78180 index 1b4fd68..2234175 100644
78181 --- a/net/rds/tcp_send.c
78182 +++ b/net/rds/tcp_send.c
78183 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78184
78185 oldfs = get_fs();
78186 set_fs(KERNEL_DS);
78187 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78188 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78189 sizeof(val));
78190 set_fs(oldfs);
78191 }
78192 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78193 index 05996d0..5a1dfe0 100644
78194 --- a/net/rxrpc/af_rxrpc.c
78195 +++ b/net/rxrpc/af_rxrpc.c
78196 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78197 __be32 rxrpc_epoch;
78198
78199 /* current debugging ID */
78200 -atomic_t rxrpc_debug_id;
78201 +atomic_unchecked_t rxrpc_debug_id;
78202
78203 /* count of skbs currently in use */
78204 atomic_t rxrpc_n_skbs;
78205 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78206 index e4d9cbc..b229649 100644
78207 --- a/net/rxrpc/ar-ack.c
78208 +++ b/net/rxrpc/ar-ack.c
78209 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78210
78211 _enter("{%d,%d,%d,%d},",
78212 call->acks_hard, call->acks_unacked,
78213 - atomic_read(&call->sequence),
78214 + atomic_read_unchecked(&call->sequence),
78215 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78216
78217 stop = 0;
78218 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78219
78220 /* each Tx packet has a new serial number */
78221 sp->hdr.serial =
78222 - htonl(atomic_inc_return(&call->conn->serial));
78223 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78224
78225 hdr = (struct rxrpc_header *) txb->head;
78226 hdr->serial = sp->hdr.serial;
78227 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78228 */
78229 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78230 {
78231 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78232 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78233 }
78234
78235 /*
78236 @@ -629,7 +629,7 @@ process_further:
78237
78238 latest = ntohl(sp->hdr.serial);
78239 hard = ntohl(ack.firstPacket);
78240 - tx = atomic_read(&call->sequence);
78241 + tx = atomic_read_unchecked(&call->sequence);
78242
78243 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78244 latest,
78245 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78246 goto maybe_reschedule;
78247
78248 send_ACK_with_skew:
78249 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78250 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78251 ntohl(ack.serial));
78252 send_ACK:
78253 mtu = call->conn->trans->peer->if_mtu;
78254 @@ -1173,7 +1173,7 @@ send_ACK:
78255 ackinfo.rxMTU = htonl(5692);
78256 ackinfo.jumbo_max = htonl(4);
78257
78258 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78259 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78260 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78261 ntohl(hdr.serial),
78262 ntohs(ack.maxSkew),
78263 @@ -1191,7 +1191,7 @@ send_ACK:
78264 send_message:
78265 _debug("send message");
78266
78267 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78268 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78269 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78270 send_message_2:
78271
78272 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78273 index a3bbb36..3341fb9 100644
78274 --- a/net/rxrpc/ar-call.c
78275 +++ b/net/rxrpc/ar-call.c
78276 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78277 spin_lock_init(&call->lock);
78278 rwlock_init(&call->state_lock);
78279 atomic_set(&call->usage, 1);
78280 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78281 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78282 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78283
78284 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78285 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78286 index 4106ca9..a338d7a 100644
78287 --- a/net/rxrpc/ar-connection.c
78288 +++ b/net/rxrpc/ar-connection.c
78289 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78290 rwlock_init(&conn->lock);
78291 spin_lock_init(&conn->state_lock);
78292 atomic_set(&conn->usage, 1);
78293 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78294 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78295 conn->avail_calls = RXRPC_MAXCALLS;
78296 conn->size_align = 4;
78297 conn->header_size = sizeof(struct rxrpc_header);
78298 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78299 index e7ed43a..6afa140 100644
78300 --- a/net/rxrpc/ar-connevent.c
78301 +++ b/net/rxrpc/ar-connevent.c
78302 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78303
78304 len = iov[0].iov_len + iov[1].iov_len;
78305
78306 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78307 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78308 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78309
78310 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78311 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78312 index 529572f..c758ca7 100644
78313 --- a/net/rxrpc/ar-input.c
78314 +++ b/net/rxrpc/ar-input.c
78315 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78316 /* track the latest serial number on this connection for ACK packet
78317 * information */
78318 serial = ntohl(sp->hdr.serial);
78319 - hi_serial = atomic_read(&call->conn->hi_serial);
78320 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78321 while (serial > hi_serial)
78322 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78323 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78324 serial);
78325
78326 /* request ACK generation for any ACK or DATA packet that requests
78327 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78328 index a693aca..81e7293 100644
78329 --- a/net/rxrpc/ar-internal.h
78330 +++ b/net/rxrpc/ar-internal.h
78331 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78332 int error; /* error code for local abort */
78333 int debug_id; /* debug ID for printks */
78334 unsigned int call_counter; /* call ID counter */
78335 - atomic_t serial; /* packet serial number counter */
78336 - atomic_t hi_serial; /* highest serial number received */
78337 + atomic_unchecked_t serial; /* packet serial number counter */
78338 + atomic_unchecked_t hi_serial; /* highest serial number received */
78339 u8 avail_calls; /* number of calls available */
78340 u8 size_align; /* data size alignment (for security) */
78341 u8 header_size; /* rxrpc + security header size */
78342 @@ -346,7 +346,7 @@ struct rxrpc_call {
78343 spinlock_t lock;
78344 rwlock_t state_lock; /* lock for state transition */
78345 atomic_t usage;
78346 - atomic_t sequence; /* Tx data packet sequence counter */
78347 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78348 u32 abort_code; /* local/remote abort code */
78349 enum { /* current state of call */
78350 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78351 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78352 */
78353 extern atomic_t rxrpc_n_skbs;
78354 extern __be32 rxrpc_epoch;
78355 -extern atomic_t rxrpc_debug_id;
78356 +extern atomic_unchecked_t rxrpc_debug_id;
78357 extern struct workqueue_struct *rxrpc_workqueue;
78358
78359 /*
78360 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78361 index 87f7135..74d3703 100644
78362 --- a/net/rxrpc/ar-local.c
78363 +++ b/net/rxrpc/ar-local.c
78364 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78365 spin_lock_init(&local->lock);
78366 rwlock_init(&local->services_lock);
78367 atomic_set(&local->usage, 1);
78368 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78369 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78370 memcpy(&local->srx, srx, sizeof(*srx));
78371 }
78372
78373 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78374 index 16ae887..d24f12b 100644
78375 --- a/net/rxrpc/ar-output.c
78376 +++ b/net/rxrpc/ar-output.c
78377 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78378 sp->hdr.cid = call->cid;
78379 sp->hdr.callNumber = call->call_id;
78380 sp->hdr.seq =
78381 - htonl(atomic_inc_return(&call->sequence));
78382 + htonl(atomic_inc_return_unchecked(&call->sequence));
78383 sp->hdr.serial =
78384 - htonl(atomic_inc_return(&conn->serial));
78385 + htonl(atomic_inc_return_unchecked(&conn->serial));
78386 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78387 sp->hdr.userStatus = 0;
78388 sp->hdr.securityIndex = conn->security_ix;
78389 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78390 index bebaa43..2644591 100644
78391 --- a/net/rxrpc/ar-peer.c
78392 +++ b/net/rxrpc/ar-peer.c
78393 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78394 INIT_LIST_HEAD(&peer->error_targets);
78395 spin_lock_init(&peer->lock);
78396 atomic_set(&peer->usage, 1);
78397 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78398 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78399 memcpy(&peer->srx, srx, sizeof(*srx));
78400
78401 rxrpc_assess_MTU_size(peer);
78402 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78403 index 38047f7..9f48511 100644
78404 --- a/net/rxrpc/ar-proc.c
78405 +++ b/net/rxrpc/ar-proc.c
78406 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78407 atomic_read(&conn->usage),
78408 rxrpc_conn_states[conn->state],
78409 key_serial(conn->key),
78410 - atomic_read(&conn->serial),
78411 - atomic_read(&conn->hi_serial));
78412 + atomic_read_unchecked(&conn->serial),
78413 + atomic_read_unchecked(&conn->hi_serial));
78414
78415 return 0;
78416 }
78417 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78418 index 92df566..87ec1bf 100644
78419 --- a/net/rxrpc/ar-transport.c
78420 +++ b/net/rxrpc/ar-transport.c
78421 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78422 spin_lock_init(&trans->client_lock);
78423 rwlock_init(&trans->conn_lock);
78424 atomic_set(&trans->usage, 1);
78425 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78426 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78427
78428 if (peer->srx.transport.family == AF_INET) {
78429 switch (peer->srx.transport_type) {
78430 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78431 index f226709..0e735a8 100644
78432 --- a/net/rxrpc/rxkad.c
78433 +++ b/net/rxrpc/rxkad.c
78434 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78435
78436 len = iov[0].iov_len + iov[1].iov_len;
78437
78438 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78439 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78440 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78441
78442 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78443 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78444
78445 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78446
78447 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78448 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78449 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78450
78451 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78452 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78453 index 1e2eee8..ce3967e 100644
78454 --- a/net/sctp/proc.c
78455 +++ b/net/sctp/proc.c
78456 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78457 seq_printf(seq,
78458 "%8pK %8pK %-3d %-3d %-2d %-4d "
78459 "%4d %8d %8d %7d %5lu %-5d %5d ",
78460 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78461 + assoc, sk,
78462 + sctp_sk(sk)->type, sk->sk_state,
78463 assoc->state, hash,
78464 assoc->assoc_id,
78465 assoc->sndbuf_used,
78466 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78467 index 31c7bfc..bc380ae 100644
78468 --- a/net/sctp/socket.c
78469 +++ b/net/sctp/socket.c
78470 @@ -4577,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78471 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78472 if (space_left < addrlen)
78473 return -ENOMEM;
78474 - if (copy_to_user(to, &temp, addrlen))
78475 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78476 return -EFAULT;
78477 to += addrlen;
78478 cnt++;
78479 diff --git a/net/socket.c b/net/socket.c
78480 index 0452dca..5af9802 100644
78481 --- a/net/socket.c
78482 +++ b/net/socket.c
78483 @@ -88,6 +88,7 @@
78484 #include <linux/nsproxy.h>
78485 #include <linux/magic.h>
78486 #include <linux/slab.h>
78487 +#include <linux/in.h>
78488
78489 #include <asm/uaccess.h>
78490 #include <asm/unistd.h>
78491 @@ -105,6 +106,8 @@
78492 #include <linux/sockios.h>
78493 #include <linux/atalk.h>
78494
78495 +#include <linux/grsock.h>
78496 +
78497 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78498 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78499 unsigned long nr_segs, loff_t pos);
78500 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78501 &sockfs_dentry_operations, SOCKFS_MAGIC);
78502 }
78503
78504 -static struct vfsmount *sock_mnt __read_mostly;
78505 +struct vfsmount *sock_mnt __read_mostly;
78506
78507 static struct file_system_type sock_fs_type = {
78508 .name = "sockfs",
78509 @@ -1210,6 +1213,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78510 return -EAFNOSUPPORT;
78511 if (type < 0 || type >= SOCK_MAX)
78512 return -EINVAL;
78513 + if (protocol < 0)
78514 + return -EINVAL;
78515
78516 /* Compatibility.
78517
78518 @@ -1341,6 +1346,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78519 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78520 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78521
78522 + if(!gr_search_socket(family, type, protocol)) {
78523 + retval = -EACCES;
78524 + goto out;
78525 + }
78526 +
78527 + if (gr_handle_sock_all(family, type, protocol)) {
78528 + retval = -EACCES;
78529 + goto out;
78530 + }
78531 +
78532 retval = sock_create(family, type, protocol, &sock);
78533 if (retval < 0)
78534 goto out;
78535 @@ -1453,6 +1468,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78536 if (sock) {
78537 err = move_addr_to_kernel(umyaddr, addrlen, &address);
78538 if (err >= 0) {
78539 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78540 + err = -EACCES;
78541 + goto error;
78542 + }
78543 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78544 + if (err)
78545 + goto error;
78546 +
78547 err = security_socket_bind(sock,
78548 (struct sockaddr *)&address,
78549 addrlen);
78550 @@ -1461,6 +1484,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78551 (struct sockaddr *)
78552 &address, addrlen);
78553 }
78554 +error:
78555 fput_light(sock->file, fput_needed);
78556 }
78557 return err;
78558 @@ -1484,10 +1508,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78559 if ((unsigned int)backlog > somaxconn)
78560 backlog = somaxconn;
78561
78562 + if (gr_handle_sock_server_other(sock->sk)) {
78563 + err = -EPERM;
78564 + goto error;
78565 + }
78566 +
78567 + err = gr_search_listen(sock);
78568 + if (err)
78569 + goto error;
78570 +
78571 err = security_socket_listen(sock, backlog);
78572 if (!err)
78573 err = sock->ops->listen(sock, backlog);
78574
78575 +error:
78576 fput_light(sock->file, fput_needed);
78577 }
78578 return err;
78579 @@ -1531,6 +1565,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78580 newsock->type = sock->type;
78581 newsock->ops = sock->ops;
78582
78583 + if (gr_handle_sock_server_other(sock->sk)) {
78584 + err = -EPERM;
78585 + sock_release(newsock);
78586 + goto out_put;
78587 + }
78588 +
78589 + err = gr_search_accept(sock);
78590 + if (err) {
78591 + sock_release(newsock);
78592 + goto out_put;
78593 + }
78594 +
78595 /*
78596 * We don't need try_module_get here, as the listening socket (sock)
78597 * has the protocol module (sock->ops->owner) held.
78598 @@ -1569,6 +1615,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78599 fd_install(newfd, newfile);
78600 err = newfd;
78601
78602 + gr_attach_curr_ip(newsock->sk);
78603 +
78604 out_put:
78605 fput_light(sock->file, fput_needed);
78606 out:
78607 @@ -1601,6 +1649,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78608 int, addrlen)
78609 {
78610 struct socket *sock;
78611 + struct sockaddr *sck;
78612 struct sockaddr_storage address;
78613 int err, fput_needed;
78614
78615 @@ -1611,6 +1660,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78616 if (err < 0)
78617 goto out_put;
78618
78619 + sck = (struct sockaddr *)&address;
78620 +
78621 + if (gr_handle_sock_client(sck)) {
78622 + err = -EACCES;
78623 + goto out_put;
78624 + }
78625 +
78626 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78627 + if (err)
78628 + goto out_put;
78629 +
78630 err =
78631 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78632 if (err)
78633 @@ -1965,7 +2025,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78634 * checking falls down on this.
78635 */
78636 if (copy_from_user(ctl_buf,
78637 - (void __user __force *)msg_sys->msg_control,
78638 + (void __force_user *)msg_sys->msg_control,
78639 ctl_len))
78640 goto out_freectl;
78641 msg_sys->msg_control = ctl_buf;
78642 @@ -2133,7 +2193,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78643 * kernel msghdr to use the kernel address space)
78644 */
78645
78646 - uaddr = (__force void __user *)msg_sys->msg_name;
78647 + uaddr = (void __force_user *)msg_sys->msg_name;
78648 uaddr_len = COMPAT_NAMELEN(msg);
78649 if (MSG_CMSG_COMPAT & flags) {
78650 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
78651 @@ -2605,7 +2665,7 @@ static int do_siocgstamp(struct net *net, struct socket *sock,
78652 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
78653 set_fs(old_fs);
78654 if (!err)
78655 - err = compat_put_timeval(up, &ktv);
78656 + err = compat_put_timeval(&ktv, up);
78657
78658 return err;
78659 }
78660 @@ -2621,7 +2681,7 @@ static int do_siocgstampns(struct net *net, struct socket *sock,
78661 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
78662 set_fs(old_fs);
78663 if (!err)
78664 - err = compat_put_timespec(up, &kts);
78665 + err = compat_put_timespec(&kts, up);
78666
78667 return err;
78668 }
78669 @@ -2658,6 +2718,7 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
78670 if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf)))
78671 return -EFAULT;
78672
78673 + memset(&ifc, 0, sizeof(ifc));
78674 if (ifc32.ifcbuf == 0) {
78675 ifc32.ifc_len = 0;
78676 ifc.ifc_len = 0;
78677 @@ -2761,7 +2822,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78678 }
78679
78680 ifr = compat_alloc_user_space(buf_size);
78681 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78682 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78683
78684 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78685 return -EFAULT;
78686 @@ -2785,12 +2846,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78687 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78688
78689 if (copy_in_user(rxnfc, compat_rxnfc,
78690 - (void *)(&rxnfc->fs.m_ext + 1) -
78691 - (void *)rxnfc) ||
78692 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78693 + (void __user *)rxnfc) ||
78694 copy_in_user(&rxnfc->fs.ring_cookie,
78695 &compat_rxnfc->fs.ring_cookie,
78696 - (void *)(&rxnfc->fs.location + 1) -
78697 - (void *)&rxnfc->fs.ring_cookie) ||
78698 + (void __user *)(&rxnfc->fs.location + 1) -
78699 + (void __user *)&rxnfc->fs.ring_cookie) ||
78700 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78701 sizeof(rxnfc->rule_cnt)))
78702 return -EFAULT;
78703 @@ -2802,12 +2863,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78704
78705 if (convert_out) {
78706 if (copy_in_user(compat_rxnfc, rxnfc,
78707 - (const void *)(&rxnfc->fs.m_ext + 1) -
78708 - (const void *)rxnfc) ||
78709 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78710 + (const void __user *)rxnfc) ||
78711 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78712 &rxnfc->fs.ring_cookie,
78713 - (const void *)(&rxnfc->fs.location + 1) -
78714 - (const void *)&rxnfc->fs.ring_cookie) ||
78715 + (const void __user *)(&rxnfc->fs.location + 1) -
78716 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78717 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78718 sizeof(rxnfc->rule_cnt)))
78719 return -EFAULT;
78720 @@ -2877,7 +2938,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78721 old_fs = get_fs();
78722 set_fs(KERNEL_DS);
78723 err = dev_ioctl(net, cmd,
78724 - (struct ifreq __user __force *) &kifr);
78725 + (struct ifreq __force_user *) &kifr);
78726 set_fs(old_fs);
78727
78728 return err;
78729 @@ -2986,7 +3047,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78730
78731 old_fs = get_fs();
78732 set_fs(KERNEL_DS);
78733 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78734 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78735 set_fs(old_fs);
78736
78737 if (cmd == SIOCGIFMAP && !err) {
78738 @@ -3091,7 +3152,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78739 ret |= __get_user(rtdev, &(ur4->rt_dev));
78740 if (rtdev) {
78741 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78742 - r4.rt_dev = (char __user __force *)devname;
78743 + r4.rt_dev = (char __force_user *)devname;
78744 devname[15] = 0;
78745 } else
78746 r4.rt_dev = NULL;
78747 @@ -3317,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78748 int __user *uoptlen;
78749 int err;
78750
78751 - uoptval = (char __user __force *) optval;
78752 - uoptlen = (int __user __force *) optlen;
78753 + uoptval = (char __force_user *) optval;
78754 + uoptlen = (int __force_user *) optlen;
78755
78756 set_fs(KERNEL_DS);
78757 if (level == SOL_SOCKET)
78758 @@ -3338,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78759 char __user *uoptval;
78760 int err;
78761
78762 - uoptval = (char __user __force *) optval;
78763 + uoptval = (char __force_user *) optval;
78764
78765 set_fs(KERNEL_DS);
78766 if (level == SOL_SOCKET)
78767 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78768 index eda32ae..1c9fa7c 100644
78769 --- a/net/sunrpc/sched.c
78770 +++ b/net/sunrpc/sched.c
78771 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
78772 #ifdef RPC_DEBUG
78773 static void rpc_task_set_debuginfo(struct rpc_task *task)
78774 {
78775 - static atomic_t rpc_pid;
78776 + static atomic_unchecked_t rpc_pid;
78777
78778 - task->tk_pid = atomic_inc_return(&rpc_pid);
78779 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78780 }
78781 #else
78782 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78783 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78784 index 8343737..677025e 100644
78785 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78786 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78787 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78788 static unsigned int min_max_inline = 4096;
78789 static unsigned int max_max_inline = 65536;
78790
78791 -atomic_t rdma_stat_recv;
78792 -atomic_t rdma_stat_read;
78793 -atomic_t rdma_stat_write;
78794 -atomic_t rdma_stat_sq_starve;
78795 -atomic_t rdma_stat_rq_starve;
78796 -atomic_t rdma_stat_rq_poll;
78797 -atomic_t rdma_stat_rq_prod;
78798 -atomic_t rdma_stat_sq_poll;
78799 -atomic_t rdma_stat_sq_prod;
78800 +atomic_unchecked_t rdma_stat_recv;
78801 +atomic_unchecked_t rdma_stat_read;
78802 +atomic_unchecked_t rdma_stat_write;
78803 +atomic_unchecked_t rdma_stat_sq_starve;
78804 +atomic_unchecked_t rdma_stat_rq_starve;
78805 +atomic_unchecked_t rdma_stat_rq_poll;
78806 +atomic_unchecked_t rdma_stat_rq_prod;
78807 +atomic_unchecked_t rdma_stat_sq_poll;
78808 +atomic_unchecked_t rdma_stat_sq_prod;
78809
78810 /* Temporary NFS request map and context caches */
78811 struct kmem_cache *svc_rdma_map_cachep;
78812 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
78813 len -= *ppos;
78814 if (len > *lenp)
78815 len = *lenp;
78816 - if (len && copy_to_user(buffer, str_buf, len))
78817 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78818 return -EFAULT;
78819 *lenp = len;
78820 *ppos += len;
78821 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
78822 {
78823 .procname = "rdma_stat_read",
78824 .data = &rdma_stat_read,
78825 - .maxlen = sizeof(atomic_t),
78826 + .maxlen = sizeof(atomic_unchecked_t),
78827 .mode = 0644,
78828 .proc_handler = read_reset_stat,
78829 },
78830 {
78831 .procname = "rdma_stat_recv",
78832 .data = &rdma_stat_recv,
78833 - .maxlen = sizeof(atomic_t),
78834 + .maxlen = sizeof(atomic_unchecked_t),
78835 .mode = 0644,
78836 .proc_handler = read_reset_stat,
78837 },
78838 {
78839 .procname = "rdma_stat_write",
78840 .data = &rdma_stat_write,
78841 - .maxlen = sizeof(atomic_t),
78842 + .maxlen = sizeof(atomic_unchecked_t),
78843 .mode = 0644,
78844 .proc_handler = read_reset_stat,
78845 },
78846 {
78847 .procname = "rdma_stat_sq_starve",
78848 .data = &rdma_stat_sq_starve,
78849 - .maxlen = sizeof(atomic_t),
78850 + .maxlen = sizeof(atomic_unchecked_t),
78851 .mode = 0644,
78852 .proc_handler = read_reset_stat,
78853 },
78854 {
78855 .procname = "rdma_stat_rq_starve",
78856 .data = &rdma_stat_rq_starve,
78857 - .maxlen = sizeof(atomic_t),
78858 + .maxlen = sizeof(atomic_unchecked_t),
78859 .mode = 0644,
78860 .proc_handler = read_reset_stat,
78861 },
78862 {
78863 .procname = "rdma_stat_rq_poll",
78864 .data = &rdma_stat_rq_poll,
78865 - .maxlen = sizeof(atomic_t),
78866 + .maxlen = sizeof(atomic_unchecked_t),
78867 .mode = 0644,
78868 .proc_handler = read_reset_stat,
78869 },
78870 {
78871 .procname = "rdma_stat_rq_prod",
78872 .data = &rdma_stat_rq_prod,
78873 - .maxlen = sizeof(atomic_t),
78874 + .maxlen = sizeof(atomic_unchecked_t),
78875 .mode = 0644,
78876 .proc_handler = read_reset_stat,
78877 },
78878 {
78879 .procname = "rdma_stat_sq_poll",
78880 .data = &rdma_stat_sq_poll,
78881 - .maxlen = sizeof(atomic_t),
78882 + .maxlen = sizeof(atomic_unchecked_t),
78883 .mode = 0644,
78884 .proc_handler = read_reset_stat,
78885 },
78886 {
78887 .procname = "rdma_stat_sq_prod",
78888 .data = &rdma_stat_sq_prod,
78889 - .maxlen = sizeof(atomic_t),
78890 + .maxlen = sizeof(atomic_unchecked_t),
78891 .mode = 0644,
78892 .proc_handler = read_reset_stat,
78893 },
78894 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78895 index 41cb63b..c4a1489 100644
78896 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78897 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78898 @@ -501,7 +501,7 @@ next_sge:
78899 svc_rdma_put_context(ctxt, 0);
78900 goto out;
78901 }
78902 - atomic_inc(&rdma_stat_read);
78903 + atomic_inc_unchecked(&rdma_stat_read);
78904
78905 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78906 chl_map->ch[ch_no].count -= read_wr.num_sge;
78907 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78908 dto_q);
78909 list_del_init(&ctxt->dto_q);
78910 } else {
78911 - atomic_inc(&rdma_stat_rq_starve);
78912 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78913 clear_bit(XPT_DATA, &xprt->xpt_flags);
78914 ctxt = NULL;
78915 }
78916 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78917 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78918 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78919 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78920 - atomic_inc(&rdma_stat_recv);
78921 + atomic_inc_unchecked(&rdma_stat_recv);
78922
78923 /* Build up the XDR from the receive buffers. */
78924 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78925 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78926 index 42eb7ba..c887c45 100644
78927 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78928 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78929 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78930 write_wr.wr.rdma.remote_addr = to;
78931
78932 /* Post It */
78933 - atomic_inc(&rdma_stat_write);
78934 + atomic_inc_unchecked(&rdma_stat_write);
78935 if (svc_rdma_send(xprt, &write_wr))
78936 goto err;
78937 return 0;
78938 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78939 index 73b428b..5f3f8f3 100644
78940 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78941 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78942 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78943 return;
78944
78945 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78946 - atomic_inc(&rdma_stat_rq_poll);
78947 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78948
78949 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78950 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78951 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78952 }
78953
78954 if (ctxt)
78955 - atomic_inc(&rdma_stat_rq_prod);
78956 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78957
78958 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78959 /*
78960 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78961 return;
78962
78963 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78964 - atomic_inc(&rdma_stat_sq_poll);
78965 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78966 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78967 if (wc.status != IB_WC_SUCCESS)
78968 /* Close the transport */
78969 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78970 }
78971
78972 if (ctxt)
78973 - atomic_inc(&rdma_stat_sq_prod);
78974 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78975 }
78976
78977 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78978 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78979 spin_lock_bh(&xprt->sc_lock);
78980 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78981 spin_unlock_bh(&xprt->sc_lock);
78982 - atomic_inc(&rdma_stat_sq_starve);
78983 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78984
78985 /* See if we can opportunistically reap SQ WR to make room */
78986 sq_cq_reap(xprt);
78987 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78988 index e3a6e37..be2ea77 100644
78989 --- a/net/sysctl_net.c
78990 +++ b/net/sysctl_net.c
78991 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78992 struct ctl_table *table)
78993 {
78994 /* Allow network administrator to have same access as root. */
78995 - if (capable(CAP_NET_ADMIN)) {
78996 + if (capable_nolog(CAP_NET_ADMIN)) {
78997 int mode = (table->mode >> 6) & 7;
78998 return (mode << 6) | (mode << 3) | mode;
78999 }
79000 diff --git a/net/tipc/link.c b/net/tipc/link.c
79001 index 7a614f4..b14dbd2 100644
79002 --- a/net/tipc/link.c
79003 +++ b/net/tipc/link.c
79004 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79005 struct tipc_msg fragm_hdr;
79006 struct sk_buff *buf, *buf_chain, *prev;
79007 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79008 - const unchar *sect_crs;
79009 + const unchar __user *sect_crs;
79010 int curr_sect;
79011 u32 fragm_no;
79012
79013 @@ -1205,7 +1205,7 @@ again:
79014
79015 if (!sect_rest) {
79016 sect_rest = msg_sect[++curr_sect].iov_len;
79017 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79018 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79019 }
79020
79021 if (sect_rest < fragm_rest)
79022 @@ -1224,7 +1224,7 @@ error:
79023 }
79024 } else
79025 skb_copy_to_linear_data_offset(buf, fragm_crs,
79026 - sect_crs, sz);
79027 + (const void __force_kernel *)sect_crs, sz);
79028 sect_crs += sz;
79029 sect_rest -= sz;
79030 fragm_crs += sz;
79031 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79032 index deea0d2..fa13bd7 100644
79033 --- a/net/tipc/msg.c
79034 +++ b/net/tipc/msg.c
79035 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79036 msg_sect[cnt].iov_len);
79037 else
79038 skb_copy_to_linear_data_offset(*buf, pos,
79039 - msg_sect[cnt].iov_base,
79040 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79041 msg_sect[cnt].iov_len);
79042 pos += msg_sect[cnt].iov_len;
79043 }
79044 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79045 index f976e9cd..560d055 100644
79046 --- a/net/tipc/subscr.c
79047 +++ b/net/tipc/subscr.c
79048 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79049 {
79050 struct iovec msg_sect;
79051
79052 - msg_sect.iov_base = (void *)&sub->evt;
79053 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79054 msg_sect.iov_len = sizeof(struct tipc_event);
79055
79056 sub->evt.event = htohl(event, sub->swap);
79057 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79058 index 641f2e4..590bb48 100644
79059 --- a/net/unix/af_unix.c
79060 +++ b/net/unix/af_unix.c
79061 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
79062 err = -ECONNREFUSED;
79063 if (!S_ISSOCK(inode->i_mode))
79064 goto put_fail;
79065 +
79066 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79067 + err = -EACCES;
79068 + goto put_fail;
79069 + }
79070 +
79071 u = unix_find_socket_byinode(inode);
79072 if (!u)
79073 goto put_fail;
79074 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
79075 if (u) {
79076 struct dentry *dentry;
79077 dentry = unix_sk(u)->path.dentry;
79078 +
79079 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79080 + err = -EPERM;
79081 + sock_put(u);
79082 + goto fail;
79083 + }
79084 +
79085 if (dentry)
79086 touch_atime(&unix_sk(u)->path);
79087 } else
79088 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
79089 err = security_path_mknod(&path, dentry, mode, 0);
79090 if (err)
79091 goto out_mknod_drop_write;
79092 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79093 + err = -EACCES;
79094 + goto out_mknod_drop_write;
79095 + }
79096 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79097 out_mknod_drop_write:
79098 mnt_drop_write(path.mnt);
79099 if (err)
79100 goto out_mknod_dput;
79101 +
79102 + gr_handle_create(dentry, path.mnt);
79103 +
79104 mutex_unlock(&path.dentry->d_inode->i_mutex);
79105 dput(path.dentry);
79106 path.dentry = dentry;
79107 @@ -1448,7 +1468,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
79108 if (NULL == siocb->scm)
79109 siocb->scm = &tmp_scm;
79110 wait_for_unix_gc();
79111 - err = scm_send(sock, msg, siocb->scm);
79112 + err = scm_send(sock, msg, siocb->scm, false);
79113 if (err < 0)
79114 return err;
79115
79116 @@ -1617,7 +1637,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
79117 if (NULL == siocb->scm)
79118 siocb->scm = &tmp_scm;
79119 wait_for_unix_gc();
79120 - err = scm_send(sock, msg, siocb->scm);
79121 + err = scm_send(sock, msg, siocb->scm, false);
79122 if (err < 0)
79123 return err;
79124
79125 diff --git a/net/wireless/core.h b/net/wireless/core.h
79126 index bc686ef..27845e6 100644
79127 --- a/net/wireless/core.h
79128 +++ b/net/wireless/core.h
79129 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
79130 struct mutex mtx;
79131
79132 /* rfkill support */
79133 - struct rfkill_ops rfkill_ops;
79134 + rfkill_ops_no_const rfkill_ops;
79135 struct rfkill *rfkill;
79136 struct work_struct rfkill_sync;
79137
79138 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79139 index b0eb7aa..7d73e82 100644
79140 --- a/net/wireless/wext-core.c
79141 +++ b/net/wireless/wext-core.c
79142 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79143 */
79144
79145 /* Support for very large requests */
79146 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79147 - (user_length > descr->max_tokens)) {
79148 + if (user_length > descr->max_tokens) {
79149 /* Allow userspace to GET more than max so
79150 * we can support any size GET requests.
79151 * There is still a limit : -ENOMEM.
79152 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79153 }
79154 }
79155
79156 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79157 - /*
79158 - * If this is a GET, but not NOMAX, it means that the extra
79159 - * data is not bounded by userspace, but by max_tokens. Thus
79160 - * set the length to max_tokens. This matches the extra data
79161 - * allocation.
79162 - * The driver should fill it with the number of tokens it
79163 - * provided, and it may check iwp->length rather than having
79164 - * knowledge of max_tokens. If the driver doesn't change the
79165 - * iwp->length, this ioctl just copies back max_token tokens
79166 - * filled with zeroes. Hopefully the driver isn't claiming
79167 - * them to be valid data.
79168 - */
79169 - iwp->length = descr->max_tokens;
79170 - }
79171 -
79172 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79173
79174 iwp->length += essid_compat;
79175 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79176 index ccfbd32..9b61cf9f 100644
79177 --- a/net/xfrm/xfrm_policy.c
79178 +++ b/net/xfrm/xfrm_policy.c
79179 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79180 {
79181 policy->walk.dead = 1;
79182
79183 - atomic_inc(&policy->genid);
79184 + atomic_inc_unchecked(&policy->genid);
79185
79186 if (del_timer(&policy->timer))
79187 xfrm_pol_put(policy);
79188 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79189 hlist_add_head(&policy->bydst, chain);
79190 xfrm_pol_hold(policy);
79191 net->xfrm.policy_count[dir]++;
79192 - atomic_inc(&flow_cache_genid);
79193 + atomic_inc_unchecked(&flow_cache_genid);
79194 if (delpol)
79195 __xfrm_policy_unlink(delpol, dir);
79196 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
79197 @@ -1532,7 +1532,7 @@ free_dst:
79198 goto out;
79199 }
79200
79201 -static int inline
79202 +static inline int
79203 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79204 {
79205 if (!*target) {
79206 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79207 return 0;
79208 }
79209
79210 -static int inline
79211 +static inline int
79212 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79213 {
79214 #ifdef CONFIG_XFRM_SUB_POLICY
79215 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79216 #endif
79217 }
79218
79219 -static int inline
79220 +static inline int
79221 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79222 {
79223 #ifdef CONFIG_XFRM_SUB_POLICY
79224 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79225
79226 xdst->num_pols = num_pols;
79227 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79228 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79229 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79230
79231 return xdst;
79232 }
79233 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79234 if (xdst->xfrm_genid != dst->xfrm->genid)
79235 return 0;
79236 if (xdst->num_pols > 0 &&
79237 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79238 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79239 return 0;
79240
79241 mtu = dst_mtu(dst->child);
79242 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79243 sizeof(pol->xfrm_vec[i].saddr));
79244 pol->xfrm_vec[i].encap_family = mp->new_family;
79245 /* flush bundles */
79246 - atomic_inc(&pol->genid);
79247 + atomic_inc_unchecked(&pol->genid);
79248 }
79249 }
79250
79251 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
79252 index 5b228f9..6aca4e3 100644
79253 --- a/net/xfrm/xfrm_state.c
79254 +++ b/net/xfrm/xfrm_state.c
79255 @@ -1981,8 +1981,10 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
79256 goto error;
79257
79258 x->outer_mode = xfrm_get_mode(x->props.mode, family);
79259 - if (x->outer_mode == NULL)
79260 + if (x->outer_mode == NULL) {
79261 + err = -EPROTONOSUPPORT;
79262 goto error;
79263 + }
79264
79265 if (init_replay) {
79266 err = xfrm_init_replay(x);
79267 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
79268 index 44293b3..be1d3e58 100644
79269 --- a/net/xfrm/xfrm_user.c
79270 +++ b/net/xfrm/xfrm_user.c
79271 @@ -1413,6 +1413,7 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
79272 struct xfrm_user_tmpl *up = &vec[i];
79273 struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
79274
79275 + memset(up, 0, sizeof(*up));
79276 memcpy(&up->id, &kp->id, sizeof(up->id));
79277 up->family = kp->encap_family;
79278 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr));
79279 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79280 index ff1720d..ed8475e 100644
79281 --- a/scripts/Makefile.build
79282 +++ b/scripts/Makefile.build
79283 @@ -111,7 +111,7 @@ endif
79284 endif
79285
79286 # Do not include host rules unless needed
79287 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79288 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79289 include scripts/Makefile.host
79290 endif
79291
79292 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79293 index 686cb0d..9d653bf 100644
79294 --- a/scripts/Makefile.clean
79295 +++ b/scripts/Makefile.clean
79296 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79297 __clean-files := $(extra-y) $(always) \
79298 $(targets) $(clean-files) \
79299 $(host-progs) \
79300 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79301 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79302 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79303
79304 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79305
79306 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79307 index 1ac414f..38575f7 100644
79308 --- a/scripts/Makefile.host
79309 +++ b/scripts/Makefile.host
79310 @@ -31,6 +31,8 @@
79311 # Note: Shared libraries consisting of C++ files are not supported
79312
79313 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79314 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79315 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79316
79317 # C code
79318 # Executables compiled from a single .c file
79319 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79320 # Shared libaries (only .c supported)
79321 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79322 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79323 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79324 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79325 # Remove .so files from "xxx-objs"
79326 host-cobjs := $(filter-out %.so,$(host-cobjs))
79327 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79328
79329 -#Object (.o) files used by the shared libaries
79330 +# Object (.o) files used by the shared libaries
79331 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79332 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79333
79334 # output directory for programs/.o files
79335 # hostprogs-y := tools/build may have been specified. Retrieve directory
79336 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79337 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79338 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79339 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79340 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79341 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79342 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79343 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79344
79345 obj-dirs += $(host-objdirs)
79346 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79347 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79348 $(call if_changed_dep,host-cshobjs)
79349
79350 +# Compile .c file, create position independent .o file
79351 +# host-cxxshobjs -> .o
79352 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79353 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79354 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79355 + $(call if_changed_dep,host-cxxshobjs)
79356 +
79357 # Link a shared library, based on position independent .o files
79358 # *.o -> .so shared library (host-cshlib)
79359 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79360 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79361 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79362 $(call if_changed,host-cshlib)
79363
79364 +# Link a shared library, based on position independent .o files
79365 +# *.o -> .so shared library (host-cxxshlib)
79366 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79367 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79368 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79369 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79370 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79371 + $(call if_changed,host-cxxshlib)
79372 +
79373 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79374 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79375 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79376
79377 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79378 index cb1f50c..cef2a7c 100644
79379 --- a/scripts/basic/fixdep.c
79380 +++ b/scripts/basic/fixdep.c
79381 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79382 /*
79383 * Lookup a value in the configuration string.
79384 */
79385 -static int is_defined_config(const char *name, int len, unsigned int hash)
79386 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79387 {
79388 struct item *aux;
79389
79390 @@ -211,10 +211,10 @@ static void clear_config(void)
79391 /*
79392 * Record the use of a CONFIG_* word.
79393 */
79394 -static void use_config(const char *m, int slen)
79395 +static void use_config(const char *m, unsigned int slen)
79396 {
79397 unsigned int hash = strhash(m, slen);
79398 - int c, i;
79399 + unsigned int c, i;
79400
79401 if (is_defined_config(m, slen, hash))
79402 return;
79403 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79404
79405 static void parse_config_file(const char *map, size_t len)
79406 {
79407 - const int *end = (const int *) (map + len);
79408 + const unsigned int *end = (const unsigned int *) (map + len);
79409 /* start at +1, so that p can never be < map */
79410 - const int *m = (const int *) map + 1;
79411 + const unsigned int *m = (const unsigned int *) map + 1;
79412 const char *p, *q;
79413
79414 for (; m < end; m++) {
79415 @@ -406,7 +406,7 @@ static void print_deps(void)
79416 static void traps(void)
79417 {
79418 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79419 - int *p = (int *)test;
79420 + unsigned int *p = (unsigned int *)test;
79421
79422 if (*p != INT_CONF) {
79423 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79424 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79425 new file mode 100644
79426 index 0000000..008ac1a
79427 --- /dev/null
79428 +++ b/scripts/gcc-plugin.sh
79429 @@ -0,0 +1,17 @@
79430 +#!/bin/bash
79431 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79432 +#include "gcc-plugin.h"
79433 +#include "tree.h"
79434 +#include "tm.h"
79435 +#include "rtl.h"
79436 +#ifdef ENABLE_BUILD_WITH_CXX
79437 +#warning $2
79438 +#else
79439 +#warning $1
79440 +#endif
79441 +EOF`
79442 +if [ $? -eq 0 ]
79443 +then
79444 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79445 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79446 +fi
79447 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79448 index cd9c6c6..0c8f0fa 100644
79449 --- a/scripts/link-vmlinux.sh
79450 +++ b/scripts/link-vmlinux.sh
79451 @@ -147,7 +147,7 @@ else
79452 fi;
79453
79454 # final build of init/
79455 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79456 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79457
79458 kallsymso=""
79459 kallsyms_vmlinux=""
79460 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79461 index 5759751..b170367 100644
79462 --- a/scripts/mod/file2alias.c
79463 +++ b/scripts/mod/file2alias.c
79464 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79465 unsigned long size, unsigned long id_size,
79466 void *symval)
79467 {
79468 - int i;
79469 + unsigned int i;
79470
79471 if (size % id_size || size < id_size) {
79472 if (cross_build != 0)
79473 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79474 /* USB is special because the bcdDevice can be matched against a numeric range */
79475 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79476 static void do_usb_entry(struct usb_device_id *id,
79477 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79478 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79479 unsigned char range_lo, unsigned char range_hi,
79480 unsigned char max, struct module *mod)
79481 {
79482 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79483 {
79484 unsigned int devlo, devhi;
79485 unsigned char chi, clo, max;
79486 - int ndigits;
79487 + unsigned int ndigits;
79488
79489 id->match_flags = TO_NATIVE(id->match_flags);
79490 id->idVendor = TO_NATIVE(id->idVendor);
79491 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79492 for (i = 0; i < count; i++) {
79493 const char *id = (char *)devs[i].id;
79494 char acpi_id[sizeof(devs[0].id)];
79495 - int j;
79496 + unsigned int j;
79497
79498 buf_printf(&mod->dev_table_buf,
79499 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79500 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79501
79502 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79503 const char *id = (char *)card->devs[j].id;
79504 - int i2, j2;
79505 + unsigned int i2, j2;
79506 int dup = 0;
79507
79508 if (!id[0])
79509 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79510 /* add an individual alias for every device entry */
79511 if (!dup) {
79512 char acpi_id[sizeof(card->devs[0].id)];
79513 - int k;
79514 + unsigned int k;
79515
79516 buf_printf(&mod->dev_table_buf,
79517 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79518 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79519 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79520 char *alias)
79521 {
79522 - int i, j;
79523 + unsigned int i, j;
79524
79525 sprintf(alias, "dmi*");
79526
79527 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79528 index 0f84bb3..2d42035 100644
79529 --- a/scripts/mod/modpost.c
79530 +++ b/scripts/mod/modpost.c
79531 @@ -925,6 +925,7 @@ enum mismatch {
79532 ANY_INIT_TO_ANY_EXIT,
79533 ANY_EXIT_TO_ANY_INIT,
79534 EXPORT_TO_INIT_EXIT,
79535 + DATA_TO_TEXT
79536 };
79537
79538 struct sectioncheck {
79539 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
79540 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79541 .mismatch = EXPORT_TO_INIT_EXIT,
79542 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79543 +},
79544 +/* Do not reference code from writable data */
79545 +{
79546 + .fromsec = { DATA_SECTIONS, NULL },
79547 + .tosec = { TEXT_SECTIONS, NULL },
79548 + .mismatch = DATA_TO_TEXT
79549 }
79550 };
79551
79552 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79553 continue;
79554 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79555 continue;
79556 - if (sym->st_value == addr)
79557 - return sym;
79558 /* Find a symbol nearby - addr are maybe negative */
79559 d = sym->st_value - addr;
79560 + if (d == 0)
79561 + return sym;
79562 if (d < 0)
79563 d = addr - sym->st_value;
79564 if (d < distance) {
79565 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
79566 tosym, prl_to, prl_to, tosym);
79567 free(prl_to);
79568 break;
79569 + case DATA_TO_TEXT:
79570 +#if 0
79571 + fprintf(stderr,
79572 + "The %s %s:%s references\n"
79573 + "the %s %s:%s%s\n",
79574 + from, fromsec, fromsym, to, tosec, tosym, to_p);
79575 +#endif
79576 + break;
79577 }
79578 fprintf(stderr, "\n");
79579 }
79580 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79581 static void check_sec_ref(struct module *mod, const char *modname,
79582 struct elf_info *elf)
79583 {
79584 - int i;
79585 + unsigned int i;
79586 Elf_Shdr *sechdrs = elf->sechdrs;
79587
79588 /* Walk through all sections */
79589 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79590 va_end(ap);
79591 }
79592
79593 -void buf_write(struct buffer *buf, const char *s, int len)
79594 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79595 {
79596 if (buf->size - buf->pos < len) {
79597 buf->size += len + SZ;
79598 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79599 if (fstat(fileno(file), &st) < 0)
79600 goto close_write;
79601
79602 - if (st.st_size != b->pos)
79603 + if (st.st_size != (off_t)b->pos)
79604 goto close_write;
79605
79606 tmp = NOFAIL(malloc(b->pos));
79607 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79608 index 51207e4..f7d603d 100644
79609 --- a/scripts/mod/modpost.h
79610 +++ b/scripts/mod/modpost.h
79611 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79612
79613 struct buffer {
79614 char *p;
79615 - int pos;
79616 - int size;
79617 + unsigned int pos;
79618 + unsigned int size;
79619 };
79620
79621 void __attribute__((format(printf, 2, 3)))
79622 buf_printf(struct buffer *buf, const char *fmt, ...);
79623
79624 void
79625 -buf_write(struct buffer *buf, const char *s, int len);
79626 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79627
79628 struct module {
79629 struct module *next;
79630 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79631 index 9dfcd6d..099068e 100644
79632 --- a/scripts/mod/sumversion.c
79633 +++ b/scripts/mod/sumversion.c
79634 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79635 goto out;
79636 }
79637
79638 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79639 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79640 warn("writing sum in %s failed: %s\n",
79641 filename, strerror(errno));
79642 goto out;
79643 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79644 index 5c11312..72742b5 100644
79645 --- a/scripts/pnmtologo.c
79646 +++ b/scripts/pnmtologo.c
79647 @@ -237,14 +237,14 @@ static void write_header(void)
79648 fprintf(out, " * Linux logo %s\n", logoname);
79649 fputs(" */\n\n", out);
79650 fputs("#include <linux/linux_logo.h>\n\n", out);
79651 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79652 + fprintf(out, "static unsigned char %s_data[] = {\n",
79653 logoname);
79654 }
79655
79656 static void write_footer(void)
79657 {
79658 fputs("\n};\n\n", out);
79659 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79660 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79661 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79662 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79663 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79664 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79665 fputs("\n};\n\n", out);
79666
79667 /* write logo clut */
79668 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79669 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79670 logoname);
79671 write_hex_cnt = 0;
79672 for (i = 0; i < logo_clutsize; i++) {
79673 diff --git a/security/Kconfig b/security/Kconfig
79674 index e9c6ac7..58348f4 100644
79675 --- a/security/Kconfig
79676 +++ b/security/Kconfig
79677 @@ -4,6 +4,888 @@
79678
79679 menu "Security options"
79680
79681 +menu "Grsecurity"
79682 +
79683 + config ARCH_TRACK_EXEC_LIMIT
79684 + bool
79685 +
79686 + config PAX_KERNEXEC_PLUGIN
79687 + bool
79688 +
79689 + config PAX_PER_CPU_PGD
79690 + bool
79691 +
79692 + config TASK_SIZE_MAX_SHIFT
79693 + int
79694 + depends on X86_64
79695 + default 47 if !PAX_PER_CPU_PGD
79696 + default 42 if PAX_PER_CPU_PGD
79697 +
79698 + config PAX_ENABLE_PAE
79699 + bool
79700 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79701 +
79702 + config PAX_USERCOPY_SLABS
79703 + bool
79704 +
79705 +config GRKERNSEC
79706 + bool "Grsecurity"
79707 + select CRYPTO
79708 + select CRYPTO_SHA256
79709 + select PROC_FS
79710 + select STOP_MACHINE
79711 + help
79712 + If you say Y here, you will be able to configure many features
79713 + that will enhance the security of your system. It is highly
79714 + recommended that you say Y here and read through the help
79715 + for each option so that you fully understand the features and
79716 + can evaluate their usefulness for your machine.
79717 +
79718 +choice
79719 + prompt "Configuration Method"
79720 + depends on GRKERNSEC
79721 + default GRKERNSEC_CONFIG_CUSTOM
79722 + help
79723 +
79724 +config GRKERNSEC_CONFIG_AUTO
79725 + bool "Automatic"
79726 + help
79727 + If you choose this configuration method, you'll be able to answer a small
79728 + number of simple questions about how you plan to use this kernel.
79729 + The settings of grsecurity and PaX will be automatically configured for
79730 + the highest commonly-used settings within the provided constraints.
79731 +
79732 + If you require additional configuration, custom changes can still be made
79733 + from the "custom configuration" menu.
79734 +
79735 +config GRKERNSEC_CONFIG_CUSTOM
79736 + bool "Custom"
79737 + help
79738 + If you choose this configuration method, you'll be able to configure all
79739 + grsecurity and PaX settings manually. Via this method, no options are
79740 + automatically enabled.
79741 +
79742 +endchoice
79743 +
79744 +choice
79745 + prompt "Usage Type"
79746 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79747 + default GRKERNSEC_CONFIG_SERVER
79748 + help
79749 +
79750 +config GRKERNSEC_CONFIG_SERVER
79751 + bool "Server"
79752 + help
79753 + Choose this option if you plan to use this kernel on a server.
79754 +
79755 +config GRKERNSEC_CONFIG_DESKTOP
79756 + bool "Desktop"
79757 + help
79758 + Choose this option if you plan to use this kernel on a desktop.
79759 +
79760 +endchoice
79761 +
79762 +choice
79763 + prompt "Virtualization Type"
79764 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
79765 + default GRKERNSEC_CONFIG_VIRT_NONE
79766 + help
79767 +
79768 +config GRKERNSEC_CONFIG_VIRT_NONE
79769 + bool "None"
79770 + help
79771 + Choose this option if this kernel will be run on bare metal.
79772 +
79773 +config GRKERNSEC_CONFIG_VIRT_GUEST
79774 + bool "Guest"
79775 + help
79776 + Choose this option if this kernel will be run as a VM guest.
79777 +
79778 +config GRKERNSEC_CONFIG_VIRT_HOST
79779 + bool "Host"
79780 + help
79781 + Choose this option if this kernel will be run as a VM host.
79782 +
79783 +endchoice
79784 +
79785 +choice
79786 + prompt "Virtualization Hardware"
79787 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79788 + help
79789 +
79790 +config GRKERNSEC_CONFIG_VIRT_EPT
79791 + bool "EPT/RVI Processor Support"
79792 + depends on X86
79793 + help
79794 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
79795 + hardware virtualization. This allows for additional kernel hardening protections
79796 + to operate without additional performance impact.
79797 +
79798 + To see if your Intel processor supports EPT, see:
79799 + http://ark.intel.com/Products/VirtualizationTechnology
79800 + (Most Core i3/5/7 support EPT)
79801 +
79802 + To see if your AMD processor supports RVI, see:
79803 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
79804 +
79805 +config GRKERNSEC_CONFIG_VIRT_SOFT
79806 + bool "First-gen/No Hardware Virtualization"
79807 + help
79808 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
79809 + support hardware virtualization or doesn't support the EPT/RVI extensions.
79810 +
79811 +endchoice
79812 +
79813 +choice
79814 + prompt "Virtualization Software"
79815 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79816 + help
79817 +
79818 +config GRKERNSEC_CONFIG_VIRT_XEN
79819 + bool "Xen"
79820 + help
79821 + Choose this option if this kernel is running as a Xen guest or host.
79822 +
79823 +config GRKERNSEC_CONFIG_VIRT_VMWARE
79824 + bool "VMWare"
79825 + help
79826 + Choose this option if this kernel is running as a VMWare guest or host.
79827 +
79828 +config GRKERNSEC_CONFIG_VIRT_KVM
79829 + bool "KVM"
79830 + help
79831 + Choose this option if this kernel is running as a KVM guest or host.
79832 +
79833 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
79834 + bool "VirtualBox"
79835 + help
79836 + Choose this option if this kernel is running as a VirtualBox guest or host.
79837 +
79838 +endchoice
79839 +
79840 +choice
79841 + prompt "Required Priorities"
79842 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79843 + default GRKERNSEC_CONFIG_PRIORITY_PERF
79844 + help
79845 +
79846 +config GRKERNSEC_CONFIG_PRIORITY_PERF
79847 + bool "Performance"
79848 + help
79849 + Choose this option if performance is of highest priority for this deployment
79850 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
79851 + and freed memory sanitizing will be disabled.
79852 +
79853 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
79854 + bool "Security"
79855 + help
79856 + Choose this option if security is of highest priority for this deployment of
79857 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
79858 + be enabled for this kernel. In a worst-case scenario, these features can
79859 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
79860 +
79861 +endchoice
79862 +
79863 +menu "Default Special Groups"
79864 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79865 +
79866 +config GRKERNSEC_PROC_GID
79867 + int "GID exempted from /proc restrictions"
79868 + default 1001
79869 + help
79870 + Setting this GID determines which group will be exempted from
79871 + grsecurity's /proc restrictions, allowing users of the specified
79872 + group to view network statistics and the existence of other users'
79873 + processes on the system.
79874 +
79875 +config GRKERNSEC_TPE_GID
79876 + int "GID for untrusted users"
79877 + depends on GRKERNSEC_CONFIG_SERVER
79878 + default 1005
79879 + help
79880 + Setting this GID determines which group untrusted users should
79881 + be added to. These users will be placed under grsecurity's Trusted Path
79882 + Execution mechanism, preventing them from executing their own binaries.
79883 + The users will only be able to execute binaries in directories owned and
79884 + writable only by the root user.
79885 +
79886 +config GRKERNSEC_SYMLINKOWN_GID
79887 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
79888 + depends on GRKERNSEC_CONFIG_SERVER
79889 + default 1006
79890 + help
79891 + Setting this GID determines what group kernel-enforced
79892 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
79893 + is enabled, a sysctl option with name "symlinkown_gid" is created.
79894 +
79895 +
79896 +endmenu
79897 +
79898 +menu "Customize Configuration"
79899 +depends on GRKERNSEC
79900 +
79901 +menu "PaX"
79902 +
79903 +config PAX
79904 + bool "Enable various PaX features"
79905 + default y if GRKERNSEC_CONFIG_AUTO
79906 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79907 + help
79908 + This allows you to enable various PaX features. PaX adds
79909 + intrusion prevention mechanisms to the kernel that reduce
79910 + the risks posed by exploitable memory corruption bugs.
79911 +
79912 +menu "PaX Control"
79913 + depends on PAX
79914 +
79915 +config PAX_SOFTMODE
79916 + bool 'Support soft mode'
79917 + help
79918 + Enabling this option will allow you to run PaX in soft mode, that
79919 + is, PaX features will not be enforced by default, only on executables
79920 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79921 + support as they are the only way to mark executables for soft mode use.
79922 +
79923 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79924 + line option on boot. Furthermore you can control various PaX features
79925 + at runtime via the entries in /proc/sys/kernel/pax.
79926 +
79927 +config PAX_EI_PAX
79928 + bool 'Use legacy ELF header marking'
79929 + default y if GRKERNSEC_CONFIG_AUTO
79930 + help
79931 + Enabling this option will allow you to control PaX features on
79932 + a per executable basis via the 'chpax' utility available at
79933 + http://pax.grsecurity.net/. The control flags will be read from
79934 + an otherwise reserved part of the ELF header. This marking has
79935 + numerous drawbacks (no support for soft-mode, toolchain does not
79936 + know about the non-standard use of the ELF header) therefore it
79937 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79938 + support.
79939 +
79940 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79941 + support as well, they will override the legacy EI_PAX marks.
79942 +
79943 + If you enable none of the marking options then all applications
79944 + will run with PaX enabled on them by default.
79945 +
79946 +config PAX_PT_PAX_FLAGS
79947 + bool 'Use ELF program header marking'
79948 + default y if GRKERNSEC_CONFIG_AUTO
79949 + help
79950 + Enabling this option will allow you to control PaX features on
79951 + a per executable basis via the 'paxctl' utility available at
79952 + http://pax.grsecurity.net/. The control flags will be read from
79953 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79954 + has the benefits of supporting both soft mode and being fully
79955 + integrated into the toolchain (the binutils patch is available
79956 + from http://pax.grsecurity.net).
79957 +
79958 + Note that if you enable the legacy EI_PAX marking support as well,
79959 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79960 +
79961 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79962 + must make sure that the marks are the same if a binary has both marks.
79963 +
79964 + If you enable none of the marking options then all applications
79965 + will run with PaX enabled on them by default.
79966 +
79967 +config PAX_XATTR_PAX_FLAGS
79968 + bool 'Use filesystem extended attributes marking'
79969 + default y if GRKERNSEC_CONFIG_AUTO
79970 + select CIFS_XATTR if CIFS
79971 + select EXT2_FS_XATTR if EXT2_FS
79972 + select EXT3_FS_XATTR if EXT3_FS
79973 + select EXT4_FS_XATTR if EXT4_FS
79974 + select JFFS2_FS_XATTR if JFFS2_FS
79975 + select REISERFS_FS_XATTR if REISERFS_FS
79976 + select SQUASHFS_XATTR if SQUASHFS
79977 + select TMPFS_XATTR if TMPFS
79978 + select UBIFS_FS_XATTR if UBIFS_FS
79979 + help
79980 + Enabling this option will allow you to control PaX features on
79981 + a per executable basis via the 'setfattr' utility. The control
79982 + flags will be read from the user.pax.flags extended attribute of
79983 + the file. This marking has the benefit of supporting binary-only
79984 + applications that self-check themselves (e.g., skype) and would
79985 + not tolerate chpax/paxctl changes. The main drawback is that
79986 + extended attributes are not supported by some filesystems (e.g.,
79987 + isofs, udf, vfat) so copying files through such filesystems will
79988 + lose the extended attributes and these PaX markings.
79989 +
79990 + Note that if you enable the legacy EI_PAX marking support as well,
79991 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79992 +
79993 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79994 + must make sure that the marks are the same if a binary has both marks.
79995 +
79996 + If you enable none of the marking options then all applications
79997 + will run with PaX enabled on them by default.
79998 +
79999 +choice
80000 + prompt 'MAC system integration'
80001 + default PAX_HAVE_ACL_FLAGS
80002 + help
80003 + Mandatory Access Control systems have the option of controlling
80004 + PaX flags on a per executable basis, choose the method supported
80005 + by your particular system.
80006 +
80007 + - "none": if your MAC system does not interact with PaX,
80008 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80009 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80010 +
80011 + NOTE: this option is for developers/integrators only.
80012 +
80013 + config PAX_NO_ACL_FLAGS
80014 + bool 'none'
80015 +
80016 + config PAX_HAVE_ACL_FLAGS
80017 + bool 'direct'
80018 +
80019 + config PAX_HOOK_ACL_FLAGS
80020 + bool 'hook'
80021 +endchoice
80022 +
80023 +endmenu
80024 +
80025 +menu "Non-executable pages"
80026 + depends on PAX
80027 +
80028 +config PAX_NOEXEC
80029 + bool "Enforce non-executable pages"
80030 + default y if GRKERNSEC_CONFIG_AUTO
80031 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80032 + help
80033 + By design some architectures do not allow for protecting memory
80034 + pages against execution or even if they do, Linux does not make
80035 + use of this feature. In practice this means that if a page is
80036 + readable (such as the stack or heap) it is also executable.
80037 +
80038 + There is a well known exploit technique that makes use of this
80039 + fact and a common programming mistake where an attacker can
80040 + introduce code of his choice somewhere in the attacked program's
80041 + memory (typically the stack or the heap) and then execute it.
80042 +
80043 + If the attacked program was running with different (typically
80044 + higher) privileges than that of the attacker, then he can elevate
80045 + his own privilege level (e.g. get a root shell, write to files for
80046 + which he does not have write access to, etc).
80047 +
80048 + Enabling this option will let you choose from various features
80049 + that prevent the injection and execution of 'foreign' code in
80050 + a program.
80051 +
80052 + This will also break programs that rely on the old behaviour and
80053 + expect that dynamically allocated memory via the malloc() family
80054 + of functions is executable (which it is not). Notable examples
80055 + are the XFree86 4.x server, the java runtime and wine.
80056 +
80057 +config PAX_PAGEEXEC
80058 + bool "Paging based non-executable pages"
80059 + default y if GRKERNSEC_CONFIG_AUTO
80060 + 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)
80061 + select S390_SWITCH_AMODE if S390
80062 + select S390_EXEC_PROTECT if S390
80063 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80064 + help
80065 + This implementation is based on the paging feature of the CPU.
80066 + On i386 without hardware non-executable bit support there is a
80067 + variable but usually low performance impact, however on Intel's
80068 + P4 core based CPUs it is very high so you should not enable this
80069 + for kernels meant to be used on such CPUs.
80070 +
80071 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80072 + with hardware non-executable bit support there is no performance
80073 + impact, on ppc the impact is negligible.
80074 +
80075 + Note that several architectures require various emulations due to
80076 + badly designed userland ABIs, this will cause a performance impact
80077 + but will disappear as soon as userland is fixed. For example, ppc
80078 + userland MUST have been built with secure-plt by a recent toolchain.
80079 +
80080 +config PAX_SEGMEXEC
80081 + bool "Segmentation based non-executable pages"
80082 + default y if GRKERNSEC_CONFIG_AUTO
80083 + depends on PAX_NOEXEC && X86_32
80084 + help
80085 + This implementation is based on the segmentation feature of the
80086 + CPU and has a very small performance impact, however applications
80087 + will be limited to a 1.5 GB address space instead of the normal
80088 + 3 GB.
80089 +
80090 +config PAX_EMUTRAMP
80091 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80092 + default y if PARISC
80093 + help
80094 + There are some programs and libraries that for one reason or
80095 + another attempt to execute special small code snippets from
80096 + non-executable memory pages. Most notable examples are the
80097 + signal handler return code generated by the kernel itself and
80098 + the GCC trampolines.
80099 +
80100 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80101 + such programs will no longer work under your kernel.
80102 +
80103 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80104 + utilities to enable trampoline emulation for the affected programs
80105 + yet still have the protection provided by the non-executable pages.
80106 +
80107 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80108 + your system will not even boot.
80109 +
80110 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80111 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80112 + for the affected files.
80113 +
80114 + NOTE: enabling this feature *may* open up a loophole in the
80115 + protection provided by non-executable pages that an attacker
80116 + could abuse. Therefore the best solution is to not have any
80117 + files on your system that would require this option. This can
80118 + be achieved by not using libc5 (which relies on the kernel
80119 + signal handler return code) and not using or rewriting programs
80120 + that make use of the nested function implementation of GCC.
80121 + Skilled users can just fix GCC itself so that it implements
80122 + nested function calls in a way that does not interfere with PaX.
80123 +
80124 +config PAX_EMUSIGRT
80125 + bool "Automatically emulate sigreturn trampolines"
80126 + depends on PAX_EMUTRAMP && PARISC
80127 + default y
80128 + help
80129 + Enabling this option will have the kernel automatically detect
80130 + and emulate signal return trampolines executing on the stack
80131 + that would otherwise lead to task termination.
80132 +
80133 + This solution is intended as a temporary one for users with
80134 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80135 + Modula-3 runtime, etc) or executables linked to such, basically
80136 + everything that does not specify its own SA_RESTORER function in
80137 + normal executable memory like glibc 2.1+ does.
80138 +
80139 + On parisc you MUST enable this option, otherwise your system will
80140 + not even boot.
80141 +
80142 + NOTE: this feature cannot be disabled on a per executable basis
80143 + and since it *does* open up a loophole in the protection provided
80144 + by non-executable pages, the best solution is to not have any
80145 + files on your system that would require this option.
80146 +
80147 +config PAX_MPROTECT
80148 + bool "Restrict mprotect()"
80149 + default y if GRKERNSEC_CONFIG_AUTO
80150 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80151 + help
80152 + Enabling this option will prevent programs from
80153 + - changing the executable status of memory pages that were
80154 + not originally created as executable,
80155 + - making read-only executable pages writable again,
80156 + - creating executable pages from anonymous memory,
80157 + - making read-only-after-relocations (RELRO) data pages writable again.
80158 +
80159 + You should say Y here to complete the protection provided by
80160 + the enforcement of non-executable pages.
80161 +
80162 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80163 + this feature on a per file basis.
80164 +
80165 +config PAX_MPROTECT_COMPAT
80166 + bool "Use legacy/compat protection demoting (read help)"
80167 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80168 + depends on PAX_MPROTECT
80169 + help
80170 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80171 + by sending the proper error code to the application. For some broken
80172 + userland, this can cause problems with Python or other applications. The
80173 + current implementation however allows for applications like clamav to
80174 + detect if JIT compilation/execution is allowed and to fall back gracefully
80175 + to an interpreter-based mode if it does not. While we encourage everyone
80176 + to use the current implementation as-is and push upstream to fix broken
80177 + userland (note that the RWX logging option can assist with this), in some
80178 + environments this may not be possible. Having to disable MPROTECT
80179 + completely on certain binaries reduces the security benefit of PaX,
80180 + so this option is provided for those environments to revert to the old
80181 + behavior.
80182 +
80183 +config PAX_ELFRELOCS
80184 + bool "Allow ELF text relocations (read help)"
80185 + depends on PAX_MPROTECT
80186 + default n
80187 + help
80188 + Non-executable pages and mprotect() restrictions are effective
80189 + in preventing the introduction of new executable code into an
80190 + attacked task's address space. There remain only two venues
80191 + for this kind of attack: if the attacker can execute already
80192 + existing code in the attacked task then he can either have it
80193 + create and mmap() a file containing his code or have it mmap()
80194 + an already existing ELF library that does not have position
80195 + independent code in it and use mprotect() on it to make it
80196 + writable and copy his code there. While protecting against
80197 + the former approach is beyond PaX, the latter can be prevented
80198 + by having only PIC ELF libraries on one's system (which do not
80199 + need to relocate their code). If you are sure this is your case,
80200 + as is the case with all modern Linux distributions, then leave
80201 + this option disabled. You should say 'n' here.
80202 +
80203 +config PAX_ETEXECRELOCS
80204 + bool "Allow ELF ET_EXEC text relocations"
80205 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80206 + select PAX_ELFRELOCS
80207 + default y
80208 + help
80209 + On some architectures there are incorrectly created applications
80210 + that require text relocations and would not work without enabling
80211 + this option. If you are an alpha, ia64 or parisc user, you should
80212 + enable this option and disable it once you have made sure that
80213 + none of your applications need it.
80214 +
80215 +config PAX_EMUPLT
80216 + bool "Automatically emulate ELF PLT"
80217 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80218 + default y
80219 + help
80220 + Enabling this option will have the kernel automatically detect
80221 + and emulate the Procedure Linkage Table entries in ELF files.
80222 + On some architectures such entries are in writable memory, and
80223 + become non-executable leading to task termination. Therefore
80224 + it is mandatory that you enable this option on alpha, parisc,
80225 + sparc and sparc64, otherwise your system would not even boot.
80226 +
80227 + NOTE: this feature *does* open up a loophole in the protection
80228 + provided by the non-executable pages, therefore the proper
80229 + solution is to modify the toolchain to produce a PLT that does
80230 + not need to be writable.
80231 +
80232 +config PAX_DLRESOLVE
80233 + bool 'Emulate old glibc resolver stub'
80234 + depends on PAX_EMUPLT && SPARC
80235 + default n
80236 + help
80237 + This option is needed if userland has an old glibc (before 2.4)
80238 + that puts a 'save' instruction into the runtime generated resolver
80239 + stub that needs special emulation.
80240 +
80241 +config PAX_KERNEXEC
80242 + bool "Enforce non-executable kernel pages"
80243 + 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))
80244 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80245 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80246 + select PAX_KERNEXEC_PLUGIN if X86_64
80247 + help
80248 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80249 + that is, enabling this option will make it harder to inject
80250 + and execute 'foreign' code in kernel memory itself.
80251 +
80252 + Note that on x86_64 kernels there is a known regression when
80253 + this feature and KVM/VMX are both enabled in the host kernel.
80254 +
80255 +choice
80256 + prompt "Return Address Instrumentation Method"
80257 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80258 + depends on PAX_KERNEXEC_PLUGIN
80259 + help
80260 + Select the method used to instrument function pointer dereferences.
80261 + Note that binary modules cannot be instrumented by this approach.
80262 +
80263 + Note that the implementation requires a gcc with plugin support,
80264 + i.e., gcc 4.5 or newer. You may need to install the supporting
80265 + headers explicitly in addition to the normal gcc package.
80266 +
80267 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80268 + bool "bts"
80269 + help
80270 + This method is compatible with binary only modules but has
80271 + a higher runtime overhead.
80272 +
80273 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80274 + bool "or"
80275 + depends on !PARAVIRT
80276 + help
80277 + This method is incompatible with binary only modules but has
80278 + a lower runtime overhead.
80279 +endchoice
80280 +
80281 +config PAX_KERNEXEC_PLUGIN_METHOD
80282 + string
80283 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80284 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80285 + default ""
80286 +
80287 +config PAX_KERNEXEC_MODULE_TEXT
80288 + int "Minimum amount of memory reserved for module code"
80289 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80290 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80291 + depends on PAX_KERNEXEC && X86_32 && MODULES
80292 + help
80293 + Due to implementation details the kernel must reserve a fixed
80294 + amount of memory for module code at compile time that cannot be
80295 + changed at runtime. Here you can specify the minimum amount
80296 + in MB that will be reserved. Due to the same implementation
80297 + details this size will always be rounded up to the next 2/4 MB
80298 + boundary (depends on PAE) so the actually available memory for
80299 + module code will usually be more than this minimum.
80300 +
80301 + The default 4 MB should be enough for most users but if you have
80302 + an excessive number of modules (e.g., most distribution configs
80303 + compile many drivers as modules) or use huge modules such as
80304 + nvidia's kernel driver, you will need to adjust this amount.
80305 + A good rule of thumb is to look at your currently loaded kernel
80306 + modules and add up their sizes.
80307 +
80308 +endmenu
80309 +
80310 +menu "Address Space Layout Randomization"
80311 + depends on PAX
80312 +
80313 +config PAX_ASLR
80314 + bool "Address Space Layout Randomization"
80315 + default y if GRKERNSEC_CONFIG_AUTO
80316 + help
80317 + Many if not most exploit techniques rely on the knowledge of
80318 + certain addresses in the attacked program. The following options
80319 + will allow the kernel to apply a certain amount of randomization
80320 + to specific parts of the program thereby forcing an attacker to
80321 + guess them in most cases. Any failed guess will most likely crash
80322 + the attacked program which allows the kernel to detect such attempts
80323 + and react on them. PaX itself provides no reaction mechanisms,
80324 + instead it is strongly encouraged that you make use of Nergal's
80325 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80326 + (http://www.grsecurity.net/) built-in crash detection features or
80327 + develop one yourself.
80328 +
80329 + By saying Y here you can choose to randomize the following areas:
80330 + - top of the task's kernel stack
80331 + - top of the task's userland stack
80332 + - base address for mmap() requests that do not specify one
80333 + (this includes all libraries)
80334 + - base address of the main executable
80335 +
80336 + It is strongly recommended to say Y here as address space layout
80337 + randomization has negligible impact on performance yet it provides
80338 + a very effective protection.
80339 +
80340 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80341 + this feature on a per file basis.
80342 +
80343 +config PAX_RANDKSTACK
80344 + bool "Randomize kernel stack base"
80345 + default y if GRKERNSEC_CONFIG_AUTO
80346 + depends on X86_TSC && X86
80347 + help
80348 + By saying Y here the kernel will randomize every task's kernel
80349 + stack on every system call. This will not only force an attacker
80350 + to guess it but also prevent him from making use of possible
80351 + leaked information about it.
80352 +
80353 + Since the kernel stack is a rather scarce resource, randomization
80354 + may cause unexpected stack overflows, therefore you should very
80355 + carefully test your system. Note that once enabled in the kernel
80356 + configuration, this feature cannot be disabled on a per file basis.
80357 +
80358 +config PAX_RANDUSTACK
80359 + bool "Randomize user stack base"
80360 + default y if GRKERNSEC_CONFIG_AUTO
80361 + depends on PAX_ASLR
80362 + help
80363 + By saying Y here the kernel will randomize every task's userland
80364 + stack. The randomization is done in two steps where the second
80365 + one may apply a big amount of shift to the top of the stack and
80366 + cause problems for programs that want to use lots of memory (more
80367 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80368 + For this reason the second step can be controlled by 'chpax' or
80369 + 'paxctl' on a per file basis.
80370 +
80371 +config PAX_RANDMMAP
80372 + bool "Randomize mmap() base"
80373 + default y if GRKERNSEC_CONFIG_AUTO
80374 + depends on PAX_ASLR
80375 + help
80376 + By saying Y here the kernel will use a randomized base address for
80377 + mmap() requests that do not specify one themselves. As a result
80378 + all dynamically loaded libraries will appear at random addresses
80379 + and therefore be harder to exploit by a technique where an attacker
80380 + attempts to execute library code for his purposes (e.g. spawn a
80381 + shell from an exploited program that is running at an elevated
80382 + privilege level).
80383 +
80384 + Furthermore, if a program is relinked as a dynamic ELF file, its
80385 + base address will be randomized as well, completing the full
80386 + randomization of the address space layout. Attacking such programs
80387 + becomes a guess game. You can find an example of doing this at
80388 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80389 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80390 +
80391 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80392 + feature on a per file basis.
80393 +
80394 +endmenu
80395 +
80396 +menu "Miscellaneous hardening features"
80397 +
80398 +config PAX_MEMORY_SANITIZE
80399 + bool "Sanitize all freed memory"
80400 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80401 + depends on !HIBERNATION
80402 + help
80403 + By saying Y here the kernel will erase memory pages as soon as they
80404 + are freed. This in turn reduces the lifetime of data stored in the
80405 + pages, making it less likely that sensitive information such as
80406 + passwords, cryptographic secrets, etc stay in memory for too long.
80407 +
80408 + This is especially useful for programs whose runtime is short, long
80409 + lived processes and the kernel itself benefit from this as long as
80410 + they operate on whole memory pages and ensure timely freeing of pages
80411 + that may hold sensitive information.
80412 +
80413 + The tradeoff is performance impact, on a single CPU system kernel
80414 + compilation sees a 3% slowdown, other systems and workloads may vary
80415 + and you are advised to test this feature on your expected workload
80416 + before deploying it.
80417 +
80418 + Note that this feature does not protect data stored in live pages,
80419 + e.g., process memory swapped to disk may stay there for a long time.
80420 +
80421 +config PAX_MEMORY_STACKLEAK
80422 + bool "Sanitize kernel stack"
80423 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80424 + depends on X86
80425 + help
80426 + By saying Y here the kernel will erase the kernel stack before it
80427 + returns from a system call. This in turn reduces the information
80428 + that a kernel stack leak bug can reveal.
80429 +
80430 + Note that such a bug can still leak information that was put on
80431 + the stack by the current system call (the one eventually triggering
80432 + the bug) but traces of earlier system calls on the kernel stack
80433 + cannot leak anymore.
80434 +
80435 + The tradeoff is performance impact: on a single CPU system kernel
80436 + compilation sees a 1% slowdown, other systems and workloads may vary
80437 + and you are advised to test this feature on your expected workload
80438 + before deploying it.
80439 +
80440 + Note that the full feature requires a gcc with plugin support,
80441 + i.e., gcc 4.5 or newer. You may need to install the supporting
80442 + headers explicitly in addition to the normal gcc package. Using
80443 + older gcc versions means that functions with large enough stack
80444 + frames may leave uninitialized memory behind that may be exposed
80445 + to a later syscall leaking the stack.
80446 +
80447 +config PAX_MEMORY_UDEREF
80448 + bool "Prevent invalid userland pointer dereference"
80449 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80450 + depends on X86 && !UML_X86 && !XEN
80451 + select PAX_PER_CPU_PGD if X86_64
80452 + help
80453 + By saying Y here the kernel will be prevented from dereferencing
80454 + userland pointers in contexts where the kernel expects only kernel
80455 + pointers. This is both a useful runtime debugging feature and a
80456 + security measure that prevents exploiting a class of kernel bugs.
80457 +
80458 + The tradeoff is that some virtualization solutions may experience
80459 + a huge slowdown and therefore you should not enable this feature
80460 + for kernels meant to run in such environments. Whether a given VM
80461 + solution is affected or not is best determined by simply trying it
80462 + out, the performance impact will be obvious right on boot as this
80463 + mechanism engages from very early on. A good rule of thumb is that
80464 + VMs running on CPUs without hardware virtualization support (i.e.,
80465 + the majority of IA-32 CPUs) will likely experience the slowdown.
80466 +
80467 +config PAX_REFCOUNT
80468 + bool "Prevent various kernel object reference counter overflows"
80469 + default y if GRKERNSEC_CONFIG_AUTO
80470 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80471 + help
80472 + By saying Y here the kernel will detect and prevent overflowing
80473 + various (but not all) kinds of object reference counters. Such
80474 + overflows can normally occur due to bugs only and are often, if
80475 + not always, exploitable.
80476 +
80477 + The tradeoff is that data structures protected by an overflowed
80478 + refcount will never be freed and therefore will leak memory. Note
80479 + that this leak also happens even without this protection but in
80480 + that case the overflow can eventually trigger the freeing of the
80481 + data structure while it is still being used elsewhere, resulting
80482 + in the exploitable situation that this feature prevents.
80483 +
80484 + Since this has a negligible performance impact, you should enable
80485 + this feature.
80486 +
80487 +config PAX_USERCOPY
80488 + bool "Harden heap object copies between kernel and userland"
80489 + default y if GRKERNSEC_CONFIG_AUTO
80490 + depends on X86 || PPC || SPARC || ARM
80491 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80492 + select PAX_USERCOPY_SLABS
80493 + help
80494 + By saying Y here the kernel will enforce the size of heap objects
80495 + when they are copied in either direction between the kernel and
80496 + userland, even if only a part of the heap object is copied.
80497 +
80498 + Specifically, this checking prevents information leaking from the
80499 + kernel heap during kernel to userland copies (if the kernel heap
80500 + object is otherwise fully initialized) and prevents kernel heap
80501 + overflows during userland to kernel copies.
80502 +
80503 + Note that the current implementation provides the strictest bounds
80504 + checks for the SLUB allocator.
80505 +
80506 + Enabling this option also enables per-slab cache protection against
80507 + data in a given cache being copied into/out of via userland
80508 + accessors. Though the whitelist of regions will be reduced over
80509 + time, it notably protects important data structures like task structs.
80510 +
80511 + If frame pointers are enabled on x86, this option will also restrict
80512 + copies into and out of the kernel stack to local variables within a
80513 + single frame.
80514 +
80515 + Since this has a negligible performance impact, you should enable
80516 + this feature.
80517 +
80518 +config PAX_SIZE_OVERFLOW
80519 + bool "Prevent various integer overflows in function size parameters"
80520 + default y if GRKERNSEC_CONFIG_AUTO
80521 + depends on X86
80522 + help
80523 + By saying Y here the kernel recomputes expressions of function
80524 + arguments marked by a size_overflow attribute with double integer
80525 + precision (DImode/TImode for 32/64 bit integer types).
80526 +
80527 + The recomputed argument is checked against TYPE_MAX and an event
80528 + is logged on overflow and the triggering process is killed.
80529 +
80530 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80531 +
80532 + Note that the implementation requires a gcc with plugin support,
80533 + i.e., gcc 4.5 or newer. You may need to install the supporting
80534 + headers explicitly in addition to the normal gcc package.
80535 +
80536 +config PAX_LATENT_ENTROPY
80537 + bool "Generate some entropy during boot"
80538 + default y if GRKERNSEC_CONFIG_AUTO
80539 + help
80540 + By saying Y here the kernel will instrument early boot code to
80541 + extract some entropy from both original and artificially created
80542 + program state. This will help especially embedded systems where
80543 + there is little 'natural' source of entropy normally. The cost
80544 + is some slowdown of the boot process.
80545 +
80546 + Note that the implementation requires a gcc with plugin support,
80547 + i.e., gcc 4.5 or newer. You may need to install the supporting
80548 + headers explicitly in addition to the normal gcc package.
80549 +
80550 + Note that entropy extracted this way is not cryptographically
80551 + secure!
80552 +
80553 +endmenu
80554 +
80555 +endmenu
80556 +
80557 +source grsecurity/Kconfig
80558 +
80559 +endmenu
80560 +
80561 +endmenu
80562 +
80563 source security/keys/Kconfig
80564
80565 config SECURITY_DMESG_RESTRICT
80566 @@ -103,7 +985,7 @@ config INTEL_TXT
80567 config LSM_MMAP_MIN_ADDR
80568 int "Low address space for LSM to protect from user allocation"
80569 depends on SECURITY && SECURITY_SELINUX
80570 - default 32768 if ARM
80571 + default 32768 if ALPHA || ARM || PARISC || SPARC32
80572 default 65536
80573 help
80574 This is the portion of low virtual memory which should be protected
80575 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
80576 index 8ea39aa..8569ac5 100644
80577 --- a/security/apparmor/lsm.c
80578 +++ b/security/apparmor/lsm.c
80579 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
80580 return error;
80581 }
80582
80583 -static struct security_operations apparmor_ops = {
80584 +static struct security_operations apparmor_ops __read_only = {
80585 .name = "apparmor",
80586
80587 .ptrace_access_check = apparmor_ptrace_access_check,
80588 diff --git a/security/commoncap.c b/security/commoncap.c
80589 index 6dbae46..d5611fd 100644
80590 --- a/security/commoncap.c
80591 +++ b/security/commoncap.c
80592 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
80593 return 0;
80594 }
80595
80596 +/* returns:
80597 + 1 for suid privilege
80598 + 2 for sgid privilege
80599 + 3 for fscap privilege
80600 +*/
80601 +int is_privileged_binary(const struct dentry *dentry)
80602 +{
80603 + struct cpu_vfs_cap_data capdata;
80604 + struct inode *inode = dentry->d_inode;
80605 +
80606 + if (!inode || S_ISDIR(inode->i_mode))
80607 + return 0;
80608 +
80609 + if (inode->i_mode & S_ISUID)
80610 + return 1;
80611 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
80612 + return 2;
80613 +
80614 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
80615 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
80616 + return 3;
80617 + }
80618 +
80619 + return 0;
80620 +}
80621 +
80622 /*
80623 * Attempt to get the on-exec apply capability sets for an executable file from
80624 * its xattrs and, if present, apply them to the proposed credentials being
80625 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80626 const struct cred *cred = current_cred();
80627 kuid_t root_uid = make_kuid(cred->user_ns, 0);
80628
80629 + if (gr_acl_enable_at_secure())
80630 + return 1;
80631 +
80632 if (!uid_eq(cred->uid, root_uid)) {
80633 if (bprm->cap_effective)
80634 return 1;
80635 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80636 index 3ccf7ac..d73ad64 100644
80637 --- a/security/integrity/ima/ima.h
80638 +++ b/security/integrity/ima/ima.h
80639 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80640 extern spinlock_t ima_queue_lock;
80641
80642 struct ima_h_table {
80643 - atomic_long_t len; /* number of stored measurements in the list */
80644 - atomic_long_t violations;
80645 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80646 + atomic_long_unchecked_t violations;
80647 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80648 };
80649 extern struct ima_h_table ima_htable;
80650 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80651 index 88a2788..581ab92 100644
80652 --- a/security/integrity/ima/ima_api.c
80653 +++ b/security/integrity/ima/ima_api.c
80654 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80655 int result;
80656
80657 /* can overflow, only indicator */
80658 - atomic_long_inc(&ima_htable.violations);
80659 + atomic_long_inc_unchecked(&ima_htable.violations);
80660
80661 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80662 if (!entry) {
80663 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80664 index e1aa2b4..52027bf 100644
80665 --- a/security/integrity/ima/ima_fs.c
80666 +++ b/security/integrity/ima/ima_fs.c
80667 @@ -28,12 +28,12 @@
80668 static int valid_policy = 1;
80669 #define TMPBUFLEN 12
80670 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80671 - loff_t *ppos, atomic_long_t *val)
80672 + loff_t *ppos, atomic_long_unchecked_t *val)
80673 {
80674 char tmpbuf[TMPBUFLEN];
80675 ssize_t len;
80676
80677 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80678 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80679 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80680 }
80681
80682 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80683 index 55a6271..ad829c3 100644
80684 --- a/security/integrity/ima/ima_queue.c
80685 +++ b/security/integrity/ima/ima_queue.c
80686 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80687 INIT_LIST_HEAD(&qe->later);
80688 list_add_tail_rcu(&qe->later, &ima_measurements);
80689
80690 - atomic_long_inc(&ima_htable.len);
80691 + atomic_long_inc_unchecked(&ima_htable.len);
80692 key = ima_hash_key(entry->digest);
80693 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80694 return 0;
80695 diff --git a/security/keys/compat.c b/security/keys/compat.c
80696 index c92d42b..341e7ea 100644
80697 --- a/security/keys/compat.c
80698 +++ b/security/keys/compat.c
80699 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80700 if (ret == 0)
80701 goto no_payload_free;
80702
80703 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80704 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80705
80706 if (iov != iovstack)
80707 kfree(iov);
80708 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80709 index 0f5b3f0..b8d47c1 100644
80710 --- a/security/keys/keyctl.c
80711 +++ b/security/keys/keyctl.c
80712 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80713 /*
80714 * Copy the iovec data from userspace
80715 */
80716 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80717 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80718 unsigned ioc)
80719 {
80720 for (; ioc > 0; ioc--) {
80721 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80722 * If successful, 0 will be returned.
80723 */
80724 long keyctl_instantiate_key_common(key_serial_t id,
80725 - const struct iovec *payload_iov,
80726 + const struct iovec __user *payload_iov,
80727 unsigned ioc,
80728 size_t plen,
80729 key_serial_t ringid)
80730 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
80731 [0].iov_len = plen
80732 };
80733
80734 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80735 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80736 }
80737
80738 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80739 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80740 if (ret == 0)
80741 goto no_payload_free;
80742
80743 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80744 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80745
80746 if (iov != iovstack)
80747 kfree(iov);
80748 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80749 index 7445875..262834f 100644
80750 --- a/security/keys/keyring.c
80751 +++ b/security/keys/keyring.c
80752 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
80753 ret = -EFAULT;
80754
80755 for (loop = 0; loop < klist->nkeys; loop++) {
80756 + key_serial_t serial;
80757 key = rcu_deref_link_locked(klist, loop,
80758 keyring);
80759 + serial = key->serial;
80760
80761 tmp = sizeof(key_serial_t);
80762 if (tmp > buflen)
80763 tmp = buflen;
80764
80765 - if (copy_to_user(buffer,
80766 - &key->serial,
80767 - tmp) != 0)
80768 + if (copy_to_user(buffer, &serial, tmp))
80769 goto error;
80770
80771 buflen -= tmp;
80772 diff --git a/security/min_addr.c b/security/min_addr.c
80773 index f728728..6457a0c 100644
80774 --- a/security/min_addr.c
80775 +++ b/security/min_addr.c
80776 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80777 */
80778 static void update_mmap_min_addr(void)
80779 {
80780 +#ifndef SPARC
80781 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80782 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80783 mmap_min_addr = dac_mmap_min_addr;
80784 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80785 #else
80786 mmap_min_addr = dac_mmap_min_addr;
80787 #endif
80788 +#endif
80789 }
80790
80791 /*
80792 diff --git a/security/security.c b/security/security.c
80793 index 860aeb3..45765c0 100644
80794 --- a/security/security.c
80795 +++ b/security/security.c
80796 @@ -20,6 +20,7 @@
80797 #include <linux/ima.h>
80798 #include <linux/evm.h>
80799 #include <linux/fsnotify.h>
80800 +#include <linux/mm.h>
80801 #include <linux/mman.h>
80802 #include <linux/mount.h>
80803 #include <linux/personality.h>
80804 @@ -32,8 +33,8 @@
80805 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80806 CONFIG_DEFAULT_SECURITY;
80807
80808 -static struct security_operations *security_ops;
80809 -static struct security_operations default_security_ops = {
80810 +static struct security_operations *security_ops __read_only;
80811 +static struct security_operations default_security_ops __read_only = {
80812 .name = "default",
80813 };
80814
80815 @@ -74,7 +75,9 @@ int __init security_init(void)
80816
80817 void reset_security_ops(void)
80818 {
80819 + pax_open_kernel();
80820 security_ops = &default_security_ops;
80821 + pax_close_kernel();
80822 }
80823
80824 /* Save user chosen LSM */
80825 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80826 index db10db2..99a640f 100644
80827 --- a/security/selinux/hooks.c
80828 +++ b/security/selinux/hooks.c
80829 @@ -95,8 +95,6 @@
80830
80831 #define NUM_SEL_MNT_OPTS 5
80832
80833 -extern struct security_operations *security_ops;
80834 -
80835 /* SECMARK reference count */
80836 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80837
80838 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80839
80840 #endif
80841
80842 -static struct security_operations selinux_ops = {
80843 +static struct security_operations selinux_ops __read_only = {
80844 .name = "selinux",
80845
80846 .ptrace_access_check = selinux_ptrace_access_check,
80847 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80848 index c220f31..89fab3f 100644
80849 --- a/security/selinux/include/xfrm.h
80850 +++ b/security/selinux/include/xfrm.h
80851 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80852
80853 static inline void selinux_xfrm_notify_policyload(void)
80854 {
80855 - atomic_inc(&flow_cache_genid);
80856 + atomic_inc_unchecked(&flow_cache_genid);
80857 }
80858 #else
80859 static inline int selinux_xfrm_enabled(void)
80860 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80861 index ee0bb57..57fcd43 100644
80862 --- a/security/smack/smack_lsm.c
80863 +++ b/security/smack/smack_lsm.c
80864 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80865 return 0;
80866 }
80867
80868 -struct security_operations smack_ops = {
80869 +struct security_operations smack_ops __read_only = {
80870 .name = "smack",
80871
80872 .ptrace_access_check = smack_ptrace_access_check,
80873 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80874 index c2d04a5..e6a1aeb 100644
80875 --- a/security/tomoyo/tomoyo.c
80876 +++ b/security/tomoyo/tomoyo.c
80877 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80878 * tomoyo_security_ops is a "struct security_operations" which is used for
80879 * registering TOMOYO.
80880 */
80881 -static struct security_operations tomoyo_security_ops = {
80882 +static struct security_operations tomoyo_security_ops __read_only = {
80883 .name = "tomoyo",
80884 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80885 .cred_prepare = tomoyo_cred_prepare,
80886 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
80887 index 51d6709..1f3dbe2 100644
80888 --- a/security/yama/Kconfig
80889 +++ b/security/yama/Kconfig
80890 @@ -1,6 +1,6 @@
80891 config SECURITY_YAMA
80892 bool "Yama support"
80893 - depends on SECURITY
80894 + depends on SECURITY && !GRKERNSEC
80895 select SECURITYFS
80896 select SECURITY_PATH
80897 default n
80898 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80899 index 270790d..c67dfcb 100644
80900 --- a/sound/aoa/codecs/onyx.c
80901 +++ b/sound/aoa/codecs/onyx.c
80902 @@ -54,7 +54,7 @@ struct onyx {
80903 spdif_locked:1,
80904 analog_locked:1,
80905 original_mute:2;
80906 - int open_count;
80907 + local_t open_count;
80908 struct codec_info *codec_info;
80909
80910 /* mutex serializes concurrent access to the device
80911 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80912 struct onyx *onyx = cii->codec_data;
80913
80914 mutex_lock(&onyx->mutex);
80915 - onyx->open_count++;
80916 + local_inc(&onyx->open_count);
80917 mutex_unlock(&onyx->mutex);
80918
80919 return 0;
80920 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80921 struct onyx *onyx = cii->codec_data;
80922
80923 mutex_lock(&onyx->mutex);
80924 - onyx->open_count--;
80925 - if (!onyx->open_count)
80926 + if (local_dec_and_test(&onyx->open_count))
80927 onyx->spdif_locked = onyx->analog_locked = 0;
80928 mutex_unlock(&onyx->mutex);
80929
80930 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80931 index ffd2025..df062c9 100644
80932 --- a/sound/aoa/codecs/onyx.h
80933 +++ b/sound/aoa/codecs/onyx.h
80934 @@ -11,6 +11,7 @@
80935 #include <linux/i2c.h>
80936 #include <asm/pmac_low_i2c.h>
80937 #include <asm/prom.h>
80938 +#include <asm/local.h>
80939
80940 /* PCM3052 register definitions */
80941
80942 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80943 index 08fde00..0bf641a 100644
80944 --- a/sound/core/oss/pcm_oss.c
80945 +++ b/sound/core/oss/pcm_oss.c
80946 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80947 if (in_kernel) {
80948 mm_segment_t fs;
80949 fs = snd_enter_user();
80950 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80951 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80952 snd_leave_user(fs);
80953 } else {
80954 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80955 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80956 }
80957 if (ret != -EPIPE && ret != -ESTRPIPE)
80958 break;
80959 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80960 if (in_kernel) {
80961 mm_segment_t fs;
80962 fs = snd_enter_user();
80963 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80964 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80965 snd_leave_user(fs);
80966 } else {
80967 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80968 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80969 }
80970 if (ret == -EPIPE) {
80971 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80972 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80973 struct snd_pcm_plugin_channel *channels;
80974 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80975 if (!in_kernel) {
80976 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80977 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80978 return -EFAULT;
80979 buf = runtime->oss.buffer;
80980 }
80981 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80982 }
80983 } else {
80984 tmp = snd_pcm_oss_write2(substream,
80985 - (const char __force *)buf,
80986 + (const char __force_kernel *)buf,
80987 runtime->oss.period_bytes, 0);
80988 if (tmp <= 0)
80989 goto err;
80990 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80991 struct snd_pcm_runtime *runtime = substream->runtime;
80992 snd_pcm_sframes_t frames, frames1;
80993 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80994 - char __user *final_dst = (char __force __user *)buf;
80995 + char __user *final_dst = (char __force_user *)buf;
80996 if (runtime->oss.plugin_first) {
80997 struct snd_pcm_plugin_channel *channels;
80998 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80999 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81000 xfer += tmp;
81001 runtime->oss.buffer_used -= tmp;
81002 } else {
81003 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81004 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81005 runtime->oss.period_bytes, 0);
81006 if (tmp <= 0)
81007 goto err;
81008 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81009 size1);
81010 size1 /= runtime->channels; /* frames */
81011 fs = snd_enter_user();
81012 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81013 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81014 snd_leave_user(fs);
81015 }
81016 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81017 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81018 index 91cdf94..4085161 100644
81019 --- a/sound/core/pcm_compat.c
81020 +++ b/sound/core/pcm_compat.c
81021 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81022 int err;
81023
81024 fs = snd_enter_user();
81025 - err = snd_pcm_delay(substream, &delay);
81026 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81027 snd_leave_user(fs);
81028 if (err < 0)
81029 return err;
81030 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81031 index 53b5ada..2db94c8 100644
81032 --- a/sound/core/pcm_native.c
81033 +++ b/sound/core/pcm_native.c
81034 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81035 switch (substream->stream) {
81036 case SNDRV_PCM_STREAM_PLAYBACK:
81037 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81038 - (void __user *)arg);
81039 + (void __force_user *)arg);
81040 break;
81041 case SNDRV_PCM_STREAM_CAPTURE:
81042 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81043 - (void __user *)arg);
81044 + (void __force_user *)arg);
81045 break;
81046 default:
81047 result = -EINVAL;
81048 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81049 index 5cf8d65..912a79c 100644
81050 --- a/sound/core/seq/seq_device.c
81051 +++ b/sound/core/seq/seq_device.c
81052 @@ -64,7 +64,7 @@ struct ops_list {
81053 int argsize; /* argument size */
81054
81055 /* operators */
81056 - struct snd_seq_dev_ops ops;
81057 + struct snd_seq_dev_ops *ops;
81058
81059 /* registred devices */
81060 struct list_head dev_list; /* list of devices */
81061 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81062
81063 mutex_lock(&ops->reg_mutex);
81064 /* copy driver operators */
81065 - ops->ops = *entry;
81066 + ops->ops = entry;
81067 ops->driver |= DRIVER_LOADED;
81068 ops->argsize = argsize;
81069
81070 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81071 dev->name, ops->id, ops->argsize, dev->argsize);
81072 return -EINVAL;
81073 }
81074 - if (ops->ops.init_device(dev) >= 0) {
81075 + if (ops->ops->init_device(dev) >= 0) {
81076 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81077 ops->num_init_devices++;
81078 } else {
81079 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81080 dev->name, ops->id, ops->argsize, dev->argsize);
81081 return -EINVAL;
81082 }
81083 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81084 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81085 dev->status = SNDRV_SEQ_DEVICE_FREE;
81086 dev->driver_data = NULL;
81087 ops->num_init_devices--;
81088 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81089 index 621e60e..f4543f5 100644
81090 --- a/sound/drivers/mts64.c
81091 +++ b/sound/drivers/mts64.c
81092 @@ -29,6 +29,7 @@
81093 #include <sound/initval.h>
81094 #include <sound/rawmidi.h>
81095 #include <sound/control.h>
81096 +#include <asm/local.h>
81097
81098 #define CARD_NAME "Miditerminal 4140"
81099 #define DRIVER_NAME "MTS64"
81100 @@ -67,7 +68,7 @@ struct mts64 {
81101 struct pardevice *pardev;
81102 int pardev_claimed;
81103
81104 - int open_count;
81105 + local_t open_count;
81106 int current_midi_output_port;
81107 int current_midi_input_port;
81108 u8 mode[MTS64_NUM_INPUT_PORTS];
81109 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81110 {
81111 struct mts64 *mts = substream->rmidi->private_data;
81112
81113 - if (mts->open_count == 0) {
81114 + if (local_read(&mts->open_count) == 0) {
81115 /* We don't need a spinlock here, because this is just called
81116 if the device has not been opened before.
81117 So there aren't any IRQs from the device */
81118 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81119
81120 msleep(50);
81121 }
81122 - ++(mts->open_count);
81123 + local_inc(&mts->open_count);
81124
81125 return 0;
81126 }
81127 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81128 struct mts64 *mts = substream->rmidi->private_data;
81129 unsigned long flags;
81130
81131 - --(mts->open_count);
81132 - if (mts->open_count == 0) {
81133 + if (local_dec_return(&mts->open_count) == 0) {
81134 /* We need the spinlock_irqsave here because we can still
81135 have IRQs at this point */
81136 spin_lock_irqsave(&mts->lock, flags);
81137 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81138
81139 msleep(500);
81140
81141 - } else if (mts->open_count < 0)
81142 - mts->open_count = 0;
81143 + } else if (local_read(&mts->open_count) < 0)
81144 + local_set(&mts->open_count, 0);
81145
81146 return 0;
81147 }
81148 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81149 index b953fb4..1999c01 100644
81150 --- a/sound/drivers/opl4/opl4_lib.c
81151 +++ b/sound/drivers/opl4/opl4_lib.c
81152 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81153 MODULE_DESCRIPTION("OPL4 driver");
81154 MODULE_LICENSE("GPL");
81155
81156 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81157 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81158 {
81159 int timeout = 10;
81160 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81161 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81162 index 3e32bd3..46fc152 100644
81163 --- a/sound/drivers/portman2x4.c
81164 +++ b/sound/drivers/portman2x4.c
81165 @@ -48,6 +48,7 @@
81166 #include <sound/initval.h>
81167 #include <sound/rawmidi.h>
81168 #include <sound/control.h>
81169 +#include <asm/local.h>
81170
81171 #define CARD_NAME "Portman 2x4"
81172 #define DRIVER_NAME "portman"
81173 @@ -85,7 +86,7 @@ struct portman {
81174 struct pardevice *pardev;
81175 int pardev_claimed;
81176
81177 - int open_count;
81178 + local_t open_count;
81179 int mode[PORTMAN_NUM_INPUT_PORTS];
81180 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81181 };
81182 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81183 index ea995af..f1bfa37 100644
81184 --- a/sound/firewire/amdtp.c
81185 +++ b/sound/firewire/amdtp.c
81186 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81187 ptr = s->pcm_buffer_pointer + data_blocks;
81188 if (ptr >= pcm->runtime->buffer_size)
81189 ptr -= pcm->runtime->buffer_size;
81190 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81191 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81192
81193 s->pcm_period_pointer += data_blocks;
81194 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81195 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81196 */
81197 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81198 {
81199 - ACCESS_ONCE(s->source_node_id_field) =
81200 + ACCESS_ONCE_RW(s->source_node_id_field) =
81201 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81202 }
81203 EXPORT_SYMBOL(amdtp_out_stream_update);
81204 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81205 index b680c5e..061b7a0 100644
81206 --- a/sound/firewire/amdtp.h
81207 +++ b/sound/firewire/amdtp.h
81208 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81209 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81210 struct snd_pcm_substream *pcm)
81211 {
81212 - ACCESS_ONCE(s->pcm) = pcm;
81213 + ACCESS_ONCE_RW(s->pcm) = pcm;
81214 }
81215
81216 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81217 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81218 index d428ffe..751ef78 100644
81219 --- a/sound/firewire/isight.c
81220 +++ b/sound/firewire/isight.c
81221 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81222 ptr += count;
81223 if (ptr >= runtime->buffer_size)
81224 ptr -= runtime->buffer_size;
81225 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81226 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81227
81228 isight->period_counter += count;
81229 if (isight->period_counter >= runtime->period_size) {
81230 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81231 if (err < 0)
81232 return err;
81233
81234 - ACCESS_ONCE(isight->pcm_active) = true;
81235 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81236
81237 return 0;
81238 }
81239 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81240 {
81241 struct isight *isight = substream->private_data;
81242
81243 - ACCESS_ONCE(isight->pcm_active) = false;
81244 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81245
81246 mutex_lock(&isight->mutex);
81247 isight_stop_streaming(isight);
81248 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81249
81250 switch (cmd) {
81251 case SNDRV_PCM_TRIGGER_START:
81252 - ACCESS_ONCE(isight->pcm_running) = true;
81253 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81254 break;
81255 case SNDRV_PCM_TRIGGER_STOP:
81256 - ACCESS_ONCE(isight->pcm_running) = false;
81257 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81258 break;
81259 default:
81260 return -EINVAL;
81261 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81262 index 7bd5e33..1fcab12 100644
81263 --- a/sound/isa/cmi8330.c
81264 +++ b/sound/isa/cmi8330.c
81265 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81266
81267 struct snd_pcm *pcm;
81268 struct snd_cmi8330_stream {
81269 - struct snd_pcm_ops ops;
81270 + snd_pcm_ops_no_const ops;
81271 snd_pcm_open_callback_t open;
81272 void *private_data; /* sb or wss */
81273 } streams[2];
81274 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81275 index 733b014..56ce96f 100644
81276 --- a/sound/oss/sb_audio.c
81277 +++ b/sound/oss/sb_audio.c
81278 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81279 buf16 = (signed short *)(localbuf + localoffs);
81280 while (c)
81281 {
81282 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81283 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81284 if (copy_from_user(lbuf8,
81285 userbuf+useroffs + p,
81286 locallen))
81287 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81288 index 09d4648..cf234c7 100644
81289 --- a/sound/oss/swarm_cs4297a.c
81290 +++ b/sound/oss/swarm_cs4297a.c
81291 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81292 {
81293 struct cs4297a_state *s;
81294 u32 pwr, id;
81295 - mm_segment_t fs;
81296 int rval;
81297 #ifndef CONFIG_BCM_CS4297A_CSWARM
81298 u64 cfg;
81299 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81300 if (!rval) {
81301 char *sb1250_duart_present;
81302
81303 +#if 0
81304 + mm_segment_t fs;
81305 fs = get_fs();
81306 set_fs(KERNEL_DS);
81307 -#if 0
81308 val = SOUND_MASK_LINE;
81309 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81310 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81311 val = initvol[i].vol;
81312 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81313 }
81314 + set_fs(fs);
81315 // cs4297a_write_ac97(s, 0x18, 0x0808);
81316 #else
81317 // cs4297a_write_ac97(s, 0x5e, 0x180);
81318 cs4297a_write_ac97(s, 0x02, 0x0808);
81319 cs4297a_write_ac97(s, 0x18, 0x0808);
81320 #endif
81321 - set_fs(fs);
81322
81323 list_add(&s->list, &cs4297a_devs);
81324
81325 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81326 index 2fdaadb..7df8fc6 100644
81327 --- a/sound/pci/hda/hda_codec.h
81328 +++ b/sound/pci/hda/hda_codec.h
81329 @@ -611,7 +611,7 @@ struct hda_bus_ops {
81330 /* notify power-up/down from codec to controller */
81331 void (*pm_notify)(struct hda_bus *bus);
81332 #endif
81333 -};
81334 +} __no_const;
81335
81336 /* template to pass to the bus constructor */
81337 struct hda_bus_template {
81338 @@ -711,6 +711,7 @@ struct hda_codec_ops {
81339 #endif
81340 void (*reboot_notify)(struct hda_codec *codec);
81341 };
81342 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81343
81344 /* record for amp information cache */
81345 struct hda_cache_head {
81346 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
81347 struct snd_pcm_substream *substream);
81348 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81349 struct snd_pcm_substream *substream);
81350 -};
81351 +} __no_const;
81352
81353 /* PCM information for each substream */
81354 struct hda_pcm_stream {
81355 @@ -799,7 +800,7 @@ struct hda_codec {
81356 const char *modelname; /* model name for preset */
81357
81358 /* set by patch */
81359 - struct hda_codec_ops patch_ops;
81360 + hda_codec_ops_no_const patch_ops;
81361
81362 /* PCM to create, set by patch_ops.build_pcms callback */
81363 unsigned int num_pcms;
81364 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81365 index 0da778a..bc38b84 100644
81366 --- a/sound/pci/ice1712/ice1712.h
81367 +++ b/sound/pci/ice1712/ice1712.h
81368 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81369 unsigned int mask_flags; /* total mask bits */
81370 struct snd_akm4xxx_ops {
81371 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81372 - } ops;
81373 + } __no_const ops;
81374 };
81375
81376 struct snd_ice1712_spdif {
81377 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81378 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81379 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81380 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81381 - } ops;
81382 + } __no_const ops;
81383 };
81384
81385
81386 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81387 index a8159b81..5f006a5 100644
81388 --- a/sound/pci/ymfpci/ymfpci_main.c
81389 +++ b/sound/pci/ymfpci/ymfpci_main.c
81390 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81391 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81392 break;
81393 }
81394 - if (atomic_read(&chip->interrupt_sleep_count)) {
81395 - atomic_set(&chip->interrupt_sleep_count, 0);
81396 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81397 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81398 wake_up(&chip->interrupt_sleep);
81399 }
81400 __end:
81401 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81402 continue;
81403 init_waitqueue_entry(&wait, current);
81404 add_wait_queue(&chip->interrupt_sleep, &wait);
81405 - atomic_inc(&chip->interrupt_sleep_count);
81406 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81407 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81408 remove_wait_queue(&chip->interrupt_sleep, &wait);
81409 }
81410 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81411 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81412 spin_unlock(&chip->reg_lock);
81413
81414 - if (atomic_read(&chip->interrupt_sleep_count)) {
81415 - atomic_set(&chip->interrupt_sleep_count, 0);
81416 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81417 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81418 wake_up(&chip->interrupt_sleep);
81419 }
81420 }
81421 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81422 spin_lock_init(&chip->reg_lock);
81423 spin_lock_init(&chip->voice_lock);
81424 init_waitqueue_head(&chip->interrupt_sleep);
81425 - atomic_set(&chip->interrupt_sleep_count, 0);
81426 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81427 chip->card = card;
81428 chip->pci = pci;
81429 chip->irq = -1;
81430 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81431 new file mode 100644
81432 index 0000000..50f2f2f
81433 --- /dev/null
81434 +++ b/tools/gcc/.gitignore
81435 @@ -0,0 +1 @@
81436 +size_overflow_hash.h
81437 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81438 new file mode 100644
81439 index 0000000..1d09b7e
81440 --- /dev/null
81441 +++ b/tools/gcc/Makefile
81442 @@ -0,0 +1,43 @@
81443 +#CC := gcc
81444 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81445 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81446 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81447 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81448 +
81449 +ifeq ($(PLUGINCC),$(HOSTCC))
81450 +HOSTLIBS := hostlibs
81451 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81452 +else
81453 +HOSTLIBS := hostcxxlibs
81454 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81455 +endif
81456 +
81457 +$(HOSTLIBS)-y := constify_plugin.so
81458 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81459 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81460 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81461 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81462 +$(HOSTLIBS)-y += colorize_plugin.so
81463 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81464 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81465 +
81466 +always := $($(HOSTLIBS)-y)
81467 +
81468 +constify_plugin-objs := constify_plugin.o
81469 +stackleak_plugin-objs := stackleak_plugin.o
81470 +kallocstat_plugin-objs := kallocstat_plugin.o
81471 +kernexec_plugin-objs := kernexec_plugin.o
81472 +checker_plugin-objs := checker_plugin.o
81473 +colorize_plugin-objs := colorize_plugin.o
81474 +size_overflow_plugin-objs := size_overflow_plugin.o
81475 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81476 +
81477 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81478 +
81479 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81480 + cmd_build_size_overflow_hash = \
81481 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81482 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81483 + $(call if_changed,build_size_overflow_hash)
81484 +
81485 +targets += size_overflow_hash.h
81486 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81487 new file mode 100644
81488 index 0000000..d41b5af
81489 --- /dev/null
81490 +++ b/tools/gcc/checker_plugin.c
81491 @@ -0,0 +1,171 @@
81492 +/*
81493 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81494 + * Licensed under the GPL v2
81495 + *
81496 + * Note: the choice of the license means that the compilation process is
81497 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81498 + * but for the kernel it doesn't matter since it doesn't link against
81499 + * any of the gcc libraries
81500 + *
81501 + * gcc plugin to implement various sparse (source code checker) features
81502 + *
81503 + * TODO:
81504 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81505 + *
81506 + * BUGS:
81507 + * - none known
81508 + */
81509 +#include "gcc-plugin.h"
81510 +#include "config.h"
81511 +#include "system.h"
81512 +#include "coretypes.h"
81513 +#include "tree.h"
81514 +#include "tree-pass.h"
81515 +#include "flags.h"
81516 +#include "intl.h"
81517 +#include "toplev.h"
81518 +#include "plugin.h"
81519 +//#include "expr.h" where are you...
81520 +#include "diagnostic.h"
81521 +#include "plugin-version.h"
81522 +#include "tm.h"
81523 +#include "function.h"
81524 +#include "basic-block.h"
81525 +#include "gimple.h"
81526 +#include "rtl.h"
81527 +#include "emit-rtl.h"
81528 +#include "tree-flow.h"
81529 +#include "target.h"
81530 +
81531 +extern void c_register_addr_space (const char *str, addr_space_t as);
81532 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81533 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81534 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
81535 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
81536 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
81537 +
81538 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81539 +extern rtx emit_move_insn(rtx x, rtx y);
81540 +
81541 +int plugin_is_GPL_compatible;
81542 +
81543 +static struct plugin_info checker_plugin_info = {
81544 + .version = "201111150100",
81545 +};
81546 +
81547 +#define ADDR_SPACE_KERNEL 0
81548 +#define ADDR_SPACE_FORCE_KERNEL 1
81549 +#define ADDR_SPACE_USER 2
81550 +#define ADDR_SPACE_FORCE_USER 3
81551 +#define ADDR_SPACE_IOMEM 0
81552 +#define ADDR_SPACE_FORCE_IOMEM 0
81553 +#define ADDR_SPACE_PERCPU 0
81554 +#define ADDR_SPACE_FORCE_PERCPU 0
81555 +#define ADDR_SPACE_RCU 0
81556 +#define ADDR_SPACE_FORCE_RCU 0
81557 +
81558 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81559 +{
81560 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81561 +}
81562 +
81563 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81564 +{
81565 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81566 +}
81567 +
81568 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81569 +{
81570 + return default_addr_space_valid_pointer_mode(mode, as);
81571 +}
81572 +
81573 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81574 +{
81575 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81576 +}
81577 +
81578 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81579 +{
81580 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81581 +}
81582 +
81583 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81584 +{
81585 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81586 + return true;
81587 +
81588 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81589 + return true;
81590 +
81591 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81592 + return true;
81593 +
81594 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81595 + return true;
81596 +
81597 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81598 + return true;
81599 +
81600 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81601 + return true;
81602 +
81603 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81604 + return true;
81605 +
81606 + return subset == superset;
81607 +}
81608 +
81609 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81610 +{
81611 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81612 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81613 +
81614 + return op;
81615 +}
81616 +
81617 +static void register_checker_address_spaces(void *event_data, void *data)
81618 +{
81619 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81620 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81621 + c_register_addr_space("__user", ADDR_SPACE_USER);
81622 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81623 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81624 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81625 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81626 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81627 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81628 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81629 +
81630 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81631 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81632 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81633 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81634 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81635 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81636 + targetm.addr_space.convert = checker_addr_space_convert;
81637 +}
81638 +
81639 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81640 +{
81641 + const char * const plugin_name = plugin_info->base_name;
81642 + const int argc = plugin_info->argc;
81643 + const struct plugin_argument * const argv = plugin_info->argv;
81644 + int i;
81645 +
81646 + if (!plugin_default_version_check(version, &gcc_version)) {
81647 + error(G_("incompatible gcc/plugin versions"));
81648 + return 1;
81649 + }
81650 +
81651 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81652 +
81653 + for (i = 0; i < argc; ++i)
81654 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81655 +
81656 + if (TARGET_64BIT == 0)
81657 + return 0;
81658 +
81659 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81660 +
81661 + return 0;
81662 +}
81663 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
81664 new file mode 100644
81665 index 0000000..846aeb0
81666 --- /dev/null
81667 +++ b/tools/gcc/colorize_plugin.c
81668 @@ -0,0 +1,148 @@
81669 +/*
81670 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
81671 + * Licensed under the GPL v2
81672 + *
81673 + * Note: the choice of the license means that the compilation process is
81674 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81675 + * but for the kernel it doesn't matter since it doesn't link against
81676 + * any of the gcc libraries
81677 + *
81678 + * gcc plugin to colorize diagnostic output
81679 + *
81680 + */
81681 +
81682 +#include "gcc-plugin.h"
81683 +#include "config.h"
81684 +#include "system.h"
81685 +#include "coretypes.h"
81686 +#include "tree.h"
81687 +#include "tree-pass.h"
81688 +#include "flags.h"
81689 +#include "intl.h"
81690 +#include "toplev.h"
81691 +#include "plugin.h"
81692 +#include "diagnostic.h"
81693 +#include "plugin-version.h"
81694 +#include "tm.h"
81695 +
81696 +int plugin_is_GPL_compatible;
81697 +
81698 +static struct plugin_info colorize_plugin_info = {
81699 + .version = "201203092200",
81700 + .help = NULL,
81701 +};
81702 +
81703 +#define GREEN "\033[32m\033[2m"
81704 +#define LIGHTGREEN "\033[32m\033[1m"
81705 +#define YELLOW "\033[33m\033[2m"
81706 +#define LIGHTYELLOW "\033[33m\033[1m"
81707 +#define RED "\033[31m\033[2m"
81708 +#define LIGHTRED "\033[31m\033[1m"
81709 +#define BLUE "\033[34m\033[2m"
81710 +#define LIGHTBLUE "\033[34m\033[1m"
81711 +#define BRIGHT "\033[m\033[1m"
81712 +#define NORMAL "\033[m"
81713 +
81714 +static diagnostic_starter_fn old_starter;
81715 +static diagnostic_finalizer_fn old_finalizer;
81716 +
81717 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81718 +{
81719 + const char *color;
81720 + char *newprefix;
81721 +
81722 + switch (diagnostic->kind) {
81723 + case DK_NOTE:
81724 + color = LIGHTBLUE;
81725 + break;
81726 +
81727 + case DK_PEDWARN:
81728 + case DK_WARNING:
81729 + color = LIGHTYELLOW;
81730 + break;
81731 +
81732 + case DK_ERROR:
81733 + case DK_FATAL:
81734 + case DK_ICE:
81735 + case DK_PERMERROR:
81736 + case DK_SORRY:
81737 + color = LIGHTRED;
81738 + break;
81739 +
81740 + default:
81741 + color = NORMAL;
81742 + }
81743 +
81744 + old_starter(context, diagnostic);
81745 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81746 + return;
81747 + pp_destroy_prefix(context->printer);
81748 + pp_set_prefix(context->printer, newprefix);
81749 +}
81750 +
81751 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81752 +{
81753 + old_finalizer(context, diagnostic);
81754 +}
81755 +
81756 +static void colorize_arm(void)
81757 +{
81758 + old_starter = diagnostic_starter(global_dc);
81759 + old_finalizer = diagnostic_finalizer(global_dc);
81760 +
81761 + diagnostic_starter(global_dc) = start_colorize;
81762 + diagnostic_finalizer(global_dc) = finalize_colorize;
81763 +}
81764 +
81765 +static unsigned int execute_colorize_rearm(void)
81766 +{
81767 + if (diagnostic_starter(global_dc) == start_colorize)
81768 + return 0;
81769 +
81770 + colorize_arm();
81771 + return 0;
81772 +}
81773 +
81774 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81775 + .pass = {
81776 + .type = SIMPLE_IPA_PASS,
81777 + .name = "colorize_rearm",
81778 + .gate = NULL,
81779 + .execute = execute_colorize_rearm,
81780 + .sub = NULL,
81781 + .next = NULL,
81782 + .static_pass_number = 0,
81783 + .tv_id = TV_NONE,
81784 + .properties_required = 0,
81785 + .properties_provided = 0,
81786 + .properties_destroyed = 0,
81787 + .todo_flags_start = 0,
81788 + .todo_flags_finish = 0
81789 + }
81790 +};
81791 +
81792 +static void colorize_start_unit(void *gcc_data, void *user_data)
81793 +{
81794 + colorize_arm();
81795 +}
81796 +
81797 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81798 +{
81799 + const char * const plugin_name = plugin_info->base_name;
81800 + struct register_pass_info colorize_rearm_pass_info = {
81801 + .pass = &pass_ipa_colorize_rearm.pass,
81802 + .reference_pass_name = "*free_lang_data",
81803 + .ref_pass_instance_number = 1,
81804 + .pos_op = PASS_POS_INSERT_AFTER
81805 + };
81806 +
81807 + if (!plugin_default_version_check(version, &gcc_version)) {
81808 + error(G_("incompatible gcc/plugin versions"));
81809 + return 1;
81810 + }
81811 +
81812 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81813 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81814 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81815 + return 0;
81816 +}
81817 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81818 new file mode 100644
81819 index 0000000..048d4ff
81820 --- /dev/null
81821 +++ b/tools/gcc/constify_plugin.c
81822 @@ -0,0 +1,328 @@
81823 +/*
81824 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81825 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81826 + * Licensed under the GPL v2, or (at your option) v3
81827 + *
81828 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81829 + *
81830 + * Homepage:
81831 + * http://www.grsecurity.net/~ephox/const_plugin/
81832 + *
81833 + * Usage:
81834 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81835 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81836 + */
81837 +
81838 +#include "gcc-plugin.h"
81839 +#include "config.h"
81840 +#include "system.h"
81841 +#include "coretypes.h"
81842 +#include "tree.h"
81843 +#include "tree-pass.h"
81844 +#include "flags.h"
81845 +#include "intl.h"
81846 +#include "toplev.h"
81847 +#include "plugin.h"
81848 +#include "diagnostic.h"
81849 +#include "plugin-version.h"
81850 +#include "tm.h"
81851 +#include "function.h"
81852 +#include "basic-block.h"
81853 +#include "gimple.h"
81854 +#include "rtl.h"
81855 +#include "emit-rtl.h"
81856 +#include "tree-flow.h"
81857 +
81858 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81859 +
81860 +int plugin_is_GPL_compatible;
81861 +
81862 +static struct plugin_info const_plugin_info = {
81863 + .version = "201205300030",
81864 + .help = "no-constify\tturn off constification\n",
81865 +};
81866 +
81867 +static void deconstify_tree(tree node);
81868 +
81869 +static void deconstify_type(tree type)
81870 +{
81871 + tree field;
81872 +
81873 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
81874 + tree type = TREE_TYPE(field);
81875 +
81876 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81877 + continue;
81878 + if (!TYPE_READONLY(type))
81879 + continue;
81880 +
81881 + deconstify_tree(field);
81882 + }
81883 + TYPE_READONLY(type) = 0;
81884 + C_TYPE_FIELDS_READONLY(type) = 0;
81885 +}
81886 +
81887 +static void deconstify_tree(tree node)
81888 +{
81889 + tree old_type, new_type, field;
81890 +
81891 + old_type = TREE_TYPE(node);
81892 +
81893 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
81894 +
81895 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81896 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81897 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81898 + DECL_FIELD_CONTEXT(field) = new_type;
81899 +
81900 + deconstify_type(new_type);
81901 +
81902 + TREE_READONLY(node) = 0;
81903 + TREE_TYPE(node) = new_type;
81904 +}
81905 +
81906 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81907 +{
81908 + tree type;
81909 +
81910 + *no_add_attrs = true;
81911 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81912 + error("%qE attribute does not apply to functions", name);
81913 + return NULL_TREE;
81914 + }
81915 +
81916 + if (TREE_CODE(*node) == VAR_DECL) {
81917 + error("%qE attribute does not apply to variables", name);
81918 + return NULL_TREE;
81919 + }
81920 +
81921 + if (TYPE_P(*node)) {
81922 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81923 + *no_add_attrs = false;
81924 + else
81925 + error("%qE attribute applies to struct and union types only", name);
81926 + return NULL_TREE;
81927 + }
81928 +
81929 + type = TREE_TYPE(*node);
81930 +
81931 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81932 + error("%qE attribute applies to struct and union types only", name);
81933 + return NULL_TREE;
81934 + }
81935 +
81936 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81937 + error("%qE attribute is already applied to the type", name);
81938 + return NULL_TREE;
81939 + }
81940 +
81941 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81942 + error("%qE attribute used on type that is not constified", name);
81943 + return NULL_TREE;
81944 + }
81945 +
81946 + if (TREE_CODE(*node) == TYPE_DECL) {
81947 + deconstify_tree(*node);
81948 + return NULL_TREE;
81949 + }
81950 +
81951 + return NULL_TREE;
81952 +}
81953 +
81954 +static void constify_type(tree type)
81955 +{
81956 + TYPE_READONLY(type) = 1;
81957 + C_TYPE_FIELDS_READONLY(type) = 1;
81958 +}
81959 +
81960 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81961 +{
81962 + *no_add_attrs = true;
81963 + if (!TYPE_P(*node)) {
81964 + error("%qE attribute applies to types only", name);
81965 + return NULL_TREE;
81966 + }
81967 +
81968 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81969 + error("%qE attribute applies to struct and union types only", name);
81970 + return NULL_TREE;
81971 + }
81972 +
81973 + *no_add_attrs = false;
81974 + constify_type(*node);
81975 + return NULL_TREE;
81976 +}
81977 +
81978 +static struct attribute_spec no_const_attr = {
81979 + .name = "no_const",
81980 + .min_length = 0,
81981 + .max_length = 0,
81982 + .decl_required = false,
81983 + .type_required = false,
81984 + .function_type_required = false,
81985 + .handler = handle_no_const_attribute,
81986 +#if BUILDING_GCC_VERSION >= 4007
81987 + .affects_type_identity = true
81988 +#endif
81989 +};
81990 +
81991 +static struct attribute_spec do_const_attr = {
81992 + .name = "do_const",
81993 + .min_length = 0,
81994 + .max_length = 0,
81995 + .decl_required = false,
81996 + .type_required = false,
81997 + .function_type_required = false,
81998 + .handler = handle_do_const_attribute,
81999 +#if BUILDING_GCC_VERSION >= 4007
82000 + .affects_type_identity = true
82001 +#endif
82002 +};
82003 +
82004 +static void register_attributes(void *event_data, void *data)
82005 +{
82006 + register_attribute(&no_const_attr);
82007 + register_attribute(&do_const_attr);
82008 +}
82009 +
82010 +static bool is_fptr(tree field)
82011 +{
82012 + tree ptr = TREE_TYPE(field);
82013 +
82014 + if (TREE_CODE(ptr) != POINTER_TYPE)
82015 + return false;
82016 +
82017 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82018 +}
82019 +
82020 +static bool walk_struct(tree node)
82021 +{
82022 + tree field;
82023 +
82024 + if (TYPE_FIELDS(node) == NULL_TREE)
82025 + return false;
82026 +
82027 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82028 + gcc_assert(!TYPE_READONLY(node));
82029 + deconstify_type(node);
82030 + return false;
82031 + }
82032 +
82033 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82034 + tree type = TREE_TYPE(field);
82035 + enum tree_code code = TREE_CODE(type);
82036 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82037 + if (!(walk_struct(type)))
82038 + return false;
82039 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82040 + return false;
82041 + }
82042 + return true;
82043 +}
82044 +
82045 +static void finish_type(void *event_data, void *data)
82046 +{
82047 + tree type = (tree)event_data;
82048 +
82049 + if (type == NULL_TREE)
82050 + return;
82051 +
82052 + if (TYPE_READONLY(type))
82053 + return;
82054 +
82055 + if (walk_struct(type))
82056 + constify_type(type);
82057 +}
82058 +
82059 +static unsigned int check_local_variables(void);
82060 +
82061 +struct gimple_opt_pass pass_local_variable = {
82062 + {
82063 + .type = GIMPLE_PASS,
82064 + .name = "check_local_variables",
82065 + .gate = NULL,
82066 + .execute = check_local_variables,
82067 + .sub = NULL,
82068 + .next = NULL,
82069 + .static_pass_number = 0,
82070 + .tv_id = TV_NONE,
82071 + .properties_required = 0,
82072 + .properties_provided = 0,
82073 + .properties_destroyed = 0,
82074 + .todo_flags_start = 0,
82075 + .todo_flags_finish = 0
82076 + }
82077 +};
82078 +
82079 +static unsigned int check_local_variables(void)
82080 +{
82081 + tree var;
82082 + referenced_var_iterator rvi;
82083 +
82084 +#if BUILDING_GCC_VERSION == 4005
82085 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82086 +#else
82087 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82088 +#endif
82089 + tree type = TREE_TYPE(var);
82090 +
82091 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82092 + continue;
82093 +
82094 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82095 + continue;
82096 +
82097 + if (!TYPE_READONLY(type))
82098 + continue;
82099 +
82100 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82101 +// continue;
82102 +
82103 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82104 +// continue;
82105 +
82106 + if (walk_struct(type)) {
82107 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82108 + return 1;
82109 + }
82110 + }
82111 + return 0;
82112 +}
82113 +
82114 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82115 +{
82116 + const char * const plugin_name = plugin_info->base_name;
82117 + const int argc = plugin_info->argc;
82118 + const struct plugin_argument * const argv = plugin_info->argv;
82119 + int i;
82120 + bool constify = true;
82121 +
82122 + struct register_pass_info local_variable_pass_info = {
82123 + .pass = &pass_local_variable.pass,
82124 + .reference_pass_name = "*referenced_vars",
82125 + .ref_pass_instance_number = 1,
82126 + .pos_op = PASS_POS_INSERT_AFTER
82127 + };
82128 +
82129 + if (!plugin_default_version_check(version, &gcc_version)) {
82130 + error(G_("incompatible gcc/plugin versions"));
82131 + return 1;
82132 + }
82133 +
82134 + for (i = 0; i < argc; ++i) {
82135 + if (!(strcmp(argv[i].key, "no-constify"))) {
82136 + constify = false;
82137 + continue;
82138 + }
82139 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82140 + }
82141 +
82142 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82143 + if (constify) {
82144 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82145 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82146 + }
82147 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82148 +
82149 + return 0;
82150 +}
82151 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82152 new file mode 100644
82153 index 0000000..68b646e
82154 --- /dev/null
82155 +++ b/tools/gcc/generate_size_overflow_hash.sh
82156 @@ -0,0 +1,94 @@
82157 +#!/bin/bash
82158 +
82159 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82160 +
82161 +header1="size_overflow_hash.h"
82162 +database="size_overflow_hash.data"
82163 +n=65536
82164 +
82165 +usage() {
82166 +cat <<EOF
82167 +usage: $0 options
82168 +OPTIONS:
82169 + -h|--help help
82170 + -o header file
82171 + -d database file
82172 + -n hash array size
82173 +EOF
82174 + return 0
82175 +}
82176 +
82177 +while true
82178 +do
82179 + case "$1" in
82180 + -h|--help) usage && exit 0;;
82181 + -n) n=$2; shift 2;;
82182 + -o) header1="$2"; shift 2;;
82183 + -d) database="$2"; shift 2;;
82184 + --) shift 1; break ;;
82185 + *) break ;;
82186 + esac
82187 +done
82188 +
82189 +create_defines() {
82190 + for i in `seq 1 10`
82191 + do
82192 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82193 + done
82194 + echo >> "$header1"
82195 +}
82196 +
82197 +create_structs () {
82198 + rm -f "$header1"
82199 +
82200 + create_defines
82201 +
82202 + cat "$database" | while read data
82203 + do
82204 + data_array=($data)
82205 + struct_hash_name="${data_array[0]}"
82206 + funcn="${data_array[1]}"
82207 + params="${data_array[2]}"
82208 + next="${data_array[5]}"
82209 +
82210 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82211 +
82212 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82213 + echo -en "\t.param\t= " >> "$header1"
82214 + line=
82215 + for param_num in ${params//-/ };
82216 + do
82217 + line="${line}PARAM"$param_num"|"
82218 + done
82219 +
82220 + echo -e "${line%?},\n};\n" >> "$header1"
82221 + done
82222 +}
82223 +
82224 +create_headers () {
82225 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82226 +}
82227 +
82228 +create_array_elements () {
82229 + index=0
82230 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82231 + do
82232 + data_array=($data)
82233 + i="${data_array[3]}"
82234 + hash="${data_array[4]}"
82235 + while [[ $index -lt $i ]]
82236 + do
82237 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82238 + index=$(($index + 1))
82239 + done
82240 + index=$(($index + 1))
82241 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82242 + done
82243 + echo '};' >> $header1
82244 +}
82245 +
82246 +create_structs
82247 +create_headers
82248 +create_array_elements
82249 +
82250 +exit 0
82251 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82252 new file mode 100644
82253 index 0000000..a86e422
82254 --- /dev/null
82255 +++ b/tools/gcc/kallocstat_plugin.c
82256 @@ -0,0 +1,167 @@
82257 +/*
82258 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82259 + * Licensed under the GPL v2
82260 + *
82261 + * Note: the choice of the license means that the compilation process is
82262 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82263 + * but for the kernel it doesn't matter since it doesn't link against
82264 + * any of the gcc libraries
82265 + *
82266 + * gcc plugin to find the distribution of k*alloc sizes
82267 + *
82268 + * TODO:
82269 + *
82270 + * BUGS:
82271 + * - none known
82272 + */
82273 +#include "gcc-plugin.h"
82274 +#include "config.h"
82275 +#include "system.h"
82276 +#include "coretypes.h"
82277 +#include "tree.h"
82278 +#include "tree-pass.h"
82279 +#include "flags.h"
82280 +#include "intl.h"
82281 +#include "toplev.h"
82282 +#include "plugin.h"
82283 +//#include "expr.h" where are you...
82284 +#include "diagnostic.h"
82285 +#include "plugin-version.h"
82286 +#include "tm.h"
82287 +#include "function.h"
82288 +#include "basic-block.h"
82289 +#include "gimple.h"
82290 +#include "rtl.h"
82291 +#include "emit-rtl.h"
82292 +
82293 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82294 +
82295 +int plugin_is_GPL_compatible;
82296 +
82297 +static const char * const kalloc_functions[] = {
82298 + "__kmalloc",
82299 + "kmalloc",
82300 + "kmalloc_large",
82301 + "kmalloc_node",
82302 + "kmalloc_order",
82303 + "kmalloc_order_trace",
82304 + "kmalloc_slab",
82305 + "kzalloc",
82306 + "kzalloc_node",
82307 +};
82308 +
82309 +static struct plugin_info kallocstat_plugin_info = {
82310 + .version = "201111150100",
82311 +};
82312 +
82313 +static unsigned int execute_kallocstat(void);
82314 +
82315 +static struct gimple_opt_pass kallocstat_pass = {
82316 + .pass = {
82317 + .type = GIMPLE_PASS,
82318 + .name = "kallocstat",
82319 + .gate = NULL,
82320 + .execute = execute_kallocstat,
82321 + .sub = NULL,
82322 + .next = NULL,
82323 + .static_pass_number = 0,
82324 + .tv_id = TV_NONE,
82325 + .properties_required = 0,
82326 + .properties_provided = 0,
82327 + .properties_destroyed = 0,
82328 + .todo_flags_start = 0,
82329 + .todo_flags_finish = 0
82330 + }
82331 +};
82332 +
82333 +static bool is_kalloc(const char *fnname)
82334 +{
82335 + size_t i;
82336 +
82337 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82338 + if (!strcmp(fnname, kalloc_functions[i]))
82339 + return true;
82340 + return false;
82341 +}
82342 +
82343 +static unsigned int execute_kallocstat(void)
82344 +{
82345 + basic_block bb;
82346 +
82347 + // 1. loop through BBs and GIMPLE statements
82348 + FOR_EACH_BB(bb) {
82349 + gimple_stmt_iterator gsi;
82350 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82351 + // gimple match:
82352 + tree fndecl, size;
82353 + gimple call_stmt;
82354 + const char *fnname;
82355 +
82356 + // is it a call
82357 + call_stmt = gsi_stmt(gsi);
82358 + if (!is_gimple_call(call_stmt))
82359 + continue;
82360 + fndecl = gimple_call_fndecl(call_stmt);
82361 + if (fndecl == NULL_TREE)
82362 + continue;
82363 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82364 + continue;
82365 +
82366 + // is it a call to k*alloc
82367 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82368 + if (!is_kalloc(fnname))
82369 + continue;
82370 +
82371 + // is the size arg the result of a simple const assignment
82372 + size = gimple_call_arg(call_stmt, 0);
82373 + while (true) {
82374 + gimple def_stmt;
82375 + expanded_location xloc;
82376 + size_t size_val;
82377 +
82378 + if (TREE_CODE(size) != SSA_NAME)
82379 + break;
82380 + def_stmt = SSA_NAME_DEF_STMT(size);
82381 + if (!def_stmt || !is_gimple_assign(def_stmt))
82382 + break;
82383 + if (gimple_num_ops(def_stmt) != 2)
82384 + break;
82385 + size = gimple_assign_rhs1(def_stmt);
82386 + if (!TREE_CONSTANT(size))
82387 + continue;
82388 + xloc = expand_location(gimple_location(def_stmt));
82389 + if (!xloc.file)
82390 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82391 + size_val = TREE_INT_CST_LOW(size);
82392 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82393 + break;
82394 + }
82395 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82396 +//debug_tree(gimple_call_fn(call_stmt));
82397 +//print_node(stderr, "pax", fndecl, 4);
82398 + }
82399 + }
82400 +
82401 + return 0;
82402 +}
82403 +
82404 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82405 +{
82406 + const char * const plugin_name = plugin_info->base_name;
82407 + struct register_pass_info kallocstat_pass_info = {
82408 + .pass = &kallocstat_pass.pass,
82409 + .reference_pass_name = "ssa",
82410 + .ref_pass_instance_number = 1,
82411 + .pos_op = PASS_POS_INSERT_AFTER
82412 + };
82413 +
82414 + if (!plugin_default_version_check(version, &gcc_version)) {
82415 + error(G_("incompatible gcc/plugin versions"));
82416 + return 1;
82417 + }
82418 +
82419 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82420 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82421 +
82422 + return 0;
82423 +}
82424 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82425 new file mode 100644
82426 index 0000000..98011fa
82427 --- /dev/null
82428 +++ b/tools/gcc/kernexec_plugin.c
82429 @@ -0,0 +1,427 @@
82430 +/*
82431 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82432 + * Licensed under the GPL v2
82433 + *
82434 + * Note: the choice of the license means that the compilation process is
82435 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82436 + * but for the kernel it doesn't matter since it doesn't link against
82437 + * any of the gcc libraries
82438 + *
82439 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82440 + *
82441 + * TODO:
82442 + *
82443 + * BUGS:
82444 + * - none known
82445 + */
82446 +#include "gcc-plugin.h"
82447 +#include "config.h"
82448 +#include "system.h"
82449 +#include "coretypes.h"
82450 +#include "tree.h"
82451 +#include "tree-pass.h"
82452 +#include "flags.h"
82453 +#include "intl.h"
82454 +#include "toplev.h"
82455 +#include "plugin.h"
82456 +//#include "expr.h" where are you...
82457 +#include "diagnostic.h"
82458 +#include "plugin-version.h"
82459 +#include "tm.h"
82460 +#include "function.h"
82461 +#include "basic-block.h"
82462 +#include "gimple.h"
82463 +#include "rtl.h"
82464 +#include "emit-rtl.h"
82465 +#include "tree-flow.h"
82466 +
82467 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82468 +extern rtx emit_move_insn(rtx x, rtx y);
82469 +
82470 +int plugin_is_GPL_compatible;
82471 +
82472 +static struct plugin_info kernexec_plugin_info = {
82473 + .version = "201111291120",
82474 + .help = "method=[bts|or]\tinstrumentation method\n"
82475 +};
82476 +
82477 +static unsigned int execute_kernexec_reload(void);
82478 +static unsigned int execute_kernexec_fptr(void);
82479 +static unsigned int execute_kernexec_retaddr(void);
82480 +static bool kernexec_cmodel_check(void);
82481 +
82482 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82483 +static void (*kernexec_instrument_retaddr)(rtx);
82484 +
82485 +static struct gimple_opt_pass kernexec_reload_pass = {
82486 + .pass = {
82487 + .type = GIMPLE_PASS,
82488 + .name = "kernexec_reload",
82489 + .gate = kernexec_cmodel_check,
82490 + .execute = execute_kernexec_reload,
82491 + .sub = NULL,
82492 + .next = NULL,
82493 + .static_pass_number = 0,
82494 + .tv_id = TV_NONE,
82495 + .properties_required = 0,
82496 + .properties_provided = 0,
82497 + .properties_destroyed = 0,
82498 + .todo_flags_start = 0,
82499 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82500 + }
82501 +};
82502 +
82503 +static struct gimple_opt_pass kernexec_fptr_pass = {
82504 + .pass = {
82505 + .type = GIMPLE_PASS,
82506 + .name = "kernexec_fptr",
82507 + .gate = kernexec_cmodel_check,
82508 + .execute = execute_kernexec_fptr,
82509 + .sub = NULL,
82510 + .next = NULL,
82511 + .static_pass_number = 0,
82512 + .tv_id = TV_NONE,
82513 + .properties_required = 0,
82514 + .properties_provided = 0,
82515 + .properties_destroyed = 0,
82516 + .todo_flags_start = 0,
82517 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82518 + }
82519 +};
82520 +
82521 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82522 + .pass = {
82523 + .type = RTL_PASS,
82524 + .name = "kernexec_retaddr",
82525 + .gate = kernexec_cmodel_check,
82526 + .execute = execute_kernexec_retaddr,
82527 + .sub = NULL,
82528 + .next = NULL,
82529 + .static_pass_number = 0,
82530 + .tv_id = TV_NONE,
82531 + .properties_required = 0,
82532 + .properties_provided = 0,
82533 + .properties_destroyed = 0,
82534 + .todo_flags_start = 0,
82535 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
82536 + }
82537 +};
82538 +
82539 +static bool kernexec_cmodel_check(void)
82540 +{
82541 + tree section;
82542 +
82543 + if (ix86_cmodel != CM_KERNEL)
82544 + return false;
82545 +
82546 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
82547 + if (!section || !TREE_VALUE(section))
82548 + return true;
82549 +
82550 + section = TREE_VALUE(TREE_VALUE(section));
82551 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
82552 + return true;
82553 +
82554 + return false;
82555 +}
82556 +
82557 +/*
82558 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
82559 + */
82560 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
82561 +{
82562 + gimple asm_movabs_stmt;
82563 +
82564 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
82565 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
82566 + gimple_asm_set_volatile(asm_movabs_stmt, true);
82567 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
82568 + update_stmt(asm_movabs_stmt);
82569 +}
82570 +
82571 +/*
82572 + * find all asm() stmts that clobber r10 and add a reload of r10
82573 + */
82574 +static unsigned int execute_kernexec_reload(void)
82575 +{
82576 + basic_block bb;
82577 +
82578 + // 1. loop through BBs and GIMPLE statements
82579 + FOR_EACH_BB(bb) {
82580 + gimple_stmt_iterator gsi;
82581 +
82582 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82583 + // gimple match: __asm__ ("" : : : "r10");
82584 + gimple asm_stmt;
82585 + size_t nclobbers;
82586 +
82587 + // is it an asm ...
82588 + asm_stmt = gsi_stmt(gsi);
82589 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
82590 + continue;
82591 +
82592 + // ... clobbering r10
82593 + nclobbers = gimple_asm_nclobbers(asm_stmt);
82594 + while (nclobbers--) {
82595 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
82596 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
82597 + continue;
82598 + kernexec_reload_fptr_mask(&gsi);
82599 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
82600 + break;
82601 + }
82602 + }
82603 + }
82604 +
82605 + return 0;
82606 +}
82607 +
82608 +/*
82609 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
82610 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
82611 + */
82612 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
82613 +{
82614 + gimple assign_intptr, assign_new_fptr, call_stmt;
82615 + tree intptr, old_fptr, new_fptr, kernexec_mask;
82616 +
82617 + call_stmt = gsi_stmt(*gsi);
82618 + old_fptr = gimple_call_fn(call_stmt);
82619 +
82620 + // create temporary unsigned long variable used for bitops and cast fptr to it
82621 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
82622 + add_referenced_var(intptr);
82623 + mark_sym_for_renaming(intptr);
82624 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
82625 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82626 + update_stmt(assign_intptr);
82627 +
82628 + // apply logical or to temporary unsigned long and bitmask
82629 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
82630 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
82631 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
82632 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82633 + update_stmt(assign_intptr);
82634 +
82635 + // cast temporary unsigned long back to a temporary fptr variable
82636 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
82637 + add_referenced_var(new_fptr);
82638 + mark_sym_for_renaming(new_fptr);
82639 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
82640 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
82641 + update_stmt(assign_new_fptr);
82642 +
82643 + // replace call stmt fn with the new fptr
82644 + gimple_call_set_fn(call_stmt, new_fptr);
82645 + update_stmt(call_stmt);
82646 +}
82647 +
82648 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
82649 +{
82650 + gimple asm_or_stmt, call_stmt;
82651 + tree old_fptr, new_fptr, input, output;
82652 + VEC(tree, gc) *inputs = NULL;
82653 + VEC(tree, gc) *outputs = NULL;
82654 +
82655 + call_stmt = gsi_stmt(*gsi);
82656 + old_fptr = gimple_call_fn(call_stmt);
82657 +
82658 + // create temporary fptr variable
82659 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
82660 + add_referenced_var(new_fptr);
82661 + mark_sym_for_renaming(new_fptr);
82662 +
82663 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
82664 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
82665 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
82666 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
82667 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
82668 + VEC_safe_push(tree, gc, inputs, input);
82669 + VEC_safe_push(tree, gc, outputs, output);
82670 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
82671 + gimple_asm_set_volatile(asm_or_stmt, true);
82672 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
82673 + update_stmt(asm_or_stmt);
82674 +
82675 + // replace call stmt fn with the new fptr
82676 + gimple_call_set_fn(call_stmt, new_fptr);
82677 + update_stmt(call_stmt);
82678 +}
82679 +
82680 +/*
82681 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82682 + */
82683 +static unsigned int execute_kernexec_fptr(void)
82684 +{
82685 + basic_block bb;
82686 +
82687 + // 1. loop through BBs and GIMPLE statements
82688 + FOR_EACH_BB(bb) {
82689 + gimple_stmt_iterator gsi;
82690 +
82691 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82692 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82693 + tree fn;
82694 + gimple call_stmt;
82695 +
82696 + // is it a call ...
82697 + call_stmt = gsi_stmt(gsi);
82698 + if (!is_gimple_call(call_stmt))
82699 + continue;
82700 + fn = gimple_call_fn(call_stmt);
82701 + if (TREE_CODE(fn) == ADDR_EXPR)
82702 + continue;
82703 + if (TREE_CODE(fn) != SSA_NAME)
82704 + gcc_unreachable();
82705 +
82706 + // ... through a function pointer
82707 + fn = SSA_NAME_VAR(fn);
82708 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82709 + continue;
82710 + fn = TREE_TYPE(fn);
82711 + if (TREE_CODE(fn) != POINTER_TYPE)
82712 + continue;
82713 + fn = TREE_TYPE(fn);
82714 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82715 + continue;
82716 +
82717 + kernexec_instrument_fptr(&gsi);
82718 +
82719 +//debug_tree(gimple_call_fn(call_stmt));
82720 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82721 + }
82722 + }
82723 +
82724 + return 0;
82725 +}
82726 +
82727 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82728 +static void kernexec_instrument_retaddr_bts(rtx insn)
82729 +{
82730 + rtx btsq;
82731 + rtvec argvec, constraintvec, labelvec;
82732 + int line;
82733 +
82734 + // create asm volatile("btsq $63,(%%rsp)":::)
82735 + argvec = rtvec_alloc(0);
82736 + constraintvec = rtvec_alloc(0);
82737 + labelvec = rtvec_alloc(0);
82738 + line = expand_location(RTL_LOCATION(insn)).line;
82739 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82740 + MEM_VOLATILE_P(btsq) = 1;
82741 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82742 + emit_insn_before(btsq, insn);
82743 +}
82744 +
82745 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82746 +static void kernexec_instrument_retaddr_or(rtx insn)
82747 +{
82748 + rtx orq;
82749 + rtvec argvec, constraintvec, labelvec;
82750 + int line;
82751 +
82752 + // create asm volatile("orq %%r10,(%%rsp)":::)
82753 + argvec = rtvec_alloc(0);
82754 + constraintvec = rtvec_alloc(0);
82755 + labelvec = rtvec_alloc(0);
82756 + line = expand_location(RTL_LOCATION(insn)).line;
82757 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82758 + MEM_VOLATILE_P(orq) = 1;
82759 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82760 + emit_insn_before(orq, insn);
82761 +}
82762 +
82763 +/*
82764 + * find all asm level function returns and forcibly set the highest bit of the return address
82765 + */
82766 +static unsigned int execute_kernexec_retaddr(void)
82767 +{
82768 + rtx insn;
82769 +
82770 + // 1. find function returns
82771 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82772 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82773 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82774 + rtx body;
82775 +
82776 + // is it a retn
82777 + if (!JUMP_P(insn))
82778 + continue;
82779 + body = PATTERN(insn);
82780 + if (GET_CODE(body) == PARALLEL)
82781 + body = XVECEXP(body, 0, 0);
82782 + if (GET_CODE(body) != RETURN)
82783 + continue;
82784 + kernexec_instrument_retaddr(insn);
82785 + }
82786 +
82787 +// print_simple_rtl(stderr, get_insns());
82788 +// print_rtl(stderr, get_insns());
82789 +
82790 + return 0;
82791 +}
82792 +
82793 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82794 +{
82795 + const char * const plugin_name = plugin_info->base_name;
82796 + const int argc = plugin_info->argc;
82797 + const struct plugin_argument * const argv = plugin_info->argv;
82798 + int i;
82799 + struct register_pass_info kernexec_reload_pass_info = {
82800 + .pass = &kernexec_reload_pass.pass,
82801 + .reference_pass_name = "ssa",
82802 + .ref_pass_instance_number = 1,
82803 + .pos_op = PASS_POS_INSERT_AFTER
82804 + };
82805 + struct register_pass_info kernexec_fptr_pass_info = {
82806 + .pass = &kernexec_fptr_pass.pass,
82807 + .reference_pass_name = "ssa",
82808 + .ref_pass_instance_number = 1,
82809 + .pos_op = PASS_POS_INSERT_AFTER
82810 + };
82811 + struct register_pass_info kernexec_retaddr_pass_info = {
82812 + .pass = &kernexec_retaddr_pass.pass,
82813 + .reference_pass_name = "pro_and_epilogue",
82814 + .ref_pass_instance_number = 1,
82815 + .pos_op = PASS_POS_INSERT_AFTER
82816 + };
82817 +
82818 + if (!plugin_default_version_check(version, &gcc_version)) {
82819 + error(G_("incompatible gcc/plugin versions"));
82820 + return 1;
82821 + }
82822 +
82823 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82824 +
82825 + if (TARGET_64BIT == 0)
82826 + return 0;
82827 +
82828 + for (i = 0; i < argc; ++i) {
82829 + if (!strcmp(argv[i].key, "method")) {
82830 + if (!argv[i].value) {
82831 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82832 + continue;
82833 + }
82834 + if (!strcmp(argv[i].value, "bts")) {
82835 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82836 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82837 + } else if (!strcmp(argv[i].value, "or")) {
82838 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82839 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82840 + fix_register("r10", 1, 1);
82841 + } else
82842 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82843 + continue;
82844 + }
82845 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82846 + }
82847 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82848 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82849 +
82850 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82851 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82852 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82853 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82854 +
82855 + return 0;
82856 +}
82857 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
82858 new file mode 100644
82859 index 0000000..b8008f7
82860 --- /dev/null
82861 +++ b/tools/gcc/latent_entropy_plugin.c
82862 @@ -0,0 +1,295 @@
82863 +/*
82864 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
82865 + * Licensed under the GPL v2
82866 + *
82867 + * Note: the choice of the license means that the compilation process is
82868 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82869 + * but for the kernel it doesn't matter since it doesn't link against
82870 + * any of the gcc libraries
82871 + *
82872 + * gcc plugin to help generate a little bit of entropy from program state,
82873 + * used during boot in the kernel
82874 + *
82875 + * TODO:
82876 + * - add ipa pass to identify not explicitly marked candidate functions
82877 + * - mix in more program state (function arguments/return values, loop variables, etc)
82878 + * - more instrumentation control via attribute parameters
82879 + *
82880 + * BUGS:
82881 + * - LTO needs -flto-partition=none for now
82882 + */
82883 +#include "gcc-plugin.h"
82884 +#include "config.h"
82885 +#include "system.h"
82886 +#include "coretypes.h"
82887 +#include "tree.h"
82888 +#include "tree-pass.h"
82889 +#include "flags.h"
82890 +#include "intl.h"
82891 +#include "toplev.h"
82892 +#include "plugin.h"
82893 +//#include "expr.h" where are you...
82894 +#include "diagnostic.h"
82895 +#include "plugin-version.h"
82896 +#include "tm.h"
82897 +#include "function.h"
82898 +#include "basic-block.h"
82899 +#include "gimple.h"
82900 +#include "rtl.h"
82901 +#include "emit-rtl.h"
82902 +#include "tree-flow.h"
82903 +
82904 +int plugin_is_GPL_compatible;
82905 +
82906 +static tree latent_entropy_decl;
82907 +
82908 +static struct plugin_info latent_entropy_plugin_info = {
82909 + .version = "201207271820",
82910 + .help = NULL
82911 +};
82912 +
82913 +static unsigned int execute_latent_entropy(void);
82914 +static bool gate_latent_entropy(void);
82915 +
82916 +static struct gimple_opt_pass latent_entropy_pass = {
82917 + .pass = {
82918 + .type = GIMPLE_PASS,
82919 + .name = "latent_entropy",
82920 + .gate = gate_latent_entropy,
82921 + .execute = execute_latent_entropy,
82922 + .sub = NULL,
82923 + .next = NULL,
82924 + .static_pass_number = 0,
82925 + .tv_id = TV_NONE,
82926 + .properties_required = PROP_gimple_leh | PROP_cfg,
82927 + .properties_provided = 0,
82928 + .properties_destroyed = 0,
82929 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82930 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82931 + }
82932 +};
82933 +
82934 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82935 +{
82936 + if (TREE_CODE(*node) != FUNCTION_DECL) {
82937 + *no_add_attrs = true;
82938 + error("%qE attribute only applies to functions", name);
82939 + }
82940 + return NULL_TREE;
82941 +}
82942 +
82943 +static struct attribute_spec latent_entropy_attr = {
82944 + .name = "latent_entropy",
82945 + .min_length = 0,
82946 + .max_length = 0,
82947 + .decl_required = true,
82948 + .type_required = false,
82949 + .function_type_required = false,
82950 + .handler = handle_latent_entropy_attribute,
82951 +#if BUILDING_GCC_VERSION >= 4007
82952 + .affects_type_identity = false
82953 +#endif
82954 +};
82955 +
82956 +static void register_attributes(void *event_data, void *data)
82957 +{
82958 + register_attribute(&latent_entropy_attr);
82959 +}
82960 +
82961 +static bool gate_latent_entropy(void)
82962 +{
82963 + tree latent_entropy_attr;
82964 +
82965 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
82966 + return latent_entropy_attr != NULL_TREE;
82967 +}
82968 +
82969 +static unsigned HOST_WIDE_INT seed;
82970 +static unsigned HOST_WIDE_INT get_random_const(void)
82971 +{
82972 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
82973 + return seed;
82974 +}
82975 +
82976 +static enum tree_code get_op(tree *rhs)
82977 +{
82978 + static enum tree_code op;
82979 + unsigned HOST_WIDE_INT random_const;
82980 +
82981 + random_const = get_random_const();
82982 +
82983 + switch (op) {
82984 + case BIT_XOR_EXPR:
82985 + op = PLUS_EXPR;
82986 + break;
82987 +
82988 + case PLUS_EXPR:
82989 + if (rhs) {
82990 + op = LROTATE_EXPR;
82991 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
82992 + break;
82993 + }
82994 +
82995 + case LROTATE_EXPR:
82996 + default:
82997 + op = BIT_XOR_EXPR;
82998 + break;
82999 + }
83000 + if (rhs)
83001 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83002 + return op;
83003 +}
83004 +
83005 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83006 +{
83007 + gimple_stmt_iterator gsi;
83008 + gimple assign;
83009 + tree addxorrol, rhs;
83010 + enum tree_code op;
83011 +
83012 + op = get_op(&rhs);
83013 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83014 + assign = gimple_build_assign(local_entropy, addxorrol);
83015 + find_referenced_vars_in(assign);
83016 +//debug_bb(bb);
83017 + gsi = gsi_after_labels(bb);
83018 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83019 + update_stmt(assign);
83020 +}
83021 +
83022 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83023 +{
83024 + gimple_stmt_iterator gsi;
83025 + gimple assign;
83026 + tree addxorrol, temp;
83027 +
83028 + // 1. create temporary copy of latent_entropy
83029 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83030 + add_referenced_var(temp);
83031 + mark_sym_for_renaming(temp);
83032 +
83033 + // 2. read...
83034 + assign = gimple_build_assign(temp, latent_entropy_decl);
83035 + find_referenced_vars_in(assign);
83036 + gsi = gsi_after_labels(bb);
83037 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83038 + update_stmt(assign);
83039 +
83040 + // 3. ...modify...
83041 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83042 + assign = gimple_build_assign(temp, addxorrol);
83043 + find_referenced_vars_in(assign);
83044 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83045 + update_stmt(assign);
83046 +
83047 + // 4. ...write latent_entropy
83048 + assign = gimple_build_assign(latent_entropy_decl, temp);
83049 + find_referenced_vars_in(assign);
83050 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83051 + update_stmt(assign);
83052 +}
83053 +
83054 +static unsigned int execute_latent_entropy(void)
83055 +{
83056 + basic_block bb;
83057 + gimple assign;
83058 + gimple_stmt_iterator gsi;
83059 + tree local_entropy;
83060 +
83061 + if (!latent_entropy_decl) {
83062 + struct varpool_node *node;
83063 +
83064 + for (node = varpool_nodes; node; node = node->next) {
83065 + tree var = node->decl;
83066 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83067 + continue;
83068 + latent_entropy_decl = var;
83069 +// debug_tree(var);
83070 + break;
83071 + }
83072 + if (!latent_entropy_decl) {
83073 +// debug_tree(current_function_decl);
83074 + return 0;
83075 + }
83076 + }
83077 +
83078 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83079 +
83080 + // 1. create local entropy variable
83081 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83082 + add_referenced_var(local_entropy);
83083 + mark_sym_for_renaming(local_entropy);
83084 +
83085 + // 2. initialize local entropy variable
83086 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83087 + if (dom_info_available_p(CDI_DOMINATORS))
83088 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83089 + gsi = gsi_start_bb(bb);
83090 +
83091 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83092 +// gimple_set_location(assign, loc);
83093 + find_referenced_vars_in(assign);
83094 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83095 + update_stmt(assign);
83096 + bb = bb->next_bb;
83097 +
83098 + // 3. instrument each BB with an operation on the local entropy variable
83099 + while (bb != EXIT_BLOCK_PTR) {
83100 + perturb_local_entropy(bb, local_entropy);
83101 + bb = bb->next_bb;
83102 + };
83103 +
83104 + // 4. mix local entropy into the global entropy variable
83105 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83106 + return 0;
83107 +}
83108 +
83109 +static void start_unit_callback(void *gcc_data, void *user_data)
83110 +{
83111 +#if BUILDING_GCC_VERSION >= 4007
83112 + seed = get_random_seed(false);
83113 +#else
83114 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83115 + seed *= seed;
83116 +#endif
83117 +
83118 + if (in_lto_p)
83119 + return;
83120 +
83121 + // extern u64 latent_entropy
83122 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83123 +
83124 + TREE_STATIC(latent_entropy_decl) = 1;
83125 + TREE_PUBLIC(latent_entropy_decl) = 1;
83126 + TREE_USED(latent_entropy_decl) = 1;
83127 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83128 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83129 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83130 + DECL_INITIAL(latent_entropy_decl) = NULL;
83131 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83132 +// varpool_finalize_decl(latent_entropy_decl);
83133 +// varpool_mark_needed_node(latent_entropy_decl);
83134 +}
83135 +
83136 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83137 +{
83138 + const char * const plugin_name = plugin_info->base_name;
83139 + struct register_pass_info latent_entropy_pass_info = {
83140 + .pass = &latent_entropy_pass.pass,
83141 + .reference_pass_name = "optimized",
83142 + .ref_pass_instance_number = 1,
83143 + .pos_op = PASS_POS_INSERT_BEFORE
83144 + };
83145 +
83146 + if (!plugin_default_version_check(version, &gcc_version)) {
83147 + error(G_("incompatible gcc/plugin versions"));
83148 + return 1;
83149 + }
83150 +
83151 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83152 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83153 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83154 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83155 +
83156 + return 0;
83157 +}
83158 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83159 new file mode 100644
83160 index 0000000..50e9970
83161 --- /dev/null
83162 +++ b/tools/gcc/size_overflow_hash.data
83163 @@ -0,0 +1,3164 @@
83164 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83165 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83166 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83167 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83168 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83169 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83170 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83171 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83172 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
83173 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83174 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
83175 +_000013_hash kmemdup 2 64015 _000013_hash NULL
83176 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
83177 +_000015_hash memdup_user 2 59590 _000015_hash NULL
83178 +_000016_hash module_alloc 1 63630 _000016_hash NULL
83179 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
83180 +_000018_hash read_kcore 3 63488 _000018_hash NULL
83181 +_000019_hash read_ldt 2 47570 _000019_hash NULL
83182 +_000020_hash read_zero 3 19366 _000020_hash NULL
83183 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
83184 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
83185 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
83186 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
83187 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
83188 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
83189 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
83190 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
83191 +_000029_hash adu_write 3 30487 _000029_hash NULL
83192 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
83193 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
83194 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
83195 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
83196 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
83197 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
83198 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
83199 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
83200 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
83201 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
83202 +_000041_hash alloc_context 1 3194 _000041_hash NULL
83203 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
83204 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
83205 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
83206 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
83207 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
83208 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
83209 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
83210 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
83211 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
83212 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
83213 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
83214 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
83215 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
83216 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
83217 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
83218 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
83219 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
83220 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
83221 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
83222 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
83223 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
83224 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
83225 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
83226 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
83227 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
83228 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
83229 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
83230 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
83231 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
83232 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
83233 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
83234 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
83235 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
83236 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
83237 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
83238 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
83239 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
83240 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
83241 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
83242 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
83243 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
83244 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
83245 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
83246 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
83247 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
83248 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
83249 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
83250 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
83251 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
83252 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
83253 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
83254 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
83255 +_000096_hash capi_write 3 35104 _000096_hash NULL
83256 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
83257 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
83258 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
83259 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
83260 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
83261 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
83262 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
83263 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
83264 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
83265 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
83266 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
83267 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
83268 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
83269 +_000111_hash change_xattr 5 61390 _000111_hash NULL
83270 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
83271 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
83272 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
83273 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
83274 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
83275 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
83276 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
83277 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
83278 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
83279 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
83280 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
83281 +_000123_hash cmm_write 3 2896 _000123_hash NULL
83282 +_000124_hash cm_write 3 36858 _000124_hash NULL
83283 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
83284 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
83285 +_000127_hash command_file_write 3 31318 _000127_hash NULL
83286 +_000128_hash command_write 3 58841 _000128_hash NULL
83287 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
83288 +_000130_hash concat_writev 3 21451 _000130_hash NULL
83289 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
83290 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
83291 +_000133_hash copy_items 6 50140 _000133_hash NULL
83292 +_000134_hash copy_macs 4 45534 _000134_hash NULL
83293 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
83294 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
83295 +_000137_hash cosa_write 3 1774 _000137_hash NULL
83296 +_000138_hash create_entry 2 33479 _000138_hash NULL
83297 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
83298 +_000141_hash create_xattr 5 54106 _000141_hash NULL
83299 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
83300 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
83301 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
83302 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
83303 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
83304 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
83305 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
83306 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
83307 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
83308 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
83309 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
83310 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
83311 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
83312 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
83313 +_000158_hash dev_config 3 8506 _000158_hash NULL
83314 +_000159_hash device_write 3 45156 _000159_hash NULL
83315 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
83316 +_000161_hash devres_alloc 2 551 _000161_hash NULL
83317 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
83318 +_000163_hash direct_entry 3 38836 _000163_hash NULL
83319 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
83320 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
83321 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
83322 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
83323 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
83324 +_000169_hash dm_read 3 15674 _000169_hash NULL
83325 +_000170_hash dm_write 3 2513 _000170_hash NULL
83326 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
83327 +_000172_hash dns_query 3 9676 _000172_hash NULL
83328 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
83329 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
83330 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
83331 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
83332 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
83333 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
83334 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
83335 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
83336 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
83337 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
83338 +_000183_hash dsp_write 2 46218 _000183_hash NULL
83339 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
83340 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
83341 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
83342 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
83343 +_000188_hash dvb_play 3 50814 _000188_hash NULL
83344 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
83345 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
83346 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
83347 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
83348 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
83349 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
83350 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
83351 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
83352 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
83353 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
83354 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
83355 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
83356 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
83357 +_000202_hash ep_read 3 58813 _000202_hash NULL
83358 +_000203_hash ep_write 3 59008 _000203_hash NULL
83359 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
83360 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
83361 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
83362 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
83363 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
83364 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
83365 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
83366 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
83367 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
83368 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
83369 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
83370 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
83371 +_000216_hash fl_create 5 56435 _000216_hash NULL
83372 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
83373 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
83374 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
83375 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
83376 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
83377 +_000222_hash get_arg 3 5694 _000222_hash NULL
83378 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
83379 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
83380 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
83381 +_000226_hash get_registers 3 26187 _000226_hash NULL
83382 +_000227_hash get_scq 2 10897 _000227_hash NULL
83383 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
83384 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
83385 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
83386 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
83387 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
83388 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
83389 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
83390 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
83391 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
83392 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
83393 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
83394 +_000239_hash handle_request 9 10024 _000239_hash NULL
83395 +_000240_hash hash_new 1 62224 _000240_hash NULL
83396 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
83397 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
83398 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
83399 +_000244_hash heap_init 2 49617 _000244_hash NULL
83400 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
83401 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
83402 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
83403 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
83404 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
83405 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
83406 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
83407 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
83408 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
83409 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
83410 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
83411 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
83412 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
83413 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
83414 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
83415 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
83416 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
83417 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
83418 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
83419 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
83420 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
83421 +_000266_hash ieee80211_build_probe_req 7-5 27660 _000266_hash NULL
83422 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
83423 +_000268_hash if_write 3 51756 _000268_hash NULL
83424 +_000269_hash ilo_write 3 64378 _000269_hash NULL
83425 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
83426 +_000271_hash init_data_container 1 60709 _000271_hash NULL
83427 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
83428 +_000273_hash insert_dent 7 65034 _000273_hash NULL
83429 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
83430 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
83431 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
83432 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
83433 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
83434 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
83435 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
83436 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
83437 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
83438 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
83439 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
83440 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
83441 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
83442 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
83443 +_000288_hash irias_new_octseq_value 2 13596 _003296_hash NULL nohasharray
83444 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
83445 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
83446 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
83447 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
83448 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
83449 +_000294_hash isdn_read 3 50021 _000294_hash NULL
83450 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
83451 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
83452 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
83453 +_000298_hash iso_callback 3 43208 _000298_hash NULL
83454 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
83455 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
83456 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
83457 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
83458 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
83459 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
83460 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
83461 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
83462 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
83463 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
83464 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
83465 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
83466 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
83467 +_000314_hash kmalloc_node 1 50163 _003293_hash NULL nohasharray
83468 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
83469 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
83470 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
83471 +_000319_hash kone_receive 4 4690 _000319_hash NULL
83472 +_000320_hash kone_send 4 63435 _000320_hash NULL
83473 +_000321_hash krealloc 2 14908 _000321_hash NULL
83474 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
83475 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
83476 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
83477 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
83478 +_000326_hash kzalloc 1 54740 _000326_hash NULL
83479 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
83480 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
83481 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
83482 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
83483 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
83484 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
83485 +_000333_hash __lgread 4 31668 _000333_hash NULL
83486 +_000334_hash libipw_alloc_txb 1-3-2 27579 _000334_hash NULL
83487 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
83488 +_000336_hash listxattr 3 12769 _000336_hash NULL
83489 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
83490 +_000338_hash load_msg 2 95 _000338_hash NULL
83491 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
83492 +_000340_hash lp_write 3 9511 _000340_hash NULL
83493 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
83494 +_000342_hash mce_write 3 26201 _000342_hash NULL
83495 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
83496 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
83497 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
83498 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
83499 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
83500 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
83501 +_000350_hash mem_rw 3 22085 _000350_hash NULL
83502 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
83503 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
83504 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
83505 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
83506 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
83507 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
83508 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
83509 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
83510 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
83511 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
83512 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
83513 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
83514 +_000363_hash mtdchar_write 3 56831 _002688_hash NULL nohasharray
83515 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
83516 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
83517 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
83518 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
83519 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
83520 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
83521 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
83522 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
83523 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
83524 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
83525 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
83526 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
83527 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
83528 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
83529 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
83530 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
83531 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
83532 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
83533 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
83534 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
83535 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
83536 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
83537 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
83538 +_000391_hash nvram_write 3 3894 _000391_hash NULL
83539 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
83540 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
83541 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
83542 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
83543 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
83544 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
83545 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
83546 +_000399_hash opticon_write 4 60775 _000399_hash NULL
83547 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
83548 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
83549 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
83550 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
83551 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
83552 +_000405_hash parse_command 2 37079 _000405_hash NULL
83553 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
83554 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
83555 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
83556 +_000409_hash pg_write 3 40766 _000409_hash NULL
83557 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
83558 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
83559 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
83560 +_000413_hash pkt_add 3 39897 _000413_hash NULL
83561 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
83562 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
83563 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
83564 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
83565 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
83566 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
83567 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
83568 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
83569 +_000422_hash ppp_write 3 34034 _000422_hash NULL
83570 +_000423_hash pp_read 3 33210 _000423_hash NULL
83571 +_000424_hash pp_write 3 39554 _000424_hash NULL
83572 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
83573 +_000426_hash printer_write 3 60276 _000426_hash NULL
83574 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
83575 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
83576 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
83577 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
83578 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
83579 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
83580 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
83581 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
83582 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
83583 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
83584 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
83585 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
83586 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
83587 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
83588 +_000442_hash pt_write 3 40159 _000442_hash NULL
83589 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
83590 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
83591 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
83592 +_000446_hash r3964_write 4 57662 _000446_hash NULL
83593 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
83594 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
83595 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
83596 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
83597 +_000451_hash rbd_add 3 16366 _000451_hash NULL
83598 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
83599 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
83600 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
83601 +_000455_hash read 3 9397 _000455_hash NULL
83602 +_000456_hash read_buf 2 20469 _000456_hash NULL
83603 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
83604 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
83605 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
83606 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
83607 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
83608 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
83609 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
83610 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
83611 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
83612 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
83613 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
83614 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
83615 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
83616 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
83617 +_000471_hash revalidate 2 19043 _000471_hash NULL
83618 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
83619 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
83620 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
83621 +_000475_hash rngapi_reset 3 34366 _002911_hash NULL nohasharray
83622 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
83623 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
83624 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
83625 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
83626 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
83627 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
83628 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
83629 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
83630 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
83631 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
83632 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
83633 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
83634 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
83635 +_000489_hash savemem 3 58129 _000489_hash NULL
83636 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
83637 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
83638 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
83639 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
83640 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
83641 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
83642 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
83643 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
83644 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
83645 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
83646 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
83647 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
83648 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
83649 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
83650 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
83651 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
83652 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
83653 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
83654 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
83655 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
83656 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
83657 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
83658 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
83659 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
83660 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
83661 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
83662 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
83663 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
83664 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
83665 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
83666 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
83667 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
83668 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
83669 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
83670 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
83671 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
83672 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
83673 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
83674 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
83675 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
83676 +_000532_hash set_registers 3 53582 _000532_hash NULL
83677 +_000533_hash setsockopt 5 54539 _000533_hash NULL
83678 +_000534_hash setup_req 3 5848 _000534_hash NULL
83679 +_000535_hash setup_window 7 59178 _000535_hash NULL
83680 +_000536_hash setxattr 4 37006 _000536_hash NULL
83681 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
83682 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
83683 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
83684 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
83685 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
83686 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
83687 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
83688 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
83689 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
83690 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
83691 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
83692 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
83693 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
83694 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
83695 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
83696 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
83697 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
83698 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
83699 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
83700 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
83701 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
83702 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
83703 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
83704 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
83705 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
83706 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
83707 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
83708 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
83709 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
83710 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
83711 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
83712 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
83713 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
83714 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
83715 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
83716 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
83717 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
83718 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
83719 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
83720 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
83721 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
83722 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
83723 +_000581_hash spidev_write 3 44510 _000581_hash NULL
83724 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
83725 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
83726 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
83727 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
83728 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
83729 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
83730 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
83731 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
83732 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
83733 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
83734 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
83735 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
83736 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
83737 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
83738 +_000597_hash tower_write 3 8580 _000597_hash NULL
83739 +_000598_hash tpm_write 3 50798 _000598_hash NULL
83740 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
83741 +_000600_hash trusted_update 3 12664 _000600_hash NULL
83742 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
83743 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
83744 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
83745 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
83746 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
83747 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
83748 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
83749 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
83750 +_000609_hash uea_request 4 47613 _000609_hash NULL
83751 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
83752 +_000611_hash uio_write 3 43202 _000611_hash NULL
83753 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
83754 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
83755 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
83756 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
83757 +_000616_hash usblp_write 3 23178 _000616_hash NULL
83758 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
83759 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
83760 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
83761 +_000621_hash user_update 3 41332 _000621_hash NULL
83762 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
83763 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
83764 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
83765 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
83766 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
83767 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
83768 +_000629_hash vcs_write 3 3910 _000629_hash NULL
83769 +_000630_hash vfd_write 3 14717 _000630_hash NULL
83770 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
83771 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
83772 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
83773 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
83774 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
83775 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
83776 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
83777 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
83778 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
83779 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
83780 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
83781 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
83782 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
83783 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
83784 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
83785 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
83786 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
83787 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
83788 +_000651_hash wdm_write 3 53735 _000651_hash NULL
83789 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
83790 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
83791 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
83792 +_000655_hash write 3 62671 _000655_hash NULL
83793 +_000656_hash write_flush 3 50803 _000656_hash NULL
83794 +_000657_hash write_rio 3 54837 _000657_hash NULL
83795 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
83796 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
83797 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
83798 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
83799 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
83800 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
83801 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
83802 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
83803 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
83804 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
83805 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
83806 +_000669_hash zoran_write 3 22404 _000669_hash NULL
83807 +_000671_hash acpi_ex_allocate_name_string 2-1 7685 _002855_hash NULL nohasharray
83808 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
83809 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
83810 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
83811 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
83812 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
83813 +_000677_hash add_res_range 4 21310 _000677_hash NULL
83814 +_000678_hash addtgt 3 54703 _000678_hash NULL
83815 +_000679_hash add_uuid 4 49831 _000679_hash NULL
83816 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
83817 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
83818 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
83819 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
83820 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
83821 +_000685_hash alloc_async 1 14208 _000685_hash NULL
83822 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
83823 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
83824 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
83825 +_000689_hash alloc_context 1 41283 _000689_hash NULL
83826 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
83827 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
83828 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
83829 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
83830 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
83831 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
83832 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
83833 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
83834 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
83835 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
83836 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
83837 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
83838 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
83839 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
83840 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
83841 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
83842 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
83843 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
83844 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
83845 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
83846 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
83847 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
83848 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
83849 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
83850 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
83851 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
83852 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
83853 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
83854 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
83855 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
83856 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
83857 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
83858 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
83859 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
83860 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
83861 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
83862 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
83863 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
83864 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
83865 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
83866 +_000736_hash ati_create_gatt_pages 1 4722 _003185_hash NULL nohasharray
83867 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
83868 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
83869 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
83870 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
83871 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
83872 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
83873 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
83874 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
83875 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
83876 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
83877 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
83878 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
83879 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
83880 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
83881 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
83882 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
83883 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
83884 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
83885 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
83886 +_000759_hash ca_extend 2 64541 _000759_hash NULL
83887 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
83888 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
83889 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
83890 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
83891 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
83892 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
83893 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
83894 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
83895 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
83896 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
83897 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
83898 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
83899 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
83900 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
83901 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
83902 +_000778_hash cifs_writedata_alloc 1 32880 _003119_hash NULL nohasharray
83903 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
83904 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
83905 +_000781_hash construct_key 3 11329 _000781_hash NULL
83906 +_000782_hash context_alloc 3 24645 _000782_hash NULL
83907 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
83908 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
83909 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
83910 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
83911 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
83912 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
83913 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
83914 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
83915 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
83916 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
83917 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
83918 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
83919 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
83920 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
83921 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
83922 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
83923 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
83924 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
83925 +_000805_hash depth_write 3 3021 _000805_hash NULL
83926 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
83927 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
83928 +_000808_hash dev_write 3 7708 _000808_hash NULL
83929 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
83930 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
83931 +_000811_hash disconnect 4 32521 _000811_hash NULL
83932 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
83933 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
83934 +_000815_hash do_dccp_setsockopt 5 54377 _003160_hash NULL nohasharray
83935 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
83936 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
83937 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
83938 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
83939 +_000820_hash do_sync 1 9604 _000820_hash NULL
83940 +_000821_hash dup_array 3 33551 _000821_hash NULL
83941 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
83942 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
83943 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
83944 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
83945 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
83946 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
83947 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
83948 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
83949 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
83950 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
83951 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
83952 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
83953 +_000834_hash enable_write 3 30456 _000834_hash NULL
83954 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
83955 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
83956 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
83957 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
83958 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
83959 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
83960 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
83961 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
83962 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
83963 +_000844_hash fillonedir 3 41746 _000844_hash NULL
83964 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
83965 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
83966 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
83967 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
83968 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
83969 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
83970 +_000851_hash get_entry 4 16003 _000851_hash NULL
83971 +_000852_hash get_free_de 2 33714 _000852_hash NULL
83972 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
83973 +_000854_hash getxattr 4 24398 _000854_hash NULL
83974 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
83975 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
83976 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
83977 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
83978 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
83979 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
83980 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
83981 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
83982 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
83983 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
83984 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
83985 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
83986 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
83987 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
83988 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
83989 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
83990 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
83991 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
83992 +_000876_hash ieee80211_send_probe_req 6-4 6924 _000876_hash NULL
83993 +_000877_hash if_writecmd 2 815 _000877_hash NULL
83994 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
83995 +_000880_hash init_ipath 1 48187 _000880_hash NULL
83996 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
83997 +_000883_hash init_q 4 132 _000883_hash NULL
83998 +_000884_hash init_state 2 60165 _000884_hash NULL
83999 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
84000 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
84001 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
84002 +_000888_hash interfaces 2 38859 _000888_hash NULL
84003 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
84004 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
84005 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
84006 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
84007 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
84008 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
84009 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
84010 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
84011 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
84012 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
84013 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
84014 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
84015 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
84016 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
84017 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
84018 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
84019 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
84020 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
84021 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
84022 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
84023 +_000911_hash isdn_write 3 45863 _000911_hash NULL
84024 +_000912_hash isku_receive 4 54130 _000912_hash NULL
84025 +_000913_hash isku_send 4 41542 _000913_hash NULL
84026 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
84027 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
84028 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
84029 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
84030 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
84031 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
84032 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
84033 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
84034 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
84035 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
84036 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
84037 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
84038 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
84039 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
84040 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
84041 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
84042 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
84043 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
84044 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
84045 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
84046 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
84047 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
84048 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
84049 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
84050 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
84051 +_000940_hash kvm_write_guest_page 5 63555 _002809_hash NULL nohasharray
84052 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
84053 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
84054 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
84055 +_000945_hash lc_create 3 48662 _000945_hash NULL
84056 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
84057 +_000947_hash linear_conf 2 23485 _003314_hash NULL nohasharray
84058 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
84059 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
84060 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
84061 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
84062 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
84063 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
84064 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
84065 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
84066 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
84067 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
84068 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
84069 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
84070 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
84071 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
84072 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
84073 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
84074 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
84075 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
84076 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
84077 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
84078 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
84079 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
84080 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
84081 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
84082 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
84083 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
84084 +_000977_hash new_dir 3 31919 _000977_hash NULL
84085 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
84086 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
84087 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
84088 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
84089 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
84090 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
84091 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
84092 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
84093 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
84094 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
84095 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
84096 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
84097 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
84098 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
84099 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
84100 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
84101 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
84102 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
84103 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
84104 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
84105 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
84106 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
84107 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
84108 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
84109 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
84110 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
84111 +_001008_hash osst_write 3 31581 _001008_hash NULL
84112 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
84113 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
84114 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
84115 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
84116 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
84117 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
84118 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
84119 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
84120 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
84121 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
84122 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
84123 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
84124 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
84125 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
84126 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
84127 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
84128 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
84129 +_001030_hash play_iframe 3 8219 _001030_hash NULL
84130 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
84131 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
84132 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
84133 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
84134 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
84135 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
84136 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
84137 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
84138 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
84139 +_001042_hash proc_write 3 51003 _001042_hash NULL
84140 +_001043_hash profile_load 3 58267 _001043_hash NULL
84141 +_001044_hash profile_remove 3 8556 _001044_hash NULL
84142 +_001045_hash profile_replace 3 14652 _001045_hash NULL
84143 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
84144 +_001047_hash pyra_send 4 12061 _001047_hash NULL
84145 +_001048_hash qc_capture 3 19298 _001048_hash NULL
84146 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
84147 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
84148 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
84149 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
84150 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
84151 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
84152 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
84153 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
84154 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
84155 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
84156 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
84157 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
84158 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
84159 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
84160 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
84161 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
84162 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
84163 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
84164 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
84165 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
84166 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
84167 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
84168 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
84169 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
84170 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
84171 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
84172 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
84173 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
84174 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
84175 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
84176 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
84177 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
84178 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
84179 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
84180 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
84181 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
84182 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
84183 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
84184 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
84185 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
84186 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
84187 +_001092_hash security_context_to_sid_default 2 3492 _003366_hash NULL nohasharray
84188 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
84189 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
84190 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
84191 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
84192 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
84193 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
84194 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
84195 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
84196 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
84197 +_001102_hash set_connectable 4 56458 _001102_hash NULL
84198 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
84199 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
84200 +_001105_hash setkey 3 14987 _001105_hash NULL
84201 +_001106_hash set_le 4 30581 _001106_hash NULL
84202 +_001107_hash set_link_security 4 4502 _001107_hash NULL
84203 +_001108_hash set_local_name 4 55757 _001108_hash NULL
84204 +_001109_hash set_powered 4 12129 _001109_hash NULL
84205 +_001110_hash set_ssp 4 62411 _001110_hash NULL
84206 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
84207 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
84208 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
84209 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
84210 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
84211 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
84212 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
84213 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
84214 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
84215 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
84216 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
84217 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
84218 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
84219 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
84220 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
84221 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
84222 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
84223 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
84224 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
84225 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
84226 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
84227 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
84228 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
84229 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
84230 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
84231 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
84232 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
84233 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
84234 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
84235 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
84236 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
84237 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
84238 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
84239 +_001148_hash sound_write 3 5102 _001148_hash NULL
84240 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
84241 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
84242 +_001151_hash spidev_message 3 5518 _001151_hash NULL
84243 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
84244 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
84245 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
84246 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
84247 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
84248 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
84249 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
84250 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
84251 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
84252 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
84253 +_001163_hash st_write 3 16874 _001163_hash NULL
84254 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
84255 +_001165_hash symtab_init 2 61050 _001165_hash NULL
84256 +_001166_hash sys_bind 3 10799 _001166_hash NULL
84257 +_001167_hash sys_connect 3 15291 _003291_hash NULL nohasharray
84258 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
84259 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
84260 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
84261 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
84262 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
84263 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
84264 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
84265 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
84266 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
84267 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
84268 +_001178_hash sys_semop 3 39457 _001178_hash NULL
84269 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
84270 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
84271 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
84272 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
84273 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
84274 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
84275 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
84276 +_001186_hash timeout_write 3 50991 _001186_hash NULL
84277 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
84278 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
84279 +_001189_hash tm6000_read_write_usb 7 50774 _002917_hash NULL nohasharray
84280 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
84281 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
84282 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
84283 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
84284 +_001195_hash ts_write 3 64336 _001195_hash NULL
84285 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
84286 +_001197_hash tty_write 3 5494 _001197_hash NULL
84287 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
84288 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
84289 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
84290 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
84291 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
84292 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
84293 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
84294 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
84295 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
84296 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
84297 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
84298 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
84299 +_001211_hash uvc_alloc_entity 3-4 20836 _001211_hash NULL
84300 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
84301 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
84302 +_001214_hash vb2_read 3 42703 _001214_hash NULL
84303 +_001215_hash vb2_write 3 31948 _001215_hash NULL
84304 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
84305 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
84306 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
84307 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
84308 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
84309 +_001223_hash vmalloc 1 15464 _001223_hash NULL
84310 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
84311 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
84312 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
84313 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
84314 +_001228_hash vzalloc 1 47421 _001228_hash NULL
84315 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
84316 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
84317 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
84318 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
84319 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
84320 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
84321 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
84322 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
84323 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
84324 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
84325 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
84326 +_001240_hash xfs_dir_cilookup_result 3 64288 _003139_hash NULL nohasharray
84327 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
84328 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
84329 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
84330 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
84331 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
84332 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
84333 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
84334 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
84335 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
84336 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
84337 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
84338 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
84339 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
84340 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
84341 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
84342 +_001256_hash add_child 4 45201 _001256_hash NULL
84343 +_001257_hash add_port 2 54941 _001257_hash NULL
84344 +_001258_hash adu_read 3 24177 _001258_hash NULL
84345 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
84346 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
84347 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
84348 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
84349 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
84350 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
84351 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
84352 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
84353 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
84354 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
84355 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
84356 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
84357 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
84358 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
84359 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
84360 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
84361 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
84362 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
84363 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
84364 +_001280_hash async_setkey 3 35521 _001280_hash NULL
84365 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
84366 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
84367 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
84368 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
84369 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
84370 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
84371 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
84372 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
84373 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
84374 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
84375 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
84376 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
84377 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
84378 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
84379 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
84380 +_001298_hash bm_init 2 13529 _001298_hash NULL
84381 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
84382 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
84383 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
84384 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
84385 +_001303_hash cache_read 3 24790 _001303_hash NULL
84386 +_001304_hash cache_write 3 13589 _001304_hash NULL
84387 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
84388 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
84389 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
84390 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
84391 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
84392 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
84393 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
84394 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
84395 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
84396 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
84397 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
84398 +_001317_hash copy_oldmem_page 3-1 26164 _001317_hash NULL
84399 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
84400 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
84401 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
84402 +_001321_hash crypto_authenc_setkey 3 80 _003311_hash NULL nohasharray
84403 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
84404 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
84405 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
84406 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
84407 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
84408 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
84409 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
84410 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
84411 +_001331_hash dev_read 3 56369 _001331_hash NULL
84412 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
84413 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
84414 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
84415 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
84416 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
84417 +_001338_hash do_readlink 2 43518 _001338_hash NULL
84418 +_001339_hash __do_replace 5 37227 _001339_hash NULL
84419 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
84420 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
84421 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
84422 +_001343_hash dump_midi 3 51040 _001343_hash NULL
84423 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
84424 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
84425 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5-2 4303 _001346_hash NULL
84426 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
84427 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
84428 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
84429 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
84430 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
84431 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
84432 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
84433 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
84434 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
84435 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
84436 +_001358_hash filldir 3 55137 _001358_hash NULL
84437 +_001359_hash filldir64 3 46469 _001359_hash NULL
84438 +_001360_hash fops_read 3 40672 _001360_hash NULL
84439 +_001361_hash from_buffer 3 18625 _001361_hash NULL
84440 +_001362_hash fsm_init 2 16134 _001362_hash NULL
84441 +_001363_hash get_subdir 3 62581 _001363_hash NULL
84442 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
84443 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
84444 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
84445 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
84446 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
84447 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
84448 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
84449 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
84450 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
84451 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
84452 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
84453 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
84454 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
84455 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
84456 +_001379_hash ilo_read 3 32531 _001379_hash NULL
84457 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
84458 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
84459 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
84460 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
84461 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
84462 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
84463 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
84464 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
84465 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
84466 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
84467 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
84468 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
84469 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
84470 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
84471 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
84472 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
84473 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
84474 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
84475 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
84476 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
84477 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
84478 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
84479 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
84480 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
84481 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
84482 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
84483 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
84484 +_001412_hash keyring_read 3 13438 _001412_hash NULL
84485 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
84486 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
84487 +_001415_hash kmp_init 2 41373 _001415_hash NULL
84488 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
84489 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
84490 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
84491 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
84492 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
84493 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
84494 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
84495 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
84496 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
84497 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
84498 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
84499 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
84500 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
84501 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
84502 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
84503 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
84504 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
84505 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
84506 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
84507 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
84508 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
84509 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
84510 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
84511 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
84512 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
84513 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
84514 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
84515 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
84516 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
84517 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
84518 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
84519 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
84520 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
84521 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
84522 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
84523 +_001454_hash override_release 2 52032 _001454_hash NULL
84524 +_001455_hash packet_snd 3 13634 _001455_hash NULL
84525 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
84526 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
84527 +_001458_hash pg_read 3 17276 _001458_hash NULL
84528 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
84529 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
84530 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
84531 +_001462_hash pms_capture 4 27142 _001462_hash NULL
84532 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
84533 +_001464_hash printer_read 3 54851 _001464_hash NULL
84534 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
84535 +_001466_hash pt_read 3 49136 _001466_hash NULL
84536 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
84537 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
84538 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
84539 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
84540 +_001471_hash qcam_read 3 13977 _001471_hash NULL
84541 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
84542 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
84543 +_001474_hash read_flush 3 43851 _001474_hash NULL
84544 +_001475_hash read_profile 3 27859 _001475_hash NULL
84545 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
84546 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
84547 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
84548 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
84549 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
84550 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
84551 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
84552 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
84553 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
84554 +_001486_hash roccat_read 3 41093 _001486_hash NULL
84555 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
84556 +_001488_hash scsi_register 2 49094 _001488_hash NULL
84557 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
84558 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
84559 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
84560 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
84561 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
84562 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
84563 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
84564 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
84565 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
84566 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
84567 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
84568 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
84569 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
84570 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
84571 +_001503_hash set_arg 3 42824 _001503_hash NULL
84572 +_001504_hash sg_read 3 25799 _001504_hash NULL
84573 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
84574 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
84575 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
84576 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
84577 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
84578 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
84579 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
84580 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
84581 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
84582 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
84583 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
84584 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
84585 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
84586 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
84587 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
84588 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
84589 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
84590 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
84591 +_001525_hash store_msg 3 56417 _001525_hash NULL
84592 +_001526_hash str_to_user 2 11411 _001526_hash NULL
84593 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
84594 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
84595 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
84596 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
84597 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
84598 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
84599 +_001533_hash sys_process_vm_readv 3-5 19090 _003125_hash NULL nohasharray
84600 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
84601 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
84602 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
84603 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
84604 +_001540_hash team_options_register 3 20091 _001540_hash NULL
84605 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
84606 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
84607 +_001543_hash tipc_send 4 51238 _001543_hash NULL
84608 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
84609 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
84610 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
84611 +_001547_hash tnode_new 3 44757 _001547_hash NULL
84612 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
84613 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
84614 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
84615 +_001551_hash tpm_read 3 50344 _001551_hash NULL
84616 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
84617 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
84618 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
84619 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
84620 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
84621 +_001558_hash uio_read 3 49300 _001558_hash NULL
84622 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
84623 +_001560_hash unlink1 3 63059 _001560_hash NULL
84624 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
84625 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
84626 +_001564_hash usblp_read 3 57342 _003306_hash NULL nohasharray
84627 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
84628 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
84629 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
84630 +_001568_hash user_read 3 51881 _001568_hash NULL
84631 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
84632 +_001570_hash vcs_read 3 8017 _001570_hash NULL
84633 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
84634 +_001572_hash venus_create 4 20555 _001572_hash NULL
84635 +_001573_hash venus_link 5 32165 _001573_hash NULL
84636 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
84637 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
84638 +_001576_hash venus_remove 4 59781 _001576_hash NULL
84639 +_001577_hash venus_rename 4-5 17707 _003279_hash NULL nohasharray
84640 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
84641 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
84642 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
84643 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
84644 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
84645 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
84646 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
84647 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
84648 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
84649 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
84650 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
84651 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
84652 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
84653 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
84654 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
84655 +_001596_hash wdm_read 3 6549 _001596_hash NULL
84656 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
84657 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
84658 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
84659 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
84660 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
84661 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
84662 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
84663 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
84664 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
84665 +_001606_hash xz_dec_lzma2_create 2 36353 _002745_hash NULL nohasharray
84666 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
84667 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
84668 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
84669 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
84670 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
84671 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
84672 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
84673 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
84674 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
84675 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
84676 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
84677 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
84678 +_001619_hash __alloc_bootmem_low 1 43423 _003150_hash NULL nohasharray
84679 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
84680 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
84681 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
84682 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
84683 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
84684 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
84685 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
84686 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
84687 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
84688 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
84689 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
84690 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
84691 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
84692 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
84693 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
84694 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
84695 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
84696 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
84697 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
84698 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
84699 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
84700 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
84701 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
84702 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
84703 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
84704 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
84705 +_001648_hash blk_queue_init_tags 2 44355 _002686_hash NULL nohasharray
84706 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
84707 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
84708 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
84709 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
84710 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
84711 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
84712 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
84713 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
84714 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
84715 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
84716 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
84717 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
84718 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
84719 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
84720 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
84721 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
84722 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
84723 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
84724 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
84725 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
84726 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
84727 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
84728 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
84729 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
84730 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
84731 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
84732 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
84733 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
84734 +_001677_hash create_subvol 4 2347 _001677_hash NULL
84735 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
84736 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
84737 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
84738 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
84739 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
84740 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
84741 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
84742 +_001687_hash debug_output 3 18575 _001687_hash NULL
84743 +_001688_hash debug_read 3 19322 _001688_hash NULL
84744 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
84745 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
84746 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
84747 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
84748 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
84749 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
84750 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
84751 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
84752 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
84753 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
84754 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
84755 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
84756 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
84757 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
84758 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
84759 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
84760 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
84761 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
84762 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
84763 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
84764 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
84765 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
84766 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
84767 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
84768 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
84769 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
84770 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
84771 +_001716_hash filter_read 3 61692 _001716_hash NULL
84772 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
84773 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
84774 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
84775 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
84776 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
84777 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
84778 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
84779 +_001724_hash ht40allow_map_read 3 55209 _002830_hash NULL nohasharray
84780 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
84781 +_001726_hash hysdn_conf_read 3 42324 _003205_hash NULL nohasharray
84782 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
84783 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
84784 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
84785 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
84786 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
84787 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
84788 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
84789 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
84790 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
84791 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
84792 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
84793 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
84794 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
84795 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
84796 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
84797 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
84798 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
84799 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
84800 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
84801 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
84802 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
84803 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
84804 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
84805 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
84806 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
84807 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
84808 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
84809 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
84810 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
84811 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
84812 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
84813 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
84814 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
84815 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
84816 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
84817 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
84818 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
84819 +_001765_hash ipw_write 3 59807 _001765_hash NULL
84820 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
84821 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
84822 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
84823 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
84824 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
84825 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
84826 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
84827 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
84828 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
84829 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
84830 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
84831 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
84832 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
84833 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
84834 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
84835 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
84836 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
84837 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
84838 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
84839 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
84840 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
84841 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
84842 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
84843 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
84844 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
84845 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
84846 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
84847 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
84848 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
84849 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
84850 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
84851 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
84852 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
84853 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
84854 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
84855 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
84856 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
84857 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
84858 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
84859 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
84860 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
84861 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
84862 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _003026_hash NULL nohasharray
84863 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
84864 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
84865 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
84866 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
84867 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
84868 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
84869 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
84870 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
84871 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
84872 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
84873 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
84874 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
84875 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
84876 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
84877 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
84878 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
84879 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
84880 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
84881 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
84882 +_001828_hash key_key_read 3 3241 _001828_hash NULL
84883 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
84884 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
84885 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
84886 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
84887 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
84888 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
84889 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
84890 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
84891 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
84892 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
84893 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
84894 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
84895 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
84896 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
84897 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
84898 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
84899 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
84900 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
84901 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
84902 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
84903 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
84904 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
84905 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
84906 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
84907 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
84908 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
84909 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
84910 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
84911 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
84912 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
84913 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
84914 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
84915 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
84916 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
84917 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
84918 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
84919 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
84920 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
84921 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
84922 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
84923 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
84924 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
84925 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
84926 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
84927 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
84928 +_001876_hash nfsd_vfs_read 6 62605 _003003_hash NULL nohasharray
84929 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
84930 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
84931 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
84932 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
84933 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
84934 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
84935 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
84936 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
84937 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
84938 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
84939 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
84940 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
84941 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
84942 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
84943 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
84944 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
84945 +_001893_hash page_readlink 3 23346 _001893_hash NULL
84946 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
84947 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
84948 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
84949 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
84950 +_001898_hash pms_read 3 53873 _001898_hash NULL
84951 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
84952 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
84953 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
84954 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
84955 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
84956 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
84957 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
84958 +_001906_hash proc_read 3 43614 _001906_hash NULL
84959 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
84960 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
84961 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
84962 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
84963 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
84964 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
84965 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
84966 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
84967 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
84968 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
84969 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
84970 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
84971 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
84972 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
84973 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
84974 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
84975 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
84976 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
84977 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
84978 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
84979 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
84980 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
84981 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
84982 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
84983 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
84984 +_001932_hash queues_read 3 24877 _001932_hash NULL
84985 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
84986 +_001934_hash rcname_read 3 25919 _001934_hash NULL
84987 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
84988 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
84989 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
84990 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
84991 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
84992 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
84993 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
84994 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
84995 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
84996 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
84997 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
84998 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
84999 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
85000 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
85001 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
85002 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
85003 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
85004 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
85005 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
85006 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
85007 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
85008 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
85009 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
85010 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
85011 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
85012 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
85013 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
85014 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
85015 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
85016 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
85017 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
85018 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
85019 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
85020 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
85021 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
85022 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
85023 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
85024 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
85025 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
85026 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
85027 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
85028 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
85029 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
85030 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
85031 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
85032 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
85033 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
85034 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
85035 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
85036 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
85037 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
85038 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
85039 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
85040 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
85041 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003089_hash NULL nohasharray
85042 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
85043 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
85044 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
85045 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
85046 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
85047 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
85048 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
85049 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
85050 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
85051 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
85052 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
85053 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
85054 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
85055 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
85056 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
85057 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
85058 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
85059 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
85060 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
85061 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
85062 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
85063 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
85064 +_002013_hash sel_read_policyvers 3 55 _003257_hash NULL nohasharray
85065 +_002014_hash send_msg 4 37323 _002014_hash NULL
85066 +_002015_hash send_packet 4 52960 _002015_hash NULL
85067 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
85068 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
85069 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
85070 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
85071 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
85072 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
85073 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
85074 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
85075 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
85076 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
85077 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
85078 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
85079 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
85080 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
85081 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
85082 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
85083 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
85084 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
85085 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
85086 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
85087 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
85088 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
85089 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
85090 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
85091 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
85092 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
85093 +_002045_hash st_read 3 51251 _002045_hash NULL
85094 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
85095 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
85096 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
85097 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
85098 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
85099 +_002051_hash sys_readv 3 50664 _002051_hash NULL
85100 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
85101 +_002053_hash sys_writev 3 28384 _002053_hash NULL
85102 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
85103 +_002055_hash ts_read 3 44687 _002055_hash NULL
85104 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
85105 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
85106 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
85107 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
85108 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
85109 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
85110 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
85111 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
85112 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
85113 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
85114 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
85115 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
85116 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
85117 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
85118 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
85119 +_002074_hash waiters_read 3 40902 _002074_hash NULL
85120 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
85121 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
85122 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
85123 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
85124 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
85125 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
85126 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
85127 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
85128 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
85129 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
85130 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
85131 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
85132 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
85133 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
85134 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
85135 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
85136 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
85137 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
85138 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
85139 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
85140 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
85141 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
85142 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
85143 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
85144 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
85145 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
85146 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
85147 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
85148 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
85149 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
85150 +_002106_hash cx18_read 3 23699 _002106_hash NULL
85151 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
85152 +_002108_hash depth_read 3 31112 _002108_hash NULL
85153 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
85154 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
85155 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
85156 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
85157 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
85158 +_002115_hash enable_read 3 2117 _002115_hash NULL
85159 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
85160 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
85161 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
85162 +_002119_hash frequency_read 3 64031 _003106_hash NULL nohasharray
85163 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
85164 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
85165 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
85166 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
85167 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
85168 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
85169 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
85170 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
85171 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
85172 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
85173 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
85174 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
85175 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
85176 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
85177 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
85178 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
85179 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
85180 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
85181 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
85182 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
85183 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
85184 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
85185 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
85186 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
85187 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
85188 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
85189 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
85190 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
85191 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
85192 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
85193 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
85194 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
85195 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
85196 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
85197 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
85198 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
85199 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
85200 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002859_hash NULL nohasharray
85201 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
85202 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
85203 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
85204 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
85205 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
85206 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
85207 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
85208 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
85209 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
85210 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
85211 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
85212 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
85213 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
85214 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
85215 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
85216 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
85217 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
85218 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
85219 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
85220 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
85221 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
85222 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
85223 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
85224 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
85225 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
85226 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
85227 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
85228 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
85229 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
85230 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
85231 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
85232 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
85233 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
85234 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
85235 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
85236 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
85237 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
85238 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
85239 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
85240 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
85241 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
85242 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
85243 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
85244 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
85245 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
85246 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
85247 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
85248 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
85249 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
85250 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
85251 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
85252 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
85253 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
85254 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
85255 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
85256 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
85257 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
85258 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
85259 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
85260 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
85261 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
85262 +_002220_hash power_read 3 15939 _002220_hash NULL
85263 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
85264 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
85265 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
85266 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
85267 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
85268 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
85269 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
85270 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
85271 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
85272 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
85273 +_002231_hash read_tree_block 3 841 _002231_hash NULL
85274 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
85275 +_002234_hash recv_msg 4 48709 _002234_hash NULL
85276 +_002235_hash recv_stream 4 30138 _002235_hash NULL
85277 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
85278 +_002237_hash request_key_async 4 6990 _002237_hash NULL
85279 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
85280 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
85281 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
85282 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
85283 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
85284 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
85285 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
85286 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
85287 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
85288 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
85289 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
85290 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
85291 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
85292 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
85293 +_002252_hash send_stream 4 3397 _002252_hash NULL
85294 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
85295 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
85296 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
85297 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
85298 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
85299 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
85300 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
85301 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
85302 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
85303 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
85304 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
85305 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
85306 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
85307 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
85308 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
85309 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
85310 +_002270_hash timeout_read 3 47915 _002270_hash NULL
85311 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
85312 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
85313 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
85314 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
85315 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
85316 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
85317 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
85318 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
85319 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
85320 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
85321 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
85322 +_002283_hash user_power_read 3 39414 _002283_hash NULL
85323 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
85324 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
85325 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
85326 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
85327 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
85328 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
85329 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
85330 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
85331 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
85332 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
85333 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
85334 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
85335 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
85336 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
85337 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
85338 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
85339 +_002300_hash spi_execute 5 28736 _002300_hash NULL
85340 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
85341 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
85342 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
85343 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
85344 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
85345 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
85346 +_002308_hash write_leb 5 36957 _002308_hash NULL
85347 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
85348 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
85349 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
85350 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
85351 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
85352 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
85353 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
85354 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
85355 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
85356 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
85357 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
85358 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
85359 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
85360 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
85361 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
85362 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
85363 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
85364 +_002329_hash recover_head 3 17904 _002329_hash NULL
85365 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
85366 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
85367 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
85368 +_002334_hash amthi_read 4 45831 _002334_hash NULL
85369 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
85370 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
85371 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
85372 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
85373 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
85374 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
85375 +_002341_hash card_send_command 3 40757 _002341_hash NULL
85376 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
85377 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
85378 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
85379 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
85380 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
85381 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
85382 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
85383 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
85384 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
85385 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
85386 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
85387 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
85388 +_002354_hash fir16_create 3 5574 _002354_hash NULL
85389 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
85390 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
85391 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
85392 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
85393 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
85394 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
85395 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
85396 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
85397 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
85398 +_002365_hash keymap_store 4 45406 _002365_hash NULL
85399 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
85400 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
85401 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
85402 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
85403 +_002370_hash lirc_write 3 20604 _002370_hash NULL
85404 +_002371_hash _malloc 1 54077 _002371_hash NULL
85405 +_002372_hash mei_read 3 6507 _002372_hash NULL
85406 +_002373_hash mei_write 3 4005 _002373_hash NULL
85407 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
85408 +_002375_hash msg_set 3 51725 _002375_hash NULL
85409 +_002376_hash newpart 6 47485 _002376_hash NULL
85410 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
85411 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
85412 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
85413 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
85414 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
85415 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
85416 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
85417 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
85418 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
85419 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
85420 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
85421 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
85422 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
85423 +_002393_hash sep_read 3 17161 _002393_hash NULL
85424 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
85425 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
85426 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
85427 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
85428 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
85429 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
85430 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
85431 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
85432 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
85433 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
85434 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
85435 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
85436 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
85437 +_002411_hash mempool_create 1 29437 _002411_hash NULL
85438 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
85439 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
85440 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
85441 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
85442 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
85443 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
85444 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
85445 +_002419_hash add_partition 2 55588 _002419_hash NULL
85446 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
85447 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
85448 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
85449 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
85450 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
85451 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
85452 +_002427_hash bioset_create 1 5580 _002427_hash NULL
85453 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
85454 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
85455 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
85456 +_002431_hash prison_create 1 43623 _002431_hash NULL
85457 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
85458 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
85459 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
85460 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
85461 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
85462 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
85463 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
85464 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
85465 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
85466 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
85467 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
85468 +_002443_hash comedi_read 3 13199 _002443_hash NULL
85469 +_002444_hash comedi_write 3 47926 _002444_hash NULL
85470 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
85471 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
85472 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
85473 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
85474 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
85475 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
85476 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
85477 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
85478 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
85479 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
85480 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
85481 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
85482 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
85483 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
85484 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
85485 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
85486 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
85487 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
85488 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
85489 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
85490 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
85491 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
85492 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
85493 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
85494 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
85495 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
85496 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
85497 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
85498 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
85499 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
85500 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
85501 +_002476_hash flash_read 3 57843 _002476_hash NULL
85502 +_002477_hash flash_write 3 62354 _002477_hash NULL
85503 +_002478_hash gather_array 3 56641 _002478_hash NULL
85504 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
85505 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
85506 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
85507 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
85508 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
85509 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
85510 +_002486_hash ieee80211_alloc_txb 1-2 52477 _002486_hash NULL
85511 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
85512 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
85513 +_002489_hash init_cdev 1 8274 _002489_hash NULL
85514 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
85515 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
85516 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
85517 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
85518 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
85519 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
85520 +_002496_hash options_write 3 47243 _002496_hash NULL
85521 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
85522 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
85523 +_002499_hash portnames_read 3 41958 _002499_hash NULL
85524 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
85525 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
85526 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
85527 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
85528 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
85529 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
85530 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
85531 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
85532 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
85533 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
85534 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
85535 +_002511_hash queue_reply 3 22416 _002511_hash NULL
85536 +_002512_hash Realloc 2 34961 _002512_hash NULL
85537 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
85538 +_002514_hash rtllib_alloc_txb 1-2 21687 _002514_hash NULL
85539 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
85540 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
85541 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
85542 +_002518_hash split 2 11691 _002518_hash NULL
85543 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
85544 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
85545 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
85546 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
85547 +_002523_hash tunables_read 3 36385 _002523_hash NULL
85548 +_002524_hash tunables_write 3 59563 _002524_hash NULL
85549 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
85550 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
85551 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
85552 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
85553 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
85554 +_002530_hash xsd_read 3 15653 _002530_hash NULL
85555 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
85556 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _003110_hash NULL nohasharray
85557 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
85558 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
85559 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
85560 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
85561 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
85562 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
85563 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
85564 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
85565 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
85566 +_002546_hash compat_readv 3 30273 _002546_hash NULL
85567 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
85568 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
85569 +_002551_hash compat_writev 3 60063 _002551_hash NULL
85570 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
85571 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
85572 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
85573 +_002555_hash xd_rw 4 49020 _002555_hash NULL
85574 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
85575 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
85576 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
85577 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
85578 +_002560_hash ms_rw 4 17220 _002560_hash NULL
85579 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
85580 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
85581 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
85582 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
85583 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
85584 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
85585 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
85586 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
85587 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
85588 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
85589 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
85590 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
85591 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
85592 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
85593 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
85594 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
85595 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
85596 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
85597 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
85598 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
85599 +_002584_hash fb_read 3 33506 _002584_hash NULL
85600 +_002585_hash fb_write 3 46924 _002585_hash NULL
85601 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
85602 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
85603 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
85604 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
85605 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
85606 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
85607 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
85608 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
85609 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
85610 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
85611 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
85612 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
85613 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
85614 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
85615 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
85616 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
85617 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
85618 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
85619 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
85620 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
85621 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
85622 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
85623 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
85624 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
85625 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
85626 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
85627 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
85628 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
85629 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
85630 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
85631 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
85632 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
85633 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
85634 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
85635 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
85636 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
85637 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
85638 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
85639 +_002626_hash create_table 2 16213 _002626_hash NULL
85640 +_002627_hash mem_read 3 57631 _002627_hash NULL
85641 +_002628_hash mem_write 3 22232 _002628_hash NULL
85642 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
85643 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
85644 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
85645 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
85646 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
85647 +_002634_hash alloc_dummy_extent_buffer 2 56374 _002634_hash NULL
85648 +_002635_hash alloc_fdtable 1 17389 _002635_hash NULL
85649 +_002636_hash alloc_large_system_hash 2 22391 _002636_hash NULL
85650 +_002637_hash alloc_ldt 2 21972 _002637_hash NULL
85651 +_002638_hash __alloc_skb 1 23940 _002638_hash NULL
85652 +_002639_hash __ata_change_queue_depth 3 23484 _002639_hash NULL
85653 +_002640_hash btrfs_alloc_free_block 3 8986 _002640_hash NULL
85654 +_002641_hash btrfs_find_device_for_logical 2 44993 _002641_hash NULL
85655 +_002642_hash ccid3_hc_rx_getsockopt 3 62331 _002642_hash NULL
85656 +_002643_hash ccid3_hc_tx_getsockopt 3 16314 _002643_hash NULL
85657 +_002644_hash cifs_readdata_alloc 1 26360 _002644_hash NULL
85658 +_002645_hash cistpl_vers_1 4 15023 _002645_hash NULL
85659 +_002646_hash cmm_read 3 57520 _002646_hash NULL
85660 +_002647_hash cosa_read 3 25966 _002647_hash NULL
85661 +_002648_hash dm_table_create 3 35687 _002648_hash NULL
85662 +_002649_hash dpcm_state_read_file 3 65489 _002649_hash NULL
85663 +_002651_hash edac_mc_alloc 4 3611 _002651_hash NULL
85664 +_002652_hash ep0_read 3 38095 _002652_hash NULL
85665 +_002653_hash event_buffer_read 3 48772 _002765_hash NULL nohasharray
85666 +_002654_hash extend_netdev_table 2 21453 _002654_hash NULL
85667 +_002655_hash extract_entropy_user 3 26952 _002655_hash NULL
85668 +_002656_hash fcoe_ctlr_device_add 3 1793 _002656_hash NULL
85669 +_002657_hash fd_do_readv 3 51297 _002657_hash NULL
85670 +_002658_hash fd_do_writev 3 29329 _002658_hash NULL
85671 +_002659_hash ffs_ep0_read 3 2672 _002659_hash NULL
85672 +_002660_hash fill_readbuf 3 32464 _002660_hash NULL
85673 +_002661_hash fw_iso_buffer_alloc 2 13704 _002661_hash NULL
85674 +_002662_hash get_fd_set 1 3866 _002662_hash NULL
85675 +_002663_hash hidraw_report_event 3 20503 _002663_hash NULL
85676 +_002664_hash ieee80211_if_read_ht_opmode 3 29044 _002664_hash NULL
85677 +_002665_hash ieee80211_if_read_num_mcast_sta 3 12419 _002665_hash NULL
85678 +_002666_hash iwl_dbgfs_calib_disabled_read 3 22649 _002666_hash NULL
85679 +_002667_hash iwl_dbgfs_rf_reset_read 3 26512 _002667_hash NULL
85680 +_002668_hash ixgbe_alloc_q_vector 4-6 24439 _002668_hash NULL
85681 +_002670_hash joydev_handle_JSIOCSAXMAP 3 48898 _002836_hash NULL nohasharray
85682 +_002671_hash joydev_handle_JSIOCSBTNMAP 3 15643 _002671_hash NULL
85683 +_002672_hash __kfifo_from_user_r 3 60345 _002672_hash NULL
85684 +_002673_hash kstrtoint_from_user 2 8778 _002673_hash NULL
85685 +_002674_hash kstrtol_from_user 2 10168 _002674_hash NULL
85686 +_002675_hash kstrtoll_from_user 2 19500 _002675_hash NULL
85687 +_002676_hash kstrtos16_from_user 2 28300 _002676_hash NULL
85688 +_002677_hash kstrtos8_from_user 2 58268 _002677_hash NULL
85689 +_002678_hash kstrtou16_from_user 2 54274 _002678_hash NULL
85690 +_002679_hash kstrtou8_from_user 2 55599 _002679_hash NULL
85691 +_002680_hash kstrtouint_from_user 2 10536 _002680_hash NULL
85692 +_002681_hash kstrtoul_from_user 2 64569 _002681_hash NULL
85693 +_002682_hash kstrtoull_from_user 2 63026 _002682_hash NULL
85694 +_002683_hash l2cap_create_iframe_pdu 3 40055 _002683_hash NULL
85695 +_002684_hash l2tp_ip6_recvmsg 4 62874 _002684_hash NULL
85696 +_002685_hash mem_cgroup_read 5 22461 _002685_hash NULL
85697 +_002686_hash nfs_fscache_get_super_cookie 3 44355 _002686_hash &_001648_hash
85698 +_002687_hash nfs_pgarray_set 2 1085 _002687_hash NULL
85699 +_002688_hash ntfs_rl_realloc 3 56831 _002688_hash &_000363_hash
85700 +_002689_hash ntfs_rl_realloc_nofail 3 32173 _002689_hash NULL
85701 +_002690_hash pn533_dep_link_up 5 22154 _002690_hash NULL
85702 +_002691_hash port_fops_write 3 54627 _002691_hash NULL
85703 +_002692_hash ptp_read 4 63251 _002692_hash NULL
85704 +_002693_hash qla4xxx_change_queue_depth 2 1268 _002693_hash NULL
85705 +_002694_hash reqsk_queue_alloc 2 40272 _002694_hash NULL
85706 +_002695_hash resize_info_buffer 2 62889 _002695_hash NULL
85707 +_002696_hash rfkill_fop_write 3 64808 _002696_hash NULL
85708 +_002697_hash rt2x00debug_write_rfcsr 3 41473 _002697_hash NULL
85709 +_002698_hash rvmalloc 1 46873 _002698_hash NULL
85710 +_002699_hash rw_copy_check_uvector 3 45748 _002699_hash NULL
85711 +_002700_hash sctp_getsockopt_active_key 2 45483 _002700_hash NULL
85712 +_002701_hash sctp_getsockopt_adaptation_layer 2 45375 _002701_hash NULL
85713 +_002702_hash sctp_getsockopt_assoc_ids 2 9043 _002702_hash NULL
85714 +_002703_hash sctp_getsockopt_associnfo 2 58169 _002703_hash NULL
85715 +_002704_hash sctp_getsockopt_assoc_number 2 6384 _002704_hash NULL
85716 +_002705_hash sctp_getsockopt_auto_asconf 2 46584 _002705_hash NULL
85717 +_002706_hash sctp_getsockopt_context 2 52490 _002706_hash NULL
85718 +_002707_hash sctp_getsockopt_default_send_param 2 63056 _002707_hash NULL
85719 +_002708_hash sctp_getsockopt_disable_fragments 2 12330 _002708_hash NULL
85720 +_002709_hash sctp_getsockopt_fragment_interleave 2 51215 _002709_hash NULL
85721 +_002710_hash sctp_getsockopt_initmsg 2 26042 _002710_hash NULL
85722 +_002711_hash sctp_getsockopt_mappedv4 2 20044 _002711_hash NULL
85723 +_002712_hash sctp_getsockopt_nodelay 2 9560 _002712_hash NULL
85724 +_002713_hash sctp_getsockopt_partial_delivery_point 2 60952 _002713_hash NULL
85725 +_002714_hash sctp_getsockopt_peeloff 2 59190 _002714_hash NULL
85726 +_002715_hash sctp_getsockopt_peer_addr_info 2 6024 _002715_hash NULL
85727 +_002716_hash sctp_getsockopt_peer_addr_params 2 53645 _002716_hash NULL
85728 +_002717_hash sctp_getsockopt_primary_addr 2 24639 _002717_hash NULL
85729 +_002718_hash sctp_getsockopt_rtoinfo 2 62027 _002718_hash NULL
85730 +_002719_hash sctp_getsockopt_sctp_status 2 56540 _002719_hash NULL
85731 +_002720_hash self_check_write 5 50856 _002720_hash NULL
85732 +_002721_hash smk_read_mapped 3 7562 _002721_hash NULL
85733 +_002722_hash smk_set_cipso 3 20379 _002722_hash NULL
85734 +_002723_hash smk_user_access 3 24440 _002723_hash NULL
85735 +_002724_hash smk_write_mapped 3 13519 _002724_hash NULL
85736 +_002725_hash smk_write_rules_list 3 18565 _002725_hash NULL
85737 +_002726_hash snd_mixart_BA0_read 5 45069 _002726_hash NULL
85738 +_002727_hash snd_mixart_BA1_read 5 5082 _002727_hash NULL
85739 +_002728_hash snd_pcm_oss_read2 3 54387 _002728_hash NULL
85740 +_002729_hash syslog_print 2 307 _002729_hash NULL
85741 +_002730_hash tcp_dma_try_early_copy 3 4457 _002730_hash NULL
85742 +_002731_hash tcp_send_rcvq 3 11316 _002731_hash NULL
85743 +_002732_hash tomoyo_init_log 2 61526 _002732_hash NULL
85744 +_002733_hash ubi_dump_flash 4 46381 _002733_hash NULL
85745 +_002734_hash ubi_eba_atomic_leb_change 5 60379 _002734_hash NULL
85746 +_002735_hash ubi_eba_write_leb 5-6 36029 _002735_hash NULL
85747 +_002737_hash ubi_eba_write_leb_st 5 44343 _002737_hash NULL
85748 +_002738_hash ubi_self_check_all_ff 4 41959 _002738_hash NULL
85749 +_002739_hash unix_bind 3 15668 _002739_hash NULL
85750 +_002740_hash usbvision_rvmalloc 1 19655 _002740_hash NULL
85751 +_002742_hash v4l2_ctrl_new 7 24927 _002742_hash NULL
85752 +_002743_hash v4l2_event_subscribe 3 53687 _002743_hash NULL
85753 +_002744_hash v9fs_direct_read 3 45546 _002744_hash NULL
85754 +_002745_hash v9fs_file_readn 4 36353 _002745_hash &_001606_hash
85755 +_002746_hash __videobuf_alloc_vb 1 5665 _002746_hash NULL
85756 +_002747_hash wm8350_write 3 24480 _002747_hash NULL
85757 +_002748_hash xfs_buf_read_uncached 3 42844 _002748_hash NULL
85758 +_002749_hash yurex_write 3 8761 _002749_hash NULL
85759 +_002750_hash alloc_skb 1 55439 _002750_hash NULL
85760 +_002751_hash alloc_skb_fclone 1 3467 _002751_hash NULL
85761 +_002752_hash ata_scsi_change_queue_depth 2 23126 _002752_hash NULL
85762 +_002753_hash ath6kl_disconnect_timeout_write 3 794 _002753_hash NULL
85763 +_002754_hash ath6kl_keepalive_write 3 45600 _002754_hash NULL
85764 +_002755_hash ath6kl_lrssi_roam_write 3 8362 _002755_hash NULL
85765 +_002756_hash ath6kl_regread_write 3 14220 _002756_hash NULL
85766 +_002757_hash core_sys_select 1 47494 _002757_hash NULL
85767 +_002758_hash do_syslog 3 56807 _002758_hash NULL
85768 +_002759_hash expand_fdtable 2 39273 _002759_hash NULL
85769 +_002760_hash fd_execute_cmd 3 1132 _002760_hash NULL
85770 +_002761_hash get_chars 3 40373 _002761_hash NULL
85771 +_002762_hash hid_report_raw_event 4 2762 _002762_hash NULL
85772 +_002763_hash inet_csk_listen_start 2 38233 _002763_hash NULL
85773 +_002764_hash kstrtou32_from_user 2 30361 _002764_hash NULL
85774 +_002765_hash l2cap_segment_sdu 4 48772 _002765_hash &_002653_hash
85775 +_002766_hash __netdev_alloc_skb 2 18595 _002766_hash NULL
85776 +_002767_hash nfs_readdata_alloc 2 65015 _002767_hash NULL
85777 +_002768_hash nfs_writedata_alloc 2 12133 _002768_hash NULL
85778 +_002769_hash ntfs_rl_append 2-4 6037 _002769_hash NULL
85779 +_002771_hash ntfs_rl_insert 2-4 4931 _002771_hash NULL
85780 +_002773_hash ntfs_rl_replace 2-4 14136 _002773_hash NULL
85781 +_002775_hash ntfs_rl_split 2-4 52328 _002775_hash NULL
85782 +_002777_hash port_fops_read 3 49626 _002777_hash NULL
85783 +_002778_hash random_read 3 13815 _002778_hash NULL
85784 +_002779_hash sg_proc_write_adio 3 45704 _002779_hash NULL
85785 +_002780_hash sg_proc_write_dressz 3 46316 _002780_hash NULL
85786 +_002781_hash tcp_sendmsg 4 30296 _002781_hash NULL
85787 +_002782_hash tomoyo_write_log2 2 34318 _002782_hash NULL
85788 +_002783_hash ubi_leb_change 4 10289 _002783_hash NULL
85789 +_002784_hash ubi_leb_write 4-5 5478 _002784_hash NULL
85790 +_002786_hash urandom_read 3 30462 _002786_hash NULL
85791 +_002787_hash v9fs_cached_file_read 3 2514 _002787_hash NULL
85792 +_002788_hash __videobuf_alloc_cached 1 12740 _002788_hash NULL
85793 +_002789_hash __videobuf_alloc_uncached 1 55711 _002789_hash NULL
85794 +_002790_hash wm8350_block_write 3 19727 _002790_hash NULL
85795 +_002791_hash alloc_tx 2 32143 _002791_hash NULL
85796 +_002792_hash alloc_wr 1-2 24635 _002792_hash NULL
85797 +_002794_hash ath6kl_endpoint_stats_write 3 59621 _002794_hash NULL
85798 +_002795_hash ath6kl_fwlog_mask_write 3 24810 _002795_hash NULL
85799 +_002796_hash ath9k_wmi_cmd 4 327 _002796_hash NULL
85800 +_002797_hash atm_alloc_charge 2 19517 _002879_hash NULL nohasharray
85801 +_002798_hash ax25_output 2 22736 _002798_hash NULL
85802 +_002799_hash bcsp_prepare_pkt 3 12961 _002799_hash NULL
85803 +_002800_hash bt_skb_alloc 1 6404 _002800_hash NULL
85804 +_002801_hash capinc_tty_write 3 28539 _002801_hash NULL
85805 +_002802_hash cfpkt_create_pfx 1-2 23594 _002802_hash NULL
85806 +_002804_hash cmd_complete 6 51629 _002804_hash NULL
85807 +_002805_hash cmtp_add_msgpart 4 9252 _002805_hash NULL
85808 +_002806_hash cmtp_send_interopmsg 7 376 _002806_hash NULL
85809 +_002807_hash cxgb3_get_cpl_reply_skb 2 10620 _002807_hash NULL
85810 +_002808_hash dbg_leb_change 4 23555 _002808_hash NULL
85811 +_002809_hash dbg_leb_write 4-5 63555 _002809_hash &_000940_hash
85812 +_002811_hash dccp_listen_start 2 35918 _002811_hash NULL
85813 +_002812_hash __dev_alloc_skb 1 28681 _002812_hash NULL
85814 +_002813_hash diva_os_alloc_message_buffer 1 64568 _002813_hash NULL
85815 +_002814_hash dn_alloc_skb 2 6631 _002814_hash NULL
85816 +_002815_hash do_pselect 1 62061 _002815_hash NULL
85817 +_002816_hash _fc_frame_alloc 1 43568 _002816_hash NULL
85818 +_002817_hash find_skb 2 20431 _002817_hash NULL
85819 +_002818_hash fm_send_cmd 5 39639 _002818_hash NULL
85820 +_002819_hash gem_alloc_skb 2 51715 _002819_hash NULL
85821 +_002820_hash get_packet 3 41914 _002820_hash NULL
85822 +_002821_hash get_packet 3 5747 _002821_hash NULL
85823 +_002822_hash get_packet_pg 4 28023 _002822_hash NULL
85824 +_002823_hash get_skb 2 63008 _002823_hash NULL
85825 +_002824_hash hidp_queue_report 3 1881 _002824_hash NULL
85826 +_002825_hash __hidp_send_ctrl_message 4 28303 _002825_hash NULL
85827 +_002826_hash hycapi_rx_capipkt 3 11602 _002826_hash NULL
85828 +_002827_hash i2400m_net_rx 5 27170 _002827_hash NULL
85829 +_002828_hash igmpv3_newpack 2 35912 _002828_hash NULL
85830 +_002829_hash inet_listen 2 14723 _002829_hash NULL
85831 +_002830_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _002830_hash &_001724_hash
85832 +_002831_hash isdn_ppp_ccp_xmit_reset 6 63297 _002831_hash NULL
85833 +_002832_hash kmsg_read 3 46514 _002832_hash NULL
85834 +_002833_hash _l2_alloc_skb 1 11883 _002833_hash NULL
85835 +_002834_hash l3_alloc_skb 1 32289 _002834_hash NULL
85836 +_002835_hash llc_alloc_frame 4 64366 _002835_hash NULL
85837 +_002836_hash mac_drv_rx_init 2 48898 _002836_hash &_002670_hash
85838 +_002837_hash mgmt_event 4 12810 _002837_hash NULL
85839 +_002838_hash mI_alloc_skb 1 24770 _002838_hash NULL
85840 +_002839_hash nci_skb_alloc 2 49757 _002839_hash NULL
85841 +_002840_hash netdev_alloc_skb 2 62437 _002840_hash NULL
85842 +_002841_hash __netdev_alloc_skb_ip_align 2 55067 _002841_hash NULL
85843 +_002842_hash new_skb 1 21148 _002842_hash NULL
85844 +_002843_hash nfc_alloc_recv_skb 1 10244 _002843_hash NULL
85845 +_002844_hash nfcwilink_skb_alloc 1 16167 _002844_hash NULL
85846 +_002845_hash nfulnl_alloc_skb 2 65207 _002845_hash NULL
85847 +_002846_hash ni65_alloc_mem 3 10664 _002846_hash NULL
85848 +_002847_hash pep_alloc_skb 3 46303 _002847_hash NULL
85849 +_002848_hash pn_raw_send 2 54330 _002848_hash NULL
85850 +_002849_hash __pskb_copy 2 9038 _002849_hash NULL
85851 +_002850_hash refill_pool 2 19477 _002850_hash NULL
85852 +_002851_hash rfcomm_wmalloc 2 58090 _002851_hash NULL
85853 +_002852_hash rx 4 57944 _002852_hash NULL
85854 +_002853_hash sctp_ulpevent_new 1 33377 _002853_hash NULL
85855 +_002854_hash send_command 4 10832 _002854_hash NULL
85856 +_002855_hash skb_copy_expand 2-3 7685 _002855_hash &_000671_hash
85857 +_002857_hash sk_stream_alloc_skb 2 57622 _002857_hash NULL
85858 +_002858_hash sock_alloc_send_pskb 2 21246 _002858_hash NULL
85859 +_002859_hash sock_rmalloc 2 59740 _002859_hash &_002157_hash
85860 +_002860_hash sock_wmalloc 2 16472 _002860_hash NULL
85861 +_002861_hash solos_param_store 4 34755 _002861_hash NULL
85862 +_002862_hash sys_select 1 38827 _002862_hash NULL
85863 +_002863_hash sys_syslog 3 10746 _002863_hash NULL
85864 +_002864_hash t4vf_pktgl_to_skb 2 39005 _002864_hash NULL
85865 +_002865_hash tcp_collapse 5-6 63294 _002865_hash NULL
85866 +_002867_hash tipc_cfg_reply_alloc 1 27606 _002867_hash NULL
85867 +_002868_hash ubifs_leb_change 4 17789 _002868_hash NULL
85868 +_002869_hash ubifs_leb_write 4-5 22679 _002869_hash NULL
85869 +_002871_hash ulog_alloc_skb 1 23427 _002871_hash NULL
85870 +_002872_hash _alloc_mISDN_skb 3 52232 _002872_hash NULL
85871 +_002873_hash ath9k_multi_regread 4 65056 _002873_hash NULL
85872 +_002874_hash ath_rxbuf_alloc 2 24745 _002874_hash NULL
85873 +_002875_hash ax25_send_frame 2 19964 _002875_hash NULL
85874 +_002876_hash bchannel_get_rxbuf 2 37213 _002876_hash NULL
85875 +_002877_hash cfpkt_create 1 18197 _002877_hash NULL
85876 +_002878_hash console_store 4 36007 _002878_hash NULL
85877 +_002879_hash dev_alloc_skb 1 19517 _002879_hash &_002797_hash
85878 +_002880_hash dn_nsp_do_disc 2-6 49474 _002880_hash NULL
85879 +_002882_hash do_write_orph_node 2 64343 _002882_hash NULL
85880 +_002883_hash dsp_cmx_send_member 2 15625 _002883_hash NULL
85881 +_002884_hash fc_frame_alloc 2 1596 _002884_hash NULL
85882 +_002885_hash fc_frame_alloc_fill 2 59394 _002885_hash NULL
85883 +_002886_hash fmc_send_cmd 5 20435 _002886_hash NULL
85884 +_002887_hash hci_send_cmd 3 43810 _002887_hash NULL
85885 +_002888_hash hci_si_event 3 1404 _002888_hash NULL
85886 +_002889_hash hfcpci_empty_bfifo 4 62323 _002889_hash NULL
85887 +_002890_hash hidp_send_ctrl_message 4 43702 _002890_hash NULL
85888 +_002891_hash hysdn_sched_rx 3 60533 _002891_hash NULL
85889 +_002892_hash inet_dccp_listen 2 28565 _002892_hash NULL
85890 +_002893_hash ip6_append_data 4-5 36490 _002893_hash NULL
85891 +_002894_hash __ip_append_data 7-8 36191 _002894_hash NULL
85892 +_002895_hash l1oip_socket_recv 6 56537 _002895_hash NULL
85893 +_002896_hash l2cap_build_cmd 4 48676 _002896_hash NULL
85894 +_002897_hash l2down_create 4 21755 _002897_hash NULL
85895 +_002898_hash l2up_create 3 6430 _002898_hash NULL
85896 +_002899_hash ldisc_receive 4 41516 _002899_hash NULL
85897 +_002902_hash lro_gen_skb 6 2644 _002902_hash NULL
85898 +_002903_hash macvtap_alloc_skb 2-4-3 50629 _002903_hash NULL
85899 +_002906_hash mgmt_device_found 10 14146 _002906_hash NULL
85900 +_002907_hash nci_send_cmd 3 58206 _002907_hash NULL
85901 +_002908_hash netdev_alloc_skb_ip_align 2 40811 _002908_hash NULL
85902 +_002909_hash nfcwilink_send_bts_cmd 3 10802 _002909_hash NULL
85903 +_002910_hash nfqnl_mangle 2 14583 _002910_hash NULL
85904 +_002911_hash p54_alloc_skb 3 34366 _002911_hash &_000475_hash
85905 +_002912_hash packet_alloc_skb 2-5-4 62602 _002912_hash NULL
85906 +_002915_hash pep_indicate 5 38611 _002915_hash NULL
85907 +_002916_hash pep_reply 5 50582 _002916_hash NULL
85908 +_002917_hash pipe_handler_request 5 50774 _002917_hash &_001189_hash
85909 +_002918_hash ql_process_mac_rx_page 4 15543 _002918_hash NULL
85910 +_002919_hash ql_process_mac_rx_skb 4 6689 _002919_hash NULL
85911 +_002920_hash rfcomm_tty_write 3 51603 _002920_hash NULL
85912 +_002921_hash send_mpa_reject 3 7135 _002921_hash NULL
85913 +_002922_hash send_mpa_reply 3 32372 _002922_hash NULL
85914 +_002923_hash set_rxd_buffer_pointer 8 9950 _002923_hash NULL
85915 +_002924_hash sge_rx 3 50594 _002924_hash NULL
85916 +_002925_hash skb_cow_data 2 11565 _002925_hash NULL
85917 +_002926_hash smp_build_cmd 3 45853 _002926_hash NULL
85918 +_002927_hash sock_alloc_send_skb 2 23720 _002927_hash NULL
85919 +_002928_hash sys_pselect6 1 57449 _002928_hash NULL
85920 +_002929_hash tcp_fragment 3 20436 _002929_hash NULL
85921 +_002930_hash teiup_create 3 43201 _002930_hash NULL
85922 +_002931_hash tg3_run_loopback 2 30093 _002931_hash NULL
85923 +_002932_hash tun_alloc_skb 2-4-3 41216 _002932_hash NULL
85924 +_002935_hash ubifs_write_node 5 11258 _002935_hash NULL
85925 +_002936_hash use_pool 2 64607 _002936_hash NULL
85926 +_002937_hash vxge_rx_alloc 3 52024 _002937_hash NULL
85927 +_002938_hash add_packet 3 54433 _002938_hash NULL
85928 +_002939_hash add_rx_skb 3 8257 _002939_hash NULL
85929 +_002940_hash ath6kl_buf_alloc 1 57304 _002940_hash NULL
85930 +_002941_hash bat_iv_ogm_aggregate_new 2 2620 _002941_hash NULL
85931 +_002942_hash bnx2fc_process_l2_frame_compl 3 65072 _002942_hash NULL
85932 +_002943_hash brcmu_pkt_buf_get_skb 1 5556 _002943_hash NULL
85933 +_002944_hash br_send_bpdu 3 29669 _002944_hash NULL
85934 +_002945_hash bt_skb_send_alloc 2 6581 _002945_hash NULL
85935 +_002946_hash c4iw_reject_cr 3 28174 _002946_hash NULL
85936 +_002947_hash carl9170_rx_copy_data 2 21656 _002947_hash NULL
85937 +_002948_hash cfpkt_add_body 3 44630 _002948_hash NULL
85938 +_002949_hash cfpkt_append 3 61206 _002949_hash NULL
85939 +_002950_hash cosa_net_setup_rx 2 38594 _002950_hash NULL
85940 +_002951_hash cxgb4_pktgl_to_skb 2 61899 _002951_hash NULL
85941 +_002952_hash dn_alloc_send_pskb 2 4465 _002952_hash NULL
85942 +_002953_hash dn_nsp_return_disc 2 60296 _002953_hash NULL
85943 +_002954_hash dn_nsp_send_disc 2 23469 _002954_hash NULL
85944 +_002955_hash dsp_tone_hw_message 3 17678 _002955_hash NULL
85945 +_002956_hash dvb_net_sec 3 37884 _002956_hash NULL
85946 +_002957_hash e1000_check_copybreak 3 62448 _002957_hash NULL
85947 +_002958_hash fast_rx_path 3 59214 _002958_hash NULL
85948 +_002959_hash fc_fcp_frame_alloc 2 12624 _002959_hash NULL
85949 +_002960_hash fcoe_ctlr_send_keep_alive 3 15308 _002960_hash NULL
85950 +_002961_hash fwnet_incoming_packet 3 40380 _002961_hash NULL
85951 +_002962_hash fwnet_pd_new 4 39947 _002962_hash NULL
85952 +_002963_hash got_frame 2 16028 _002963_hash NULL
85953 +_002964_hash gsm_mux_rx_netchar 3 33336 _002964_hash NULL
85954 +_002965_hash hdlcdev_rx 3 997 _002965_hash NULL
85955 +_002966_hash hdlc_empty_fifo 2 18397 _002966_hash NULL
85956 +_002967_hash hfc_empty_fifo 2 57972 _002967_hash NULL
85957 +_002968_hash hfcpci_empty_fifo 4 2427 _002968_hash NULL
85958 +_002969_hash hfcsusb_rx_frame 3 52745 _002969_hash NULL
85959 +_002970_hash hidp_output_raw_report 3 5629 _002970_hash NULL
85960 +_002971_hash hscx_empty_fifo 2 13360 _002971_hash NULL
85961 +_002972_hash hysdn_rx_netpkt 3 16136 _002972_hash NULL
85962 +_002973_hash ieee80211_fragment 4 33112 _002973_hash NULL
85963 +_002974_hash ieee80211_probereq_get 4-6 29069 _002974_hash NULL
85964 +_002976_hash ieee80211_send_auth 5 24121 _002976_hash NULL
85965 +_002977_hash ieee80211_set_probe_resp 3 10077 _002977_hash NULL
85966 +_002978_hash ieee80211_tdls_mgmt 8 9581 _002978_hash NULL
85967 +_002979_hash ip6_ufo_append_data 5-7-6 4780 _002979_hash NULL
85968 +_002982_hash ip_ufo_append_data 6-8-7 12775 _002982_hash NULL
85969 +_002985_hash ipw_packet_received_skb 2 1230 _002985_hash NULL
85970 +_002986_hash iwch_reject_cr 3 23901 _002986_hash NULL
85971 +_002987_hash iwm_rx_packet_alloc 3 9898 _002987_hash NULL
85972 +_002988_hash ixgb_check_copybreak 3 5847 _002988_hash NULL
85973 +_002989_hash l1oip_socket_parse 4 4507 _002989_hash NULL
85974 +_002990_hash l2cap_send_cmd 4 14548 _002990_hash NULL
85975 +_002991_hash l2tp_ip6_sendmsg 4 7461 _002991_hash NULL
85976 +_002993_hash lowpan_fragment_xmit 3-4 22095 _002993_hash NULL
85977 +_002996_hash mcs_unwrap_fir 3 25733 _002996_hash NULL
85978 +_002997_hash mcs_unwrap_mir 3 9455 _002997_hash NULL
85979 +_002998_hash mld_newpack 2 50950 _002998_hash NULL
85980 +_002999_hash nfc_alloc_send_skb 4 3167 _002999_hash NULL
85981 +_003000_hash p54_download_eeprom 4 43842 _003000_hash NULL
85982 +_003002_hash ppp_tx_cp 5 62044 _003002_hash NULL
85983 +_003003_hash prism2_send_mgmt 4 62605 _003003_hash &_001876_hash
85984 +_003004_hash prism2_sta_send_mgmt 5 43916 _003004_hash NULL
85985 +_003005_hash _queue_data 4 54983 _003005_hash NULL
85986 +_003006_hash read_dma 3 55086 _003006_hash NULL
85987 +_003007_hash read_fifo 3 826 _003007_hash NULL
85988 +_003008_hash receive_copy 3 12216 _003008_hash NULL
85989 +_003009_hash rtl8169_try_rx_copy 3 705 _003009_hash NULL
85990 +_003010_hash _rtl92s_firmware_downloadcode 3 14021 _003010_hash NULL
85991 +_003011_hash rx_data 4 60442 _003011_hash NULL
85992 +_003012_hash sis190_try_rx_copy 3 57069 _003012_hash NULL
85993 +_003013_hash skge_rx_get 3 40598 _003013_hash NULL
85994 +_003014_hash tcp_mark_head_lost 2 35895 _003014_hash NULL
85995 +_003015_hash tcp_match_skb_to_sack 3-4 23568 _003015_hash NULL
85996 +_003017_hash tso_fragment 3 29050 _003017_hash NULL
85997 +_003018_hash tt_response_fill_table 1 57902 _003018_hash NULL
85998 +_003020_hash udpv6_sendmsg 4 22316 _003020_hash NULL
85999 +_003021_hash velocity_rx_copy 2 34583 _003021_hash NULL
86000 +_003022_hash W6692_empty_Bfifo 2 47804 _003022_hash NULL
86001 +_003023_hash zd_mac_rx 3 38296 _003023_hash NULL
86002 +_003024_hash ath6kl_wmi_get_new_buf 1 52304 _003024_hash NULL
86003 +_003025_hash bat_iv_ogm_queue_add 3 30870 _003025_hash NULL
86004 +_003026_hash brcmf_alloc_pkt_and_read 2 63116 _003026_hash &_001808_hash
86005 +_003027_hash brcmf_sdcard_recv_buf 6 38179 _003027_hash NULL
86006 +_003028_hash brcmf_sdcard_rwdata 5 65041 _003028_hash NULL
86007 +_003029_hash brcmf_sdcard_send_buf 6 7713 _003029_hash NULL
86008 +_003030_hash carl9170_handle_mpdu 3 11056 _003030_hash NULL
86009 +_003031_hash cfpkt_add_trail 3 27260 _003031_hash NULL
86010 +_003032_hash cfpkt_pad_trail 2 55511 _003032_hash NULL
86011 +_003033_hash dvb_net_sec_callback 2 28786 _003033_hash NULL
86012 +_003034_hash fwnet_receive_packet 9 50537 _003034_hash NULL
86013 +_003035_hash handle_rx_packet 3 58993 _003035_hash NULL
86014 +_003036_hash HDLC_irq 2 8709 _003036_hash NULL
86015 +_003037_hash hdlc_rpr_irq 2 10240 _003037_hash NULL
86016 +_003043_hash ipwireless_network_packet_received 4 51277 _003043_hash NULL
86017 +_003044_hash l2cap_bredr_sig_cmd 3 49065 _003044_hash NULL
86018 +_003045_hash l2cap_sock_alloc_skb_cb 2 33532 _003045_hash NULL
86019 +_003046_hash llcp_allocate_pdu 3 19866 _003046_hash NULL
86020 +_003047_hash ppp_cp_event 6 2965 _003047_hash NULL
86021 +_003048_hash receive_client_update_packet 3 49104 _003048_hash NULL
86022 +_003049_hash receive_server_sync_packet 3 59021 _003049_hash NULL
86023 +_003050_hash sky2_receive 2 13407 _003050_hash NULL
86024 +_003051_hash tcp_sacktag_walk 5-6 49703 _003051_hash NULL
86025 +_003053_hash tcp_write_xmit 2 64602 _003053_hash NULL
86026 +_003054_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _003054_hash NULL
86027 +_003055_hash ath6kl_wmi_beginscan_cmd 8 25462 _003055_hash NULL
86028 +_003056_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _003056_hash NULL
86029 +_003057_hash ath6kl_wmi_set_appie_cmd 5 39266 _003057_hash NULL
86030 +_003058_hash ath6kl_wmi_set_ie_cmd 6 37260 _003058_hash NULL
86031 +_003059_hash ath6kl_wmi_startscan_cmd 8 33674 _003059_hash NULL
86032 +_003060_hash ath6kl_wmi_test_cmd 3 27312 _003060_hash NULL
86033 +_003061_hash brcmf_sdbrcm_membytes 3-5 37324 _003061_hash NULL
86034 +_003063_hash brcmf_sdbrcm_read_control 3 22721 _003063_hash NULL
86035 +_003064_hash brcmf_tx_frame 3 20978 _003064_hash NULL
86036 +_003065_hash __carl9170_rx 3 56784 _003065_hash NULL
86037 +_003066_hash cfpkt_setlen 2 49343 _003066_hash NULL
86038 +_003067_hash hdlc_irq_one 2 3944 _003067_hash NULL
86039 +_003069_hash tcp_push_one 2 48816 _003069_hash NULL
86040 +_003070_hash __tcp_push_pending_frames 2 48148 _003070_hash NULL
86041 +_003071_hash brcmf_sdbrcm_bus_txctl 3 42492 _003071_hash NULL
86042 +_003072_hash carl9170_rx 3 13272 _003072_hash NULL
86043 +_003073_hash carl9170_rx_stream 3 1334 _003073_hash NULL
86044 +_003074_hash tcp_push 3 10680 _003074_hash NULL
86045 +_003075_hash create_log 2 8225 _003075_hash NULL
86046 +_003076_hash expand_files 2 17080 _003076_hash NULL
86047 +_003077_hash iio_device_alloc 1 41440 _003077_hash NULL
86048 +_003078_hash OS_mem_token_alloc 1 14276 _003078_hash NULL
86049 +_003079_hash packet_came 3 18072 _003079_hash NULL
86050 +_003080_hash softsynth_write 3 3455 _003080_hash NULL
86051 +_003081_hash alloc_fd 1 37637 _003081_hash NULL
86052 +_003082_hash sys_dup3 2 33421 _003082_hash NULL
86053 +_003083_hash do_fcntl 3 31468 _003083_hash NULL
86054 +_003084_hash sys_dup2 2 25284 _003084_hash NULL
86055 +_003085_hash sys_fcntl 3 19267 _003085_hash NULL
86056 +_003086_hash sys_fcntl64 3 29031 _003086_hash NULL
86057 +_003087_hash cmpk_message_handle_tx 4 54024 _003087_hash NULL
86058 +_003088_hash comedi_buf_alloc 3 24822 _003088_hash NULL
86059 +_003089_hash compat_rw_copy_check_uvector 3 22001 _003089_hash &_001989_hash
86060 +_003090_hash compat_sys_fcntl64 3 60256 _003090_hash NULL
86061 +_003091_hash evtchn_write 3 43278 _003091_hash NULL
86062 +_003092_hash fw_download_code 3 13249 _003092_hash NULL
86063 +_003093_hash fwSendNullPacket 2 54618 _003093_hash NULL
86064 +_003095_hash ieee80211_authentication_req 3 63973 _003095_hash NULL
86065 +_003097_hash rtllib_authentication_req 3 26713 _003097_hash NULL
86066 +_003098_hash SendTxCommandPacket 3 42901 _003098_hash NULL
86067 +_003099_hash snd_nm256_capture_copy 5 28622 _003099_hash NULL
86068 +_003100_hash snd_nm256_playback_copy 5 38567 _003100_hash NULL
86069 +_003101_hash tomoyo_init_log 2 14806 _003101_hash NULL
86070 +_003102_hash usbdux_attach_common 4 51764 _003271_hash NULL nohasharray
86071 +_003103_hash compat_sys_fcntl 3 15654 _003103_hash NULL
86072 +_003104_hash ieee80211_auth_challenge 3 18810 _003104_hash NULL
86073 +_003105_hash ieee80211_rtl_auth_challenge 3 61897 _003105_hash NULL
86074 +_003106_hash resize_async_buffer 4 64031 _003106_hash &_002119_hash
86075 +_003107_hash rtllib_auth_challenge 3 12493 _003107_hash NULL
86076 +_003108_hash tomoyo_write_log2 2 11732 _003108_hash NULL
86077 +_003109_hash allocate_probes 1 40204 _003109_hash NULL
86078 +_003110_hash alloc_ftrace_hash 1 57431 _003110_hash &_002532_hash
86079 +_003111_hash __alloc_preds 2 9492 _003111_hash NULL
86080 +_003112_hash __alloc_pred_stack 2 26687 _003112_hash NULL
86081 +_003113_hash alloc_sched_domains 1 47756 _003113_hash NULL
86082 +_003114_hash alloc_trace_probe 6 38720 _003114_hash NULL
86083 +_003115_hash alloc_trace_uprobe 3 13870 _003115_hash NULL
86084 +_003116_hash arcfb_write 3 8702 _003116_hash NULL
86085 +_003117_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003117_hash NULL
86086 +_003118_hash ath6kl_usb_post_recv_transfers 2 32892 _003118_hash NULL
86087 +_003119_hash ath6kl_usb_submit_ctrl_in 6 32880 _003119_hash &_000778_hash
86088 +_003120_hash ath6kl_usb_submit_ctrl_out 6 9978 _003120_hash NULL
86089 +_003121_hash auok190xfb_write 3 37001 _003121_hash NULL
86090 +_003122_hash beacon_interval_write 3 17952 _003122_hash NULL
86091 +_003123_hash blk_dropped_read 3 4168 _003123_hash NULL
86092 +_003124_hash blk_msg_write 3 13655 _003124_hash NULL
86093 +_003125_hash brcmf_usbdev_qinit 2 19090 _003125_hash &_001533_hash
86094 +_003126_hash brcmf_usb_dl_cmd 4 53130 _003126_hash NULL
86095 +_003127_hash broadsheetfb_write 3 39976 _003127_hash NULL
86096 +_003128_hash broadsheet_spiflash_rewrite_sector 2 54864 _003128_hash NULL
86097 +_003129_hash cyttsp_probe 4 1940 _003129_hash NULL
86098 +_003130_hash da9052_group_write 3 4534 _003130_hash NULL
86099 +_003131_hash dccpprobe_read 3 52549 _003131_hash NULL
86100 +_003132_hash drm_property_create_bitmask 5 30195 _003132_hash NULL
86101 +_003133_hash dtim_interval_write 3 30489 _003133_hash NULL
86102 +_003134_hash dynamic_ps_timeout_write 3 37713 _003134_hash NULL
86103 +_003135_hash event_enable_read 3 7074 _003135_hash NULL
86104 +_003136_hash event_enable_write 3 45238 _003136_hash NULL
86105 +_003137_hash event_filter_read 3 23494 _003137_hash NULL
86106 +_003138_hash event_filter_write 3 56609 _003138_hash NULL
86107 +_003139_hash event_id_read 3 64288 _003139_hash &_001240_hash
86108 +_003140_hash f_audio_buffer_alloc 1 41110 _003140_hash NULL
86109 +_003141_hash fb_sys_read 3 13778 _003141_hash NULL
86110 +_003142_hash fb_sys_write 3 33130 _003142_hash NULL
86111 +_003143_hash forced_ps_write 3 37209 _003143_hash NULL
86112 +_003144_hash __fprog_create 2 41263 _003144_hash NULL
86113 +_003145_hash fq_codel_zalloc 1 15378 _003145_hash NULL
86114 +_003146_hash ftrace_pid_write 3 39710 _003146_hash NULL
86115 +_003147_hash ftrace_profile_read 3 21327 _003147_hash NULL
86116 +_003148_hash ftrace_profile_write 3 53327 _003148_hash NULL
86117 +_003149_hash ftrace_write 3 29551 _003149_hash NULL
86118 +_003150_hash gdm_wimax_netif_rx 3 43423 _003150_hash &_001619_hash
86119 +_003151_hash gpio_power_write 3 1991 _003151_hash NULL
86120 +_003152_hash hecubafb_write 3 26942 _003152_hash NULL
86121 +_003153_hash hsc_msg_alloc 1 60990 _003153_hash NULL
86122 +_003154_hash hsc_write 3 55875 _003154_hash NULL
86123 +_003155_hash hsi_alloc_controller 1 41802 _003155_hash NULL
86124 +_003156_hash hsi_register_board_info 2 13820 _003156_hash NULL
86125 +_003157_hash i915_ring_stop_read 3 42549 _003157_hash NULL
86126 +_003158_hash i915_ring_stop_write 3 59010 _003158_hash NULL
86127 +_003159_hash ieee802154_alloc_device 1 13767 _003159_hash NULL
86128 +_003160_hash intel_sdvo_write_cmd 4 54377 _003160_hash &_000815_hash
86129 +_003161_hash ivtvfb_write 3 40023 _003161_hash NULL
86130 +_003162_hash metronomefb_write 3 8823 _003162_hash NULL
86131 +_003163_hash mwifiex_usb_submit_rx_urb 2 54558 _003163_hash NULL
86132 +_003164_hash nfc_hci_hcp_message_tx 6 14534 _003164_hash NULL
86133 +_003165_hash nfc_hci_set_param 5 40697 _003165_hash NULL
86134 +_003166_hash nfc_shdlc_alloc_skb 2 12741 _003166_hash NULL
86135 +_003167_hash odev_update 2 50169 _003167_hash NULL
86136 +_003168_hash oz_add_farewell 5 20652 _003168_hash NULL
86137 +_003169_hash oz_cdev_read 3 20659 _003169_hash NULL
86138 +_003170_hash oz_cdev_write 3 33852 _003170_hash NULL
86139 +_003171_hash oz_ep_alloc 2 5587 _003171_hash NULL
86140 +_003172_hash oz_events_read 3 47535 _003172_hash NULL
86141 +_003173_hash pmcraid_copy_sglist 3 38431 _003173_hash NULL
86142 +_003174_hash prctl_set_mm 3 64538 _003174_hash NULL
86143 +_003175_hash ptp_filter_init 2 36780 _003175_hash NULL
86144 +_003176_hash rb_simple_read 3 45972 _003176_hash NULL
86145 +_003177_hash rb_simple_write 3 20890 _003177_hash NULL
86146 +_003178_hash read_file_dfs 3 43145 _003178_hash NULL
86147 +_003179_hash rx_streaming_always_write 3 32357 _003179_hash NULL
86148 +_003180_hash rx_streaming_interval_write 3 50120 _003180_hash NULL
86149 +_003181_hash shmem_pread_fast 3 34147 _003181_hash NULL
86150 +_003182_hash shmem_pread_slow 3 3198 _003182_hash NULL
86151 +_003183_hash shmem_pwrite_fast 3 46842 _003183_hash NULL
86152 +_003184_hash shmem_pwrite_slow 3 31741 _003184_hash NULL
86153 +_003185_hash show_header 3 4722 _003185_hash &_000736_hash
86154 +_003186_hash split_scan_timeout_write 3 52128 _003186_hash NULL
86155 +_003187_hash stack_max_size_read 3 1445 _003187_hash NULL
86156 +_003188_hash stack_max_size_write 3 36068 _003188_hash NULL
86157 +_003189_hash subsystem_filter_read 3 62310 _003189_hash NULL
86158 +_003190_hash subsystem_filter_write 3 13022 _003190_hash NULL
86159 +_003191_hash suspend_dtim_interval_write 3 48854 _003191_hash NULL
86160 +_003192_hash system_enable_read 3 25815 _003192_hash NULL
86161 +_003193_hash system_enable_write 3 61396 _003193_hash NULL
86162 +_003194_hash trace_options_core_read 3 47390 _003194_hash NULL
86163 +_003195_hash trace_options_core_write 3 61551 _003195_hash NULL
86164 +_003196_hash trace_options_read 3 11419 _003196_hash NULL
86165 +_003197_hash trace_options_write 3 48275 _003197_hash NULL
86166 +_003198_hash trace_parser_get_init 2 31379 _003198_hash NULL
86167 +_003199_hash traceprobe_probes_write 3 64969 _003199_hash NULL
86168 +_003200_hash trace_seq_to_user 3 65398 _003200_hash NULL
86169 +_003201_hash tracing_buffers_read 3 11124 _003201_hash NULL
86170 +_003202_hash tracing_clock_write 3 27961 _003202_hash NULL
86171 +_003203_hash tracing_cpumask_read 3 7010 _003203_hash NULL
86172 +_003204_hash tracing_ctrl_read 3 46922 _003204_hash NULL
86173 +_003205_hash tracing_ctrl_write 3 42324 _003205_hash &_001726_hash
86174 +_003206_hash tracing_entries_read 3 8345 _003206_hash NULL
86175 +_003207_hash tracing_entries_write 3 60563 _003207_hash NULL
86176 +_003208_hash tracing_max_lat_read 3 8890 _003208_hash NULL
86177 +_003209_hash tracing_max_lat_write 3 8728 _003209_hash NULL
86178 +_003210_hash tracing_read_dyn_info 3 45468 _003210_hash NULL
86179 +_003211_hash tracing_readme_read 3 16493 _003211_hash NULL
86180 +_003212_hash tracing_saved_cmdlines_read 3 21434 _003212_hash NULL
86181 +_003213_hash tracing_set_trace_read 3 44122 _003213_hash NULL
86182 +_003214_hash tracing_set_trace_write 3 57096 _003214_hash NULL
86183 +_003215_hash tracing_stats_read 3 34537 _003215_hash NULL
86184 +_003216_hash tracing_total_entries_read 3 62817 _003216_hash NULL
86185 +_003217_hash tracing_trace_options_write 3 153 _003217_hash NULL
86186 +_003218_hash ttm_put_pages 2 9179 _003218_hash NULL
86187 +_003219_hash udl_prime_create 2 57159 _003219_hash NULL
86188 +_003220_hash ufx_alloc_urb_list 3 10349 _003220_hash NULL
86189 +_003221_hash u_memcpya 2-3 30139 _003221_hash NULL
86190 +_003223_hash viafb_dfph_proc_write 3 49288 _003223_hash NULL
86191 +_003224_hash viafb_dfpl_proc_write 3 627 _003224_hash NULL
86192 +_003225_hash viafb_dvp0_proc_write 3 23023 _003225_hash NULL
86193 +_003226_hash viafb_dvp1_proc_write 3 48864 _003226_hash NULL
86194 +_003227_hash viafb_vt1636_proc_write 3 16018 _003227_hash NULL
86195 +_003228_hash vivi_read 3 23073 _003228_hash NULL
86196 +_003229_hash wl1271_rx_filter_alloc_field 5 46721 _003229_hash NULL
86197 +_003230_hash wl12xx_cmd_build_probe_req 6-8 3098 _003230_hash NULL
86198 +_003232_hash wlcore_alloc_hw 1 7785 _003232_hash NULL
86199 +_003233_hash alloc_and_copy_ftrace_hash 1 29368 _003233_hash NULL
86200 +_003234_hash create_trace_probe 1 20175 _003234_hash NULL
86201 +_003235_hash create_trace_uprobe 1 13184 _003235_hash NULL
86202 +_003236_hash intel_sdvo_set_value 4 2311 _003236_hash NULL
86203 +_003237_hash mmio_read 4 40348 _003237_hash NULL
86204 +_003238_hash nfc_hci_execute_cmd 5 43882 _003238_hash NULL
86205 +_003239_hash nfc_hci_send_event 5 21452 _003239_hash NULL
86206 +_003240_hash nfc_hci_send_response 5 56462 _003240_hash NULL
86207 +_003241_hash picolcd_fb_write 3 2318 _003241_hash NULL
86208 +_003242_hash probes_write 3 29711 _003242_hash NULL
86209 +_003243_hash sys_prctl 4 8766 _003243_hash NULL
86210 +_003244_hash tracing_read_pipe 3 35312 _003244_hash NULL
86211 +_003245_hash brcmf_usb_attach 1-2 44656 _003245_hash NULL
86212 +_003247_hash dlfb_ops_write 3 64150 _003247_hash NULL
86213 +_003248_hash nfc_hci_send_cmd 5 55714 _003248_hash NULL
86214 +_003249_hash ufx_ops_write 3 54848 _003249_hash NULL
86215 +_003250_hash viafb_iga1_odev_proc_write 3 36241 _003250_hash NULL
86216 +_003251_hash viafb_iga2_odev_proc_write 3 2363 _003251_hash NULL
86217 +_003252_hash xenfb_write 3 43412 _003252_hash NULL
86218 +_003253_hash acl_alloc 1 35979 _003253_hash NULL
86219 +_003254_hash acl_alloc_stack_init 1 60630 _003254_hash NULL
86220 +_003255_hash acl_alloc_num 1-2 60778 _003255_hash NULL
86221 +_003257_hash padzero 1 55 _003257_hash &_002013_hash
86222 +_003258_hash __get_vm_area_node 1 55305 _003258_hash NULL
86223 +_003259_hash get_vm_area 1 18080 _003259_hash NULL
86224 +_003260_hash __get_vm_area 1 61599 _003260_hash NULL
86225 +_003261_hash get_vm_area_caller 1 10527 _003261_hash NULL
86226 +_003262_hash __get_vm_area_caller 1 56416 _003302_hash NULL nohasharray
86227 +_003263_hash alloc_vm_area 1 36149 _003263_hash NULL
86228 +_003264_hash __ioremap_caller 1-2 21800 _003264_hash NULL
86229 +_003266_hash vmap 2 15025 _003266_hash NULL
86230 +_003267_hash ioremap_cache 1-2 47189 _003267_hash NULL
86231 +_003269_hash ioremap_nocache 1-2 2439 _003269_hash NULL
86232 +_003271_hash ioremap_prot 1-2 51764 _003271_hash &_003102_hash
86233 +_003273_hash ioremap_wc 1-2 62695 _003273_hash NULL
86234 +_003274_hash acpi_os_ioremap 1-2 49523 _003274_hash NULL
86235 +_003276_hash ca91cx42_alloc_resource 2 10502 _003276_hash NULL
86236 +_003277_hash devm_ioremap_nocache 2-3 2036 _003277_hash NULL
86237 +_003279_hash __einj_error_trigger 1 17707 _003279_hash &_001577_hash
86238 +_003280_hash io_mapping_map_wc 2 19284 _003280_hash NULL
86239 +_003281_hash ioremap 1-2 23172 _003281_hash NULL
86240 +_003283_hash lguest_map 1-2 42008 _003283_hash NULL
86241 +_003285_hash msix_map_region 3 3411 _003285_hash NULL
86242 +_003286_hash pci_iomap 3 47575 _003286_hash NULL
86243 +_003287_hash sfi_map_memory 1-2 5183 _003287_hash NULL
86244 +_003289_hash tsi148_alloc_resource 2 24563 _003289_hash NULL
86245 +_003290_hash vb2_vmalloc_get_userptr 3 31374 _003290_hash NULL
86246 +_003291_hash xlate_dev_mem_ptr 1 15291 _003291_hash &_001167_hash
86247 +_003292_hash a4t_cs_init 3 27734 _003292_hash NULL
86248 +_003293_hash aac_nark_ioremap 2 50163 _003293_hash &_000314_hash
86249 +_003294_hash aac_rkt_ioremap 2 3333 _003294_hash NULL
86250 +_003295_hash aac_rx_ioremap 2 52410 _003295_hash NULL
86251 +_003296_hash aac_sa_ioremap 2 13596 _003296_hash &_000288_hash
86252 +_003297_hash aac_src_ioremap 2 41688 _003297_hash NULL
86253 +_003298_hash aac_srcv_ioremap 2 6659 _003298_hash NULL
86254 +_003299_hash acpi_map 1-2 58725 _003299_hash NULL
86255 +_003301_hash acpi_os_read_memory 1-3 54186 _003301_hash NULL
86256 +_003302_hash acpi_os_write_memory 1-3 56416 _003302_hash &_003262_hash
86257 +_003303_hash c101_run 2 37279 _003303_hash NULL
86258 +_003304_hash ca91cx42_master_set 4 23146 _003304_hash NULL
86259 +_003305_hash check586 2 29914 _003305_hash NULL
86260 +_003306_hash check_mirror 1-2 57342 _003306_hash &_001564_hash
86261 +_003308_hash cru_detect 1 11272 _003308_hash NULL
86262 +_003309_hash cs553x_init_one 3 58886 _003309_hash NULL
86263 +_003310_hash cycx_setup 4 47562 _003310_hash NULL
86264 +_003311_hash DepcaSignature 2 80 _003311_hash &_001321_hash
86265 +_003312_hash devm_ioremap 2-3 29235 _003312_hash NULL
86266 +_003314_hash divasa_remap_pci_bar 3-4 23485 _003314_hash &_000947_hash
86267 +_003316_hash dma_declare_coherent_memory 2-4 14244 _003316_hash NULL
86268 +_003318_hash doc_probe 1 23285 _003318_hash NULL
86269 +_003319_hash DoC_Probe 1 57534 _003319_hash NULL
86270 +_003320_hash ems_pcmcia_add_card 2 62627 _003320_hash NULL
86271 +_003321_hash gdth_init_isa 1 28091 _003321_hash NULL
86272 +_003322_hash gdth_search_isa 1 58595 _003322_hash NULL
86273 +_003323_hash isp1760_register 1-2 628 _003323_hash NULL
86274 +_003325_hash mthca_map_reg 2-3 5664 _003325_hash NULL
86275 +_003327_hash n2_run 3 53459 _003327_hash NULL
86276 +_003328_hash pcim_iomap 3 58334 _003328_hash NULL
86277 +_003329_hash probe_bios 1 17467 _003329_hash NULL
86278 +_003330_hash register_device 2-3 60015 _003330_hash NULL
86279 +_003332_hash remap_pci_mem 1-2 15966 _003332_hash NULL
86280 +_003334_hash rtl_port_map 1-2 2385 _003334_hash NULL
86281 +_003336_hash sfi_map_table 1 5462 _003336_hash NULL
86282 +_003337_hash sriov_enable_migration 2 14889 _003337_hash NULL
86283 +_003338_hash ssb_bus_scan 2 36578 _003338_hash NULL
86284 +_003339_hash ssb_ioremap 2 5228 _003339_hash NULL
86285 +_003340_hash tpm_tis_init 2-3 15304 _003340_hash NULL
86286 +_003342_hash tsi148_master_set 4 14685 _003342_hash NULL
86287 +_003343_hash acpi_os_map_memory 1-2 11161 _003343_hash NULL
86288 +_003345_hash com90xx_found 3 13974 _003345_hash NULL
86289 +_003346_hash dmam_declare_coherent_memory 2-4 43679 _003346_hash NULL
86290 +_003348_hash gdth_isa_probe_one 1 48925 _003348_hash NULL
86291 +_003349_hash sfi_check_table 1 6772 _003349_hash NULL
86292 +_003350_hash sfi_sysfs_install_table 1 51688 _003350_hash NULL
86293 +_003351_hash sriov_enable 2 59689 _003351_hash NULL
86294 +_003352_hash ssb_bus_register 3 65183 _003352_hash NULL
86295 +_003353_hash acpi_ex_system_memory_space_handler 2 31192 _003353_hash NULL
86296 +_003354_hash acpi_tb_check_xsdt 1 21862 _003354_hash NULL
86297 +_003355_hash acpi_tb_install_table 1 12988 _003355_hash NULL
86298 +_003356_hash acpi_tb_parse_root_table 1 53455 _003356_hash NULL
86299 +_003357_hash check_vendor_extension 1 3254 _003357_hash NULL
86300 +_003358_hash pci_enable_sriov 2 35745 _003358_hash NULL
86301 +_003359_hash ssb_bus_pcmciabus_register 3 56020 _003359_hash NULL
86302 +_003360_hash ssb_bus_ssbbus_register 2 2217 _003360_hash NULL
86303 +_003361_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003361_hash NULL
86304 +_003364_hash alloc_vm_area 1 15989 _003364_hash NULL
86305 +_003366_hash efi_ioremap 1-2 3492 _003366_hash &_001092_hash
86306 +_003368_hash init_chip_wc_pat 2 62768 _003368_hash NULL
86307 +_003369_hash io_mapping_create_wc 1-2 1354 _003369_hash NULL
86308 +_003371_hash iommu_map_mmio_space 1 30919 _003371_hash NULL
86309 +_003372_hash arch_gnttab_map_shared 3 41306 _003372_hash NULL
86310 +_003373_hash arch_gnttab_map_status 3 49812 _003373_hash NULL
86311 +_003374_hash intel_render_ring_init_dri 2-3 45446 _003374_hash NULL
86312 +_003376_hash persistent_ram_iomap 1-2 47156 _003376_hash NULL
86313 +_003378_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _003378_hash NULL
86314 +_003379_hash ttm_bo_ioremap 2-3 31082 _003379_hash NULL
86315 +_003381_hash ttm_bo_kmap_ttm 3 5922 _003381_hash NULL
86316 +_003382_hash atyfb_setup_generic 3 49151 _003382_hash NULL
86317 +_003383_hash do_test 1 15766 _003383_hash NULL
86318 +_003384_hash mga_ioremap 1-2 8571 _003384_hash NULL
86319 +_003386_hash mid_get_vbt_data_r0 2 10876 _003386_hash NULL
86320 +_003387_hash mid_get_vbt_data_r10 2 6308 _003387_hash NULL
86321 +_003388_hash mid_get_vbt_data_r1 2 26170 _003388_hash NULL
86322 +_003389_hash persistent_ram_buffer_map 1-2 11332 _003389_hash NULL
86323 +_003391_hash read_vbt_r0 1 503 _003391_hash NULL
86324 +_003392_hash read_vbt_r10 1 60679 _003392_hash NULL
86325 +_003393_hash tpci200_slot_map_space 2 3848 _003393_hash NULL
86326 +_003394_hash ttm_bo_kmap 2-3 60118 _003394_hash NULL
86327 +_003395_hash persistent_ram_new 1-2 14588 _003395_hash NULL
86328 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
86329 new file mode 100644
86330 index 0000000..e9310fa
86331 --- /dev/null
86332 +++ b/tools/gcc/size_overflow_plugin.c
86333 @@ -0,0 +1,1612 @@
86334 +/*
86335 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
86336 + * Licensed under the GPL v2, or (at your option) v3
86337 + *
86338 + * Homepage:
86339 + * http://www.grsecurity.net/~ephox/overflow_plugin/
86340 + *
86341 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
86342 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
86343 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
86344 + *
86345 + * Usage:
86346 + * $ 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
86347 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
86348 + */
86349 +
86350 +#include "gcc-plugin.h"
86351 +#include "config.h"
86352 +#include "system.h"
86353 +#include "coretypes.h"
86354 +#include "tree.h"
86355 +#include "tree-pass.h"
86356 +#include "intl.h"
86357 +#include "plugin-version.h"
86358 +#include "tm.h"
86359 +#include "toplev.h"
86360 +#include "function.h"
86361 +#include "tree-flow.h"
86362 +#include "plugin.h"
86363 +#include "gimple.h"
86364 +#include "c-common.h"
86365 +#include "diagnostic.h"
86366 +#include "cfgloop.h"
86367 +
86368 +struct size_overflow_hash {
86369 + const struct size_overflow_hash * const next;
86370 + const char * const name;
86371 + const unsigned int param;
86372 +};
86373 +
86374 +#include "size_overflow_hash.h"
86375 +
86376 +#define __unused __attribute__((__unused__))
86377 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
86378 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
86379 +#define BEFORE_STMT true
86380 +#define AFTER_STMT false
86381 +#define CREATE_NEW_VAR NULL_TREE
86382 +#define CODES_LIMIT 32
86383 +#define MAX_PARAM 10
86384 +#define MY_STMT GF_PLF_1
86385 +#define NO_CAST_CHECK GF_PLF_2
86386 +
86387 +#if BUILDING_GCC_VERSION == 4005
86388 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
86389 +#endif
86390 +
86391 +int plugin_is_GPL_compatible;
86392 +void debug_gimple_stmt(gimple gs);
86393 +
86394 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs);
86395 +static tree report_size_overflow_decl;
86396 +static const_tree const_char_ptr_type_node;
86397 +static unsigned int handle_function(void);
86398 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
86399 +static tree get_size_overflow_type(gimple stmt, tree node);
86400 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
86401 +
86402 +static struct plugin_info size_overflow_plugin_info = {
86403 + .version = "20120820beta",
86404 + .help = "no-size-overflow\tturn off size overflow checking\n",
86405 +};
86406 +
86407 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
86408 +{
86409 + unsigned int arg_count;
86410 +
86411 + if (TREE_CODE(*node) == FUNCTION_DECL)
86412 + arg_count = type_num_arguments(TREE_TYPE(*node));
86413 + else if (TREE_CODE(*node) == FUNCTION_TYPE || TREE_CODE(*node) == METHOD_TYPE)
86414 + arg_count = type_num_arguments(*node);
86415 + else {
86416 + *no_add_attrs = true;
86417 + error("%qE attribute only applies to functions", name);
86418 + return NULL_TREE;
86419 + }
86420 +
86421 + for (; args; args = TREE_CHAIN(args)) {
86422 + tree position = TREE_VALUE(args);
86423 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
86424 + error("handle_size_overflow_attribute: overflow parameter outside range.");
86425 + *no_add_attrs = true;
86426 + }
86427 + }
86428 + return NULL_TREE;
86429 +}
86430 +
86431 +static struct attribute_spec size_overflow_attr = {
86432 + .name = "size_overflow",
86433 + .min_length = 1,
86434 + .max_length = -1,
86435 + .decl_required = true,
86436 + .type_required = false,
86437 + .function_type_required = false,
86438 + .handler = handle_size_overflow_attribute,
86439 +#if BUILDING_GCC_VERSION >= 4007
86440 + .affects_type_identity = false
86441 +#endif
86442 +};
86443 +
86444 +static void register_attributes(void __unused *event_data, void __unused *data)
86445 +{
86446 + register_attribute(&size_overflow_attr);
86447 +}
86448 +
86449 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
86450 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
86451 +{
86452 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
86453 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
86454 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
86455 +
86456 + unsigned int m = 0x57559429;
86457 + unsigned int n = 0x5052acdb;
86458 + const unsigned int *key4 = (const unsigned int *)key;
86459 + unsigned int h = len;
86460 + unsigned int k = len + seed + n;
86461 + unsigned long long p;
86462 +
86463 + while (len >= 8) {
86464 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
86465 + len -= 8;
86466 + }
86467 + if (len >= 4) {
86468 + cwmixb(key4[0]) key4 += 1;
86469 + len -= 4;
86470 + }
86471 + if (len)
86472 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
86473 + cwmixb(h ^ (k + n));
86474 + return k ^ h;
86475 +
86476 +#undef cwfold
86477 +#undef cwmixa
86478 +#undef cwmixb
86479 +}
86480 +
86481 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
86482 +{
86483 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
86484 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
86485 + return fn ^ codes;
86486 +}
86487 +
86488 +static inline const_tree get_original_function_decl(const_tree fndecl)
86489 +{
86490 + if (DECL_ABSTRACT_ORIGIN(fndecl))
86491 + return DECL_ABSTRACT_ORIGIN(fndecl);
86492 + return fndecl;
86493 +}
86494 +
86495 +static inline gimple get_def_stmt(const_tree node)
86496 +{
86497 + gcc_assert(node != NULL_TREE);
86498 + gcc_assert(TREE_CODE(node) == SSA_NAME);
86499 + return SSA_NAME_DEF_STMT(node);
86500 +}
86501 +
86502 +static unsigned char get_tree_code(tree type)
86503 +{
86504 + switch (TREE_CODE(type)) {
86505 + case ARRAY_TYPE:
86506 + return 0;
86507 + case BOOLEAN_TYPE:
86508 + return 1;
86509 + case ENUMERAL_TYPE:
86510 + return 2;
86511 + case FUNCTION_TYPE:
86512 + return 3;
86513 + case INTEGER_TYPE:
86514 + return 4;
86515 + case POINTER_TYPE:
86516 + return 5;
86517 + case RECORD_TYPE:
86518 + return 6;
86519 + case UNION_TYPE:
86520 + return 7;
86521 + case VOID_TYPE:
86522 + return 8;
86523 + case REAL_TYPE:
86524 + return 9;
86525 + case VECTOR_TYPE:
86526 + return 10;
86527 + case REFERENCE_TYPE:
86528 + return 11;
86529 + default:
86530 + debug_tree(type);
86531 + gcc_unreachable();
86532 + }
86533 +}
86534 +
86535 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
86536 +{
86537 + gcc_assert(type != NULL_TREE);
86538 +
86539 + while (type && len < CODES_LIMIT) {
86540 + tree_codes[len] = get_tree_code(type);
86541 + len++;
86542 + type = TREE_TYPE(type);
86543 + }
86544 + return len;
86545 +}
86546 +
86547 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
86548 +{
86549 + tree arg;
86550 + const_tree result, type = TREE_TYPE(fndecl);
86551 + enum tree_code code = TREE_CODE(type);
86552 + size_t len = 0;
86553 +
86554 + gcc_assert(code == FUNCTION_TYPE);
86555 +
86556 + arg = TYPE_ARG_TYPES(type);
86557 + // skip builtins __builtin_constant_p
86558 + if (!arg && DECL_BUILT_IN(fndecl))
86559 + return 0;
86560 + gcc_assert(arg != NULL_TREE);
86561 +
86562 + if (TREE_CODE_CLASS(code) == tcc_type)
86563 + result = type;
86564 + else
86565 + result = DECL_RESULT(fndecl);
86566 +
86567 + gcc_assert(result != NULL_TREE);
86568 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
86569 +
86570 + while (arg && len < CODES_LIMIT) {
86571 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
86572 + arg = TREE_CHAIN(arg);
86573 + }
86574 +
86575 + gcc_assert(len != 0);
86576 + return len;
86577 +}
86578 +
86579 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
86580 +{
86581 + unsigned int hash;
86582 + const struct size_overflow_hash *entry;
86583 + unsigned char tree_codes[CODES_LIMIT];
86584 + size_t len;
86585 + const char *func_name = NAME(fndecl);
86586 +
86587 + len = get_function_decl(fndecl, tree_codes);
86588 + if (len == 0)
86589 + return NULL;
86590 +
86591 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
86592 +
86593 + entry = size_overflow_hash[hash];
86594 + while (entry) {
86595 + if (!strcmp(entry->name, func_name))
86596 + return entry;
86597 + entry = entry->next;
86598 + }
86599 +
86600 + return NULL;
86601 +}
86602 +
86603 +static void check_arg_type(const_tree arg)
86604 +{
86605 + const_tree type = TREE_TYPE(arg);
86606 + enum tree_code code = TREE_CODE(type);
86607 +
86608 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
86609 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
86610 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
86611 +}
86612 +
86613 +static int find_arg_number(const_tree arg, const_tree func)
86614 +{
86615 + tree var;
86616 + bool match = false;
86617 + unsigned int argnum = 1;
86618 +
86619 + if (TREE_CODE(arg) == SSA_NAME)
86620 + arg = SSA_NAME_VAR(arg);
86621 +
86622 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
86623 + if (strcmp(NAME(arg), NAME(var))) {
86624 + argnum++;
86625 + continue;
86626 + }
86627 + check_arg_type(var);
86628 +
86629 + match = true;
86630 + break;
86631 + }
86632 + if (!match) {
86633 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
86634 + return 0;
86635 + }
86636 + return argnum;
86637 +}
86638 +
86639 +static void print_missing_msg(const_tree func, unsigned int argnum)
86640 +{
86641 + unsigned int new_hash;
86642 + size_t len;
86643 + unsigned char tree_codes[CODES_LIMIT];
86644 + location_t loc = DECL_SOURCE_LOCATION(func);
86645 + const char *curfunc = NAME(func);
86646 +
86647 + len = get_function_decl(func, tree_codes);
86648 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
86649 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
86650 +}
86651 +
86652 +static void check_missing_attribute(const_tree arg)
86653 +{
86654 + const_tree type = TREE_TYPE(arg);
86655 + const_tree func = get_original_function_decl(current_function_decl);
86656 + unsigned int argnum;
86657 + const struct size_overflow_hash *hash;
86658 +
86659 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
86660 +
86661 + if (TREE_CODE(type) == POINTER_TYPE)
86662 + return;
86663 +
86664 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
86665 + return;
86666 +
86667 + argnum = find_arg_number(arg, func);
86668 + if (argnum == 0)
86669 + return;
86670 +
86671 + hash = get_function_hash(func);
86672 + if (!hash || !(hash->param & (1U << argnum)))
86673 + print_missing_msg(func, argnum);
86674 +}
86675 +
86676 +static tree create_new_var(tree type)
86677 +{
86678 + tree new_var = create_tmp_var(type, "cicus");
86679 +
86680 + add_referenced_var(new_var);
86681 + mark_sym_for_renaming(new_var);
86682 + return new_var;
86683 +}
86684 +
86685 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
86686 +{
86687 + gimple assign;
86688 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86689 + tree type = TREE_TYPE(rhs1);
86690 + tree lhs = create_new_var(type);
86691 +
86692 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
86693 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
86694 +
86695 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86696 + update_stmt(assign);
86697 + gimple_set_plf(assign, MY_STMT, true);
86698 + return assign;
86699 +}
86700 +
86701 +static bool is_bool(const_tree node)
86702 +{
86703 + const_tree type;
86704 +
86705 + if (node == NULL_TREE)
86706 + return false;
86707 +
86708 + type = TREE_TYPE(node);
86709 + if (!INTEGRAL_TYPE_P(type))
86710 + return false;
86711 + if (TREE_CODE(type) == BOOLEAN_TYPE)
86712 + return true;
86713 + if (TYPE_PRECISION(type) == 1)
86714 + return true;
86715 + return false;
86716 +}
86717 +
86718 +static tree cast_a_tree(tree type, tree var)
86719 +{
86720 + gcc_assert(type != NULL_TREE);
86721 + gcc_assert(var != NULL_TREE);
86722 + gcc_assert(fold_convertible_p(type, var));
86723 +
86724 + return fold_convert(type, var);
86725 +}
86726 +
86727 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
86728 +{
86729 + gimple assign;
86730 +
86731 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
86732 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
86733 + gcc_unreachable();
86734 +
86735 + if (lhs == CREATE_NEW_VAR)
86736 + lhs = create_new_var(dst_type);
86737 +
86738 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
86739 +
86740 + if (!gsi_end_p(*gsi)) {
86741 + location_t loc = gimple_location(gsi_stmt(*gsi));
86742 + gimple_set_location(assign, loc);
86743 + }
86744 +
86745 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
86746 +
86747 + if (before)
86748 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
86749 + else
86750 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
86751 + update_stmt(assign);
86752 + gimple_set_plf(assign, MY_STMT, true);
86753 +
86754 + return assign;
86755 +}
86756 +
86757 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
86758 +{
86759 + const_gimple assign;
86760 + gimple_stmt_iterator gsi;
86761 +
86762 + if (new_rhs1 == NULL_TREE)
86763 + return NULL_TREE;
86764 +
86765 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
86766 + gsi = gsi_for_stmt(stmt);
86767 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
86768 + return gimple_get_lhs(assign);
86769 + }
86770 + return new_rhs1;
86771 +}
86772 +
86773 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
86774 +{
86775 + tree size_overflow_type = get_size_overflow_type(stmt, node);
86776 +
86777 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86778 +
86779 + if (new_rhs2 != NULL_TREE)
86780 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
86781 +
86782 + if (new_rhs3 != NULL_TREE)
86783 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
86784 +
86785 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
86786 +}
86787 +
86788 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
86789 +{
86790 + const_tree oldstmt_rhs1;
86791 + tree size_overflow_type, lhs;
86792 + enum tree_code code;
86793 + gimple stmt;
86794 + gimple_stmt_iterator gsi;
86795 +
86796 + if (!*potentionally_overflowed)
86797 + return NULL_TREE;
86798 +
86799 + if (rhs1 == NULL_TREE) {
86800 + debug_gimple_stmt(oldstmt);
86801 + error("create_assign: rhs1 is NULL_TREE");
86802 + gcc_unreachable();
86803 + }
86804 +
86805 + if (gimple_code(oldstmt) == GIMPLE_ASM)
86806 + lhs = rhs1;
86807 + else
86808 + lhs = gimple_get_lhs(oldstmt);
86809 +
86810 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
86811 + code = TREE_CODE(oldstmt_rhs1);
86812 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
86813 + check_missing_attribute(oldstmt_rhs1);
86814 +
86815 + gsi = gsi_for_stmt(oldstmt);
86816 + pointer_set_insert(visited, oldstmt);
86817 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
86818 + basic_block next_bb, cur_bb;
86819 + const_edge e;
86820 +
86821 + gcc_assert(before == false);
86822 + gcc_assert(stmt_can_throw_internal(oldstmt));
86823 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
86824 + gcc_assert(!gsi_end_p(gsi));
86825 +
86826 + cur_bb = gimple_bb(oldstmt);
86827 + next_bb = cur_bb->next_bb;
86828 + e = find_edge(cur_bb, next_bb);
86829 + gcc_assert(e != NULL);
86830 + gcc_assert(e->flags & EDGE_FALLTHRU);
86831 +
86832 + gsi = gsi_after_labels(next_bb);
86833 + gcc_assert(!gsi_end_p(gsi));
86834 +
86835 + before = true;
86836 + oldstmt = gsi_stmt(gsi);
86837 + pointer_set_insert(visited, oldstmt);
86838 + }
86839 +
86840 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
86841 +
86842 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
86843 + gimple_set_plf(stmt, MY_STMT, true);
86844 + return gimple_get_lhs(stmt);
86845 +}
86846 +
86847 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
86848 +{
86849 + gimple stmt;
86850 + gimple_stmt_iterator gsi;
86851 + tree new_var, lhs = gimple_get_lhs(oldstmt);
86852 +
86853 + if (!*potentionally_overflowed)
86854 + return NULL_TREE;
86855 +
86856 + if (gimple_plf(oldstmt, MY_STMT))
86857 + return lhs;
86858 +
86859 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
86860 + rhs1 = gimple_assign_rhs1(oldstmt);
86861 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
86862 + }
86863 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
86864 + rhs2 = gimple_assign_rhs2(oldstmt);
86865 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
86866 + }
86867 +
86868 + stmt = gimple_copy(oldstmt);
86869 + gimple_set_location(stmt, gimple_location(oldstmt));
86870 + gimple_set_plf(stmt, MY_STMT, true);
86871 +
86872 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
86873 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
86874 +
86875 + if (is_bool(lhs))
86876 + new_var = SSA_NAME_VAR(lhs);
86877 + else
86878 + new_var = create_new_var(size_overflow_type);
86879 + new_var = make_ssa_name(new_var, stmt);
86880 + gimple_set_lhs(stmt, new_var);
86881 +
86882 + if (rhs1 != NULL_TREE) {
86883 + if (!gimple_assign_cast_p(oldstmt))
86884 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
86885 + gimple_assign_set_rhs1(stmt, rhs1);
86886 + }
86887 +
86888 + if (rhs2 != NULL_TREE)
86889 + gimple_assign_set_rhs2(stmt, rhs2);
86890 +#if BUILDING_GCC_VERSION >= 4007
86891 + if (rhs3 != NULL_TREE)
86892 + gimple_assign_set_rhs3(stmt, rhs3);
86893 +#endif
86894 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
86895 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
86896 +
86897 + gsi = gsi_for_stmt(oldstmt);
86898 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
86899 + update_stmt(stmt);
86900 + pointer_set_insert(visited, oldstmt);
86901 + return gimple_get_lhs(stmt);
86902 +}
86903 +
86904 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
86905 +{
86906 + basic_block bb;
86907 + gimple phi;
86908 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
86909 +
86910 + bb = gsi_bb(gsi);
86911 +
86912 + phi = create_phi_node(result, bb);
86913 + gsi = gsi_last(phi_nodes(bb));
86914 + gsi_remove(&gsi, false);
86915 +
86916 + gsi = gsi_for_stmt(oldstmt);
86917 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
86918 + gimple_set_bb(phi, bb);
86919 + gimple_set_plf(phi, MY_STMT, true);
86920 + return phi;
86921 +}
86922 +
86923 +static basic_block create_a_first_bb(void)
86924 +{
86925 + basic_block first_bb;
86926 +
86927 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86928 + if (dom_info_available_p(CDI_DOMINATORS))
86929 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
86930 + return first_bb;
86931 +}
86932 +
86933 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
86934 +{
86935 + basic_block bb;
86936 + const_gimple newstmt;
86937 + gimple_stmt_iterator gsi;
86938 + bool before = BEFORE_STMT;
86939 +
86940 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
86941 + gsi = gsi_for_stmt(get_def_stmt(arg));
86942 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
86943 + return gimple_get_lhs(newstmt);
86944 + }
86945 +
86946 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
86947 + gsi = gsi_after_labels(bb);
86948 + if (bb->index == 0) {
86949 + bb = create_a_first_bb();
86950 + gsi = gsi_start_bb(bb);
86951 + }
86952 + if (gsi_end_p(gsi))
86953 + before = AFTER_STMT;
86954 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
86955 + return gimple_get_lhs(newstmt);
86956 +}
86957 +
86958 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
86959 +{
86960 + gimple newstmt;
86961 + gimple_stmt_iterator gsi;
86962 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
86963 + gimple def_newstmt = get_def_stmt(new_rhs);
86964 +
86965 + gsi_insert = gsi_insert_after;
86966 + gsi = gsi_for_stmt(def_newstmt);
86967 +
86968 + switch (gimple_code(get_def_stmt(arg))) {
86969 + case GIMPLE_PHI:
86970 + newstmt = gimple_build_assign(new_var, new_rhs);
86971 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
86972 + gsi_insert = gsi_insert_before;
86973 + break;
86974 + case GIMPLE_ASM:
86975 + case GIMPLE_CALL:
86976 + newstmt = gimple_build_assign(new_var, new_rhs);
86977 + break;
86978 + case GIMPLE_ASSIGN:
86979 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
86980 + break;
86981 + default:
86982 + /* unknown gimple_code (handle_build_new_phi_arg) */
86983 + gcc_unreachable();
86984 + }
86985 +
86986 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
86987 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
86988 + gimple_set_plf(newstmt, MY_STMT, true);
86989 + update_stmt(newstmt);
86990 + return newstmt;
86991 +}
86992 +
86993 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
86994 +{
86995 + const_gimple newstmt;
86996 + tree new_rhs;
86997 +
86998 + new_rhs = expand(visited, potentionally_overflowed, arg);
86999 + if (new_rhs == NULL_TREE)
87000 + return NULL_TREE;
87001 +
87002 + new_rhs = cast_to_new_size_overflow_type(get_def_stmt(new_rhs), new_rhs, size_overflow_type, AFTER_STMT);
87003 +
87004 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87005 + return gimple_get_lhs(newstmt);
87006 +}
87007 +
87008 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree orig_result)
87009 +{
87010 + gimple phi, oldstmt = get_def_stmt(orig_result);
87011 + tree new_result, size_overflow_type;
87012 + unsigned int i;
87013 + unsigned int n = gimple_phi_num_args(oldstmt);
87014 +
87015 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87016 +
87017 + new_result = create_new_var(size_overflow_type);
87018 +
87019 + pointer_set_insert(visited, oldstmt);
87020 + phi = overflow_create_phi_node(oldstmt, new_result);
87021 + for (i = 0; i < n; i++) {
87022 + tree arg, lhs;
87023 +
87024 + arg = gimple_phi_arg_def(oldstmt, i);
87025 + if (is_gimple_constant(arg))
87026 + arg = cast_a_tree(size_overflow_type, arg);
87027 + lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_result);
87028 + if (lhs == NULL_TREE)
87029 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87030 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87031 + }
87032 +
87033 + update_stmt(phi);
87034 + return gimple_phi_result(phi);
87035 +}
87036 +
87037 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87038 +{
87039 + const_gimple assign;
87040 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87041 + tree origtype = TREE_TYPE(orig_rhs);
87042 +
87043 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87044 +
87045 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87046 + return gimple_get_lhs(assign);
87047 +}
87048 +
87049 +static void change_rhs1(gimple stmt, tree new_rhs1)
87050 +{
87051 + tree assign_rhs;
87052 + const_tree rhs = gimple_assign_rhs1(stmt);
87053 +
87054 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87055 + gimple_assign_set_rhs1(stmt, assign_rhs);
87056 + update_stmt(stmt);
87057 +}
87058 +
87059 +static bool check_mode_type(const_gimple stmt)
87060 +{
87061 + const_tree lhs = gimple_get_lhs(stmt);
87062 + const_tree lhs_type = TREE_TYPE(lhs);
87063 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
87064 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
87065 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
87066 +
87067 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
87068 + return false;
87069 +
87070 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
87071 + return false;
87072 +
87073 + return true;
87074 +}
87075 +
87076 +static bool check_undefined_integer_operation(const_gimple stmt)
87077 +{
87078 + const_gimple def_stmt;
87079 + const_tree lhs = gimple_get_lhs(stmt);
87080 + const_tree rhs1 = gimple_assign_rhs1(stmt);
87081 + const_tree rhs1_type = TREE_TYPE(rhs1);
87082 + const_tree lhs_type = TREE_TYPE(lhs);
87083 +
87084 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
87085 + return false;
87086 +
87087 + def_stmt = get_def_stmt(rhs1);
87088 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
87089 + return false;
87090 +
87091 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
87092 + return false;
87093 + return true;
87094 +}
87095 +
87096 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
87097 +{
87098 + const_tree rhs1, lhs, rhs1_type, lhs_type;
87099 + enum machine_mode lhs_mode, rhs_mode;
87100 + gimple def_stmt = get_def_stmt(no_const_rhs);
87101 +
87102 + if (!gimple_assign_cast_p(def_stmt))
87103 + return false;
87104 +
87105 + rhs1 = gimple_assign_rhs1(def_stmt);
87106 + lhs = gimple_get_lhs(def_stmt);
87107 + rhs1_type = TREE_TYPE(rhs1);
87108 + lhs_type = TREE_TYPE(lhs);
87109 + rhs_mode = TYPE_MODE(rhs1_type);
87110 + lhs_mode = TYPE_MODE(lhs_type);
87111 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
87112 + return false;
87113 +
87114 + return true;
87115 +}
87116 +
87117 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt)
87118 +{
87119 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
87120 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
87121 + const_tree rhs1_type = TREE_TYPE(rhs1);
87122 + const_tree lhs_type = TREE_TYPE(lhs);
87123 +
87124 + *potentionally_overflowed = true;
87125 +
87126 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87127 +
87128 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
87129 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87130 +
87131 + if (gimple_plf(stmt, MY_STMT))
87132 + return lhs;
87133 +
87134 + if (gimple_plf(stmt, NO_CAST_CHECK))
87135 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
87136 +
87137 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
87138 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
87139 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87140 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
87141 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87142 + }
87143 +
87144 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
87145 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
87146 +
87147 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
87148 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87149 +
87150 + change_rhs1(stmt, new_rhs1);
87151 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
87152 +
87153 + rhs1 = gimple_assign_rhs1(stmt);
87154 + rhs1_type = TREE_TYPE(rhs1);
87155 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
87156 + return create_assign(visited, potentionally_overflowed, stmt, rhs1, AFTER_STMT);
87157 +
87158 + if (!check_mode_type(stmt))
87159 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87160 +
87161 + size_overflow_type = get_size_overflow_type(stmt, lhs);
87162 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87163 +
87164 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, potentionally_overflowed, BEFORE_STMT);
87165 +
87166 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87167 +}
87168 +
87169 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87170 +{
87171 + gimple def_stmt = get_def_stmt(lhs);
87172 + tree rhs1 = gimple_assign_rhs1(def_stmt);
87173 +
87174 + if (is_gimple_constant(rhs1))
87175 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87176 +
87177 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
87178 + switch (TREE_CODE(rhs1)) {
87179 + case SSA_NAME:
87180 + return handle_unary_rhs(visited, potentionally_overflowed, def_stmt);
87181 + case ARRAY_REF:
87182 + case BIT_FIELD_REF:
87183 + case ADDR_EXPR:
87184 + case COMPONENT_REF:
87185 + case INDIRECT_REF:
87186 +#if BUILDING_GCC_VERSION >= 4006
87187 + case MEM_REF:
87188 +#endif
87189 + case PARM_DECL:
87190 + case TARGET_MEM_REF:
87191 + case VAR_DECL:
87192 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87193 +
87194 + default:
87195 + debug_gimple_stmt(def_stmt);
87196 + debug_tree(rhs1);
87197 + gcc_unreachable();
87198 + }
87199 +}
87200 +
87201 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
87202 +{
87203 + gimple cond_stmt;
87204 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
87205 +
87206 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
87207 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
87208 + update_stmt(cond_stmt);
87209 +}
87210 +
87211 +static tree create_string_param(tree string)
87212 +{
87213 + tree i_type, a_type;
87214 + const int length = TREE_STRING_LENGTH(string);
87215 +
87216 + gcc_assert(length > 0);
87217 +
87218 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
87219 + a_type = build_array_type(char_type_node, i_type);
87220 +
87221 + TREE_TYPE(string) = a_type;
87222 + TREE_CONSTANT(string) = 1;
87223 + TREE_READONLY(string) = 1;
87224 +
87225 + return build1(ADDR_EXPR, ptr_type_node, string);
87226 +}
87227 +
87228 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
87229 +{
87230 + gimple func_stmt;
87231 + const_gimple def_stmt;
87232 + const_tree loc_line;
87233 + tree loc_file, ssa_name, current_func;
87234 + expanded_location xloc;
87235 + char ssa_name_buf[256];
87236 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
87237 +
87238 + def_stmt = get_def_stmt(arg);
87239 + xloc = expand_location(gimple_location(def_stmt));
87240 +
87241 + if (!gimple_has_location(def_stmt)) {
87242 + xloc = expand_location(gimple_location(stmt));
87243 + if (!gimple_has_location(stmt))
87244 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
87245 + }
87246 +
87247 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
87248 +
87249 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
87250 + loc_file = create_string_param(loc_file);
87251 +
87252 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
87253 + current_func = create_string_param(current_func);
87254 +
87255 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
87256 + ssa_name = build_string(256, ssa_name_buf);
87257 + ssa_name = create_string_param(ssa_name);
87258 +
87259 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
87260 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
87261 +
87262 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
87263 +}
87264 +
87265 +static void __unused print_the_code_insertions(const_gimple stmt)
87266 +{
87267 + location_t loc = gimple_location(stmt);
87268 +
87269 + inform(loc, "Integer size_overflow check applied here.");
87270 +}
87271 +
87272 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
87273 +{
87274 + basic_block cond_bb, join_bb, bb_true;
87275 + edge e;
87276 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87277 +
87278 + cond_bb = gimple_bb(stmt);
87279 + if (before)
87280 + gsi_prev(&gsi);
87281 + if (gsi_end_p(gsi))
87282 + e = split_block_after_labels(cond_bb);
87283 + else
87284 + e = split_block(cond_bb, gsi_stmt(gsi));
87285 + cond_bb = e->src;
87286 + join_bb = e->dest;
87287 + e->flags = EDGE_FALSE_VALUE;
87288 + e->probability = REG_BR_PROB_BASE;
87289 +
87290 + bb_true = create_empty_bb(cond_bb);
87291 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
87292 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
87293 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
87294 +
87295 + if (dom_info_available_p(CDI_DOMINATORS)) {
87296 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
87297 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
87298 + }
87299 +
87300 + if (current_loops != NULL) {
87301 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
87302 + add_bb_to_loop(bb_true, cond_bb->loop_father);
87303 + }
87304 +
87305 + insert_cond(cond_bb, arg, cond_code, type_value);
87306 + insert_cond_result(bb_true, stmt, arg, min);
87307 +
87308 +// print_the_code_insertions(stmt);
87309 +}
87310 +
87311 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
87312 +{
87313 + const_tree rhs_type = TREE_TYPE(rhs);
87314 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
87315 +
87316 + gcc_assert(rhs_type != NULL_TREE);
87317 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
87318 +
87319 + if (!*potentionally_overflowed)
87320 + return;
87321 +
87322 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
87323 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
87324 +
87325 + gcc_assert(!TREE_OVERFLOW(type_max));
87326 +
87327 + cast_rhs_type = TREE_TYPE(cast_rhs);
87328 + type_max_type = TREE_TYPE(type_max);
87329 + type_min_type = TREE_TYPE(type_min);
87330 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
87331 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
87332 +
87333 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
87334 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
87335 +}
87336 +
87337 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
87338 +{
87339 + gimple change_rhs_def_stmt;
87340 + tree lhs = gimple_get_lhs(def_stmt);
87341 + tree lhs_type = TREE_TYPE(lhs);
87342 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
87343 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
87344 +
87345 + if (change_rhs == NULL_TREE)
87346 + return get_size_overflow_type(def_stmt, lhs);
87347 +
87348 + change_rhs_def_stmt = get_def_stmt(change_rhs);
87349 +
87350 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
87351 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87352 +
87353 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
87354 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87355 +
87356 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
87357 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87358 +
87359 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
87360 + debug_gimple_stmt(def_stmt);
87361 + gcc_unreachable();
87362 + }
87363 +
87364 + return get_size_overflow_type(def_stmt, lhs);
87365 +}
87366 +
87367 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
87368 +{
87369 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
87370 + return false;
87371 + if (!is_gimple_constant(rhs))
87372 + return false;
87373 + return true;
87374 +}
87375 +
87376 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
87377 +{
87378 + gimple def_stmt;
87379 +
87380 + def_stmt = get_def_stmt(new_rhs);
87381 + // get_size_overflow_type
87382 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
87383 + gcc_assert(gimple_assign_cast_p(def_stmt));
87384 + return gimple_assign_rhs1(def_stmt);
87385 +}
87386 +
87387 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
87388 +{
87389 + gimple_stmt_iterator gsi;
87390 + const_gimple cast_stmt;
87391 + gimple def_stmt;
87392 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
87393 +
87394 + if (mode != TImode && mode != DImode) {
87395 + def_stmt = get_def_stmt(new_rhs);
87396 + gcc_assert(gimple_assign_cast_p(def_stmt));
87397 + new_rhs = gimple_assign_rhs1(def_stmt);
87398 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
87399 + }
87400 +
87401 + gcc_assert(mode == TImode || mode == DImode);
87402 +
87403 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
87404 + return new_rhs;
87405 +
87406 + gsi = gsi_for_stmt(stmt);
87407 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87408 + new_rhs = gimple_get_lhs(cast_stmt);
87409 +
87410 + if (mode == DImode)
87411 + return new_rhs;
87412 +
87413 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, potentionally_overflowed, BEFORE_STMT);
87414 +
87415 + return new_rhs;
87416 +}
87417 +
87418 +static bool is_an_integer_trunction(const_gimple stmt)
87419 +{
87420 + gimple rhs1_def_stmt, rhs2_def_stmt;
87421 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
87422 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
87423 + const_tree rhs1 = gimple_assign_rhs1(stmt);
87424 + const_tree rhs2 = gimple_assign_rhs2(stmt);
87425 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
87426 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
87427 +
87428 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
87429 + return false;
87430 +
87431 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
87432 +
87433 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
87434 + return false;
87435 +
87436 + rhs1_def_stmt = get_def_stmt(rhs1);
87437 + rhs2_def_stmt = get_def_stmt(rhs2);
87438 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
87439 + return false;
87440 +
87441 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
87442 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
87443 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
87444 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
87445 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
87446 + return false;
87447 +
87448 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
87449 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
87450 + return true;
87451 +}
87452 +
87453 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87454 +{
87455 + tree new_rhs1, new_rhs2;
87456 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
87457 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
87458 + gimple assign, stmt = get_def_stmt(lhs);
87459 + tree rhs1 = gimple_assign_rhs1(stmt);
87460 + tree rhs2 = gimple_assign_rhs2(stmt);
87461 +
87462 + if (!is_an_integer_trunction(stmt))
87463 + return NULL_TREE;
87464 +
87465 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87466 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
87467 +
87468 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
87469 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
87470 +
87471 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
87472 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
87473 +
87474 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
87475 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs1_def_stmt_rhs1);
87476 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs2_def_stmt_rhs1);
87477 + }
87478 +
87479 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
87480 + new_lhs = gimple_get_lhs(assign);
87481 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
87482 +
87483 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
87484 +}
87485 +
87486 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
87487 +{
87488 + const_gimple def_stmt;
87489 +
87490 + if (TREE_CODE(rhs) != SSA_NAME)
87491 + return false;
87492 +
87493 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
87494 + return false;
87495 +
87496 + def_stmt = get_def_stmt(rhs);
87497 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
87498 + return false;
87499 +
87500 + return true;
87501 +}
87502 +
87503 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool *potentionally_overflowed, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
87504 +{
87505 + tree new_rhs, size_overflow_type, orig_rhs;
87506 + void (*gimple_assign_set_rhs)(gimple, tree);
87507 + tree rhs1 = gimple_assign_rhs1(stmt);
87508 + tree rhs2 = gimple_assign_rhs2(stmt);
87509 + tree lhs = gimple_get_lhs(stmt);
87510 +
87511 + if (change_rhs == NULL_TREE)
87512 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87513 +
87514 + if (new_rhs2 == NULL_TREE) {
87515 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
87516 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
87517 + orig_rhs = rhs1;
87518 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
87519 + } else {
87520 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
87521 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
87522 + orig_rhs = rhs2;
87523 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
87524 + }
87525 +
87526 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
87527 +
87528 + if (check_overflow)
87529 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
87530 +
87531 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
87532 + gimple_assign_set_rhs(stmt, new_rhs);
87533 + update_stmt(stmt);
87534 +
87535 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87536 +}
87537 +
87538 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87539 +{
87540 + tree rhs1, rhs2, new_lhs;
87541 + gimple def_stmt = get_def_stmt(lhs);
87542 + tree new_rhs1 = NULL_TREE;
87543 + tree new_rhs2 = NULL_TREE;
87544 +
87545 + rhs1 = gimple_assign_rhs1(def_stmt);
87546 + rhs2 = gimple_assign_rhs2(def_stmt);
87547 +
87548 + /* no DImode/TImode division in the 32/64 bit kernel */
87549 + switch (gimple_assign_rhs_code(def_stmt)) {
87550 + case RDIV_EXPR:
87551 + case TRUNC_DIV_EXPR:
87552 + case CEIL_DIV_EXPR:
87553 + case FLOOR_DIV_EXPR:
87554 + case ROUND_DIV_EXPR:
87555 + case TRUNC_MOD_EXPR:
87556 + case CEIL_MOD_EXPR:
87557 + case FLOOR_MOD_EXPR:
87558 + case ROUND_MOD_EXPR:
87559 + case EXACT_DIV_EXPR:
87560 + case POINTER_PLUS_EXPR:
87561 + case BIT_AND_EXPR:
87562 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87563 + default:
87564 + break;
87565 + }
87566 +
87567 + *potentionally_overflowed = true;
87568 +
87569 + new_lhs = handle_integer_truncation(visited, potentionally_overflowed, lhs);
87570 + if (new_lhs != NULL_TREE)
87571 + return new_lhs;
87572 +
87573 + if (TREE_CODE(rhs1) == SSA_NAME)
87574 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87575 + if (TREE_CODE(rhs2) == SSA_NAME)
87576 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
87577 +
87578 + if (is_a_neg_overflow(def_stmt, rhs2))
87579 + return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
87580 + if (is_a_neg_overflow(def_stmt, rhs1))
87581 + return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
87582 +
87583 + if (is_a_constant_overflow(def_stmt, rhs2))
87584 + return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
87585 + if (is_a_constant_overflow(def_stmt, rhs1))
87586 + return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
87587 +
87588 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
87589 +}
87590 +
87591 +#if BUILDING_GCC_VERSION >= 4007
87592 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree rhs)
87593 +{
87594 + if (is_gimple_constant(rhs))
87595 + return cast_a_tree(size_overflow_type, rhs);
87596 + if (TREE_CODE(rhs) != SSA_NAME)
87597 + return NULL_TREE;
87598 + return expand(visited, potentionally_overflowed, rhs);
87599 +}
87600 +
87601 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87602 +{
87603 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
87604 + gimple def_stmt = get_def_stmt(lhs);
87605 +
87606 + *potentionally_overflowed = true;
87607 +
87608 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
87609 +
87610 + rhs1 = gimple_assign_rhs1(def_stmt);
87611 + rhs2 = gimple_assign_rhs2(def_stmt);
87612 + rhs3 = gimple_assign_rhs3(def_stmt);
87613 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs1);
87614 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
87615 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
87616 +
87617 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
87618 +}
87619 +#endif
87620 +
87621 +static tree get_size_overflow_type(gimple stmt, tree node)
87622 +{
87623 + tree type;
87624 +
87625 + gcc_assert(node != NULL_TREE);
87626 +
87627 + type = TREE_TYPE(node);
87628 +
87629 + if (gimple_plf(stmt, MY_STMT))
87630 + return TREE_TYPE(node);
87631 +
87632 + switch (TYPE_MODE(type)) {
87633 + case QImode:
87634 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
87635 + case HImode:
87636 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
87637 + case SImode:
87638 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
87639 + case DImode:
87640 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
87641 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
87642 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
87643 + default:
87644 + debug_tree(node);
87645 + error("get_size_overflow_type: unsupported gcc configuration.");
87646 + gcc_unreachable();
87647 + }
87648 +}
87649 +
87650 +static tree expand_visited(gimple def_stmt)
87651 +{
87652 + const_gimple next_stmt;
87653 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
87654 +
87655 + gsi_next(&gsi);
87656 + next_stmt = gsi_stmt(gsi);
87657 +
87658 + switch (gimple_code(next_stmt)) {
87659 + case GIMPLE_ASSIGN:
87660 + return gimple_get_lhs(next_stmt);
87661 + case GIMPLE_PHI:
87662 + return gimple_phi_result(next_stmt);
87663 + case GIMPLE_CALL:
87664 + return gimple_call_lhs(next_stmt);
87665 + default:
87666 + return NULL_TREE;
87667 + }
87668 +}
87669 +
87670 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87671 +{
87672 + gimple def_stmt;
87673 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
87674 +
87675 + if (is_gimple_constant(lhs))
87676 + return NULL_TREE;
87677 +
87678 + if (TREE_CODE(lhs) == ADDR_EXPR)
87679 + return NULL_TREE;
87680 +
87681 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
87682 +
87683 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
87684 + check_missing_attribute(lhs);
87685 +
87686 + def_stmt = get_def_stmt(lhs);
87687 +
87688 + if (!def_stmt)
87689 + return NULL_TREE;
87690 +
87691 + if (gimple_plf(def_stmt, MY_STMT))
87692 + return lhs;
87693 +
87694 + if (pointer_set_contains(visited, def_stmt))
87695 + return expand_visited(def_stmt);
87696 +
87697 + switch (gimple_code(def_stmt)) {
87698 + case GIMPLE_NOP:
87699 + check_missing_attribute(lhs);
87700 + return NULL_TREE;
87701 + case GIMPLE_PHI:
87702 + return build_new_phi(visited, potentionally_overflowed, lhs);
87703 + case GIMPLE_CALL:
87704 + case GIMPLE_ASM:
87705 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87706 + case GIMPLE_ASSIGN:
87707 + switch (gimple_num_ops(def_stmt)) {
87708 + case 2:
87709 + return handle_unary_ops(visited, potentionally_overflowed, lhs);
87710 + case 3:
87711 + return handle_binary_ops(visited, potentionally_overflowed, lhs);
87712 +#if BUILDING_GCC_VERSION >= 4007
87713 + case 4:
87714 + return handle_ternary_ops(visited, potentionally_overflowed, lhs);
87715 +#endif
87716 + }
87717 + default:
87718 + debug_gimple_stmt(def_stmt);
87719 + error("expand: unknown gimple code");
87720 + gcc_unreachable();
87721 + }
87722 +}
87723 +
87724 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
87725 +{
87726 + const_gimple assign;
87727 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87728 + tree origtype = TREE_TYPE(origarg);
87729 +
87730 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
87731 +
87732 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87733 +
87734 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
87735 + update_stmt(stmt);
87736 +}
87737 +
87738 +static tree get_function_arg(unsigned int argnum, const_gimple stmt, const_tree fndecl)
87739 +{
87740 + const char *origid;
87741 + tree arg;
87742 + const_tree origarg;
87743 +
87744 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
87745 + gcc_assert(gimple_call_num_args(stmt) > argnum);
87746 + return gimple_call_arg(stmt, argnum);
87747 + }
87748 +
87749 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
87750 + while (origarg && argnum) {
87751 + argnum--;
87752 + origarg = TREE_CHAIN(origarg);
87753 + }
87754 +
87755 + gcc_assert(argnum == 0);
87756 +
87757 + gcc_assert(origarg != NULL_TREE);
87758 + origid = NAME(origarg);
87759 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
87760 + if (!strcmp(origid, NAME(arg)))
87761 + return arg;
87762 + }
87763 + return NULL_TREE;
87764 +}
87765 +
87766 +static void handle_function_arg(gimple stmt, const_tree fndecl, unsigned int argnum)
87767 +{
87768 + struct pointer_set_t *visited;
87769 + tree arg, newarg;
87770 + bool potentionally_overflowed;
87771 +
87772 + arg = get_function_arg(argnum, stmt, fndecl);
87773 + if (arg == NULL_TREE)
87774 + return;
87775 +
87776 + if (is_gimple_constant(arg))
87777 + return;
87778 + if (TREE_CODE(arg) != SSA_NAME)
87779 + return;
87780 +
87781 + check_arg_type(arg);
87782 +
87783 + visited = pointer_set_create();
87784 + potentionally_overflowed = false;
87785 + newarg = expand(visited, &potentionally_overflowed, arg);
87786 + pointer_set_destroy(visited);
87787 +
87788 + if (newarg == NULL_TREE || !potentionally_overflowed)
87789 + return;
87790 +
87791 + change_function_arg(stmt, arg, argnum, newarg);
87792 +
87793 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
87794 +}
87795 +
87796 +static void handle_function_by_attribute(gimple stmt, const_tree attr, const_tree fndecl)
87797 +{
87798 + tree p = TREE_VALUE(attr);
87799 + do {
87800 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
87801 + p = TREE_CHAIN(p);
87802 + } while (p);
87803 +}
87804 +
87805 +static void handle_function_by_hash(gimple stmt, const_tree fndecl)
87806 +{
87807 + const_tree orig_fndecl;
87808 + unsigned int num;
87809 + const struct size_overflow_hash *hash;
87810 +
87811 + orig_fndecl = get_original_function_decl(fndecl);
87812 + hash = get_function_hash(orig_fndecl);
87813 + if (!hash)
87814 + return;
87815 +
87816 + for (num = 1; num <= MAX_PARAM; num++)
87817 + if (hash->param & (1U << num))
87818 + handle_function_arg(stmt, fndecl, num - 1);
87819 +}
87820 +
87821 +static void set_plf_false(void)
87822 +{
87823 + basic_block bb;
87824 +
87825 + FOR_ALL_BB(bb) {
87826 + gimple_stmt_iterator si;
87827 +
87828 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
87829 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87830 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
87831 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87832 + }
87833 +}
87834 +
87835 +static unsigned int handle_function(void)
87836 +{
87837 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
87838 +
87839 + set_plf_false();
87840 +
87841 + do {
87842 + gimple_stmt_iterator gsi;
87843 + next = bb->next_bb;
87844 +
87845 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87846 + const_tree fndecl, attr;
87847 + gimple stmt = gsi_stmt(gsi);
87848 +
87849 + if (!(is_gimple_call(stmt)))
87850 + continue;
87851 + fndecl = gimple_call_fndecl(stmt);
87852 + if (fndecl == NULL_TREE)
87853 + continue;
87854 + if (gimple_call_num_args(stmt) == 0)
87855 + continue;
87856 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
87857 + if (!attr || !TREE_VALUE(attr))
87858 + handle_function_by_hash(stmt, fndecl);
87859 + else
87860 + handle_function_by_attribute(stmt, attr, fndecl);
87861 + gsi = gsi_for_stmt(stmt);
87862 + next = gimple_bb(stmt)->next_bb;
87863 + }
87864 + bb = next;
87865 + } while (bb);
87866 + return 0;
87867 +}
87868 +
87869 +static struct gimple_opt_pass size_overflow_pass = {
87870 + .pass = {
87871 + .type = GIMPLE_PASS,
87872 + .name = "size_overflow",
87873 + .gate = NULL,
87874 + .execute = handle_function,
87875 + .sub = NULL,
87876 + .next = NULL,
87877 + .static_pass_number = 0,
87878 + .tv_id = TV_NONE,
87879 + .properties_required = PROP_cfg | PROP_referenced_vars,
87880 + .properties_provided = 0,
87881 + .properties_destroyed = 0,
87882 + .todo_flags_start = 0,
87883 + .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
87884 + }
87885 +};
87886 +
87887 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
87888 +{
87889 + tree fntype;
87890 +
87891 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
87892 +
87893 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
87894 + fntype = build_function_type_list(void_type_node,
87895 + const_char_ptr_type_node,
87896 + unsigned_type_node,
87897 + const_char_ptr_type_node,
87898 + const_char_ptr_type_node,
87899 + NULL_TREE);
87900 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
87901 +
87902 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
87903 + TREE_PUBLIC(report_size_overflow_decl) = 1;
87904 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
87905 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
87906 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
87907 +}
87908 +
87909 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87910 +{
87911 + int i;
87912 + const char * const plugin_name = plugin_info->base_name;
87913 + const int argc = plugin_info->argc;
87914 + const struct plugin_argument * const argv = plugin_info->argv;
87915 + bool enable = true;
87916 +
87917 + struct register_pass_info size_overflow_pass_info = {
87918 + .pass = &size_overflow_pass.pass,
87919 + .reference_pass_name = "ssa",
87920 + .ref_pass_instance_number = 1,
87921 + .pos_op = PASS_POS_INSERT_AFTER
87922 + };
87923 +
87924 + if (!plugin_default_version_check(version, &gcc_version)) {
87925 + error(G_("incompatible gcc/plugin versions"));
87926 + return 1;
87927 + }
87928 +
87929 + for (i = 0; i < argc; ++i) {
87930 + if (!strcmp(argv[i].key, "no-size-overflow")) {
87931 + enable = false;
87932 + continue;
87933 + }
87934 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87935 + }
87936 +
87937 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
87938 + if (enable) {
87939 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87940 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
87941 + }
87942 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87943 +
87944 + return 0;
87945 +}
87946 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
87947 new file mode 100644
87948 index 0000000..38d2014
87949 --- /dev/null
87950 +++ b/tools/gcc/stackleak_plugin.c
87951 @@ -0,0 +1,313 @@
87952 +/*
87953 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
87954 + * Licensed under the GPL v2
87955 + *
87956 + * Note: the choice of the license means that the compilation process is
87957 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87958 + * but for the kernel it doesn't matter since it doesn't link against
87959 + * any of the gcc libraries
87960 + *
87961 + * gcc plugin to help implement various PaX features
87962 + *
87963 + * - track lowest stack pointer
87964 + *
87965 + * TODO:
87966 + * - initialize all local variables
87967 + *
87968 + * BUGS:
87969 + * - none known
87970 + */
87971 +#include "gcc-plugin.h"
87972 +#include "config.h"
87973 +#include "system.h"
87974 +#include "coretypes.h"
87975 +#include "tree.h"
87976 +#include "tree-pass.h"
87977 +#include "flags.h"
87978 +#include "intl.h"
87979 +#include "toplev.h"
87980 +#include "plugin.h"
87981 +//#include "expr.h" where are you...
87982 +#include "diagnostic.h"
87983 +#include "plugin-version.h"
87984 +#include "tm.h"
87985 +#include "function.h"
87986 +#include "basic-block.h"
87987 +#include "gimple.h"
87988 +#include "rtl.h"
87989 +#include "emit-rtl.h"
87990 +
87991 +extern void print_gimple_stmt(FILE *, gimple, int, int);
87992 +
87993 +int plugin_is_GPL_compatible;
87994 +
87995 +static int track_frame_size = -1;
87996 +static const char track_function[] = "pax_track_stack";
87997 +static const char check_function[] = "pax_check_alloca";
87998 +static bool init_locals;
87999 +
88000 +static struct plugin_info stackleak_plugin_info = {
88001 + .version = "201203140940",
88002 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
88003 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
88004 +};
88005 +
88006 +static bool gate_stackleak_track_stack(void);
88007 +static unsigned int execute_stackleak_tree_instrument(void);
88008 +static unsigned int execute_stackleak_final(void);
88009 +
88010 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
88011 + .pass = {
88012 + .type = GIMPLE_PASS,
88013 + .name = "stackleak_tree_instrument",
88014 + .gate = gate_stackleak_track_stack,
88015 + .execute = execute_stackleak_tree_instrument,
88016 + .sub = NULL,
88017 + .next = NULL,
88018 + .static_pass_number = 0,
88019 + .tv_id = TV_NONE,
88020 + .properties_required = PROP_gimple_leh | PROP_cfg,
88021 + .properties_provided = 0,
88022 + .properties_destroyed = 0,
88023 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
88024 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
88025 + }
88026 +};
88027 +
88028 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
88029 + .pass = {
88030 + .type = RTL_PASS,
88031 + .name = "stackleak_final",
88032 + .gate = gate_stackleak_track_stack,
88033 + .execute = execute_stackleak_final,
88034 + .sub = NULL,
88035 + .next = NULL,
88036 + .static_pass_number = 0,
88037 + .tv_id = TV_NONE,
88038 + .properties_required = 0,
88039 + .properties_provided = 0,
88040 + .properties_destroyed = 0,
88041 + .todo_flags_start = 0,
88042 + .todo_flags_finish = TODO_dump_func
88043 + }
88044 +};
88045 +
88046 +static bool gate_stackleak_track_stack(void)
88047 +{
88048 + return track_frame_size >= 0;
88049 +}
88050 +
88051 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
88052 +{
88053 + gimple check_alloca;
88054 + tree fntype, fndecl, alloca_size;
88055 +
88056 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
88057 + fndecl = build_fn_decl(check_function, fntype);
88058 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
88059 +
88060 + // insert call to void pax_check_alloca(unsigned long size)
88061 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
88062 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
88063 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
88064 +}
88065 +
88066 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
88067 +{
88068 + gimple track_stack;
88069 + tree fntype, fndecl;
88070 +
88071 + fntype = build_function_type_list(void_type_node, NULL_TREE);
88072 + fndecl = build_fn_decl(track_function, fntype);
88073 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
88074 +
88075 + // insert call to void pax_track_stack(void)
88076 + track_stack = gimple_build_call(fndecl, 0);
88077 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
88078 +}
88079 +
88080 +#if BUILDING_GCC_VERSION == 4005
88081 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
88082 +{
88083 + tree fndecl;
88084 +
88085 + if (!is_gimple_call(stmt))
88086 + return false;
88087 + fndecl = gimple_call_fndecl(stmt);
88088 + if (!fndecl)
88089 + return false;
88090 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
88091 + return false;
88092 +// print_node(stderr, "pax", fndecl, 4);
88093 + return DECL_FUNCTION_CODE(fndecl) == code;
88094 +}
88095 +#endif
88096 +
88097 +static bool is_alloca(gimple stmt)
88098 +{
88099 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
88100 + return true;
88101 +
88102 +#if BUILDING_GCC_VERSION >= 4007
88103 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
88104 + return true;
88105 +#endif
88106 +
88107 + return false;
88108 +}
88109 +
88110 +static unsigned int execute_stackleak_tree_instrument(void)
88111 +{
88112 + basic_block bb, entry_bb;
88113 + bool prologue_instrumented = false, is_leaf = true;
88114 +
88115 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
88116 +
88117 + // 1. loop through BBs and GIMPLE statements
88118 + FOR_EACH_BB(bb) {
88119 + gimple_stmt_iterator gsi;
88120 +
88121 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
88122 + gimple stmt;
88123 +
88124 + stmt = gsi_stmt(gsi);
88125 +
88126 + if (is_gimple_call(stmt))
88127 + is_leaf = false;
88128 +
88129 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
88130 + if (!is_alloca(stmt))
88131 + continue;
88132 +
88133 + // 2. insert stack overflow check before each __builtin_alloca call
88134 + stackleak_check_alloca(&gsi);
88135 +
88136 + // 3. insert track call after each __builtin_alloca call
88137 + stackleak_add_instrumentation(&gsi);
88138 + if (bb == entry_bb)
88139 + prologue_instrumented = true;
88140 + }
88141 + }
88142 +
88143 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
88144 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
88145 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
88146 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
88147 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
88148 + return 0;
88149 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
88150 + return 0;
88151 +
88152 + // 4. insert track call at the beginning
88153 + if (!prologue_instrumented) {
88154 + gimple_stmt_iterator gsi;
88155 +
88156 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88157 + if (dom_info_available_p(CDI_DOMINATORS))
88158 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
88159 + gsi = gsi_start_bb(bb);
88160 + stackleak_add_instrumentation(&gsi);
88161 + }
88162 +
88163 + return 0;
88164 +}
88165 +
88166 +static unsigned int execute_stackleak_final(void)
88167 +{
88168 + rtx insn;
88169 +
88170 + if (cfun->calls_alloca)
88171 + return 0;
88172 +
88173 + // keep calls only if function frame is big enough
88174 + if (get_frame_size() >= track_frame_size)
88175 + return 0;
88176 +
88177 + // 1. find pax_track_stack calls
88178 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
88179 + // 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))
88180 + rtx body;
88181 +
88182 + if (!CALL_P(insn))
88183 + continue;
88184 + body = PATTERN(insn);
88185 + if (GET_CODE(body) != CALL)
88186 + continue;
88187 + body = XEXP(body, 0);
88188 + if (GET_CODE(body) != MEM)
88189 + continue;
88190 + body = XEXP(body, 0);
88191 + if (GET_CODE(body) != SYMBOL_REF)
88192 + continue;
88193 + if (strcmp(XSTR(body, 0), track_function))
88194 + continue;
88195 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
88196 + // 2. delete call
88197 + insn = delete_insn_and_edges(insn);
88198 +#if BUILDING_GCC_VERSION >= 4007
88199 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
88200 + insn = delete_insn_and_edges(insn);
88201 +#endif
88202 + }
88203 +
88204 +// print_simple_rtl(stderr, get_insns());
88205 +// print_rtl(stderr, get_insns());
88206 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
88207 +
88208 + return 0;
88209 +}
88210 +
88211 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
88212 +{
88213 + const char * const plugin_name = plugin_info->base_name;
88214 + const int argc = plugin_info->argc;
88215 + const struct plugin_argument * const argv = plugin_info->argv;
88216 + int i;
88217 + struct register_pass_info stackleak_tree_instrument_pass_info = {
88218 + .pass = &stackleak_tree_instrument_pass.pass,
88219 +// .reference_pass_name = "tree_profile",
88220 + .reference_pass_name = "optimized",
88221 + .ref_pass_instance_number = 1,
88222 + .pos_op = PASS_POS_INSERT_BEFORE
88223 + };
88224 + struct register_pass_info stackleak_final_pass_info = {
88225 + .pass = &stackleak_final_rtl_opt_pass.pass,
88226 + .reference_pass_name = "final",
88227 + .ref_pass_instance_number = 1,
88228 + .pos_op = PASS_POS_INSERT_BEFORE
88229 + };
88230 +
88231 + if (!plugin_default_version_check(version, &gcc_version)) {
88232 + error(G_("incompatible gcc/plugin versions"));
88233 + return 1;
88234 + }
88235 +
88236 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
88237 +
88238 + for (i = 0; i < argc; ++i) {
88239 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
88240 + if (!argv[i].value) {
88241 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
88242 + continue;
88243 + }
88244 + track_frame_size = atoi(argv[i].value);
88245 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
88246 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
88247 + continue;
88248 + }
88249 + if (!strcmp(argv[i].key, "initialize-locals")) {
88250 + if (argv[i].value) {
88251 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
88252 + continue;
88253 + }
88254 + init_locals = true;
88255 + continue;
88256 + }
88257 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
88258 + }
88259 +
88260 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
88261 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
88262 +
88263 + return 0;
88264 +}
88265 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
88266 index 6789d78..4afd019e 100644
88267 --- a/tools/perf/util/include/asm/alternative-asm.h
88268 +++ b/tools/perf/util/include/asm/alternative-asm.h
88269 @@ -5,4 +5,7 @@
88270
88271 #define altinstruction_entry #
88272
88273 + .macro pax_force_retaddr rip=0, reload=0
88274 + .endm
88275 +
88276 #endif
88277 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
88278 index af0f22f..9a7d479 100644
88279 --- a/usr/gen_init_cpio.c
88280 +++ b/usr/gen_init_cpio.c
88281 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
88282 int retval;
88283 int rc = -1;
88284 int namesize;
88285 - int i;
88286 + unsigned int i;
88287
88288 mode |= S_IFREG;
88289
88290 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
88291 *env_var = *expanded = '\0';
88292 strncat(env_var, start + 2, end - start - 2);
88293 strncat(expanded, new_location, start - new_location);
88294 - strncat(expanded, getenv(env_var), PATH_MAX);
88295 - strncat(expanded, end + 1, PATH_MAX);
88296 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
88297 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
88298 strncpy(new_location, expanded, PATH_MAX);
88299 + new_location[PATH_MAX] = 0;
88300 } else
88301 break;
88302 }
88303 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
88304 index 44ee712..7da730b 100644
88305 --- a/virt/kvm/kvm_main.c
88306 +++ b/virt/kvm/kvm_main.c
88307 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
88308
88309 static cpumask_var_t cpus_hardware_enabled;
88310 static int kvm_usage_count = 0;
88311 -static atomic_t hardware_enable_failed;
88312 +static atomic_unchecked_t hardware_enable_failed;
88313
88314 struct kmem_cache *kvm_vcpu_cache;
88315 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
88316 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
88317
88318 if (r) {
88319 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
88320 - atomic_inc(&hardware_enable_failed);
88321 + atomic_inc_unchecked(&hardware_enable_failed);
88322 printk(KERN_INFO "kvm: enabling virtualization on "
88323 "CPU%d failed\n", cpu);
88324 }
88325 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
88326
88327 kvm_usage_count++;
88328 if (kvm_usage_count == 1) {
88329 - atomic_set(&hardware_enable_failed, 0);
88330 + atomic_set_unchecked(&hardware_enable_failed, 0);
88331 on_each_cpu(hardware_enable_nolock, NULL, 1);
88332
88333 - if (atomic_read(&hardware_enable_failed)) {
88334 + if (atomic_read_unchecked(&hardware_enable_failed)) {
88335 hardware_disable_all_nolock();
88336 r = -EBUSY;
88337 }
88338 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
88339 kvm_arch_vcpu_put(vcpu);
88340 }
88341
88342 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88343 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88344 struct module *module)
88345 {
88346 int r;
88347 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88348 if (!vcpu_align)
88349 vcpu_align = __alignof__(struct kvm_vcpu);
88350 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
88351 - 0, NULL);
88352 + SLAB_USERCOPY, NULL);
88353 if (!kvm_vcpu_cache) {
88354 r = -ENOMEM;
88355 goto out_free_3;
88356 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88357 if (r)
88358 goto out_free;
88359
88360 - kvm_chardev_ops.owner = module;
88361 - kvm_vm_fops.owner = module;
88362 - kvm_vcpu_fops.owner = module;
88363 + pax_open_kernel();
88364 + *(void **)&kvm_chardev_ops.owner = module;
88365 + *(void **)&kvm_vm_fops.owner = module;
88366 + *(void **)&kvm_vcpu_fops.owner = module;
88367 + pax_close_kernel();
88368
88369 r = misc_register(&kvm_dev);
88370 if (r) {