]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.0-201208052125.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.0-201208052125.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 4bb09e1..d2e3cb6 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 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 +$(sort $(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379 +$(sort $(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..9269ea1 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 +" sub %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 +" sbc %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 +" sbc %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 +
1394 +#ifdef CONFIG_PAX_REFCOUNT
1395 +" bvc 3f\n"
1396 +"2: bkpt 0xf103\n"
1397 +"3:\n"
1398 +#endif
1399 +
1400 " strexd %2, %0, %H0, [%4]\n"
1401 " teq %2, #0\n"
1402 " bne 1b\n"
1403 -"2:"
1404 +"4:\n"
1405 +
1406 +#ifdef CONFIG_PAX_REFCOUNT
1407 + _ASM_EXTABLE(2b, 4b)
1408 +#endif
1409 +
1410 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1411 : "r" (&v->counter), "r" (u), "r" (a)
1412 : "cc");
1413 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1414
1415 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1416 #define atomic64_inc(v) atomic64_add(1LL, (v))
1417 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1418 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1419 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1420 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1421 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1422 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1423 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1424 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1425 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1426 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1427 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1428 index 75fe66b..2255c86 100644
1429 --- a/arch/arm/include/asm/cache.h
1430 +++ b/arch/arm/include/asm/cache.h
1431 @@ -4,8 +4,10 @@
1432 #ifndef __ASMARM_CACHE_H
1433 #define __ASMARM_CACHE_H
1434
1435 +#include <linux/const.h>
1436 +
1437 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1438 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1439 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1440
1441 /*
1442 * Memory returned by kmalloc() may be used for DMA, so we must make
1443 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1444 index 004c1bc..d9d6d91 100644
1445 --- a/arch/arm/include/asm/cacheflush.h
1446 +++ b/arch/arm/include/asm/cacheflush.h
1447 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1448 void (*dma_unmap_area)(const void *, size_t, int);
1449
1450 void (*dma_flush_range)(const void *, const void *);
1451 -};
1452 +} __no_const;
1453
1454 /*
1455 * Select the calling method
1456 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1457 index 7eb18c1..e38b6d2 100644
1458 --- a/arch/arm/include/asm/cmpxchg.h
1459 +++ b/arch/arm/include/asm/cmpxchg.h
1460 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1461
1462 #define xchg(ptr,x) \
1463 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1464 +#define xchg_unchecked(ptr,x) \
1465 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1466
1467 #include <asm-generic/cmpxchg-local.h>
1468
1469 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1470 index 38050b1..9d90e8b 100644
1471 --- a/arch/arm/include/asm/elf.h
1472 +++ b/arch/arm/include/asm/elf.h
1473 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1474 the loader. We need to make sure that it is out of the way of the program
1475 that it will "exec", and that there is sufficient room for the brk. */
1476
1477 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1478 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1479 +
1480 +#ifdef CONFIG_PAX_ASLR
1481 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1482 +
1483 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1484 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485 +#endif
1486
1487 /* When the program starts, a1 contains a pointer to a function to be
1488 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1489 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1490 extern void elf_set_personality(const struct elf32_hdr *);
1491 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1492
1493 -struct mm_struct;
1494 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1495 -#define arch_randomize_brk arch_randomize_brk
1496 -
1497 #endif
1498 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1499 index e51b1e8..32a3113 100644
1500 --- a/arch/arm/include/asm/kmap_types.h
1501 +++ b/arch/arm/include/asm/kmap_types.h
1502 @@ -21,6 +21,7 @@ enum km_type {
1503 KM_L1_CACHE,
1504 KM_L2_CACHE,
1505 KM_KDB,
1506 + KM_CLEARPAGE,
1507 KM_TYPE_NR
1508 };
1509
1510 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1511 index 53426c6..c7baff3 100644
1512 --- a/arch/arm/include/asm/outercache.h
1513 +++ b/arch/arm/include/asm/outercache.h
1514 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1515 #endif
1516 void (*set_debug)(unsigned long);
1517 void (*resume)(void);
1518 -};
1519 +} __no_const;
1520
1521 #ifdef CONFIG_OUTER_CACHE
1522
1523 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1524 index ecf9019..b71d9a1 100644
1525 --- a/arch/arm/include/asm/page.h
1526 +++ b/arch/arm/include/asm/page.h
1527 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1528 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1529 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1530 unsigned long vaddr, struct vm_area_struct *vma);
1531 -};
1532 +} __no_const;
1533
1534 #ifdef MULTI_USER
1535 extern struct cpu_user_fns cpu_user;
1536 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1537 index 943504f..bf8d667 100644
1538 --- a/arch/arm/include/asm/pgalloc.h
1539 +++ b/arch/arm/include/asm/pgalloc.h
1540 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1541 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1542 }
1543
1544 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1545 +{
1546 + pud_populate(mm, pud, pmd);
1547 +}
1548 +
1549 #else /* !CONFIG_ARM_LPAE */
1550
1551 /*
1552 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1553 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1554 #define pmd_free(mm, pmd) do { } while (0)
1555 #define pud_populate(mm,pmd,pte) BUG()
1556 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1557
1558 #endif /* CONFIG_ARM_LPAE */
1559
1560 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1561 index af7b0bd..6750a8c 100644
1562 --- a/arch/arm/include/asm/thread_info.h
1563 +++ b/arch/arm/include/asm/thread_info.h
1564 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1565 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1566 #define TIF_SYSCALL_TRACE 8
1567 #define TIF_SYSCALL_AUDIT 9
1568 +
1569 +/* within 8 bits of TIF_SYSCALL_TRACE
1570 + to meet flexible second operand requirements
1571 +*/
1572 +#define TIF_GRSEC_SETXID 10
1573 +
1574 #define TIF_POLLING_NRFLAG 16
1575 #define TIF_USING_IWMMXT 17
1576 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1577 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1578 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1579 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1580 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1581 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1582
1583 /* Checks for any syscall work in entry-common.S */
1584 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1585 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1586 + _TIF_GRSEC_SETXID)
1587
1588 /*
1589 * Change these and you break ASM code in entry-common.S
1590 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1591 index 71f6536..602f279 100644
1592 --- a/arch/arm/include/asm/uaccess.h
1593 +++ b/arch/arm/include/asm/uaccess.h
1594 @@ -22,6 +22,8 @@
1595 #define VERIFY_READ 0
1596 #define VERIFY_WRITE 1
1597
1598 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1599 +
1600 /*
1601 * The exception table consists of pairs of addresses: the first is the
1602 * address of an instruction that is allowed to fault, and the second is
1603 @@ -387,8 +389,23 @@ do { \
1604
1605
1606 #ifdef CONFIG_MMU
1607 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1608 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1609 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1610 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1611 +
1612 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1613 +{
1614 + if (!__builtin_constant_p(n))
1615 + check_object_size(to, n, false);
1616 + return ___copy_from_user(to, from, n);
1617 +}
1618 +
1619 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1620 +{
1621 + if (!__builtin_constant_p(n))
1622 + check_object_size(from, n, true);
1623 + return ___copy_to_user(to, from, n);
1624 +}
1625 +
1626 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1627 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1628 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1629 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1630
1631 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1632 {
1633 + if ((long)n < 0)
1634 + return n;
1635 +
1636 if (access_ok(VERIFY_READ, from, n))
1637 n = __copy_from_user(to, from, n);
1638 else /* security hole - plug it */
1639 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1640
1641 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1642 {
1643 + if ((long)n < 0)
1644 + return n;
1645 +
1646 if (access_ok(VERIFY_WRITE, to, n))
1647 n = __copy_to_user(to, from, n);
1648 return n;
1649 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1650 index b57c75e..ed2d6b2 100644
1651 --- a/arch/arm/kernel/armksyms.c
1652 +++ b/arch/arm/kernel/armksyms.c
1653 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1654 #ifdef CONFIG_MMU
1655 EXPORT_SYMBOL(copy_page);
1656
1657 -EXPORT_SYMBOL(__copy_from_user);
1658 -EXPORT_SYMBOL(__copy_to_user);
1659 +EXPORT_SYMBOL(___copy_from_user);
1660 +EXPORT_SYMBOL(___copy_to_user);
1661 EXPORT_SYMBOL(__clear_user);
1662
1663 EXPORT_SYMBOL(__get_user_1);
1664 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1665 index 19c95ea..7160f7c 100644
1666 --- a/arch/arm/kernel/process.c
1667 +++ b/arch/arm/kernel/process.c
1668 @@ -28,7 +28,6 @@
1669 #include <linux/tick.h>
1670 #include <linux/utsname.h>
1671 #include <linux/uaccess.h>
1672 -#include <linux/random.h>
1673 #include <linux/hw_breakpoint.h>
1674 #include <linux/cpuidle.h>
1675
1676 @@ -255,9 +254,10 @@ void machine_power_off(void)
1677 machine_shutdown();
1678 if (pm_power_off)
1679 pm_power_off();
1680 + BUG();
1681 }
1682
1683 -void machine_restart(char *cmd)
1684 +__noreturn void machine_restart(char *cmd)
1685 {
1686 machine_shutdown();
1687
1688 @@ -499,12 +499,6 @@ unsigned long get_wchan(struct task_struct *p)
1689 return 0;
1690 }
1691
1692 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1693 -{
1694 - unsigned long range_end = mm->brk + 0x02000000;
1695 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1696 -}
1697 -
1698 #ifdef CONFIG_MMU
1699 /*
1700 * The vectors page is always readable from user space for the
1701 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1702 index 14e3826..d832d89 100644
1703 --- a/arch/arm/kernel/ptrace.c
1704 +++ b/arch/arm/kernel/ptrace.c
1705 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1706 return ret;
1707 }
1708
1709 +#ifdef CONFIG_GRKERNSEC_SETXID
1710 +extern void gr_delayed_cred_worker(void);
1711 +#endif
1712 +
1713 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1714 {
1715 unsigned long ip;
1716
1717 +#ifdef CONFIG_GRKERNSEC_SETXID
1718 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1719 + gr_delayed_cred_worker();
1720 +#endif
1721 +
1722 if (why)
1723 audit_syscall_exit(regs);
1724 else
1725 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1726 index e15d83b..8c466dd 100644
1727 --- a/arch/arm/kernel/setup.c
1728 +++ b/arch/arm/kernel/setup.c
1729 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1730 struct cpu_tlb_fns cpu_tlb __read_mostly;
1731 #endif
1732 #ifdef MULTI_USER
1733 -struct cpu_user_fns cpu_user __read_mostly;
1734 +struct cpu_user_fns cpu_user __read_only;
1735 #endif
1736 #ifdef MULTI_CACHE
1737 -struct cpu_cache_fns cpu_cache __read_mostly;
1738 +struct cpu_cache_fns cpu_cache __read_only;
1739 #endif
1740 #ifdef CONFIG_OUTER_CACHE
1741 -struct outer_cache_fns outer_cache __read_mostly;
1742 +struct outer_cache_fns outer_cache __read_only;
1743 EXPORT_SYMBOL(outer_cache);
1744 #endif
1745
1746 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1747 index 3647170..065e1cd 100644
1748 --- a/arch/arm/kernel/traps.c
1749 +++ b/arch/arm/kernel/traps.c
1750 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1751
1752 static DEFINE_RAW_SPINLOCK(die_lock);
1753
1754 +extern void gr_handle_kernel_exploit(void);
1755 +
1756 /*
1757 * This function is protected against re-entrancy.
1758 */
1759 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1760 panic("Fatal exception in interrupt");
1761 if (panic_on_oops)
1762 panic("Fatal exception");
1763 +
1764 + gr_handle_kernel_exploit();
1765 +
1766 if (ret != NOTIFY_STOP)
1767 do_exit(SIGSEGV);
1768 }
1769 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1770 index 66a477a..bee61d3 100644
1771 --- a/arch/arm/lib/copy_from_user.S
1772 +++ b/arch/arm/lib/copy_from_user.S
1773 @@ -16,7 +16,7 @@
1774 /*
1775 * Prototype:
1776 *
1777 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1778 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1779 *
1780 * Purpose:
1781 *
1782 @@ -84,11 +84,11 @@
1783
1784 .text
1785
1786 -ENTRY(__copy_from_user)
1787 +ENTRY(___copy_from_user)
1788
1789 #include "copy_template.S"
1790
1791 -ENDPROC(__copy_from_user)
1792 +ENDPROC(___copy_from_user)
1793
1794 .pushsection .fixup,"ax"
1795 .align 0
1796 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1797 index 6ee2f67..d1cce76 100644
1798 --- a/arch/arm/lib/copy_page.S
1799 +++ b/arch/arm/lib/copy_page.S
1800 @@ -10,6 +10,7 @@
1801 * ASM optimised string functions
1802 */
1803 #include <linux/linkage.h>
1804 +#include <linux/const.h>
1805 #include <asm/assembler.h>
1806 #include <asm/asm-offsets.h>
1807 #include <asm/cache.h>
1808 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1809 index d066df6..df28194 100644
1810 --- a/arch/arm/lib/copy_to_user.S
1811 +++ b/arch/arm/lib/copy_to_user.S
1812 @@ -16,7 +16,7 @@
1813 /*
1814 * Prototype:
1815 *
1816 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1817 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1818 *
1819 * Purpose:
1820 *
1821 @@ -88,11 +88,11 @@
1822 .text
1823
1824 ENTRY(__copy_to_user_std)
1825 -WEAK(__copy_to_user)
1826 +WEAK(___copy_to_user)
1827
1828 #include "copy_template.S"
1829
1830 -ENDPROC(__copy_to_user)
1831 +ENDPROC(___copy_to_user)
1832 ENDPROC(__copy_to_user_std)
1833
1834 .pushsection .fixup,"ax"
1835 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1836 index 025f742..8432b08 100644
1837 --- a/arch/arm/lib/uaccess_with_memcpy.c
1838 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1839 @@ -104,7 +104,7 @@ out:
1840 }
1841
1842 unsigned long
1843 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1844 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1845 {
1846 /*
1847 * This test is stubbed out of the main function above to keep
1848 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1849 index 2c5d0ed..7d9099c 100644
1850 --- a/arch/arm/mach-omap2/board-n8x0.c
1851 +++ b/arch/arm/mach-omap2/board-n8x0.c
1852 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1853 }
1854 #endif
1855
1856 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1857 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1858 .late_init = n8x0_menelaus_late_init,
1859 };
1860
1861 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1862 index c3bd834..e81ef02 100644
1863 --- a/arch/arm/mm/fault.c
1864 +++ b/arch/arm/mm/fault.c
1865 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1866 }
1867 #endif
1868
1869 +#ifdef CONFIG_PAX_PAGEEXEC
1870 + if (fsr & FSR_LNX_PF) {
1871 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1872 + do_group_exit(SIGKILL);
1873 + }
1874 +#endif
1875 +
1876 tsk->thread.address = addr;
1877 tsk->thread.error_code = fsr;
1878 tsk->thread.trap_no = 14;
1879 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1880 }
1881 #endif /* CONFIG_MMU */
1882
1883 +#ifdef CONFIG_PAX_PAGEEXEC
1884 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1885 +{
1886 + long i;
1887 +
1888 + printk(KERN_ERR "PAX: bytes at PC: ");
1889 + for (i = 0; i < 20; i++) {
1890 + unsigned char c;
1891 + if (get_user(c, (__force unsigned char __user *)pc+i))
1892 + printk(KERN_CONT "?? ");
1893 + else
1894 + printk(KERN_CONT "%02x ", c);
1895 + }
1896 + printk("\n");
1897 +
1898 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1899 + for (i = -1; i < 20; i++) {
1900 + unsigned long c;
1901 + if (get_user(c, (__force unsigned long __user *)sp+i))
1902 + printk(KERN_CONT "???????? ");
1903 + else
1904 + printk(KERN_CONT "%08lx ", c);
1905 + }
1906 + printk("\n");
1907 +}
1908 +#endif
1909 +
1910 /*
1911 * First Level Translation Fault Handler
1912 *
1913 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1914 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1915 struct siginfo info;
1916
1917 +#ifdef CONFIG_PAX_REFCOUNT
1918 + if (fsr_fs(ifsr) == 2) {
1919 + unsigned int bkpt;
1920 +
1921 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1922 + current->thread.error_code = ifsr;
1923 + current->thread.trap_no = 0;
1924 + pax_report_refcount_overflow(regs);
1925 + fixup_exception(regs);
1926 + return;
1927 + }
1928 + }
1929 +#endif
1930 +
1931 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1932 return;
1933
1934 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1935 index ce8cb19..3ec539d 100644
1936 --- a/arch/arm/mm/mmap.c
1937 +++ b/arch/arm/mm/mmap.c
1938 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1939 if (len > TASK_SIZE)
1940 return -ENOMEM;
1941
1942 +#ifdef CONFIG_PAX_RANDMMAP
1943 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1944 +#endif
1945 +
1946 if (addr) {
1947 if (do_align)
1948 addr = COLOUR_ALIGN(addr, pgoff);
1949 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1950 addr = PAGE_ALIGN(addr);
1951
1952 vma = find_vma(mm, addr);
1953 - if (TASK_SIZE - len >= addr &&
1954 - (!vma || addr + len <= vma->vm_start))
1955 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1956 return addr;
1957 }
1958 if (len > mm->cached_hole_size) {
1959 - start_addr = addr = mm->free_area_cache;
1960 + start_addr = addr = mm->free_area_cache;
1961 } else {
1962 - start_addr = addr = mm->mmap_base;
1963 - mm->cached_hole_size = 0;
1964 + start_addr = addr = mm->mmap_base;
1965 + mm->cached_hole_size = 0;
1966 }
1967
1968 full_search:
1969 @@ -124,14 +127,14 @@ full_search:
1970 * Start a new search - just in case we missed
1971 * some holes.
1972 */
1973 - if (start_addr != TASK_UNMAPPED_BASE) {
1974 - start_addr = addr = TASK_UNMAPPED_BASE;
1975 + if (start_addr != mm->mmap_base) {
1976 + start_addr = addr = mm->mmap_base;
1977 mm->cached_hole_size = 0;
1978 goto full_search;
1979 }
1980 return -ENOMEM;
1981 }
1982 - if (!vma || addr + len <= vma->vm_start) {
1983 + if (check_heap_stack_gap(vma, addr, len)) {
1984 /*
1985 * Remember the place where we stopped the search:
1986 */
1987 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1988
1989 if (mmap_is_legacy()) {
1990 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1991 +
1992 +#ifdef CONFIG_PAX_RANDMMAP
1993 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1994 + mm->mmap_base += mm->delta_mmap;
1995 +#endif
1996 +
1997 mm->get_unmapped_area = arch_get_unmapped_area;
1998 mm->unmap_area = arch_unmap_area;
1999 } else {
2000 mm->mmap_base = mmap_base(random_factor);
2001 +
2002 +#ifdef CONFIG_PAX_RANDMMAP
2003 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2004 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2005 +#endif
2006 +
2007 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2008 mm->unmap_area = arch_unmap_area_topdown;
2009 }
2010 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2011 index fd556f7..af2e7d2 100644
2012 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2013 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2014 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2015 value in bridge_virt_base */
2016 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2017 const int win);
2018 -};
2019 +} __no_const;
2020
2021 /*
2022 * Information needed to setup one address mapping.
2023 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2024 index 71a6827..e7fbc23 100644
2025 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2026 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2027 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2028 int (*started)(unsigned ch);
2029 int (*flush)(unsigned ch);
2030 int (*stop)(unsigned ch);
2031 -};
2032 +} __no_const;
2033
2034 extern void *samsung_dmadev_get_ops(void);
2035 extern void *s3c_dma_get_ops(void);
2036 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2037 index 5f28cae..3d23723 100644
2038 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2039 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2040 @@ -14,7 +14,7 @@
2041 struct s5p_ehci_platdata {
2042 int (*phy_init)(struct platform_device *pdev, int type);
2043 int (*phy_exit)(struct platform_device *pdev, int type);
2044 -};
2045 +} __no_const;
2046
2047 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2048
2049 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2050 index c3a58a1..78fbf54 100644
2051 --- a/arch/avr32/include/asm/cache.h
2052 +++ b/arch/avr32/include/asm/cache.h
2053 @@ -1,8 +1,10 @@
2054 #ifndef __ASM_AVR32_CACHE_H
2055 #define __ASM_AVR32_CACHE_H
2056
2057 +#include <linux/const.h>
2058 +
2059 #define L1_CACHE_SHIFT 5
2060 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2061 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2062
2063 /*
2064 * Memory returned by kmalloc() may be used for DMA, so we must make
2065 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2066 index 3b3159b..425ea94 100644
2067 --- a/arch/avr32/include/asm/elf.h
2068 +++ b/arch/avr32/include/asm/elf.h
2069 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2070 the loader. We need to make sure that it is out of the way of the program
2071 that it will "exec", and that there is sufficient room for the brk. */
2072
2073 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2074 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2075
2076 +#ifdef CONFIG_PAX_ASLR
2077 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2078 +
2079 +#define PAX_DELTA_MMAP_LEN 15
2080 +#define PAX_DELTA_STACK_LEN 15
2081 +#endif
2082
2083 /* This yields a mask that user programs can use to figure out what
2084 instruction set this CPU supports. This could be done in user space,
2085 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2086 index b7f5c68..556135c 100644
2087 --- a/arch/avr32/include/asm/kmap_types.h
2088 +++ b/arch/avr32/include/asm/kmap_types.h
2089 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2090 D(11) KM_IRQ1,
2091 D(12) KM_SOFTIRQ0,
2092 D(13) KM_SOFTIRQ1,
2093 -D(14) KM_TYPE_NR
2094 +D(14) KM_CLEARPAGE,
2095 +D(15) KM_TYPE_NR
2096 };
2097
2098 #undef D
2099 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2100 index f7040a1..db9f300 100644
2101 --- a/arch/avr32/mm/fault.c
2102 +++ b/arch/avr32/mm/fault.c
2103 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2104
2105 int exception_trace = 1;
2106
2107 +#ifdef CONFIG_PAX_PAGEEXEC
2108 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2109 +{
2110 + unsigned long i;
2111 +
2112 + printk(KERN_ERR "PAX: bytes at PC: ");
2113 + for (i = 0; i < 20; i++) {
2114 + unsigned char c;
2115 + if (get_user(c, (unsigned char *)pc+i))
2116 + printk(KERN_CONT "???????? ");
2117 + else
2118 + printk(KERN_CONT "%02x ", c);
2119 + }
2120 + printk("\n");
2121 +}
2122 +#endif
2123 +
2124 /*
2125 * This routine handles page faults. It determines the address and the
2126 * problem, and then passes it off to one of the appropriate routines.
2127 @@ -156,6 +173,16 @@ bad_area:
2128 up_read(&mm->mmap_sem);
2129
2130 if (user_mode(regs)) {
2131 +
2132 +#ifdef CONFIG_PAX_PAGEEXEC
2133 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2134 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2135 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2136 + do_group_exit(SIGKILL);
2137 + }
2138 + }
2139 +#endif
2140 +
2141 if (exception_trace && printk_ratelimit())
2142 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2143 "sp %08lx ecr %lu\n",
2144 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2145 index 568885a..f8008df 100644
2146 --- a/arch/blackfin/include/asm/cache.h
2147 +++ b/arch/blackfin/include/asm/cache.h
2148 @@ -7,6 +7,7 @@
2149 #ifndef __ARCH_BLACKFIN_CACHE_H
2150 #define __ARCH_BLACKFIN_CACHE_H
2151
2152 +#include <linux/const.h>
2153 #include <linux/linkage.h> /* for asmlinkage */
2154
2155 /*
2156 @@ -14,7 +15,7 @@
2157 * Blackfin loads 32 bytes for cache
2158 */
2159 #define L1_CACHE_SHIFT 5
2160 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2161 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2162 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2163
2164 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2165 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2166 index aea2718..3639a60 100644
2167 --- a/arch/cris/include/arch-v10/arch/cache.h
2168 +++ b/arch/cris/include/arch-v10/arch/cache.h
2169 @@ -1,8 +1,9 @@
2170 #ifndef _ASM_ARCH_CACHE_H
2171 #define _ASM_ARCH_CACHE_H
2172
2173 +#include <linux/const.h>
2174 /* Etrax 100LX have 32-byte cache-lines. */
2175 -#define L1_CACHE_BYTES 32
2176 #define L1_CACHE_SHIFT 5
2177 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2178
2179 #endif /* _ASM_ARCH_CACHE_H */
2180 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2181 index 7caf25d..ee65ac5 100644
2182 --- a/arch/cris/include/arch-v32/arch/cache.h
2183 +++ b/arch/cris/include/arch-v32/arch/cache.h
2184 @@ -1,11 +1,12 @@
2185 #ifndef _ASM_CRIS_ARCH_CACHE_H
2186 #define _ASM_CRIS_ARCH_CACHE_H
2187
2188 +#include <linux/const.h>
2189 #include <arch/hwregs/dma.h>
2190
2191 /* A cache-line is 32 bytes. */
2192 -#define L1_CACHE_BYTES 32
2193 #define L1_CACHE_SHIFT 5
2194 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2195
2196 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2197
2198 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2199 index b86329d..6709906 100644
2200 --- a/arch/frv/include/asm/atomic.h
2201 +++ b/arch/frv/include/asm/atomic.h
2202 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2203 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2204 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2205
2206 +#define atomic64_read_unchecked(v) atomic64_read(v)
2207 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2208 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2209 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2210 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2211 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2212 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2213 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2214 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2215 +
2216 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2217 {
2218 int c, old;
2219 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2220 index 2797163..c2a401d 100644
2221 --- a/arch/frv/include/asm/cache.h
2222 +++ b/arch/frv/include/asm/cache.h
2223 @@ -12,10 +12,11 @@
2224 #ifndef __ASM_CACHE_H
2225 #define __ASM_CACHE_H
2226
2227 +#include <linux/const.h>
2228
2229 /* bytes per L1 cache line */
2230 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2231 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2232 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2233
2234 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2235 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2236 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2237 index f8e16b2..c73ff79 100644
2238 --- a/arch/frv/include/asm/kmap_types.h
2239 +++ b/arch/frv/include/asm/kmap_types.h
2240 @@ -23,6 +23,7 @@ enum km_type {
2241 KM_IRQ1,
2242 KM_SOFTIRQ0,
2243 KM_SOFTIRQ1,
2244 + KM_CLEARPAGE,
2245 KM_TYPE_NR
2246 };
2247
2248 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2249 index 385fd30..6c3d97e 100644
2250 --- a/arch/frv/mm/elf-fdpic.c
2251 +++ b/arch/frv/mm/elf-fdpic.c
2252 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2253 if (addr) {
2254 addr = PAGE_ALIGN(addr);
2255 vma = find_vma(current->mm, addr);
2256 - if (TASK_SIZE - len >= addr &&
2257 - (!vma || addr + len <= vma->vm_start))
2258 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2259 goto success;
2260 }
2261
2262 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 for (; vma; vma = vma->vm_next) {
2264 if (addr > limit)
2265 break;
2266 - if (addr + len <= vma->vm_start)
2267 + if (check_heap_stack_gap(vma, addr, len))
2268 goto success;
2269 addr = vma->vm_end;
2270 }
2271 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2272 for (; vma; vma = vma->vm_next) {
2273 if (addr > limit)
2274 break;
2275 - if (addr + len <= vma->vm_start)
2276 + if (check_heap_stack_gap(vma, addr, len))
2277 goto success;
2278 addr = vma->vm_end;
2279 }
2280 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2281 index c635028..6d9445a 100644
2282 --- a/arch/h8300/include/asm/cache.h
2283 +++ b/arch/h8300/include/asm/cache.h
2284 @@ -1,8 +1,10 @@
2285 #ifndef __ARCH_H8300_CACHE_H
2286 #define __ARCH_H8300_CACHE_H
2287
2288 +#include <linux/const.h>
2289 +
2290 /* bytes per L1 cache line */
2291 -#define L1_CACHE_BYTES 4
2292 +#define L1_CACHE_BYTES _AC(4,UL)
2293
2294 /* m68k-elf-gcc 2.95.2 doesn't like these */
2295
2296 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2297 index 0f01de2..d37d309 100644
2298 --- a/arch/hexagon/include/asm/cache.h
2299 +++ b/arch/hexagon/include/asm/cache.h
2300 @@ -21,9 +21,11 @@
2301 #ifndef __ASM_CACHE_H
2302 #define __ASM_CACHE_H
2303
2304 +#include <linux/const.h>
2305 +
2306 /* Bytes per L1 cache line */
2307 -#define L1_CACHE_SHIFT (5)
2308 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2309 +#define L1_CACHE_SHIFT 5
2310 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2311
2312 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2313 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2314 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2315 index 7d91166..88ab87e 100644
2316 --- a/arch/ia64/include/asm/atomic.h
2317 +++ b/arch/ia64/include/asm/atomic.h
2318 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2319 #define atomic64_inc(v) atomic64_add(1, (v))
2320 #define atomic64_dec(v) atomic64_sub(1, (v))
2321
2322 +#define atomic64_read_unchecked(v) atomic64_read(v)
2323 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2324 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2325 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2326 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2327 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2328 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2329 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2330 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2331 +
2332 /* Atomic operations are already serializing */
2333 #define smp_mb__before_atomic_dec() barrier()
2334 #define smp_mb__after_atomic_dec() barrier()
2335 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2336 index 988254a..e1ee885 100644
2337 --- a/arch/ia64/include/asm/cache.h
2338 +++ b/arch/ia64/include/asm/cache.h
2339 @@ -1,6 +1,7 @@
2340 #ifndef _ASM_IA64_CACHE_H
2341 #define _ASM_IA64_CACHE_H
2342
2343 +#include <linux/const.h>
2344
2345 /*
2346 * Copyright (C) 1998-2000 Hewlett-Packard Co
2347 @@ -9,7 +10,7 @@
2348
2349 /* Bytes per L1 (data) cache line. */
2350 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2351 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2352 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2353
2354 #ifdef CONFIG_SMP
2355 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2356 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2357 index b5298eb..67c6e62 100644
2358 --- a/arch/ia64/include/asm/elf.h
2359 +++ b/arch/ia64/include/asm/elf.h
2360 @@ -42,6 +42,13 @@
2361 */
2362 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2363
2364 +#ifdef CONFIG_PAX_ASLR
2365 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2366 +
2367 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2368 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2369 +#endif
2370 +
2371 #define PT_IA_64_UNWIND 0x70000001
2372
2373 /* IA-64 relocations: */
2374 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2375 index 96a8d92..617a1cf 100644
2376 --- a/arch/ia64/include/asm/pgalloc.h
2377 +++ b/arch/ia64/include/asm/pgalloc.h
2378 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2379 pgd_val(*pgd_entry) = __pa(pud);
2380 }
2381
2382 +static inline void
2383 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2384 +{
2385 + pgd_populate(mm, pgd_entry, pud);
2386 +}
2387 +
2388 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2389 {
2390 return quicklist_alloc(0, GFP_KERNEL, NULL);
2391 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2392 pud_val(*pud_entry) = __pa(pmd);
2393 }
2394
2395 +static inline void
2396 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2397 +{
2398 + pud_populate(mm, pud_entry, pmd);
2399 +}
2400 +
2401 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2402 {
2403 return quicklist_alloc(0, GFP_KERNEL, NULL);
2404 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2405 index 815810c..d60bd4c 100644
2406 --- a/arch/ia64/include/asm/pgtable.h
2407 +++ b/arch/ia64/include/asm/pgtable.h
2408 @@ -12,7 +12,7 @@
2409 * David Mosberger-Tang <davidm@hpl.hp.com>
2410 */
2411
2412 -
2413 +#include <linux/const.h>
2414 #include <asm/mman.h>
2415 #include <asm/page.h>
2416 #include <asm/processor.h>
2417 @@ -142,6 +142,17 @@
2418 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2420 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2421 +
2422 +#ifdef CONFIG_PAX_PAGEEXEC
2423 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2424 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2425 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2426 +#else
2427 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2428 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2429 +# define PAGE_COPY_NOEXEC PAGE_COPY
2430 +#endif
2431 +
2432 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2433 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2434 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2435 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2436 index 54ff557..70c88b7 100644
2437 --- a/arch/ia64/include/asm/spinlock.h
2438 +++ b/arch/ia64/include/asm/spinlock.h
2439 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2440 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2441
2442 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2443 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2444 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2445 }
2446
2447 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2448 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2449 index 449c8c0..432a3d2 100644
2450 --- a/arch/ia64/include/asm/uaccess.h
2451 +++ b/arch/ia64/include/asm/uaccess.h
2452 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2453 const void *__cu_from = (from); \
2454 long __cu_len = (n); \
2455 \
2456 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2457 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2458 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2459 __cu_len; \
2460 })
2461 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2462 long __cu_len = (n); \
2463 \
2464 __chk_user_ptr(__cu_from); \
2465 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2466 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2467 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2468 __cu_len; \
2469 })
2470 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2471 index 24603be..948052d 100644
2472 --- a/arch/ia64/kernel/module.c
2473 +++ b/arch/ia64/kernel/module.c
2474 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2475 void
2476 module_free (struct module *mod, void *module_region)
2477 {
2478 - if (mod && mod->arch.init_unw_table &&
2479 - module_region == mod->module_init) {
2480 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2481 unw_remove_unwind_table(mod->arch.init_unw_table);
2482 mod->arch.init_unw_table = NULL;
2483 }
2484 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2485 }
2486
2487 static inline int
2488 +in_init_rx (const struct module *mod, uint64_t addr)
2489 +{
2490 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2491 +}
2492 +
2493 +static inline int
2494 +in_init_rw (const struct module *mod, uint64_t addr)
2495 +{
2496 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2497 +}
2498 +
2499 +static inline int
2500 in_init (const struct module *mod, uint64_t addr)
2501 {
2502 - return addr - (uint64_t) mod->module_init < mod->init_size;
2503 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2504 +}
2505 +
2506 +static inline int
2507 +in_core_rx (const struct module *mod, uint64_t addr)
2508 +{
2509 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2510 +}
2511 +
2512 +static inline int
2513 +in_core_rw (const struct module *mod, uint64_t addr)
2514 +{
2515 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2516 }
2517
2518 static inline int
2519 in_core (const struct module *mod, uint64_t addr)
2520 {
2521 - return addr - (uint64_t) mod->module_core < mod->core_size;
2522 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2523 }
2524
2525 static inline int
2526 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2527 break;
2528
2529 case RV_BDREL:
2530 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2531 + if (in_init_rx(mod, val))
2532 + val -= (uint64_t) mod->module_init_rx;
2533 + else if (in_init_rw(mod, val))
2534 + val -= (uint64_t) mod->module_init_rw;
2535 + else if (in_core_rx(mod, val))
2536 + val -= (uint64_t) mod->module_core_rx;
2537 + else if (in_core_rw(mod, val))
2538 + val -= (uint64_t) mod->module_core_rw;
2539 break;
2540
2541 case RV_LTV:
2542 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2543 * addresses have been selected...
2544 */
2545 uint64_t gp;
2546 - if (mod->core_size > MAX_LTOFF)
2547 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2548 /*
2549 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2550 * at the end of the module.
2551 */
2552 - gp = mod->core_size - MAX_LTOFF / 2;
2553 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2554 else
2555 - gp = mod->core_size / 2;
2556 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2557 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2558 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2559 mod->arch.gp = gp;
2560 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2561 }
2562 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2563 index d9439ef..b9a4303 100644
2564 --- a/arch/ia64/kernel/sys_ia64.c
2565 +++ b/arch/ia64/kernel/sys_ia64.c
2566 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2567 if (REGION_NUMBER(addr) == RGN_HPAGE)
2568 addr = 0;
2569 #endif
2570 +
2571 +#ifdef CONFIG_PAX_RANDMMAP
2572 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2573 + addr = mm->free_area_cache;
2574 + else
2575 +#endif
2576 +
2577 if (!addr)
2578 addr = mm->free_area_cache;
2579
2580 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2582 /* At this point: (!vma || addr < vma->vm_end). */
2583 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2584 - if (start_addr != TASK_UNMAPPED_BASE) {
2585 + if (start_addr != mm->mmap_base) {
2586 /* Start a new search --- just in case we missed some holes. */
2587 - addr = TASK_UNMAPPED_BASE;
2588 + addr = mm->mmap_base;
2589 goto full_search;
2590 }
2591 return -ENOMEM;
2592 }
2593 - if (!vma || addr + len <= vma->vm_start) {
2594 + if (check_heap_stack_gap(vma, addr, len)) {
2595 /* Remember the address where we stopped this search: */
2596 mm->free_area_cache = addr + len;
2597 return addr;
2598 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2599 index 0ccb28f..8992469 100644
2600 --- a/arch/ia64/kernel/vmlinux.lds.S
2601 +++ b/arch/ia64/kernel/vmlinux.lds.S
2602 @@ -198,7 +198,7 @@ SECTIONS {
2603 /* Per-cpu data: */
2604 . = ALIGN(PERCPU_PAGE_SIZE);
2605 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2606 - __phys_per_cpu_start = __per_cpu_load;
2607 + __phys_per_cpu_start = per_cpu_load;
2608 /*
2609 * ensure percpu data fits
2610 * into percpu page size
2611 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2612 index 02d29c2..ea893df 100644
2613 --- a/arch/ia64/mm/fault.c
2614 +++ b/arch/ia64/mm/fault.c
2615 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2616 return pte_present(pte);
2617 }
2618
2619 +#ifdef CONFIG_PAX_PAGEEXEC
2620 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2621 +{
2622 + unsigned long i;
2623 +
2624 + printk(KERN_ERR "PAX: bytes at PC: ");
2625 + for (i = 0; i < 8; i++) {
2626 + unsigned int c;
2627 + if (get_user(c, (unsigned int *)pc+i))
2628 + printk(KERN_CONT "???????? ");
2629 + else
2630 + printk(KERN_CONT "%08x ", c);
2631 + }
2632 + printk("\n");
2633 +}
2634 +#endif
2635 +
2636 void __kprobes
2637 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2638 {
2639 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2640 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2641 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2642
2643 - if ((vma->vm_flags & mask) != mask)
2644 + if ((vma->vm_flags & mask) != mask) {
2645 +
2646 +#ifdef CONFIG_PAX_PAGEEXEC
2647 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2648 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2649 + goto bad_area;
2650 +
2651 + up_read(&mm->mmap_sem);
2652 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2653 + do_group_exit(SIGKILL);
2654 + }
2655 +#endif
2656 +
2657 goto bad_area;
2658
2659 + }
2660 +
2661 /*
2662 * If for any reason at all we couldn't handle the fault, make
2663 * sure we exit gracefully rather than endlessly redo the
2664 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2665 index 5ca674b..e0e1b70 100644
2666 --- a/arch/ia64/mm/hugetlbpage.c
2667 +++ b/arch/ia64/mm/hugetlbpage.c
2668 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2669 /* At this point: (!vmm || addr < vmm->vm_end). */
2670 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2671 return -ENOMEM;
2672 - if (!vmm || (addr + len) <= vmm->vm_start)
2673 + if (check_heap_stack_gap(vmm, addr, len))
2674 return addr;
2675 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2676 }
2677 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2678 index 0eab454..bd794f2 100644
2679 --- a/arch/ia64/mm/init.c
2680 +++ b/arch/ia64/mm/init.c
2681 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2682 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2683 vma->vm_end = vma->vm_start + PAGE_SIZE;
2684 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2685 +
2686 +#ifdef CONFIG_PAX_PAGEEXEC
2687 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2688 + vma->vm_flags &= ~VM_EXEC;
2689 +
2690 +#ifdef CONFIG_PAX_MPROTECT
2691 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2692 + vma->vm_flags &= ~VM_MAYEXEC;
2693 +#endif
2694 +
2695 + }
2696 +#endif
2697 +
2698 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2699 down_write(&current->mm->mmap_sem);
2700 if (insert_vm_struct(current->mm, vma)) {
2701 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2702 index 40b3ee9..8c2c112 100644
2703 --- a/arch/m32r/include/asm/cache.h
2704 +++ b/arch/m32r/include/asm/cache.h
2705 @@ -1,8 +1,10 @@
2706 #ifndef _ASM_M32R_CACHE_H
2707 #define _ASM_M32R_CACHE_H
2708
2709 +#include <linux/const.h>
2710 +
2711 /* L1 cache line size */
2712 #define L1_CACHE_SHIFT 4
2713 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2714 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2715
2716 #endif /* _ASM_M32R_CACHE_H */
2717 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2718 index 82abd15..d95ae5d 100644
2719 --- a/arch/m32r/lib/usercopy.c
2720 +++ b/arch/m32r/lib/usercopy.c
2721 @@ -14,6 +14,9 @@
2722 unsigned long
2723 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2724 {
2725 + if ((long)n < 0)
2726 + return n;
2727 +
2728 prefetch(from);
2729 if (access_ok(VERIFY_WRITE, to, n))
2730 __copy_user(to,from,n);
2731 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 unsigned long
2733 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2734 {
2735 + if ((long)n < 0)
2736 + return n;
2737 +
2738 prefetchw(to);
2739 if (access_ok(VERIFY_READ, from, n))
2740 __copy_user_zeroing(to,from,n);
2741 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2742 index 0395c51..5f26031 100644
2743 --- a/arch/m68k/include/asm/cache.h
2744 +++ b/arch/m68k/include/asm/cache.h
2745 @@ -4,9 +4,11 @@
2746 #ifndef __ARCH_M68K_CACHE_H
2747 #define __ARCH_M68K_CACHE_H
2748
2749 +#include <linux/const.h>
2750 +
2751 /* bytes per L1 cache line */
2752 #define L1_CACHE_SHIFT 4
2753 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2754 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2755
2756 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2757
2758 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2759 index 4efe96a..60e8699 100644
2760 --- a/arch/microblaze/include/asm/cache.h
2761 +++ b/arch/microblaze/include/asm/cache.h
2762 @@ -13,11 +13,12 @@
2763 #ifndef _ASM_MICROBLAZE_CACHE_H
2764 #define _ASM_MICROBLAZE_CACHE_H
2765
2766 +#include <linux/const.h>
2767 #include <asm/registers.h>
2768
2769 #define L1_CACHE_SHIFT 5
2770 /* word-granular cache in microblaze */
2771 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2773
2774 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2775
2776 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2777 index 3f4c5cb..3439c6e 100644
2778 --- a/arch/mips/include/asm/atomic.h
2779 +++ b/arch/mips/include/asm/atomic.h
2780 @@ -21,6 +21,10 @@
2781 #include <asm/cmpxchg.h>
2782 #include <asm/war.h>
2783
2784 +#ifdef CONFIG_GENERIC_ATOMIC64
2785 +#include <asm-generic/atomic64.h>
2786 +#endif
2787 +
2788 #define ATOMIC_INIT(i) { (i) }
2789
2790 /*
2791 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2792 */
2793 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2794
2795 +#define atomic64_read_unchecked(v) atomic64_read(v)
2796 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2797 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2798 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2799 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2800 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2801 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2802 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2803 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2804 +
2805 #endif /* CONFIG_64BIT */
2806
2807 /*
2808 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2809 index b4db69f..8f3b093 100644
2810 --- a/arch/mips/include/asm/cache.h
2811 +++ b/arch/mips/include/asm/cache.h
2812 @@ -9,10 +9,11 @@
2813 #ifndef _ASM_CACHE_H
2814 #define _ASM_CACHE_H
2815
2816 +#include <linux/const.h>
2817 #include <kmalloc.h>
2818
2819 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2820 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2821 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2822
2823 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2824 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2825 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2826 index 455c0ac..ad65fbe 100644
2827 --- a/arch/mips/include/asm/elf.h
2828 +++ b/arch/mips/include/asm/elf.h
2829 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2830 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2831 #endif
2832
2833 +#ifdef CONFIG_PAX_ASLR
2834 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2835 +
2836 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2837 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2838 +#endif
2839 +
2840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2841 struct linux_binprm;
2842 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2843 int uses_interp);
2844
2845 -struct mm_struct;
2846 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2847 -#define arch_randomize_brk arch_randomize_brk
2848 -
2849 #endif /* _ASM_ELF_H */
2850 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2851 index c1f6afa..38cc6e9 100644
2852 --- a/arch/mips/include/asm/exec.h
2853 +++ b/arch/mips/include/asm/exec.h
2854 @@ -12,6 +12,6 @@
2855 #ifndef _ASM_EXEC_H
2856 #define _ASM_EXEC_H
2857
2858 -extern unsigned long arch_align_stack(unsigned long sp);
2859 +#define arch_align_stack(x) ((x) & ~0xfUL)
2860
2861 #endif /* _ASM_EXEC_H */
2862 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2863 index da9bd7d..91aa7ab 100644
2864 --- a/arch/mips/include/asm/page.h
2865 +++ b/arch/mips/include/asm/page.h
2866 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2867 #ifdef CONFIG_CPU_MIPS32
2868 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2869 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2870 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2871 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2872 #else
2873 typedef struct { unsigned long long pte; } pte_t;
2874 #define pte_val(x) ((x).pte)
2875 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2876 index 881d18b..cea38bc 100644
2877 --- a/arch/mips/include/asm/pgalloc.h
2878 +++ b/arch/mips/include/asm/pgalloc.h
2879 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2880 {
2881 set_pud(pud, __pud((unsigned long)pmd));
2882 }
2883 +
2884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2885 +{
2886 + pud_populate(mm, pud, pmd);
2887 +}
2888 #endif
2889
2890 /*
2891 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2892 index ca97e0e..cd08920 100644
2893 --- a/arch/mips/include/asm/thread_info.h
2894 +++ b/arch/mips/include/asm/thread_info.h
2895 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2897 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2898 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2899 +/* li takes a 32bit immediate */
2900 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2901 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2902
2903 #ifdef CONFIG_MIPS32_O32
2904 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2905 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2906 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2907 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2908 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2909 +
2910 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2911
2912 /* work to do in syscall_trace_leave() */
2913 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2914 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2915
2916 /* work to do on interrupt/exception return */
2917 #define _TIF_WORK_MASK (0x0000ffef & \
2918 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2919 /* work to do on any return to u-space */
2920 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2921 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2922
2923 #endif /* __KERNEL__ */
2924
2925 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2926 index 9fdd8bc..4bd7f1a 100644
2927 --- a/arch/mips/kernel/binfmt_elfn32.c
2928 +++ b/arch/mips/kernel/binfmt_elfn32.c
2929 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2930 #undef ELF_ET_DYN_BASE
2931 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2932
2933 +#ifdef CONFIG_PAX_ASLR
2934 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2935 +
2936 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2937 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2938 +#endif
2939 +
2940 #include <asm/processor.h>
2941 #include <linux/module.h>
2942 #include <linux/elfcore.h>
2943 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2944 index ff44823..97f8906 100644
2945 --- a/arch/mips/kernel/binfmt_elfo32.c
2946 +++ b/arch/mips/kernel/binfmt_elfo32.c
2947 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2948 #undef ELF_ET_DYN_BASE
2949 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2950
2951 +#ifdef CONFIG_PAX_ASLR
2952 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2953 +
2954 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2955 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2956 +#endif
2957 +
2958 #include <asm/processor.h>
2959
2960 /*
2961 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2962 index e9a5fd7..378809a 100644
2963 --- a/arch/mips/kernel/process.c
2964 +++ b/arch/mips/kernel/process.c
2965 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2966 out:
2967 return pc;
2968 }
2969 -
2970 -/*
2971 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2972 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2973 - */
2974 -unsigned long arch_align_stack(unsigned long sp)
2975 -{
2976 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2977 - sp -= get_random_int() & ~PAGE_MASK;
2978 -
2979 - return sp & ALMASK;
2980 -}
2981 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2982 index 4812c6d..2069554 100644
2983 --- a/arch/mips/kernel/ptrace.c
2984 +++ b/arch/mips/kernel/ptrace.c
2985 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2986 return arch;
2987 }
2988
2989 +#ifdef CONFIG_GRKERNSEC_SETXID
2990 +extern void gr_delayed_cred_worker(void);
2991 +#endif
2992 +
2993 /*
2994 * Notification of system call entry/exit
2995 * - triggered by current->work.syscall_trace
2996 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2997 /* do the secure computing check first */
2998 secure_computing_strict(regs->regs[2]);
2999
3000 +#ifdef CONFIG_GRKERNSEC_SETXID
3001 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3002 + gr_delayed_cred_worker();
3003 +#endif
3004 +
3005 if (!(current->ptrace & PT_PTRACED))
3006 goto out;
3007
3008 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3009 index a632bc1..0b77c7c 100644
3010 --- a/arch/mips/kernel/scall32-o32.S
3011 +++ b/arch/mips/kernel/scall32-o32.S
3012 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3013
3014 stack_done:
3015 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3016 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3017 + li t1, _TIF_SYSCALL_WORK
3018 and t0, t1
3019 bnez t0, syscall_trace_entry # -> yes
3020
3021 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3022 index 3b5a5e9..e1ee86d 100644
3023 --- a/arch/mips/kernel/scall64-64.S
3024 +++ b/arch/mips/kernel/scall64-64.S
3025 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3026
3027 sd a3, PT_R26(sp) # save a3 for syscall restarting
3028
3029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3030 + li t1, _TIF_SYSCALL_WORK
3031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3032 and t0, t1, t0
3033 bnez t0, syscall_trace_entry
3034 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3035 index 6be6f70..1859577 100644
3036 --- a/arch/mips/kernel/scall64-n32.S
3037 +++ b/arch/mips/kernel/scall64-n32.S
3038 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3039
3040 sd a3, PT_R26(sp) # save a3 for syscall restarting
3041
3042 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3043 + li t1, _TIF_SYSCALL_WORK
3044 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3045 and t0, t1, t0
3046 bnez t0, n32_syscall_trace_entry
3047 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3048 index 5422855..74e63a3 100644
3049 --- a/arch/mips/kernel/scall64-o32.S
3050 +++ b/arch/mips/kernel/scall64-o32.S
3051 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3052 PTR 4b, bad_stack
3053 .previous
3054
3055 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3056 + li t1, _TIF_SYSCALL_WORK
3057 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3058 and t0, t1, t0
3059 bnez t0, trace_a_syscall
3060 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3061 index c14f6df..537e729 100644
3062 --- a/arch/mips/mm/fault.c
3063 +++ b/arch/mips/mm/fault.c
3064 @@ -27,6 +27,23 @@
3065 #include <asm/highmem.h> /* For VMALLOC_END */
3066 #include <linux/kdebug.h>
3067
3068 +#ifdef CONFIG_PAX_PAGEEXEC
3069 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3070 +{
3071 + unsigned long i;
3072 +
3073 + printk(KERN_ERR "PAX: bytes at PC: ");
3074 + for (i = 0; i < 5; i++) {
3075 + unsigned int c;
3076 + if (get_user(c, (unsigned int *)pc+i))
3077 + printk(KERN_CONT "???????? ");
3078 + else
3079 + printk(KERN_CONT "%08x ", c);
3080 + }
3081 + printk("\n");
3082 +}
3083 +#endif
3084 +
3085 /*
3086 * This routine handles page faults. It determines the address,
3087 * and the problem, and then passes it off to one of the appropriate
3088 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3089 index 302d779..7d35bf8 100644
3090 --- a/arch/mips/mm/mmap.c
3091 +++ b/arch/mips/mm/mmap.c
3092 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3093 do_color_align = 1;
3094
3095 /* requesting a specific address */
3096 +
3097 +#ifdef CONFIG_PAX_RANDMMAP
3098 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3099 +#endif
3100 +
3101 if (addr) {
3102 if (do_color_align)
3103 addr = COLOUR_ALIGN(addr, pgoff);
3104 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3105 addr = PAGE_ALIGN(addr);
3106
3107 vma = find_vma(mm, addr);
3108 - if (TASK_SIZE - len >= addr &&
3109 - (!vma || addr + len <= vma->vm_start))
3110 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 }
3113
3114 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* At this point: (!vma || addr < vma->vm_end). */
3116 if (TASK_SIZE - len < addr)
3117 return -ENOMEM;
3118 - if (!vma || addr + len <= vma->vm_start)
3119 + if (check_heap_stack_gap(vmm, addr, len))
3120 return addr;
3121 addr = vma->vm_end;
3122 if (do_color_align)
3123 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 /* make sure it can fit in the remaining address space */
3125 if (likely(addr > len)) {
3126 vma = find_vma(mm, addr - len);
3127 - if (!vma || addr <= vma->vm_start) {
3128 + if (check_heap_stack_gap(vmm, addr - len, len))
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr - len;
3131 }
3132 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3133 * return with success:
3134 */
3135 vma = find_vma(mm, addr);
3136 - if (likely(!vma || addr + len <= vma->vm_start)) {
3137 + if (check_heap_stack_gap(vmm, addr, len)) {
3138 /* cache the address as a hint for next time */
3139 return mm->free_area_cache = addr;
3140 }
3141 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3142 mm->unmap_area = arch_unmap_area_topdown;
3143 }
3144 }
3145 -
3146 -static inline unsigned long brk_rnd(void)
3147 -{
3148 - unsigned long rnd = get_random_int();
3149 -
3150 - rnd = rnd << PAGE_SHIFT;
3151 - /* 8MB for 32bit, 256MB for 64bit */
3152 - if (TASK_IS_32BIT_ADDR)
3153 - rnd = rnd & 0x7ffffful;
3154 - else
3155 - rnd = rnd & 0xffffffful;
3156 -
3157 - return rnd;
3158 -}
3159 -
3160 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3161 -{
3162 - unsigned long base = mm->brk;
3163 - unsigned long ret;
3164 -
3165 - ret = PAGE_ALIGN(base + brk_rnd());
3166 -
3167 - if (ret < mm->brk)
3168 - return mm->brk;
3169 -
3170 - return ret;
3171 -}
3172 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3173 index 967d144..db12197 100644
3174 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3175 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3176 @@ -11,12 +11,14 @@
3177 #ifndef _ASM_PROC_CACHE_H
3178 #define _ASM_PROC_CACHE_H
3179
3180 +#include <linux/const.h>
3181 +
3182 /* L1 cache */
3183
3184 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3185 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3186 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3187 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3188 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3189 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3190
3191 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3192 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3193 index bcb5df2..84fabd2 100644
3194 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3195 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3196 @@ -16,13 +16,15 @@
3197 #ifndef _ASM_PROC_CACHE_H
3198 #define _ASM_PROC_CACHE_H
3199
3200 +#include <linux/const.h>
3201 +
3202 /*
3203 * L1 cache
3204 */
3205 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3206 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3207 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3208 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3209 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3210 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3211
3212 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3213 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3214 index 4ce7a01..449202a 100644
3215 --- a/arch/openrisc/include/asm/cache.h
3216 +++ b/arch/openrisc/include/asm/cache.h
3217 @@ -19,11 +19,13 @@
3218 #ifndef __ASM_OPENRISC_CACHE_H
3219 #define __ASM_OPENRISC_CACHE_H
3220
3221 +#include <linux/const.h>
3222 +
3223 /* FIXME: How can we replace these with values from the CPU...
3224 * they shouldn't be hard-coded!
3225 */
3226
3227 -#define L1_CACHE_BYTES 16
3228 #define L1_CACHE_SHIFT 4
3229 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3230
3231 #endif /* __ASM_OPENRISC_CACHE_H */
3232 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3233 index 6c6defc..d30653d 100644
3234 --- a/arch/parisc/include/asm/atomic.h
3235 +++ b/arch/parisc/include/asm/atomic.h
3236 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3237
3238 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3239
3240 +#define atomic64_read_unchecked(v) atomic64_read(v)
3241 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3242 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3243 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3244 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3245 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3246 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3247 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3248 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3249 +
3250 #endif /* !CONFIG_64BIT */
3251
3252
3253 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3254 index 47f11c7..3420df2 100644
3255 --- a/arch/parisc/include/asm/cache.h
3256 +++ b/arch/parisc/include/asm/cache.h
3257 @@ -5,6 +5,7 @@
3258 #ifndef __ARCH_PARISC_CACHE_H
3259 #define __ARCH_PARISC_CACHE_H
3260
3261 +#include <linux/const.h>
3262
3263 /*
3264 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3265 @@ -15,13 +16,13 @@
3266 * just ruin performance.
3267 */
3268 #ifdef CONFIG_PA20
3269 -#define L1_CACHE_BYTES 64
3270 #define L1_CACHE_SHIFT 6
3271 #else
3272 -#define L1_CACHE_BYTES 32
3273 #define L1_CACHE_SHIFT 5
3274 #endif
3275
3276 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3277 +
3278 #ifndef __ASSEMBLY__
3279
3280 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3281 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3282 index 19f6cb1..6c78cf2 100644
3283 --- a/arch/parisc/include/asm/elf.h
3284 +++ b/arch/parisc/include/asm/elf.h
3285 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3286
3287 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3288
3289 +#ifdef CONFIG_PAX_ASLR
3290 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3291 +
3292 +#define PAX_DELTA_MMAP_LEN 16
3293 +#define PAX_DELTA_STACK_LEN 16
3294 +#endif
3295 +
3296 /* This yields a mask that user programs can use to figure out what
3297 instruction set this CPU supports. This could be done in user space,
3298 but it's not easy, and we've already done it here. */
3299 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3300 index fc987a1..6e068ef 100644
3301 --- a/arch/parisc/include/asm/pgalloc.h
3302 +++ b/arch/parisc/include/asm/pgalloc.h
3303 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3304 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3305 }
3306
3307 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3308 +{
3309 + pgd_populate(mm, pgd, pmd);
3310 +}
3311 +
3312 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3313 {
3314 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3315 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3316 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3317 #define pmd_free(mm, x) do { } while (0)
3318 #define pgd_populate(mm, pmd, pte) BUG()
3319 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3320
3321 #endif
3322
3323 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3324 index ee99f23..802b0a1 100644
3325 --- a/arch/parisc/include/asm/pgtable.h
3326 +++ b/arch/parisc/include/asm/pgtable.h
3327 @@ -212,6 +212,17 @@ struct vm_area_struct;
3328 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3329 #define PAGE_COPY PAGE_EXECREAD
3330 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3331 +
3332 +#ifdef CONFIG_PAX_PAGEEXEC
3333 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3334 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3335 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3336 +#else
3337 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3338 +# define PAGE_COPY_NOEXEC PAGE_COPY
3339 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3340 +#endif
3341 +
3342 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3343 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3344 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3345 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3346 index 4ba2c93..f5e3974 100644
3347 --- a/arch/parisc/include/asm/uaccess.h
3348 +++ b/arch/parisc/include/asm/uaccess.h
3349 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3350 const void __user *from,
3351 unsigned long n)
3352 {
3353 - int sz = __compiletime_object_size(to);
3354 + size_t sz = __compiletime_object_size(to);
3355 int ret = -EFAULT;
3356
3357 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3358 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3359 ret = __copy_from_user(to, from, n);
3360 else
3361 copy_from_user_overflow();
3362 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3363 index 5e34ccf..672bc9c 100644
3364 --- a/arch/parisc/kernel/module.c
3365 +++ b/arch/parisc/kernel/module.c
3366 @@ -98,16 +98,38 @@
3367
3368 /* three functions to determine where in the module core
3369 * or init pieces the location is */
3370 +static inline int in_init_rx(struct module *me, void *loc)
3371 +{
3372 + return (loc >= me->module_init_rx &&
3373 + loc < (me->module_init_rx + me->init_size_rx));
3374 +}
3375 +
3376 +static inline int in_init_rw(struct module *me, void *loc)
3377 +{
3378 + return (loc >= me->module_init_rw &&
3379 + loc < (me->module_init_rw + me->init_size_rw));
3380 +}
3381 +
3382 static inline int in_init(struct module *me, void *loc)
3383 {
3384 - return (loc >= me->module_init &&
3385 - loc <= (me->module_init + me->init_size));
3386 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3387 +}
3388 +
3389 +static inline int in_core_rx(struct module *me, void *loc)
3390 +{
3391 + return (loc >= me->module_core_rx &&
3392 + loc < (me->module_core_rx + me->core_size_rx));
3393 +}
3394 +
3395 +static inline int in_core_rw(struct module *me, void *loc)
3396 +{
3397 + return (loc >= me->module_core_rw &&
3398 + loc < (me->module_core_rw + me->core_size_rw));
3399 }
3400
3401 static inline int in_core(struct module *me, void *loc)
3402 {
3403 - return (loc >= me->module_core &&
3404 - loc <= (me->module_core + me->core_size));
3405 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3406 }
3407
3408 static inline int in_local(struct module *me, void *loc)
3409 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3410 }
3411
3412 /* align things a bit */
3413 - me->core_size = ALIGN(me->core_size, 16);
3414 - me->arch.got_offset = me->core_size;
3415 - me->core_size += gots * sizeof(struct got_entry);
3416 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3417 + me->arch.got_offset = me->core_size_rw;
3418 + me->core_size_rw += gots * sizeof(struct got_entry);
3419
3420 - me->core_size = ALIGN(me->core_size, 16);
3421 - me->arch.fdesc_offset = me->core_size;
3422 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3423 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3424 + me->arch.fdesc_offset = me->core_size_rw;
3425 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3426
3427 me->arch.got_max = gots;
3428 me->arch.fdesc_max = fdescs;
3429 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430
3431 BUG_ON(value == 0);
3432
3433 - got = me->module_core + me->arch.got_offset;
3434 + got = me->module_core_rw + me->arch.got_offset;
3435 for (i = 0; got[i].addr; i++)
3436 if (got[i].addr == value)
3437 goto out;
3438 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3439 #ifdef CONFIG_64BIT
3440 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3441 {
3442 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3443 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3444
3445 if (!value) {
3446 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3447 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3448
3449 /* Create new one */
3450 fdesc->addr = value;
3451 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453 return (Elf_Addr)fdesc;
3454 }
3455 #endif /* CONFIG_64BIT */
3456 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3457
3458 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3459 end = table + sechdrs[me->arch.unwind_section].sh_size;
3460 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3461 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3462
3463 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3464 me->arch.unwind_section, table, end, gp);
3465 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3466 index c9b9322..02d8940 100644
3467 --- a/arch/parisc/kernel/sys_parisc.c
3468 +++ b/arch/parisc/kernel/sys_parisc.c
3469 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473 - if (!vma || addr + len <= vma->vm_start)
3474 + if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = vma->vm_end;
3477 }
3478 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3479 /* At this point: (!vma || addr < vma->vm_end). */
3480 if (TASK_SIZE - len < addr)
3481 return -ENOMEM;
3482 - if (!vma || addr + len <= vma->vm_start)
3483 + if (check_heap_stack_gap(vma, addr, len))
3484 return addr;
3485 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3486 if (addr < vma->vm_end) /* handle wraparound */
3487 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3488 if (flags & MAP_FIXED)
3489 return addr;
3490 if (!addr)
3491 - addr = TASK_UNMAPPED_BASE;
3492 + addr = current->mm->mmap_base;
3493
3494 if (filp) {
3495 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3496 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3497 index 45ba99f..8e22c33 100644
3498 --- a/arch/parisc/kernel/traps.c
3499 +++ b/arch/parisc/kernel/traps.c
3500 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3501
3502 down_read(&current->mm->mmap_sem);
3503 vma = find_vma(current->mm,regs->iaoq[0]);
3504 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3505 - && (vma->vm_flags & VM_EXEC)) {
3506 -
3507 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3508 fault_address = regs->iaoq[0];
3509 fault_space = regs->iasq[0];
3510
3511 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3512 index 18162ce..94de376 100644
3513 --- a/arch/parisc/mm/fault.c
3514 +++ b/arch/parisc/mm/fault.c
3515 @@ -15,6 +15,7 @@
3516 #include <linux/sched.h>
3517 #include <linux/interrupt.h>
3518 #include <linux/module.h>
3519 +#include <linux/unistd.h>
3520
3521 #include <asm/uaccess.h>
3522 #include <asm/traps.h>
3523 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3524 static unsigned long
3525 parisc_acctyp(unsigned long code, unsigned int inst)
3526 {
3527 - if (code == 6 || code == 16)
3528 + if (code == 6 || code == 7 || code == 16)
3529 return VM_EXEC;
3530
3531 switch (inst & 0xf0000000) {
3532 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3533 }
3534 #endif
3535
3536 +#ifdef CONFIG_PAX_PAGEEXEC
3537 +/*
3538 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3539 + *
3540 + * returns 1 when task should be killed
3541 + * 2 when rt_sigreturn trampoline was detected
3542 + * 3 when unpatched PLT trampoline was detected
3543 + */
3544 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3545 +{
3546 +
3547 +#ifdef CONFIG_PAX_EMUPLT
3548 + int err;
3549 +
3550 + do { /* PaX: unpatched PLT emulation */
3551 + unsigned int bl, depwi;
3552 +
3553 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3554 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3555 +
3556 + if (err)
3557 + break;
3558 +
3559 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3560 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3561 +
3562 + err = get_user(ldw, (unsigned int *)addr);
3563 + err |= get_user(bv, (unsigned int *)(addr+4));
3564 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3565 +
3566 + if (err)
3567 + break;
3568 +
3569 + if (ldw == 0x0E801096U &&
3570 + bv == 0xEAC0C000U &&
3571 + ldw2 == 0x0E881095U)
3572 + {
3573 + unsigned int resolver, map;
3574 +
3575 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3576 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3577 + if (err)
3578 + break;
3579 +
3580 + regs->gr[20] = instruction_pointer(regs)+8;
3581 + regs->gr[21] = map;
3582 + regs->gr[22] = resolver;
3583 + regs->iaoq[0] = resolver | 3UL;
3584 + regs->iaoq[1] = regs->iaoq[0] + 4;
3585 + return 3;
3586 + }
3587 + }
3588 + } while (0);
3589 +#endif
3590 +
3591 +#ifdef CONFIG_PAX_EMUTRAMP
3592 +
3593 +#ifndef CONFIG_PAX_EMUSIGRT
3594 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3595 + return 1;
3596 +#endif
3597 +
3598 + do { /* PaX: rt_sigreturn emulation */
3599 + unsigned int ldi1, ldi2, bel, nop;
3600 +
3601 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3602 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3603 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3604 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3605 +
3606 + if (err)
3607 + break;
3608 +
3609 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3610 + ldi2 == 0x3414015AU &&
3611 + bel == 0xE4008200U &&
3612 + nop == 0x08000240U)
3613 + {
3614 + regs->gr[25] = (ldi1 & 2) >> 1;
3615 + regs->gr[20] = __NR_rt_sigreturn;
3616 + regs->gr[31] = regs->iaoq[1] + 16;
3617 + regs->sr[0] = regs->iasq[1];
3618 + regs->iaoq[0] = 0x100UL;
3619 + regs->iaoq[1] = regs->iaoq[0] + 4;
3620 + regs->iasq[0] = regs->sr[2];
3621 + regs->iasq[1] = regs->sr[2];
3622 + return 2;
3623 + }
3624 + } while (0);
3625 +#endif
3626 +
3627 + return 1;
3628 +}
3629 +
3630 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3631 +{
3632 + unsigned long i;
3633 +
3634 + printk(KERN_ERR "PAX: bytes at PC: ");
3635 + for (i = 0; i < 5; i++) {
3636 + unsigned int c;
3637 + if (get_user(c, (unsigned int *)pc+i))
3638 + printk(KERN_CONT "???????? ");
3639 + else
3640 + printk(KERN_CONT "%08x ", c);
3641 + }
3642 + printk("\n");
3643 +}
3644 +#endif
3645 +
3646 int fixup_exception(struct pt_regs *regs)
3647 {
3648 const struct exception_table_entry *fix;
3649 @@ -192,8 +303,33 @@ good_area:
3650
3651 acc_type = parisc_acctyp(code,regs->iir);
3652
3653 - if ((vma->vm_flags & acc_type) != acc_type)
3654 + if ((vma->vm_flags & acc_type) != acc_type) {
3655 +
3656 +#ifdef CONFIG_PAX_PAGEEXEC
3657 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3658 + (address & ~3UL) == instruction_pointer(regs))
3659 + {
3660 + up_read(&mm->mmap_sem);
3661 + switch (pax_handle_fetch_fault(regs)) {
3662 +
3663 +#ifdef CONFIG_PAX_EMUPLT
3664 + case 3:
3665 + return;
3666 +#endif
3667 +
3668 +#ifdef CONFIG_PAX_EMUTRAMP
3669 + case 2:
3670 + return;
3671 +#endif
3672 +
3673 + }
3674 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3675 + do_group_exit(SIGKILL);
3676 + }
3677 +#endif
3678 +
3679 goto bad_area;
3680 + }
3681
3682 /*
3683 * If for any reason at all we couldn't handle the fault, make
3684 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3685 index da29032..f76c24c 100644
3686 --- a/arch/powerpc/include/asm/atomic.h
3687 +++ b/arch/powerpc/include/asm/atomic.h
3688 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3689 return t1;
3690 }
3691
3692 +#define atomic64_read_unchecked(v) atomic64_read(v)
3693 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3694 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3695 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3696 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3697 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3698 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3699 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3700 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3701 +
3702 #endif /* __powerpc64__ */
3703
3704 #endif /* __KERNEL__ */
3705 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3706 index 9e495c9..b6878e5 100644
3707 --- a/arch/powerpc/include/asm/cache.h
3708 +++ b/arch/powerpc/include/asm/cache.h
3709 @@ -3,6 +3,7 @@
3710
3711 #ifdef __KERNEL__
3712
3713 +#include <linux/const.h>
3714
3715 /* bytes per L1 cache line */
3716 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3717 @@ -22,7 +23,7 @@
3718 #define L1_CACHE_SHIFT 7
3719 #endif
3720
3721 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3723
3724 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3725
3726 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3727 index 3bf9cca..e7457d0 100644
3728 --- a/arch/powerpc/include/asm/elf.h
3729 +++ b/arch/powerpc/include/asm/elf.h
3730 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3731 the loader. We need to make sure that it is out of the way of the program
3732 that it will "exec", and that there is sufficient room for the brk. */
3733
3734 -extern unsigned long randomize_et_dyn(unsigned long base);
3735 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3736 +#define ELF_ET_DYN_BASE (0x20000000)
3737 +
3738 +#ifdef CONFIG_PAX_ASLR
3739 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3740 +
3741 +#ifdef __powerpc64__
3742 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3743 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3744 +#else
3745 +#define PAX_DELTA_MMAP_LEN 15
3746 +#define PAX_DELTA_STACK_LEN 15
3747 +#endif
3748 +#endif
3749
3750 /*
3751 * Our registers are always unsigned longs, whether we're a 32 bit
3752 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3753 (0x7ff >> (PAGE_SHIFT - 12)) : \
3754 (0x3ffff >> (PAGE_SHIFT - 12)))
3755
3756 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3757 -#define arch_randomize_brk arch_randomize_brk
3758 -
3759 #endif /* __KERNEL__ */
3760
3761 /*
3762 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3763 index 8196e9c..d83a9f3 100644
3764 --- a/arch/powerpc/include/asm/exec.h
3765 +++ b/arch/powerpc/include/asm/exec.h
3766 @@ -4,6 +4,6 @@
3767 #ifndef _ASM_POWERPC_EXEC_H
3768 #define _ASM_POWERPC_EXEC_H
3769
3770 -extern unsigned long arch_align_stack(unsigned long sp);
3771 +#define arch_align_stack(x) ((x) & ~0xfUL)
3772
3773 #endif /* _ASM_POWERPC_EXEC_H */
3774 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3775 index bca8fdc..61e9580 100644
3776 --- a/arch/powerpc/include/asm/kmap_types.h
3777 +++ b/arch/powerpc/include/asm/kmap_types.h
3778 @@ -27,6 +27,7 @@ enum km_type {
3779 KM_PPC_SYNC_PAGE,
3780 KM_PPC_SYNC_ICACHE,
3781 KM_KDB,
3782 + KM_CLEARPAGE,
3783 KM_TYPE_NR
3784 };
3785
3786 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3787 index d4a7f64..451de1c 100644
3788 --- a/arch/powerpc/include/asm/mman.h
3789 +++ b/arch/powerpc/include/asm/mman.h
3790 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3791 }
3792 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3793
3794 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3795 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3796 {
3797 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3798 }
3799 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3800 index f072e97..b436dee 100644
3801 --- a/arch/powerpc/include/asm/page.h
3802 +++ b/arch/powerpc/include/asm/page.h
3803 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3804 * and needs to be executable. This means the whole heap ends
3805 * up being executable.
3806 */
3807 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3808 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3809 +#define VM_DATA_DEFAULT_FLAGS32 \
3810 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3811 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3812
3813 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3814 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3815 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3816 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3817 #endif
3818
3819 +#define ktla_ktva(addr) (addr)
3820 +#define ktva_ktla(addr) (addr)
3821 +
3822 /*
3823 * Use the top bit of the higher-level page table entries to indicate whether
3824 * the entries we point to contain hugepages. This works because we know that
3825 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3826 index fed85e6..da5c71b 100644
3827 --- a/arch/powerpc/include/asm/page_64.h
3828 +++ b/arch/powerpc/include/asm/page_64.h
3829 @@ -146,15 +146,18 @@ do { \
3830 * stack by default, so in the absence of a PT_GNU_STACK program header
3831 * we turn execute permission off.
3832 */
3833 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3834 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3835 +#define VM_STACK_DEFAULT_FLAGS32 \
3836 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3837 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3838
3839 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3840 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3841
3842 +#ifndef CONFIG_PAX_PAGEEXEC
3843 #define VM_STACK_DEFAULT_FLAGS \
3844 (is_32bit_task() ? \
3845 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3846 +#endif
3847
3848 #include <asm-generic/getorder.h>
3849
3850 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3851 index 292725c..f87ae14 100644
3852 --- a/arch/powerpc/include/asm/pgalloc-64.h
3853 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3854 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3855 #ifndef CONFIG_PPC_64K_PAGES
3856
3857 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3858 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3859
3860 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3861 {
3862 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3863 pud_set(pud, (unsigned long)pmd);
3864 }
3865
3866 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867 +{
3868 + pud_populate(mm, pud, pmd);
3869 +}
3870 +
3871 #define pmd_populate(mm, pmd, pte_page) \
3872 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3873 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3874 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3875 #else /* CONFIG_PPC_64K_PAGES */
3876
3877 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3878 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3879
3880 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3881 pte_t *pte)
3882 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3883 index 2e0e411..7899c68 100644
3884 --- a/arch/powerpc/include/asm/pgtable.h
3885 +++ b/arch/powerpc/include/asm/pgtable.h
3886 @@ -2,6 +2,7 @@
3887 #define _ASM_POWERPC_PGTABLE_H
3888 #ifdef __KERNEL__
3889
3890 +#include <linux/const.h>
3891 #ifndef __ASSEMBLY__
3892 #include <asm/processor.h> /* For TASK_SIZE */
3893 #include <asm/mmu.h>
3894 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3895 index 4aad413..85d86bf 100644
3896 --- a/arch/powerpc/include/asm/pte-hash32.h
3897 +++ b/arch/powerpc/include/asm/pte-hash32.h
3898 @@ -21,6 +21,7 @@
3899 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3900 #define _PAGE_USER 0x004 /* usermode access allowed */
3901 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3902 +#define _PAGE_EXEC _PAGE_GUARDED
3903 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3904 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3905 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3906 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3907 index f0cb7f4..d1296c4 100644
3908 --- a/arch/powerpc/include/asm/reg.h
3909 +++ b/arch/powerpc/include/asm/reg.h
3910 @@ -212,6 +212,7 @@
3911 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3912 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3913 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3914 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3915 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3916 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3917 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3918 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3919 index 68831e9..379c695 100644
3920 --- a/arch/powerpc/include/asm/thread_info.h
3921 +++ b/arch/powerpc/include/asm/thread_info.h
3922 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3923 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3924 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3925 #define TIF_SINGLESTEP 8 /* singlestepping active */
3926 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3927 #define TIF_SECCOMP 10 /* secure computing */
3928 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3929 #define TIF_NOERROR 12 /* Force successful syscall return */
3930 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3931 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3932 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3933 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3934 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3935
3936 /* as above, but as bit values */
3937 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3938 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3939 #define _TIF_NOERROR (1<<TIF_NOERROR)
3940 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3941 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3942 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3943 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3944 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3945 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3946 + _TIF_GRSEC_SETXID)
3947
3948 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3949 _TIF_NOTIFY_RESUME)
3950 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3951 index 17bb40c..353c98b 100644
3952 --- a/arch/powerpc/include/asm/uaccess.h
3953 +++ b/arch/powerpc/include/asm/uaccess.h
3954 @@ -13,6 +13,8 @@
3955 #define VERIFY_READ 0
3956 #define VERIFY_WRITE 1
3957
3958 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3959 +
3960 /*
3961 * The fs value determines whether argument validity checking should be
3962 * performed or not. If get_fs() == USER_DS, checking is performed, with
3963 @@ -329,52 +331,6 @@ do { \
3964 extern unsigned long __copy_tofrom_user(void __user *to,
3965 const void __user *from, unsigned long size);
3966
3967 -#ifndef __powerpc64__
3968 -
3969 -static inline unsigned long copy_from_user(void *to,
3970 - const void __user *from, unsigned long n)
3971 -{
3972 - unsigned long over;
3973 -
3974 - if (access_ok(VERIFY_READ, from, n))
3975 - return __copy_tofrom_user((__force void __user *)to, from, n);
3976 - if ((unsigned long)from < TASK_SIZE) {
3977 - over = (unsigned long)from + n - TASK_SIZE;
3978 - return __copy_tofrom_user((__force void __user *)to, from,
3979 - n - over) + over;
3980 - }
3981 - return n;
3982 -}
3983 -
3984 -static inline unsigned long copy_to_user(void __user *to,
3985 - const void *from, unsigned long n)
3986 -{
3987 - unsigned long over;
3988 -
3989 - if (access_ok(VERIFY_WRITE, to, n))
3990 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3991 - if ((unsigned long)to < TASK_SIZE) {
3992 - over = (unsigned long)to + n - TASK_SIZE;
3993 - return __copy_tofrom_user(to, (__force void __user *)from,
3994 - n - over) + over;
3995 - }
3996 - return n;
3997 -}
3998 -
3999 -#else /* __powerpc64__ */
4000 -
4001 -#define __copy_in_user(to, from, size) \
4002 - __copy_tofrom_user((to), (from), (size))
4003 -
4004 -extern unsigned long copy_from_user(void *to, const void __user *from,
4005 - unsigned long n);
4006 -extern unsigned long copy_to_user(void __user *to, const void *from,
4007 - unsigned long n);
4008 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4009 - unsigned long n);
4010 -
4011 -#endif /* __powerpc64__ */
4012 -
4013 static inline unsigned long __copy_from_user_inatomic(void *to,
4014 const void __user *from, unsigned long n)
4015 {
4016 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4017 if (ret == 0)
4018 return 0;
4019 }
4020 +
4021 + if (!__builtin_constant_p(n))
4022 + check_object_size(to, n, false);
4023 +
4024 return __copy_tofrom_user((__force void __user *)to, from, n);
4025 }
4026
4027 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4028 if (ret == 0)
4029 return 0;
4030 }
4031 +
4032 + if (!__builtin_constant_p(n))
4033 + check_object_size(from, n, true);
4034 +
4035 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4036 }
4037
4038 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4039 return __copy_to_user_inatomic(to, from, size);
4040 }
4041
4042 +#ifndef __powerpc64__
4043 +
4044 +static inline unsigned long __must_check copy_from_user(void *to,
4045 + const void __user *from, unsigned long n)
4046 +{
4047 + unsigned long over;
4048 +
4049 + if ((long)n < 0)
4050 + return n;
4051 +
4052 + if (access_ok(VERIFY_READ, from, n)) {
4053 + if (!__builtin_constant_p(n))
4054 + check_object_size(to, n, false);
4055 + return __copy_tofrom_user((__force void __user *)to, from, n);
4056 + }
4057 + if ((unsigned long)from < TASK_SIZE) {
4058 + over = (unsigned long)from + n - TASK_SIZE;
4059 + if (!__builtin_constant_p(n - over))
4060 + check_object_size(to, n - over, false);
4061 + return __copy_tofrom_user((__force void __user *)to, from,
4062 + n - over) + over;
4063 + }
4064 + return n;
4065 +}
4066 +
4067 +static inline unsigned long __must_check copy_to_user(void __user *to,
4068 + const void *from, unsigned long n)
4069 +{
4070 + unsigned long over;
4071 +
4072 + if ((long)n < 0)
4073 + return n;
4074 +
4075 + if (access_ok(VERIFY_WRITE, to, n)) {
4076 + if (!__builtin_constant_p(n))
4077 + check_object_size(from, n, true);
4078 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4079 + }
4080 + if ((unsigned long)to < TASK_SIZE) {
4081 + over = (unsigned long)to + n - TASK_SIZE;
4082 + if (!__builtin_constant_p(n))
4083 + check_object_size(from, n - over, true);
4084 + return __copy_tofrom_user(to, (__force void __user *)from,
4085 + n - over) + over;
4086 + }
4087 + return n;
4088 +}
4089 +
4090 +#else /* __powerpc64__ */
4091 +
4092 +#define __copy_in_user(to, from, size) \
4093 + __copy_tofrom_user((to), (from), (size))
4094 +
4095 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4096 +{
4097 + if ((long)n < 0 || n > INT_MAX)
4098 + return n;
4099 +
4100 + if (!__builtin_constant_p(n))
4101 + check_object_size(to, n, false);
4102 +
4103 + if (likely(access_ok(VERIFY_READ, from, n)))
4104 + n = __copy_from_user(to, from, n);
4105 + else
4106 + memset(to, 0, n);
4107 + return n;
4108 +}
4109 +
4110 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4111 +{
4112 + if ((long)n < 0 || n > INT_MAX)
4113 + return n;
4114 +
4115 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4116 + if (!__builtin_constant_p(n))
4117 + check_object_size(from, n, true);
4118 + n = __copy_to_user(to, from, n);
4119 + }
4120 + return n;
4121 +}
4122 +
4123 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4124 + unsigned long n);
4125 +
4126 +#endif /* __powerpc64__ */
4127 +
4128 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4129
4130 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4131 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4132 index 7215cc2..a9730c1 100644
4133 --- a/arch/powerpc/kernel/exceptions-64e.S
4134 +++ b/arch/powerpc/kernel/exceptions-64e.S
4135 @@ -661,6 +661,7 @@ storage_fault_common:
4136 std r14,_DAR(r1)
4137 std r15,_DSISR(r1)
4138 addi r3,r1,STACK_FRAME_OVERHEAD
4139 + bl .save_nvgprs
4140 mr r4,r14
4141 mr r5,r15
4142 ld r14,PACA_EXGEN+EX_R14(r13)
4143 @@ -669,8 +670,7 @@ storage_fault_common:
4144 cmpdi r3,0
4145 bne- 1f
4146 b .ret_from_except_lite
4147 -1: bl .save_nvgprs
4148 - mr r5,r3
4149 +1: mr r5,r3
4150 addi r3,r1,STACK_FRAME_OVERHEAD
4151 ld r4,_DAR(r1)
4152 bl .bad_page_fault
4153 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4154 index 1c06d29..c2a339b 100644
4155 --- a/arch/powerpc/kernel/exceptions-64s.S
4156 +++ b/arch/powerpc/kernel/exceptions-64s.S
4157 @@ -888,10 +888,10 @@ handle_page_fault:
4158 11: ld r4,_DAR(r1)
4159 ld r5,_DSISR(r1)
4160 addi r3,r1,STACK_FRAME_OVERHEAD
4161 + bl .save_nvgprs
4162 bl .do_page_fault
4163 cmpdi r3,0
4164 beq+ 12f
4165 - bl .save_nvgprs
4166 mr r5,r3
4167 addi r3,r1,STACK_FRAME_OVERHEAD
4168 lwz r4,_DAR(r1)
4169 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4170 index 2e3200c..72095ce 100644
4171 --- a/arch/powerpc/kernel/module_32.c
4172 +++ b/arch/powerpc/kernel/module_32.c
4173 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4174 me->arch.core_plt_section = i;
4175 }
4176 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4177 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4178 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4179 return -ENOEXEC;
4180 }
4181
4182 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4183
4184 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4185 /* Init, or core PLT? */
4186 - if (location >= mod->module_core
4187 - && location < mod->module_core + mod->core_size)
4188 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4189 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4190 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4191 - else
4192 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4193 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4194 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4195 + else {
4196 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4197 + return ~0UL;
4198 + }
4199
4200 /* Find this entry, or if that fails, the next avail. entry */
4201 while (entry->jump[0]) {
4202 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4203 index 710f400..d00ebe6 100644
4204 --- a/arch/powerpc/kernel/process.c
4205 +++ b/arch/powerpc/kernel/process.c
4206 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4207 * Lookup NIP late so we have the best change of getting the
4208 * above info out without failing
4209 */
4210 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4211 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4212 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4213 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4214 #endif
4215 show_stack(current, (unsigned long *) regs->gpr[1]);
4216 if (!user_mode(regs))
4217 @@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4218 newsp = stack[0];
4219 ip = stack[STACK_FRAME_LR_SAVE];
4220 if (!firstframe || ip != lr) {
4221 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4222 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4223 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4224 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4225 - printk(" (%pS)",
4226 + printk(" (%pA)",
4227 (void *)current->ret_stack[curr_frame].ret);
4228 curr_frame--;
4229 }
4230 @@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4231 struct pt_regs *regs = (struct pt_regs *)
4232 (sp + STACK_FRAME_OVERHEAD);
4233 lr = regs->link;
4234 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4235 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4236 regs->trap, (void *)regs->nip, (void *)lr);
4237 firstframe = 1;
4238 }
4239 @@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4240 mtspr(SPRN_CTRLT, ctrl);
4241 }
4242 #endif /* CONFIG_PPC64 */
4243 -
4244 -unsigned long arch_align_stack(unsigned long sp)
4245 -{
4246 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4247 - sp -= get_random_int() & ~PAGE_MASK;
4248 - return sp & ~0xf;
4249 -}
4250 -
4251 -static inline unsigned long brk_rnd(void)
4252 -{
4253 - unsigned long rnd = 0;
4254 -
4255 - /* 8MB for 32bit, 1GB for 64bit */
4256 - if (is_32bit_task())
4257 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4258 - else
4259 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4260 -
4261 - return rnd << PAGE_SHIFT;
4262 -}
4263 -
4264 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4265 -{
4266 - unsigned long base = mm->brk;
4267 - unsigned long ret;
4268 -
4269 -#ifdef CONFIG_PPC_STD_MMU_64
4270 - /*
4271 - * If we are using 1TB segments and we are allowed to randomise
4272 - * the heap, we can put it above 1TB so it is backed by a 1TB
4273 - * segment. Otherwise the heap will be in the bottom 1TB
4274 - * which always uses 256MB segments and this may result in a
4275 - * performance penalty.
4276 - */
4277 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4278 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4279 -#endif
4280 -
4281 - ret = PAGE_ALIGN(base + brk_rnd());
4282 -
4283 - if (ret < mm->brk)
4284 - return mm->brk;
4285 -
4286 - return ret;
4287 -}
4288 -
4289 -unsigned long randomize_et_dyn(unsigned long base)
4290 -{
4291 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4292 -
4293 - if (ret < base)
4294 - return base;
4295 -
4296 - return ret;
4297 -}
4298 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4299 index c10fc28..c4ef063 100644
4300 --- a/arch/powerpc/kernel/ptrace.c
4301 +++ b/arch/powerpc/kernel/ptrace.c
4302 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4303 return ret;
4304 }
4305
4306 +#ifdef CONFIG_GRKERNSEC_SETXID
4307 +extern void gr_delayed_cred_worker(void);
4308 +#endif
4309 +
4310 /*
4311 * We must return the syscall number to actually look up in the table.
4312 * This can be -1L to skip running any syscall at all.
4313 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4314
4315 secure_computing_strict(regs->gpr[0]);
4316
4317 +#ifdef CONFIG_GRKERNSEC_SETXID
4318 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4319 + gr_delayed_cred_worker();
4320 +#endif
4321 +
4322 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4323 tracehook_report_syscall_entry(regs))
4324 /*
4325 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4326 {
4327 int step;
4328
4329 +#ifdef CONFIG_GRKERNSEC_SETXID
4330 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4331 + gr_delayed_cred_worker();
4332 +#endif
4333 +
4334 audit_syscall_exit(regs);
4335
4336 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4337 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4338 index 8b4c049..dcd6ef3 100644
4339 --- a/arch/powerpc/kernel/signal_32.c
4340 +++ b/arch/powerpc/kernel/signal_32.c
4341 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4342 /* Save user registers on the stack */
4343 frame = &rt_sf->uc.uc_mcontext;
4344 addr = frame;
4345 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4346 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4347 if (save_user_regs(regs, frame, 0, 1))
4348 goto badframe;
4349 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4350 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4351 index d183f87..1867f1a 100644
4352 --- a/arch/powerpc/kernel/signal_64.c
4353 +++ b/arch/powerpc/kernel/signal_64.c
4354 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4355 current->thread.fpscr.val = 0;
4356
4357 /* Set up to return from userspace. */
4358 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4359 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4360 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4361 } else {
4362 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4363 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4364 index 1589723..cefe690 100644
4365 --- a/arch/powerpc/kernel/traps.c
4366 +++ b/arch/powerpc/kernel/traps.c
4367 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4368 return flags;
4369 }
4370
4371 +extern void gr_handle_kernel_exploit(void);
4372 +
4373 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4374 int signr)
4375 {
4376 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4377 panic("Fatal exception in interrupt");
4378 if (panic_on_oops)
4379 panic("Fatal exception");
4380 +
4381 + gr_handle_kernel_exploit();
4382 +
4383 do_exit(signr);
4384 }
4385
4386 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4387 index 9eb5b9b..e45498a 100644
4388 --- a/arch/powerpc/kernel/vdso.c
4389 +++ b/arch/powerpc/kernel/vdso.c
4390 @@ -34,6 +34,7 @@
4391 #include <asm/firmware.h>
4392 #include <asm/vdso.h>
4393 #include <asm/vdso_datapage.h>
4394 +#include <asm/mman.h>
4395
4396 #include "setup.h"
4397
4398 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4399 vdso_base = VDSO32_MBASE;
4400 #endif
4401
4402 - current->mm->context.vdso_base = 0;
4403 + current->mm->context.vdso_base = ~0UL;
4404
4405 /* vDSO has a problem and was disabled, just don't "enable" it for the
4406 * process
4407 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = get_unmapped_area(NULL, vdso_base,
4409 (vdso_pages << PAGE_SHIFT) +
4410 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4411 - 0, 0);
4412 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4413 if (IS_ERR_VALUE(vdso_base)) {
4414 rc = vdso_base;
4415 goto fail_mmapsem;
4416 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4417 index 5eea6f3..5d10396 100644
4418 --- a/arch/powerpc/lib/usercopy_64.c
4419 +++ b/arch/powerpc/lib/usercopy_64.c
4420 @@ -9,22 +9,6 @@
4421 #include <linux/module.h>
4422 #include <asm/uaccess.h>
4423
4424 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4425 -{
4426 - if (likely(access_ok(VERIFY_READ, from, n)))
4427 - n = __copy_from_user(to, from, n);
4428 - else
4429 - memset(to, 0, n);
4430 - return n;
4431 -}
4432 -
4433 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4434 -{
4435 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4436 - n = __copy_to_user(to, from, n);
4437 - return n;
4438 -}
4439 -
4440 unsigned long copy_in_user(void __user *to, const void __user *from,
4441 unsigned long n)
4442 {
4443 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4444 return n;
4445 }
4446
4447 -EXPORT_SYMBOL(copy_from_user);
4448 -EXPORT_SYMBOL(copy_to_user);
4449 EXPORT_SYMBOL(copy_in_user);
4450
4451 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4452 index 08ffcf5..a0ab912 100644
4453 --- a/arch/powerpc/mm/fault.c
4454 +++ b/arch/powerpc/mm/fault.c
4455 @@ -32,6 +32,10 @@
4456 #include <linux/perf_event.h>
4457 #include <linux/magic.h>
4458 #include <linux/ratelimit.h>
4459 +#include <linux/slab.h>
4460 +#include <linux/pagemap.h>
4461 +#include <linux/compiler.h>
4462 +#include <linux/unistd.h>
4463
4464 #include <asm/firmware.h>
4465 #include <asm/page.h>
4466 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4467 }
4468 #endif
4469
4470 +#ifdef CONFIG_PAX_PAGEEXEC
4471 +/*
4472 + * PaX: decide what to do with offenders (regs->nip = fault address)
4473 + *
4474 + * returns 1 when task should be killed
4475 + */
4476 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4477 +{
4478 + return 1;
4479 +}
4480 +
4481 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4482 +{
4483 + unsigned long i;
4484 +
4485 + printk(KERN_ERR "PAX: bytes at PC: ");
4486 + for (i = 0; i < 5; i++) {
4487 + unsigned int c;
4488 + if (get_user(c, (unsigned int __user *)pc+i))
4489 + printk(KERN_CONT "???????? ");
4490 + else
4491 + printk(KERN_CONT "%08x ", c);
4492 + }
4493 + printk("\n");
4494 +}
4495 +#endif
4496 +
4497 /*
4498 * Check whether the instruction at regs->nip is a store using
4499 * an update addressing form which will update r1.
4500 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4501 * indicate errors in DSISR but can validly be set in SRR1.
4502 */
4503 if (trap == 0x400)
4504 - error_code &= 0x48200000;
4505 + error_code &= 0x58200000;
4506 else
4507 is_write = error_code & DSISR_ISSTORE;
4508 #else
4509 @@ -366,7 +397,7 @@ good_area:
4510 * "undefined". Of those that can be set, this is the only
4511 * one which seems bad.
4512 */
4513 - if (error_code & 0x10000000)
4514 + if (error_code & DSISR_GUARDED)
4515 /* Guarded storage error. */
4516 goto bad_area;
4517 #endif /* CONFIG_8xx */
4518 @@ -381,7 +412,7 @@ good_area:
4519 * processors use the same I/D cache coherency mechanism
4520 * as embedded.
4521 */
4522 - if (error_code & DSISR_PROTFAULT)
4523 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4524 goto bad_area;
4525 #endif /* CONFIG_PPC_STD_MMU */
4526
4527 @@ -463,6 +494,23 @@ bad_area:
4528 bad_area_nosemaphore:
4529 /* User mode accesses cause a SIGSEGV */
4530 if (user_mode(regs)) {
4531 +
4532 +#ifdef CONFIG_PAX_PAGEEXEC
4533 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4534 +#ifdef CONFIG_PPC_STD_MMU
4535 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4536 +#else
4537 + if (is_exec && regs->nip == address) {
4538 +#endif
4539 + switch (pax_handle_fetch_fault(regs)) {
4540 + }
4541 +
4542 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4543 + do_group_exit(SIGKILL);
4544 + }
4545 + }
4546 +#endif
4547 +
4548 _exception(SIGSEGV, regs, code, address);
4549 return 0;
4550 }
4551 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4552 index 67a42ed..1c7210c 100644
4553 --- a/arch/powerpc/mm/mmap_64.c
4554 +++ b/arch/powerpc/mm/mmap_64.c
4555 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4556 */
4557 if (mmap_is_legacy()) {
4558 mm->mmap_base = TASK_UNMAPPED_BASE;
4559 +
4560 +#ifdef CONFIG_PAX_RANDMMAP
4561 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4562 + mm->mmap_base += mm->delta_mmap;
4563 +#endif
4564 +
4565 mm->get_unmapped_area = arch_get_unmapped_area;
4566 mm->unmap_area = arch_unmap_area;
4567 } else {
4568 mm->mmap_base = mmap_base();
4569 +
4570 +#ifdef CONFIG_PAX_RANDMMAP
4571 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4572 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4573 +#endif
4574 +
4575 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4576 mm->unmap_area = arch_unmap_area_topdown;
4577 }
4578 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4579 index 73709f7..6b90313 100644
4580 --- a/arch/powerpc/mm/slice.c
4581 +++ b/arch/powerpc/mm/slice.c
4582 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4583 if ((mm->task_size - len) < addr)
4584 return 0;
4585 vma = find_vma(mm, addr);
4586 - return (!vma || (addr + len) <= vma->vm_start);
4587 + return check_heap_stack_gap(vma, addr, len);
4588 }
4589
4590 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4591 @@ -256,7 +256,7 @@ full_search:
4592 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4593 continue;
4594 }
4595 - if (!vma || addr + len <= vma->vm_start) {
4596 + if (check_heap_stack_gap(vma, addr, len)) {
4597 /*
4598 * Remember the place where we stopped the search:
4599 */
4600 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4601 }
4602 }
4603
4604 - addr = mm->mmap_base;
4605 - while (addr > len) {
4606 + if (mm->mmap_base < len)
4607 + addr = -ENOMEM;
4608 + else
4609 + addr = mm->mmap_base - len;
4610 +
4611 + while (!IS_ERR_VALUE(addr)) {
4612 /* Go down by chunk size */
4613 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4614 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4615
4616 /* Check for hit with different page size */
4617 mask = slice_range_to_mask(addr, len);
4618 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4619 * return with success:
4620 */
4621 vma = find_vma(mm, addr);
4622 - if (!vma || (addr + len) <= vma->vm_start) {
4623 + if (check_heap_stack_gap(vma, addr, len)) {
4624 /* remember the address as a hint for next time */
4625 if (use_cache)
4626 mm->free_area_cache = addr;
4627 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 mm->cached_hole_size = vma->vm_start - addr;
4629
4630 /* try just below the current vma->vm_start */
4631 - addr = vma->vm_start;
4632 + addr = skip_heap_stack_gap(vma, len);
4633 }
4634
4635 /*
4636 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4637 if (fixed && addr > (mm->task_size - len))
4638 return -EINVAL;
4639
4640 +#ifdef CONFIG_PAX_RANDMMAP
4641 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4642 + addr = 0;
4643 +#endif
4644 +
4645 /* If hint, make sure it matches our alignment restrictions */
4646 if (!fixed && addr) {
4647 addr = _ALIGN_UP(addr, 1ul << pshift);
4648 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4649 index 748347b..81bc6c7 100644
4650 --- a/arch/s390/include/asm/atomic.h
4651 +++ b/arch/s390/include/asm/atomic.h
4652 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4653 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4654 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4655
4656 +#define atomic64_read_unchecked(v) atomic64_read(v)
4657 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4658 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4659 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4660 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4661 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4662 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4663 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4664 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4665 +
4666 #define smp_mb__before_atomic_dec() smp_mb()
4667 #define smp_mb__after_atomic_dec() smp_mb()
4668 #define smp_mb__before_atomic_inc() smp_mb()
4669 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4670 index 2a30d5a..5e5586f 100644
4671 --- a/arch/s390/include/asm/cache.h
4672 +++ b/arch/s390/include/asm/cache.h
4673 @@ -11,8 +11,10 @@
4674 #ifndef __ARCH_S390_CACHE_H
4675 #define __ARCH_S390_CACHE_H
4676
4677 -#define L1_CACHE_BYTES 256
4678 +#include <linux/const.h>
4679 +
4680 #define L1_CACHE_SHIFT 8
4681 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4682 #define NET_SKB_PAD 32
4683
4684 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4685 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4686 index 06151e6..c08cb52 100644
4687 --- a/arch/s390/include/asm/elf.h
4688 +++ b/arch/s390/include/asm/elf.h
4689 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4690 the loader. We need to make sure that it is out of the way of the program
4691 that it will "exec", and that there is sufficient room for the brk. */
4692
4693 -extern unsigned long randomize_et_dyn(unsigned long base);
4694 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4695 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4696 +
4697 +#ifdef CONFIG_PAX_ASLR
4698 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4699 +
4700 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4701 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4702 +#endif
4703
4704 /* This yields a mask that user programs can use to figure out what
4705 instruction set this CPU supports. */
4706 @@ -210,7 +216,4 @@ struct linux_binprm;
4707 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4708 int arch_setup_additional_pages(struct linux_binprm *, int);
4709
4710 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4711 -#define arch_randomize_brk arch_randomize_brk
4712 -
4713 #endif
4714 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4715 index c4a93d6..4d2a9b4 100644
4716 --- a/arch/s390/include/asm/exec.h
4717 +++ b/arch/s390/include/asm/exec.h
4718 @@ -7,6 +7,6 @@
4719 #ifndef __ASM_EXEC_H
4720 #define __ASM_EXEC_H
4721
4722 -extern unsigned long arch_align_stack(unsigned long sp);
4723 +#define arch_align_stack(x) ((x) & ~0xfUL)
4724
4725 #endif /* __ASM_EXEC_H */
4726 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4727 index 1f3a79b..44d7f9c 100644
4728 --- a/arch/s390/include/asm/uaccess.h
4729 +++ b/arch/s390/include/asm/uaccess.h
4730 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4731 copy_to_user(void __user *to, const void *from, unsigned long n)
4732 {
4733 might_fault();
4734 +
4735 + if ((long)n < 0)
4736 + return n;
4737 +
4738 if (access_ok(VERIFY_WRITE, to, n))
4739 n = __copy_to_user(to, from, n);
4740 return n;
4741 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4742 static inline unsigned long __must_check
4743 __copy_from_user(void *to, const void __user *from, unsigned long n)
4744 {
4745 + if ((long)n < 0)
4746 + return n;
4747 +
4748 if (__builtin_constant_p(n) && (n <= 256))
4749 return uaccess.copy_from_user_small(n, from, to);
4750 else
4751 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4752 static inline unsigned long __must_check
4753 copy_from_user(void *to, const void __user *from, unsigned long n)
4754 {
4755 - unsigned int sz = __compiletime_object_size(to);
4756 + size_t sz = __compiletime_object_size(to);
4757
4758 might_fault();
4759 - if (unlikely(sz != -1 && sz < n)) {
4760 +
4761 + if ((long)n < 0)
4762 + return n;
4763 +
4764 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4765 copy_from_user_overflow();
4766 return n;
4767 }
4768 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4769 index dfcb343..eda788a 100644
4770 --- a/arch/s390/kernel/module.c
4771 +++ b/arch/s390/kernel/module.c
4772 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4773
4774 /* Increase core size by size of got & plt and set start
4775 offsets for got and plt. */
4776 - me->core_size = ALIGN(me->core_size, 4);
4777 - me->arch.got_offset = me->core_size;
4778 - me->core_size += me->arch.got_size;
4779 - me->arch.plt_offset = me->core_size;
4780 - me->core_size += me->arch.plt_size;
4781 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4782 + me->arch.got_offset = me->core_size_rw;
4783 + me->core_size_rw += me->arch.got_size;
4784 + me->arch.plt_offset = me->core_size_rx;
4785 + me->core_size_rx += me->arch.plt_size;
4786 return 0;
4787 }
4788
4789 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4790 if (info->got_initialized == 0) {
4791 Elf_Addr *gotent;
4792
4793 - gotent = me->module_core + me->arch.got_offset +
4794 + gotent = me->module_core_rw + me->arch.got_offset +
4795 info->got_offset;
4796 *gotent = val;
4797 info->got_initialized = 1;
4798 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 else if (r_type == R_390_GOTENT ||
4800 r_type == R_390_GOTPLTENT)
4801 *(unsigned int *) loc =
4802 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4803 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4804 else if (r_type == R_390_GOT64 ||
4805 r_type == R_390_GOTPLT64)
4806 *(unsigned long *) loc = val;
4807 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4809 if (info->plt_initialized == 0) {
4810 unsigned int *ip;
4811 - ip = me->module_core + me->arch.plt_offset +
4812 + ip = me->module_core_rx + me->arch.plt_offset +
4813 info->plt_offset;
4814 #ifndef CONFIG_64BIT
4815 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4816 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 val - loc + 0xffffUL < 0x1ffffeUL) ||
4818 (r_type == R_390_PLT32DBL &&
4819 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4820 - val = (Elf_Addr) me->module_core +
4821 + val = (Elf_Addr) me->module_core_rx +
4822 me->arch.plt_offset +
4823 info->plt_offset;
4824 val += rela->r_addend - loc;
4825 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4827 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4828 val = val + rela->r_addend -
4829 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4830 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4831 if (r_type == R_390_GOTOFF16)
4832 *(unsigned short *) loc = val;
4833 else if (r_type == R_390_GOTOFF32)
4834 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 break;
4836 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4837 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4838 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4839 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4840 rela->r_addend - loc;
4841 if (r_type == R_390_GOTPC)
4842 *(unsigned int *) loc = val;
4843 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4844 index 60055ce..ee4b252 100644
4845 --- a/arch/s390/kernel/process.c
4846 +++ b/arch/s390/kernel/process.c
4847 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4848 }
4849 return 0;
4850 }
4851 -
4852 -unsigned long arch_align_stack(unsigned long sp)
4853 -{
4854 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4855 - sp -= get_random_int() & ~PAGE_MASK;
4856 - return sp & ~0xf;
4857 -}
4858 -
4859 -static inline unsigned long brk_rnd(void)
4860 -{
4861 - /* 8MB for 32bit, 1GB for 64bit */
4862 - if (is_32bit_task())
4863 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4864 - else
4865 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4866 -}
4867 -
4868 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4869 -{
4870 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4871 -
4872 - if (ret < mm->brk)
4873 - return mm->brk;
4874 - return ret;
4875 -}
4876 -
4877 -unsigned long randomize_et_dyn(unsigned long base)
4878 -{
4879 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4880 -
4881 - if (!(current->flags & PF_RANDOMIZE))
4882 - return base;
4883 - if (ret < base)
4884 - return base;
4885 - return ret;
4886 -}
4887 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4888 index 2857c48..d047481 100644
4889 --- a/arch/s390/mm/mmap.c
4890 +++ b/arch/s390/mm/mmap.c
4891 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4892 */
4893 if (mmap_is_legacy()) {
4894 mm->mmap_base = TASK_UNMAPPED_BASE;
4895 +
4896 +#ifdef CONFIG_PAX_RANDMMAP
4897 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4898 + mm->mmap_base += mm->delta_mmap;
4899 +#endif
4900 +
4901 mm->get_unmapped_area = arch_get_unmapped_area;
4902 mm->unmap_area = arch_unmap_area;
4903 } else {
4904 mm->mmap_base = mmap_base();
4905 +
4906 +#ifdef CONFIG_PAX_RANDMMAP
4907 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4908 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4909 +#endif
4910 +
4911 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4912 mm->unmap_area = arch_unmap_area_topdown;
4913 }
4914 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4915 */
4916 if (mmap_is_legacy()) {
4917 mm->mmap_base = TASK_UNMAPPED_BASE;
4918 +
4919 +#ifdef CONFIG_PAX_RANDMMAP
4920 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4921 + mm->mmap_base += mm->delta_mmap;
4922 +#endif
4923 +
4924 mm->get_unmapped_area = s390_get_unmapped_area;
4925 mm->unmap_area = arch_unmap_area;
4926 } else {
4927 mm->mmap_base = mmap_base();
4928 +
4929 +#ifdef CONFIG_PAX_RANDMMAP
4930 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4931 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4932 +#endif
4933 +
4934 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4935 mm->unmap_area = arch_unmap_area_topdown;
4936 }
4937 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4938 index ae3d59f..f65f075 100644
4939 --- a/arch/score/include/asm/cache.h
4940 +++ b/arch/score/include/asm/cache.h
4941 @@ -1,7 +1,9 @@
4942 #ifndef _ASM_SCORE_CACHE_H
4943 #define _ASM_SCORE_CACHE_H
4944
4945 +#include <linux/const.h>
4946 +
4947 #define L1_CACHE_SHIFT 4
4948 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4949 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4950
4951 #endif /* _ASM_SCORE_CACHE_H */
4952 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4953 index f9f3cd5..58ff438 100644
4954 --- a/arch/score/include/asm/exec.h
4955 +++ b/arch/score/include/asm/exec.h
4956 @@ -1,6 +1,6 @@
4957 #ifndef _ASM_SCORE_EXEC_H
4958 #define _ASM_SCORE_EXEC_H
4959
4960 -extern unsigned long arch_align_stack(unsigned long sp);
4961 +#define arch_align_stack(x) (x)
4962
4963 #endif /* _ASM_SCORE_EXEC_H */
4964 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4965 index 2707023..1c2a3b7 100644
4966 --- a/arch/score/kernel/process.c
4967 +++ b/arch/score/kernel/process.c
4968 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4969
4970 return task_pt_regs(task)->cp0_epc;
4971 }
4972 -
4973 -unsigned long arch_align_stack(unsigned long sp)
4974 -{
4975 - return sp;
4976 -}
4977 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4978 index ef9e555..331bd29 100644
4979 --- a/arch/sh/include/asm/cache.h
4980 +++ b/arch/sh/include/asm/cache.h
4981 @@ -9,10 +9,11 @@
4982 #define __ASM_SH_CACHE_H
4983 #ifdef __KERNEL__
4984
4985 +#include <linux/const.h>
4986 #include <linux/init.h>
4987 #include <cpu/cache.h>
4988
4989 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4990 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4991
4992 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4993
4994 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4995 index afeb710..d1d1289 100644
4996 --- a/arch/sh/mm/mmap.c
4997 +++ b/arch/sh/mm/mmap.c
4998 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4999 addr = PAGE_ALIGN(addr);
5000
5001 vma = find_vma(mm, addr);
5002 - if (TASK_SIZE - len >= addr &&
5003 - (!vma || addr + len <= vma->vm_start))
5004 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5005 return addr;
5006 }
5007
5008 @@ -106,7 +105,7 @@ full_search:
5009 }
5010 return -ENOMEM;
5011 }
5012 - if (likely(!vma || addr + len <= vma->vm_start)) {
5013 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5014 /*
5015 * Remember the place where we stopped the search:
5016 */
5017 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5018 addr = PAGE_ALIGN(addr);
5019
5020 vma = find_vma(mm, addr);
5021 - if (TASK_SIZE - len >= addr &&
5022 - (!vma || addr + len <= vma->vm_start))
5023 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5024 return addr;
5025 }
5026
5027 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5028 /* make sure it can fit in the remaining address space */
5029 if (likely(addr > len)) {
5030 vma = find_vma(mm, addr-len);
5031 - if (!vma || addr <= vma->vm_start) {
5032 + if (check_heap_stack_gap(vma, addr - len, len)) {
5033 /* remember the address as a hint for next time */
5034 return (mm->free_area_cache = addr-len);
5035 }
5036 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 if (unlikely(mm->mmap_base < len))
5038 goto bottomup;
5039
5040 - addr = mm->mmap_base-len;
5041 - if (do_colour_align)
5042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5043 + addr = mm->mmap_base - len;
5044
5045 do {
5046 + if (do_colour_align)
5047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5048 /*
5049 * Lookup failure means no vma is above this address,
5050 * else if new region fits below vma->vm_start,
5051 * return with success:
5052 */
5053 vma = find_vma(mm, addr);
5054 - if (likely(!vma || addr+len <= vma->vm_start)) {
5055 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5056 /* remember the address as a hint for next time */
5057 return (mm->free_area_cache = addr);
5058 }
5059 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5060 mm->cached_hole_size = vma->vm_start - addr;
5061
5062 /* try just below the current vma->vm_start */
5063 - addr = vma->vm_start-len;
5064 - if (do_colour_align)
5065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5066 - } while (likely(len < vma->vm_start));
5067 + addr = skip_heap_stack_gap(vma, len);
5068 + } while (!IS_ERR_VALUE(addr));
5069
5070 bottomup:
5071 /*
5072 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5073 index ce35a1c..2e7b8f9 100644
5074 --- a/arch/sparc/include/asm/atomic_64.h
5075 +++ b/arch/sparc/include/asm/atomic_64.h
5076 @@ -14,18 +14,40 @@
5077 #define ATOMIC64_INIT(i) { (i) }
5078
5079 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5080 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5081 +{
5082 + return v->counter;
5083 +}
5084 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5085 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5086 +{
5087 + return v->counter;
5088 +}
5089
5090 #define atomic_set(v, i) (((v)->counter) = i)
5091 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5092 +{
5093 + v->counter = i;
5094 +}
5095 #define atomic64_set(v, i) (((v)->counter) = i)
5096 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5097 +{
5098 + v->counter = i;
5099 +}
5100
5101 extern void atomic_add(int, atomic_t *);
5102 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5103 extern void atomic64_add(long, atomic64_t *);
5104 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5105 extern void atomic_sub(int, atomic_t *);
5106 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5107 extern void atomic64_sub(long, atomic64_t *);
5108 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5109
5110 extern int atomic_add_ret(int, atomic_t *);
5111 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5112 extern long atomic64_add_ret(long, atomic64_t *);
5113 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5114 extern int atomic_sub_ret(int, atomic_t *);
5115 extern long atomic64_sub_ret(long, atomic64_t *);
5116
5117 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5118 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5119
5120 #define atomic_inc_return(v) atomic_add_ret(1, v)
5121 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5122 +{
5123 + return atomic_add_ret_unchecked(1, v);
5124 +}
5125 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5126 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5127 +{
5128 + return atomic64_add_ret_unchecked(1, v);
5129 +}
5130
5131 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5132 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5133
5134 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5135 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5136 +{
5137 + return atomic_add_ret_unchecked(i, v);
5138 +}
5139 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5140 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5141 +{
5142 + return atomic64_add_ret_unchecked(i, v);
5143 +}
5144
5145 /*
5146 * atomic_inc_and_test - increment and test
5147 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5148 * other cases.
5149 */
5150 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5151 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5152 +{
5153 + return atomic_inc_return_unchecked(v) == 0;
5154 +}
5155 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5156
5157 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5158 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5159 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5160
5161 #define atomic_inc(v) atomic_add(1, v)
5162 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5163 +{
5164 + atomic_add_unchecked(1, v);
5165 +}
5166 #define atomic64_inc(v) atomic64_add(1, v)
5167 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5168 +{
5169 + atomic64_add_unchecked(1, v);
5170 +}
5171
5172 #define atomic_dec(v) atomic_sub(1, v)
5173 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5174 +{
5175 + atomic_sub_unchecked(1, v);
5176 +}
5177 #define atomic64_dec(v) atomic64_sub(1, v)
5178 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5179 +{
5180 + atomic64_sub_unchecked(1, v);
5181 +}
5182
5183 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5184 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5185
5186 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5187 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5188 +{
5189 + return cmpxchg(&v->counter, old, new);
5190 +}
5191 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5192 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5193 +{
5194 + return xchg(&v->counter, new);
5195 +}
5196
5197 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5198 {
5199 - int c, old;
5200 + int c, old, new;
5201 c = atomic_read(v);
5202 for (;;) {
5203 - if (unlikely(c == (u)))
5204 + if (unlikely(c == u))
5205 break;
5206 - old = atomic_cmpxchg((v), c, c + (a));
5207 +
5208 + asm volatile("addcc %2, %0, %0\n"
5209 +
5210 +#ifdef CONFIG_PAX_REFCOUNT
5211 + "tvs %%icc, 6\n"
5212 +#endif
5213 +
5214 + : "=r" (new)
5215 + : "0" (c), "ir" (a)
5216 + : "cc");
5217 +
5218 + old = atomic_cmpxchg(v, c, new);
5219 if (likely(old == c))
5220 break;
5221 c = old;
5222 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5223 #define atomic64_cmpxchg(v, o, n) \
5224 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5225 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5226 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5227 +{
5228 + return xchg(&v->counter, new);
5229 +}
5230
5231 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5232 {
5233 - long c, old;
5234 + long c, old, new;
5235 c = atomic64_read(v);
5236 for (;;) {
5237 - if (unlikely(c == (u)))
5238 + if (unlikely(c == u))
5239 break;
5240 - old = atomic64_cmpxchg((v), c, c + (a));
5241 +
5242 + asm volatile("addcc %2, %0, %0\n"
5243 +
5244 +#ifdef CONFIG_PAX_REFCOUNT
5245 + "tvs %%xcc, 6\n"
5246 +#endif
5247 +
5248 + : "=r" (new)
5249 + : "0" (c), "ir" (a)
5250 + : "cc");
5251 +
5252 + old = atomic64_cmpxchg(v, c, new);
5253 if (likely(old == c))
5254 break;
5255 c = old;
5256 }
5257 - return c != (u);
5258 + return c != u;
5259 }
5260
5261 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5262 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5263 index 5bb6991..5c2132e 100644
5264 --- a/arch/sparc/include/asm/cache.h
5265 +++ b/arch/sparc/include/asm/cache.h
5266 @@ -7,10 +7,12 @@
5267 #ifndef _SPARC_CACHE_H
5268 #define _SPARC_CACHE_H
5269
5270 +#include <linux/const.h>
5271 +
5272 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5273
5274 #define L1_CACHE_SHIFT 5
5275 -#define L1_CACHE_BYTES 32
5276 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5277
5278 #ifdef CONFIG_SPARC32
5279 #define SMP_CACHE_BYTES_SHIFT 5
5280 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5281 index 2d4d755..81b6662 100644
5282 --- a/arch/sparc/include/asm/elf_32.h
5283 +++ b/arch/sparc/include/asm/elf_32.h
5284 @@ -114,6 +114,13 @@ typedef struct {
5285
5286 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5287
5288 +#ifdef CONFIG_PAX_ASLR
5289 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5290 +
5291 +#define PAX_DELTA_MMAP_LEN 16
5292 +#define PAX_DELTA_STACK_LEN 16
5293 +#endif
5294 +
5295 /* This yields a mask that user programs can use to figure out what
5296 instruction set this cpu supports. This can NOT be done in userspace
5297 on Sparc. */
5298 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5299 index 7df8b7f..4946269 100644
5300 --- a/arch/sparc/include/asm/elf_64.h
5301 +++ b/arch/sparc/include/asm/elf_64.h
5302 @@ -180,6 +180,13 @@ typedef struct {
5303 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5304 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5305
5306 +#ifdef CONFIG_PAX_ASLR
5307 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5308 +
5309 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5310 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5311 +#endif
5312 +
5313 extern unsigned long sparc64_elf_hwcap;
5314 #define ELF_HWCAP sparc64_elf_hwcap
5315
5316 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5317 index e5b169b46..e90b4fa 100644
5318 --- a/arch/sparc/include/asm/pgalloc_32.h
5319 +++ b/arch/sparc/include/asm/pgalloc_32.h
5320 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5321 }
5322
5323 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5324 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5325
5326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5327 unsigned long address)
5328 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5329 index 40b2d7a..22a665b 100644
5330 --- a/arch/sparc/include/asm/pgalloc_64.h
5331 +++ b/arch/sparc/include/asm/pgalloc_64.h
5332 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5333 }
5334
5335 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5336 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5337
5338 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5339 {
5340 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5341 index cbbbed5..0983069 100644
5342 --- a/arch/sparc/include/asm/pgtable_32.h
5343 +++ b/arch/sparc/include/asm/pgtable_32.h
5344 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5345 #define PAGE_SHARED SRMMU_PAGE_SHARED
5346 #define PAGE_COPY SRMMU_PAGE_COPY
5347 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5348 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5349 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5350 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5351 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5352
5353 /* Top-level page directory */
5354 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5355
5356 /* xwr */
5357 #define __P000 PAGE_NONE
5358 -#define __P001 PAGE_READONLY
5359 -#define __P010 PAGE_COPY
5360 -#define __P011 PAGE_COPY
5361 +#define __P001 PAGE_READONLY_NOEXEC
5362 +#define __P010 PAGE_COPY_NOEXEC
5363 +#define __P011 PAGE_COPY_NOEXEC
5364 #define __P100 PAGE_READONLY
5365 #define __P101 PAGE_READONLY
5366 #define __P110 PAGE_COPY
5367 #define __P111 PAGE_COPY
5368
5369 #define __S000 PAGE_NONE
5370 -#define __S001 PAGE_READONLY
5371 -#define __S010 PAGE_SHARED
5372 -#define __S011 PAGE_SHARED
5373 +#define __S001 PAGE_READONLY_NOEXEC
5374 +#define __S010 PAGE_SHARE_NOEXEC
5375 +#define __S011 PAGE_SHARE_NOEXEC
5376 #define __S100 PAGE_READONLY
5377 #define __S101 PAGE_READONLY
5378 #define __S110 PAGE_SHARED
5379 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5380 index 79da178..c2eede8 100644
5381 --- a/arch/sparc/include/asm/pgtsrmmu.h
5382 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5383 @@ -115,6 +115,11 @@
5384 SRMMU_EXEC | SRMMU_REF)
5385 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5386 SRMMU_EXEC | SRMMU_REF)
5387 +
5388 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5389 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5390 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5391 +
5392 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5393 SRMMU_DIRTY | SRMMU_REF)
5394
5395 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5396 index 9689176..63c18ea 100644
5397 --- a/arch/sparc/include/asm/spinlock_64.h
5398 +++ b/arch/sparc/include/asm/spinlock_64.h
5399 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5400
5401 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5402
5403 -static void inline arch_read_lock(arch_rwlock_t *lock)
5404 +static inline void arch_read_lock(arch_rwlock_t *lock)
5405 {
5406 unsigned long tmp1, tmp2;
5407
5408 __asm__ __volatile__ (
5409 "1: ldsw [%2], %0\n"
5410 " brlz,pn %0, 2f\n"
5411 -"4: add %0, 1, %1\n"
5412 +"4: addcc %0, 1, %1\n"
5413 +
5414 +#ifdef CONFIG_PAX_REFCOUNT
5415 +" tvs %%icc, 6\n"
5416 +#endif
5417 +
5418 " cas [%2], %0, %1\n"
5419 " cmp %0, %1\n"
5420 " bne,pn %%icc, 1b\n"
5421 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5422 " .previous"
5423 : "=&r" (tmp1), "=&r" (tmp2)
5424 : "r" (lock)
5425 - : "memory");
5426 + : "memory", "cc");
5427 }
5428
5429 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5430 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5431 {
5432 int tmp1, tmp2;
5433
5434 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5435 "1: ldsw [%2], %0\n"
5436 " brlz,a,pn %0, 2f\n"
5437 " mov 0, %0\n"
5438 -" add %0, 1, %1\n"
5439 +" addcc %0, 1, %1\n"
5440 +
5441 +#ifdef CONFIG_PAX_REFCOUNT
5442 +" tvs %%icc, 6\n"
5443 +#endif
5444 +
5445 " cas [%2], %0, %1\n"
5446 " cmp %0, %1\n"
5447 " bne,pn %%icc, 1b\n"
5448 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 return tmp1;
5450 }
5451
5452 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5453 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5454 {
5455 unsigned long tmp1, tmp2;
5456
5457 __asm__ __volatile__(
5458 "1: lduw [%2], %0\n"
5459 -" sub %0, 1, %1\n"
5460 +" subcc %0, 1, %1\n"
5461 +
5462 +#ifdef CONFIG_PAX_REFCOUNT
5463 +" tvs %%icc, 6\n"
5464 +#endif
5465 +
5466 " cas [%2], %0, %1\n"
5467 " cmp %0, %1\n"
5468 " bne,pn %%xcc, 1b\n"
5469 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5470 : "memory");
5471 }
5472
5473 -static void inline arch_write_lock(arch_rwlock_t *lock)
5474 +static inline void arch_write_lock(arch_rwlock_t *lock)
5475 {
5476 unsigned long mask, tmp1, tmp2;
5477
5478 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5483 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5484 {
5485 __asm__ __volatile__(
5486 " stw %%g0, [%0]"
5487 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5492 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5493 {
5494 unsigned long mask, tmp1, tmp2, result;
5495
5496 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5497 index e6cd224..3a71793 100644
5498 --- a/arch/sparc/include/asm/thread_info_32.h
5499 +++ b/arch/sparc/include/asm/thread_info_32.h
5500 @@ -49,6 +49,8 @@ struct thread_info {
5501 unsigned long w_saved;
5502
5503 struct restart_block restart_block;
5504 +
5505 + unsigned long lowest_stack;
5506 };
5507
5508 /*
5509 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5510 index cfa8c38..13f30d3 100644
5511 --- a/arch/sparc/include/asm/thread_info_64.h
5512 +++ b/arch/sparc/include/asm/thread_info_64.h
5513 @@ -63,6 +63,8 @@ struct thread_info {
5514 struct pt_regs *kern_una_regs;
5515 unsigned int kern_una_insn;
5516
5517 + unsigned long lowest_stack;
5518 +
5519 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5520 };
5521
5522 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5523 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5524 /* flag bit 6 is available */
5525 #define TIF_32BIT 7 /* 32-bit binary */
5526 -/* flag bit 8 is available */
5527 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5528 #define TIF_SECCOMP 9 /* secure computing */
5529 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5530 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5531 +
5532 /* NOTE: Thread flags >= 12 should be ones we have no interest
5533 * in using in assembly, else we can't use the mask as
5534 * an immediate value in instructions such as andcc.
5535 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5536 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5537 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5538 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5539 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5540
5541 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5542 _TIF_DO_NOTIFY_RESUME_MASK | \
5543 _TIF_NEED_RESCHED)
5544 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5545
5546 +#define _TIF_WORK_SYSCALL \
5547 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5548 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5549 +
5550 +
5551 /*
5552 * Thread-synchronous status.
5553 *
5554 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5555 index 0167d26..9acd8ed 100644
5556 --- a/arch/sparc/include/asm/uaccess.h
5557 +++ b/arch/sparc/include/asm/uaccess.h
5558 @@ -1,5 +1,13 @@
5559 #ifndef ___ASM_SPARC_UACCESS_H
5560 #define ___ASM_SPARC_UACCESS_H
5561 +
5562 +#ifdef __KERNEL__
5563 +#ifndef __ASSEMBLY__
5564 +#include <linux/types.h>
5565 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5566 +#endif
5567 +#endif
5568 +
5569 #if defined(__sparc__) && defined(__arch64__)
5570 #include <asm/uaccess_64.h>
5571 #else
5572 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5573 index 53a28dd..50c38c3 100644
5574 --- a/arch/sparc/include/asm/uaccess_32.h
5575 +++ b/arch/sparc/include/asm/uaccess_32.h
5576 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5577
5578 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5579 {
5580 - if (n && __access_ok((unsigned long) to, n))
5581 + if ((long)n < 0)
5582 + return n;
5583 +
5584 + if (n && __access_ok((unsigned long) to, n)) {
5585 + if (!__builtin_constant_p(n))
5586 + check_object_size(from, n, true);
5587 return __copy_user(to, (__force void __user *) from, n);
5588 - else
5589 + } else
5590 return n;
5591 }
5592
5593 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5594 {
5595 + if ((long)n < 0)
5596 + return n;
5597 +
5598 + if (!__builtin_constant_p(n))
5599 + check_object_size(from, n, true);
5600 +
5601 return __copy_user(to, (__force void __user *) from, n);
5602 }
5603
5604 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5605 {
5606 - if (n && __access_ok((unsigned long) from, n))
5607 + if ((long)n < 0)
5608 + return n;
5609 +
5610 + if (n && __access_ok((unsigned long) from, n)) {
5611 + if (!__builtin_constant_p(n))
5612 + check_object_size(to, n, false);
5613 return __copy_user((__force void __user *) to, from, n);
5614 - else
5615 + } else
5616 return n;
5617 }
5618
5619 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5620 {
5621 + if ((long)n < 0)
5622 + return n;
5623 +
5624 return __copy_user((__force void __user *) to, from, n);
5625 }
5626
5627 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5628 index 7c831d8..d440ca7 100644
5629 --- a/arch/sparc/include/asm/uaccess_64.h
5630 +++ b/arch/sparc/include/asm/uaccess_64.h
5631 @@ -10,6 +10,7 @@
5632 #include <linux/compiler.h>
5633 #include <linux/string.h>
5634 #include <linux/thread_info.h>
5635 +#include <linux/kernel.h>
5636 #include <asm/asi.h>
5637 #include <asm/spitfire.h>
5638 #include <asm-generic/uaccess-unaligned.h>
5639 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5640 static inline unsigned long __must_check
5641 copy_from_user(void *to, const void __user *from, unsigned long size)
5642 {
5643 - unsigned long ret = ___copy_from_user(to, from, size);
5644 + unsigned long ret;
5645
5646 + if ((long)size < 0 || size > INT_MAX)
5647 + return size;
5648 +
5649 + if (!__builtin_constant_p(size))
5650 + check_object_size(to, size, false);
5651 +
5652 + ret = ___copy_from_user(to, from, size);
5653 if (unlikely(ret))
5654 ret = copy_from_user_fixup(to, from, size);
5655
5656 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5657 static inline unsigned long __must_check
5658 copy_to_user(void __user *to, const void *from, unsigned long size)
5659 {
5660 - unsigned long ret = ___copy_to_user(to, from, size);
5661 + unsigned long ret;
5662
5663 + if ((long)size < 0 || size > INT_MAX)
5664 + return size;
5665 +
5666 + if (!__builtin_constant_p(size))
5667 + check_object_size(from, size, true);
5668 +
5669 + ret = ___copy_to_user(to, from, size);
5670 if (unlikely(ret))
5671 ret = copy_to_user_fixup(to, from, size);
5672 return ret;
5673 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5674 index 6cf591b..b49e65a 100644
5675 --- a/arch/sparc/kernel/Makefile
5676 +++ b/arch/sparc/kernel/Makefile
5677 @@ -3,7 +3,7 @@
5678 #
5679
5680 asflags-y := -ansi
5681 -ccflags-y := -Werror
5682 +#ccflags-y := -Werror
5683
5684 extra-y := head_$(BITS).o
5685
5686 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5687 index cb36e82..1c1462f 100644
5688 --- a/arch/sparc/kernel/process_32.c
5689 +++ b/arch/sparc/kernel/process_32.c
5690 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5691
5692 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5693 r->psr, r->pc, r->npc, r->y, print_tainted());
5694 - printk("PC: <%pS>\n", (void *) r->pc);
5695 + printk("PC: <%pA>\n", (void *) r->pc);
5696 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5697 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5698 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5699 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5700 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5701 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5702 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5703 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5704
5705 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5706 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5707 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5708 rw = (struct reg_window32 *) fp;
5709 pc = rw->ins[7];
5710 printk("[%08lx : ", pc);
5711 - printk("%pS ] ", (void *) pc);
5712 + printk("%pA ] ", (void *) pc);
5713 fp = rw->ins[6];
5714 } while (++count < 16);
5715 printk("\n");
5716 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5717 index aff0c72..9067b39 100644
5718 --- a/arch/sparc/kernel/process_64.c
5719 +++ b/arch/sparc/kernel/process_64.c
5720 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5721 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5722 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5723 if (regs->tstate & TSTATE_PRIV)
5724 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5725 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5726 }
5727
5728 void show_regs(struct pt_regs *regs)
5729 {
5730 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5731 regs->tpc, regs->tnpc, regs->y, print_tainted());
5732 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5733 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5734 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5735 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5736 regs->u_regs[3]);
5737 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5738 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5739 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5740 regs->u_regs[15]);
5741 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5742 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5743 show_regwindow(regs);
5744 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5745 }
5746 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5747 ((tp && tp->task) ? tp->task->pid : -1));
5748
5749 if (gp->tstate & TSTATE_PRIV) {
5750 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5751 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5752 (void *) gp->tpc,
5753 (void *) gp->o7,
5754 (void *) gp->i7,
5755 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5756 index 484daba..0674139 100644
5757 --- a/arch/sparc/kernel/ptrace_64.c
5758 +++ b/arch/sparc/kernel/ptrace_64.c
5759 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5760 return ret;
5761 }
5762
5763 +#ifdef CONFIG_GRKERNSEC_SETXID
5764 +extern void gr_delayed_cred_worker(void);
5765 +#endif
5766 +
5767 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5768 {
5769 int ret = 0;
5770 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5771 /* do the secure computing check first */
5772 secure_computing_strict(regs->u_regs[UREG_G1]);
5773
5774 +#ifdef CONFIG_GRKERNSEC_SETXID
5775 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5776 + gr_delayed_cred_worker();
5777 +#endif
5778 +
5779 if (test_thread_flag(TIF_SYSCALL_TRACE))
5780 ret = tracehook_report_syscall_entry(regs);
5781
5782 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5783
5784 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5785 {
5786 +#ifdef CONFIG_GRKERNSEC_SETXID
5787 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5788 + gr_delayed_cred_worker();
5789 +#endif
5790 +
5791 audit_syscall_exit(regs);
5792
5793 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5794 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5795 index 0c9b31b..7cb7aee 100644
5796 --- a/arch/sparc/kernel/sys_sparc_32.c
5797 +++ b/arch/sparc/kernel/sys_sparc_32.c
5798 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5799 if (len > TASK_SIZE - PAGE_SIZE)
5800 return -ENOMEM;
5801 if (!addr)
5802 - addr = TASK_UNMAPPED_BASE;
5803 + addr = current->mm->mmap_base;
5804
5805 if (flags & MAP_SHARED)
5806 addr = COLOUR_ALIGN(addr);
5807 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5808 /* At this point: (!vmm || addr < vmm->vm_end). */
5809 if (TASK_SIZE - PAGE_SIZE - len < addr)
5810 return -ENOMEM;
5811 - if (!vmm || addr + len <= vmm->vm_start)
5812 + if (check_heap_stack_gap(vmm, addr, len))
5813 return addr;
5814 addr = vmm->vm_end;
5815 if (flags & MAP_SHARED)
5816 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5817 index 275f74f..81bf5b8 100644
5818 --- a/arch/sparc/kernel/sys_sparc_64.c
5819 +++ b/arch/sparc/kernel/sys_sparc_64.c
5820 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5821 /* We do not accept a shared mapping if it would violate
5822 * cache aliasing constraints.
5823 */
5824 - if ((flags & MAP_SHARED) &&
5825 + if ((filp || (flags & MAP_SHARED)) &&
5826 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5827 return -EINVAL;
5828 return addr;
5829 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5830 if (filp || (flags & MAP_SHARED))
5831 do_color_align = 1;
5832
5833 +#ifdef CONFIG_PAX_RANDMMAP
5834 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5835 +#endif
5836 +
5837 if (addr) {
5838 if (do_color_align)
5839 addr = COLOUR_ALIGN(addr, pgoff);
5840 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5841 addr = PAGE_ALIGN(addr);
5842
5843 vma = find_vma(mm, addr);
5844 - if (task_size - len >= addr &&
5845 - (!vma || addr + len <= vma->vm_start))
5846 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5847 return addr;
5848 }
5849
5850 if (len > mm->cached_hole_size) {
5851 - start_addr = addr = mm->free_area_cache;
5852 + start_addr = addr = mm->free_area_cache;
5853 } else {
5854 - start_addr = addr = TASK_UNMAPPED_BASE;
5855 + start_addr = addr = mm->mmap_base;
5856 mm->cached_hole_size = 0;
5857 }
5858
5859 @@ -174,14 +177,14 @@ full_search:
5860 vma = find_vma(mm, VA_EXCLUDE_END);
5861 }
5862 if (unlikely(task_size < addr)) {
5863 - if (start_addr != TASK_UNMAPPED_BASE) {
5864 - start_addr = addr = TASK_UNMAPPED_BASE;
5865 + if (start_addr != mm->mmap_base) {
5866 + start_addr = addr = mm->mmap_base;
5867 mm->cached_hole_size = 0;
5868 goto full_search;
5869 }
5870 return -ENOMEM;
5871 }
5872 - if (likely(!vma || addr + len <= vma->vm_start)) {
5873 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5874 /*
5875 * Remember the place where we stopped the search:
5876 */
5877 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5878 /* We do not accept a shared mapping if it would violate
5879 * cache aliasing constraints.
5880 */
5881 - if ((flags & MAP_SHARED) &&
5882 + if ((filp || (flags & MAP_SHARED)) &&
5883 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5884 return -EINVAL;
5885 return addr;
5886 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5887 addr = PAGE_ALIGN(addr);
5888
5889 vma = find_vma(mm, addr);
5890 - if (task_size - len >= addr &&
5891 - (!vma || addr + len <= vma->vm_start))
5892 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5893 return addr;
5894 }
5895
5896 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5897 /* make sure it can fit in the remaining address space */
5898 if (likely(addr > len)) {
5899 vma = find_vma(mm, addr-len);
5900 - if (!vma || addr <= vma->vm_start) {
5901 + if (check_heap_stack_gap(vma, addr - len, len)) {
5902 /* remember the address as a hint for next time */
5903 return (mm->free_area_cache = addr-len);
5904 }
5905 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 if (unlikely(mm->mmap_base < len))
5907 goto bottomup;
5908
5909 - addr = mm->mmap_base-len;
5910 - if (do_color_align)
5911 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5912 + addr = mm->mmap_base - len;
5913
5914 do {
5915 + if (do_color_align)
5916 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5917 /*
5918 * Lookup failure means no vma is above this address,
5919 * else if new region fits below vma->vm_start,
5920 * return with success:
5921 */
5922 vma = find_vma(mm, addr);
5923 - if (likely(!vma || addr+len <= vma->vm_start)) {
5924 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5925 /* remember the address as a hint for next time */
5926 return (mm->free_area_cache = addr);
5927 }
5928 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5929 mm->cached_hole_size = vma->vm_start - addr;
5930
5931 /* try just below the current vma->vm_start */
5932 - addr = vma->vm_start-len;
5933 - if (do_color_align)
5934 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5935 - } while (likely(len < vma->vm_start));
5936 + addr = skip_heap_stack_gap(vma, len);
5937 + } while (!IS_ERR_VALUE(addr));
5938
5939 bottomup:
5940 /*
5941 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5942 gap == RLIM_INFINITY ||
5943 sysctl_legacy_va_layout) {
5944 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5945 +
5946 +#ifdef CONFIG_PAX_RANDMMAP
5947 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5948 + mm->mmap_base += mm->delta_mmap;
5949 +#endif
5950 +
5951 mm->get_unmapped_area = arch_get_unmapped_area;
5952 mm->unmap_area = arch_unmap_area;
5953 } else {
5954 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5955 gap = (task_size / 6 * 5);
5956
5957 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5958 +
5959 +#ifdef CONFIG_PAX_RANDMMAP
5960 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5961 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5962 +#endif
5963 +
5964 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5965 mm->unmap_area = arch_unmap_area_topdown;
5966 }
5967 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5968 index 1d7e274..b39c527 100644
5969 --- a/arch/sparc/kernel/syscalls.S
5970 +++ b/arch/sparc/kernel/syscalls.S
5971 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5972 #endif
5973 .align 32
5974 1: ldx [%g6 + TI_FLAGS], %l5
5975 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5976 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5977 be,pt %icc, rtrap
5978 nop
5979 call syscall_trace_leave
5980 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5981
5982 srl %i5, 0, %o5 ! IEU1
5983 srl %i2, 0, %o2 ! IEU0 Group
5984 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5985 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5986 bne,pn %icc, linux_syscall_trace32 ! CTI
5987 mov %i0, %l5 ! IEU1
5988 call %l7 ! CTI Group brk forced
5989 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5990
5991 mov %i3, %o3 ! IEU1
5992 mov %i4, %o4 ! IEU0 Group
5993 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5994 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5995 bne,pn %icc, linux_syscall_trace ! CTI Group
5996 mov %i0, %l5 ! IEU0
5997 2: call %l7 ! CTI Group brk forced
5998 @@ -226,7 +226,7 @@ ret_sys_call:
5999
6000 cmp %o0, -ERESTART_RESTARTBLOCK
6001 bgeu,pn %xcc, 1f
6002 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6003 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6004 80:
6005 /* System call success, clear Carry condition code. */
6006 andn %g3, %g2, %g3
6007 @@ -241,7 +241,7 @@ ret_sys_call:
6008 /* System call failure, set Carry condition code.
6009 * Also, get abs(errno) to return to the process.
6010 */
6011 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6012 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6013 sub %g0, %o0, %o0
6014 or %g3, %g2, %g3
6015 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6016 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6017 index a5785ea..405c5f7 100644
6018 --- a/arch/sparc/kernel/traps_32.c
6019 +++ b/arch/sparc/kernel/traps_32.c
6020 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6021 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6022 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6023
6024 +extern void gr_handle_kernel_exploit(void);
6025 +
6026 void die_if_kernel(char *str, struct pt_regs *regs)
6027 {
6028 static int die_counter;
6029 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6030 count++ < 30 &&
6031 (((unsigned long) rw) >= PAGE_OFFSET) &&
6032 !(((unsigned long) rw) & 0x7)) {
6033 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6034 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6035 (void *) rw->ins[7]);
6036 rw = (struct reg_window32 *)rw->ins[6];
6037 }
6038 }
6039 printk("Instruction DUMP:");
6040 instruction_dump ((unsigned long *) regs->pc);
6041 - if(regs->psr & PSR_PS)
6042 + if(regs->psr & PSR_PS) {
6043 + gr_handle_kernel_exploit();
6044 do_exit(SIGKILL);
6045 + }
6046 do_exit(SIGSEGV);
6047 }
6048
6049 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6050 index 3b05e66..6ea2917 100644
6051 --- a/arch/sparc/kernel/traps_64.c
6052 +++ b/arch/sparc/kernel/traps_64.c
6053 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6054 i + 1,
6055 p->trapstack[i].tstate, p->trapstack[i].tpc,
6056 p->trapstack[i].tnpc, p->trapstack[i].tt);
6057 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6058 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6059 }
6060 }
6061
6062 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6063
6064 lvl -= 0x100;
6065 if (regs->tstate & TSTATE_PRIV) {
6066 +
6067 +#ifdef CONFIG_PAX_REFCOUNT
6068 + if (lvl == 6)
6069 + pax_report_refcount_overflow(regs);
6070 +#endif
6071 +
6072 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6073 die_if_kernel(buffer, regs);
6074 }
6075 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6076 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6077 {
6078 char buffer[32];
6079 -
6080 +
6081 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6082 0, lvl, SIGTRAP) == NOTIFY_STOP)
6083 return;
6084
6085 +#ifdef CONFIG_PAX_REFCOUNT
6086 + if (lvl == 6)
6087 + pax_report_refcount_overflow(regs);
6088 +#endif
6089 +
6090 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6091
6092 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6093 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6094 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6095 printk("%s" "ERROR(%d): ",
6096 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6097 - printk("TPC<%pS>\n", (void *) regs->tpc);
6098 + printk("TPC<%pA>\n", (void *) regs->tpc);
6099 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6100 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6101 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6102 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6103 smp_processor_id(),
6104 (type & 0x1) ? 'I' : 'D',
6105 regs->tpc);
6106 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6107 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6108 panic("Irrecoverable Cheetah+ parity error.");
6109 }
6110
6111 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6112 smp_processor_id(),
6113 (type & 0x1) ? 'I' : 'D',
6114 regs->tpc);
6115 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6116 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6117 }
6118
6119 struct sun4v_error_entry {
6120 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6121
6122 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6123 regs->tpc, tl);
6124 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6125 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6126 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6127 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6128 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6129 (void *) regs->u_regs[UREG_I7]);
6130 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6131 "pte[%lx] error[%lx]\n",
6132 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6133
6134 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6135 regs->tpc, tl);
6136 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6137 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6138 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6139 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6140 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6141 (void *) regs->u_regs[UREG_I7]);
6142 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6143 "pte[%lx] error[%lx]\n",
6144 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6145 fp = (unsigned long)sf->fp + STACK_BIAS;
6146 }
6147
6148 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6149 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6150 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6151 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6152 int index = tsk->curr_ret_stack;
6153 if (tsk->ret_stack && index >= graph) {
6154 pc = tsk->ret_stack[index - graph].ret;
6155 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6156 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6157 graph++;
6158 }
6159 }
6160 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6161 return (struct reg_window *) (fp + STACK_BIAS);
6162 }
6163
6164 +extern void gr_handle_kernel_exploit(void);
6165 +
6166 void die_if_kernel(char *str, struct pt_regs *regs)
6167 {
6168 static int die_counter;
6169 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6170 while (rw &&
6171 count++ < 30 &&
6172 kstack_valid(tp, (unsigned long) rw)) {
6173 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6174 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6175 (void *) rw->ins[7]);
6176
6177 rw = kernel_stack_up(rw);
6178 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6179 }
6180 user_instruction_dump ((unsigned int __user *) regs->tpc);
6181 }
6182 - if (regs->tstate & TSTATE_PRIV)
6183 + if (regs->tstate & TSTATE_PRIV) {
6184 + gr_handle_kernel_exploit();
6185 do_exit(SIGKILL);
6186 + }
6187 do_exit(SIGSEGV);
6188 }
6189 EXPORT_SYMBOL(die_if_kernel);
6190 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6191 index f81d038..e7a4680 100644
6192 --- a/arch/sparc/kernel/unaligned_64.c
6193 +++ b/arch/sparc/kernel/unaligned_64.c
6194 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6195 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6196
6197 if (__ratelimit(&ratelimit)) {
6198 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6199 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6200 regs->tpc, (void *) regs->tpc);
6201 }
6202 }
6203 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6204 index dff4096..bd9a388 100644
6205 --- a/arch/sparc/lib/Makefile
6206 +++ b/arch/sparc/lib/Makefile
6207 @@ -2,7 +2,7 @@
6208 #
6209
6210 asflags-y := -ansi -DST_DIV0=0x02
6211 -ccflags-y := -Werror
6212 +#ccflags-y := -Werror
6213
6214 lib-$(CONFIG_SPARC32) += ashrdi3.o
6215 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6216 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6217 index 4d502da..527c48d 100644
6218 --- a/arch/sparc/lib/atomic_64.S
6219 +++ b/arch/sparc/lib/atomic_64.S
6220 @@ -17,7 +17,12 @@
6221 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6222 BACKOFF_SETUP(%o2)
6223 1: lduw [%o1], %g1
6224 - add %g1, %o0, %g7
6225 + addcc %g1, %o0, %g7
6226 +
6227 +#ifdef CONFIG_PAX_REFCOUNT
6228 + tvs %icc, 6
6229 +#endif
6230 +
6231 cas [%o1], %g1, %g7
6232 cmp %g1, %g7
6233 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6234 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6235 2: BACKOFF_SPIN(%o2, %o3, 1b)
6236 ENDPROC(atomic_add)
6237
6238 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6239 + BACKOFF_SETUP(%o2)
6240 +1: lduw [%o1], %g1
6241 + add %g1, %o0, %g7
6242 + cas [%o1], %g1, %g7
6243 + cmp %g1, %g7
6244 + bne,pn %icc, 2f
6245 + nop
6246 + retl
6247 + nop
6248 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 +ENDPROC(atomic_add_unchecked)
6250 +
6251 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6252 BACKOFF_SETUP(%o2)
6253 1: lduw [%o1], %g1
6254 - sub %g1, %o0, %g7
6255 + subcc %g1, %o0, %g7
6256 +
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + tvs %icc, 6
6259 +#endif
6260 +
6261 cas [%o1], %g1, %g7
6262 cmp %g1, %g7
6263 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6264 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6265 2: BACKOFF_SPIN(%o2, %o3, 1b)
6266 ENDPROC(atomic_sub)
6267
6268 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6269 + BACKOFF_SETUP(%o2)
6270 +1: lduw [%o1], %g1
6271 + sub %g1, %o0, %g7
6272 + cas [%o1], %g1, %g7
6273 + cmp %g1, %g7
6274 + bne,pn %icc, 2f
6275 + nop
6276 + retl
6277 + nop
6278 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 +ENDPROC(atomic_sub_unchecked)
6280 +
6281 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6282 BACKOFF_SETUP(%o2)
6283 1: lduw [%o1], %g1
6284 - add %g1, %o0, %g7
6285 + addcc %g1, %o0, %g7
6286 +
6287 +#ifdef CONFIG_PAX_REFCOUNT
6288 + tvs %icc, 6
6289 +#endif
6290 +
6291 cas [%o1], %g1, %g7
6292 cmp %g1, %g7
6293 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6294 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6295 2: BACKOFF_SPIN(%o2, %o3, 1b)
6296 ENDPROC(atomic_add_ret)
6297
6298 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6299 + BACKOFF_SETUP(%o2)
6300 +1: lduw [%o1], %g1
6301 + addcc %g1, %o0, %g7
6302 + cas [%o1], %g1, %g7
6303 + cmp %g1, %g7
6304 + bne,pn %icc, 2f
6305 + add %g7, %o0, %g7
6306 + sra %g7, 0, %o0
6307 + retl
6308 + nop
6309 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 +ENDPROC(atomic_add_ret_unchecked)
6311 +
6312 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6313 BACKOFF_SETUP(%o2)
6314 1: lduw [%o1], %g1
6315 - sub %g1, %o0, %g7
6316 + subcc %g1, %o0, %g7
6317 +
6318 +#ifdef CONFIG_PAX_REFCOUNT
6319 + tvs %icc, 6
6320 +#endif
6321 +
6322 cas [%o1], %g1, %g7
6323 cmp %g1, %g7
6324 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6325 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6326 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6327 BACKOFF_SETUP(%o2)
6328 1: ldx [%o1], %g1
6329 - add %g1, %o0, %g7
6330 + addcc %g1, %o0, %g7
6331 +
6332 +#ifdef CONFIG_PAX_REFCOUNT
6333 + tvs %xcc, 6
6334 +#endif
6335 +
6336 casx [%o1], %g1, %g7
6337 cmp %g1, %g7
6338 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6339 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6340 2: BACKOFF_SPIN(%o2, %o3, 1b)
6341 ENDPROC(atomic64_add)
6342
6343 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6344 + BACKOFF_SETUP(%o2)
6345 +1: ldx [%o1], %g1
6346 + addcc %g1, %o0, %g7
6347 + casx [%o1], %g1, %g7
6348 + cmp %g1, %g7
6349 + bne,pn %xcc, 2f
6350 + nop
6351 + retl
6352 + nop
6353 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 +ENDPROC(atomic64_add_unchecked)
6355 +
6356 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: ldx [%o1], %g1
6359 - sub %g1, %o0, %g7
6360 + subcc %g1, %o0, %g7
6361 +
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + tvs %xcc, 6
6364 +#endif
6365 +
6366 casx [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6369 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6370 2: BACKOFF_SPIN(%o2, %o3, 1b)
6371 ENDPROC(atomic64_sub)
6372
6373 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6374 + BACKOFF_SETUP(%o2)
6375 +1: ldx [%o1], %g1
6376 + subcc %g1, %o0, %g7
6377 + casx [%o1], %g1, %g7
6378 + cmp %g1, %g7
6379 + bne,pn %xcc, 2f
6380 + nop
6381 + retl
6382 + nop
6383 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 +ENDPROC(atomic64_sub_unchecked)
6385 +
6386 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6387 BACKOFF_SETUP(%o2)
6388 1: ldx [%o1], %g1
6389 - add %g1, %o0, %g7
6390 + addcc %g1, %o0, %g7
6391 +
6392 +#ifdef CONFIG_PAX_REFCOUNT
6393 + tvs %xcc, 6
6394 +#endif
6395 +
6396 casx [%o1], %g1, %g7
6397 cmp %g1, %g7
6398 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6399 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6400 2: BACKOFF_SPIN(%o2, %o3, 1b)
6401 ENDPROC(atomic64_add_ret)
6402
6403 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6404 + BACKOFF_SETUP(%o2)
6405 +1: ldx [%o1], %g1
6406 + addcc %g1, %o0, %g7
6407 + casx [%o1], %g1, %g7
6408 + cmp %g1, %g7
6409 + bne,pn %xcc, 2f
6410 + add %g7, %o0, %g7
6411 + mov %g7, %o0
6412 + retl
6413 + nop
6414 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 +ENDPROC(atomic64_add_ret_unchecked)
6416 +
6417 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6418 BACKOFF_SETUP(%o2)
6419 1: ldx [%o1], %g1
6420 - sub %g1, %o0, %g7
6421 + subcc %g1, %o0, %g7
6422 +
6423 +#ifdef CONFIG_PAX_REFCOUNT
6424 + tvs %xcc, 6
6425 +#endif
6426 +
6427 casx [%o1], %g1, %g7
6428 cmp %g1, %g7
6429 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6430 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6431 index 3b31218..345c609 100644
6432 --- a/arch/sparc/lib/ksyms.c
6433 +++ b/arch/sparc/lib/ksyms.c
6434 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6435
6436 /* Atomic counter implementation. */
6437 EXPORT_SYMBOL(atomic_add);
6438 +EXPORT_SYMBOL(atomic_add_unchecked);
6439 EXPORT_SYMBOL(atomic_add_ret);
6440 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6441 EXPORT_SYMBOL(atomic_sub);
6442 +EXPORT_SYMBOL(atomic_sub_unchecked);
6443 EXPORT_SYMBOL(atomic_sub_ret);
6444 EXPORT_SYMBOL(atomic64_add);
6445 +EXPORT_SYMBOL(atomic64_add_unchecked);
6446 EXPORT_SYMBOL(atomic64_add_ret);
6447 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6448 EXPORT_SYMBOL(atomic64_sub);
6449 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6450 EXPORT_SYMBOL(atomic64_sub_ret);
6451
6452 /* Atomic bit operations. */
6453 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6454 index 30c3ecc..736f015 100644
6455 --- a/arch/sparc/mm/Makefile
6456 +++ b/arch/sparc/mm/Makefile
6457 @@ -2,7 +2,7 @@
6458 #
6459
6460 asflags-y := -ansi
6461 -ccflags-y := -Werror
6462 +#ccflags-y := -Werror
6463
6464 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6465 obj-y += fault_$(BITS).o
6466 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6467 index f46cf6b..cc0666bae 100644
6468 --- a/arch/sparc/mm/fault_32.c
6469 +++ b/arch/sparc/mm/fault_32.c
6470 @@ -21,6 +21,9 @@
6471 #include <linux/perf_event.h>
6472 #include <linux/interrupt.h>
6473 #include <linux/kdebug.h>
6474 +#include <linux/slab.h>
6475 +#include <linux/pagemap.h>
6476 +#include <linux/compiler.h>
6477
6478 #include <asm/page.h>
6479 #include <asm/pgtable.h>
6480 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6481 return safe_compute_effective_address(regs, insn);
6482 }
6483
6484 +#ifdef CONFIG_PAX_PAGEEXEC
6485 +#ifdef CONFIG_PAX_DLRESOLVE
6486 +static void pax_emuplt_close(struct vm_area_struct *vma)
6487 +{
6488 + vma->vm_mm->call_dl_resolve = 0UL;
6489 +}
6490 +
6491 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6492 +{
6493 + unsigned int *kaddr;
6494 +
6495 + vmf->page = alloc_page(GFP_HIGHUSER);
6496 + if (!vmf->page)
6497 + return VM_FAULT_OOM;
6498 +
6499 + kaddr = kmap(vmf->page);
6500 + memset(kaddr, 0, PAGE_SIZE);
6501 + kaddr[0] = 0x9DE3BFA8U; /* save */
6502 + flush_dcache_page(vmf->page);
6503 + kunmap(vmf->page);
6504 + return VM_FAULT_MAJOR;
6505 +}
6506 +
6507 +static const struct vm_operations_struct pax_vm_ops = {
6508 + .close = pax_emuplt_close,
6509 + .fault = pax_emuplt_fault
6510 +};
6511 +
6512 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6513 +{
6514 + int ret;
6515 +
6516 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6517 + vma->vm_mm = current->mm;
6518 + vma->vm_start = addr;
6519 + vma->vm_end = addr + PAGE_SIZE;
6520 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6521 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6522 + vma->vm_ops = &pax_vm_ops;
6523 +
6524 + ret = insert_vm_struct(current->mm, vma);
6525 + if (ret)
6526 + return ret;
6527 +
6528 + ++current->mm->total_vm;
6529 + return 0;
6530 +}
6531 +#endif
6532 +
6533 +/*
6534 + * PaX: decide what to do with offenders (regs->pc = fault address)
6535 + *
6536 + * returns 1 when task should be killed
6537 + * 2 when patched PLT trampoline was detected
6538 + * 3 when unpatched PLT trampoline was detected
6539 + */
6540 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6541 +{
6542 +
6543 +#ifdef CONFIG_PAX_EMUPLT
6544 + int err;
6545 +
6546 + do { /* PaX: patched PLT emulation #1 */
6547 + unsigned int sethi1, sethi2, jmpl;
6548 +
6549 + err = get_user(sethi1, (unsigned int *)regs->pc);
6550 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6551 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6552 +
6553 + if (err)
6554 + break;
6555 +
6556 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6557 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6558 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6559 + {
6560 + unsigned int addr;
6561 +
6562 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6563 + addr = regs->u_regs[UREG_G1];
6564 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6565 + regs->pc = addr;
6566 + regs->npc = addr+4;
6567 + return 2;
6568 + }
6569 + } while (0);
6570 +
6571 + do { /* PaX: patched PLT emulation #2 */
6572 + unsigned int ba;
6573 +
6574 + err = get_user(ba, (unsigned int *)regs->pc);
6575 +
6576 + if (err)
6577 + break;
6578 +
6579 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6580 + unsigned int addr;
6581 +
6582 + if ((ba & 0xFFC00000U) == 0x30800000U)
6583 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6584 + else
6585 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6586 + regs->pc = addr;
6587 + regs->npc = addr+4;
6588 + return 2;
6589 + }
6590 + } while (0);
6591 +
6592 + do { /* PaX: patched PLT emulation #3 */
6593 + unsigned int sethi, bajmpl, nop;
6594 +
6595 + err = get_user(sethi, (unsigned int *)regs->pc);
6596 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6597 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6598 +
6599 + if (err)
6600 + break;
6601 +
6602 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6603 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6604 + nop == 0x01000000U)
6605 + {
6606 + unsigned int addr;
6607 +
6608 + addr = (sethi & 0x003FFFFFU) << 10;
6609 + regs->u_regs[UREG_G1] = addr;
6610 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6611 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6612 + else
6613 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6614 + regs->pc = addr;
6615 + regs->npc = addr+4;
6616 + return 2;
6617 + }
6618 + } while (0);
6619 +
6620 + do { /* PaX: unpatched PLT emulation step 1 */
6621 + unsigned int sethi, ba, nop;
6622 +
6623 + err = get_user(sethi, (unsigned int *)regs->pc);
6624 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6625 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6626 +
6627 + if (err)
6628 + break;
6629 +
6630 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6631 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6632 + nop == 0x01000000U)
6633 + {
6634 + unsigned int addr, save, call;
6635 +
6636 + if ((ba & 0xFFC00000U) == 0x30800000U)
6637 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6638 + else
6639 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6640 +
6641 + err = get_user(save, (unsigned int *)addr);
6642 + err |= get_user(call, (unsigned int *)(addr+4));
6643 + err |= get_user(nop, (unsigned int *)(addr+8));
6644 + if (err)
6645 + break;
6646 +
6647 +#ifdef CONFIG_PAX_DLRESOLVE
6648 + if (save == 0x9DE3BFA8U &&
6649 + (call & 0xC0000000U) == 0x40000000U &&
6650 + nop == 0x01000000U)
6651 + {
6652 + struct vm_area_struct *vma;
6653 + unsigned long call_dl_resolve;
6654 +
6655 + down_read(&current->mm->mmap_sem);
6656 + call_dl_resolve = current->mm->call_dl_resolve;
6657 + up_read(&current->mm->mmap_sem);
6658 + if (likely(call_dl_resolve))
6659 + goto emulate;
6660 +
6661 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6662 +
6663 + down_write(&current->mm->mmap_sem);
6664 + if (current->mm->call_dl_resolve) {
6665 + call_dl_resolve = current->mm->call_dl_resolve;
6666 + up_write(&current->mm->mmap_sem);
6667 + if (vma)
6668 + kmem_cache_free(vm_area_cachep, vma);
6669 + goto emulate;
6670 + }
6671 +
6672 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6673 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6674 + up_write(&current->mm->mmap_sem);
6675 + if (vma)
6676 + kmem_cache_free(vm_area_cachep, vma);
6677 + return 1;
6678 + }
6679 +
6680 + if (pax_insert_vma(vma, call_dl_resolve)) {
6681 + up_write(&current->mm->mmap_sem);
6682 + kmem_cache_free(vm_area_cachep, vma);
6683 + return 1;
6684 + }
6685 +
6686 + current->mm->call_dl_resolve = call_dl_resolve;
6687 + up_write(&current->mm->mmap_sem);
6688 +
6689 +emulate:
6690 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6691 + regs->pc = call_dl_resolve;
6692 + regs->npc = addr+4;
6693 + return 3;
6694 + }
6695 +#endif
6696 +
6697 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6698 + if ((save & 0xFFC00000U) == 0x05000000U &&
6699 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6700 + nop == 0x01000000U)
6701 + {
6702 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6703 + regs->u_regs[UREG_G2] = addr + 4;
6704 + addr = (save & 0x003FFFFFU) << 10;
6705 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6706 + regs->pc = addr;
6707 + regs->npc = addr+4;
6708 + return 3;
6709 + }
6710 + }
6711 + } while (0);
6712 +
6713 + do { /* PaX: unpatched PLT emulation step 2 */
6714 + unsigned int save, call, nop;
6715 +
6716 + err = get_user(save, (unsigned int *)(regs->pc-4));
6717 + err |= get_user(call, (unsigned int *)regs->pc);
6718 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6719 + if (err)
6720 + break;
6721 +
6722 + if (save == 0x9DE3BFA8U &&
6723 + (call & 0xC0000000U) == 0x40000000U &&
6724 + nop == 0x01000000U)
6725 + {
6726 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6727 +
6728 + regs->u_regs[UREG_RETPC] = regs->pc;
6729 + regs->pc = dl_resolve;
6730 + regs->npc = dl_resolve+4;
6731 + return 3;
6732 + }
6733 + } while (0);
6734 +#endif
6735 +
6736 + return 1;
6737 +}
6738 +
6739 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6740 +{
6741 + unsigned long i;
6742 +
6743 + printk(KERN_ERR "PAX: bytes at PC: ");
6744 + for (i = 0; i < 8; i++) {
6745 + unsigned int c;
6746 + if (get_user(c, (unsigned int *)pc+i))
6747 + printk(KERN_CONT "???????? ");
6748 + else
6749 + printk(KERN_CONT "%08x ", c);
6750 + }
6751 + printk("\n");
6752 +}
6753 +#endif
6754 +
6755 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6756 int text_fault)
6757 {
6758 @@ -248,6 +522,24 @@ good_area:
6759 if (!(vma->vm_flags & VM_WRITE))
6760 goto bad_area;
6761 } else {
6762 +
6763 +#ifdef CONFIG_PAX_PAGEEXEC
6764 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6765 + up_read(&mm->mmap_sem);
6766 + switch (pax_handle_fetch_fault(regs)) {
6767 +
6768 +#ifdef CONFIG_PAX_EMUPLT
6769 + case 2:
6770 + case 3:
6771 + return;
6772 +#endif
6773 +
6774 + }
6775 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6776 + do_group_exit(SIGKILL);
6777 + }
6778 +#endif
6779 +
6780 /* Allow reads even for write-only mappings */
6781 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6782 goto bad_area;
6783 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6784 index 1fe0429..8dd5dd5 100644
6785 --- a/arch/sparc/mm/fault_64.c
6786 +++ b/arch/sparc/mm/fault_64.c
6787 @@ -21,6 +21,9 @@
6788 #include <linux/kprobes.h>
6789 #include <linux/kdebug.h>
6790 #include <linux/percpu.h>
6791 +#include <linux/slab.h>
6792 +#include <linux/pagemap.h>
6793 +#include <linux/compiler.h>
6794
6795 #include <asm/page.h>
6796 #include <asm/pgtable.h>
6797 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6798 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6799 regs->tpc);
6800 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6801 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6802 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6803 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6804 dump_stack();
6805 unhandled_fault(regs->tpc, current, regs);
6806 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6807 show_regs(regs);
6808 }
6809
6810 +#ifdef CONFIG_PAX_PAGEEXEC
6811 +#ifdef CONFIG_PAX_DLRESOLVE
6812 +static void pax_emuplt_close(struct vm_area_struct *vma)
6813 +{
6814 + vma->vm_mm->call_dl_resolve = 0UL;
6815 +}
6816 +
6817 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6818 +{
6819 + unsigned int *kaddr;
6820 +
6821 + vmf->page = alloc_page(GFP_HIGHUSER);
6822 + if (!vmf->page)
6823 + return VM_FAULT_OOM;
6824 +
6825 + kaddr = kmap(vmf->page);
6826 + memset(kaddr, 0, PAGE_SIZE);
6827 + kaddr[0] = 0x9DE3BFA8U; /* save */
6828 + flush_dcache_page(vmf->page);
6829 + kunmap(vmf->page);
6830 + return VM_FAULT_MAJOR;
6831 +}
6832 +
6833 +static const struct vm_operations_struct pax_vm_ops = {
6834 + .close = pax_emuplt_close,
6835 + .fault = pax_emuplt_fault
6836 +};
6837 +
6838 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6839 +{
6840 + int ret;
6841 +
6842 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6843 + vma->vm_mm = current->mm;
6844 + vma->vm_start = addr;
6845 + vma->vm_end = addr + PAGE_SIZE;
6846 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6847 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6848 + vma->vm_ops = &pax_vm_ops;
6849 +
6850 + ret = insert_vm_struct(current->mm, vma);
6851 + if (ret)
6852 + return ret;
6853 +
6854 + ++current->mm->total_vm;
6855 + return 0;
6856 +}
6857 +#endif
6858 +
6859 +/*
6860 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6861 + *
6862 + * returns 1 when task should be killed
6863 + * 2 when patched PLT trampoline was detected
6864 + * 3 when unpatched PLT trampoline was detected
6865 + */
6866 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6867 +{
6868 +
6869 +#ifdef CONFIG_PAX_EMUPLT
6870 + int err;
6871 +
6872 + do { /* PaX: patched PLT emulation #1 */
6873 + unsigned int sethi1, sethi2, jmpl;
6874 +
6875 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6876 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6877 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6878 +
6879 + if (err)
6880 + break;
6881 +
6882 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6883 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6884 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6885 + {
6886 + unsigned long addr;
6887 +
6888 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6889 + addr = regs->u_regs[UREG_G1];
6890 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6891 +
6892 + if (test_thread_flag(TIF_32BIT))
6893 + addr &= 0xFFFFFFFFUL;
6894 +
6895 + regs->tpc = addr;
6896 + regs->tnpc = addr+4;
6897 + return 2;
6898 + }
6899 + } while (0);
6900 +
6901 + do { /* PaX: patched PLT emulation #2 */
6902 + unsigned int ba;
6903 +
6904 + err = get_user(ba, (unsigned int *)regs->tpc);
6905 +
6906 + if (err)
6907 + break;
6908 +
6909 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6910 + unsigned long addr;
6911 +
6912 + if ((ba & 0xFFC00000U) == 0x30800000U)
6913 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6914 + else
6915 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6916 +
6917 + if (test_thread_flag(TIF_32BIT))
6918 + addr &= 0xFFFFFFFFUL;
6919 +
6920 + regs->tpc = addr;
6921 + regs->tnpc = addr+4;
6922 + return 2;
6923 + }
6924 + } while (0);
6925 +
6926 + do { /* PaX: patched PLT emulation #3 */
6927 + unsigned int sethi, bajmpl, nop;
6928 +
6929 + err = get_user(sethi, (unsigned int *)regs->tpc);
6930 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6931 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6932 +
6933 + if (err)
6934 + break;
6935 +
6936 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6937 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6938 + nop == 0x01000000U)
6939 + {
6940 + unsigned long addr;
6941 +
6942 + addr = (sethi & 0x003FFFFFU) << 10;
6943 + regs->u_regs[UREG_G1] = addr;
6944 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6945 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6946 + else
6947 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6948 +
6949 + if (test_thread_flag(TIF_32BIT))
6950 + addr &= 0xFFFFFFFFUL;
6951 +
6952 + regs->tpc = addr;
6953 + regs->tnpc = addr+4;
6954 + return 2;
6955 + }
6956 + } while (0);
6957 +
6958 + do { /* PaX: patched PLT emulation #4 */
6959 + unsigned int sethi, mov1, call, mov2;
6960 +
6961 + err = get_user(sethi, (unsigned int *)regs->tpc);
6962 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6963 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6964 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6965 +
6966 + if (err)
6967 + break;
6968 +
6969 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6970 + mov1 == 0x8210000FU &&
6971 + (call & 0xC0000000U) == 0x40000000U &&
6972 + mov2 == 0x9E100001U)
6973 + {
6974 + unsigned long addr;
6975 +
6976 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6977 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6978 +
6979 + if (test_thread_flag(TIF_32BIT))
6980 + addr &= 0xFFFFFFFFUL;
6981 +
6982 + regs->tpc = addr;
6983 + regs->tnpc = addr+4;
6984 + return 2;
6985 + }
6986 + } while (0);
6987 +
6988 + do { /* PaX: patched PLT emulation #5 */
6989 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6990 +
6991 + err = get_user(sethi, (unsigned int *)regs->tpc);
6992 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6993 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6994 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6995 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6996 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6997 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6998 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6999 +
7000 + if (err)
7001 + break;
7002 +
7003 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7005 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7006 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7007 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7008 + sllx == 0x83287020U &&
7009 + jmpl == 0x81C04005U &&
7010 + nop == 0x01000000U)
7011 + {
7012 + unsigned long addr;
7013 +
7014 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7015 + regs->u_regs[UREG_G1] <<= 32;
7016 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7017 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7018 + regs->tpc = addr;
7019 + regs->tnpc = addr+4;
7020 + return 2;
7021 + }
7022 + } while (0);
7023 +
7024 + do { /* PaX: patched PLT emulation #6 */
7025 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7026 +
7027 + err = get_user(sethi, (unsigned int *)regs->tpc);
7028 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7029 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7030 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7031 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7032 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7033 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7034 +
7035 + if (err)
7036 + break;
7037 +
7038 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7039 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7040 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7041 + sllx == 0x83287020U &&
7042 + (or & 0xFFFFE000U) == 0x8A116000U &&
7043 + jmpl == 0x81C04005U &&
7044 + nop == 0x01000000U)
7045 + {
7046 + unsigned long addr;
7047 +
7048 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7049 + regs->u_regs[UREG_G1] <<= 32;
7050 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7051 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052 + regs->tpc = addr;
7053 + regs->tnpc = addr+4;
7054 + return 2;
7055 + }
7056 + } while (0);
7057 +
7058 + do { /* PaX: unpatched PLT emulation step 1 */
7059 + unsigned int sethi, ba, nop;
7060 +
7061 + err = get_user(sethi, (unsigned int *)regs->tpc);
7062 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7063 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7064 +
7065 + if (err)
7066 + break;
7067 +
7068 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7069 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7070 + nop == 0x01000000U)
7071 + {
7072 + unsigned long addr;
7073 + unsigned int save, call;
7074 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7075 +
7076 + if ((ba & 0xFFC00000U) == 0x30800000U)
7077 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7078 + else
7079 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7080 +
7081 + if (test_thread_flag(TIF_32BIT))
7082 + addr &= 0xFFFFFFFFUL;
7083 +
7084 + err = get_user(save, (unsigned int *)addr);
7085 + err |= get_user(call, (unsigned int *)(addr+4));
7086 + err |= get_user(nop, (unsigned int *)(addr+8));
7087 + if (err)
7088 + break;
7089 +
7090 +#ifdef CONFIG_PAX_DLRESOLVE
7091 + if (save == 0x9DE3BFA8U &&
7092 + (call & 0xC0000000U) == 0x40000000U &&
7093 + nop == 0x01000000U)
7094 + {
7095 + struct vm_area_struct *vma;
7096 + unsigned long call_dl_resolve;
7097 +
7098 + down_read(&current->mm->mmap_sem);
7099 + call_dl_resolve = current->mm->call_dl_resolve;
7100 + up_read(&current->mm->mmap_sem);
7101 + if (likely(call_dl_resolve))
7102 + goto emulate;
7103 +
7104 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7105 +
7106 + down_write(&current->mm->mmap_sem);
7107 + if (current->mm->call_dl_resolve) {
7108 + call_dl_resolve = current->mm->call_dl_resolve;
7109 + up_write(&current->mm->mmap_sem);
7110 + if (vma)
7111 + kmem_cache_free(vm_area_cachep, vma);
7112 + goto emulate;
7113 + }
7114 +
7115 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7116 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7117 + up_write(&current->mm->mmap_sem);
7118 + if (vma)
7119 + kmem_cache_free(vm_area_cachep, vma);
7120 + return 1;
7121 + }
7122 +
7123 + if (pax_insert_vma(vma, call_dl_resolve)) {
7124 + up_write(&current->mm->mmap_sem);
7125 + kmem_cache_free(vm_area_cachep, vma);
7126 + return 1;
7127 + }
7128 +
7129 + current->mm->call_dl_resolve = call_dl_resolve;
7130 + up_write(&current->mm->mmap_sem);
7131 +
7132 +emulate:
7133 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7134 + regs->tpc = call_dl_resolve;
7135 + regs->tnpc = addr+4;
7136 + return 3;
7137 + }
7138 +#endif
7139 +
7140 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7141 + if ((save & 0xFFC00000U) == 0x05000000U &&
7142 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7143 + nop == 0x01000000U)
7144 + {
7145 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7146 + regs->u_regs[UREG_G2] = addr + 4;
7147 + addr = (save & 0x003FFFFFU) << 10;
7148 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7149 +
7150 + if (test_thread_flag(TIF_32BIT))
7151 + addr &= 0xFFFFFFFFUL;
7152 +
7153 + regs->tpc = addr;
7154 + regs->tnpc = addr+4;
7155 + return 3;
7156 + }
7157 +
7158 + /* PaX: 64-bit PLT stub */
7159 + err = get_user(sethi1, (unsigned int *)addr);
7160 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7161 + err |= get_user(or1, (unsigned int *)(addr+8));
7162 + err |= get_user(or2, (unsigned int *)(addr+12));
7163 + err |= get_user(sllx, (unsigned int *)(addr+16));
7164 + err |= get_user(add, (unsigned int *)(addr+20));
7165 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7166 + err |= get_user(nop, (unsigned int *)(addr+28));
7167 + if (err)
7168 + break;
7169 +
7170 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7171 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7172 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7173 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7174 + sllx == 0x89293020U &&
7175 + add == 0x8A010005U &&
7176 + jmpl == 0x89C14000U &&
7177 + nop == 0x01000000U)
7178 + {
7179 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7181 + regs->u_regs[UREG_G4] <<= 32;
7182 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7183 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7184 + regs->u_regs[UREG_G4] = addr + 24;
7185 + addr = regs->u_regs[UREG_G5];
7186 + regs->tpc = addr;
7187 + regs->tnpc = addr+4;
7188 + return 3;
7189 + }
7190 + }
7191 + } while (0);
7192 +
7193 +#ifdef CONFIG_PAX_DLRESOLVE
7194 + do { /* PaX: unpatched PLT emulation step 2 */
7195 + unsigned int save, call, nop;
7196 +
7197 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7198 + err |= get_user(call, (unsigned int *)regs->tpc);
7199 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7200 + if (err)
7201 + break;
7202 +
7203 + if (save == 0x9DE3BFA8U &&
7204 + (call & 0xC0000000U) == 0x40000000U &&
7205 + nop == 0x01000000U)
7206 + {
7207 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7208 +
7209 + if (test_thread_flag(TIF_32BIT))
7210 + dl_resolve &= 0xFFFFFFFFUL;
7211 +
7212 + regs->u_regs[UREG_RETPC] = regs->tpc;
7213 + regs->tpc = dl_resolve;
7214 + regs->tnpc = dl_resolve+4;
7215 + return 3;
7216 + }
7217 + } while (0);
7218 +#endif
7219 +
7220 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7221 + unsigned int sethi, ba, nop;
7222 +
7223 + err = get_user(sethi, (unsigned int *)regs->tpc);
7224 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7225 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7226 +
7227 + if (err)
7228 + break;
7229 +
7230 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7231 + (ba & 0xFFF00000U) == 0x30600000U &&
7232 + nop == 0x01000000U)
7233 + {
7234 + unsigned long addr;
7235 +
7236 + addr = (sethi & 0x003FFFFFU) << 10;
7237 + regs->u_regs[UREG_G1] = addr;
7238 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7239 +
7240 + if (test_thread_flag(TIF_32BIT))
7241 + addr &= 0xFFFFFFFFUL;
7242 +
7243 + regs->tpc = addr;
7244 + regs->tnpc = addr+4;
7245 + return 2;
7246 + }
7247 + } while (0);
7248 +
7249 +#endif
7250 +
7251 + return 1;
7252 +}
7253 +
7254 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7255 +{
7256 + unsigned long i;
7257 +
7258 + printk(KERN_ERR "PAX: bytes at PC: ");
7259 + for (i = 0; i < 8; i++) {
7260 + unsigned int c;
7261 + if (get_user(c, (unsigned int *)pc+i))
7262 + printk(KERN_CONT "???????? ");
7263 + else
7264 + printk(KERN_CONT "%08x ", c);
7265 + }
7266 + printk("\n");
7267 +}
7268 +#endif
7269 +
7270 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7271 {
7272 struct mm_struct *mm = current->mm;
7273 @@ -343,6 +806,29 @@ retry:
7274 if (!vma)
7275 goto bad_area;
7276
7277 +#ifdef CONFIG_PAX_PAGEEXEC
7278 + /* PaX: detect ITLB misses on non-exec pages */
7279 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7280 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7281 + {
7282 + if (address != regs->tpc)
7283 + goto good_area;
7284 +
7285 + up_read(&mm->mmap_sem);
7286 + switch (pax_handle_fetch_fault(regs)) {
7287 +
7288 +#ifdef CONFIG_PAX_EMUPLT
7289 + case 2:
7290 + case 3:
7291 + return;
7292 +#endif
7293 +
7294 + }
7295 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7296 + do_group_exit(SIGKILL);
7297 + }
7298 +#endif
7299 +
7300 /* Pure DTLB misses do not tell us whether the fault causing
7301 * load/store/atomic was a write or not, it only says that there
7302 * was no match. So in such a case we (carefully) read the
7303 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7304 index 07e1453..0a7d9e9 100644
7305 --- a/arch/sparc/mm/hugetlbpage.c
7306 +++ b/arch/sparc/mm/hugetlbpage.c
7307 @@ -67,7 +67,7 @@ full_search:
7308 }
7309 return -ENOMEM;
7310 }
7311 - if (likely(!vma || addr + len <= vma->vm_start)) {
7312 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7313 /*
7314 * Remember the place where we stopped the search:
7315 */
7316 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7317 /* make sure it can fit in the remaining address space */
7318 if (likely(addr > len)) {
7319 vma = find_vma(mm, addr-len);
7320 - if (!vma || addr <= vma->vm_start) {
7321 + if (check_heap_stack_gap(vma, addr - len, len)) {
7322 /* remember the address as a hint for next time */
7323 return (mm->free_area_cache = addr-len);
7324 }
7325 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7326 if (unlikely(mm->mmap_base < len))
7327 goto bottomup;
7328
7329 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7330 + addr = mm->mmap_base - len;
7331
7332 do {
7333 + addr &= HPAGE_MASK;
7334 /*
7335 * Lookup failure means no vma is above this address,
7336 * else if new region fits below vma->vm_start,
7337 * return with success:
7338 */
7339 vma = find_vma(mm, addr);
7340 - if (likely(!vma || addr+len <= vma->vm_start)) {
7341 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr);
7344 }
7345 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 mm->cached_hole_size = vma->vm_start - addr;
7347
7348 /* try just below the current vma->vm_start */
7349 - addr = (vma->vm_start-len) & HPAGE_MASK;
7350 - } while (likely(len < vma->vm_start));
7351 + addr = skip_heap_stack_gap(vma, len);
7352 + } while (!IS_ERR_VALUE(addr));
7353
7354 bottomup:
7355 /*
7356 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7357 if (addr) {
7358 addr = ALIGN(addr, HPAGE_SIZE);
7359 vma = find_vma(mm, addr);
7360 - if (task_size - len >= addr &&
7361 - (!vma || addr + len <= vma->vm_start))
7362 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7363 return addr;
7364 }
7365 if (mm->get_unmapped_area == arch_get_unmapped_area)
7366 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7367 index f4500c6..889656c 100644
7368 --- a/arch/tile/include/asm/atomic_64.h
7369 +++ b/arch/tile/include/asm/atomic_64.h
7370 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7371
7372 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7373
7374 +#define atomic64_read_unchecked(v) atomic64_read(v)
7375 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7376 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7377 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7378 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7379 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7380 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7381 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7382 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7383 +
7384 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7385 #define smp_mb__before_atomic_dec() smp_mb()
7386 #define smp_mb__after_atomic_dec() smp_mb()
7387 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7388 index 392e533..536b092 100644
7389 --- a/arch/tile/include/asm/cache.h
7390 +++ b/arch/tile/include/asm/cache.h
7391 @@ -15,11 +15,12 @@
7392 #ifndef _ASM_TILE_CACHE_H
7393 #define _ASM_TILE_CACHE_H
7394
7395 +#include <linux/const.h>
7396 #include <arch/chip.h>
7397
7398 /* bytes per L1 data cache line */
7399 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7400 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7401 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7402
7403 /* bytes per L2 cache line */
7404 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7405 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7406 index 9ab078a..d6635c2 100644
7407 --- a/arch/tile/include/asm/uaccess.h
7408 +++ b/arch/tile/include/asm/uaccess.h
7409 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7410 const void __user *from,
7411 unsigned long n)
7412 {
7413 - int sz = __compiletime_object_size(to);
7414 + size_t sz = __compiletime_object_size(to);
7415
7416 - if (likely(sz == -1 || sz >= n))
7417 + if (likely(sz == (size_t)-1 || sz >= n))
7418 n = _copy_from_user(to, from, n);
7419 else
7420 copy_from_user_overflow();
7421 diff --git a/arch/um/Makefile b/arch/um/Makefile
7422 index 0970910..13adb57a 100644
7423 --- a/arch/um/Makefile
7424 +++ b/arch/um/Makefile
7425 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7428
7429 +ifdef CONSTIFY_PLUGIN
7430 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7431 +endif
7432 +
7433 #This will adjust *FLAGS accordingly to the platform.
7434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7435
7436 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7437 index 19e1bdd..3665b77 100644
7438 --- a/arch/um/include/asm/cache.h
7439 +++ b/arch/um/include/asm/cache.h
7440 @@ -1,6 +1,7 @@
7441 #ifndef __UM_CACHE_H
7442 #define __UM_CACHE_H
7443
7444 +#include <linux/const.h>
7445
7446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7448 @@ -12,6 +13,6 @@
7449 # define L1_CACHE_SHIFT 5
7450 #endif
7451
7452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7454
7455 #endif
7456 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7457 index 6c03acd..a5e0215 100644
7458 --- a/arch/um/include/asm/kmap_types.h
7459 +++ b/arch/um/include/asm/kmap_types.h
7460 @@ -23,6 +23,7 @@ enum km_type {
7461 KM_IRQ1,
7462 KM_SOFTIRQ0,
7463 KM_SOFTIRQ1,
7464 + KM_CLEARPAGE,
7465 KM_TYPE_NR
7466 };
7467
7468 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7469 index 7cfc3ce..cbd1a58 100644
7470 --- a/arch/um/include/asm/page.h
7471 +++ b/arch/um/include/asm/page.h
7472 @@ -14,6 +14,9 @@
7473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7474 #define PAGE_MASK (~(PAGE_SIZE-1))
7475
7476 +#define ktla_ktva(addr) (addr)
7477 +#define ktva_ktla(addr) (addr)
7478 +
7479 #ifndef __ASSEMBLY__
7480
7481 struct page;
7482 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7483 index 0032f92..cd151e0 100644
7484 --- a/arch/um/include/asm/pgtable-3level.h
7485 +++ b/arch/um/include/asm/pgtable-3level.h
7486 @@ -58,6 +58,7 @@
7487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7488 #define pud_populate(mm, pud, pmd) \
7489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7490 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7491
7492 #ifdef CONFIG_64BIT
7493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7494 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7495 index ccb9a9d..cc425bb 100644
7496 --- a/arch/um/kernel/process.c
7497 +++ b/arch/um/kernel/process.c
7498 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7499 return 2;
7500 }
7501
7502 -/*
7503 - * Only x86 and x86_64 have an arch_align_stack().
7504 - * All other arches have "#define arch_align_stack(x) (x)"
7505 - * in their asm/system.h
7506 - * As this is included in UML from asm-um/system-generic.h,
7507 - * we can use it to behave as the subarch does.
7508 - */
7509 -#ifndef arch_align_stack
7510 -unsigned long arch_align_stack(unsigned long sp)
7511 -{
7512 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7513 - sp -= get_random_int() % 8192;
7514 - return sp & ~0xf;
7515 -}
7516 -#endif
7517 -
7518 unsigned long get_wchan(struct task_struct *p)
7519 {
7520 unsigned long stack_page, sp, ip;
7521 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7522 index ad8f795..2c7eec6 100644
7523 --- a/arch/unicore32/include/asm/cache.h
7524 +++ b/arch/unicore32/include/asm/cache.h
7525 @@ -12,8 +12,10 @@
7526 #ifndef __UNICORE_CACHE_H__
7527 #define __UNICORE_CACHE_H__
7528
7529 -#define L1_CACHE_SHIFT (5)
7530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7531 +#include <linux/const.h>
7532 +
7533 +#define L1_CACHE_SHIFT 5
7534 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7535
7536 /*
7537 * Memory returned by kmalloc() may be used for DMA, so we must make
7538 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7539 index c70684f..698fa4b 100644
7540 --- a/arch/x86/Kconfig
7541 +++ b/arch/x86/Kconfig
7542 @@ -218,7 +218,7 @@ config X86_HT
7543
7544 config X86_32_LAZY_GS
7545 def_bool y
7546 - depends on X86_32 && !CC_STACKPROTECTOR
7547 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7548
7549 config ARCH_HWEIGHT_CFLAGS
7550 string
7551 @@ -1047,7 +1047,7 @@ choice
7552
7553 config NOHIGHMEM
7554 bool "off"
7555 - depends on !X86_NUMAQ
7556 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7557 ---help---
7558 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7559 However, the address space of 32-bit x86 processors is only 4
7560 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7561
7562 config HIGHMEM4G
7563 bool "4GB"
7564 - depends on !X86_NUMAQ
7565 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7566 ---help---
7567 Select this if you have a 32-bit processor and between 1 and 4
7568 gigabytes of physical RAM.
7569 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7570 hex
7571 default 0xB0000000 if VMSPLIT_3G_OPT
7572 default 0x80000000 if VMSPLIT_2G
7573 - default 0x78000000 if VMSPLIT_2G_OPT
7574 + default 0x70000000 if VMSPLIT_2G_OPT
7575 default 0x40000000 if VMSPLIT_1G
7576 default 0xC0000000
7577 depends on X86_32
7578 @@ -1526,6 +1526,7 @@ config SECCOMP
7579
7580 config CC_STACKPROTECTOR
7581 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7582 + depends on X86_64 || !PAX_MEMORY_UDEREF
7583 ---help---
7584 This option turns on the -fstack-protector GCC feature. This
7585 feature puts, at the beginning of functions, a canary value on
7586 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7587 config PHYSICAL_START
7588 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7589 default "0x1000000"
7590 + range 0x400000 0x40000000
7591 ---help---
7592 This gives the physical address where the kernel is loaded.
7593
7594 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7595 config PHYSICAL_ALIGN
7596 hex "Alignment value to which kernel should be aligned" if X86_32
7597 default "0x1000000"
7598 + range 0x400000 0x1000000 if PAX_KERNEXEC
7599 range 0x2000 0x1000000
7600 ---help---
7601 This value puts the alignment restrictions on physical address
7602 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7603 Say N if you want to disable CPU hotplug.
7604
7605 config COMPAT_VDSO
7606 - def_bool y
7607 + def_bool n
7608 prompt "Compat VDSO support"
7609 depends on X86_32 || IA32_EMULATION
7610 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7611 ---help---
7612 Map the 32-bit VDSO to the predictable old-style address too.
7613
7614 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7615 index 706e12e..62e4feb 100644
7616 --- a/arch/x86/Kconfig.cpu
7617 +++ b/arch/x86/Kconfig.cpu
7618 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7619
7620 config X86_F00F_BUG
7621 def_bool y
7622 - depends on M586MMX || M586TSC || M586 || M486 || M386
7623 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7624
7625 config X86_INVD_BUG
7626 def_bool y
7627 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7628
7629 config X86_ALIGNMENT_16
7630 def_bool y
7631 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7632 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7633
7634 config X86_INTEL_USERCOPY
7635 def_bool y
7636 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7637 # generates cmov.
7638 config X86_CMOV
7639 def_bool y
7640 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7641 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7642
7643 config X86_MINIMUM_CPU_FAMILY
7644 int
7645 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7646 index e46c214..ab62fd1 100644
7647 --- a/arch/x86/Kconfig.debug
7648 +++ b/arch/x86/Kconfig.debug
7649 @@ -84,7 +84,7 @@ config X86_PTDUMP
7650 config DEBUG_RODATA
7651 bool "Write protect kernel read-only data structures"
7652 default y
7653 - depends on DEBUG_KERNEL
7654 + depends on DEBUG_KERNEL && BROKEN
7655 ---help---
7656 Mark the kernel read-only data as write-protected in the pagetables,
7657 in order to catch accidental (and incorrect) writes to such const
7658 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7659
7660 config DEBUG_SET_MODULE_RONX
7661 bool "Set loadable kernel module data as NX and text as RO"
7662 - depends on MODULES
7663 + depends on MODULES && BROKEN
7664 ---help---
7665 This option helps catch unintended modifications to loadable
7666 kernel module's text and read-only data. It also prevents execution
7667 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7668
7669 config DEBUG_STRICT_USER_COPY_CHECKS
7670 bool "Strict copy size checks"
7671 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7672 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7673 ---help---
7674 Enabling this option turns a certain set of sanity checks for user
7675 copy operations into compile time failures.
7676 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7677 index 1f25214..39422b3 100644
7678 --- a/arch/x86/Makefile
7679 +++ b/arch/x86/Makefile
7680 @@ -46,6 +46,7 @@ else
7681 UTS_MACHINE := x86_64
7682 CHECKFLAGS += -D__x86_64__ -m64
7683
7684 + biarch := $(call cc-option,-m64)
7685 KBUILD_AFLAGS += -m64
7686 KBUILD_CFLAGS += -m64
7687
7688 @@ -222,3 +223,12 @@ define archhelp
7689 echo ' FDARGS="..." arguments for the booted kernel'
7690 echo ' FDINITRD=file initrd for the booted kernel'
7691 endef
7692 +
7693 +define OLD_LD
7694 +
7695 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7696 +*** Please upgrade your binutils to 2.18 or newer
7697 +endef
7698 +
7699 +archprepare:
7700 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7701 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7702 index 5a747dd..ff7b12c 100644
7703 --- a/arch/x86/boot/Makefile
7704 +++ b/arch/x86/boot/Makefile
7705 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7706 $(call cc-option, -fno-stack-protector) \
7707 $(call cc-option, -mpreferred-stack-boundary=2)
7708 KBUILD_CFLAGS += $(call cc-option, -m32)
7709 +ifdef CONSTIFY_PLUGIN
7710 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7711 +endif
7712 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7713 GCOV_PROFILE := n
7714
7715 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7716 index 878e4b9..20537ab 100644
7717 --- a/arch/x86/boot/bitops.h
7718 +++ b/arch/x86/boot/bitops.h
7719 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7720 u8 v;
7721 const u32 *p = (const u32 *)addr;
7722
7723 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7724 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7725 return v;
7726 }
7727
7728 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7729
7730 static inline void set_bit(int nr, void *addr)
7731 {
7732 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7733 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7734 }
7735
7736 #endif /* BOOT_BITOPS_H */
7737 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7738 index 18997e5..83d9c67 100644
7739 --- a/arch/x86/boot/boot.h
7740 +++ b/arch/x86/boot/boot.h
7741 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7742 static inline u16 ds(void)
7743 {
7744 u16 seg;
7745 - asm("movw %%ds,%0" : "=rm" (seg));
7746 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7747 return seg;
7748 }
7749
7750 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7751 static inline int memcmp(const void *s1, const void *s2, size_t len)
7752 {
7753 u8 diff;
7754 - asm("repe; cmpsb; setnz %0"
7755 + asm volatile("repe; cmpsb; setnz %0"
7756 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7757 return diff;
7758 }
7759 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7760 index e398bb5..3a382ca 100644
7761 --- a/arch/x86/boot/compressed/Makefile
7762 +++ b/arch/x86/boot/compressed/Makefile
7763 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7764 KBUILD_CFLAGS += $(cflags-y)
7765 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7766 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7767 +ifdef CONSTIFY_PLUGIN
7768 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7769 +endif
7770
7771 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7772 GCOV_PROFILE := n
7773 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7774 index 4e85f5f..39fa641 100644
7775 --- a/arch/x86/boot/compressed/eboot.c
7776 +++ b/arch/x86/boot/compressed/eboot.c
7777 @@ -142,7 +142,6 @@ again:
7778 *addr = max_addr;
7779 }
7780
7781 -free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783
7784 fail:
7785 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7786 if (i == map_size / desc_size)
7787 status = EFI_NOT_FOUND;
7788
7789 -free_pool:
7790 efi_call_phys1(sys_table->boottime->free_pool, map);
7791 fail:
7792 return status;
7793 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7794 index c85e3ac..6f5aa80 100644
7795 --- a/arch/x86/boot/compressed/head_32.S
7796 +++ b/arch/x86/boot/compressed/head_32.S
7797 @@ -106,7 +106,7 @@ preferred_addr:
7798 notl %eax
7799 andl %eax, %ebx
7800 #else
7801 - movl $LOAD_PHYSICAL_ADDR, %ebx
7802 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7803 #endif
7804
7805 /* Target address to relocate to for decompression */
7806 @@ -192,7 +192,7 @@ relocated:
7807 * and where it was actually loaded.
7808 */
7809 movl %ebp, %ebx
7810 - subl $LOAD_PHYSICAL_ADDR, %ebx
7811 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7812 jz 2f /* Nothing to be done if loaded at compiled addr. */
7813 /*
7814 * Process relocations.
7815 @@ -200,8 +200,7 @@ relocated:
7816
7817 1: subl $4, %edi
7818 movl (%edi), %ecx
7819 - testl %ecx, %ecx
7820 - jz 2f
7821 + jecxz 2f
7822 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7823 jmp 1b
7824 2:
7825 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7826 index 87e03a1..0d94c76 100644
7827 --- a/arch/x86/boot/compressed/head_64.S
7828 +++ b/arch/x86/boot/compressed/head_64.S
7829 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7830 notl %eax
7831 andl %eax, %ebx
7832 #else
7833 - movl $LOAD_PHYSICAL_ADDR, %ebx
7834 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7835 #endif
7836
7837 /* Target address to relocate to for decompression */
7838 @@ -263,7 +263,7 @@ preferred_addr:
7839 notq %rax
7840 andq %rax, %rbp
7841 #else
7842 - movq $LOAD_PHYSICAL_ADDR, %rbp
7843 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7844 #endif
7845
7846 /* Target address to relocate to for decompression */
7847 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7848 index 7116dcb..d9ae1d7 100644
7849 --- a/arch/x86/boot/compressed/misc.c
7850 +++ b/arch/x86/boot/compressed/misc.c
7851 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7852 case PT_LOAD:
7853 #ifdef CONFIG_RELOCATABLE
7854 dest = output;
7855 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7856 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7857 #else
7858 dest = (void *)(phdr->p_paddr);
7859 #endif
7860 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7861 error("Destination address too large");
7862 #endif
7863 #ifndef CONFIG_RELOCATABLE
7864 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7865 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7866 error("Wrong destination address");
7867 #endif
7868
7869 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7870 index 4d3ff03..e4972ff 100644
7871 --- a/arch/x86/boot/cpucheck.c
7872 +++ b/arch/x86/boot/cpucheck.c
7873 @@ -74,7 +74,7 @@ static int has_fpu(void)
7874 u16 fcw = -1, fsw = -1;
7875 u32 cr0;
7876
7877 - asm("movl %%cr0,%0" : "=r" (cr0));
7878 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7879 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7880 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7881 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7882 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7883 {
7884 u32 f0, f1;
7885
7886 - asm("pushfl ; "
7887 + asm volatile("pushfl ; "
7888 "pushfl ; "
7889 "popl %0 ; "
7890 "movl %0,%1 ; "
7891 @@ -115,7 +115,7 @@ static void get_flags(void)
7892 set_bit(X86_FEATURE_FPU, cpu.flags);
7893
7894 if (has_eflag(X86_EFLAGS_ID)) {
7895 - asm("cpuid"
7896 + asm volatile("cpuid"
7897 : "=a" (max_intel_level),
7898 "=b" (cpu_vendor[0]),
7899 "=d" (cpu_vendor[1]),
7900 @@ -124,7 +124,7 @@ static void get_flags(void)
7901
7902 if (max_intel_level >= 0x00000001 &&
7903 max_intel_level <= 0x0000ffff) {
7904 - asm("cpuid"
7905 + asm volatile("cpuid"
7906 : "=a" (tfms),
7907 "=c" (cpu.flags[4]),
7908 "=d" (cpu.flags[0])
7909 @@ -136,7 +136,7 @@ static void get_flags(void)
7910 cpu.model += ((tfms >> 16) & 0xf) << 4;
7911 }
7912
7913 - asm("cpuid"
7914 + asm volatile("cpuid"
7915 : "=a" (max_amd_level)
7916 : "a" (0x80000000)
7917 : "ebx", "ecx", "edx");
7918 @@ -144,7 +144,7 @@ static void get_flags(void)
7919 if (max_amd_level >= 0x80000001 &&
7920 max_amd_level <= 0x8000ffff) {
7921 u32 eax = 0x80000001;
7922 - asm("cpuid"
7923 + asm volatile("cpuid"
7924 : "+a" (eax),
7925 "=c" (cpu.flags[6]),
7926 "=d" (cpu.flags[1])
7927 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7928 u32 ecx = MSR_K7_HWCR;
7929 u32 eax, edx;
7930
7931 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7932 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7933 eax &= ~(1 << 15);
7934 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7935 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7936
7937 get_flags(); /* Make sure it really did something */
7938 err = check_flags();
7939 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7940 u32 ecx = MSR_VIA_FCR;
7941 u32 eax, edx;
7942
7943 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7944 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7945 eax |= (1<<1)|(1<<7);
7946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 set_bit(X86_FEATURE_CX8, cpu.flags);
7950 err = check_flags();
7951 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7952 u32 eax, edx;
7953 u32 level = 1;
7954
7955 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7956 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7957 - asm("cpuid"
7958 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7959 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7960 + asm volatile("cpuid"
7961 : "+a" (level), "=d" (cpu.flags[0])
7962 : : "ecx", "ebx");
7963 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7964 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7965
7966 err = check_flags();
7967 }
7968 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7969 index efe5acf..22a3784 100644
7970 --- a/arch/x86/boot/header.S
7971 +++ b/arch/x86/boot/header.S
7972 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7973 # single linked list of
7974 # struct setup_data
7975
7976 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7977 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7978
7979 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7980 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7981 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7982 +#else
7983 #define VO_INIT_SIZE (VO__end - VO__text)
7984 +#endif
7985 #if ZO_INIT_SIZE > VO_INIT_SIZE
7986 #define INIT_SIZE ZO_INIT_SIZE
7987 #else
7988 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7989 index db75d07..8e6d0af 100644
7990 --- a/arch/x86/boot/memory.c
7991 +++ b/arch/x86/boot/memory.c
7992 @@ -19,7 +19,7 @@
7993
7994 static int detect_memory_e820(void)
7995 {
7996 - int count = 0;
7997 + unsigned int count = 0;
7998 struct biosregs ireg, oreg;
7999 struct e820entry *desc = boot_params.e820_map;
8000 static struct e820entry buf; /* static so it is zeroed */
8001 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8002 index 11e8c6e..fdbb1ed 100644
8003 --- a/arch/x86/boot/video-vesa.c
8004 +++ b/arch/x86/boot/video-vesa.c
8005 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8006
8007 boot_params.screen_info.vesapm_seg = oreg.es;
8008 boot_params.screen_info.vesapm_off = oreg.di;
8009 + boot_params.screen_info.vesapm_size = oreg.cx;
8010 }
8011
8012 /*
8013 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8014 index 43eda28..5ab5fdb 100644
8015 --- a/arch/x86/boot/video.c
8016 +++ b/arch/x86/boot/video.c
8017 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8018 static unsigned int get_entry(void)
8019 {
8020 char entry_buf[4];
8021 - int i, len = 0;
8022 + unsigned int i, len = 0;
8023 int key;
8024 unsigned int v;
8025
8026 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8027 index 5b577d5..3c1fed4 100644
8028 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8029 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8030 @@ -8,6 +8,8 @@
8031 * including this sentence is retained in full.
8032 */
8033
8034 +#include <asm/alternative-asm.h>
8035 +
8036 .extern crypto_ft_tab
8037 .extern crypto_it_tab
8038 .extern crypto_fl_tab
8039 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8040 je B192; \
8041 leaq 32(r9),r9;
8042
8043 +#define ret pax_force_retaddr 0, 1; ret
8044 +
8045 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8046 movq r1,r2; \
8047 movq r3,r4; \
8048 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8049 index 3470624..201259d 100644
8050 --- a/arch/x86/crypto/aesni-intel_asm.S
8051 +++ b/arch/x86/crypto/aesni-intel_asm.S
8052 @@ -31,6 +31,7 @@
8053
8054 #include <linux/linkage.h>
8055 #include <asm/inst.h>
8056 +#include <asm/alternative-asm.h>
8057
8058 #ifdef __x86_64__
8059 .data
8060 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8061 pop %r14
8062 pop %r13
8063 pop %r12
8064 + pax_force_retaddr 0, 1
8065 ret
8066 +ENDPROC(aesni_gcm_dec)
8067
8068
8069 /*****************************************************************************
8070 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8071 pop %r14
8072 pop %r13
8073 pop %r12
8074 + pax_force_retaddr 0, 1
8075 ret
8076 +ENDPROC(aesni_gcm_enc)
8077
8078 #endif
8079
8080 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8081 pxor %xmm1, %xmm0
8082 movaps %xmm0, (TKEYP)
8083 add $0x10, TKEYP
8084 + pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8089 shufps $0b01001110, %xmm2, %xmm1
8090 movaps %xmm1, 0x10(TKEYP)
8091 add $0x20, TKEYP
8092 + pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8097
8098 movaps %xmm0, (TKEYP)
8099 add $0x10, TKEYP
8100 + pax_force_retaddr_bts
8101 ret
8102
8103 .align 4
8104 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8105 pxor %xmm1, %xmm2
8106 movaps %xmm2, (TKEYP)
8107 add $0x10, TKEYP
8108 + pax_force_retaddr_bts
8109 ret
8110
8111 /*
8112 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8113 #ifndef __x86_64__
8114 popl KEYP
8115 #endif
8116 + pax_force_retaddr 0, 1
8117 ret
8118 +ENDPROC(aesni_set_key)
8119
8120 /*
8121 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8122 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8123 popl KLEN
8124 popl KEYP
8125 #endif
8126 + pax_force_retaddr 0, 1
8127 ret
8128 +ENDPROC(aesni_enc)
8129
8130 /*
8131 * _aesni_enc1: internal ABI
8132 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8133 AESENC KEY STATE
8134 movaps 0x70(TKEYP), KEY
8135 AESENCLAST KEY STATE
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8141 AESENCLAST KEY STATE2
8142 AESENCLAST KEY STATE3
8143 AESENCLAST KEY STATE4
8144 + pax_force_retaddr_bts
8145 ret
8146
8147 /*
8148 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8149 popl KLEN
8150 popl KEYP
8151 #endif
8152 + pax_force_retaddr 0, 1
8153 ret
8154 +ENDPROC(aesni_dec)
8155
8156 /*
8157 * _aesni_dec1: internal ABI
8158 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8159 AESDEC KEY STATE
8160 movaps 0x70(TKEYP), KEY
8161 AESDECLAST KEY STATE
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8167 AESDECLAST KEY STATE2
8168 AESDECLAST KEY STATE3
8169 AESDECLAST KEY STATE4
8170 + pax_force_retaddr_bts
8171 ret
8172
8173 /*
8174 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8175 popl KEYP
8176 popl LEN
8177 #endif
8178 + pax_force_retaddr 0, 1
8179 ret
8180 +ENDPROC(aesni_ecb_enc)
8181
8182 /*
8183 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8184 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8185 popl KEYP
8186 popl LEN
8187 #endif
8188 + pax_force_retaddr 0, 1
8189 ret
8190 +ENDPROC(aesni_ecb_dec)
8191
8192 /*
8193 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8194 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8195 popl LEN
8196 popl IVP
8197 #endif
8198 + pax_force_retaddr 0, 1
8199 ret
8200 +ENDPROC(aesni_cbc_enc)
8201
8202 /*
8203 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8205 popl LEN
8206 popl IVP
8207 #endif
8208 + pax_force_retaddr 0, 1
8209 ret
8210 +ENDPROC(aesni_cbc_dec)
8211
8212 #ifdef __x86_64__
8213 .align 16
8214 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8215 mov $1, TCTR_LOW
8216 MOVQ_R64_XMM TCTR_LOW INC
8217 MOVQ_R64_XMM CTR TCTR_LOW
8218 + pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222 @@ -2554,6 +2582,7 @@ _aesni_inc:
8223 .Linc_low:
8224 movaps CTR, IV
8225 PSHUFB_XMM BSWAP_MASK IV
8226 + pax_force_retaddr_bts
8227 ret
8228
8229 /*
8230 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8231 .Lctr_enc_ret:
8232 movups IV, (IVP)
8233 .Lctr_enc_just_ret:
8234 + pax_force_retaddr 0, 1
8235 ret
8236 +ENDPROC(aesni_ctr_enc)
8237 #endif
8238 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8239 index 391d245..67f35c2 100644
8240 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8241 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8242 @@ -20,6 +20,8 @@
8243 *
8244 */
8245
8246 +#include <asm/alternative-asm.h>
8247 +
8248 .file "blowfish-x86_64-asm.S"
8249 .text
8250
8251 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8252 jnz __enc_xor;
8253
8254 write_block();
8255 + pax_force_retaddr 0, 1
8256 ret;
8257 __enc_xor:
8258 xor_block();
8259 + pax_force_retaddr 0, 1
8260 ret;
8261
8262 .align 8
8263 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8264
8265 movq %r11, %rbp;
8266
8267 + pax_force_retaddr 0, 1
8268 ret;
8269
8270 /**********************************************************************
8271 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8272
8273 popq %rbx;
8274 popq %rbp;
8275 + pax_force_retaddr 0, 1
8276 ret;
8277
8278 __enc_xor4:
8279 @@ -349,6 +355,7 @@ __enc_xor4:
8280
8281 popq %rbx;
8282 popq %rbp;
8283 + pax_force_retaddr 0, 1
8284 ret;
8285
8286 .align 8
8287 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8288 popq %rbx;
8289 popq %rbp;
8290
8291 + pax_force_retaddr 0, 1
8292 ret;
8293
8294 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8295 index 0b33743..7a56206 100644
8296 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8297 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8298 @@ -20,6 +20,8 @@
8299 *
8300 */
8301
8302 +#include <asm/alternative-asm.h>
8303 +
8304 .file "camellia-x86_64-asm_64.S"
8305 .text
8306
8307 @@ -229,12 +231,14 @@ __enc_done:
8308 enc_outunpack(mov, RT1);
8309
8310 movq RRBP, %rbp;
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 __enc_xor:
8315 enc_outunpack(xor, RT1);
8316
8317 movq RRBP, %rbp;
8318 + pax_force_retaddr 0, 1
8319 ret;
8320
8321 .global camellia_dec_blk;
8322 @@ -275,6 +279,7 @@ __dec_rounds16:
8323 dec_outunpack();
8324
8325 movq RRBP, %rbp;
8326 + pax_force_retaddr 0, 1
8327 ret;
8328
8329 /**********************************************************************
8330 @@ -468,6 +473,7 @@ __enc2_done:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334 + pax_force_retaddr 0, 1
8335 ret;
8336
8337 __enc2_xor:
8338 @@ -475,6 +481,7 @@ __enc2_xor:
8339
8340 movq RRBP, %rbp;
8341 popq %rbx;
8342 + pax_force_retaddr 0, 1
8343 ret;
8344
8345 .global camellia_dec_blk_2way;
8346 @@ -517,4 +524,5 @@ __dec2_rounds16:
8347
8348 movq RRBP, %rbp;
8349 movq RXOR, %rbx;
8350 + pax_force_retaddr 0, 1
8351 ret;
8352 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8353 index 6214a9b..1f4fc9a 100644
8354 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8355 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8356 @@ -1,3 +1,5 @@
8357 +#include <asm/alternative-asm.h>
8358 +
8359 # enter ECRYPT_encrypt_bytes
8360 .text
8361 .p2align 5
8362 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366 + pax_force_retaddr 0, 1
8367 ret
8368 # bytesatleast65:
8369 ._bytesatleast65:
8370 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374 + pax_force_retaddr
8375 ret
8376 # enter ECRYPT_ivsetup
8377 .text
8378 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8379 add %r11,%rsp
8380 mov %rdi,%rax
8381 mov %rsi,%rdx
8382 + pax_force_retaddr
8383 ret
8384 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8385 index 3ee1ff0..cbc568b 100644
8386 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8387 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8388 @@ -24,6 +24,8 @@
8389 *
8390 */
8391
8392 +#include <asm/alternative-asm.h>
8393 +
8394 .file "serpent-sse2-x86_64-asm_64.S"
8395 .text
8396
8397 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8398 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8399 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8400
8401 + pax_force_retaddr
8402 ret;
8403
8404 __enc_xor8:
8405 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8406 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8407
8408 + pax_force_retaddr
8409 ret;
8410
8411 .align 8
8412 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8413 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8414 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8415
8416 + pax_force_retaddr
8417 ret;
8418 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8419 index b2c2f57..8470cab 100644
8420 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8421 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8422 @@ -28,6 +28,8 @@
8423 * (at your option) any later version.
8424 */
8425
8426 +#include <asm/alternative-asm.h>
8427 +
8428 #define CTX %rdi // arg1
8429 #define BUF %rsi // arg2
8430 #define CNT %rdx // arg3
8431 @@ -104,6 +106,7 @@
8432 pop %r12
8433 pop %rbp
8434 pop %rbx
8435 + pax_force_retaddr 0, 1
8436 ret
8437
8438 .size \name, .-\name
8439 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8440 index 5b012a2..36d5364 100644
8441 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8442 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8443 @@ -20,6 +20,8 @@
8444 *
8445 */
8446
8447 +#include <asm/alternative-asm.h>
8448 +
8449 .file "twofish-x86_64-asm-3way.S"
8450 .text
8451
8452 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8453 popq %r13;
8454 popq %r14;
8455 popq %r15;
8456 + pax_force_retaddr 0, 1
8457 ret;
8458
8459 __enc_xor3:
8460 @@ -271,6 +274,7 @@ __enc_xor3:
8461 popq %r13;
8462 popq %r14;
8463 popq %r15;
8464 + pax_force_retaddr 0, 1
8465 ret;
8466
8467 .global twofish_dec_blk_3way
8468 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8469 popq %r13;
8470 popq %r14;
8471 popq %r15;
8472 + pax_force_retaddr 0, 1
8473 ret;
8474
8475 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8476 index 7bcf3fc..f53832f 100644
8477 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8478 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8479 @@ -21,6 +21,7 @@
8480 .text
8481
8482 #include <asm/asm-offsets.h>
8483 +#include <asm/alternative-asm.h>
8484
8485 #define a_offset 0
8486 #define b_offset 4
8487 @@ -268,6 +269,7 @@ twofish_enc_blk:
8488
8489 popq R1
8490 movq $1,%rax
8491 + pax_force_retaddr 0, 1
8492 ret
8493
8494 twofish_dec_blk:
8495 @@ -319,4 +321,5 @@ twofish_dec_blk:
8496
8497 popq R1
8498 movq $1,%rax
8499 + pax_force_retaddr 0, 1
8500 ret
8501 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8502 index 07b3a68..bd2a388 100644
8503 --- a/arch/x86/ia32/ia32_aout.c
8504 +++ b/arch/x86/ia32/ia32_aout.c
8505 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8506 unsigned long dump_start, dump_size;
8507 struct user32 dump;
8508
8509 + memset(&dump, 0, sizeof(dump));
8510 +
8511 fs = get_fs();
8512 set_fs(KERNEL_DS);
8513 has_dumped = 1;
8514 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8515 index 673ac9b..7a8c5df 100644
8516 --- a/arch/x86/ia32/ia32_signal.c
8517 +++ b/arch/x86/ia32/ia32_signal.c
8518 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8519 }
8520 seg = get_fs();
8521 set_fs(KERNEL_DS);
8522 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8523 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8524 set_fs(seg);
8525 if (ret >= 0 && uoss_ptr) {
8526 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8527 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8528 */
8529 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8530 size_t frame_size,
8531 - void **fpstate)
8532 + void __user **fpstate)
8533 {
8534 unsigned long sp;
8535
8536 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8537
8538 if (used_math()) {
8539 sp = sp - sig_xstate_ia32_size;
8540 - *fpstate = (struct _fpstate_ia32 *) sp;
8541 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8542 if (save_i387_xstate_ia32(*fpstate) < 0)
8543 return (void __user *) -1L;
8544 }
8545 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8546 sp -= frame_size;
8547 /* Align the stack pointer according to the i386 ABI,
8548 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8549 - sp = ((sp + 4) & -16ul) - 4;
8550 + sp = ((sp - 12) & -16ul) - 4;
8551 return (void __user *) sp;
8552 }
8553
8554 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8555 * These are actually not used anymore, but left because some
8556 * gdb versions depend on them as a marker.
8557 */
8558 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8559 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8560 } put_user_catch(err);
8561
8562 if (err)
8563 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8564 0xb8,
8565 __NR_ia32_rt_sigreturn,
8566 0x80cd,
8567 - 0,
8568 + 0
8569 };
8570
8571 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8572 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8573
8574 if (ka->sa.sa_flags & SA_RESTORER)
8575 restorer = ka->sa.sa_restorer;
8576 + else if (current->mm->context.vdso)
8577 + /* Return stub is in 32bit vsyscall page */
8578 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8579 else
8580 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8581 - rt_sigreturn);
8582 + restorer = &frame->retcode;
8583 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8584
8585 /*
8586 * Not actually used anymore, but left because some gdb
8587 * versions need it.
8588 */
8589 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8590 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8591 } put_user_catch(err);
8592
8593 if (err)
8594 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8595 index 20e5f7b..eab8751 100644
8596 --- a/arch/x86/ia32/ia32entry.S
8597 +++ b/arch/x86/ia32/ia32entry.S
8598 @@ -14,8 +14,10 @@
8599 #include <asm/segment.h>
8600 #include <asm/irqflags.h>
8601 #include <asm/asm.h>
8602 +#include <asm/pgtable.h>
8603 #include <linux/linkage.h>
8604 #include <linux/err.h>
8605 +#include <asm/alternative-asm.h>
8606
8607 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8608 #include <linux/elf-em.h>
8609 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8610 ENDPROC(native_irq_enable_sysexit)
8611 #endif
8612
8613 + .macro pax_enter_kernel_user
8614 + pax_set_fptr_mask
8615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8616 + call pax_enter_kernel_user
8617 +#endif
8618 + .endm
8619 +
8620 + .macro pax_exit_kernel_user
8621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8622 + call pax_exit_kernel_user
8623 +#endif
8624 +#ifdef CONFIG_PAX_RANDKSTACK
8625 + pushq %rax
8626 + pushq %r11
8627 + call pax_randomize_kstack
8628 + popq %r11
8629 + popq %rax
8630 +#endif
8631 + .endm
8632 +
8633 +.macro pax_erase_kstack
8634 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8635 + call pax_erase_kstack
8636 +#endif
8637 +.endm
8638 +
8639 /*
8640 * 32bit SYSENTER instruction entry.
8641 *
8642 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8643 CFI_REGISTER rsp,rbp
8644 SWAPGS_UNSAFE_STACK
8645 movq PER_CPU_VAR(kernel_stack), %rsp
8646 - addq $(KERNEL_STACK_OFFSET),%rsp
8647 - /*
8648 - * No need to follow this irqs on/off section: the syscall
8649 - * disabled irqs, here we enable it straight after entry:
8650 - */
8651 - ENABLE_INTERRUPTS(CLBR_NONE)
8652 movl %ebp,%ebp /* zero extension */
8653 pushq_cfi $__USER32_DS
8654 /*CFI_REL_OFFSET ss,0*/
8655 @@ -134,22 +156,37 @@ ENTRY(ia32_sysenter_target)
8656 CFI_REL_OFFSET rsp,0
8657 pushfq_cfi
8658 /*CFI_REL_OFFSET rflags,0*/
8659 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8660 - CFI_REGISTER rip,r10
8661 + orl $X86_EFLAGS_IF,(%rsp)
8662 + GET_THREAD_INFO(%r11)
8663 + movl TI_sysenter_return(%r11), %r11d
8664 + CFI_REGISTER rip,r11
8665 pushq_cfi $__USER32_CS
8666 /*CFI_REL_OFFSET cs,0*/
8667 movl %eax, %eax
8668 - pushq_cfi %r10
8669 + pushq_cfi %r11
8670 CFI_REL_OFFSET rip,0
8671 pushq_cfi %rax
8672 cld
8673 SAVE_ARGS 0,1,0
8674 + pax_enter_kernel_user
8675 + /*
8676 + * No need to follow this irqs on/off section: the syscall
8677 + * disabled irqs, here we enable it straight after entry:
8678 + */
8679 + ENABLE_INTERRUPTS(CLBR_NONE)
8680 /* no need to do an access_ok check here because rbp has been
8681 32bit zero extended */
8682 +
8683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8684 + mov $PAX_USER_SHADOW_BASE,%r11
8685 + add %r11,%rbp
8686 +#endif
8687 +
8688 1: movl (%rbp),%ebp
8689 _ASM_EXTABLE(1b,ia32_badarg)
8690 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8691 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8692 + GET_THREAD_INFO(%r11)
8693 + orl $TS_COMPAT,TI_status(%r11)
8694 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8695 CFI_REMEMBER_STATE
8696 jnz sysenter_tracesys
8697 cmpq $(IA32_NR_syscalls-1),%rax
8698 @@ -159,12 +196,15 @@ sysenter_do_call:
8699 sysenter_dispatch:
8700 call *ia32_sys_call_table(,%rax,8)
8701 movq %rax,RAX-ARGOFFSET(%rsp)
8702 + GET_THREAD_INFO(%r11)
8703 DISABLE_INTERRUPTS(CLBR_NONE)
8704 TRACE_IRQS_OFF
8705 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8706 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8707 jnz sysexit_audit
8708 sysexit_from_sys_call:
8709 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8710 + pax_exit_kernel_user
8711 + pax_erase_kstack
8712 + andl $~TS_COMPAT,TI_status(%r11)
8713 /* clear IF, that popfq doesn't enable interrupts early */
8714 andl $~0x200,EFLAGS-R11(%rsp)
8715 movl RIP-R11(%rsp),%edx /* User %eip */
8716 @@ -190,6 +230,9 @@ sysexit_from_sys_call:
8717 movl %eax,%esi /* 2nd arg: syscall number */
8718 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8719 call __audit_syscall_entry
8720 +
8721 + pax_erase_kstack
8722 +
8723 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8724 cmpq $(IA32_NR_syscalls-1),%rax
8725 ja ia32_badsys
8726 @@ -201,7 +244,7 @@ sysexit_from_sys_call:
8727 .endm
8728
8729 .macro auditsys_exit exit
8730 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8731 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8732 jnz ia32_ret_from_sys_call
8733 TRACE_IRQS_ON
8734 sti
8735 @@ -212,11 +255,12 @@ sysexit_from_sys_call:
8736 1: setbe %al /* 1 if error, 0 if not */
8737 movzbl %al,%edi /* zero-extend that into %edi */
8738 call __audit_syscall_exit
8739 + GET_THREAD_INFO(%r11)
8740 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8741 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8742 cli
8743 TRACE_IRQS_OFF
8744 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8745 + testl %edi,TI_flags(%r11)
8746 jz \exit
8747 CLEAR_RREGS -ARGOFFSET
8748 jmp int_with_check
8749 @@ -234,7 +278,7 @@ sysexit_audit:
8750
8751 sysenter_tracesys:
8752 #ifdef CONFIG_AUDITSYSCALL
8753 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8754 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8755 jz sysenter_auditsys
8756 #endif
8757 SAVE_REST
8758 @@ -242,6 +286,9 @@ sysenter_tracesys:
8759 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8760 movq %rsp,%rdi /* &pt_regs -> arg1 */
8761 call syscall_trace_enter
8762 +
8763 + pax_erase_kstack
8764 +
8765 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8766 RESTORE_REST
8767 cmpq $(IA32_NR_syscalls-1),%rax
8768 @@ -273,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
8769 ENTRY(ia32_cstar_target)
8770 CFI_STARTPROC32 simple
8771 CFI_SIGNAL_FRAME
8772 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8773 + CFI_DEF_CFA rsp,0
8774 CFI_REGISTER rip,rcx
8775 /*CFI_REGISTER rflags,r11*/
8776 SWAPGS_UNSAFE_STACK
8777 movl %esp,%r8d
8778 CFI_REGISTER rsp,r8
8779 movq PER_CPU_VAR(kernel_stack),%rsp
8780 + SAVE_ARGS 8*6,0,0
8781 + pax_enter_kernel_user
8782 /*
8783 * No need to follow this irqs on/off section: the syscall
8784 * disabled irqs and here we enable it straight after entry:
8785 */
8786 ENABLE_INTERRUPTS(CLBR_NONE)
8787 - SAVE_ARGS 8,0,0
8788 movl %eax,%eax /* zero extension */
8789 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8790 movq %rcx,RIP-ARGOFFSET(%rsp)
8791 @@ -301,10 +349,17 @@ ENTRY(ia32_cstar_target)
8792 /* no need to do an access_ok check here because r8 has been
8793 32bit zero extended */
8794 /* hardware stack frame is complete now */
8795 +
8796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8797 + mov $PAX_USER_SHADOW_BASE,%r11
8798 + add %r11,%r8
8799 +#endif
8800 +
8801 1: movl (%r8),%r9d
8802 _ASM_EXTABLE(1b,ia32_badarg)
8803 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8804 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8805 + GET_THREAD_INFO(%r11)
8806 + orl $TS_COMPAT,TI_status(%r11)
8807 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8808 CFI_REMEMBER_STATE
8809 jnz cstar_tracesys
8810 cmpq $IA32_NR_syscalls-1,%rax
8811 @@ -314,12 +369,15 @@ cstar_do_call:
8812 cstar_dispatch:
8813 call *ia32_sys_call_table(,%rax,8)
8814 movq %rax,RAX-ARGOFFSET(%rsp)
8815 + GET_THREAD_INFO(%r11)
8816 DISABLE_INTERRUPTS(CLBR_NONE)
8817 TRACE_IRQS_OFF
8818 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8820 jnz sysretl_audit
8821 sysretl_from_sys_call:
8822 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8823 + pax_exit_kernel_user
8824 + pax_erase_kstack
8825 + andl $~TS_COMPAT,TI_status(%r11)
8826 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8827 movl RIP-ARGOFFSET(%rsp),%ecx
8828 CFI_REGISTER rip,rcx
8829 @@ -347,7 +405,7 @@ sysretl_audit:
8830
8831 cstar_tracesys:
8832 #ifdef CONFIG_AUDITSYSCALL
8833 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8834 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8835 jz cstar_auditsys
8836 #endif
8837 xchgl %r9d,%ebp
8838 @@ -356,6 +414,9 @@ cstar_tracesys:
8839 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8840 movq %rsp,%rdi /* &pt_regs -> arg1 */
8841 call syscall_trace_enter
8842 +
8843 + pax_erase_kstack
8844 +
8845 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8846 RESTORE_REST
8847 xchgl %ebp,%r9d
8848 @@ -401,19 +462,21 @@ ENTRY(ia32_syscall)
8849 CFI_REL_OFFSET rip,RIP-RIP
8850 PARAVIRT_ADJUST_EXCEPTION_FRAME
8851 SWAPGS
8852 - /*
8853 - * No need to follow this irqs on/off section: the syscall
8854 - * disabled irqs and here we enable it straight after entry:
8855 - */
8856 - ENABLE_INTERRUPTS(CLBR_NONE)
8857 movl %eax,%eax
8858 pushq_cfi %rax
8859 cld
8860 /* note the registers are not zero extended to the sf.
8861 this could be a problem. */
8862 SAVE_ARGS 0,1,0
8863 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8864 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8865 + pax_enter_kernel_user
8866 + /*
8867 + * No need to follow this irqs on/off section: the syscall
8868 + * disabled irqs and here we enable it straight after entry:
8869 + */
8870 + ENABLE_INTERRUPTS(CLBR_NONE)
8871 + GET_THREAD_INFO(%r11)
8872 + orl $TS_COMPAT,TI_status(%r11)
8873 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8874 jnz ia32_tracesys
8875 cmpq $(IA32_NR_syscalls-1),%rax
8876 ja ia32_badsys
8877 @@ -432,6 +495,9 @@ ia32_tracesys:
8878 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8879 movq %rsp,%rdi /* &pt_regs -> arg1 */
8880 call syscall_trace_enter
8881 +
8882 + pax_erase_kstack
8883 +
8884 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8885 RESTORE_REST
8886 cmpq $(IA32_NR_syscalls-1),%rax
8887 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8888 index 4540bec..714d913 100644
8889 --- a/arch/x86/ia32/sys_ia32.c
8890 +++ b/arch/x86/ia32/sys_ia32.c
8891 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8892 */
8893 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8894 {
8895 - typeof(ubuf->st_uid) uid = 0;
8896 - typeof(ubuf->st_gid) gid = 0;
8897 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8898 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8899 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8900 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8901 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8902 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8903 return ret;
8904 }
8905
8906 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8907 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8908 int options)
8909 {
8910 return compat_sys_wait4(pid, stat_addr, options, NULL);
8911 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8912 mm_segment_t old_fs = get_fs();
8913
8914 set_fs(KERNEL_DS);
8915 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8916 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8917 set_fs(old_fs);
8918 if (put_compat_timespec(&t, interval))
8919 return -EFAULT;
8920 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8921 mm_segment_t old_fs = get_fs();
8922
8923 set_fs(KERNEL_DS);
8924 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8925 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8926 set_fs(old_fs);
8927 if (!ret) {
8928 switch (_NSIG_WORDS) {
8929 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8930 if (copy_siginfo_from_user32(&info, uinfo))
8931 return -EFAULT;
8932 set_fs(KERNEL_DS);
8933 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8934 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8935 set_fs(old_fs);
8936 return ret;
8937 }
8938 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8939 return -EFAULT;
8940
8941 set_fs(KERNEL_DS);
8942 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8943 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8944 count);
8945 set_fs(old_fs);
8946
8947 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8948 index 952bd01..7692c6f 100644
8949 --- a/arch/x86/include/asm/alternative-asm.h
8950 +++ b/arch/x86/include/asm/alternative-asm.h
8951 @@ -15,6 +15,45 @@
8952 .endm
8953 #endif
8954
8955 +#ifdef KERNEXEC_PLUGIN
8956 + .macro pax_force_retaddr_bts rip=0
8957 + btsq $63,\rip(%rsp)
8958 + .endm
8959 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8960 + .macro pax_force_retaddr rip=0, reload=0
8961 + btsq $63,\rip(%rsp)
8962 + .endm
8963 + .macro pax_force_fptr ptr
8964 + btsq $63,\ptr
8965 + .endm
8966 + .macro pax_set_fptr_mask
8967 + .endm
8968 +#endif
8969 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8970 + .macro pax_force_retaddr rip=0, reload=0
8971 + .if \reload
8972 + pax_set_fptr_mask
8973 + .endif
8974 + orq %r10,\rip(%rsp)
8975 + .endm
8976 + .macro pax_force_fptr ptr
8977 + orq %r10,\ptr
8978 + .endm
8979 + .macro pax_set_fptr_mask
8980 + movabs $0x8000000000000000,%r10
8981 + .endm
8982 +#endif
8983 +#else
8984 + .macro pax_force_retaddr rip=0, reload=0
8985 + .endm
8986 + .macro pax_force_fptr ptr
8987 + .endm
8988 + .macro pax_force_retaddr_bts rip=0
8989 + .endm
8990 + .macro pax_set_fptr_mask
8991 + .endm
8992 +#endif
8993 +
8994 .macro altinstruction_entry orig alt feature orig_len alt_len
8995 .long \orig - .
8996 .long \alt - .
8997 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8998 index 49331be..9706065 100644
8999 --- a/arch/x86/include/asm/alternative.h
9000 +++ b/arch/x86/include/asm/alternative.h
9001 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9002 ".section .discard,\"aw\",@progbits\n" \
9003 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9004 ".previous\n" \
9005 - ".section .altinstr_replacement, \"ax\"\n" \
9006 + ".section .altinstr_replacement, \"a\"\n" \
9007 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9008 ".previous"
9009
9010 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9011 index eaff479..3025a63 100644
9012 --- a/arch/x86/include/asm/apic.h
9013 +++ b/arch/x86/include/asm/apic.h
9014 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9015
9016 #ifdef CONFIG_X86_LOCAL_APIC
9017
9018 -extern unsigned int apic_verbosity;
9019 +extern int apic_verbosity;
9020 extern int local_apic_timer_c2_ok;
9021
9022 extern int disable_apic;
9023 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9024 index 20370c6..a2eb9b0 100644
9025 --- a/arch/x86/include/asm/apm.h
9026 +++ b/arch/x86/include/asm/apm.h
9027 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9028 __asm__ __volatile__(APM_DO_ZERO_SEGS
9029 "pushl %%edi\n\t"
9030 "pushl %%ebp\n\t"
9031 - "lcall *%%cs:apm_bios_entry\n\t"
9032 + "lcall *%%ss:apm_bios_entry\n\t"
9033 "setc %%al\n\t"
9034 "popl %%ebp\n\t"
9035 "popl %%edi\n\t"
9036 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9037 __asm__ __volatile__(APM_DO_ZERO_SEGS
9038 "pushl %%edi\n\t"
9039 "pushl %%ebp\n\t"
9040 - "lcall *%%cs:apm_bios_entry\n\t"
9041 + "lcall *%%ss:apm_bios_entry\n\t"
9042 "setc %%bl\n\t"
9043 "popl %%ebp\n\t"
9044 "popl %%edi\n\t"
9045 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9046 index 58cb6d4..a4b806c 100644
9047 --- a/arch/x86/include/asm/atomic.h
9048 +++ b/arch/x86/include/asm/atomic.h
9049 @@ -22,7 +22,18 @@
9050 */
9051 static inline int atomic_read(const atomic_t *v)
9052 {
9053 - return (*(volatile int *)&(v)->counter);
9054 + return (*(volatile const int *)&(v)->counter);
9055 +}
9056 +
9057 +/**
9058 + * atomic_read_unchecked - read atomic variable
9059 + * @v: pointer of type atomic_unchecked_t
9060 + *
9061 + * Atomically reads the value of @v.
9062 + */
9063 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9064 +{
9065 + return (*(volatile const int *)&(v)->counter);
9066 }
9067
9068 /**
9069 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9070 }
9071
9072 /**
9073 + * atomic_set_unchecked - set atomic variable
9074 + * @v: pointer of type atomic_unchecked_t
9075 + * @i: required value
9076 + *
9077 + * Atomically sets the value of @v to @i.
9078 + */
9079 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9080 +{
9081 + v->counter = i;
9082 +}
9083 +
9084 +/**
9085 * atomic_add - add integer to atomic variable
9086 * @i: integer value to add
9087 * @v: pointer of type atomic_t
9088 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9089 */
9090 static inline void atomic_add(int i, atomic_t *v)
9091 {
9092 - asm volatile(LOCK_PREFIX "addl %1,%0"
9093 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9094 +
9095 +#ifdef CONFIG_PAX_REFCOUNT
9096 + "jno 0f\n"
9097 + LOCK_PREFIX "subl %1,%0\n"
9098 + "int $4\n0:\n"
9099 + _ASM_EXTABLE(0b, 0b)
9100 +#endif
9101 +
9102 + : "+m" (v->counter)
9103 + : "ir" (i));
9104 +}
9105 +
9106 +/**
9107 + * atomic_add_unchecked - add integer to atomic variable
9108 + * @i: integer value to add
9109 + * @v: pointer of type atomic_unchecked_t
9110 + *
9111 + * Atomically adds @i to @v.
9112 + */
9113 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9114 +{
9115 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9116 : "+m" (v->counter)
9117 : "ir" (i));
9118 }
9119 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9120 */
9121 static inline void atomic_sub(int i, atomic_t *v)
9122 {
9123 - asm volatile(LOCK_PREFIX "subl %1,%0"
9124 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9125 +
9126 +#ifdef CONFIG_PAX_REFCOUNT
9127 + "jno 0f\n"
9128 + LOCK_PREFIX "addl %1,%0\n"
9129 + "int $4\n0:\n"
9130 + _ASM_EXTABLE(0b, 0b)
9131 +#endif
9132 +
9133 + : "+m" (v->counter)
9134 + : "ir" (i));
9135 +}
9136 +
9137 +/**
9138 + * atomic_sub_unchecked - subtract integer from atomic variable
9139 + * @i: integer value to subtract
9140 + * @v: pointer of type atomic_unchecked_t
9141 + *
9142 + * Atomically subtracts @i from @v.
9143 + */
9144 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9145 +{
9146 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9147 : "+m" (v->counter)
9148 : "ir" (i));
9149 }
9150 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9151 {
9152 unsigned char c;
9153
9154 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9155 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9156 +
9157 +#ifdef CONFIG_PAX_REFCOUNT
9158 + "jno 0f\n"
9159 + LOCK_PREFIX "addl %2,%0\n"
9160 + "int $4\n0:\n"
9161 + _ASM_EXTABLE(0b, 0b)
9162 +#endif
9163 +
9164 + "sete %1\n"
9165 : "+m" (v->counter), "=qm" (c)
9166 : "ir" (i) : "memory");
9167 return c;
9168 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9169 */
9170 static inline void atomic_inc(atomic_t *v)
9171 {
9172 - asm volatile(LOCK_PREFIX "incl %0"
9173 + asm volatile(LOCK_PREFIX "incl %0\n"
9174 +
9175 +#ifdef CONFIG_PAX_REFCOUNT
9176 + "jno 0f\n"
9177 + LOCK_PREFIX "decl %0\n"
9178 + "int $4\n0:\n"
9179 + _ASM_EXTABLE(0b, 0b)
9180 +#endif
9181 +
9182 + : "+m" (v->counter));
9183 +}
9184 +
9185 +/**
9186 + * atomic_inc_unchecked - increment atomic variable
9187 + * @v: pointer of type atomic_unchecked_t
9188 + *
9189 + * Atomically increments @v by 1.
9190 + */
9191 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9192 +{
9193 + asm volatile(LOCK_PREFIX "incl %0\n"
9194 : "+m" (v->counter));
9195 }
9196
9197 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9198 */
9199 static inline void atomic_dec(atomic_t *v)
9200 {
9201 - asm volatile(LOCK_PREFIX "decl %0"
9202 + asm volatile(LOCK_PREFIX "decl %0\n"
9203 +
9204 +#ifdef CONFIG_PAX_REFCOUNT
9205 + "jno 0f\n"
9206 + LOCK_PREFIX "incl %0\n"
9207 + "int $4\n0:\n"
9208 + _ASM_EXTABLE(0b, 0b)
9209 +#endif
9210 +
9211 + : "+m" (v->counter));
9212 +}
9213 +
9214 +/**
9215 + * atomic_dec_unchecked - decrement atomic variable
9216 + * @v: pointer of type atomic_unchecked_t
9217 + *
9218 + * Atomically decrements @v by 1.
9219 + */
9220 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9221 +{
9222 + asm volatile(LOCK_PREFIX "decl %0\n"
9223 : "+m" (v->counter));
9224 }
9225
9226 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9227 {
9228 unsigned char c;
9229
9230 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9231 + asm volatile(LOCK_PREFIX "decl %0\n"
9232 +
9233 +#ifdef CONFIG_PAX_REFCOUNT
9234 + "jno 0f\n"
9235 + LOCK_PREFIX "incl %0\n"
9236 + "int $4\n0:\n"
9237 + _ASM_EXTABLE(0b, 0b)
9238 +#endif
9239 +
9240 + "sete %1\n"
9241 : "+m" (v->counter), "=qm" (c)
9242 : : "memory");
9243 return c != 0;
9244 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9245 {
9246 unsigned char c;
9247
9248 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9249 + asm volatile(LOCK_PREFIX "incl %0\n"
9250 +
9251 +#ifdef CONFIG_PAX_REFCOUNT
9252 + "jno 0f\n"
9253 + LOCK_PREFIX "decl %0\n"
9254 + "int $4\n0:\n"
9255 + _ASM_EXTABLE(0b, 0b)
9256 +#endif
9257 +
9258 + "sete %1\n"
9259 + : "+m" (v->counter), "=qm" (c)
9260 + : : "memory");
9261 + return c != 0;
9262 +}
9263 +
9264 +/**
9265 + * atomic_inc_and_test_unchecked - increment and test
9266 + * @v: pointer of type atomic_unchecked_t
9267 + *
9268 + * Atomically increments @v by 1
9269 + * and returns true if the result is zero, or false for all
9270 + * other cases.
9271 + */
9272 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9273 +{
9274 + unsigned char c;
9275 +
9276 + asm volatile(LOCK_PREFIX "incl %0\n"
9277 + "sete %1\n"
9278 : "+m" (v->counter), "=qm" (c)
9279 : : "memory");
9280 return c != 0;
9281 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9282 {
9283 unsigned char c;
9284
9285 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9286 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9287 +
9288 +#ifdef CONFIG_PAX_REFCOUNT
9289 + "jno 0f\n"
9290 + LOCK_PREFIX "subl %2,%0\n"
9291 + "int $4\n0:\n"
9292 + _ASM_EXTABLE(0b, 0b)
9293 +#endif
9294 +
9295 + "sets %1\n"
9296 : "+m" (v->counter), "=qm" (c)
9297 : "ir" (i) : "memory");
9298 return c;
9299 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9300 goto no_xadd;
9301 #endif
9302 /* Modern 486+ processor */
9303 - return i + xadd(&v->counter, i);
9304 + return i + xadd_check_overflow(&v->counter, i);
9305
9306 #ifdef CONFIG_M386
9307 no_xadd: /* Legacy 386 processor */
9308 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9309 }
9310
9311 /**
9312 + * atomic_add_return_unchecked - add integer and return
9313 + * @i: integer value to add
9314 + * @v: pointer of type atomic_unchecked_t
9315 + *
9316 + * Atomically adds @i to @v and returns @i + @v
9317 + */
9318 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9319 +{
9320 +#ifdef CONFIG_M386
9321 + int __i;
9322 + unsigned long flags;
9323 + if (unlikely(boot_cpu_data.x86 <= 3))
9324 + goto no_xadd;
9325 +#endif
9326 + /* Modern 486+ processor */
9327 + return i + xadd(&v->counter, i);
9328 +
9329 +#ifdef CONFIG_M386
9330 +no_xadd: /* Legacy 386 processor */
9331 + raw_local_irq_save(flags);
9332 + __i = atomic_read_unchecked(v);
9333 + atomic_set_unchecked(v, i + __i);
9334 + raw_local_irq_restore(flags);
9335 + return i + __i;
9336 +#endif
9337 +}
9338 +
9339 +/**
9340 * atomic_sub_return - subtract integer and return
9341 * @v: pointer of type atomic_t
9342 * @i: integer value to subtract
9343 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9344 }
9345
9346 #define atomic_inc_return(v) (atomic_add_return(1, v))
9347 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9348 +{
9349 + return atomic_add_return_unchecked(1, v);
9350 +}
9351 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9352
9353 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9354 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9355 return cmpxchg(&v->counter, old, new);
9356 }
9357
9358 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9359 +{
9360 + return cmpxchg(&v->counter, old, new);
9361 +}
9362 +
9363 static inline int atomic_xchg(atomic_t *v, int new)
9364 {
9365 return xchg(&v->counter, new);
9366 }
9367
9368 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9369 +{
9370 + return xchg(&v->counter, new);
9371 +}
9372 +
9373 /**
9374 * __atomic_add_unless - add unless the number is already a given value
9375 * @v: pointer of type atomic_t
9376 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9377 */
9378 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9379 {
9380 - int c, old;
9381 + int c, old, new;
9382 c = atomic_read(v);
9383 for (;;) {
9384 - if (unlikely(c == (u)))
9385 + if (unlikely(c == u))
9386 break;
9387 - old = atomic_cmpxchg((v), c, c + (a));
9388 +
9389 + asm volatile("addl %2,%0\n"
9390 +
9391 +#ifdef CONFIG_PAX_REFCOUNT
9392 + "jno 0f\n"
9393 + "subl %2,%0\n"
9394 + "int $4\n0:\n"
9395 + _ASM_EXTABLE(0b, 0b)
9396 +#endif
9397 +
9398 + : "=r" (new)
9399 + : "0" (c), "ir" (a));
9400 +
9401 + old = atomic_cmpxchg(v, c, new);
9402 if (likely(old == c))
9403 break;
9404 c = old;
9405 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9406 return c;
9407 }
9408
9409 +/**
9410 + * atomic_inc_not_zero_hint - increment if not null
9411 + * @v: pointer of type atomic_t
9412 + * @hint: probable value of the atomic before the increment
9413 + *
9414 + * This version of atomic_inc_not_zero() gives a hint of probable
9415 + * value of the atomic. This helps processor to not read the memory
9416 + * before doing the atomic read/modify/write cycle, lowering
9417 + * number of bus transactions on some arches.
9418 + *
9419 + * Returns: 0 if increment was not done, 1 otherwise.
9420 + */
9421 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9422 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9423 +{
9424 + int val, c = hint, new;
9425 +
9426 + /* sanity test, should be removed by compiler if hint is a constant */
9427 + if (!hint)
9428 + return __atomic_add_unless(v, 1, 0);
9429 +
9430 + do {
9431 + asm volatile("incl %0\n"
9432 +
9433 +#ifdef CONFIG_PAX_REFCOUNT
9434 + "jno 0f\n"
9435 + "decl %0\n"
9436 + "int $4\n0:\n"
9437 + _ASM_EXTABLE(0b, 0b)
9438 +#endif
9439 +
9440 + : "=r" (new)
9441 + : "0" (c));
9442 +
9443 + val = atomic_cmpxchg(v, c, new);
9444 + if (val == c)
9445 + return 1;
9446 + c = val;
9447 + } while (c);
9448 +
9449 + return 0;
9450 +}
9451
9452 /*
9453 * atomic_dec_if_positive - decrement by 1 if old value positive
9454 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9455 #endif
9456
9457 /* These are x86-specific, used by some header files */
9458 -#define atomic_clear_mask(mask, addr) \
9459 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9460 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9461 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9462 +{
9463 + asm volatile(LOCK_PREFIX "andl %1,%0"
9464 + : "+m" (v->counter)
9465 + : "r" (~(mask))
9466 + : "memory");
9467 +}
9468
9469 -#define atomic_set_mask(mask, addr) \
9470 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9471 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9472 - : "memory")
9473 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9474 +{
9475 + asm volatile(LOCK_PREFIX "andl %1,%0"
9476 + : "+m" (v->counter)
9477 + : "r" (~(mask))
9478 + : "memory");
9479 +}
9480 +
9481 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9482 +{
9483 + asm volatile(LOCK_PREFIX "orl %1,%0"
9484 + : "+m" (v->counter)
9485 + : "r" (mask)
9486 + : "memory");
9487 +}
9488 +
9489 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9490 +{
9491 + asm volatile(LOCK_PREFIX "orl %1,%0"
9492 + : "+m" (v->counter)
9493 + : "r" (mask)
9494 + : "memory");
9495 +}
9496
9497 /* Atomic operations are already serializing on x86 */
9498 #define smp_mb__before_atomic_dec() barrier()
9499 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9500 index b154de7..aadebd8 100644
9501 --- a/arch/x86/include/asm/atomic64_32.h
9502 +++ b/arch/x86/include/asm/atomic64_32.h
9503 @@ -12,6 +12,14 @@ typedef struct {
9504 u64 __aligned(8) counter;
9505 } atomic64_t;
9506
9507 +#ifdef CONFIG_PAX_REFCOUNT
9508 +typedef struct {
9509 + u64 __aligned(8) counter;
9510 +} atomic64_unchecked_t;
9511 +#else
9512 +typedef atomic64_t atomic64_unchecked_t;
9513 +#endif
9514 +
9515 #define ATOMIC64_INIT(val) { (val) }
9516
9517 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9518 @@ -37,21 +45,31 @@ typedef struct {
9519 ATOMIC64_DECL_ONE(sym##_386)
9520
9521 ATOMIC64_DECL_ONE(add_386);
9522 +ATOMIC64_DECL_ONE(add_unchecked_386);
9523 ATOMIC64_DECL_ONE(sub_386);
9524 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9525 ATOMIC64_DECL_ONE(inc_386);
9526 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9527 ATOMIC64_DECL_ONE(dec_386);
9528 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9529 #endif
9530
9531 #define alternative_atomic64(f, out, in...) \
9532 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9533
9534 ATOMIC64_DECL(read);
9535 +ATOMIC64_DECL(read_unchecked);
9536 ATOMIC64_DECL(set);
9537 +ATOMIC64_DECL(set_unchecked);
9538 ATOMIC64_DECL(xchg);
9539 ATOMIC64_DECL(add_return);
9540 +ATOMIC64_DECL(add_return_unchecked);
9541 ATOMIC64_DECL(sub_return);
9542 +ATOMIC64_DECL(sub_return_unchecked);
9543 ATOMIC64_DECL(inc_return);
9544 +ATOMIC64_DECL(inc_return_unchecked);
9545 ATOMIC64_DECL(dec_return);
9546 +ATOMIC64_DECL(dec_return_unchecked);
9547 ATOMIC64_DECL(dec_if_positive);
9548 ATOMIC64_DECL(inc_not_zero);
9549 ATOMIC64_DECL(add_unless);
9550 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9551 }
9552
9553 /**
9554 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9555 + * @p: pointer to type atomic64_unchecked_t
9556 + * @o: expected value
9557 + * @n: new value
9558 + *
9559 + * Atomically sets @v to @n if it was equal to @o and returns
9560 + * the old value.
9561 + */
9562 +
9563 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9564 +{
9565 + return cmpxchg64(&v->counter, o, n);
9566 +}
9567 +
9568 +/**
9569 * atomic64_xchg - xchg atomic64 variable
9570 * @v: pointer to type atomic64_t
9571 * @n: value to assign
9572 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9573 }
9574
9575 /**
9576 + * atomic64_set_unchecked - set atomic64 variable
9577 + * @v: pointer to type atomic64_unchecked_t
9578 + * @n: value to assign
9579 + *
9580 + * Atomically sets the value of @v to @n.
9581 + */
9582 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9583 +{
9584 + unsigned high = (unsigned)(i >> 32);
9585 + unsigned low = (unsigned)i;
9586 + alternative_atomic64(set, /* no output */,
9587 + "S" (v), "b" (low), "c" (high)
9588 + : "eax", "edx", "memory");
9589 +}
9590 +
9591 +/**
9592 * atomic64_read - read atomic64 variable
9593 * @v: pointer to type atomic64_t
9594 *
9595 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9596 }
9597
9598 /**
9599 + * atomic64_read_unchecked - read atomic64 variable
9600 + * @v: pointer to type atomic64_unchecked_t
9601 + *
9602 + * Atomically reads the value of @v and returns it.
9603 + */
9604 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9605 +{
9606 + long long r;
9607 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9608 + return r;
9609 + }
9610 +
9611 +/**
9612 * atomic64_add_return - add and return
9613 * @i: integer value to add
9614 * @v: pointer to type atomic64_t
9615 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9616 return i;
9617 }
9618
9619 +/**
9620 + * atomic64_add_return_unchecked - add and return
9621 + * @i: integer value to add
9622 + * @v: pointer to type atomic64_unchecked_t
9623 + *
9624 + * Atomically adds @i to @v and returns @i + *@v
9625 + */
9626 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9627 +{
9628 + alternative_atomic64(add_return_unchecked,
9629 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9630 + ASM_NO_INPUT_CLOBBER("memory"));
9631 + return i;
9632 +}
9633 +
9634 /*
9635 * Other variants with different arithmetic operators:
9636 */
9637 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9638 return a;
9639 }
9640
9641 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9642 +{
9643 + long long a;
9644 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9645 + "S" (v) : "memory", "ecx");
9646 + return a;
9647 +}
9648 +
9649 static inline long long atomic64_dec_return(atomic64_t *v)
9650 {
9651 long long a;
9652 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9653 }
9654
9655 /**
9656 + * atomic64_add_unchecked - add integer to atomic64 variable
9657 + * @i: integer value to add
9658 + * @v: pointer to type atomic64_unchecked_t
9659 + *
9660 + * Atomically adds @i to @v.
9661 + */
9662 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9663 +{
9664 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9665 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9666 + ASM_NO_INPUT_CLOBBER("memory"));
9667 + return i;
9668 +}
9669 +
9670 +/**
9671 * atomic64_sub - subtract the atomic64 variable
9672 * @i: integer value to subtract
9673 * @v: pointer to type atomic64_t
9674 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9675 index 0e1cbfc..5623683 100644
9676 --- a/arch/x86/include/asm/atomic64_64.h
9677 +++ b/arch/x86/include/asm/atomic64_64.h
9678 @@ -18,7 +18,19 @@
9679 */
9680 static inline long atomic64_read(const atomic64_t *v)
9681 {
9682 - return (*(volatile long *)&(v)->counter);
9683 + return (*(volatile const long *)&(v)->counter);
9684 +}
9685 +
9686 +/**
9687 + * atomic64_read_unchecked - read atomic64 variable
9688 + * @v: pointer of type atomic64_unchecked_t
9689 + *
9690 + * Atomically reads the value of @v.
9691 + * Doesn't imply a read memory barrier.
9692 + */
9693 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9694 +{
9695 + return (*(volatile const long *)&(v)->counter);
9696 }
9697
9698 /**
9699 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9700 }
9701
9702 /**
9703 + * atomic64_set_unchecked - set atomic64 variable
9704 + * @v: pointer to type atomic64_unchecked_t
9705 + * @i: required value
9706 + *
9707 + * Atomically sets the value of @v to @i.
9708 + */
9709 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9710 +{
9711 + v->counter = i;
9712 +}
9713 +
9714 +/**
9715 * atomic64_add - add integer to atomic64 variable
9716 * @i: integer value to add
9717 * @v: pointer to type atomic64_t
9718 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9719 */
9720 static inline void atomic64_add(long i, atomic64_t *v)
9721 {
9722 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9723 +
9724 +#ifdef CONFIG_PAX_REFCOUNT
9725 + "jno 0f\n"
9726 + LOCK_PREFIX "subq %1,%0\n"
9727 + "int $4\n0:\n"
9728 + _ASM_EXTABLE(0b, 0b)
9729 +#endif
9730 +
9731 + : "=m" (v->counter)
9732 + : "er" (i), "m" (v->counter));
9733 +}
9734 +
9735 +/**
9736 + * atomic64_add_unchecked - add integer to atomic64 variable
9737 + * @i: integer value to add
9738 + * @v: pointer to type atomic64_unchecked_t
9739 + *
9740 + * Atomically adds @i to @v.
9741 + */
9742 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9743 +{
9744 asm volatile(LOCK_PREFIX "addq %1,%0"
9745 : "=m" (v->counter)
9746 : "er" (i), "m" (v->counter));
9747 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9748 */
9749 static inline void atomic64_sub(long i, atomic64_t *v)
9750 {
9751 - asm volatile(LOCK_PREFIX "subq %1,%0"
9752 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9753 +
9754 +#ifdef CONFIG_PAX_REFCOUNT
9755 + "jno 0f\n"
9756 + LOCK_PREFIX "addq %1,%0\n"
9757 + "int $4\n0:\n"
9758 + _ASM_EXTABLE(0b, 0b)
9759 +#endif
9760 +
9761 + : "=m" (v->counter)
9762 + : "er" (i), "m" (v->counter));
9763 +}
9764 +
9765 +/**
9766 + * atomic64_sub_unchecked - subtract the atomic64 variable
9767 + * @i: integer value to subtract
9768 + * @v: pointer to type atomic64_unchecked_t
9769 + *
9770 + * Atomically subtracts @i from @v.
9771 + */
9772 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9773 +{
9774 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9775 : "=m" (v->counter)
9776 : "er" (i), "m" (v->counter));
9777 }
9778 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9779 {
9780 unsigned char c;
9781
9782 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9783 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9784 +
9785 +#ifdef CONFIG_PAX_REFCOUNT
9786 + "jno 0f\n"
9787 + LOCK_PREFIX "addq %2,%0\n"
9788 + "int $4\n0:\n"
9789 + _ASM_EXTABLE(0b, 0b)
9790 +#endif
9791 +
9792 + "sete %1\n"
9793 : "=m" (v->counter), "=qm" (c)
9794 : "er" (i), "m" (v->counter) : "memory");
9795 return c;
9796 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9797 */
9798 static inline void atomic64_inc(atomic64_t *v)
9799 {
9800 + asm volatile(LOCK_PREFIX "incq %0\n"
9801 +
9802 +#ifdef CONFIG_PAX_REFCOUNT
9803 + "jno 0f\n"
9804 + LOCK_PREFIX "decq %0\n"
9805 + "int $4\n0:\n"
9806 + _ASM_EXTABLE(0b, 0b)
9807 +#endif
9808 +
9809 + : "=m" (v->counter)
9810 + : "m" (v->counter));
9811 +}
9812 +
9813 +/**
9814 + * atomic64_inc_unchecked - increment atomic64 variable
9815 + * @v: pointer to type atomic64_unchecked_t
9816 + *
9817 + * Atomically increments @v by 1.
9818 + */
9819 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9820 +{
9821 asm volatile(LOCK_PREFIX "incq %0"
9822 : "=m" (v->counter)
9823 : "m" (v->counter));
9824 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9825 */
9826 static inline void atomic64_dec(atomic64_t *v)
9827 {
9828 - asm volatile(LOCK_PREFIX "decq %0"
9829 + asm volatile(LOCK_PREFIX "decq %0\n"
9830 +
9831 +#ifdef CONFIG_PAX_REFCOUNT
9832 + "jno 0f\n"
9833 + LOCK_PREFIX "incq %0\n"
9834 + "int $4\n0:\n"
9835 + _ASM_EXTABLE(0b, 0b)
9836 +#endif
9837 +
9838 + : "=m" (v->counter)
9839 + : "m" (v->counter));
9840 +}
9841 +
9842 +/**
9843 + * atomic64_dec_unchecked - decrement atomic64 variable
9844 + * @v: pointer to type atomic64_t
9845 + *
9846 + * Atomically decrements @v by 1.
9847 + */
9848 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9849 +{
9850 + asm volatile(LOCK_PREFIX "decq %0\n"
9851 : "=m" (v->counter)
9852 : "m" (v->counter));
9853 }
9854 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9855 {
9856 unsigned char c;
9857
9858 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9859 + asm volatile(LOCK_PREFIX "decq %0\n"
9860 +
9861 +#ifdef CONFIG_PAX_REFCOUNT
9862 + "jno 0f\n"
9863 + LOCK_PREFIX "incq %0\n"
9864 + "int $4\n0:\n"
9865 + _ASM_EXTABLE(0b, 0b)
9866 +#endif
9867 +
9868 + "sete %1\n"
9869 : "=m" (v->counter), "=qm" (c)
9870 : "m" (v->counter) : "memory");
9871 return c != 0;
9872 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9873 {
9874 unsigned char c;
9875
9876 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9877 + asm volatile(LOCK_PREFIX "incq %0\n"
9878 +
9879 +#ifdef CONFIG_PAX_REFCOUNT
9880 + "jno 0f\n"
9881 + LOCK_PREFIX "decq %0\n"
9882 + "int $4\n0:\n"
9883 + _ASM_EXTABLE(0b, 0b)
9884 +#endif
9885 +
9886 + "sete %1\n"
9887 : "=m" (v->counter), "=qm" (c)
9888 : "m" (v->counter) : "memory");
9889 return c != 0;
9890 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9891 {
9892 unsigned char c;
9893
9894 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9895 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9896 +
9897 +#ifdef CONFIG_PAX_REFCOUNT
9898 + "jno 0f\n"
9899 + LOCK_PREFIX "subq %2,%0\n"
9900 + "int $4\n0:\n"
9901 + _ASM_EXTABLE(0b, 0b)
9902 +#endif
9903 +
9904 + "sets %1\n"
9905 : "=m" (v->counter), "=qm" (c)
9906 : "er" (i), "m" (v->counter) : "memory");
9907 return c;
9908 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9909 */
9910 static inline long atomic64_add_return(long i, atomic64_t *v)
9911 {
9912 + return i + xadd_check_overflow(&v->counter, i);
9913 +}
9914 +
9915 +/**
9916 + * atomic64_add_return_unchecked - add and return
9917 + * @i: integer value to add
9918 + * @v: pointer to type atomic64_unchecked_t
9919 + *
9920 + * Atomically adds @i to @v and returns @i + @v
9921 + */
9922 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9923 +{
9924 return i + xadd(&v->counter, i);
9925 }
9926
9927 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9928 }
9929
9930 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9931 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9932 +{
9933 + return atomic64_add_return_unchecked(1, v);
9934 +}
9935 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9936
9937 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9938 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9939 return cmpxchg(&v->counter, old, new);
9940 }
9941
9942 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9943 +{
9944 + return cmpxchg(&v->counter, old, new);
9945 +}
9946 +
9947 static inline long atomic64_xchg(atomic64_t *v, long new)
9948 {
9949 return xchg(&v->counter, new);
9950 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9951 */
9952 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9953 {
9954 - long c, old;
9955 + long c, old, new;
9956 c = atomic64_read(v);
9957 for (;;) {
9958 - if (unlikely(c == (u)))
9959 + if (unlikely(c == u))
9960 break;
9961 - old = atomic64_cmpxchg((v), c, c + (a));
9962 +
9963 + asm volatile("add %2,%0\n"
9964 +
9965 +#ifdef CONFIG_PAX_REFCOUNT
9966 + "jno 0f\n"
9967 + "sub %2,%0\n"
9968 + "int $4\n0:\n"
9969 + _ASM_EXTABLE(0b, 0b)
9970 +#endif
9971 +
9972 + : "=r" (new)
9973 + : "0" (c), "ir" (a));
9974 +
9975 + old = atomic64_cmpxchg(v, c, new);
9976 if (likely(old == c))
9977 break;
9978 c = old;
9979 }
9980 - return c != (u);
9981 + return c != u;
9982 }
9983
9984 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9985 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9986 index a6983b2..63f48a2 100644
9987 --- a/arch/x86/include/asm/bitops.h
9988 +++ b/arch/x86/include/asm/bitops.h
9989 @@ -40,7 +40,7 @@
9990 * a mask operation on a byte.
9991 */
9992 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9993 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9994 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9995 #define CONST_MASK(nr) (1 << ((nr) & 7))
9996
9997 /**
9998 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9999 index b13fe63..0dab13a 100644
10000 --- a/arch/x86/include/asm/boot.h
10001 +++ b/arch/x86/include/asm/boot.h
10002 @@ -11,10 +11,15 @@
10003 #include <asm/pgtable_types.h>
10004
10005 /* Physical address where kernel should be loaded. */
10006 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10007 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10008 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10009 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10010
10011 +#ifndef __ASSEMBLY__
10012 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10013 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10014 +#endif
10015 +
10016 /* Minimum kernel alignment, as a power of two */
10017 #ifdef CONFIG_X86_64
10018 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10019 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10020 index 48f99f1..d78ebf9 100644
10021 --- a/arch/x86/include/asm/cache.h
10022 +++ b/arch/x86/include/asm/cache.h
10023 @@ -5,12 +5,13 @@
10024
10025 /* L1 cache line size */
10026 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10027 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10028 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10029
10030 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10031 +#define __read_only __attribute__((__section__(".data..read_only")))
10032
10033 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10034 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10035 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10036
10037 #ifdef CONFIG_X86_VSMP
10038 #ifdef CONFIG_SMP
10039 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10040 index 9863ee3..4a1f8e1 100644
10041 --- a/arch/x86/include/asm/cacheflush.h
10042 +++ b/arch/x86/include/asm/cacheflush.h
10043 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10044 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10045
10046 if (pg_flags == _PGMT_DEFAULT)
10047 - return -1;
10048 + return ~0UL;
10049 else if (pg_flags == _PGMT_WC)
10050 return _PAGE_CACHE_WC;
10051 else if (pg_flags == _PGMT_UC_MINUS)
10052 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10053 index 46fc474..b02b0f9 100644
10054 --- a/arch/x86/include/asm/checksum_32.h
10055 +++ b/arch/x86/include/asm/checksum_32.h
10056 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10057 int len, __wsum sum,
10058 int *src_err_ptr, int *dst_err_ptr);
10059
10060 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10061 + int len, __wsum sum,
10062 + int *src_err_ptr, int *dst_err_ptr);
10063 +
10064 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10065 + int len, __wsum sum,
10066 + int *src_err_ptr, int *dst_err_ptr);
10067 +
10068 /*
10069 * Note: when you get a NULL pointer exception here this means someone
10070 * passed in an incorrect kernel address to one of these functions.
10071 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10072 int *err_ptr)
10073 {
10074 might_sleep();
10075 - return csum_partial_copy_generic((__force void *)src, dst,
10076 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10077 len, sum, err_ptr, NULL);
10078 }
10079
10080 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10081 {
10082 might_sleep();
10083 if (access_ok(VERIFY_WRITE, dst, len))
10084 - return csum_partial_copy_generic(src, (__force void *)dst,
10085 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10086 len, sum, NULL, err_ptr);
10087
10088 if (len)
10089 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10090 index 99480e5..d81165b 100644
10091 --- a/arch/x86/include/asm/cmpxchg.h
10092 +++ b/arch/x86/include/asm/cmpxchg.h
10093 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10094 __compiletime_error("Bad argument size for cmpxchg");
10095 extern void __xadd_wrong_size(void)
10096 __compiletime_error("Bad argument size for xadd");
10097 +extern void __xadd_check_overflow_wrong_size(void)
10098 + __compiletime_error("Bad argument size for xadd_check_overflow");
10099 extern void __add_wrong_size(void)
10100 __compiletime_error("Bad argument size for add");
10101 +extern void __add_check_overflow_wrong_size(void)
10102 + __compiletime_error("Bad argument size for add_check_overflow");
10103
10104 /*
10105 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10106 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10107 __ret; \
10108 })
10109
10110 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10111 + ({ \
10112 + __typeof__ (*(ptr)) __ret = (arg); \
10113 + switch (sizeof(*(ptr))) { \
10114 + case __X86_CASE_L: \
10115 + asm volatile (lock #op "l %0, %1\n" \
10116 + "jno 0f\n" \
10117 + "mov %0,%1\n" \
10118 + "int $4\n0:\n" \
10119 + _ASM_EXTABLE(0b, 0b) \
10120 + : "+r" (__ret), "+m" (*(ptr)) \
10121 + : : "memory", "cc"); \
10122 + break; \
10123 + case __X86_CASE_Q: \
10124 + asm volatile (lock #op "q %q0, %1\n" \
10125 + "jno 0f\n" \
10126 + "mov %0,%1\n" \
10127 + "int $4\n0:\n" \
10128 + _ASM_EXTABLE(0b, 0b) \
10129 + : "+r" (__ret), "+m" (*(ptr)) \
10130 + : : "memory", "cc"); \
10131 + break; \
10132 + default: \
10133 + __ ## op ## _check_overflow_wrong_size(); \
10134 + } \
10135 + __ret; \
10136 + })
10137 +
10138 /*
10139 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10140 * Since this is generally used to protect other memory information, we
10141 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10142 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10143 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10144
10145 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10146 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10147 +
10148 #define __add(ptr, inc, lock) \
10149 ({ \
10150 __typeof__ (*(ptr)) __ret = (inc); \
10151 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10152 index f91e80f..7f9bd27 100644
10153 --- a/arch/x86/include/asm/cpufeature.h
10154 +++ b/arch/x86/include/asm/cpufeature.h
10155 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10156 ".section .discard,\"aw\",@progbits\n"
10157 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10158 ".previous\n"
10159 - ".section .altinstr_replacement,\"ax\"\n"
10160 + ".section .altinstr_replacement,\"a\"\n"
10161 "3: movb $1,%0\n"
10162 "4:\n"
10163 ".previous\n"
10164 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10165 index 8bf1c06..f723dfd 100644
10166 --- a/arch/x86/include/asm/desc.h
10167 +++ b/arch/x86/include/asm/desc.h
10168 @@ -4,6 +4,7 @@
10169 #include <asm/desc_defs.h>
10170 #include <asm/ldt.h>
10171 #include <asm/mmu.h>
10172 +#include <asm/pgtable.h>
10173
10174 #include <linux/smp.h>
10175 #include <linux/percpu.h>
10176 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10177
10178 desc->type = (info->read_exec_only ^ 1) << 1;
10179 desc->type |= info->contents << 2;
10180 + desc->type |= info->seg_not_present ^ 1;
10181
10182 desc->s = 1;
10183 desc->dpl = 0x3;
10184 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10185 }
10186
10187 extern struct desc_ptr idt_descr;
10188 -extern gate_desc idt_table[];
10189 extern struct desc_ptr nmi_idt_descr;
10190 -extern gate_desc nmi_idt_table[];
10191 -
10192 -struct gdt_page {
10193 - struct desc_struct gdt[GDT_ENTRIES];
10194 -} __attribute__((aligned(PAGE_SIZE)));
10195 -
10196 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10197 +extern gate_desc idt_table[256];
10198 +extern gate_desc nmi_idt_table[256];
10199
10200 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10201 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10202 {
10203 - return per_cpu(gdt_page, cpu).gdt;
10204 + return cpu_gdt_table[cpu];
10205 }
10206
10207 #ifdef CONFIG_X86_64
10208 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10209 unsigned long base, unsigned dpl, unsigned flags,
10210 unsigned short seg)
10211 {
10212 - gate->a = (seg << 16) | (base & 0xffff);
10213 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10214 + gate->gate.offset_low = base;
10215 + gate->gate.seg = seg;
10216 + gate->gate.reserved = 0;
10217 + gate->gate.type = type;
10218 + gate->gate.s = 0;
10219 + gate->gate.dpl = dpl;
10220 + gate->gate.p = 1;
10221 + gate->gate.offset_high = base >> 16;
10222 }
10223
10224 #endif
10225 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10226
10227 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10228 {
10229 + pax_open_kernel();
10230 memcpy(&idt[entry], gate, sizeof(*gate));
10231 + pax_close_kernel();
10232 }
10233
10234 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10235 {
10236 + pax_open_kernel();
10237 memcpy(&ldt[entry], desc, 8);
10238 + pax_close_kernel();
10239 }
10240
10241 static inline void
10242 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10243 default: size = sizeof(*gdt); break;
10244 }
10245
10246 + pax_open_kernel();
10247 memcpy(&gdt[entry], desc, size);
10248 + pax_close_kernel();
10249 }
10250
10251 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10252 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10253
10254 static inline void native_load_tr_desc(void)
10255 {
10256 + pax_open_kernel();
10257 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10258 + pax_close_kernel();
10259 }
10260
10261 static inline void native_load_gdt(const struct desc_ptr *dtr)
10262 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10263 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10264 unsigned int i;
10265
10266 + pax_open_kernel();
10267 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10268 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10269 + pax_close_kernel();
10270 }
10271
10272 #define _LDT_empty(info) \
10273 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10274 }
10275
10276 #ifdef CONFIG_X86_64
10277 -static inline void set_nmi_gate(int gate, void *addr)
10278 +static inline void set_nmi_gate(int gate, const void *addr)
10279 {
10280 gate_desc s;
10281
10282 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10283 }
10284 #endif
10285
10286 -static inline void _set_gate(int gate, unsigned type, void *addr,
10287 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10288 unsigned dpl, unsigned ist, unsigned seg)
10289 {
10290 gate_desc s;
10291 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10292 * Pentium F0 0F bugfix can have resulted in the mapped
10293 * IDT being write-protected.
10294 */
10295 -static inline void set_intr_gate(unsigned int n, void *addr)
10296 +static inline void set_intr_gate(unsigned int n, const void *addr)
10297 {
10298 BUG_ON((unsigned)n > 0xFF);
10299 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10300 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10301 /*
10302 * This routine sets up an interrupt gate at directory privilege level 3.
10303 */
10304 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10305 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10306 {
10307 BUG_ON((unsigned)n > 0xFF);
10308 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10309 }
10310
10311 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10312 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10313 {
10314 BUG_ON((unsigned)n > 0xFF);
10315 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10316 }
10317
10318 -static inline void set_trap_gate(unsigned int n, void *addr)
10319 +static inline void set_trap_gate(unsigned int n, const void *addr)
10320 {
10321 BUG_ON((unsigned)n > 0xFF);
10322 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10323 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10324 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10325 {
10326 BUG_ON((unsigned)n > 0xFF);
10327 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10328 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10329 }
10330
10331 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10332 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10333 {
10334 BUG_ON((unsigned)n > 0xFF);
10335 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10336 }
10337
10338 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10339 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10340 {
10341 BUG_ON((unsigned)n > 0xFF);
10342 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10343 }
10344
10345 +#ifdef CONFIG_X86_32
10346 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10347 +{
10348 + struct desc_struct d;
10349 +
10350 + if (likely(limit))
10351 + limit = (limit - 1UL) >> PAGE_SHIFT;
10352 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10353 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10354 +}
10355 +#endif
10356 +
10357 #endif /* _ASM_X86_DESC_H */
10358 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10359 index 278441f..b95a174 100644
10360 --- a/arch/x86/include/asm/desc_defs.h
10361 +++ b/arch/x86/include/asm/desc_defs.h
10362 @@ -31,6 +31,12 @@ struct desc_struct {
10363 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10364 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10365 };
10366 + struct {
10367 + u16 offset_low;
10368 + u16 seg;
10369 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10370 + unsigned offset_high: 16;
10371 + } gate;
10372 };
10373 } __attribute__((packed));
10374
10375 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10376 index 3778256..c5d4fce 100644
10377 --- a/arch/x86/include/asm/e820.h
10378 +++ b/arch/x86/include/asm/e820.h
10379 @@ -69,7 +69,7 @@ struct e820map {
10380 #define ISA_START_ADDRESS 0xa0000
10381 #define ISA_END_ADDRESS 0x100000
10382
10383 -#define BIOS_BEGIN 0x000a0000
10384 +#define BIOS_BEGIN 0x000c0000
10385 #define BIOS_END 0x00100000
10386
10387 #define BIOS_ROM_BASE 0xffe00000
10388 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10389 index 5939f44..f8845f6 100644
10390 --- a/arch/x86/include/asm/elf.h
10391 +++ b/arch/x86/include/asm/elf.h
10392 @@ -243,7 +243,25 @@ extern int force_personality32;
10393 the loader. We need to make sure that it is out of the way of the program
10394 that it will "exec", and that there is sufficient room for the brk. */
10395
10396 +#ifdef CONFIG_PAX_SEGMEXEC
10397 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10398 +#else
10399 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10400 +#endif
10401 +
10402 +#ifdef CONFIG_PAX_ASLR
10403 +#ifdef CONFIG_X86_32
10404 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10405 +
10406 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10407 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10408 +#else
10409 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10410 +
10411 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10412 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10413 +#endif
10414 +#endif
10415
10416 /* This yields a mask that user programs can use to figure out what
10417 instruction set this CPU supports. This could be done in user space,
10418 @@ -296,16 +314,12 @@ do { \
10419
10420 #define ARCH_DLINFO \
10421 do { \
10422 - if (vdso_enabled) \
10423 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10424 - (unsigned long)current->mm->context.vdso); \
10425 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10426 } while (0)
10427
10428 #define ARCH_DLINFO_X32 \
10429 do { \
10430 - if (vdso_enabled) \
10431 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10432 - (unsigned long)current->mm->context.vdso); \
10433 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10434 } while (0)
10435
10436 #define AT_SYSINFO 32
10437 @@ -320,7 +334,7 @@ else \
10438
10439 #endif /* !CONFIG_X86_32 */
10440
10441 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10442 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10443
10444 #define VDSO_ENTRY \
10445 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10446 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10447 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10448 #define compat_arch_setup_additional_pages syscall32_setup_pages
10449
10450 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10451 -#define arch_randomize_brk arch_randomize_brk
10452 -
10453 /*
10454 * True on X86_32 or when emulating IA32 on X86_64
10455 */
10456 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10457 index cc70c1c..d96d011 100644
10458 --- a/arch/x86/include/asm/emergency-restart.h
10459 +++ b/arch/x86/include/asm/emergency-restart.h
10460 @@ -15,6 +15,6 @@ enum reboot_type {
10461
10462 extern enum reboot_type reboot_type;
10463
10464 -extern void machine_emergency_restart(void);
10465 +extern void machine_emergency_restart(void) __noreturn;
10466
10467 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10468 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10469 index 75f4c6d..ee3eb8f 100644
10470 --- a/arch/x86/include/asm/fpu-internal.h
10471 +++ b/arch/x86/include/asm/fpu-internal.h
10472 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10473 {
10474 int err;
10475
10476 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10477 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10478 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10479 +#endif
10480 +
10481 /* See comment in fxsave() below. */
10482 #ifdef CONFIG_AS_FXSAVEQ
10483 asm volatile("1: fxrstorq %[fx]\n\t"
10484 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10485 {
10486 int err;
10487
10488 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10489 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10490 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10491 +#endif
10492 +
10493 /*
10494 * Clear the bytes not touched by the fxsave and reserved
10495 * for the SW usage.
10496 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10497 "emms\n\t" /* clear stack tags */
10498 "fildl %P[addr]", /* set F?P to defined value */
10499 X86_FEATURE_FXSAVE_LEAK,
10500 - [addr] "m" (tsk->thread.fpu.has_fpu));
10501 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10502
10503 return fpu_restore_checking(&tsk->thread.fpu);
10504 }
10505 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10506 index 71ecbcb..bac10b7 100644
10507 --- a/arch/x86/include/asm/futex.h
10508 +++ b/arch/x86/include/asm/futex.h
10509 @@ -11,16 +11,18 @@
10510 #include <asm/processor.h>
10511
10512 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10513 + typecheck(u32 __user *, uaddr); \
10514 asm volatile("1:\t" insn "\n" \
10515 "2:\t.section .fixup,\"ax\"\n" \
10516 "3:\tmov\t%3, %1\n" \
10517 "\tjmp\t2b\n" \
10518 "\t.previous\n" \
10519 _ASM_EXTABLE(1b, 3b) \
10520 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10521 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10522 : "i" (-EFAULT), "0" (oparg), "1" (0))
10523
10524 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10525 + typecheck(u32 __user *, uaddr); \
10526 asm volatile("1:\tmovl %2, %0\n" \
10527 "\tmovl\t%0, %3\n" \
10528 "\t" insn "\n" \
10529 @@ -33,7 +35,7 @@
10530 _ASM_EXTABLE(1b, 4b) \
10531 _ASM_EXTABLE(2b, 4b) \
10532 : "=&a" (oldval), "=&r" (ret), \
10533 - "+m" (*uaddr), "=&r" (tem) \
10534 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10535 : "r" (oparg), "i" (-EFAULT), "1" (0))
10536
10537 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10538 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10539
10540 switch (op) {
10541 case FUTEX_OP_SET:
10542 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10543 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10544 break;
10545 case FUTEX_OP_ADD:
10546 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10547 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10548 uaddr, oparg);
10549 break;
10550 case FUTEX_OP_OR:
10551 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10552 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10553 return -EFAULT;
10554
10555 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10556 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10557 "2:\t.section .fixup, \"ax\"\n"
10558 "3:\tmov %3, %0\n"
10559 "\tjmp 2b\n"
10560 "\t.previous\n"
10561 _ASM_EXTABLE(1b, 3b)
10562 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10563 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10564 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10565 : "memory"
10566 );
10567 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10568 index eb92a6e..b98b2f4 100644
10569 --- a/arch/x86/include/asm/hw_irq.h
10570 +++ b/arch/x86/include/asm/hw_irq.h
10571 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10572 extern void enable_IO_APIC(void);
10573
10574 /* Statistics */
10575 -extern atomic_t irq_err_count;
10576 -extern atomic_t irq_mis_count;
10577 +extern atomic_unchecked_t irq_err_count;
10578 +extern atomic_unchecked_t irq_mis_count;
10579
10580 /* EISA */
10581 extern void eisa_set_level_irq(unsigned int irq);
10582 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10583 index d8e8eef..99f81ae 100644
10584 --- a/arch/x86/include/asm/io.h
10585 +++ b/arch/x86/include/asm/io.h
10586 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10587
10588 #include <linux/vmalloc.h>
10589
10590 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10591 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10592 +{
10593 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10594 +}
10595 +
10596 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10597 +{
10598 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10599 +}
10600 +
10601 /*
10602 * Convert a virtual cached pointer to an uncached pointer
10603 */
10604 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10605 index bba3cf8..06bc8da 100644
10606 --- a/arch/x86/include/asm/irqflags.h
10607 +++ b/arch/x86/include/asm/irqflags.h
10608 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10609 sti; \
10610 sysexit
10611
10612 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10613 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10614 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10615 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10616 +
10617 #else
10618 #define INTERRUPT_RETURN iret
10619 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10620 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10621 index 5478825..839e88c 100644
10622 --- a/arch/x86/include/asm/kprobes.h
10623 +++ b/arch/x86/include/asm/kprobes.h
10624 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10625 #define RELATIVEJUMP_SIZE 5
10626 #define RELATIVECALL_OPCODE 0xe8
10627 #define RELATIVE_ADDR_SIZE 4
10628 -#define MAX_STACK_SIZE 64
10629 -#define MIN_STACK_SIZE(ADDR) \
10630 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10631 - THREAD_SIZE - (unsigned long)(ADDR))) \
10632 - ? (MAX_STACK_SIZE) \
10633 - : (((unsigned long)current_thread_info()) + \
10634 - THREAD_SIZE - (unsigned long)(ADDR)))
10635 +#define MAX_STACK_SIZE 64UL
10636 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10637
10638 #define flush_insn_slot(p) do { } while (0)
10639
10640 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10641 index db7c1f2..92f130a 100644
10642 --- a/arch/x86/include/asm/kvm_host.h
10643 +++ b/arch/x86/include/asm/kvm_host.h
10644 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10645 int (*check_intercept)(struct kvm_vcpu *vcpu,
10646 struct x86_instruction_info *info,
10647 enum x86_intercept_stage stage);
10648 -};
10649 +} __do_const;
10650
10651 struct kvm_arch_async_pf {
10652 u32 token;
10653 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10654 index c8bed0d..e5721fa 100644
10655 --- a/arch/x86/include/asm/local.h
10656 +++ b/arch/x86/include/asm/local.h
10657 @@ -17,26 +17,58 @@ typedef struct {
10658
10659 static inline void local_inc(local_t *l)
10660 {
10661 - asm volatile(_ASM_INC "%0"
10662 + asm volatile(_ASM_INC "%0\n"
10663 +
10664 +#ifdef CONFIG_PAX_REFCOUNT
10665 + "jno 0f\n"
10666 + _ASM_DEC "%0\n"
10667 + "int $4\n0:\n"
10668 + _ASM_EXTABLE(0b, 0b)
10669 +#endif
10670 +
10671 : "+m" (l->a.counter));
10672 }
10673
10674 static inline void local_dec(local_t *l)
10675 {
10676 - asm volatile(_ASM_DEC "%0"
10677 + asm volatile(_ASM_DEC "%0\n"
10678 +
10679 +#ifdef CONFIG_PAX_REFCOUNT
10680 + "jno 0f\n"
10681 + _ASM_INC "%0\n"
10682 + "int $4\n0:\n"
10683 + _ASM_EXTABLE(0b, 0b)
10684 +#endif
10685 +
10686 : "+m" (l->a.counter));
10687 }
10688
10689 static inline void local_add(long i, local_t *l)
10690 {
10691 - asm volatile(_ASM_ADD "%1,%0"
10692 + asm volatile(_ASM_ADD "%1,%0\n"
10693 +
10694 +#ifdef CONFIG_PAX_REFCOUNT
10695 + "jno 0f\n"
10696 + _ASM_SUB "%1,%0\n"
10697 + "int $4\n0:\n"
10698 + _ASM_EXTABLE(0b, 0b)
10699 +#endif
10700 +
10701 : "+m" (l->a.counter)
10702 : "ir" (i));
10703 }
10704
10705 static inline void local_sub(long i, local_t *l)
10706 {
10707 - asm volatile(_ASM_SUB "%1,%0"
10708 + asm volatile(_ASM_SUB "%1,%0\n"
10709 +
10710 +#ifdef CONFIG_PAX_REFCOUNT
10711 + "jno 0f\n"
10712 + _ASM_ADD "%1,%0\n"
10713 + "int $4\n0:\n"
10714 + _ASM_EXTABLE(0b, 0b)
10715 +#endif
10716 +
10717 : "+m" (l->a.counter)
10718 : "ir" (i));
10719 }
10720 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10721 {
10722 unsigned char c;
10723
10724 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10725 + asm volatile(_ASM_SUB "%2,%0\n"
10726 +
10727 +#ifdef CONFIG_PAX_REFCOUNT
10728 + "jno 0f\n"
10729 + _ASM_ADD "%2,%0\n"
10730 + "int $4\n0:\n"
10731 + _ASM_EXTABLE(0b, 0b)
10732 +#endif
10733 +
10734 + "sete %1\n"
10735 : "+m" (l->a.counter), "=qm" (c)
10736 : "ir" (i) : "memory");
10737 return c;
10738 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10739 {
10740 unsigned char c;
10741
10742 - asm volatile(_ASM_DEC "%0; sete %1"
10743 + asm volatile(_ASM_DEC "%0\n"
10744 +
10745 +#ifdef CONFIG_PAX_REFCOUNT
10746 + "jno 0f\n"
10747 + _ASM_INC "%0\n"
10748 + "int $4\n0:\n"
10749 + _ASM_EXTABLE(0b, 0b)
10750 +#endif
10751 +
10752 + "sete %1\n"
10753 : "+m" (l->a.counter), "=qm" (c)
10754 : : "memory");
10755 return c != 0;
10756 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10757 {
10758 unsigned char c;
10759
10760 - asm volatile(_ASM_INC "%0; sete %1"
10761 + asm volatile(_ASM_INC "%0\n"
10762 +
10763 +#ifdef CONFIG_PAX_REFCOUNT
10764 + "jno 0f\n"
10765 + _ASM_DEC "%0\n"
10766 + "int $4\n0:\n"
10767 + _ASM_EXTABLE(0b, 0b)
10768 +#endif
10769 +
10770 + "sete %1\n"
10771 : "+m" (l->a.counter), "=qm" (c)
10772 : : "memory");
10773 return c != 0;
10774 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10775 {
10776 unsigned char c;
10777
10778 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10779 + asm volatile(_ASM_ADD "%2,%0\n"
10780 +
10781 +#ifdef CONFIG_PAX_REFCOUNT
10782 + "jno 0f\n"
10783 + _ASM_SUB "%2,%0\n"
10784 + "int $4\n0:\n"
10785 + _ASM_EXTABLE(0b, 0b)
10786 +#endif
10787 +
10788 + "sets %1\n"
10789 : "+m" (l->a.counter), "=qm" (c)
10790 : "ir" (i) : "memory");
10791 return c;
10792 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10793 #endif
10794 /* Modern 486+ processor */
10795 __i = i;
10796 - asm volatile(_ASM_XADD "%0, %1;"
10797 + asm volatile(_ASM_XADD "%0, %1\n"
10798 +
10799 +#ifdef CONFIG_PAX_REFCOUNT
10800 + "jno 0f\n"
10801 + _ASM_MOV "%0,%1\n"
10802 + "int $4\n0:\n"
10803 + _ASM_EXTABLE(0b, 0b)
10804 +#endif
10805 +
10806 : "+r" (i), "+m" (l->a.counter)
10807 : : "memory");
10808 return i + __i;
10809 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10810 index 593e51d..fa69c9a 100644
10811 --- a/arch/x86/include/asm/mman.h
10812 +++ b/arch/x86/include/asm/mman.h
10813 @@ -5,4 +5,14 @@
10814
10815 #include <asm-generic/mman.h>
10816
10817 +#ifdef __KERNEL__
10818 +#ifndef __ASSEMBLY__
10819 +#ifdef CONFIG_X86_32
10820 +#define arch_mmap_check i386_mmap_check
10821 +int i386_mmap_check(unsigned long addr, unsigned long len,
10822 + unsigned long flags);
10823 +#endif
10824 +#endif
10825 +#endif
10826 +
10827 #endif /* _ASM_X86_MMAN_H */
10828 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10829 index 5f55e69..e20bfb1 100644
10830 --- a/arch/x86/include/asm/mmu.h
10831 +++ b/arch/x86/include/asm/mmu.h
10832 @@ -9,7 +9,7 @@
10833 * we put the segment information here.
10834 */
10835 typedef struct {
10836 - void *ldt;
10837 + struct desc_struct *ldt;
10838 int size;
10839
10840 #ifdef CONFIG_X86_64
10841 @@ -18,7 +18,19 @@ typedef struct {
10842 #endif
10843
10844 struct mutex lock;
10845 - void *vdso;
10846 + unsigned long vdso;
10847 +
10848 +#ifdef CONFIG_X86_32
10849 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10850 + unsigned long user_cs_base;
10851 + unsigned long user_cs_limit;
10852 +
10853 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10854 + cpumask_t cpu_user_cs_mask;
10855 +#endif
10856 +
10857 +#endif
10858 +#endif
10859 } mm_context_t;
10860
10861 #ifdef CONFIG_SMP
10862 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10863 index cdbf367..adb37ac 100644
10864 --- a/arch/x86/include/asm/mmu_context.h
10865 +++ b/arch/x86/include/asm/mmu_context.h
10866 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10867
10868 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10869 {
10870 +
10871 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10872 + unsigned int i;
10873 + pgd_t *pgd;
10874 +
10875 + pax_open_kernel();
10876 + pgd = get_cpu_pgd(smp_processor_id());
10877 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10878 + set_pgd_batched(pgd+i, native_make_pgd(0));
10879 + pax_close_kernel();
10880 +#endif
10881 +
10882 #ifdef CONFIG_SMP
10883 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10884 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10885 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10886 struct task_struct *tsk)
10887 {
10888 unsigned cpu = smp_processor_id();
10889 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10890 + int tlbstate = TLBSTATE_OK;
10891 +#endif
10892
10893 if (likely(prev != next)) {
10894 #ifdef CONFIG_SMP
10895 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10896 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10897 +#endif
10898 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10899 this_cpu_write(cpu_tlbstate.active_mm, next);
10900 #endif
10901 cpumask_set_cpu(cpu, mm_cpumask(next));
10902
10903 /* Re-load page tables */
10904 +#ifdef CONFIG_PAX_PER_CPU_PGD
10905 + pax_open_kernel();
10906 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10907 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10908 + pax_close_kernel();
10909 + load_cr3(get_cpu_pgd(cpu));
10910 +#else
10911 load_cr3(next->pgd);
10912 +#endif
10913
10914 /* stop flush ipis for the previous mm */
10915 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10916 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10917 */
10918 if (unlikely(prev->context.ldt != next->context.ldt))
10919 load_LDT_nolock(&next->context);
10920 - }
10921 +
10922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10923 + if (!(__supported_pte_mask & _PAGE_NX)) {
10924 + smp_mb__before_clear_bit();
10925 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10926 + smp_mb__after_clear_bit();
10927 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10928 + }
10929 +#endif
10930 +
10931 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10932 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10933 + prev->context.user_cs_limit != next->context.user_cs_limit))
10934 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10935 #ifdef CONFIG_SMP
10936 + else if (unlikely(tlbstate != TLBSTATE_OK))
10937 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10938 +#endif
10939 +#endif
10940 +
10941 + }
10942 else {
10943 +
10944 +#ifdef CONFIG_PAX_PER_CPU_PGD
10945 + pax_open_kernel();
10946 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10947 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10948 + pax_close_kernel();
10949 + load_cr3(get_cpu_pgd(cpu));
10950 +#endif
10951 +
10952 +#ifdef CONFIG_SMP
10953 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10954 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10955
10956 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10957 * tlb flush IPI delivery. We must reload CR3
10958 * to make sure to use no freed page tables.
10959 */
10960 +
10961 +#ifndef CONFIG_PAX_PER_CPU_PGD
10962 load_cr3(next->pgd);
10963 +#endif
10964 +
10965 load_LDT_nolock(&next->context);
10966 +
10967 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10968 + if (!(__supported_pte_mask & _PAGE_NX))
10969 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10970 +#endif
10971 +
10972 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10973 +#ifdef CONFIG_PAX_PAGEEXEC
10974 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10975 +#endif
10976 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10977 +#endif
10978 +
10979 }
10980 +#endif
10981 }
10982 -#endif
10983 }
10984
10985 #define activate_mm(prev, next) \
10986 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10987 index 9eae775..c914fea 100644
10988 --- a/arch/x86/include/asm/module.h
10989 +++ b/arch/x86/include/asm/module.h
10990 @@ -5,6 +5,7 @@
10991
10992 #ifdef CONFIG_X86_64
10993 /* X86_64 does not define MODULE_PROC_FAMILY */
10994 +#define MODULE_PROC_FAMILY ""
10995 #elif defined CONFIG_M386
10996 #define MODULE_PROC_FAMILY "386 "
10997 #elif defined CONFIG_M486
10998 @@ -59,8 +60,20 @@
10999 #error unknown processor family
11000 #endif
11001
11002 -#ifdef CONFIG_X86_32
11003 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11004 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11005 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11006 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11007 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11008 +#else
11009 +#define MODULE_PAX_KERNEXEC ""
11010 #endif
11011
11012 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11013 +#define MODULE_PAX_UDEREF "UDEREF "
11014 +#else
11015 +#define MODULE_PAX_UDEREF ""
11016 +#endif
11017 +
11018 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11019 +
11020 #endif /* _ASM_X86_MODULE_H */
11021 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11022 index 320f7bb..e89f8f8 100644
11023 --- a/arch/x86/include/asm/page_64_types.h
11024 +++ b/arch/x86/include/asm/page_64_types.h
11025 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11026
11027 /* duplicated to the one in bootmem.h */
11028 extern unsigned long max_pfn;
11029 -extern unsigned long phys_base;
11030 +extern const unsigned long phys_base;
11031
11032 extern unsigned long __phys_addr(unsigned long);
11033 #define __phys_reloc_hide(x) (x)
11034 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11035 index 6cbbabf..11b3aed 100644
11036 --- a/arch/x86/include/asm/paravirt.h
11037 +++ b/arch/x86/include/asm/paravirt.h
11038 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11039 val);
11040 }
11041
11042 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11043 +{
11044 + pgdval_t val = native_pgd_val(pgd);
11045 +
11046 + if (sizeof(pgdval_t) > sizeof(long))
11047 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11048 + val, (u64)val >> 32);
11049 + else
11050 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11051 + val);
11052 +}
11053 +
11054 static inline void pgd_clear(pgd_t *pgdp)
11055 {
11056 set_pgd(pgdp, __pgd(0));
11057 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11058 pv_mmu_ops.set_fixmap(idx, phys, flags);
11059 }
11060
11061 +#ifdef CONFIG_PAX_KERNEXEC
11062 +static inline unsigned long pax_open_kernel(void)
11063 +{
11064 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11065 +}
11066 +
11067 +static inline unsigned long pax_close_kernel(void)
11068 +{
11069 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11070 +}
11071 +#else
11072 +static inline unsigned long pax_open_kernel(void) { return 0; }
11073 +static inline unsigned long pax_close_kernel(void) { return 0; }
11074 +#endif
11075 +
11076 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11077
11078 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11079 @@ -965,7 +992,7 @@ extern void default_banner(void);
11080
11081 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11082 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11083 -#define PARA_INDIRECT(addr) *%cs:addr
11084 +#define PARA_INDIRECT(addr) *%ss:addr
11085 #endif
11086
11087 #define INTERRUPT_RETURN \
11088 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11089 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11090 CLBR_NONE, \
11091 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11092 +
11093 +#define GET_CR0_INTO_RDI \
11094 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11095 + mov %rax,%rdi
11096 +
11097 +#define SET_RDI_INTO_CR0 \
11098 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11099 +
11100 +#define GET_CR3_INTO_RDI \
11101 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11102 + mov %rax,%rdi
11103 +
11104 +#define SET_RDI_INTO_CR3 \
11105 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11106 +
11107 #endif /* CONFIG_X86_32 */
11108
11109 #endif /* __ASSEMBLY__ */
11110 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11111 index 8e8b9a4..f07d725 100644
11112 --- a/arch/x86/include/asm/paravirt_types.h
11113 +++ b/arch/x86/include/asm/paravirt_types.h
11114 @@ -84,20 +84,20 @@ struct pv_init_ops {
11115 */
11116 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11117 unsigned long addr, unsigned len);
11118 -};
11119 +} __no_const;
11120
11121
11122 struct pv_lazy_ops {
11123 /* Set deferred update mode, used for batching operations. */
11124 void (*enter)(void);
11125 void (*leave)(void);
11126 -};
11127 +} __no_const;
11128
11129 struct pv_time_ops {
11130 unsigned long long (*sched_clock)(void);
11131 unsigned long long (*steal_clock)(int cpu);
11132 unsigned long (*get_tsc_khz)(void);
11133 -};
11134 +} __no_const;
11135
11136 struct pv_cpu_ops {
11137 /* hooks for various privileged instructions */
11138 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11139
11140 void (*start_context_switch)(struct task_struct *prev);
11141 void (*end_context_switch)(struct task_struct *next);
11142 -};
11143 +} __no_const;
11144
11145 struct pv_irq_ops {
11146 /*
11147 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11148 unsigned long start_eip,
11149 unsigned long start_esp);
11150 #endif
11151 -};
11152 +} __no_const;
11153
11154 struct pv_mmu_ops {
11155 unsigned long (*read_cr2)(void);
11156 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11157 struct paravirt_callee_save make_pud;
11158
11159 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11160 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11161 #endif /* PAGETABLE_LEVELS == 4 */
11162 #endif /* PAGETABLE_LEVELS >= 3 */
11163
11164 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11165 an mfn. We can tell which is which from the index. */
11166 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11167 phys_addr_t phys, pgprot_t flags);
11168 +
11169 +#ifdef CONFIG_PAX_KERNEXEC
11170 + unsigned long (*pax_open_kernel)(void);
11171 + unsigned long (*pax_close_kernel)(void);
11172 +#endif
11173 +
11174 };
11175
11176 struct arch_spinlock;
11177 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11178 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11179 int (*spin_trylock)(struct arch_spinlock *lock);
11180 void (*spin_unlock)(struct arch_spinlock *lock);
11181 -};
11182 +} __no_const;
11183
11184 /* This contains all the paravirt structures: we get a convenient
11185 * number for each function using the offset which we use to indicate
11186 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11187 index b4389a4..7024269 100644
11188 --- a/arch/x86/include/asm/pgalloc.h
11189 +++ b/arch/x86/include/asm/pgalloc.h
11190 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11191 pmd_t *pmd, pte_t *pte)
11192 {
11193 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11194 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11195 +}
11196 +
11197 +static inline void pmd_populate_user(struct mm_struct *mm,
11198 + pmd_t *pmd, pte_t *pte)
11199 +{
11200 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11201 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11202 }
11203
11204 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11205
11206 #ifdef CONFIG_X86_PAE
11207 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11208 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11209 +{
11210 + pud_populate(mm, pudp, pmd);
11211 +}
11212 #else /* !CONFIG_X86_PAE */
11213 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11214 {
11215 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11216 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11217 }
11218 +
11219 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11220 +{
11221 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11222 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11223 +}
11224 #endif /* CONFIG_X86_PAE */
11225
11226 #if PAGETABLE_LEVELS > 3
11227 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11228 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11229 }
11230
11231 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11232 +{
11233 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11234 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11235 +}
11236 +
11237 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11238 {
11239 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11240 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11241 index 98391db..8f6984e 100644
11242 --- a/arch/x86/include/asm/pgtable-2level.h
11243 +++ b/arch/x86/include/asm/pgtable-2level.h
11244 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11245
11246 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11247 {
11248 + pax_open_kernel();
11249 *pmdp = pmd;
11250 + pax_close_kernel();
11251 }
11252
11253 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11254 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11255 index cb00ccc..17e9054 100644
11256 --- a/arch/x86/include/asm/pgtable-3level.h
11257 +++ b/arch/x86/include/asm/pgtable-3level.h
11258 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11259
11260 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11261 {
11262 + pax_open_kernel();
11263 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11264 + pax_close_kernel();
11265 }
11266
11267 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11268 {
11269 + pax_open_kernel();
11270 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11271 + pax_close_kernel();
11272 }
11273
11274 /*
11275 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11276 index 49afb3f..91a8c63 100644
11277 --- a/arch/x86/include/asm/pgtable.h
11278 +++ b/arch/x86/include/asm/pgtable.h
11279 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11280
11281 #ifndef __PAGETABLE_PUD_FOLDED
11282 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11283 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11284 #define pgd_clear(pgd) native_pgd_clear(pgd)
11285 #endif
11286
11287 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11288
11289 #define arch_end_context_switch(prev) do {} while(0)
11290
11291 +#define pax_open_kernel() native_pax_open_kernel()
11292 +#define pax_close_kernel() native_pax_close_kernel()
11293 #endif /* CONFIG_PARAVIRT */
11294
11295 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11296 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11297 +
11298 +#ifdef CONFIG_PAX_KERNEXEC
11299 +static inline unsigned long native_pax_open_kernel(void)
11300 +{
11301 + unsigned long cr0;
11302 +
11303 + preempt_disable();
11304 + barrier();
11305 + cr0 = read_cr0() ^ X86_CR0_WP;
11306 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11307 + write_cr0(cr0);
11308 + return cr0 ^ X86_CR0_WP;
11309 +}
11310 +
11311 +static inline unsigned long native_pax_close_kernel(void)
11312 +{
11313 + unsigned long cr0;
11314 +
11315 + cr0 = read_cr0() ^ X86_CR0_WP;
11316 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11317 + write_cr0(cr0);
11318 + barrier();
11319 + preempt_enable_no_resched();
11320 + return cr0 ^ X86_CR0_WP;
11321 +}
11322 +#else
11323 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11324 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11325 +#endif
11326 +
11327 /*
11328 * The following only work if pte_present() is true.
11329 * Undefined behaviour if not..
11330 */
11331 +static inline int pte_user(pte_t pte)
11332 +{
11333 + return pte_val(pte) & _PAGE_USER;
11334 +}
11335 +
11336 static inline int pte_dirty(pte_t pte)
11337 {
11338 return pte_flags(pte) & _PAGE_DIRTY;
11339 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11340 return pte_clear_flags(pte, _PAGE_RW);
11341 }
11342
11343 +static inline pte_t pte_mkread(pte_t pte)
11344 +{
11345 + return __pte(pte_val(pte) | _PAGE_USER);
11346 +}
11347 +
11348 static inline pte_t pte_mkexec(pte_t pte)
11349 {
11350 - return pte_clear_flags(pte, _PAGE_NX);
11351 +#ifdef CONFIG_X86_PAE
11352 + if (__supported_pte_mask & _PAGE_NX)
11353 + return pte_clear_flags(pte, _PAGE_NX);
11354 + else
11355 +#endif
11356 + return pte_set_flags(pte, _PAGE_USER);
11357 +}
11358 +
11359 +static inline pte_t pte_exprotect(pte_t pte)
11360 +{
11361 +#ifdef CONFIG_X86_PAE
11362 + if (__supported_pte_mask & _PAGE_NX)
11363 + return pte_set_flags(pte, _PAGE_NX);
11364 + else
11365 +#endif
11366 + return pte_clear_flags(pte, _PAGE_USER);
11367 }
11368
11369 static inline pte_t pte_mkdirty(pte_t pte)
11370 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11371 #endif
11372
11373 #ifndef __ASSEMBLY__
11374 +
11375 +#ifdef CONFIG_PAX_PER_CPU_PGD
11376 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11377 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11378 +{
11379 + return cpu_pgd[cpu];
11380 +}
11381 +#endif
11382 +
11383 #include <linux/mm_types.h>
11384
11385 static inline int pte_none(pte_t pte)
11386 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11387
11388 static inline int pgd_bad(pgd_t pgd)
11389 {
11390 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11391 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11392 }
11393
11394 static inline int pgd_none(pgd_t pgd)
11395 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11396 * pgd_offset() returns a (pgd_t *)
11397 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11398 */
11399 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11400 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11401 +
11402 +#ifdef CONFIG_PAX_PER_CPU_PGD
11403 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11404 +#endif
11405 +
11406 /*
11407 * a shortcut which implies the use of the kernel's pgd, instead
11408 * of a process's
11409 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11410 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11411 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11412
11413 +#ifdef CONFIG_X86_32
11414 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11415 +#else
11416 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11417 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11418 +
11419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11420 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11421 +#else
11422 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11423 +#endif
11424 +
11425 +#endif
11426 +
11427 #ifndef __ASSEMBLY__
11428
11429 extern int direct_gbpages;
11430 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11431 * dst and src can be on the same page, but the range must not overlap,
11432 * and must not cross a page boundary.
11433 */
11434 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11435 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11436 {
11437 - memcpy(dst, src, count * sizeof(pgd_t));
11438 + pax_open_kernel();
11439 + while (count--)
11440 + *dst++ = *src++;
11441 + pax_close_kernel();
11442 }
11443
11444 +#ifdef CONFIG_PAX_PER_CPU_PGD
11445 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11446 +#endif
11447 +
11448 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11449 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11450 +#else
11451 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11452 +#endif
11453
11454 #include <asm-generic/pgtable.h>
11455 #endif /* __ASSEMBLY__ */
11456 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11457 index 0c92113..34a77c6 100644
11458 --- a/arch/x86/include/asm/pgtable_32.h
11459 +++ b/arch/x86/include/asm/pgtable_32.h
11460 @@ -25,9 +25,6 @@
11461 struct mm_struct;
11462 struct vm_area_struct;
11463
11464 -extern pgd_t swapper_pg_dir[1024];
11465 -extern pgd_t initial_page_table[1024];
11466 -
11467 static inline void pgtable_cache_init(void) { }
11468 static inline void check_pgt_cache(void) { }
11469 void paging_init(void);
11470 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11471 # include <asm/pgtable-2level.h>
11472 #endif
11473
11474 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11475 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11476 +#ifdef CONFIG_X86_PAE
11477 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11478 +#endif
11479 +
11480 #if defined(CONFIG_HIGHPTE)
11481 #define pte_offset_map(dir, address) \
11482 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11483 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11484 /* Clear a kernel PTE and flush it from the TLB */
11485 #define kpte_clear_flush(ptep, vaddr) \
11486 do { \
11487 + pax_open_kernel(); \
11488 pte_clear(&init_mm, (vaddr), (ptep)); \
11489 + pax_close_kernel(); \
11490 __flush_tlb_one((vaddr)); \
11491 } while (0)
11492
11493 @@ -74,6 +79,9 @@ do { \
11494
11495 #endif /* !__ASSEMBLY__ */
11496
11497 +#define HAVE_ARCH_UNMAPPED_AREA
11498 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11499 +
11500 /*
11501 * kern_addr_valid() is (1) for FLATMEM and (0) for
11502 * SPARSEMEM and DISCONTIGMEM
11503 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11504 index ed5903b..c7fe163 100644
11505 --- a/arch/x86/include/asm/pgtable_32_types.h
11506 +++ b/arch/x86/include/asm/pgtable_32_types.h
11507 @@ -8,7 +8,7 @@
11508 */
11509 #ifdef CONFIG_X86_PAE
11510 # include <asm/pgtable-3level_types.h>
11511 -# define PMD_SIZE (1UL << PMD_SHIFT)
11512 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11513 # define PMD_MASK (~(PMD_SIZE - 1))
11514 #else
11515 # include <asm/pgtable-2level_types.h>
11516 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11517 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11518 #endif
11519
11520 +#ifdef CONFIG_PAX_KERNEXEC
11521 +#ifndef __ASSEMBLY__
11522 +extern unsigned char MODULES_EXEC_VADDR[];
11523 +extern unsigned char MODULES_EXEC_END[];
11524 +#endif
11525 +#include <asm/boot.h>
11526 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11527 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11528 +#else
11529 +#define ktla_ktva(addr) (addr)
11530 +#define ktva_ktla(addr) (addr)
11531 +#endif
11532 +
11533 #define MODULES_VADDR VMALLOC_START
11534 #define MODULES_END VMALLOC_END
11535 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11536 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11537 index 975f709..9f779c9 100644
11538 --- a/arch/x86/include/asm/pgtable_64.h
11539 +++ b/arch/x86/include/asm/pgtable_64.h
11540 @@ -16,10 +16,14 @@
11541
11542 extern pud_t level3_kernel_pgt[512];
11543 extern pud_t level3_ident_pgt[512];
11544 +extern pud_t level3_vmalloc_start_pgt[512];
11545 +extern pud_t level3_vmalloc_end_pgt[512];
11546 +extern pud_t level3_vmemmap_pgt[512];
11547 +extern pud_t level2_vmemmap_pgt[512];
11548 extern pmd_t level2_kernel_pgt[512];
11549 extern pmd_t level2_fixmap_pgt[512];
11550 -extern pmd_t level2_ident_pgt[512];
11551 -extern pgd_t init_level4_pgt[];
11552 +extern pmd_t level2_ident_pgt[512*2];
11553 +extern pgd_t init_level4_pgt[512];
11554
11555 #define swapper_pg_dir init_level4_pgt
11556
11557 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11558
11559 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11560 {
11561 + pax_open_kernel();
11562 *pmdp = pmd;
11563 + pax_close_kernel();
11564 }
11565
11566 static inline void native_pmd_clear(pmd_t *pmd)
11567 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11568
11569 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11570 {
11571 + pax_open_kernel();
11572 *pudp = pud;
11573 + pax_close_kernel();
11574 }
11575
11576 static inline void native_pud_clear(pud_t *pud)
11577 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11578
11579 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11580 {
11581 + pax_open_kernel();
11582 + *pgdp = pgd;
11583 + pax_close_kernel();
11584 +}
11585 +
11586 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11587 +{
11588 *pgdp = pgd;
11589 }
11590
11591 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11592 index 766ea16..5b96cb3 100644
11593 --- a/arch/x86/include/asm/pgtable_64_types.h
11594 +++ b/arch/x86/include/asm/pgtable_64_types.h
11595 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11596 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11597 #define MODULES_END _AC(0xffffffffff000000, UL)
11598 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11599 +#define MODULES_EXEC_VADDR MODULES_VADDR
11600 +#define MODULES_EXEC_END MODULES_END
11601 +
11602 +#define ktla_ktva(addr) (addr)
11603 +#define ktva_ktla(addr) (addr)
11604
11605 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11606 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11607 index 013286a..8b42f4f 100644
11608 --- a/arch/x86/include/asm/pgtable_types.h
11609 +++ b/arch/x86/include/asm/pgtable_types.h
11610 @@ -16,13 +16,12 @@
11611 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11612 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11613 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11614 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11615 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11616 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11617 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11618 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11619 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11620 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11621 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11622 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11623 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11624 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11625
11626 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11627 @@ -40,7 +39,6 @@
11628 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11629 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11630 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11631 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11632 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11633 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11634 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11635 @@ -57,8 +55,10 @@
11636
11637 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11638 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11639 -#else
11640 +#elif defined(CONFIG_KMEMCHECK)
11641 #define _PAGE_NX (_AT(pteval_t, 0))
11642 +#else
11643 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11644 #endif
11645
11646 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11647 @@ -96,6 +96,9 @@
11648 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11649 _PAGE_ACCESSED)
11650
11651 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11652 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11653 +
11654 #define __PAGE_KERNEL_EXEC \
11655 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11656 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11657 @@ -106,7 +109,7 @@
11658 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11659 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11660 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11661 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11662 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11663 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11664 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11665 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11666 @@ -168,8 +171,8 @@
11667 * bits are combined, this will alow user to access the high address mapped
11668 * VDSO in the presence of CONFIG_COMPAT_VDSO
11669 */
11670 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11671 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11672 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11673 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11674 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11675 #endif
11676
11677 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11678 {
11679 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11680 }
11681 +#endif
11682
11683 +#if PAGETABLE_LEVELS == 3
11684 +#include <asm-generic/pgtable-nopud.h>
11685 +#endif
11686 +
11687 +#if PAGETABLE_LEVELS == 2
11688 +#include <asm-generic/pgtable-nopmd.h>
11689 +#endif
11690 +
11691 +#ifndef __ASSEMBLY__
11692 #if PAGETABLE_LEVELS > 3
11693 typedef struct { pudval_t pud; } pud_t;
11694
11695 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11696 return pud.pud;
11697 }
11698 #else
11699 -#include <asm-generic/pgtable-nopud.h>
11700 -
11701 static inline pudval_t native_pud_val(pud_t pud)
11702 {
11703 return native_pgd_val(pud.pgd);
11704 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11705 return pmd.pmd;
11706 }
11707 #else
11708 -#include <asm-generic/pgtable-nopmd.h>
11709 -
11710 static inline pmdval_t native_pmd_val(pmd_t pmd)
11711 {
11712 return native_pgd_val(pmd.pud.pgd);
11713 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11714
11715 extern pteval_t __supported_pte_mask;
11716 extern void set_nx(void);
11717 -extern int nx_enabled;
11718
11719 #define pgprot_writecombine pgprot_writecombine
11720 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11721 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11722 index 39bc577..538233f 100644
11723 --- a/arch/x86/include/asm/processor.h
11724 +++ b/arch/x86/include/asm/processor.h
11725 @@ -276,7 +276,7 @@ struct tss_struct {
11726
11727 } ____cacheline_aligned;
11728
11729 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11730 +extern struct tss_struct init_tss[NR_CPUS];
11731
11732 /*
11733 * Save the original ist values for checking stack pointers during debugging
11734 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11735 */
11736 #define TASK_SIZE PAGE_OFFSET
11737 #define TASK_SIZE_MAX TASK_SIZE
11738 +
11739 +#ifdef CONFIG_PAX_SEGMEXEC
11740 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11741 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11742 +#else
11743 #define STACK_TOP TASK_SIZE
11744 -#define STACK_TOP_MAX STACK_TOP
11745 +#endif
11746 +
11747 +#define STACK_TOP_MAX TASK_SIZE
11748
11749 #define INIT_THREAD { \
11750 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11751 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11752 .vm86_info = NULL, \
11753 .sysenter_cs = __KERNEL_CS, \
11754 .io_bitmap_ptr = NULL, \
11755 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11756 */
11757 #define INIT_TSS { \
11758 .x86_tss = { \
11759 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11760 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11761 .ss0 = __KERNEL_DS, \
11762 .ss1 = __KERNEL_CS, \
11763 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11764 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11765 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11766
11767 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11768 -#define KSTK_TOP(info) \
11769 -({ \
11770 - unsigned long *__ptr = (unsigned long *)(info); \
11771 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11772 -})
11773 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11774
11775 /*
11776 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11777 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11778 #define task_pt_regs(task) \
11779 ({ \
11780 struct pt_regs *__regs__; \
11781 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11782 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11783 __regs__ - 1; \
11784 })
11785
11786 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11787 /*
11788 * User space process size. 47bits minus one guard page.
11789 */
11790 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11791 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11792
11793 /* This decides where the kernel will search for a free chunk of vm
11794 * space during mmap's.
11795 */
11796 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11797 - 0xc0000000 : 0xFFFFe000)
11798 + 0xc0000000 : 0xFFFFf000)
11799
11800 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11801 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11802 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11803 #define STACK_TOP_MAX TASK_SIZE_MAX
11804
11805 #define INIT_THREAD { \
11806 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11807 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11808 }
11809
11810 #define INIT_TSS { \
11811 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11812 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11813 }
11814
11815 /*
11816 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11817 */
11818 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11819
11820 +#ifdef CONFIG_PAX_SEGMEXEC
11821 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11822 +#endif
11823 +
11824 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11825
11826 /* Get/set a process' ability to use the timestamp counter instruction */
11827 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11828 #define cpu_has_amd_erratum(x) (false)
11829 #endif /* CONFIG_CPU_SUP_AMD */
11830
11831 -extern unsigned long arch_align_stack(unsigned long sp);
11832 +#define arch_align_stack(x) ((x) & ~0xfUL)
11833 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11834
11835 void default_idle(void);
11836 bool set_pm_idle_to_default(void);
11837
11838 -void stop_this_cpu(void *dummy);
11839 +void stop_this_cpu(void *dummy) __noreturn;
11840
11841 #endif /* _ASM_X86_PROCESSOR_H */
11842 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11843 index dcfde52..dbfea06 100644
11844 --- a/arch/x86/include/asm/ptrace.h
11845 +++ b/arch/x86/include/asm/ptrace.h
11846 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11847 }
11848
11849 /*
11850 - * user_mode_vm(regs) determines whether a register set came from user mode.
11851 + * user_mode(regs) determines whether a register set came from user mode.
11852 * This is true if V8086 mode was enabled OR if the register set was from
11853 * protected mode with RPL-3 CS value. This tricky test checks that with
11854 * one comparison. Many places in the kernel can bypass this full check
11855 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11856 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11857 + * be used.
11858 */
11859 -static inline int user_mode(struct pt_regs *regs)
11860 +static inline int user_mode_novm(struct pt_regs *regs)
11861 {
11862 #ifdef CONFIG_X86_32
11863 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11864 #else
11865 - return !!(regs->cs & 3);
11866 + return !!(regs->cs & SEGMENT_RPL_MASK);
11867 #endif
11868 }
11869
11870 -static inline int user_mode_vm(struct pt_regs *regs)
11871 +static inline int user_mode(struct pt_regs *regs)
11872 {
11873 #ifdef CONFIG_X86_32
11874 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11875 USER_RPL;
11876 #else
11877 - return user_mode(regs);
11878 + return user_mode_novm(regs);
11879 #endif
11880 }
11881
11882 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11883 #ifdef CONFIG_X86_64
11884 static inline bool user_64bit_mode(struct pt_regs *regs)
11885 {
11886 + unsigned long cs = regs->cs & 0xffff;
11887 #ifndef CONFIG_PARAVIRT
11888 /*
11889 * On non-paravirt systems, this is the only long mode CPL 3
11890 * selector. We do not allow long mode selectors in the LDT.
11891 */
11892 - return regs->cs == __USER_CS;
11893 + return cs == __USER_CS;
11894 #else
11895 /* Headers are too twisted for this to go in paravirt.h. */
11896 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11897 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11898 #endif
11899 }
11900 #endif
11901 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11902 index fce3f4a..3f69f2a 100644
11903 --- a/arch/x86/include/asm/realmode.h
11904 +++ b/arch/x86/include/asm/realmode.h
11905 @@ -30,7 +30,7 @@ struct real_mode_header {
11906 struct trampoline_header {
11907 #ifdef CONFIG_X86_32
11908 u32 start;
11909 - u16 gdt_pad;
11910 + u16 boot_cs;
11911 u16 gdt_limit;
11912 u32 gdt_base;
11913 #else
11914 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11915 index 92f29706..a79cbbb 100644
11916 --- a/arch/x86/include/asm/reboot.h
11917 +++ b/arch/x86/include/asm/reboot.h
11918 @@ -6,19 +6,19 @@
11919 struct pt_regs;
11920
11921 struct machine_ops {
11922 - void (*restart)(char *cmd);
11923 - void (*halt)(void);
11924 - void (*power_off)(void);
11925 + void (* __noreturn restart)(char *cmd);
11926 + void (* __noreturn halt)(void);
11927 + void (* __noreturn power_off)(void);
11928 void (*shutdown)(void);
11929 void (*crash_shutdown)(struct pt_regs *);
11930 - void (*emergency_restart)(void);
11931 -};
11932 + void (* __noreturn emergency_restart)(void);
11933 +} __no_const;
11934
11935 extern struct machine_ops machine_ops;
11936
11937 void native_machine_crash_shutdown(struct pt_regs *regs);
11938 void native_machine_shutdown(void);
11939 -void machine_real_restart(unsigned int type);
11940 +void machine_real_restart(unsigned int type) __noreturn;
11941 /* These must match dispatch_table in reboot_32.S */
11942 #define MRR_BIOS 0
11943 #define MRR_APM 1
11944 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11945 index 2dbe4a7..ce1db00 100644
11946 --- a/arch/x86/include/asm/rwsem.h
11947 +++ b/arch/x86/include/asm/rwsem.h
11948 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11949 {
11950 asm volatile("# beginning down_read\n\t"
11951 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11952 +
11953 +#ifdef CONFIG_PAX_REFCOUNT
11954 + "jno 0f\n"
11955 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11956 + "int $4\n0:\n"
11957 + _ASM_EXTABLE(0b, 0b)
11958 +#endif
11959 +
11960 /* adds 0x00000001 */
11961 " jns 1f\n"
11962 " call call_rwsem_down_read_failed\n"
11963 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11964 "1:\n\t"
11965 " mov %1,%2\n\t"
11966 " add %3,%2\n\t"
11967 +
11968 +#ifdef CONFIG_PAX_REFCOUNT
11969 + "jno 0f\n"
11970 + "sub %3,%2\n"
11971 + "int $4\n0:\n"
11972 + _ASM_EXTABLE(0b, 0b)
11973 +#endif
11974 +
11975 " jle 2f\n\t"
11976 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11977 " jnz 1b\n\t"
11978 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11979 long tmp;
11980 asm volatile("# beginning down_write\n\t"
11981 LOCK_PREFIX " xadd %1,(%2)\n\t"
11982 +
11983 +#ifdef CONFIG_PAX_REFCOUNT
11984 + "jno 0f\n"
11985 + "mov %1,(%2)\n"
11986 + "int $4\n0:\n"
11987 + _ASM_EXTABLE(0b, 0b)
11988 +#endif
11989 +
11990 /* adds 0xffff0001, returns the old value */
11991 " test %1,%1\n\t"
11992 /* was the count 0 before? */
11993 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11994 long tmp;
11995 asm volatile("# beginning __up_read\n\t"
11996 LOCK_PREFIX " xadd %1,(%2)\n\t"
11997 +
11998 +#ifdef CONFIG_PAX_REFCOUNT
11999 + "jno 0f\n"
12000 + "mov %1,(%2)\n"
12001 + "int $4\n0:\n"
12002 + _ASM_EXTABLE(0b, 0b)
12003 +#endif
12004 +
12005 /* subtracts 1, returns the old value */
12006 " jns 1f\n\t"
12007 " call call_rwsem_wake\n" /* expects old value in %edx */
12008 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12009 long tmp;
12010 asm volatile("# beginning __up_write\n\t"
12011 LOCK_PREFIX " xadd %1,(%2)\n\t"
12012 +
12013 +#ifdef CONFIG_PAX_REFCOUNT
12014 + "jno 0f\n"
12015 + "mov %1,(%2)\n"
12016 + "int $4\n0:\n"
12017 + _ASM_EXTABLE(0b, 0b)
12018 +#endif
12019 +
12020 /* subtracts 0xffff0001, returns the old value */
12021 " jns 1f\n\t"
12022 " call call_rwsem_wake\n" /* expects old value in %edx */
12023 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12024 {
12025 asm volatile("# beginning __downgrade_write\n\t"
12026 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12027 +
12028 +#ifdef CONFIG_PAX_REFCOUNT
12029 + "jno 0f\n"
12030 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12031 + "int $4\n0:\n"
12032 + _ASM_EXTABLE(0b, 0b)
12033 +#endif
12034 +
12035 /*
12036 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12037 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12038 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12039 */
12040 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12041 {
12042 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12043 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12044 +
12045 +#ifdef CONFIG_PAX_REFCOUNT
12046 + "jno 0f\n"
12047 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12048 + "int $4\n0:\n"
12049 + _ASM_EXTABLE(0b, 0b)
12050 +#endif
12051 +
12052 : "+m" (sem->count)
12053 : "er" (delta));
12054 }
12055 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12056 */
12057 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12058 {
12059 - return delta + xadd(&sem->count, delta);
12060 + return delta + xadd_check_overflow(&sem->count, delta);
12061 }
12062
12063 #endif /* __KERNEL__ */
12064 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12065 index c48a950..c6d7468 100644
12066 --- a/arch/x86/include/asm/segment.h
12067 +++ b/arch/x86/include/asm/segment.h
12068 @@ -64,10 +64,15 @@
12069 * 26 - ESPFIX small SS
12070 * 27 - per-cpu [ offset to per-cpu data area ]
12071 * 28 - stack_canary-20 [ for stack protector ]
12072 - * 29 - unused
12073 - * 30 - unused
12074 + * 29 - PCI BIOS CS
12075 + * 30 - PCI BIOS DS
12076 * 31 - TSS for double fault handler
12077 */
12078 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12079 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12080 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12081 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12082 +
12083 #define GDT_ENTRY_TLS_MIN 6
12084 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12085
12086 @@ -79,6 +84,8 @@
12087
12088 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12089
12090 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12091 +
12092 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12093
12094 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12095 @@ -104,6 +111,12 @@
12096 #define __KERNEL_STACK_CANARY 0
12097 #endif
12098
12099 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12100 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12101 +
12102 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12103 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12104 +
12105 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12106
12107 /*
12108 @@ -141,7 +154,7 @@
12109 */
12110
12111 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12112 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12113 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12114
12115
12116 #else
12117 @@ -165,6 +178,8 @@
12118 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12119 #define __USER32_DS __USER_DS
12120
12121 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12122 +
12123 #define GDT_ENTRY_TSS 8 /* needs two entries */
12124 #define GDT_ENTRY_LDT 10 /* needs two entries */
12125 #define GDT_ENTRY_TLS_MIN 12
12126 @@ -185,6 +200,7 @@
12127 #endif
12128
12129 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12130 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12131 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12132 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12133 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12134 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12135 {
12136 unsigned long __limit;
12137 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12138 - return __limit + 1;
12139 + return __limit;
12140 }
12141
12142 #endif /* !__ASSEMBLY__ */
12143 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12144 index f483945..64a7851 100644
12145 --- a/arch/x86/include/asm/smp.h
12146 +++ b/arch/x86/include/asm/smp.h
12147 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12148 /* cpus sharing the last level cache: */
12149 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12150 DECLARE_PER_CPU(u16, cpu_llc_id);
12151 -DECLARE_PER_CPU(int, cpu_number);
12152 +DECLARE_PER_CPU(unsigned int, cpu_number);
12153
12154 static inline struct cpumask *cpu_sibling_mask(int cpu)
12155 {
12156 @@ -79,7 +79,7 @@ struct smp_ops {
12157
12158 void (*send_call_func_ipi)(const struct cpumask *mask);
12159 void (*send_call_func_single_ipi)(int cpu);
12160 -};
12161 +} __no_const;
12162
12163 /* Globals due to paravirt */
12164 extern void set_cpu_sibling_map(int cpu);
12165 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12166 extern int safe_smp_processor_id(void);
12167
12168 #elif defined(CONFIG_X86_64_SMP)
12169 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12170 -
12171 -#define stack_smp_processor_id() \
12172 -({ \
12173 - struct thread_info *ti; \
12174 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12175 - ti->cpu; \
12176 -})
12177 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12178 +#define stack_smp_processor_id() raw_smp_processor_id()
12179 #define safe_smp_processor_id() smp_processor_id()
12180
12181 #endif
12182 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12183 index b315a33..8849ab0 100644
12184 --- a/arch/x86/include/asm/spinlock.h
12185 +++ b/arch/x86/include/asm/spinlock.h
12186 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12187 static inline void arch_read_lock(arch_rwlock_t *rw)
12188 {
12189 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12190 +
12191 +#ifdef CONFIG_PAX_REFCOUNT
12192 + "jno 0f\n"
12193 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12194 + "int $4\n0:\n"
12195 + _ASM_EXTABLE(0b, 0b)
12196 +#endif
12197 +
12198 "jns 1f\n"
12199 "call __read_lock_failed\n\t"
12200 "1:\n"
12201 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12202 static inline void arch_write_lock(arch_rwlock_t *rw)
12203 {
12204 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12205 +
12206 +#ifdef CONFIG_PAX_REFCOUNT
12207 + "jno 0f\n"
12208 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12209 + "int $4\n0:\n"
12210 + _ASM_EXTABLE(0b, 0b)
12211 +#endif
12212 +
12213 "jz 1f\n"
12214 "call __write_lock_failed\n\t"
12215 "1:\n"
12216 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12217
12218 static inline void arch_read_unlock(arch_rwlock_t *rw)
12219 {
12220 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12221 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12222 +
12223 +#ifdef CONFIG_PAX_REFCOUNT
12224 + "jno 0f\n"
12225 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12226 + "int $4\n0:\n"
12227 + _ASM_EXTABLE(0b, 0b)
12228 +#endif
12229 +
12230 :"+m" (rw->lock) : : "memory");
12231 }
12232
12233 static inline void arch_write_unlock(arch_rwlock_t *rw)
12234 {
12235 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12236 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12237 +
12238 +#ifdef CONFIG_PAX_REFCOUNT
12239 + "jno 0f\n"
12240 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12241 + "int $4\n0:\n"
12242 + _ASM_EXTABLE(0b, 0b)
12243 +#endif
12244 +
12245 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12246 }
12247
12248 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12249 index 6a99859..03cb807 100644
12250 --- a/arch/x86/include/asm/stackprotector.h
12251 +++ b/arch/x86/include/asm/stackprotector.h
12252 @@ -47,7 +47,7 @@
12253 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12254 */
12255 #define GDT_STACK_CANARY_INIT \
12256 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12257 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12258
12259 /*
12260 * Initialize the stackprotector canary value.
12261 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12262
12263 static inline void load_stack_canary_segment(void)
12264 {
12265 -#ifdef CONFIG_X86_32
12266 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12267 asm volatile ("mov %0, %%gs" : : "r" (0));
12268 #endif
12269 }
12270 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12271 index 70bbe39..4ae2bd4 100644
12272 --- a/arch/x86/include/asm/stacktrace.h
12273 +++ b/arch/x86/include/asm/stacktrace.h
12274 @@ -11,28 +11,20 @@
12275
12276 extern int kstack_depth_to_print;
12277
12278 -struct thread_info;
12279 +struct task_struct;
12280 struct stacktrace_ops;
12281
12282 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12283 - unsigned long *stack,
12284 - unsigned long bp,
12285 - const struct stacktrace_ops *ops,
12286 - void *data,
12287 - unsigned long *end,
12288 - int *graph);
12289 +typedef unsigned long walk_stack_t(struct task_struct *task,
12290 + void *stack_start,
12291 + unsigned long *stack,
12292 + unsigned long bp,
12293 + const struct stacktrace_ops *ops,
12294 + void *data,
12295 + unsigned long *end,
12296 + int *graph);
12297
12298 -extern unsigned long
12299 -print_context_stack(struct thread_info *tinfo,
12300 - unsigned long *stack, unsigned long bp,
12301 - const struct stacktrace_ops *ops, void *data,
12302 - unsigned long *end, int *graph);
12303 -
12304 -extern unsigned long
12305 -print_context_stack_bp(struct thread_info *tinfo,
12306 - unsigned long *stack, unsigned long bp,
12307 - const struct stacktrace_ops *ops, void *data,
12308 - unsigned long *end, int *graph);
12309 +extern walk_stack_t print_context_stack;
12310 +extern walk_stack_t print_context_stack_bp;
12311
12312 /* Generic stack tracer with callbacks */
12313
12314 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12315 void (*address)(void *data, unsigned long address, int reliable);
12316 /* On negative return stop dumping */
12317 int (*stack)(void *data, char *name);
12318 - walk_stack_t walk_stack;
12319 + walk_stack_t *walk_stack;
12320 };
12321
12322 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12323 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12324 index 4ec45b3..a4f0a8a 100644
12325 --- a/arch/x86/include/asm/switch_to.h
12326 +++ b/arch/x86/include/asm/switch_to.h
12327 @@ -108,7 +108,7 @@ do { \
12328 "call __switch_to\n\t" \
12329 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12330 __switch_canary \
12331 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12332 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12333 "movq %%rax,%%rdi\n\t" \
12334 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12335 "jnz ret_from_fork\n\t" \
12336 @@ -119,7 +119,7 @@ do { \
12337 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12338 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12339 [_tif_fork] "i" (_TIF_FORK), \
12340 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12341 + [thread_info] "m" (current_tinfo), \
12342 [current_task] "m" (current_task) \
12343 __switch_canary_iparam \
12344 : "memory", "cc" __EXTRA_CLOBBER)
12345 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12346 index 3fda9db4..4ca1c61 100644
12347 --- a/arch/x86/include/asm/sys_ia32.h
12348 +++ b/arch/x86/include/asm/sys_ia32.h
12349 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12350 struct old_sigaction32 __user *);
12351 asmlinkage long sys32_alarm(unsigned int);
12352
12353 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12354 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12355 asmlinkage long sys32_sysfs(int, u32, u32);
12356
12357 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12358 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12359 index 89f794f..1422765 100644
12360 --- a/arch/x86/include/asm/thread_info.h
12361 +++ b/arch/x86/include/asm/thread_info.h
12362 @@ -10,6 +10,7 @@
12363 #include <linux/compiler.h>
12364 #include <asm/page.h>
12365 #include <asm/types.h>
12366 +#include <asm/percpu.h>
12367
12368 /*
12369 * low level task data that entry.S needs immediate access to
12370 @@ -24,7 +25,6 @@ struct exec_domain;
12371 #include <linux/atomic.h>
12372
12373 struct thread_info {
12374 - struct task_struct *task; /* main task structure */
12375 struct exec_domain *exec_domain; /* execution domain */
12376 __u32 flags; /* low level flags */
12377 __u32 status; /* thread synchronous flags */
12378 @@ -34,19 +34,13 @@ struct thread_info {
12379 mm_segment_t addr_limit;
12380 struct restart_block restart_block;
12381 void __user *sysenter_return;
12382 -#ifdef CONFIG_X86_32
12383 - unsigned long previous_esp; /* ESP of the previous stack in
12384 - case of nested (IRQ) stacks
12385 - */
12386 - __u8 supervisor_stack[0];
12387 -#endif
12388 + unsigned long lowest_stack;
12389 unsigned int sig_on_uaccess_error:1;
12390 unsigned int uaccess_err:1; /* uaccess failed */
12391 };
12392
12393 -#define INIT_THREAD_INFO(tsk) \
12394 +#define INIT_THREAD_INFO \
12395 { \
12396 - .task = &tsk, \
12397 .exec_domain = &default_exec_domain, \
12398 .flags = 0, \
12399 .cpu = 0, \
12400 @@ -57,7 +51,7 @@ struct thread_info {
12401 }, \
12402 }
12403
12404 -#define init_thread_info (init_thread_union.thread_info)
12405 +#define init_thread_info (init_thread_union.stack)
12406 #define init_stack (init_thread_union.stack)
12407
12408 #else /* !__ASSEMBLY__ */
12409 @@ -98,6 +92,7 @@ struct thread_info {
12410 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12411 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12412 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12413 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12414
12415 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12416 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12417 @@ -122,16 +117,18 @@ struct thread_info {
12418 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12419 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12420 #define _TIF_X32 (1 << TIF_X32)
12421 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12422
12423 /* work to do in syscall_trace_enter() */
12424 #define _TIF_WORK_SYSCALL_ENTRY \
12425 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12426 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12427 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12428 + _TIF_GRSEC_SETXID)
12429
12430 /* work to do in syscall_trace_leave() */
12431 #define _TIF_WORK_SYSCALL_EXIT \
12432 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12433 - _TIF_SYSCALL_TRACEPOINT)
12434 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12435
12436 /* work to do on interrupt/exception return */
12437 #define _TIF_WORK_MASK \
12438 @@ -141,7 +138,8 @@ struct thread_info {
12439
12440 /* work to do on any return to user space */
12441 #define _TIF_ALLWORK_MASK \
12442 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12443 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12444 + _TIF_GRSEC_SETXID)
12445
12446 /* Only used for 64 bit */
12447 #define _TIF_DO_NOTIFY_MASK \
12448 @@ -157,45 +155,40 @@ struct thread_info {
12449
12450 #define PREEMPT_ACTIVE 0x10000000
12451
12452 -#ifdef CONFIG_X86_32
12453 -
12454 -#define STACK_WARN (THREAD_SIZE/8)
12455 -/*
12456 - * macros/functions for gaining access to the thread information structure
12457 - *
12458 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12459 - */
12460 -#ifndef __ASSEMBLY__
12461 -
12462 -
12463 -/* how to get the current stack pointer from C */
12464 -register unsigned long current_stack_pointer asm("esp") __used;
12465 -
12466 -/* how to get the thread information struct from C */
12467 -static inline struct thread_info *current_thread_info(void)
12468 -{
12469 - return (struct thread_info *)
12470 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12471 -}
12472 -
12473 -#else /* !__ASSEMBLY__ */
12474 -
12475 +#ifdef __ASSEMBLY__
12476 /* how to get the thread information struct from ASM */
12477 #define GET_THREAD_INFO(reg) \
12478 - movl $-THREAD_SIZE, reg; \
12479 - andl %esp, reg
12480 + mov PER_CPU_VAR(current_tinfo), reg
12481
12482 /* use this one if reg already contains %esp */
12483 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12484 - andl $-THREAD_SIZE, reg
12485 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12486 +#else
12487 +/* how to get the thread information struct from C */
12488 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12489 +
12490 +static __always_inline struct thread_info *current_thread_info(void)
12491 +{
12492 + return this_cpu_read_stable(current_tinfo);
12493 +}
12494 +#endif
12495 +
12496 +#ifdef CONFIG_X86_32
12497 +
12498 +#define STACK_WARN (THREAD_SIZE/8)
12499 +/*
12500 + * macros/functions for gaining access to the thread information structure
12501 + *
12502 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12503 + */
12504 +#ifndef __ASSEMBLY__
12505 +
12506 +/* how to get the current stack pointer from C */
12507 +register unsigned long current_stack_pointer asm("esp") __used;
12508
12509 #endif
12510
12511 #else /* X86_32 */
12512
12513 -#include <asm/percpu.h>
12514 -#define KERNEL_STACK_OFFSET (5*8)
12515 -
12516 /*
12517 * macros/functions for gaining access to the thread information structure
12518 * preempt_count needs to be 1 initially, until the scheduler is functional.
12519 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12520 #ifndef __ASSEMBLY__
12521 DECLARE_PER_CPU(unsigned long, kernel_stack);
12522
12523 -static inline struct thread_info *current_thread_info(void)
12524 -{
12525 - struct thread_info *ti;
12526 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12527 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12528 - return ti;
12529 -}
12530 -
12531 -#else /* !__ASSEMBLY__ */
12532 -
12533 -/* how to get the thread information struct from ASM */
12534 -#define GET_THREAD_INFO(reg) \
12535 - movq PER_CPU_VAR(kernel_stack),reg ; \
12536 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12537 -
12538 -/*
12539 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12540 - * a certain register (to be used in assembler memory operands).
12541 - */
12542 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12543 -
12544 +/* how to get the current stack pointer from C */
12545 +register unsigned long current_stack_pointer asm("rsp") __used;
12546 #endif
12547
12548 #endif /* !X86_32 */
12549 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12550 extern void arch_task_cache_init(void);
12551 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12552 extern void arch_release_task_struct(struct task_struct *tsk);
12553 +
12554 +#define __HAVE_THREAD_FUNCTIONS
12555 +#define task_thread_info(task) (&(task)->tinfo)
12556 +#define task_stack_page(task) ((task)->stack)
12557 +#define setup_thread_stack(p, org) do {} while (0)
12558 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12559 +
12560 #endif
12561 #endif /* _ASM_X86_THREAD_INFO_H */
12562 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12563 index e1f3a17..1ab364d 100644
12564 --- a/arch/x86/include/asm/uaccess.h
12565 +++ b/arch/x86/include/asm/uaccess.h
12566 @@ -7,12 +7,15 @@
12567 #include <linux/compiler.h>
12568 #include <linux/thread_info.h>
12569 #include <linux/string.h>
12570 +#include <linux/sched.h>
12571 #include <asm/asm.h>
12572 #include <asm/page.h>
12573
12574 #define VERIFY_READ 0
12575 #define VERIFY_WRITE 1
12576
12577 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12578 +
12579 /*
12580 * The fs value determines whether argument validity checking should be
12581 * performed or not. If get_fs() == USER_DS, checking is performed, with
12582 @@ -28,7 +31,12 @@
12583
12584 #define get_ds() (KERNEL_DS)
12585 #define get_fs() (current_thread_info()->addr_limit)
12586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12587 +void __set_fs(mm_segment_t x);
12588 +void set_fs(mm_segment_t x);
12589 +#else
12590 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12591 +#endif
12592
12593 #define segment_eq(a, b) ((a).seg == (b).seg)
12594
12595 @@ -76,8 +84,33 @@
12596 * checks that the pointer is in the user space range - after calling
12597 * this function, memory access functions may still return -EFAULT.
12598 */
12599 -#define access_ok(type, addr, size) \
12600 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12601 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12602 +#define access_ok(type, addr, size) \
12603 +({ \
12604 + long __size = size; \
12605 + unsigned long __addr = (unsigned long)addr; \
12606 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12607 + unsigned long __end_ao = __addr + __size - 1; \
12608 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12609 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12610 + while(__addr_ao <= __end_ao) { \
12611 + char __c_ao; \
12612 + __addr_ao += PAGE_SIZE; \
12613 + if (__size > PAGE_SIZE) \
12614 + cond_resched(); \
12615 + if (__get_user(__c_ao, (char __user *)__addr)) \
12616 + break; \
12617 + if (type != VERIFY_WRITE) { \
12618 + __addr = __addr_ao; \
12619 + continue; \
12620 + } \
12621 + if (__put_user(__c_ao, (char __user *)__addr)) \
12622 + break; \
12623 + __addr = __addr_ao; \
12624 + } \
12625 + } \
12626 + __ret_ao; \
12627 +})
12628
12629 /*
12630 * The exception table consists of pairs of addresses relative to the
12631 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12632 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12633 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12634
12635 -
12636 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12637 +#define __copyuser_seg "gs;"
12638 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12639 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12640 +#else
12641 +#define __copyuser_seg
12642 +#define __COPYUSER_SET_ES
12643 +#define __COPYUSER_RESTORE_ES
12644 +#endif
12645
12646 #ifdef CONFIG_X86_32
12647 #define __put_user_asm_u64(x, addr, err, errret) \
12648 - asm volatile("1: movl %%eax,0(%2)\n" \
12649 - "2: movl %%edx,4(%2)\n" \
12650 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12651 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12652 "3:\n" \
12653 ".section .fixup,\"ax\"\n" \
12654 "4: movl %3,%0\n" \
12655 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12656 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12657
12658 #define __put_user_asm_ex_u64(x, addr) \
12659 - asm volatile("1: movl %%eax,0(%1)\n" \
12660 - "2: movl %%edx,4(%1)\n" \
12661 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12662 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12663 "3:\n" \
12664 _ASM_EXTABLE_EX(1b, 2b) \
12665 _ASM_EXTABLE_EX(2b, 3b) \
12666 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12667 __typeof__(*(ptr)) __pu_val; \
12668 __chk_user_ptr(ptr); \
12669 might_fault(); \
12670 - __pu_val = x; \
12671 + __pu_val = (x); \
12672 switch (sizeof(*(ptr))) { \
12673 case 1: \
12674 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12675 @@ -379,7 +420,7 @@ do { \
12676 } while (0)
12677
12678 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12679 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12680 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12681 "2:\n" \
12682 ".section .fixup,\"ax\"\n" \
12683 "3: mov %3,%0\n" \
12684 @@ -387,7 +428,7 @@ do { \
12685 " jmp 2b\n" \
12686 ".previous\n" \
12687 _ASM_EXTABLE(1b, 3b) \
12688 - : "=r" (err), ltype(x) \
12689 + : "=r" (err), ltype (x) \
12690 : "m" (__m(addr)), "i" (errret), "0" (err))
12691
12692 #define __get_user_size_ex(x, ptr, size) \
12693 @@ -412,7 +453,7 @@ do { \
12694 } while (0)
12695
12696 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12697 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12698 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12699 "2:\n" \
12700 _ASM_EXTABLE_EX(1b, 2b) \
12701 : ltype(x) : "m" (__m(addr)))
12702 @@ -429,13 +470,24 @@ do { \
12703 int __gu_err; \
12704 unsigned long __gu_val; \
12705 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12706 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12707 + (x) = (__typeof__(*(ptr)))__gu_val; \
12708 __gu_err; \
12709 })
12710
12711 /* FIXME: this hack is definitely wrong -AK */
12712 struct __large_struct { unsigned long buf[100]; };
12713 -#define __m(x) (*(struct __large_struct __user *)(x))
12714 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12715 +#define ____m(x) \
12716 +({ \
12717 + unsigned long ____x = (unsigned long)(x); \
12718 + if (____x < PAX_USER_SHADOW_BASE) \
12719 + ____x += PAX_USER_SHADOW_BASE; \
12720 + (void __user *)____x; \
12721 +})
12722 +#else
12723 +#define ____m(x) (x)
12724 +#endif
12725 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12726
12727 /*
12728 * Tell gcc we read from memory instead of writing: this is because
12729 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12730 * aliasing issues.
12731 */
12732 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12733 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12734 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12735 "2:\n" \
12736 ".section .fixup,\"ax\"\n" \
12737 "3: mov %3,%0\n" \
12738 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12739 ".previous\n" \
12740 _ASM_EXTABLE(1b, 3b) \
12741 : "=r"(err) \
12742 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12743 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12744
12745 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12746 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12747 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12748 "2:\n" \
12749 _ASM_EXTABLE_EX(1b, 2b) \
12750 : : ltype(x), "m" (__m(addr)))
12751 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12752 * On error, the variable @x is set to zero.
12753 */
12754
12755 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12756 +#define __get_user(x, ptr) get_user((x), (ptr))
12757 +#else
12758 #define __get_user(x, ptr) \
12759 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12760 +#endif
12761
12762 /**
12763 * __put_user: - Write a simple value into user space, with less checking.
12764 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12765 * Returns zero on success, or -EFAULT on error.
12766 */
12767
12768 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12769 +#define __put_user(x, ptr) put_user((x), (ptr))
12770 +#else
12771 #define __put_user(x, ptr) \
12772 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12773 +#endif
12774
12775 #define __get_user_unaligned __get_user
12776 #define __put_user_unaligned __put_user
12777 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12778 #define get_user_ex(x, ptr) do { \
12779 unsigned long __gue_val; \
12780 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12781 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12782 + (x) = (__typeof__(*(ptr)))__gue_val; \
12783 } while (0)
12784
12785 #ifdef CONFIG_X86_WP_WORKS_OK
12786 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12787 index 576e39b..ccd0a39 100644
12788 --- a/arch/x86/include/asm/uaccess_32.h
12789 +++ b/arch/x86/include/asm/uaccess_32.h
12790 @@ -11,15 +11,15 @@
12791 #include <asm/page.h>
12792
12793 unsigned long __must_check __copy_to_user_ll
12794 - (void __user *to, const void *from, unsigned long n);
12795 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12796 unsigned long __must_check __copy_from_user_ll
12797 - (void *to, const void __user *from, unsigned long n);
12798 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12799 unsigned long __must_check __copy_from_user_ll_nozero
12800 - (void *to, const void __user *from, unsigned long n);
12801 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12802 unsigned long __must_check __copy_from_user_ll_nocache
12803 - (void *to, const void __user *from, unsigned long n);
12804 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12805 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12806 - (void *to, const void __user *from, unsigned long n);
12807 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12808
12809 /**
12810 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12811 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12812 static __always_inline unsigned long __must_check
12813 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12814 {
12815 + if ((long)n < 0)
12816 + return n;
12817 +
12818 if (__builtin_constant_p(n)) {
12819 unsigned long ret;
12820
12821 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12822 return ret;
12823 }
12824 }
12825 + if (!__builtin_constant_p(n))
12826 + check_object_size(from, n, true);
12827 return __copy_to_user_ll(to, from, n);
12828 }
12829
12830 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12831 __copy_to_user(void __user *to, const void *from, unsigned long n)
12832 {
12833 might_fault();
12834 +
12835 return __copy_to_user_inatomic(to, from, n);
12836 }
12837
12838 static __always_inline unsigned long
12839 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12840 {
12841 + if ((long)n < 0)
12842 + return n;
12843 +
12844 /* Avoid zeroing the tail if the copy fails..
12845 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12846 * but as the zeroing behaviour is only significant when n is not
12847 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12848 __copy_from_user(void *to, const void __user *from, unsigned long n)
12849 {
12850 might_fault();
12851 +
12852 + if ((long)n < 0)
12853 + return n;
12854 +
12855 if (__builtin_constant_p(n)) {
12856 unsigned long ret;
12857
12858 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12859 return ret;
12860 }
12861 }
12862 + if (!__builtin_constant_p(n))
12863 + check_object_size(to, n, false);
12864 return __copy_from_user_ll(to, from, n);
12865 }
12866
12867 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12868 const void __user *from, unsigned long n)
12869 {
12870 might_fault();
12871 +
12872 + if ((long)n < 0)
12873 + return n;
12874 +
12875 if (__builtin_constant_p(n)) {
12876 unsigned long ret;
12877
12878 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12879 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12880 unsigned long n)
12881 {
12882 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12883 + if ((long)n < 0)
12884 + return n;
12885 +
12886 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12887 }
12888
12889 -unsigned long __must_check copy_to_user(void __user *to,
12890 - const void *from, unsigned long n);
12891 -unsigned long __must_check _copy_from_user(void *to,
12892 - const void __user *from,
12893 - unsigned long n);
12894 -
12895 +extern void copy_to_user_overflow(void)
12896 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12897 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12898 +#else
12899 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12900 +#endif
12901 +;
12902
12903 extern void copy_from_user_overflow(void)
12904 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12905 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12906 #endif
12907 ;
12908
12909 -static inline unsigned long __must_check copy_from_user(void *to,
12910 - const void __user *from,
12911 - unsigned long n)
12912 +/**
12913 + * copy_to_user: - Copy a block of data into user space.
12914 + * @to: Destination address, in user space.
12915 + * @from: Source address, in kernel space.
12916 + * @n: Number of bytes to copy.
12917 + *
12918 + * Context: User context only. This function may sleep.
12919 + *
12920 + * Copy data from kernel space to user space.
12921 + *
12922 + * Returns number of bytes that could not be copied.
12923 + * On success, this will be zero.
12924 + */
12925 +static inline unsigned long __must_check
12926 +copy_to_user(void __user *to, const void *from, unsigned long n)
12927 {
12928 - int sz = __compiletime_object_size(to);
12929 + size_t sz = __compiletime_object_size(from);
12930
12931 - if (likely(sz == -1 || sz >= n))
12932 - n = _copy_from_user(to, from, n);
12933 - else
12934 + if (unlikely(sz != (size_t)-1 && sz < n))
12935 + copy_to_user_overflow();
12936 + else if (access_ok(VERIFY_WRITE, to, n))
12937 + n = __copy_to_user(to, from, n);
12938 + return n;
12939 +}
12940 +
12941 +/**
12942 + * copy_from_user: - Copy a block of data from user space.
12943 + * @to: Destination address, in kernel space.
12944 + * @from: Source address, in user space.
12945 + * @n: Number of bytes to copy.
12946 + *
12947 + * Context: User context only. This function may sleep.
12948 + *
12949 + * Copy data from user space to kernel space.
12950 + *
12951 + * Returns number of bytes that could not be copied.
12952 + * On success, this will be zero.
12953 + *
12954 + * If some data could not be copied, this function will pad the copied
12955 + * data to the requested size using zero bytes.
12956 + */
12957 +static inline unsigned long __must_check
12958 +copy_from_user(void *to, const void __user *from, unsigned long n)
12959 +{
12960 + size_t sz = __compiletime_object_size(to);
12961 +
12962 + if (unlikely(sz != (size_t)-1 && sz < n))
12963 copy_from_user_overflow();
12964 -
12965 + else if (access_ok(VERIFY_READ, from, n))
12966 + n = __copy_from_user(to, from, n);
12967 + else if ((long)n > 0) {
12968 + if (!__builtin_constant_p(n))
12969 + check_object_size(to, n, false);
12970 + memset(to, 0, n);
12971 + }
12972 return n;
12973 }
12974
12975 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12976 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12977 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12978 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12979
12980 #endif /* _ASM_X86_UACCESS_32_H */
12981 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12982 index 8e796fb..72fd934 100644
12983 --- a/arch/x86/include/asm/uaccess_64.h
12984 +++ b/arch/x86/include/asm/uaccess_64.h
12985 @@ -10,6 +10,9 @@
12986 #include <asm/alternative.h>
12987 #include <asm/cpufeature.h>
12988 #include <asm/page.h>
12989 +#include <asm/pgtable.h>
12990 +
12991 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12992
12993 /*
12994 * Copy To/From Userspace
12995 @@ -17,12 +20,14 @@
12996
12997 /* Handles exceptions in both to and from, but doesn't do access_ok */
12998 __must_check unsigned long
12999 -copy_user_generic_string(void *to, const void *from, unsigned len);
13000 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13001 __must_check unsigned long
13002 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13003 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13004
13005 static __always_inline __must_check unsigned long
13006 -copy_user_generic(void *to, const void *from, unsigned len)
13007 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13008 +static __always_inline __must_check unsigned long
13009 +copy_user_generic(void *to, const void *from, unsigned long len)
13010 {
13011 unsigned ret;
13012
13013 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13014 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13015 "=d" (len)),
13016 "1" (to), "2" (from), "3" (len)
13017 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13018 + : "memory", "rcx", "r8", "r9", "r11");
13019 return ret;
13020 }
13021
13022 +static __always_inline __must_check unsigned long
13023 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13024 +static __always_inline __must_check unsigned long
13025 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13026 __must_check unsigned long
13027 -_copy_to_user(void __user *to, const void *from, unsigned len);
13028 -__must_check unsigned long
13029 -_copy_from_user(void *to, const void __user *from, unsigned len);
13030 -__must_check unsigned long
13031 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13032 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13033 +
13034 +extern void copy_to_user_overflow(void)
13035 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13036 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13037 +#else
13038 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13039 +#endif
13040 +;
13041 +
13042 +extern void copy_from_user_overflow(void)
13043 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13044 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13045 +#else
13046 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13047 +#endif
13048 +;
13049
13050 static inline unsigned long __must_check copy_from_user(void *to,
13051 const void __user *from,
13052 unsigned long n)
13053 {
13054 - int sz = __compiletime_object_size(to);
13055 -
13056 might_fault();
13057 - if (likely(sz == -1 || sz >= n))
13058 - n = _copy_from_user(to, from, n);
13059 -#ifdef CONFIG_DEBUG_VM
13060 - else
13061 - WARN(1, "Buffer overflow detected!\n");
13062 -#endif
13063 +
13064 + if (access_ok(VERIFY_READ, from, n))
13065 + n = __copy_from_user(to, from, n);
13066 + else if (n < INT_MAX) {
13067 + if (!__builtin_constant_p(n))
13068 + check_object_size(to, n, false);
13069 + memset(to, 0, n);
13070 + }
13071 return n;
13072 }
13073
13074 static __always_inline __must_check
13075 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13076 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13077 {
13078 might_fault();
13079
13080 - return _copy_to_user(dst, src, size);
13081 + if (access_ok(VERIFY_WRITE, dst, size))
13082 + size = __copy_to_user(dst, src, size);
13083 + return size;
13084 }
13085
13086 static __always_inline __must_check
13087 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13088 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13089 {
13090 - int ret = 0;
13091 + size_t sz = __compiletime_object_size(dst);
13092 + unsigned ret = 0;
13093
13094 might_fault();
13095 - if (!__builtin_constant_p(size))
13096 - return copy_user_generic(dst, (__force void *)src, size);
13097 +
13098 + if (size > INT_MAX)
13099 + return size;
13100 +
13101 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13102 + if (!__access_ok(VERIFY_READ, src, size))
13103 + return size;
13104 +#endif
13105 +
13106 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13107 + copy_from_user_overflow();
13108 + return size;
13109 + }
13110 +
13111 + if (!__builtin_constant_p(size)) {
13112 + check_object_size(dst, size, false);
13113 +
13114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13115 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13116 + src += PAX_USER_SHADOW_BASE;
13117 +#endif
13118 +
13119 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13120 + }
13121 switch (size) {
13122 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13123 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13124 ret, "b", "b", "=q", 1);
13125 return ret;
13126 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13127 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13128 ret, "w", "w", "=r", 2);
13129 return ret;
13130 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13131 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13132 ret, "l", "k", "=r", 4);
13133 return ret;
13134 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13135 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13136 ret, "q", "", "=r", 8);
13137 return ret;
13138 case 10:
13139 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13140 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13141 ret, "q", "", "=r", 10);
13142 if (unlikely(ret))
13143 return ret;
13144 __get_user_asm(*(u16 *)(8 + (char *)dst),
13145 - (u16 __user *)(8 + (char __user *)src),
13146 + (const u16 __user *)(8 + (const char __user *)src),
13147 ret, "w", "w", "=r", 2);
13148 return ret;
13149 case 16:
13150 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13151 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13152 ret, "q", "", "=r", 16);
13153 if (unlikely(ret))
13154 return ret;
13155 __get_user_asm(*(u64 *)(8 + (char *)dst),
13156 - (u64 __user *)(8 + (char __user *)src),
13157 + (const u64 __user *)(8 + (const char __user *)src),
13158 ret, "q", "", "=r", 8);
13159 return ret;
13160 default:
13161 - return copy_user_generic(dst, (__force void *)src, size);
13162 +
13163 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13164 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13165 + src += PAX_USER_SHADOW_BASE;
13166 +#endif
13167 +
13168 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13169 }
13170 }
13171
13172 static __always_inline __must_check
13173 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13174 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13175 {
13176 - int ret = 0;
13177 + size_t sz = __compiletime_object_size(src);
13178 + unsigned ret = 0;
13179
13180 might_fault();
13181 - if (!__builtin_constant_p(size))
13182 - return copy_user_generic((__force void *)dst, src, size);
13183 +
13184 + if (size > INT_MAX)
13185 + return size;
13186 +
13187 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13188 + if (!__access_ok(VERIFY_WRITE, dst, size))
13189 + return size;
13190 +#endif
13191 +
13192 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13193 + copy_to_user_overflow();
13194 + return size;
13195 + }
13196 +
13197 + if (!__builtin_constant_p(size)) {
13198 + check_object_size(src, size, true);
13199 +
13200 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13201 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13202 + dst += PAX_USER_SHADOW_BASE;
13203 +#endif
13204 +
13205 + return copy_user_generic((__force_kernel void *)dst, src, size);
13206 + }
13207 switch (size) {
13208 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13209 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13210 ret, "b", "b", "iq", 1);
13211 return ret;
13212 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13213 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13214 ret, "w", "w", "ir", 2);
13215 return ret;
13216 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13217 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13218 ret, "l", "k", "ir", 4);
13219 return ret;
13220 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13221 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13222 ret, "q", "", "er", 8);
13223 return ret;
13224 case 10:
13225 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13226 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13227 ret, "q", "", "er", 10);
13228 if (unlikely(ret))
13229 return ret;
13230 asm("":::"memory");
13231 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13232 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13233 ret, "w", "w", "ir", 2);
13234 return ret;
13235 case 16:
13236 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13237 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13238 ret, "q", "", "er", 16);
13239 if (unlikely(ret))
13240 return ret;
13241 asm("":::"memory");
13242 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13243 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13244 ret, "q", "", "er", 8);
13245 return ret;
13246 default:
13247 - return copy_user_generic((__force void *)dst, src, size);
13248 +
13249 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13250 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13251 + dst += PAX_USER_SHADOW_BASE;
13252 +#endif
13253 +
13254 + return copy_user_generic((__force_kernel void *)dst, src, size);
13255 }
13256 }
13257
13258 static __always_inline __must_check
13259 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13260 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13261 {
13262 - int ret = 0;
13263 + unsigned ret = 0;
13264
13265 might_fault();
13266 - if (!__builtin_constant_p(size))
13267 - return copy_user_generic((__force void *)dst,
13268 - (__force void *)src, size);
13269 +
13270 + if (size > INT_MAX)
13271 + return size;
13272 +
13273 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13274 + if (!__access_ok(VERIFY_READ, src, size))
13275 + return size;
13276 + if (!__access_ok(VERIFY_WRITE, dst, size))
13277 + return size;
13278 +#endif
13279 +
13280 + if (!__builtin_constant_p(size)) {
13281 +
13282 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13283 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13284 + src += PAX_USER_SHADOW_BASE;
13285 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13286 + dst += PAX_USER_SHADOW_BASE;
13287 +#endif
13288 +
13289 + return copy_user_generic((__force_kernel void *)dst,
13290 + (__force_kernel const void *)src, size);
13291 + }
13292 switch (size) {
13293 case 1: {
13294 u8 tmp;
13295 - __get_user_asm(tmp, (u8 __user *)src,
13296 + __get_user_asm(tmp, (const u8 __user *)src,
13297 ret, "b", "b", "=q", 1);
13298 if (likely(!ret))
13299 __put_user_asm(tmp, (u8 __user *)dst,
13300 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13301 }
13302 case 2: {
13303 u16 tmp;
13304 - __get_user_asm(tmp, (u16 __user *)src,
13305 + __get_user_asm(tmp, (const u16 __user *)src,
13306 ret, "w", "w", "=r", 2);
13307 if (likely(!ret))
13308 __put_user_asm(tmp, (u16 __user *)dst,
13309 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13310
13311 case 4: {
13312 u32 tmp;
13313 - __get_user_asm(tmp, (u32 __user *)src,
13314 + __get_user_asm(tmp, (const u32 __user *)src,
13315 ret, "l", "k", "=r", 4);
13316 if (likely(!ret))
13317 __put_user_asm(tmp, (u32 __user *)dst,
13318 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13319 }
13320 case 8: {
13321 u64 tmp;
13322 - __get_user_asm(tmp, (u64 __user *)src,
13323 + __get_user_asm(tmp, (const u64 __user *)src,
13324 ret, "q", "", "=r", 8);
13325 if (likely(!ret))
13326 __put_user_asm(tmp, (u64 __user *)dst,
13327 @@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13328 return ret;
13329 }
13330 default:
13331 - return copy_user_generic((__force void *)dst,
13332 - (__force void *)src, size);
13333 +
13334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13335 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13336 + src += PAX_USER_SHADOW_BASE;
13337 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13338 + dst += PAX_USER_SHADOW_BASE;
13339 +#endif
13340 +
13341 + return copy_user_generic((__force_kernel void *)dst,
13342 + (__force_kernel const void *)src, size);
13343 }
13344 }
13345
13346 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13347 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13348 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13349 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13350
13351 static __must_check __always_inline int
13352 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13353 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13354 {
13355 - return copy_user_generic(dst, (__force const void *)src, size);
13356 + if (size > INT_MAX)
13357 + return size;
13358 +
13359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13360 + if (!__access_ok(VERIFY_READ, src, size))
13361 + return size;
13362 +
13363 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13364 + src += PAX_USER_SHADOW_BASE;
13365 +#endif
13366 +
13367 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13368 }
13369
13370 -static __must_check __always_inline int
13371 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13372 +static __must_check __always_inline unsigned long
13373 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13374 {
13375 - return copy_user_generic((__force void *)dst, src, size);
13376 + if (size > INT_MAX)
13377 + return size;
13378 +
13379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13380 + if (!__access_ok(VERIFY_WRITE, dst, size))
13381 + return size;
13382 +
13383 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13384 + dst += PAX_USER_SHADOW_BASE;
13385 +#endif
13386 +
13387 + return copy_user_generic((__force_kernel void *)dst, src, size);
13388 }
13389
13390 -extern long __copy_user_nocache(void *dst, const void __user *src,
13391 - unsigned size, int zerorest);
13392 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13393 + unsigned long size, int zerorest) __size_overflow(3);
13394
13395 -static inline int
13396 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13397 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13398 {
13399 might_sleep();
13400 +
13401 + if (size > INT_MAX)
13402 + return size;
13403 +
13404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13405 + if (!__access_ok(VERIFY_READ, src, size))
13406 + return size;
13407 +#endif
13408 +
13409 return __copy_user_nocache(dst, src, size, 1);
13410 }
13411
13412 -static inline int
13413 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13414 - unsigned size)
13415 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13416 + unsigned long size)
13417 {
13418 + if (size > INT_MAX)
13419 + return size;
13420 +
13421 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13422 + if (!__access_ok(VERIFY_READ, src, size))
13423 + return size;
13424 +#endif
13425 +
13426 return __copy_user_nocache(dst, src, size, 0);
13427 }
13428
13429 -unsigned long
13430 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13431 +extern unsigned long
13432 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13433
13434 #endif /* _ASM_X86_UACCESS_64_H */
13435 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13436 index bb05228..d763d5b 100644
13437 --- a/arch/x86/include/asm/vdso.h
13438 +++ b/arch/x86/include/asm/vdso.h
13439 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13440 #define VDSO32_SYMBOL(base, name) \
13441 ({ \
13442 extern const char VDSO32_##name[]; \
13443 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13444 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13445 })
13446 #endif
13447
13448 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13449 index 5b238981..77fdd78 100644
13450 --- a/arch/x86/include/asm/word-at-a-time.h
13451 +++ b/arch/x86/include/asm/word-at-a-time.h
13452 @@ -11,7 +11,7 @@
13453 * and shift, for example.
13454 */
13455 struct word_at_a_time {
13456 - const unsigned long one_bits, high_bits;
13457 + unsigned long one_bits, high_bits;
13458 };
13459
13460 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13461 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13462 index c090af1..7e7bf16 100644
13463 --- a/arch/x86/include/asm/x86_init.h
13464 +++ b/arch/x86/include/asm/x86_init.h
13465 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13466 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13467 void (*find_smp_config)(void);
13468 void (*get_smp_config)(unsigned int early);
13469 -};
13470 +} __no_const;
13471
13472 /**
13473 * struct x86_init_resources - platform specific resource related ops
13474 @@ -43,7 +43,7 @@ struct x86_init_resources {
13475 void (*probe_roms)(void);
13476 void (*reserve_resources)(void);
13477 char *(*memory_setup)(void);
13478 -};
13479 +} __no_const;
13480
13481 /**
13482 * struct x86_init_irqs - platform specific interrupt setup
13483 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13484 void (*pre_vector_init)(void);
13485 void (*intr_init)(void);
13486 void (*trap_init)(void);
13487 -};
13488 +} __no_const;
13489
13490 /**
13491 * struct x86_init_oem - oem platform specific customizing functions
13492 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13493 struct x86_init_oem {
13494 void (*arch_setup)(void);
13495 void (*banner)(void);
13496 -};
13497 +} __no_const;
13498
13499 /**
13500 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13501 @@ -77,7 +77,7 @@ struct x86_init_oem {
13502 */
13503 struct x86_init_mapping {
13504 void (*pagetable_reserve)(u64 start, u64 end);
13505 -};
13506 +} __no_const;
13507
13508 /**
13509 * struct x86_init_paging - platform specific paging functions
13510 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13511 struct x86_init_paging {
13512 void (*pagetable_setup_start)(pgd_t *base);
13513 void (*pagetable_setup_done)(pgd_t *base);
13514 -};
13515 +} __no_const;
13516
13517 /**
13518 * struct x86_init_timers - platform specific timer setup
13519 @@ -102,7 +102,7 @@ struct x86_init_timers {
13520 void (*tsc_pre_init)(void);
13521 void (*timer_init)(void);
13522 void (*wallclock_init)(void);
13523 -};
13524 +} __no_const;
13525
13526 /**
13527 * struct x86_init_iommu - platform specific iommu setup
13528 @@ -110,7 +110,7 @@ struct x86_init_timers {
13529 */
13530 struct x86_init_iommu {
13531 int (*iommu_init)(void);
13532 -};
13533 +} __no_const;
13534
13535 /**
13536 * struct x86_init_pci - platform specific pci init functions
13537 @@ -124,7 +124,7 @@ struct x86_init_pci {
13538 int (*init)(void);
13539 void (*init_irq)(void);
13540 void (*fixup_irqs)(void);
13541 -};
13542 +} __no_const;
13543
13544 /**
13545 * struct x86_init_ops - functions for platform specific setup
13546 @@ -140,7 +140,7 @@ struct x86_init_ops {
13547 struct x86_init_timers timers;
13548 struct x86_init_iommu iommu;
13549 struct x86_init_pci pci;
13550 -};
13551 +} __no_const;
13552
13553 /**
13554 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13555 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13556 void (*setup_percpu_clockev)(void);
13557 void (*early_percpu_clock_init)(void);
13558 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13559 -};
13560 +} __no_const;
13561
13562 /**
13563 * struct x86_platform_ops - platform specific runtime functions
13564 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13565 int (*i8042_detect)(void);
13566 void (*save_sched_clock_state)(void);
13567 void (*restore_sched_clock_state)(void);
13568 -};
13569 +} __no_const;
13570
13571 struct pci_dev;
13572
13573 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13574 void (*teardown_msi_irq)(unsigned int irq);
13575 void (*teardown_msi_irqs)(struct pci_dev *dev);
13576 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13577 -};
13578 +} __no_const;
13579
13580 struct x86_io_apic_ops {
13581 void (*init) (void);
13582 unsigned int (*read) (unsigned int apic, unsigned int reg);
13583 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13584 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13585 -};
13586 +} __no_const;
13587
13588 extern struct x86_init_ops x86_init;
13589 extern struct x86_cpuinit_ops x86_cpuinit;
13590 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13591 index 8a1b6f9..a29c4e4 100644
13592 --- a/arch/x86/include/asm/xsave.h
13593 +++ b/arch/x86/include/asm/xsave.h
13594 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13595 {
13596 int err;
13597
13598 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13599 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13600 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13601 +#endif
13602 +
13603 /*
13604 * Clear the xsave header first, so that reserved fields are
13605 * initialized to zero.
13606 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13607 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13608 {
13609 int err;
13610 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13611 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13612 u32 lmask = mask;
13613 u32 hmask = mask >> 32;
13614
13615 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13616 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13617 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13618 +#endif
13619 +
13620 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13621 "2:\n"
13622 ".section .fixup,\"ax\"\n"
13623 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13624 index 95bf99de..de9235c 100644
13625 --- a/arch/x86/kernel/acpi/sleep.c
13626 +++ b/arch/x86/kernel/acpi/sleep.c
13627 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13628 #else /* CONFIG_64BIT */
13629 #ifdef CONFIG_SMP
13630 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13631 +
13632 + pax_open_kernel();
13633 early_gdt_descr.address =
13634 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13635 + pax_close_kernel();
13636 +
13637 initial_gs = per_cpu_offset(smp_processor_id());
13638 #endif
13639 initial_code = (unsigned long)wakeup_long64;
13640 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13641 index 7261083..5c12053 100644
13642 --- a/arch/x86/kernel/acpi/wakeup_32.S
13643 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13644 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13645 # and restore the stack ... but you need gdt for this to work
13646 movl saved_context_esp, %esp
13647
13648 - movl %cs:saved_magic, %eax
13649 - cmpl $0x12345678, %eax
13650 + cmpl $0x12345678, saved_magic
13651 jne bogus_magic
13652
13653 # jump to place where we left off
13654 - movl saved_eip, %eax
13655 - jmp *%eax
13656 + jmp *(saved_eip)
13657
13658 bogus_magic:
13659 jmp bogus_magic
13660 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13661 index 1f84794..e23f862 100644
13662 --- a/arch/x86/kernel/alternative.c
13663 +++ b/arch/x86/kernel/alternative.c
13664 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13665 */
13666 for (a = start; a < end; a++) {
13667 instr = (u8 *)&a->instr_offset + a->instr_offset;
13668 +
13669 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13670 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13671 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13672 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13673 +#endif
13674 +
13675 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13676 BUG_ON(a->replacementlen > a->instrlen);
13677 BUG_ON(a->instrlen > sizeof(insnbuf));
13678 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13679 for (poff = start; poff < end; poff++) {
13680 u8 *ptr = (u8 *)poff + *poff;
13681
13682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13683 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13684 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13685 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13686 +#endif
13687 +
13688 if (!*poff || ptr < text || ptr >= text_end)
13689 continue;
13690 /* turn DS segment override prefix into lock prefix */
13691 - if (*ptr == 0x3e)
13692 + if (*ktla_ktva(ptr) == 0x3e)
13693 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13694 };
13695 mutex_unlock(&text_mutex);
13696 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13697 for (poff = start; poff < end; poff++) {
13698 u8 *ptr = (u8 *)poff + *poff;
13699
13700 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13701 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13702 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13703 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13704 +#endif
13705 +
13706 if (!*poff || ptr < text || ptr >= text_end)
13707 continue;
13708 /* turn lock prefix into DS segment override prefix */
13709 - if (*ptr == 0xf0)
13710 + if (*ktla_ktva(ptr) == 0xf0)
13711 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13712 };
13713 mutex_unlock(&text_mutex);
13714 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13715
13716 BUG_ON(p->len > MAX_PATCH_LEN);
13717 /* prep the buffer with the original instructions */
13718 - memcpy(insnbuf, p->instr, p->len);
13719 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13720 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13721 (unsigned long)p->instr, p->len);
13722
13723 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13724 if (smp_alt_once)
13725 free_init_pages("SMP alternatives",
13726 (unsigned long)__smp_locks,
13727 - (unsigned long)__smp_locks_end);
13728 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13729
13730 restart_nmi();
13731 }
13732 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13733 * instructions. And on the local CPU you need to be protected again NMI or MCE
13734 * handlers seeing an inconsistent instruction while you patch.
13735 */
13736 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13737 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13738 size_t len)
13739 {
13740 unsigned long flags;
13741 local_irq_save(flags);
13742 - memcpy(addr, opcode, len);
13743 +
13744 + pax_open_kernel();
13745 + memcpy(ktla_ktva(addr), opcode, len);
13746 sync_core();
13747 + pax_close_kernel();
13748 +
13749 local_irq_restore(flags);
13750 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13751 that causes hangs on some VIA CPUs. */
13752 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13753 */
13754 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13755 {
13756 - unsigned long flags;
13757 - char *vaddr;
13758 + unsigned char *vaddr = ktla_ktva(addr);
13759 struct page *pages[2];
13760 - int i;
13761 + size_t i;
13762
13763 if (!core_kernel_text((unsigned long)addr)) {
13764 - pages[0] = vmalloc_to_page(addr);
13765 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13766 + pages[0] = vmalloc_to_page(vaddr);
13767 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13768 } else {
13769 - pages[0] = virt_to_page(addr);
13770 + pages[0] = virt_to_page(vaddr);
13771 WARN_ON(!PageReserved(pages[0]));
13772 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13773 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13774 }
13775 BUG_ON(!pages[0]);
13776 - local_irq_save(flags);
13777 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13778 - if (pages[1])
13779 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13780 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13781 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13782 - clear_fixmap(FIX_TEXT_POKE0);
13783 - if (pages[1])
13784 - clear_fixmap(FIX_TEXT_POKE1);
13785 - local_flush_tlb();
13786 - sync_core();
13787 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13788 - that causes hangs on some VIA CPUs. */
13789 + text_poke_early(addr, opcode, len);
13790 for (i = 0; i < len; i++)
13791 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13792 - local_irq_restore(flags);
13793 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13794 return addr;
13795 }
13796
13797 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13798 index 39a222e..85a7767 100644
13799 --- a/arch/x86/kernel/apic/apic.c
13800 +++ b/arch/x86/kernel/apic/apic.c
13801 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13802 /*
13803 * Debug level, exported for io_apic.c
13804 */
13805 -unsigned int apic_verbosity;
13806 +int apic_verbosity;
13807
13808 int pic_mode;
13809
13810 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13811 apic_write(APIC_ESR, 0);
13812 v1 = apic_read(APIC_ESR);
13813 ack_APIC_irq();
13814 - atomic_inc(&irq_err_count);
13815 + atomic_inc_unchecked(&irq_err_count);
13816
13817 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13818 smp_processor_id(), v0 , v1);
13819 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13820 index 5f0ff59..f9e01bc 100644
13821 --- a/arch/x86/kernel/apic/io_apic.c
13822 +++ b/arch/x86/kernel/apic/io_apic.c
13823 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13824 }
13825 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13826
13827 -void lock_vector_lock(void)
13828 +void lock_vector_lock(void) __acquires(vector_lock)
13829 {
13830 /* Used to the online set of cpus does not change
13831 * during assign_irq_vector.
13832 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13833 raw_spin_lock(&vector_lock);
13834 }
13835
13836 -void unlock_vector_lock(void)
13837 +void unlock_vector_lock(void) __releases(vector_lock)
13838 {
13839 raw_spin_unlock(&vector_lock);
13840 }
13841 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13842 ack_APIC_irq();
13843 }
13844
13845 -atomic_t irq_mis_count;
13846 +atomic_unchecked_t irq_mis_count;
13847
13848 #ifdef CONFIG_GENERIC_PENDING_IRQ
13849 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13850 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13851 * at the cpu.
13852 */
13853 if (!(v & (1 << (i & 0x1f)))) {
13854 - atomic_inc(&irq_mis_count);
13855 + atomic_inc_unchecked(&irq_mis_count);
13856
13857 eoi_ioapic_irq(irq, cfg);
13858 }
13859 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13860 index 07b0c0d..1df6f42 100644
13861 --- a/arch/x86/kernel/apm_32.c
13862 +++ b/arch/x86/kernel/apm_32.c
13863 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13864 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13865 * even though they are called in protected mode.
13866 */
13867 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13868 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13869 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13870
13871 static const char driver_version[] = "1.16ac"; /* no spaces */
13872 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13873 BUG_ON(cpu != 0);
13874 gdt = get_cpu_gdt_table(cpu);
13875 save_desc_40 = gdt[0x40 / 8];
13876 +
13877 + pax_open_kernel();
13878 gdt[0x40 / 8] = bad_bios_desc;
13879 + pax_close_kernel();
13880
13881 apm_irq_save(flags);
13882 APM_DO_SAVE_SEGS;
13883 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13884 &call->esi);
13885 APM_DO_RESTORE_SEGS;
13886 apm_irq_restore(flags);
13887 +
13888 + pax_open_kernel();
13889 gdt[0x40 / 8] = save_desc_40;
13890 + pax_close_kernel();
13891 +
13892 put_cpu();
13893
13894 return call->eax & 0xff;
13895 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13896 BUG_ON(cpu != 0);
13897 gdt = get_cpu_gdt_table(cpu);
13898 save_desc_40 = gdt[0x40 / 8];
13899 +
13900 + pax_open_kernel();
13901 gdt[0x40 / 8] = bad_bios_desc;
13902 + pax_close_kernel();
13903
13904 apm_irq_save(flags);
13905 APM_DO_SAVE_SEGS;
13906 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13907 &call->eax);
13908 APM_DO_RESTORE_SEGS;
13909 apm_irq_restore(flags);
13910 +
13911 + pax_open_kernel();
13912 gdt[0x40 / 8] = save_desc_40;
13913 + pax_close_kernel();
13914 +
13915 put_cpu();
13916 return error;
13917 }
13918 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13919 * code to that CPU.
13920 */
13921 gdt = get_cpu_gdt_table(0);
13922 +
13923 + pax_open_kernel();
13924 set_desc_base(&gdt[APM_CS >> 3],
13925 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13926 set_desc_base(&gdt[APM_CS_16 >> 3],
13927 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13928 set_desc_base(&gdt[APM_DS >> 3],
13929 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13930 + pax_close_kernel();
13931
13932 proc_create("apm", 0, NULL, &apm_file_ops);
13933
13934 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13935 index 68de2dc..1f3c720 100644
13936 --- a/arch/x86/kernel/asm-offsets.c
13937 +++ b/arch/x86/kernel/asm-offsets.c
13938 @@ -33,6 +33,8 @@ void common(void) {
13939 OFFSET(TI_status, thread_info, status);
13940 OFFSET(TI_addr_limit, thread_info, addr_limit);
13941 OFFSET(TI_preempt_count, thread_info, preempt_count);
13942 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13943 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13944
13945 BLANK();
13946 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13947 @@ -53,8 +55,26 @@ void common(void) {
13948 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13949 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13950 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13951 +
13952 +#ifdef CONFIG_PAX_KERNEXEC
13953 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13954 #endif
13955
13956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13957 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13958 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13959 +#ifdef CONFIG_X86_64
13960 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13961 +#endif
13962 +#endif
13963 +
13964 +#endif
13965 +
13966 + BLANK();
13967 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13968 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13969 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13970 +
13971 #ifdef CONFIG_XEN
13972 BLANK();
13973 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13974 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13975 index 1b4754f..fbb4227 100644
13976 --- a/arch/x86/kernel/asm-offsets_64.c
13977 +++ b/arch/x86/kernel/asm-offsets_64.c
13978 @@ -76,6 +76,7 @@ int main(void)
13979 BLANK();
13980 #undef ENTRY
13981
13982 + DEFINE(TSS_size, sizeof(struct tss_struct));
13983 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13984 BLANK();
13985
13986 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13987 index 6ab6aa2..8f71507 100644
13988 --- a/arch/x86/kernel/cpu/Makefile
13989 +++ b/arch/x86/kernel/cpu/Makefile
13990 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13991 CFLAGS_REMOVE_perf_event.o = -pg
13992 endif
13993
13994 -# Make sure load_percpu_segment has no stackprotector
13995 -nostackp := $(call cc-option, -fno-stack-protector)
13996 -CFLAGS_common.o := $(nostackp)
13997 -
13998 obj-y := intel_cacheinfo.o scattered.o topology.o
13999 obj-y += proc.o capflags.o powerflags.o common.o
14000 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14001 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14002 index 146bb62..ac9c74a 100644
14003 --- a/arch/x86/kernel/cpu/amd.c
14004 +++ b/arch/x86/kernel/cpu/amd.c
14005 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14006 unsigned int size)
14007 {
14008 /* AMD errata T13 (order #21922) */
14009 - if ((c->x86 == 6)) {
14010 + if (c->x86 == 6) {
14011 /* Duron Rev A0 */
14012 if (c->x86_model == 3 && c->x86_mask == 0)
14013 size = 64;
14014 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14015 index 6b9333b..4c3083a 100644
14016 --- a/arch/x86/kernel/cpu/common.c
14017 +++ b/arch/x86/kernel/cpu/common.c
14018 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14019
14020 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14021
14022 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14023 -#ifdef CONFIG_X86_64
14024 - /*
14025 - * We need valid kernel segments for data and code in long mode too
14026 - * IRET will check the segment types kkeil 2000/10/28
14027 - * Also sysret mandates a special GDT layout
14028 - *
14029 - * TLS descriptors are currently at a different place compared to i386.
14030 - * Hopefully nobody expects them at a fixed place (Wine?)
14031 - */
14032 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14033 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14034 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14035 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14036 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14037 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14038 -#else
14039 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14040 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14041 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14042 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14043 - /*
14044 - * Segments used for calling PnP BIOS have byte granularity.
14045 - * They code segments and data segments have fixed 64k limits,
14046 - * the transfer segment sizes are set at run time.
14047 - */
14048 - /* 32-bit code */
14049 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14050 - /* 16-bit code */
14051 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14052 - /* 16-bit data */
14053 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14054 - /* 16-bit data */
14055 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14056 - /* 16-bit data */
14057 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14058 - /*
14059 - * The APM segments have byte granularity and their bases
14060 - * are set at run time. All have 64k limits.
14061 - */
14062 - /* 32-bit code */
14063 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14064 - /* 16-bit code */
14065 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14066 - /* data */
14067 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14068 -
14069 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14070 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14071 - GDT_STACK_CANARY_INIT
14072 -#endif
14073 -} };
14074 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14075 -
14076 static int __init x86_xsave_setup(char *s)
14077 {
14078 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14079 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14080 {
14081 struct desc_ptr gdt_descr;
14082
14083 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14084 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14085 gdt_descr.size = GDT_SIZE - 1;
14086 load_gdt(&gdt_descr);
14087 /* Reload the per-cpu base */
14088 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14089 /* Filter out anything that depends on CPUID levels we don't have */
14090 filter_cpuid_features(c, true);
14091
14092 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14093 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14094 +#endif
14095 +
14096 /* If the model name is still unset, do table lookup. */
14097 if (!c->x86_model_id[0]) {
14098 const char *p;
14099 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14100 }
14101 __setup("clearcpuid=", setup_disablecpuid);
14102
14103 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14104 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14105 +
14106 #ifdef CONFIG_X86_64
14107 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14108 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14109 - (unsigned long) nmi_idt_table };
14110 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14111
14112 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14113 irq_stack_union) __aligned(PAGE_SIZE);
14114 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14115 EXPORT_PER_CPU_SYMBOL(current_task);
14116
14117 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14118 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14119 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14120 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14121
14122 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14123 @@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14124 {
14125 memset(regs, 0, sizeof(struct pt_regs));
14126 regs->fs = __KERNEL_PERCPU;
14127 - regs->gs = __KERNEL_STACK_CANARY;
14128 + savesegment(gs, regs->gs);
14129
14130 return regs;
14131 }
14132 @@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14133 int i;
14134
14135 cpu = stack_smp_processor_id();
14136 - t = &per_cpu(init_tss, cpu);
14137 + t = init_tss + cpu;
14138 oist = &per_cpu(orig_ist, cpu);
14139
14140 #ifdef CONFIG_NUMA
14141 @@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14142 switch_to_new_gdt(cpu);
14143 loadsegment(fs, 0);
14144
14145 - load_idt((const struct desc_ptr *)&idt_descr);
14146 + load_idt(&idt_descr);
14147
14148 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14149 syscall_init();
14150 @@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14151 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14152 barrier();
14153
14154 - x86_configure_nx();
14155 if (cpu != 0)
14156 enable_x2apic();
14157
14158 @@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14159 {
14160 int cpu = smp_processor_id();
14161 struct task_struct *curr = current;
14162 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14163 + struct tss_struct *t = init_tss + cpu;
14164 struct thread_struct *thread = &curr->thread;
14165
14166 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14167 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14168 index 3e6ff6c..54b4992 100644
14169 --- a/arch/x86/kernel/cpu/intel.c
14170 +++ b/arch/x86/kernel/cpu/intel.c
14171 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14172 * Update the IDT descriptor and reload the IDT so that
14173 * it uses the read-only mapped virtual address.
14174 */
14175 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14176 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14177 load_idt(&idt_descr);
14178 }
14179 #endif
14180 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14181 index da27c5d..569e359 100644
14182 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14183 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14184 @@ -42,6 +42,7 @@
14185 #include <asm/processor.h>
14186 #include <asm/mce.h>
14187 #include <asm/msr.h>
14188 +#include <asm/local.h>
14189
14190 #include "mce-internal.h"
14191
14192 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14193 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14194 m->cs, m->ip);
14195
14196 - if (m->cs == __KERNEL_CS)
14197 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14198 print_symbol("{%s}", m->ip);
14199 pr_cont("\n");
14200 }
14201 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14202
14203 #define PANIC_TIMEOUT 5 /* 5 seconds */
14204
14205 -static atomic_t mce_paniced;
14206 +static atomic_unchecked_t mce_paniced;
14207
14208 static int fake_panic;
14209 -static atomic_t mce_fake_paniced;
14210 +static atomic_unchecked_t mce_fake_paniced;
14211
14212 /* Panic in progress. Enable interrupts and wait for final IPI */
14213 static void wait_for_panic(void)
14214 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14215 /*
14216 * Make sure only one CPU runs in machine check panic
14217 */
14218 - if (atomic_inc_return(&mce_paniced) > 1)
14219 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14220 wait_for_panic();
14221 barrier();
14222
14223 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14224 console_verbose();
14225 } else {
14226 /* Don't log too much for fake panic */
14227 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14228 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14229 return;
14230 }
14231 /* First print corrected ones that are still unlogged */
14232 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14233 * might have been modified by someone else.
14234 */
14235 rmb();
14236 - if (atomic_read(&mce_paniced))
14237 + if (atomic_read_unchecked(&mce_paniced))
14238 wait_for_panic();
14239 if (!monarch_timeout)
14240 goto out;
14241 @@ -1579,7 +1580,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14242 }
14243
14244 /* Call the installed machine check handler for this CPU setup. */
14245 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14246 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14247 unexpected_machine_check;
14248
14249 /*
14250 @@ -1602,7 +1603,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14251 return;
14252 }
14253
14254 + pax_open_kernel();
14255 machine_check_vector = do_machine_check;
14256 + pax_close_kernel();
14257
14258 __mcheck_cpu_init_generic();
14259 __mcheck_cpu_init_vendor(c);
14260 @@ -1616,7 +1619,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14261 */
14262
14263 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14264 -static int mce_chrdev_open_count; /* #times opened */
14265 +static local_t mce_chrdev_open_count; /* #times opened */
14266 static int mce_chrdev_open_exclu; /* already open exclusive? */
14267
14268 static int mce_chrdev_open(struct inode *inode, struct file *file)
14269 @@ -1624,7 +1627,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14270 spin_lock(&mce_chrdev_state_lock);
14271
14272 if (mce_chrdev_open_exclu ||
14273 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14274 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14275 spin_unlock(&mce_chrdev_state_lock);
14276
14277 return -EBUSY;
14278 @@ -1632,7 +1635,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14279
14280 if (file->f_flags & O_EXCL)
14281 mce_chrdev_open_exclu = 1;
14282 - mce_chrdev_open_count++;
14283 + local_inc(&mce_chrdev_open_count);
14284
14285 spin_unlock(&mce_chrdev_state_lock);
14286
14287 @@ -1643,7 +1646,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14288 {
14289 spin_lock(&mce_chrdev_state_lock);
14290
14291 - mce_chrdev_open_count--;
14292 + local_dec(&mce_chrdev_open_count);
14293 mce_chrdev_open_exclu = 0;
14294
14295 spin_unlock(&mce_chrdev_state_lock);
14296 @@ -2368,7 +2371,7 @@ struct dentry *mce_get_debugfs_dir(void)
14297 static void mce_reset(void)
14298 {
14299 cpu_missing = 0;
14300 - atomic_set(&mce_fake_paniced, 0);
14301 + atomic_set_unchecked(&mce_fake_paniced, 0);
14302 atomic_set(&mce_executing, 0);
14303 atomic_set(&mce_callin, 0);
14304 atomic_set(&global_nwo, 0);
14305 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14306 index 2d5454c..51987eb 100644
14307 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14308 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14309 @@ -11,6 +11,7 @@
14310 #include <asm/processor.h>
14311 #include <asm/mce.h>
14312 #include <asm/msr.h>
14313 +#include <asm/pgtable.h>
14314
14315 /* By default disabled */
14316 int mce_p5_enabled __read_mostly;
14317 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14318 if (!cpu_has(c, X86_FEATURE_MCE))
14319 return;
14320
14321 + pax_open_kernel();
14322 machine_check_vector = pentium_machine_check;
14323 + pax_close_kernel();
14324 /* Make sure the vector pointer is visible before we enable MCEs: */
14325 wmb();
14326
14327 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14328 index 2d7998f..17c9de1 100644
14329 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14330 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14331 @@ -10,6 +10,7 @@
14332 #include <asm/processor.h>
14333 #include <asm/mce.h>
14334 #include <asm/msr.h>
14335 +#include <asm/pgtable.h>
14336
14337 /* Machine check handler for WinChip C6: */
14338 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14339 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14340 {
14341 u32 lo, hi;
14342
14343 + pax_open_kernel();
14344 machine_check_vector = winchip_machine_check;
14345 + pax_close_kernel();
14346 /* Make sure the vector pointer is visible before we enable MCEs: */
14347 wmb();
14348
14349 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14350 index 6b96110..0da73eb 100644
14351 --- a/arch/x86/kernel/cpu/mtrr/main.c
14352 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14353 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14354 u64 size_or_mask, size_and_mask;
14355 static bool mtrr_aps_delayed_init;
14356
14357 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14358 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14359
14360 const struct mtrr_ops *mtrr_if;
14361
14362 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14363 index df5e41f..816c719 100644
14364 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14365 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14366 @@ -25,7 +25,7 @@ struct mtrr_ops {
14367 int (*validate_add_page)(unsigned long base, unsigned long size,
14368 unsigned int type);
14369 int (*have_wrcomb)(void);
14370 -};
14371 +} __do_const;
14372
14373 extern int generic_get_free_region(unsigned long base, unsigned long size,
14374 int replace_reg);
14375 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14376 index c4706cf..264b0f7 100644
14377 --- a/arch/x86/kernel/cpu/perf_event.c
14378 +++ b/arch/x86/kernel/cpu/perf_event.c
14379 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14380 break;
14381
14382 perf_callchain_store(entry, frame.return_address);
14383 - fp = frame.next_frame;
14384 + fp = (const void __force_user *)frame.next_frame;
14385 }
14386 }
14387
14388 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14389 index 13ad899..f642b9a 100644
14390 --- a/arch/x86/kernel/crash.c
14391 +++ b/arch/x86/kernel/crash.c
14392 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14393 {
14394 #ifdef CONFIG_X86_32
14395 struct pt_regs fixed_regs;
14396 -#endif
14397
14398 -#ifdef CONFIG_X86_32
14399 - if (!user_mode_vm(regs)) {
14400 + if (!user_mode(regs)) {
14401 crash_fixup_ss_esp(&fixed_regs, regs);
14402 regs = &fixed_regs;
14403 }
14404 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14405 index 37250fe..bf2ec74 100644
14406 --- a/arch/x86/kernel/doublefault_32.c
14407 +++ b/arch/x86/kernel/doublefault_32.c
14408 @@ -11,7 +11,7 @@
14409
14410 #define DOUBLEFAULT_STACKSIZE (1024)
14411 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14412 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14413 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14414
14415 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14416
14417 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14418 unsigned long gdt, tss;
14419
14420 store_gdt(&gdt_desc);
14421 - gdt = gdt_desc.address;
14422 + gdt = (unsigned long)gdt_desc.address;
14423
14424 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14425
14426 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14427 /* 0x2 bit is always set */
14428 .flags = X86_EFLAGS_SF | 0x2,
14429 .sp = STACK_START,
14430 - .es = __USER_DS,
14431 + .es = __KERNEL_DS,
14432 .cs = __KERNEL_CS,
14433 .ss = __KERNEL_DS,
14434 - .ds = __USER_DS,
14435 + .ds = __KERNEL_DS,
14436 .fs = __KERNEL_PERCPU,
14437
14438 .__cr3 = __pa_nodebug(swapper_pg_dir),
14439 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14440 index 571246d..81f335c 100644
14441 --- a/arch/x86/kernel/dumpstack.c
14442 +++ b/arch/x86/kernel/dumpstack.c
14443 @@ -2,6 +2,9 @@
14444 * Copyright (C) 1991, 1992 Linus Torvalds
14445 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14446 */
14447 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14448 +#define __INCLUDED_BY_HIDESYM 1
14449 +#endif
14450 #include <linux/kallsyms.h>
14451 #include <linux/kprobes.h>
14452 #include <linux/uaccess.h>
14453 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14454 static void
14455 print_ftrace_graph_addr(unsigned long addr, void *data,
14456 const struct stacktrace_ops *ops,
14457 - struct thread_info *tinfo, int *graph)
14458 + struct task_struct *task, int *graph)
14459 {
14460 - struct task_struct *task;
14461 unsigned long ret_addr;
14462 int index;
14463
14464 if (addr != (unsigned long)return_to_handler)
14465 return;
14466
14467 - task = tinfo->task;
14468 index = task->curr_ret_stack;
14469
14470 if (!task->ret_stack || index < *graph)
14471 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14472 static inline void
14473 print_ftrace_graph_addr(unsigned long addr, void *data,
14474 const struct stacktrace_ops *ops,
14475 - struct thread_info *tinfo, int *graph)
14476 + struct task_struct *task, int *graph)
14477 { }
14478 #endif
14479
14480 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14481 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14482 */
14483
14484 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14485 - void *p, unsigned int size, void *end)
14486 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14487 {
14488 - void *t = tinfo;
14489 if (end) {
14490 if (p < end && p >= (end-THREAD_SIZE))
14491 return 1;
14492 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14493 }
14494
14495 unsigned long
14496 -print_context_stack(struct thread_info *tinfo,
14497 +print_context_stack(struct task_struct *task, void *stack_start,
14498 unsigned long *stack, unsigned long bp,
14499 const struct stacktrace_ops *ops, void *data,
14500 unsigned long *end, int *graph)
14501 {
14502 struct stack_frame *frame = (struct stack_frame *)bp;
14503
14504 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14505 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14506 unsigned long addr;
14507
14508 addr = *stack;
14509 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14510 } else {
14511 ops->address(data, addr, 0);
14512 }
14513 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14514 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14515 }
14516 stack++;
14517 }
14518 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14519 EXPORT_SYMBOL_GPL(print_context_stack);
14520
14521 unsigned long
14522 -print_context_stack_bp(struct thread_info *tinfo,
14523 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14524 unsigned long *stack, unsigned long bp,
14525 const struct stacktrace_ops *ops, void *data,
14526 unsigned long *end, int *graph)
14527 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14528 struct stack_frame *frame = (struct stack_frame *)bp;
14529 unsigned long *ret_addr = &frame->return_address;
14530
14531 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14532 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14533 unsigned long addr = *ret_addr;
14534
14535 if (!__kernel_text_address(addr))
14536 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14537 ops->address(data, addr, 1);
14538 frame = frame->next_frame;
14539 ret_addr = &frame->return_address;
14540 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14541 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14542 }
14543
14544 return (unsigned long)frame;
14545 @@ -189,7 +188,7 @@ void dump_stack(void)
14546
14547 bp = stack_frame(current, NULL);
14548 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14549 - current->pid, current->comm, print_tainted(),
14550 + task_pid_nr(current), current->comm, print_tainted(),
14551 init_utsname()->release,
14552 (int)strcspn(init_utsname()->version, " "),
14553 init_utsname()->version);
14554 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14555 }
14556 EXPORT_SYMBOL_GPL(oops_begin);
14557
14558 +extern void gr_handle_kernel_exploit(void);
14559 +
14560 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14561 {
14562 if (regs && kexec_should_crash(current))
14563 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14564 panic("Fatal exception in interrupt");
14565 if (panic_on_oops)
14566 panic("Fatal exception");
14567 - do_exit(signr);
14568 +
14569 + gr_handle_kernel_exploit();
14570 +
14571 + do_group_exit(signr);
14572 }
14573
14574 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14575 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14576
14577 show_regs(regs);
14578 #ifdef CONFIG_X86_32
14579 - if (user_mode_vm(regs)) {
14580 + if (user_mode(regs)) {
14581 sp = regs->sp;
14582 ss = regs->ss & 0xffff;
14583 } else {
14584 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14585 unsigned long flags = oops_begin();
14586 int sig = SIGSEGV;
14587
14588 - if (!user_mode_vm(regs))
14589 + if (!user_mode(regs))
14590 report_bug(regs->ip, regs);
14591
14592 if (__die(str, regs, err))
14593 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14594 index e0b1d78..a8ade5e 100644
14595 --- a/arch/x86/kernel/dumpstack_32.c
14596 +++ b/arch/x86/kernel/dumpstack_32.c
14597 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14598 bp = stack_frame(task, regs);
14599
14600 for (;;) {
14601 - struct thread_info *context;
14602 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14603
14604 - context = (struct thread_info *)
14605 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14606 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14607 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14608
14609 - stack = (unsigned long *)context->previous_esp;
14610 - if (!stack)
14611 + if (stack_start == task_stack_page(task))
14612 break;
14613 + stack = *(unsigned long **)stack_start;
14614 if (ops->stack(data, "IRQ") < 0)
14615 break;
14616 touch_nmi_watchdog();
14617 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14618 int i;
14619
14620 print_modules();
14621 - __show_regs(regs, !user_mode_vm(regs));
14622 + __show_regs(regs, !user_mode(regs));
14623
14624 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14625 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14626 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14627 * When in-kernel, we also print out the stack and code at the
14628 * time of the fault..
14629 */
14630 - if (!user_mode_vm(regs)) {
14631 + if (!user_mode(regs)) {
14632 unsigned int code_prologue = code_bytes * 43 / 64;
14633 unsigned int code_len = code_bytes;
14634 unsigned char c;
14635 u8 *ip;
14636 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14637
14638 printk(KERN_EMERG "Stack:\n");
14639 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14640
14641 printk(KERN_EMERG "Code: ");
14642
14643 - ip = (u8 *)regs->ip - code_prologue;
14644 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14645 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14646 /* try starting at IP */
14647 - ip = (u8 *)regs->ip;
14648 + ip = (u8 *)regs->ip + cs_base;
14649 code_len = code_len - code_prologue + 1;
14650 }
14651 for (i = 0; i < code_len; i++, ip++) {
14652 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14653 printk(KERN_CONT " Bad EIP value.");
14654 break;
14655 }
14656 - if (ip == (u8 *)regs->ip)
14657 + if (ip == (u8 *)regs->ip + cs_base)
14658 printk(KERN_CONT "<%02x> ", c);
14659 else
14660 printk(KERN_CONT "%02x ", c);
14661 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14662 {
14663 unsigned short ud2;
14664
14665 + ip = ktla_ktva(ip);
14666 if (ip < PAGE_OFFSET)
14667 return 0;
14668 if (probe_kernel_address((unsigned short *)ip, ud2))
14669 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14670
14671 return ud2 == 0x0b0f;
14672 }
14673 +
14674 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14675 +void pax_check_alloca(unsigned long size)
14676 +{
14677 + unsigned long sp = (unsigned long)&sp, stack_left;
14678 +
14679 + /* all kernel stacks are of the same size */
14680 + stack_left = sp & (THREAD_SIZE - 1);
14681 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14682 +}
14683 +EXPORT_SYMBOL(pax_check_alloca);
14684 +#endif
14685 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14686 index 791b761..2ab6e33 100644
14687 --- a/arch/x86/kernel/dumpstack_64.c
14688 +++ b/arch/x86/kernel/dumpstack_64.c
14689 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14690 unsigned long *irq_stack_end =
14691 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14692 unsigned used = 0;
14693 - struct thread_info *tinfo;
14694 int graph = 0;
14695 unsigned long dummy;
14696 + void *stack_start;
14697
14698 if (!task)
14699 task = current;
14700 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14701 * current stack address. If the stacks consist of nested
14702 * exceptions
14703 */
14704 - tinfo = task_thread_info(task);
14705 for (;;) {
14706 char *id;
14707 unsigned long *estack_end;
14708 +
14709 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14710 &used, &id);
14711
14712 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14713 if (ops->stack(data, id) < 0)
14714 break;
14715
14716 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14717 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14718 data, estack_end, &graph);
14719 ops->stack(data, "<EOE>");
14720 /*
14721 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14722 * second-to-last pointer (index -2 to end) in the
14723 * exception stack:
14724 */
14725 + if ((u16)estack_end[-1] != __KERNEL_DS)
14726 + goto out;
14727 stack = (unsigned long *) estack_end[-2];
14728 continue;
14729 }
14730 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14731 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14732 if (ops->stack(data, "IRQ") < 0)
14733 break;
14734 - bp = ops->walk_stack(tinfo, stack, bp,
14735 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14736 ops, data, irq_stack_end, &graph);
14737 /*
14738 * We link to the next stack (which would be
14739 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14740 /*
14741 * This handles the process stack:
14742 */
14743 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14744 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14745 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14746 +out:
14747 put_cpu();
14748 }
14749 EXPORT_SYMBOL(dump_trace);
14750 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14751
14752 return ud2 == 0x0b0f;
14753 }
14754 +
14755 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14756 +void pax_check_alloca(unsigned long size)
14757 +{
14758 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14759 + unsigned cpu, used;
14760 + char *id;
14761 +
14762 + /* check the process stack first */
14763 + stack_start = (unsigned long)task_stack_page(current);
14764 + stack_end = stack_start + THREAD_SIZE;
14765 + if (likely(stack_start <= sp && sp < stack_end)) {
14766 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14767 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14768 + return;
14769 + }
14770 +
14771 + cpu = get_cpu();
14772 +
14773 + /* check the irq stacks */
14774 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14775 + stack_start = stack_end - IRQ_STACK_SIZE;
14776 + if (stack_start <= sp && sp < stack_end) {
14777 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14778 + put_cpu();
14779 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14780 + return;
14781 + }
14782 +
14783 + /* check the exception stacks */
14784 + used = 0;
14785 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14786 + stack_start = stack_end - EXCEPTION_STKSZ;
14787 + if (stack_end && stack_start <= sp && sp < stack_end) {
14788 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14789 + put_cpu();
14790 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14791 + return;
14792 + }
14793 +
14794 + put_cpu();
14795 +
14796 + /* unknown stack */
14797 + BUG();
14798 +}
14799 +EXPORT_SYMBOL(pax_check_alloca);
14800 +#endif
14801 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14802 index 9b9f18b..9fcaa04 100644
14803 --- a/arch/x86/kernel/early_printk.c
14804 +++ b/arch/x86/kernel/early_printk.c
14805 @@ -7,6 +7,7 @@
14806 #include <linux/pci_regs.h>
14807 #include <linux/pci_ids.h>
14808 #include <linux/errno.h>
14809 +#include <linux/sched.h>
14810 #include <asm/io.h>
14811 #include <asm/processor.h>
14812 #include <asm/fcntl.h>
14813 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14814 index 623f288..0683156 100644
14815 --- a/arch/x86/kernel/entry_32.S
14816 +++ b/arch/x86/kernel/entry_32.S
14817 @@ -176,13 +176,146 @@
14818 /*CFI_REL_OFFSET gs, PT_GS*/
14819 .endm
14820 .macro SET_KERNEL_GS reg
14821 +
14822 +#ifdef CONFIG_CC_STACKPROTECTOR
14823 movl $(__KERNEL_STACK_CANARY), \reg
14824 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14825 + movl $(__USER_DS), \reg
14826 +#else
14827 + xorl \reg, \reg
14828 +#endif
14829 +
14830 movl \reg, %gs
14831 .endm
14832
14833 #endif /* CONFIG_X86_32_LAZY_GS */
14834
14835 -.macro SAVE_ALL
14836 +.macro pax_enter_kernel
14837 +#ifdef CONFIG_PAX_KERNEXEC
14838 + call pax_enter_kernel
14839 +#endif
14840 +.endm
14841 +
14842 +.macro pax_exit_kernel
14843 +#ifdef CONFIG_PAX_KERNEXEC
14844 + call pax_exit_kernel
14845 +#endif
14846 +.endm
14847 +
14848 +#ifdef CONFIG_PAX_KERNEXEC
14849 +ENTRY(pax_enter_kernel)
14850 +#ifdef CONFIG_PARAVIRT
14851 + pushl %eax
14852 + pushl %ecx
14853 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14854 + mov %eax, %esi
14855 +#else
14856 + mov %cr0, %esi
14857 +#endif
14858 + bts $16, %esi
14859 + jnc 1f
14860 + mov %cs, %esi
14861 + cmp $__KERNEL_CS, %esi
14862 + jz 3f
14863 + ljmp $__KERNEL_CS, $3f
14864 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14865 +2:
14866 +#ifdef CONFIG_PARAVIRT
14867 + mov %esi, %eax
14868 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14869 +#else
14870 + mov %esi, %cr0
14871 +#endif
14872 +3:
14873 +#ifdef CONFIG_PARAVIRT
14874 + popl %ecx
14875 + popl %eax
14876 +#endif
14877 + ret
14878 +ENDPROC(pax_enter_kernel)
14879 +
14880 +ENTRY(pax_exit_kernel)
14881 +#ifdef CONFIG_PARAVIRT
14882 + pushl %eax
14883 + pushl %ecx
14884 +#endif
14885 + mov %cs, %esi
14886 + cmp $__KERNEXEC_KERNEL_CS, %esi
14887 + jnz 2f
14888 +#ifdef CONFIG_PARAVIRT
14889 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14890 + mov %eax, %esi
14891 +#else
14892 + mov %cr0, %esi
14893 +#endif
14894 + btr $16, %esi
14895 + ljmp $__KERNEL_CS, $1f
14896 +1:
14897 +#ifdef CONFIG_PARAVIRT
14898 + mov %esi, %eax
14899 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14900 +#else
14901 + mov %esi, %cr0
14902 +#endif
14903 +2:
14904 +#ifdef CONFIG_PARAVIRT
14905 + popl %ecx
14906 + popl %eax
14907 +#endif
14908 + ret
14909 +ENDPROC(pax_exit_kernel)
14910 +#endif
14911 +
14912 +.macro pax_erase_kstack
14913 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14914 + call pax_erase_kstack
14915 +#endif
14916 +.endm
14917 +
14918 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14919 +/*
14920 + * ebp: thread_info
14921 + * ecx, edx: can be clobbered
14922 + */
14923 +ENTRY(pax_erase_kstack)
14924 + pushl %edi
14925 + pushl %eax
14926 +
14927 + mov TI_lowest_stack(%ebp), %edi
14928 + mov $-0xBEEF, %eax
14929 + std
14930 +
14931 +1: mov %edi, %ecx
14932 + and $THREAD_SIZE_asm - 1, %ecx
14933 + shr $2, %ecx
14934 + repne scasl
14935 + jecxz 2f
14936 +
14937 + cmp $2*16, %ecx
14938 + jc 2f
14939 +
14940 + mov $2*16, %ecx
14941 + repe scasl
14942 + jecxz 2f
14943 + jne 1b
14944 +
14945 +2: cld
14946 + mov %esp, %ecx
14947 + sub %edi, %ecx
14948 + shr $2, %ecx
14949 + rep stosl
14950 +
14951 + mov TI_task_thread_sp0(%ebp), %edi
14952 + sub $128, %edi
14953 + mov %edi, TI_lowest_stack(%ebp)
14954 +
14955 + popl %eax
14956 + popl %edi
14957 + ret
14958 +ENDPROC(pax_erase_kstack)
14959 +#endif
14960 +
14961 +.macro __SAVE_ALL _DS
14962 cld
14963 PUSH_GS
14964 pushl_cfi %fs
14965 @@ -205,7 +338,7 @@
14966 CFI_REL_OFFSET ecx, 0
14967 pushl_cfi %ebx
14968 CFI_REL_OFFSET ebx, 0
14969 - movl $(__USER_DS), %edx
14970 + movl $\_DS, %edx
14971 movl %edx, %ds
14972 movl %edx, %es
14973 movl $(__KERNEL_PERCPU), %edx
14974 @@ -213,6 +346,15 @@
14975 SET_KERNEL_GS %edx
14976 .endm
14977
14978 +.macro SAVE_ALL
14979 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14980 + __SAVE_ALL __KERNEL_DS
14981 + pax_enter_kernel
14982 +#else
14983 + __SAVE_ALL __USER_DS
14984 +#endif
14985 +.endm
14986 +
14987 .macro RESTORE_INT_REGS
14988 popl_cfi %ebx
14989 CFI_RESTORE ebx
14990 @@ -296,7 +438,7 @@ ENTRY(ret_from_fork)
14991 popfl_cfi
14992 jmp syscall_exit
14993 CFI_ENDPROC
14994 -END(ret_from_fork)
14995 +ENDPROC(ret_from_fork)
14996
14997 /*
14998 * Interrupt exit functions should be protected against kprobes
14999 @@ -329,7 +471,15 @@ ret_from_intr:
15000 andl $SEGMENT_RPL_MASK, %eax
15001 #endif
15002 cmpl $USER_RPL, %eax
15003 +
15004 +#ifdef CONFIG_PAX_KERNEXEC
15005 + jae resume_userspace
15006 +
15007 + pax_exit_kernel
15008 + jmp resume_kernel
15009 +#else
15010 jb resume_kernel # not returning to v8086 or userspace
15011 +#endif
15012
15013 ENTRY(resume_userspace)
15014 LOCKDEP_SYS_EXIT
15015 @@ -341,8 +491,8 @@ ENTRY(resume_userspace)
15016 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15017 # int/exception return?
15018 jne work_pending
15019 - jmp restore_all
15020 -END(ret_from_exception)
15021 + jmp restore_all_pax
15022 +ENDPROC(ret_from_exception)
15023
15024 #ifdef CONFIG_PREEMPT
15025 ENTRY(resume_kernel)
15026 @@ -357,7 +507,7 @@ need_resched:
15027 jz restore_all
15028 call preempt_schedule_irq
15029 jmp need_resched
15030 -END(resume_kernel)
15031 +ENDPROC(resume_kernel)
15032 #endif
15033 CFI_ENDPROC
15034 /*
15035 @@ -391,23 +541,34 @@ sysenter_past_esp:
15036 /*CFI_REL_OFFSET cs, 0*/
15037 /*
15038 * Push current_thread_info()->sysenter_return to the stack.
15039 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15040 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15041 */
15042 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15043 + pushl_cfi $0
15044 CFI_REL_OFFSET eip, 0
15045
15046 pushl_cfi %eax
15047 SAVE_ALL
15048 + GET_THREAD_INFO(%ebp)
15049 + movl TI_sysenter_return(%ebp),%ebp
15050 + movl %ebp,PT_EIP(%esp)
15051 ENABLE_INTERRUPTS(CLBR_NONE)
15052
15053 /*
15054 * Load the potential sixth argument from user stack.
15055 * Careful about security.
15056 */
15057 + movl PT_OLDESP(%esp),%ebp
15058 +
15059 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15060 + mov PT_OLDSS(%esp),%ds
15061 +1: movl %ds:(%ebp),%ebp
15062 + push %ss
15063 + pop %ds
15064 +#else
15065 cmpl $__PAGE_OFFSET-3,%ebp
15066 jae syscall_fault
15067 1: movl (%ebp),%ebp
15068 +#endif
15069 +
15070 movl %ebp,PT_EBP(%esp)
15071 _ASM_EXTABLE(1b,syscall_fault)
15072
15073 @@ -427,12 +588,24 @@ sysenter_do_call:
15074 testl $_TIF_ALLWORK_MASK, %ecx
15075 jne sysexit_audit
15076 sysenter_exit:
15077 +
15078 +#ifdef CONFIG_PAX_RANDKSTACK
15079 + pushl_cfi %eax
15080 + movl %esp, %eax
15081 + call pax_randomize_kstack
15082 + popl_cfi %eax
15083 +#endif
15084 +
15085 + pax_erase_kstack
15086 +
15087 /* if something modifies registers it must also disable sysexit */
15088 movl PT_EIP(%esp), %edx
15089 movl PT_OLDESP(%esp), %ecx
15090 xorl %ebp,%ebp
15091 TRACE_IRQS_ON
15092 1: mov PT_FS(%esp), %fs
15093 +2: mov PT_DS(%esp), %ds
15094 +3: mov PT_ES(%esp), %es
15095 PTGS_TO_GS
15096 ENABLE_INTERRUPTS_SYSEXIT
15097
15098 @@ -449,6 +622,9 @@ sysenter_audit:
15099 movl %eax,%edx /* 2nd arg: syscall number */
15100 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15101 call __audit_syscall_entry
15102 +
15103 + pax_erase_kstack
15104 +
15105 pushl_cfi %ebx
15106 movl PT_EAX(%esp),%eax /* reload syscall number */
15107 jmp sysenter_do_call
15108 @@ -474,10 +650,16 @@ sysexit_audit:
15109
15110 CFI_ENDPROC
15111 .pushsection .fixup,"ax"
15112 -2: movl $0,PT_FS(%esp)
15113 +4: movl $0,PT_FS(%esp)
15114 + jmp 1b
15115 +5: movl $0,PT_DS(%esp)
15116 + jmp 1b
15117 +6: movl $0,PT_ES(%esp)
15118 jmp 1b
15119 .popsection
15120 - _ASM_EXTABLE(1b,2b)
15121 + _ASM_EXTABLE(1b,4b)
15122 + _ASM_EXTABLE(2b,5b)
15123 + _ASM_EXTABLE(3b,6b)
15124 PTGS_TO_GS_EX
15125 ENDPROC(ia32_sysenter_target)
15126
15127 @@ -509,6 +691,15 @@ syscall_exit:
15128 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15129 jne syscall_exit_work
15130
15131 +restore_all_pax:
15132 +
15133 +#ifdef CONFIG_PAX_RANDKSTACK
15134 + movl %esp, %eax
15135 + call pax_randomize_kstack
15136 +#endif
15137 +
15138 + pax_erase_kstack
15139 +
15140 restore_all:
15141 TRACE_IRQS_IRET
15142 restore_all_notrace:
15143 @@ -565,14 +756,34 @@ ldt_ss:
15144 * compensating for the offset by changing to the ESPFIX segment with
15145 * a base address that matches for the difference.
15146 */
15147 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15148 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15149 mov %esp, %edx /* load kernel esp */
15150 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15151 mov %dx, %ax /* eax: new kernel esp */
15152 sub %eax, %edx /* offset (low word is 0) */
15153 +#ifdef CONFIG_SMP
15154 + movl PER_CPU_VAR(cpu_number), %ebx
15155 + shll $PAGE_SHIFT_asm, %ebx
15156 + addl $cpu_gdt_table, %ebx
15157 +#else
15158 + movl $cpu_gdt_table, %ebx
15159 +#endif
15160 shr $16, %edx
15161 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15162 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15163 +
15164 +#ifdef CONFIG_PAX_KERNEXEC
15165 + mov %cr0, %esi
15166 + btr $16, %esi
15167 + mov %esi, %cr0
15168 +#endif
15169 +
15170 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15171 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15172 +
15173 +#ifdef CONFIG_PAX_KERNEXEC
15174 + bts $16, %esi
15175 + mov %esi, %cr0
15176 +#endif
15177 +
15178 pushl_cfi $__ESPFIX_SS
15179 pushl_cfi %eax /* new kernel esp */
15180 /* Disable interrupts, but do not irqtrace this section: we
15181 @@ -601,35 +812,23 @@ work_resched:
15182 movl TI_flags(%ebp), %ecx
15183 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15184 # than syscall tracing?
15185 - jz restore_all
15186 + jz restore_all_pax
15187 testb $_TIF_NEED_RESCHED, %cl
15188 jnz work_resched
15189
15190 work_notifysig: # deal with pending signals and
15191 # notify-resume requests
15192 + movl %esp, %eax
15193 #ifdef CONFIG_VM86
15194 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15195 - movl %esp, %eax
15196 - jne work_notifysig_v86 # returning to kernel-space or
15197 + jz 1f # returning to kernel-space or
15198 # vm86-space
15199 - TRACE_IRQS_ON
15200 - ENABLE_INTERRUPTS(CLBR_NONE)
15201 - movb PT_CS(%esp), %bl
15202 - andb $SEGMENT_RPL_MASK, %bl
15203 - cmpb $USER_RPL, %bl
15204 - jb resume_kernel
15205 - xorl %edx, %edx
15206 - call do_notify_resume
15207 - jmp resume_userspace
15208
15209 - ALIGN
15210 -work_notifysig_v86:
15211 pushl_cfi %ecx # save ti_flags for do_notify_resume
15212 call save_v86_state # %eax contains pt_regs pointer
15213 popl_cfi %ecx
15214 movl %eax, %esp
15215 -#else
15216 - movl %esp, %eax
15217 +1:
15218 #endif
15219 TRACE_IRQS_ON
15220 ENABLE_INTERRUPTS(CLBR_NONE)
15221 @@ -640,7 +839,7 @@ work_notifysig_v86:
15222 xorl %edx, %edx
15223 call do_notify_resume
15224 jmp resume_userspace
15225 -END(work_pending)
15226 +ENDPROC(work_pending)
15227
15228 # perform syscall exit tracing
15229 ALIGN
15230 @@ -648,11 +847,14 @@ syscall_trace_entry:
15231 movl $-ENOSYS,PT_EAX(%esp)
15232 movl %esp, %eax
15233 call syscall_trace_enter
15234 +
15235 + pax_erase_kstack
15236 +
15237 /* What it returned is what we'll actually use. */
15238 cmpl $(NR_syscalls), %eax
15239 jnae syscall_call
15240 jmp syscall_exit
15241 -END(syscall_trace_entry)
15242 +ENDPROC(syscall_trace_entry)
15243
15244 # perform syscall exit tracing
15245 ALIGN
15246 @@ -665,20 +867,24 @@ syscall_exit_work:
15247 movl %esp, %eax
15248 call syscall_trace_leave
15249 jmp resume_userspace
15250 -END(syscall_exit_work)
15251 +ENDPROC(syscall_exit_work)
15252 CFI_ENDPROC
15253
15254 RING0_INT_FRAME # can't unwind into user space anyway
15255 syscall_fault:
15256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15257 + push %ss
15258 + pop %ds
15259 +#endif
15260 GET_THREAD_INFO(%ebp)
15261 movl $-EFAULT,PT_EAX(%esp)
15262 jmp resume_userspace
15263 -END(syscall_fault)
15264 +ENDPROC(syscall_fault)
15265
15266 syscall_badsys:
15267 movl $-ENOSYS,PT_EAX(%esp)
15268 jmp resume_userspace
15269 -END(syscall_badsys)
15270 +ENDPROC(syscall_badsys)
15271 CFI_ENDPROC
15272 /*
15273 * End of kprobes section
15274 @@ -750,6 +956,36 @@ ENTRY(ptregs_clone)
15275 CFI_ENDPROC
15276 ENDPROC(ptregs_clone)
15277
15278 + ALIGN;
15279 +ENTRY(kernel_execve)
15280 + CFI_STARTPROC
15281 + pushl_cfi %ebp
15282 + sub $PT_OLDSS+4,%esp
15283 + pushl_cfi %edi
15284 + pushl_cfi %ecx
15285 + pushl_cfi %eax
15286 + lea 3*4(%esp),%edi
15287 + mov $PT_OLDSS/4+1,%ecx
15288 + xorl %eax,%eax
15289 + rep stosl
15290 + popl_cfi %eax
15291 + popl_cfi %ecx
15292 + popl_cfi %edi
15293 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15294 + pushl_cfi %esp
15295 + call sys_execve
15296 + add $4,%esp
15297 + CFI_ADJUST_CFA_OFFSET -4
15298 + GET_THREAD_INFO(%ebp)
15299 + test %eax,%eax
15300 + jz syscall_exit
15301 + add $PT_OLDSS+4,%esp
15302 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15303 + popl_cfi %ebp
15304 + ret
15305 + CFI_ENDPROC
15306 +ENDPROC(kernel_execve)
15307 +
15308 .macro FIXUP_ESPFIX_STACK
15309 /*
15310 * Switch back for ESPFIX stack to the normal zerobased stack
15311 @@ -759,8 +995,15 @@ ENDPROC(ptregs_clone)
15312 * normal stack and adjusts ESP with the matching offset.
15313 */
15314 /* fixup the stack */
15315 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15316 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15317 +#ifdef CONFIG_SMP
15318 + movl PER_CPU_VAR(cpu_number), %ebx
15319 + shll $PAGE_SHIFT_asm, %ebx
15320 + addl $cpu_gdt_table, %ebx
15321 +#else
15322 + movl $cpu_gdt_table, %ebx
15323 +#endif
15324 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15325 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15326 shl $16, %eax
15327 addl %esp, %eax /* the adjusted stack pointer */
15328 pushl_cfi $__KERNEL_DS
15329 @@ -813,7 +1056,7 @@ vector=vector+1
15330 .endr
15331 2: jmp common_interrupt
15332 .endr
15333 -END(irq_entries_start)
15334 +ENDPROC(irq_entries_start)
15335
15336 .previous
15337 END(interrupt)
15338 @@ -861,7 +1104,7 @@ ENTRY(coprocessor_error)
15339 pushl_cfi $do_coprocessor_error
15340 jmp error_code
15341 CFI_ENDPROC
15342 -END(coprocessor_error)
15343 +ENDPROC(coprocessor_error)
15344
15345 ENTRY(simd_coprocessor_error)
15346 RING0_INT_FRAME
15347 @@ -882,7 +1125,7 @@ ENTRY(simd_coprocessor_error)
15348 #endif
15349 jmp error_code
15350 CFI_ENDPROC
15351 -END(simd_coprocessor_error)
15352 +ENDPROC(simd_coprocessor_error)
15353
15354 ENTRY(device_not_available)
15355 RING0_INT_FRAME
15356 @@ -890,18 +1133,18 @@ ENTRY(device_not_available)
15357 pushl_cfi $do_device_not_available
15358 jmp error_code
15359 CFI_ENDPROC
15360 -END(device_not_available)
15361 +ENDPROC(device_not_available)
15362
15363 #ifdef CONFIG_PARAVIRT
15364 ENTRY(native_iret)
15365 iret
15366 _ASM_EXTABLE(native_iret, iret_exc)
15367 -END(native_iret)
15368 +ENDPROC(native_iret)
15369
15370 ENTRY(native_irq_enable_sysexit)
15371 sti
15372 sysexit
15373 -END(native_irq_enable_sysexit)
15374 +ENDPROC(native_irq_enable_sysexit)
15375 #endif
15376
15377 ENTRY(overflow)
15378 @@ -910,7 +1153,7 @@ ENTRY(overflow)
15379 pushl_cfi $do_overflow
15380 jmp error_code
15381 CFI_ENDPROC
15382 -END(overflow)
15383 +ENDPROC(overflow)
15384
15385 ENTRY(bounds)
15386 RING0_INT_FRAME
15387 @@ -918,7 +1161,7 @@ ENTRY(bounds)
15388 pushl_cfi $do_bounds
15389 jmp error_code
15390 CFI_ENDPROC
15391 -END(bounds)
15392 +ENDPROC(bounds)
15393
15394 ENTRY(invalid_op)
15395 RING0_INT_FRAME
15396 @@ -926,7 +1169,7 @@ ENTRY(invalid_op)
15397 pushl_cfi $do_invalid_op
15398 jmp error_code
15399 CFI_ENDPROC
15400 -END(invalid_op)
15401 +ENDPROC(invalid_op)
15402
15403 ENTRY(coprocessor_segment_overrun)
15404 RING0_INT_FRAME
15405 @@ -934,35 +1177,35 @@ ENTRY(coprocessor_segment_overrun)
15406 pushl_cfi $do_coprocessor_segment_overrun
15407 jmp error_code
15408 CFI_ENDPROC
15409 -END(coprocessor_segment_overrun)
15410 +ENDPROC(coprocessor_segment_overrun)
15411
15412 ENTRY(invalid_TSS)
15413 RING0_EC_FRAME
15414 pushl_cfi $do_invalid_TSS
15415 jmp error_code
15416 CFI_ENDPROC
15417 -END(invalid_TSS)
15418 +ENDPROC(invalid_TSS)
15419
15420 ENTRY(segment_not_present)
15421 RING0_EC_FRAME
15422 pushl_cfi $do_segment_not_present
15423 jmp error_code
15424 CFI_ENDPROC
15425 -END(segment_not_present)
15426 +ENDPROC(segment_not_present)
15427
15428 ENTRY(stack_segment)
15429 RING0_EC_FRAME
15430 pushl_cfi $do_stack_segment
15431 jmp error_code
15432 CFI_ENDPROC
15433 -END(stack_segment)
15434 +ENDPROC(stack_segment)
15435
15436 ENTRY(alignment_check)
15437 RING0_EC_FRAME
15438 pushl_cfi $do_alignment_check
15439 jmp error_code
15440 CFI_ENDPROC
15441 -END(alignment_check)
15442 +ENDPROC(alignment_check)
15443
15444 ENTRY(divide_error)
15445 RING0_INT_FRAME
15446 @@ -970,7 +1213,7 @@ ENTRY(divide_error)
15447 pushl_cfi $do_divide_error
15448 jmp error_code
15449 CFI_ENDPROC
15450 -END(divide_error)
15451 +ENDPROC(divide_error)
15452
15453 #ifdef CONFIG_X86_MCE
15454 ENTRY(machine_check)
15455 @@ -979,7 +1222,7 @@ ENTRY(machine_check)
15456 pushl_cfi machine_check_vector
15457 jmp error_code
15458 CFI_ENDPROC
15459 -END(machine_check)
15460 +ENDPROC(machine_check)
15461 #endif
15462
15463 ENTRY(spurious_interrupt_bug)
15464 @@ -988,7 +1231,7 @@ ENTRY(spurious_interrupt_bug)
15465 pushl_cfi $do_spurious_interrupt_bug
15466 jmp error_code
15467 CFI_ENDPROC
15468 -END(spurious_interrupt_bug)
15469 +ENDPROC(spurious_interrupt_bug)
15470 /*
15471 * End of kprobes section
15472 */
15473 @@ -1100,7 +1343,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15474
15475 ENTRY(mcount)
15476 ret
15477 -END(mcount)
15478 +ENDPROC(mcount)
15479
15480 ENTRY(ftrace_caller)
15481 cmpl $0, function_trace_stop
15482 @@ -1129,7 +1372,7 @@ ftrace_graph_call:
15483 .globl ftrace_stub
15484 ftrace_stub:
15485 ret
15486 -END(ftrace_caller)
15487 +ENDPROC(ftrace_caller)
15488
15489 #else /* ! CONFIG_DYNAMIC_FTRACE */
15490
15491 @@ -1165,7 +1408,7 @@ trace:
15492 popl %ecx
15493 popl %eax
15494 jmp ftrace_stub
15495 -END(mcount)
15496 +ENDPROC(mcount)
15497 #endif /* CONFIG_DYNAMIC_FTRACE */
15498 #endif /* CONFIG_FUNCTION_TRACER */
15499
15500 @@ -1186,7 +1429,7 @@ ENTRY(ftrace_graph_caller)
15501 popl %ecx
15502 popl %eax
15503 ret
15504 -END(ftrace_graph_caller)
15505 +ENDPROC(ftrace_graph_caller)
15506
15507 .globl return_to_handler
15508 return_to_handler:
15509 @@ -1241,15 +1484,18 @@ error_code:
15510 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15511 REG_TO_PTGS %ecx
15512 SET_KERNEL_GS %ecx
15513 - movl $(__USER_DS), %ecx
15514 + movl $(__KERNEL_DS), %ecx
15515 movl %ecx, %ds
15516 movl %ecx, %es
15517 +
15518 + pax_enter_kernel
15519 +
15520 TRACE_IRQS_OFF
15521 movl %esp,%eax # pt_regs pointer
15522 call *%edi
15523 jmp ret_from_exception
15524 CFI_ENDPROC
15525 -END(page_fault)
15526 +ENDPROC(page_fault)
15527
15528 /*
15529 * Debug traps and NMI can happen at the one SYSENTER instruction
15530 @@ -1291,7 +1537,7 @@ debug_stack_correct:
15531 call do_debug
15532 jmp ret_from_exception
15533 CFI_ENDPROC
15534 -END(debug)
15535 +ENDPROC(debug)
15536
15537 /*
15538 * NMI is doubly nasty. It can happen _while_ we're handling
15539 @@ -1328,6 +1574,9 @@ nmi_stack_correct:
15540 xorl %edx,%edx # zero error code
15541 movl %esp,%eax # pt_regs pointer
15542 call do_nmi
15543 +
15544 + pax_exit_kernel
15545 +
15546 jmp restore_all_notrace
15547 CFI_ENDPROC
15548
15549 @@ -1364,12 +1613,15 @@ nmi_espfix_stack:
15550 FIXUP_ESPFIX_STACK # %eax == %esp
15551 xorl %edx,%edx # zero error code
15552 call do_nmi
15553 +
15554 + pax_exit_kernel
15555 +
15556 RESTORE_REGS
15557 lss 12+4(%esp), %esp # back to espfix stack
15558 CFI_ADJUST_CFA_OFFSET -24
15559 jmp irq_return
15560 CFI_ENDPROC
15561 -END(nmi)
15562 +ENDPROC(nmi)
15563
15564 ENTRY(int3)
15565 RING0_INT_FRAME
15566 @@ -1381,14 +1633,14 @@ ENTRY(int3)
15567 call do_int3
15568 jmp ret_from_exception
15569 CFI_ENDPROC
15570 -END(int3)
15571 +ENDPROC(int3)
15572
15573 ENTRY(general_protection)
15574 RING0_EC_FRAME
15575 pushl_cfi $do_general_protection
15576 jmp error_code
15577 CFI_ENDPROC
15578 -END(general_protection)
15579 +ENDPROC(general_protection)
15580
15581 #ifdef CONFIG_KVM_GUEST
15582 ENTRY(async_page_fault)
15583 @@ -1396,7 +1648,7 @@ ENTRY(async_page_fault)
15584 pushl_cfi $do_async_page_fault
15585 jmp error_code
15586 CFI_ENDPROC
15587 -END(async_page_fault)
15588 +ENDPROC(async_page_fault)
15589 #endif
15590
15591 /*
15592 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15593 index 7d65133..27bce5b 100644
15594 --- a/arch/x86/kernel/entry_64.S
15595 +++ b/arch/x86/kernel/entry_64.S
15596 @@ -57,6 +57,8 @@
15597 #include <asm/percpu.h>
15598 #include <asm/asm.h>
15599 #include <linux/err.h>
15600 +#include <asm/pgtable.h>
15601 +#include <asm/alternative-asm.h>
15602
15603 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15604 #include <linux/elf-em.h>
15605 @@ -70,8 +72,9 @@
15606 #ifdef CONFIG_FUNCTION_TRACER
15607 #ifdef CONFIG_DYNAMIC_FTRACE
15608 ENTRY(mcount)
15609 + pax_force_retaddr
15610 retq
15611 -END(mcount)
15612 +ENDPROC(mcount)
15613
15614 ENTRY(ftrace_caller)
15615 cmpl $0, function_trace_stop
15616 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15617 #endif
15618
15619 GLOBAL(ftrace_stub)
15620 + pax_force_retaddr
15621 retq
15622 -END(ftrace_caller)
15623 +ENDPROC(ftrace_caller)
15624
15625 #else /* ! CONFIG_DYNAMIC_FTRACE */
15626 ENTRY(mcount)
15627 @@ -114,6 +118,7 @@ ENTRY(mcount)
15628 #endif
15629
15630 GLOBAL(ftrace_stub)
15631 + pax_force_retaddr
15632 retq
15633
15634 trace:
15635 @@ -123,12 +128,13 @@ trace:
15636 movq 8(%rbp), %rsi
15637 subq $MCOUNT_INSN_SIZE, %rdi
15638
15639 + pax_force_fptr ftrace_trace_function
15640 call *ftrace_trace_function
15641
15642 MCOUNT_RESTORE_FRAME
15643
15644 jmp ftrace_stub
15645 -END(mcount)
15646 +ENDPROC(mcount)
15647 #endif /* CONFIG_DYNAMIC_FTRACE */
15648 #endif /* CONFIG_FUNCTION_TRACER */
15649
15650 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15651
15652 MCOUNT_RESTORE_FRAME
15653
15654 + pax_force_retaddr
15655 retq
15656 -END(ftrace_graph_caller)
15657 +ENDPROC(ftrace_graph_caller)
15658
15659 GLOBAL(return_to_handler)
15660 subq $24, %rsp
15661 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15662 movq 8(%rsp), %rdx
15663 movq (%rsp), %rax
15664 addq $24, %rsp
15665 + pax_force_fptr %rdi
15666 jmp *%rdi
15667 #endif
15668
15669 @@ -180,6 +188,282 @@ ENTRY(native_usergs_sysret64)
15670 ENDPROC(native_usergs_sysret64)
15671 #endif /* CONFIG_PARAVIRT */
15672
15673 + .macro ljmpq sel, off
15674 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15675 + .byte 0x48; ljmp *1234f(%rip)
15676 + .pushsection .rodata
15677 + .align 16
15678 + 1234: .quad \off; .word \sel
15679 + .popsection
15680 +#else
15681 + pushq $\sel
15682 + pushq $\off
15683 + lretq
15684 +#endif
15685 + .endm
15686 +
15687 + .macro pax_enter_kernel
15688 + pax_set_fptr_mask
15689 +#ifdef CONFIG_PAX_KERNEXEC
15690 + call pax_enter_kernel
15691 +#endif
15692 + .endm
15693 +
15694 + .macro pax_exit_kernel
15695 +#ifdef CONFIG_PAX_KERNEXEC
15696 + call pax_exit_kernel
15697 +#endif
15698 + .endm
15699 +
15700 +#ifdef CONFIG_PAX_KERNEXEC
15701 +ENTRY(pax_enter_kernel)
15702 + pushq %rdi
15703 +
15704 +#ifdef CONFIG_PARAVIRT
15705 + PV_SAVE_REGS(CLBR_RDI)
15706 +#endif
15707 +
15708 + GET_CR0_INTO_RDI
15709 + bts $16,%rdi
15710 + jnc 3f
15711 + mov %cs,%edi
15712 + cmp $__KERNEL_CS,%edi
15713 + jnz 2f
15714 +1:
15715 +
15716 +#ifdef CONFIG_PARAVIRT
15717 + PV_RESTORE_REGS(CLBR_RDI)
15718 +#endif
15719 +
15720 + popq %rdi
15721 + pax_force_retaddr
15722 + retq
15723 +
15724 +2: ljmpq __KERNEL_CS,1f
15725 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15726 +4: SET_RDI_INTO_CR0
15727 + jmp 1b
15728 +ENDPROC(pax_enter_kernel)
15729 +
15730 +ENTRY(pax_exit_kernel)
15731 + pushq %rdi
15732 +
15733 +#ifdef CONFIG_PARAVIRT
15734 + PV_SAVE_REGS(CLBR_RDI)
15735 +#endif
15736 +
15737 + mov %cs,%rdi
15738 + cmp $__KERNEXEC_KERNEL_CS,%edi
15739 + jz 2f
15740 +1:
15741 +
15742 +#ifdef CONFIG_PARAVIRT
15743 + PV_RESTORE_REGS(CLBR_RDI);
15744 +#endif
15745 +
15746 + popq %rdi
15747 + pax_force_retaddr
15748 + retq
15749 +
15750 +2: GET_CR0_INTO_RDI
15751 + btr $16,%rdi
15752 + ljmpq __KERNEL_CS,3f
15753 +3: SET_RDI_INTO_CR0
15754 + jmp 1b
15755 +#ifdef CONFIG_PARAVIRT
15756 + PV_RESTORE_REGS(CLBR_RDI);
15757 +#endif
15758 +
15759 + popq %rdi
15760 + pax_force_retaddr
15761 + retq
15762 +ENDPROC(pax_exit_kernel)
15763 +#endif
15764 +
15765 + .macro pax_enter_kernel_user
15766 + pax_set_fptr_mask
15767 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15768 + call pax_enter_kernel_user
15769 +#endif
15770 + .endm
15771 +
15772 + .macro pax_exit_kernel_user
15773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15774 + call pax_exit_kernel_user
15775 +#endif
15776 +#ifdef CONFIG_PAX_RANDKSTACK
15777 + pushq %rax
15778 + call pax_randomize_kstack
15779 + popq %rax
15780 +#endif
15781 + .endm
15782 +
15783 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15784 +ENTRY(pax_enter_kernel_user)
15785 + pushq %rdi
15786 + pushq %rbx
15787 +
15788 +#ifdef CONFIG_PARAVIRT
15789 + PV_SAVE_REGS(CLBR_RDI)
15790 +#endif
15791 +
15792 + GET_CR3_INTO_RDI
15793 + mov %rdi,%rbx
15794 + add $__START_KERNEL_map,%rbx
15795 + sub phys_base(%rip),%rbx
15796 +
15797 +#ifdef CONFIG_PARAVIRT
15798 + pushq %rdi
15799 + cmpl $0, pv_info+PARAVIRT_enabled
15800 + jz 1f
15801 + i = 0
15802 + .rept USER_PGD_PTRS
15803 + mov i*8(%rbx),%rsi
15804 + mov $0,%sil
15805 + lea i*8(%rbx),%rdi
15806 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15807 + i = i + 1
15808 + .endr
15809 + jmp 2f
15810 +1:
15811 +#endif
15812 +
15813 + i = 0
15814 + .rept USER_PGD_PTRS
15815 + movb $0,i*8(%rbx)
15816 + i = i + 1
15817 + .endr
15818 +
15819 +#ifdef CONFIG_PARAVIRT
15820 +2: popq %rdi
15821 +#endif
15822 + SET_RDI_INTO_CR3
15823 +
15824 +#ifdef CONFIG_PAX_KERNEXEC
15825 + GET_CR0_INTO_RDI
15826 + bts $16,%rdi
15827 + SET_RDI_INTO_CR0
15828 +#endif
15829 +
15830 +#ifdef CONFIG_PARAVIRT
15831 + PV_RESTORE_REGS(CLBR_RDI)
15832 +#endif
15833 +
15834 + popq %rbx
15835 + popq %rdi
15836 + pax_force_retaddr
15837 + retq
15838 +ENDPROC(pax_enter_kernel_user)
15839 +
15840 +ENTRY(pax_exit_kernel_user)
15841 + push %rdi
15842 +
15843 +#ifdef CONFIG_PARAVIRT
15844 + pushq %rbx
15845 + PV_SAVE_REGS(CLBR_RDI)
15846 +#endif
15847 +
15848 +#ifdef CONFIG_PAX_KERNEXEC
15849 + GET_CR0_INTO_RDI
15850 + btr $16,%rdi
15851 + SET_RDI_INTO_CR0
15852 +#endif
15853 +
15854 + GET_CR3_INTO_RDI
15855 + add $__START_KERNEL_map,%rdi
15856 + sub phys_base(%rip),%rdi
15857 +
15858 +#ifdef CONFIG_PARAVIRT
15859 + cmpl $0, pv_info+PARAVIRT_enabled
15860 + jz 1f
15861 + mov %rdi,%rbx
15862 + i = 0
15863 + .rept USER_PGD_PTRS
15864 + mov i*8(%rbx),%rsi
15865 + mov $0x67,%sil
15866 + lea i*8(%rbx),%rdi
15867 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15868 + i = i + 1
15869 + .endr
15870 + jmp 2f
15871 +1:
15872 +#endif
15873 +
15874 + i = 0
15875 + .rept USER_PGD_PTRS
15876 + movb $0x67,i*8(%rdi)
15877 + i = i + 1
15878 + .endr
15879 +
15880 +#ifdef CONFIG_PARAVIRT
15881 +2: PV_RESTORE_REGS(CLBR_RDI)
15882 + popq %rbx
15883 +#endif
15884 +
15885 + popq %rdi
15886 + pax_force_retaddr
15887 + retq
15888 +ENDPROC(pax_exit_kernel_user)
15889 +#endif
15890 +
15891 +.macro pax_erase_kstack
15892 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15893 + call pax_erase_kstack
15894 +#endif
15895 +.endm
15896 +
15897 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15898 +/*
15899 + * r11: thread_info
15900 + * rcx, rdx: can be clobbered
15901 + */
15902 +ENTRY(pax_erase_kstack)
15903 + pushq %rdi
15904 + pushq %rax
15905 + pushq %r11
15906 +
15907 + GET_THREAD_INFO(%r11)
15908 + mov TI_lowest_stack(%r11), %rdi
15909 + mov $-0xBEEF, %rax
15910 + std
15911 +
15912 +1: mov %edi, %ecx
15913 + and $THREAD_SIZE_asm - 1, %ecx
15914 + shr $3, %ecx
15915 + repne scasq
15916 + jecxz 2f
15917 +
15918 + cmp $2*8, %ecx
15919 + jc 2f
15920 +
15921 + mov $2*8, %ecx
15922 + repe scasq
15923 + jecxz 2f
15924 + jne 1b
15925 +
15926 +2: cld
15927 + mov %esp, %ecx
15928 + sub %edi, %ecx
15929 +
15930 + cmp $THREAD_SIZE_asm, %rcx
15931 + jb 3f
15932 + ud2
15933 +3:
15934 +
15935 + shr $3, %ecx
15936 + rep stosq
15937 +
15938 + mov TI_task_thread_sp0(%r11), %rdi
15939 + sub $256, %rdi
15940 + mov %rdi, TI_lowest_stack(%r11)
15941 +
15942 + popq %r11
15943 + popq %rax
15944 + popq %rdi
15945 + pax_force_retaddr
15946 + ret
15947 +ENDPROC(pax_erase_kstack)
15948 +#endif
15949
15950 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15951 #ifdef CONFIG_TRACE_IRQFLAGS
15952 @@ -271,8 +555,8 @@ ENDPROC(native_usergs_sysret64)
15953 .endm
15954
15955 .macro UNFAKE_STACK_FRAME
15956 - addq $8*6, %rsp
15957 - CFI_ADJUST_CFA_OFFSET -(6*8)
15958 + addq $8*6 + ARG_SKIP, %rsp
15959 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15960 .endm
15961
15962 /*
15963 @@ -359,7 +643,7 @@ ENDPROC(native_usergs_sysret64)
15964 movq %rsp, %rsi
15965
15966 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15967 - testl $3, CS-RBP(%rsi)
15968 + testb $3, CS-RBP(%rsi)
15969 je 1f
15970 SWAPGS
15971 /*
15972 @@ -394,9 +678,10 @@ ENTRY(save_rest)
15973 movq_cfi r15, R15+16
15974 movq %r11, 8(%rsp) /* return address */
15975 FIXUP_TOP_OF_STACK %r11, 16
15976 + pax_force_retaddr
15977 ret
15978 CFI_ENDPROC
15979 -END(save_rest)
15980 +ENDPROC(save_rest)
15981
15982 /* save complete stack frame */
15983 .pushsection .kprobes.text, "ax"
15984 @@ -425,9 +710,10 @@ ENTRY(save_paranoid)
15985 js 1f /* negative -> in kernel */
15986 SWAPGS
15987 xorl %ebx,%ebx
15988 -1: ret
15989 +1: pax_force_retaddr_bts
15990 + ret
15991 CFI_ENDPROC
15992 -END(save_paranoid)
15993 +ENDPROC(save_paranoid)
15994 .popsection
15995
15996 /*
15997 @@ -449,7 +735,7 @@ ENTRY(ret_from_fork)
15998
15999 RESTORE_REST
16000
16001 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16002 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16003 jz retint_restore_args
16004
16005 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16006 @@ -459,7 +745,7 @@ ENTRY(ret_from_fork)
16007 jmp ret_from_sys_call # go to the SYSRET fastpath
16008
16009 CFI_ENDPROC
16010 -END(ret_from_fork)
16011 +ENDPROC(ret_from_fork)
16012
16013 /*
16014 * System call entry. Up to 6 arguments in registers are supported.
16015 @@ -495,7 +781,7 @@ END(ret_from_fork)
16016 ENTRY(system_call)
16017 CFI_STARTPROC simple
16018 CFI_SIGNAL_FRAME
16019 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16020 + CFI_DEF_CFA rsp,0
16021 CFI_REGISTER rip,rcx
16022 /*CFI_REGISTER rflags,r11*/
16023 SWAPGS_UNSAFE_STACK
16024 @@ -508,16 +794,18 @@ GLOBAL(system_call_after_swapgs)
16025
16026 movq %rsp,PER_CPU_VAR(old_rsp)
16027 movq PER_CPU_VAR(kernel_stack),%rsp
16028 + SAVE_ARGS 8*6,0
16029 + pax_enter_kernel_user
16030 /*
16031 * No need to follow this irqs off/on section - it's straight
16032 * and short:
16033 */
16034 ENABLE_INTERRUPTS(CLBR_NONE)
16035 - SAVE_ARGS 8,0
16036 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16037 movq %rcx,RIP-ARGOFFSET(%rsp)
16038 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16039 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16040 + GET_THREAD_INFO(%rcx)
16041 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16042 jnz tracesys
16043 system_call_fastpath:
16044 #if __SYSCALL_MASK == ~0
16045 @@ -527,7 +815,7 @@ system_call_fastpath:
16046 cmpl $__NR_syscall_max,%eax
16047 #endif
16048 ja badsys
16049 - movq %r10,%rcx
16050 + movq R10-ARGOFFSET(%rsp),%rcx
16051 call *sys_call_table(,%rax,8) # XXX: rip relative
16052 movq %rax,RAX-ARGOFFSET(%rsp)
16053 /*
16054 @@ -541,10 +829,13 @@ sysret_check:
16055 LOCKDEP_SYS_EXIT
16056 DISABLE_INTERRUPTS(CLBR_NONE)
16057 TRACE_IRQS_OFF
16058 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16059 + GET_THREAD_INFO(%rcx)
16060 + movl TI_flags(%rcx),%edx
16061 andl %edi,%edx
16062 jnz sysret_careful
16063 CFI_REMEMBER_STATE
16064 + pax_exit_kernel_user
16065 + pax_erase_kstack
16066 /*
16067 * sysretq will re-enable interrupts:
16068 */
16069 @@ -596,14 +887,18 @@ badsys:
16070 * jump back to the normal fast path.
16071 */
16072 auditsys:
16073 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16074 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16075 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16076 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16077 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16078 movq %rax,%rsi /* 2nd arg: syscall number */
16079 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16080 call __audit_syscall_entry
16081 +
16082 + pax_erase_kstack
16083 +
16084 LOAD_ARGS 0 /* reload call-clobbered registers */
16085 + pax_set_fptr_mask
16086 jmp system_call_fastpath
16087
16088 /*
16089 @@ -624,7 +919,7 @@ sysret_audit:
16090 /* Do syscall tracing */
16091 tracesys:
16092 #ifdef CONFIG_AUDITSYSCALL
16093 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16094 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16095 jz auditsys
16096 #endif
16097 SAVE_REST
16098 @@ -632,12 +927,16 @@ tracesys:
16099 FIXUP_TOP_OF_STACK %rdi
16100 movq %rsp,%rdi
16101 call syscall_trace_enter
16102 +
16103 + pax_erase_kstack
16104 +
16105 /*
16106 * Reload arg registers from stack in case ptrace changed them.
16107 * We don't reload %rax because syscall_trace_enter() returned
16108 * the value it wants us to use in the table lookup.
16109 */
16110 LOAD_ARGS ARGOFFSET, 1
16111 + pax_set_fptr_mask
16112 RESTORE_REST
16113 #if __SYSCALL_MASK == ~0
16114 cmpq $__NR_syscall_max,%rax
16115 @@ -646,7 +945,7 @@ tracesys:
16116 cmpl $__NR_syscall_max,%eax
16117 #endif
16118 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16119 - movq %r10,%rcx /* fixup for C */
16120 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16121 call *sys_call_table(,%rax,8)
16122 movq %rax,RAX-ARGOFFSET(%rsp)
16123 /* Use IRET because user could have changed frame */
16124 @@ -667,6 +966,7 @@ GLOBAL(int_with_check)
16125 andl %edi,%edx
16126 jnz int_careful
16127 andl $~TS_COMPAT,TI_status(%rcx)
16128 + pax_erase_kstack
16129 jmp retint_swapgs
16130
16131 /* Either reschedule or signal or syscall exit tracking needed. */
16132 @@ -713,7 +1013,7 @@ int_restore_rest:
16133 TRACE_IRQS_OFF
16134 jmp int_with_check
16135 CFI_ENDPROC
16136 -END(system_call)
16137 +ENDPROC(system_call)
16138
16139 /*
16140 * Certain special system calls that need to save a complete full stack frame.
16141 @@ -729,7 +1029,7 @@ ENTRY(\label)
16142 call \func
16143 jmp ptregscall_common
16144 CFI_ENDPROC
16145 -END(\label)
16146 +ENDPROC(\label)
16147 .endm
16148
16149 PTREGSCALL stub_clone, sys_clone, %r8
16150 @@ -747,9 +1047,10 @@ ENTRY(ptregscall_common)
16151 movq_cfi_restore R12+8, r12
16152 movq_cfi_restore RBP+8, rbp
16153 movq_cfi_restore RBX+8, rbx
16154 + pax_force_retaddr
16155 ret $REST_SKIP /* pop extended registers */
16156 CFI_ENDPROC
16157 -END(ptregscall_common)
16158 +ENDPROC(ptregscall_common)
16159
16160 ENTRY(stub_execve)
16161 CFI_STARTPROC
16162 @@ -764,7 +1065,7 @@ ENTRY(stub_execve)
16163 RESTORE_REST
16164 jmp int_ret_from_sys_call
16165 CFI_ENDPROC
16166 -END(stub_execve)
16167 +ENDPROC(stub_execve)
16168
16169 /*
16170 * sigreturn is special because it needs to restore all registers on return.
16171 @@ -782,7 +1083,7 @@ ENTRY(stub_rt_sigreturn)
16172 RESTORE_REST
16173 jmp int_ret_from_sys_call
16174 CFI_ENDPROC
16175 -END(stub_rt_sigreturn)
16176 +ENDPROC(stub_rt_sigreturn)
16177
16178 #ifdef CONFIG_X86_X32_ABI
16179 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16180 @@ -851,7 +1152,7 @@ vector=vector+1
16181 2: jmp common_interrupt
16182 .endr
16183 CFI_ENDPROC
16184 -END(irq_entries_start)
16185 +ENDPROC(irq_entries_start)
16186
16187 .previous
16188 END(interrupt)
16189 @@ -871,6 +1172,16 @@ END(interrupt)
16190 subq $ORIG_RAX-RBP, %rsp
16191 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16192 SAVE_ARGS_IRQ
16193 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16194 + testb $3, CS(%rdi)
16195 + jnz 1f
16196 + pax_enter_kernel
16197 + jmp 2f
16198 +1: pax_enter_kernel_user
16199 +2:
16200 +#else
16201 + pax_enter_kernel
16202 +#endif
16203 call \func
16204 .endm
16205
16206 @@ -902,7 +1213,7 @@ ret_from_intr:
16207
16208 exit_intr:
16209 GET_THREAD_INFO(%rcx)
16210 - testl $3,CS-ARGOFFSET(%rsp)
16211 + testb $3,CS-ARGOFFSET(%rsp)
16212 je retint_kernel
16213
16214 /* Interrupt came from user space */
16215 @@ -924,12 +1235,15 @@ retint_swapgs: /* return to user-space */
16216 * The iretq could re-enable interrupts:
16217 */
16218 DISABLE_INTERRUPTS(CLBR_ANY)
16219 + pax_exit_kernel_user
16220 TRACE_IRQS_IRETQ
16221 SWAPGS
16222 jmp restore_args
16223
16224 retint_restore_args: /* return to kernel space */
16225 DISABLE_INTERRUPTS(CLBR_ANY)
16226 + pax_exit_kernel
16227 + pax_force_retaddr RIP-ARGOFFSET
16228 /*
16229 * The iretq could re-enable interrupts:
16230 */
16231 @@ -1012,7 +1326,7 @@ ENTRY(retint_kernel)
16232 #endif
16233
16234 CFI_ENDPROC
16235 -END(common_interrupt)
16236 +ENDPROC(common_interrupt)
16237 /*
16238 * End of kprobes section
16239 */
16240 @@ -1029,7 +1343,7 @@ ENTRY(\sym)
16241 interrupt \do_sym
16242 jmp ret_from_intr
16243 CFI_ENDPROC
16244 -END(\sym)
16245 +ENDPROC(\sym)
16246 .endm
16247
16248 #ifdef CONFIG_SMP
16249 @@ -1102,12 +1416,22 @@ ENTRY(\sym)
16250 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16251 call error_entry
16252 DEFAULT_FRAME 0
16253 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16254 + testb $3, CS(%rsp)
16255 + jnz 1f
16256 + pax_enter_kernel
16257 + jmp 2f
16258 +1: pax_enter_kernel_user
16259 +2:
16260 +#else
16261 + pax_enter_kernel
16262 +#endif
16263 movq %rsp,%rdi /* pt_regs pointer */
16264 xorl %esi,%esi /* no error code */
16265 call \do_sym
16266 jmp error_exit /* %ebx: no swapgs flag */
16267 CFI_ENDPROC
16268 -END(\sym)
16269 +ENDPROC(\sym)
16270 .endm
16271
16272 .macro paranoidzeroentry sym do_sym
16273 @@ -1119,15 +1443,25 @@ ENTRY(\sym)
16274 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16275 call save_paranoid
16276 TRACE_IRQS_OFF
16277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16278 + testb $3, CS(%rsp)
16279 + jnz 1f
16280 + pax_enter_kernel
16281 + jmp 2f
16282 +1: pax_enter_kernel_user
16283 +2:
16284 +#else
16285 + pax_enter_kernel
16286 +#endif
16287 movq %rsp,%rdi /* pt_regs pointer */
16288 xorl %esi,%esi /* no error code */
16289 call \do_sym
16290 jmp paranoid_exit /* %ebx: no swapgs flag */
16291 CFI_ENDPROC
16292 -END(\sym)
16293 +ENDPROC(\sym)
16294 .endm
16295
16296 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16297 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16298 .macro paranoidzeroentry_ist sym do_sym ist
16299 ENTRY(\sym)
16300 INTR_FRAME
16301 @@ -1137,14 +1471,30 @@ ENTRY(\sym)
16302 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16303 call save_paranoid
16304 TRACE_IRQS_OFF_DEBUG
16305 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16306 + testb $3, CS(%rsp)
16307 + jnz 1f
16308 + pax_enter_kernel
16309 + jmp 2f
16310 +1: pax_enter_kernel_user
16311 +2:
16312 +#else
16313 + pax_enter_kernel
16314 +#endif
16315 movq %rsp,%rdi /* pt_regs pointer */
16316 xorl %esi,%esi /* no error code */
16317 +#ifdef CONFIG_SMP
16318 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16319 + lea init_tss(%r12), %r12
16320 +#else
16321 + lea init_tss(%rip), %r12
16322 +#endif
16323 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16324 call \do_sym
16325 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16326 jmp paranoid_exit /* %ebx: no swapgs flag */
16327 CFI_ENDPROC
16328 -END(\sym)
16329 +ENDPROC(\sym)
16330 .endm
16331
16332 .macro errorentry sym do_sym
16333 @@ -1155,13 +1505,23 @@ ENTRY(\sym)
16334 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16335 call error_entry
16336 DEFAULT_FRAME 0
16337 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16338 + testb $3, CS(%rsp)
16339 + jnz 1f
16340 + pax_enter_kernel
16341 + jmp 2f
16342 +1: pax_enter_kernel_user
16343 +2:
16344 +#else
16345 + pax_enter_kernel
16346 +#endif
16347 movq %rsp,%rdi /* pt_regs pointer */
16348 movq ORIG_RAX(%rsp),%rsi /* get error code */
16349 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16350 call \do_sym
16351 jmp error_exit /* %ebx: no swapgs flag */
16352 CFI_ENDPROC
16353 -END(\sym)
16354 +ENDPROC(\sym)
16355 .endm
16356
16357 /* error code is on the stack already */
16358 @@ -1174,13 +1534,23 @@ ENTRY(\sym)
16359 call save_paranoid
16360 DEFAULT_FRAME 0
16361 TRACE_IRQS_OFF
16362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16363 + testb $3, CS(%rsp)
16364 + jnz 1f
16365 + pax_enter_kernel
16366 + jmp 2f
16367 +1: pax_enter_kernel_user
16368 +2:
16369 +#else
16370 + pax_enter_kernel
16371 +#endif
16372 movq %rsp,%rdi /* pt_regs pointer */
16373 movq ORIG_RAX(%rsp),%rsi /* get error code */
16374 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16375 call \do_sym
16376 jmp paranoid_exit /* %ebx: no swapgs flag */
16377 CFI_ENDPROC
16378 -END(\sym)
16379 +ENDPROC(\sym)
16380 .endm
16381
16382 zeroentry divide_error do_divide_error
16383 @@ -1210,9 +1580,10 @@ gs_change:
16384 2: mfence /* workaround */
16385 SWAPGS
16386 popfq_cfi
16387 + pax_force_retaddr
16388 ret
16389 CFI_ENDPROC
16390 -END(native_load_gs_index)
16391 +ENDPROC(native_load_gs_index)
16392
16393 _ASM_EXTABLE(gs_change,bad_gs)
16394 .section .fixup,"ax"
16395 @@ -1231,13 +1602,14 @@ ENTRY(kernel_thread_helper)
16396 * Here we are in the child and the registers are set as they were
16397 * at kernel_thread() invocation in the parent.
16398 */
16399 + pax_force_fptr %rsi
16400 call *%rsi
16401 # exit
16402 mov %eax, %edi
16403 call do_exit
16404 ud2 # padding for call trace
16405 CFI_ENDPROC
16406 -END(kernel_thread_helper)
16407 +ENDPROC(kernel_thread_helper)
16408
16409 /*
16410 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16411 @@ -1264,11 +1636,11 @@ ENTRY(kernel_execve)
16412 RESTORE_REST
16413 testq %rax,%rax
16414 je int_ret_from_sys_call
16415 - RESTORE_ARGS
16416 UNFAKE_STACK_FRAME
16417 + pax_force_retaddr
16418 ret
16419 CFI_ENDPROC
16420 -END(kernel_execve)
16421 +ENDPROC(kernel_execve)
16422
16423 /* Call softirq on interrupt stack. Interrupts are off. */
16424 ENTRY(call_softirq)
16425 @@ -1286,9 +1658,10 @@ ENTRY(call_softirq)
16426 CFI_DEF_CFA_REGISTER rsp
16427 CFI_ADJUST_CFA_OFFSET -8
16428 decl PER_CPU_VAR(irq_count)
16429 + pax_force_retaddr
16430 ret
16431 CFI_ENDPROC
16432 -END(call_softirq)
16433 +ENDPROC(call_softirq)
16434
16435 #ifdef CONFIG_XEN
16436 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16437 @@ -1326,7 +1699,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16438 decl PER_CPU_VAR(irq_count)
16439 jmp error_exit
16440 CFI_ENDPROC
16441 -END(xen_do_hypervisor_callback)
16442 +ENDPROC(xen_do_hypervisor_callback)
16443
16444 /*
16445 * Hypervisor uses this for application faults while it executes.
16446 @@ -1385,7 +1758,7 @@ ENTRY(xen_failsafe_callback)
16447 SAVE_ALL
16448 jmp error_exit
16449 CFI_ENDPROC
16450 -END(xen_failsafe_callback)
16451 +ENDPROC(xen_failsafe_callback)
16452
16453 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16454 xen_hvm_callback_vector xen_evtchn_do_upcall
16455 @@ -1434,16 +1807,31 @@ ENTRY(paranoid_exit)
16456 TRACE_IRQS_OFF_DEBUG
16457 testl %ebx,%ebx /* swapgs needed? */
16458 jnz paranoid_restore
16459 - testl $3,CS(%rsp)
16460 + testb $3,CS(%rsp)
16461 jnz paranoid_userspace
16462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16463 + pax_exit_kernel
16464 + TRACE_IRQS_IRETQ 0
16465 + SWAPGS_UNSAFE_STACK
16466 + RESTORE_ALL 8
16467 + pax_force_retaddr_bts
16468 + jmp irq_return
16469 +#endif
16470 paranoid_swapgs:
16471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16472 + pax_exit_kernel_user
16473 +#else
16474 + pax_exit_kernel
16475 +#endif
16476 TRACE_IRQS_IRETQ 0
16477 SWAPGS_UNSAFE_STACK
16478 RESTORE_ALL 8
16479 jmp irq_return
16480 paranoid_restore:
16481 + pax_exit_kernel
16482 TRACE_IRQS_IRETQ_DEBUG 0
16483 RESTORE_ALL 8
16484 + pax_force_retaddr_bts
16485 jmp irq_return
16486 paranoid_userspace:
16487 GET_THREAD_INFO(%rcx)
16488 @@ -1472,7 +1860,7 @@ paranoid_schedule:
16489 TRACE_IRQS_OFF
16490 jmp paranoid_userspace
16491 CFI_ENDPROC
16492 -END(paranoid_exit)
16493 +ENDPROC(paranoid_exit)
16494
16495 /*
16496 * Exception entry point. This expects an error code/orig_rax on the stack.
16497 @@ -1499,12 +1887,13 @@ ENTRY(error_entry)
16498 movq_cfi r14, R14+8
16499 movq_cfi r15, R15+8
16500 xorl %ebx,%ebx
16501 - testl $3,CS+8(%rsp)
16502 + testb $3,CS+8(%rsp)
16503 je error_kernelspace
16504 error_swapgs:
16505 SWAPGS
16506 error_sti:
16507 TRACE_IRQS_OFF
16508 + pax_force_retaddr_bts
16509 ret
16510
16511 /*
16512 @@ -1531,7 +1920,7 @@ bstep_iret:
16513 movq %rcx,RIP+8(%rsp)
16514 jmp error_swapgs
16515 CFI_ENDPROC
16516 -END(error_entry)
16517 +ENDPROC(error_entry)
16518
16519
16520 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16521 @@ -1551,7 +1940,7 @@ ENTRY(error_exit)
16522 jnz retint_careful
16523 jmp retint_swapgs
16524 CFI_ENDPROC
16525 -END(error_exit)
16526 +ENDPROC(error_exit)
16527
16528 /*
16529 * Test if a given stack is an NMI stack or not.
16530 @@ -1609,9 +1998,11 @@ ENTRY(nmi)
16531 * If %cs was not the kernel segment, then the NMI triggered in user
16532 * space, which means it is definitely not nested.
16533 */
16534 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16535 + je 1f
16536 cmpl $__KERNEL_CS, 16(%rsp)
16537 jne first_nmi
16538 -
16539 +1:
16540 /*
16541 * Check the special variable on the stack to see if NMIs are
16542 * executing.
16543 @@ -1758,6 +2149,16 @@ end_repeat_nmi:
16544 */
16545 call save_paranoid
16546 DEFAULT_FRAME 0
16547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16548 + testb $3, CS(%rsp)
16549 + jnz 1f
16550 + pax_enter_kernel
16551 + jmp 2f
16552 +1: pax_enter_kernel_user
16553 +2:
16554 +#else
16555 + pax_enter_kernel
16556 +#endif
16557 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16558 movq %rsp,%rdi
16559 movq $-1,%rsi
16560 @@ -1765,21 +2166,32 @@ end_repeat_nmi:
16561 testl %ebx,%ebx /* swapgs needed? */
16562 jnz nmi_restore
16563 nmi_swapgs:
16564 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16565 + pax_exit_kernel_user
16566 +#else
16567 + pax_exit_kernel
16568 +#endif
16569 SWAPGS_UNSAFE_STACK
16570 + RESTORE_ALL 8
16571 + /* Clear the NMI executing stack variable */
16572 + movq $0, 10*8(%rsp)
16573 + jmp irq_return
16574 nmi_restore:
16575 + pax_exit_kernel
16576 RESTORE_ALL 8
16577 + pax_force_retaddr_bts
16578 /* Clear the NMI executing stack variable */
16579 movq $0, 10*8(%rsp)
16580 jmp irq_return
16581 CFI_ENDPROC
16582 -END(nmi)
16583 +ENDPROC(nmi)
16584
16585 ENTRY(ignore_sysret)
16586 CFI_STARTPROC
16587 mov $-ENOSYS,%eax
16588 sysret
16589 CFI_ENDPROC
16590 -END(ignore_sysret)
16591 +ENDPROC(ignore_sysret)
16592
16593 /*
16594 * End of kprobes section
16595 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16596 index c3a7cb4..3ad00dc 100644
16597 --- a/arch/x86/kernel/ftrace.c
16598 +++ b/arch/x86/kernel/ftrace.c
16599 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16600 {
16601 unsigned char replaced[MCOUNT_INSN_SIZE];
16602
16603 + ip = ktla_ktva(ip);
16604 +
16605 /*
16606 * Note: Due to modules and __init, code can
16607 * disappear and change, we need to protect against faulting
16608 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16609 unsigned char old[MCOUNT_INSN_SIZE], *new;
16610 int ret;
16611
16612 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16613 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16614 new = ftrace_call_replace(ip, (unsigned long)func);
16615
16616 /* See comment above by declaration of modifying_ftrace_code */
16617 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16618 {
16619 unsigned char code[MCOUNT_INSN_SIZE];
16620
16621 + ip = ktla_ktva(ip);
16622 +
16623 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16624 return -EFAULT;
16625
16626 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16627 index c18f59d..9c0c9f6 100644
16628 --- a/arch/x86/kernel/head32.c
16629 +++ b/arch/x86/kernel/head32.c
16630 @@ -18,6 +18,7 @@
16631 #include <asm/io_apic.h>
16632 #include <asm/bios_ebda.h>
16633 #include <asm/tlbflush.h>
16634 +#include <asm/boot.h>
16635
16636 static void __init i386_default_early_setup(void)
16637 {
16638 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16639
16640 void __init i386_start_kernel(void)
16641 {
16642 - memblock_reserve(__pa_symbol(&_text),
16643 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16644 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16645
16646 #ifdef CONFIG_BLK_DEV_INITRD
16647 /* Reserve INITRD */
16648 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16649 index d42ab17..5015ea6 100644
16650 --- a/arch/x86/kernel/head_32.S
16651 +++ b/arch/x86/kernel/head_32.S
16652 @@ -26,6 +26,12 @@
16653 /* Physical address */
16654 #define pa(X) ((X) - __PAGE_OFFSET)
16655
16656 +#ifdef CONFIG_PAX_KERNEXEC
16657 +#define ta(X) (X)
16658 +#else
16659 +#define ta(X) ((X) - __PAGE_OFFSET)
16660 +#endif
16661 +
16662 /*
16663 * References to members of the new_cpu_data structure.
16664 */
16665 @@ -55,11 +61,7 @@
16666 * and small than max_low_pfn, otherwise will waste some page table entries
16667 */
16668
16669 -#if PTRS_PER_PMD > 1
16670 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16671 -#else
16672 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16673 -#endif
16674 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16675
16676 /* Number of possible pages in the lowmem region */
16677 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16678 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16679 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16680
16681 /*
16682 + * Real beginning of normal "text" segment
16683 + */
16684 +ENTRY(stext)
16685 +ENTRY(_stext)
16686 +
16687 +/*
16688 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16689 * %esi points to the real-mode code as a 32-bit pointer.
16690 * CS and DS must be 4 GB flat segments, but we don't depend on
16691 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16692 * can.
16693 */
16694 __HEAD
16695 +
16696 +#ifdef CONFIG_PAX_KERNEXEC
16697 + jmp startup_32
16698 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16699 +.fill PAGE_SIZE-5,1,0xcc
16700 +#endif
16701 +
16702 ENTRY(startup_32)
16703 movl pa(stack_start),%ecx
16704
16705 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16706 2:
16707 leal -__PAGE_OFFSET(%ecx),%esp
16708
16709 +#ifdef CONFIG_SMP
16710 + movl $pa(cpu_gdt_table),%edi
16711 + movl $__per_cpu_load,%eax
16712 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16713 + rorl $16,%eax
16714 + movb %al,__KERNEL_PERCPU + 4(%edi)
16715 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16716 + movl $__per_cpu_end - 1,%eax
16717 + subl $__per_cpu_start,%eax
16718 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16719 +#endif
16720 +
16721 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16722 + movl $NR_CPUS,%ecx
16723 + movl $pa(cpu_gdt_table),%edi
16724 +1:
16725 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16726 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16727 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16728 + addl $PAGE_SIZE_asm,%edi
16729 + loop 1b
16730 +#endif
16731 +
16732 +#ifdef CONFIG_PAX_KERNEXEC
16733 + movl $pa(boot_gdt),%edi
16734 + movl $__LOAD_PHYSICAL_ADDR,%eax
16735 + movw %ax,__BOOT_CS + 2(%edi)
16736 + rorl $16,%eax
16737 + movb %al,__BOOT_CS + 4(%edi)
16738 + movb %ah,__BOOT_CS + 7(%edi)
16739 + rorl $16,%eax
16740 +
16741 + ljmp $(__BOOT_CS),$1f
16742 +1:
16743 +
16744 + movl $NR_CPUS,%ecx
16745 + movl $pa(cpu_gdt_table),%edi
16746 + addl $__PAGE_OFFSET,%eax
16747 +1:
16748 + movw %ax,__KERNEL_CS + 2(%edi)
16749 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16750 + rorl $16,%eax
16751 + movb %al,__KERNEL_CS + 4(%edi)
16752 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16753 + movb %ah,__KERNEL_CS + 7(%edi)
16754 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16755 + rorl $16,%eax
16756 + addl $PAGE_SIZE_asm,%edi
16757 + loop 1b
16758 +#endif
16759 +
16760 /*
16761 * Clear BSS first so that there are no surprises...
16762 */
16763 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16764 movl %eax, pa(max_pfn_mapped)
16765
16766 /* Do early initialization of the fixmap area */
16767 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16768 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16769 +#ifdef CONFIG_COMPAT_VDSO
16770 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16771 +#else
16772 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16773 +#endif
16774 #else /* Not PAE */
16775
16776 page_pde_offset = (__PAGE_OFFSET >> 20);
16777 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16778 movl %eax, pa(max_pfn_mapped)
16779
16780 /* Do early initialization of the fixmap area */
16781 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16782 - movl %eax,pa(initial_page_table+0xffc)
16783 +#ifdef CONFIG_COMPAT_VDSO
16784 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16785 +#else
16786 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16787 +#endif
16788 #endif
16789
16790 #ifdef CONFIG_PARAVIRT
16791 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16792 cmpl $num_subarch_entries, %eax
16793 jae bad_subarch
16794
16795 - movl pa(subarch_entries)(,%eax,4), %eax
16796 - subl $__PAGE_OFFSET, %eax
16797 - jmp *%eax
16798 + jmp *pa(subarch_entries)(,%eax,4)
16799
16800 bad_subarch:
16801 WEAK(lguest_entry)
16802 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16803 __INITDATA
16804
16805 subarch_entries:
16806 - .long default_entry /* normal x86/PC */
16807 - .long lguest_entry /* lguest hypervisor */
16808 - .long xen_entry /* Xen hypervisor */
16809 - .long default_entry /* Moorestown MID */
16810 + .long ta(default_entry) /* normal x86/PC */
16811 + .long ta(lguest_entry) /* lguest hypervisor */
16812 + .long ta(xen_entry) /* Xen hypervisor */
16813 + .long ta(default_entry) /* Moorestown MID */
16814 num_subarch_entries = (. - subarch_entries) / 4
16815 .previous
16816 #else
16817 @@ -310,6 +380,7 @@ default_entry:
16818 orl %edx,%eax
16819 movl %eax,%cr4
16820
16821 +#ifdef CONFIG_X86_PAE
16822 testb $X86_CR4_PAE, %al # check if PAE is enabled
16823 jz 6f
16824
16825 @@ -338,6 +409,9 @@ default_entry:
16826 /* Make changes effective */
16827 wrmsr
16828
16829 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16830 +#endif
16831 +
16832 6:
16833
16834 /*
16835 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16836 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16837 movl %eax,%ss # after changing gdt.
16838
16839 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16840 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16841 movl %eax,%ds
16842 movl %eax,%es
16843
16844 movl $(__KERNEL_PERCPU), %eax
16845 movl %eax,%fs # set this cpu's percpu
16846
16847 +#ifdef CONFIG_CC_STACKPROTECTOR
16848 movl $(__KERNEL_STACK_CANARY),%eax
16849 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16850 + movl $(__USER_DS),%eax
16851 +#else
16852 + xorl %eax,%eax
16853 +#endif
16854 movl %eax,%gs
16855
16856 xorl %eax,%eax # Clear LDT
16857 @@ -520,8 +600,11 @@ setup_once:
16858 * relocation. Manually set base address in stack canary
16859 * segment descriptor.
16860 */
16861 - movl $gdt_page,%eax
16862 + movl $cpu_gdt_table,%eax
16863 movl $stack_canary,%ecx
16864 +#ifdef CONFIG_SMP
16865 + addl $__per_cpu_load,%ecx
16866 +#endif
16867 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16868 shrl $16, %ecx
16869 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16870 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16871 /* This is global to keep gas from relaxing the jumps */
16872 ENTRY(early_idt_handler)
16873 cld
16874 - cmpl $2,%ss:early_recursion_flag
16875 + cmpl $1,%ss:early_recursion_flag
16876 je hlt_loop
16877 incl %ss:early_recursion_flag
16878
16879 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16880 pushl (20+6*4)(%esp) /* trapno */
16881 pushl $fault_msg
16882 call printk
16883 -#endif
16884 call dump_stack
16885 +#endif
16886 hlt_loop:
16887 hlt
16888 jmp hlt_loop
16889 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16890 /* This is the default interrupt "handler" :-) */
16891 ALIGN
16892 ignore_int:
16893 - cld
16894 #ifdef CONFIG_PRINTK
16895 + cmpl $2,%ss:early_recursion_flag
16896 + je hlt_loop
16897 + incl %ss:early_recursion_flag
16898 + cld
16899 pushl %eax
16900 pushl %ecx
16901 pushl %edx
16902 @@ -620,9 +706,6 @@ ignore_int:
16903 movl $(__KERNEL_DS),%eax
16904 movl %eax,%ds
16905 movl %eax,%es
16906 - cmpl $2,early_recursion_flag
16907 - je hlt_loop
16908 - incl early_recursion_flag
16909 pushl 16(%esp)
16910 pushl 24(%esp)
16911 pushl 32(%esp)
16912 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16913 /*
16914 * BSS section
16915 */
16916 -__PAGE_ALIGNED_BSS
16917 - .align PAGE_SIZE
16918 #ifdef CONFIG_X86_PAE
16919 +.section .initial_pg_pmd,"a",@progbits
16920 initial_pg_pmd:
16921 .fill 1024*KPMDS,4,0
16922 #else
16923 +.section .initial_page_table,"a",@progbits
16924 ENTRY(initial_page_table)
16925 .fill 1024,4,0
16926 #endif
16927 +.section .initial_pg_fixmap,"a",@progbits
16928 initial_pg_fixmap:
16929 .fill 1024,4,0
16930 +.section .empty_zero_page,"a",@progbits
16931 ENTRY(empty_zero_page)
16932 .fill 4096,1,0
16933 +.section .swapper_pg_dir,"a",@progbits
16934 ENTRY(swapper_pg_dir)
16935 +#ifdef CONFIG_X86_PAE
16936 + .fill 4,8,0
16937 +#else
16938 .fill 1024,4,0
16939 +#endif
16940 +
16941 +/*
16942 + * The IDT has to be page-aligned to simplify the Pentium
16943 + * F0 0F bug workaround.. We have a special link segment
16944 + * for this.
16945 + */
16946 +.section .idt,"a",@progbits
16947 +ENTRY(idt_table)
16948 + .fill 256,8,0
16949
16950 /*
16951 * This starts the data section.
16952 */
16953 #ifdef CONFIG_X86_PAE
16954 -__PAGE_ALIGNED_DATA
16955 - /* Page-aligned for the benefit of paravirt? */
16956 - .align PAGE_SIZE
16957 +.section .initial_page_table,"a",@progbits
16958 ENTRY(initial_page_table)
16959 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16960 # if KPMDS == 3
16961 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
16962 # error "Kernel PMDs should be 1, 2 or 3"
16963 # endif
16964 .align PAGE_SIZE /* needs to be page-sized too */
16965 +
16966 +#ifdef CONFIG_PAX_PER_CPU_PGD
16967 +ENTRY(cpu_pgd)
16968 + .rept NR_CPUS
16969 + .fill 4,8,0
16970 + .endr
16971 +#endif
16972 +
16973 #endif
16974
16975 .data
16976 .balign 4
16977 ENTRY(stack_start)
16978 - .long init_thread_union+THREAD_SIZE
16979 + .long init_thread_union+THREAD_SIZE-8
16980
16981 __INITRODATA
16982 int_msg:
16983 @@ -739,7 +844,7 @@ fault_msg:
16984 .word 0 # 32 bit align gdt_desc.address
16985 boot_gdt_descr:
16986 .word __BOOT_DS+7
16987 - .long boot_gdt - __PAGE_OFFSET
16988 + .long pa(boot_gdt)
16989
16990 .word 0 # 32-bit align idt_desc.address
16991 idt_descr:
16992 @@ -750,7 +855,7 @@ idt_descr:
16993 .word 0 # 32 bit align gdt_desc.address
16994 ENTRY(early_gdt_descr)
16995 .word GDT_ENTRIES*8-1
16996 - .long gdt_page /* Overwritten for secondary CPUs */
16997 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16998
16999 /*
17000 * The boot_gdt must mirror the equivalent in setup.S and is
17001 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17002 .align L1_CACHE_BYTES
17003 ENTRY(boot_gdt)
17004 .fill GDT_ENTRY_BOOT_CS,8,0
17005 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17006 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17007 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17008 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17009 +
17010 + .align PAGE_SIZE_asm
17011 +ENTRY(cpu_gdt_table)
17012 + .rept NR_CPUS
17013 + .quad 0x0000000000000000 /* NULL descriptor */
17014 + .quad 0x0000000000000000 /* 0x0b reserved */
17015 + .quad 0x0000000000000000 /* 0x13 reserved */
17016 + .quad 0x0000000000000000 /* 0x1b reserved */
17017 +
17018 +#ifdef CONFIG_PAX_KERNEXEC
17019 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17020 +#else
17021 + .quad 0x0000000000000000 /* 0x20 unused */
17022 +#endif
17023 +
17024 + .quad 0x0000000000000000 /* 0x28 unused */
17025 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17026 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17027 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17028 + .quad 0x0000000000000000 /* 0x4b reserved */
17029 + .quad 0x0000000000000000 /* 0x53 reserved */
17030 + .quad 0x0000000000000000 /* 0x5b reserved */
17031 +
17032 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17033 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17034 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17035 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17036 +
17037 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17038 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17039 +
17040 + /*
17041 + * Segments used for calling PnP BIOS have byte granularity.
17042 + * The code segments and data segments have fixed 64k limits,
17043 + * the transfer segment sizes are set at run time.
17044 + */
17045 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17046 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17047 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17048 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17049 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17050 +
17051 + /*
17052 + * The APM segments have byte granularity and their bases
17053 + * are set at run time. All have 64k limits.
17054 + */
17055 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17056 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17057 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17058 +
17059 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17060 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17061 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17062 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17063 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17064 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17065 +
17066 + /* Be sure this is zeroed to avoid false validations in Xen */
17067 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17068 + .endr
17069 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17070 index 94bf9cc..400455a 100644
17071 --- a/arch/x86/kernel/head_64.S
17072 +++ b/arch/x86/kernel/head_64.S
17073 @@ -20,6 +20,8 @@
17074 #include <asm/processor-flags.h>
17075 #include <asm/percpu.h>
17076 #include <asm/nops.h>
17077 +#include <asm/cpufeature.h>
17078 +#include <asm/alternative-asm.h>
17079
17080 #ifdef CONFIG_PARAVIRT
17081 #include <asm/asm-offsets.h>
17082 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17083 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17084 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17085 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17086 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17087 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17088 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17089 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17090 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17091 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17092
17093 .text
17094 __HEAD
17095 @@ -88,35 +96,23 @@ startup_64:
17096 */
17097 addq %rbp, init_level4_pgt + 0(%rip)
17098 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17099 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17100 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17101 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17102 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17103
17104 addq %rbp, level3_ident_pgt + 0(%rip)
17105 +#ifndef CONFIG_XEN
17106 + addq %rbp, level3_ident_pgt + 8(%rip)
17107 +#endif
17108
17109 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17110 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17111 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17112 +
17113 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17114 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17115
17116 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17117 -
17118 - /* Add an Identity mapping if I am above 1G */
17119 - leaq _text(%rip), %rdi
17120 - andq $PMD_PAGE_MASK, %rdi
17121 -
17122 - movq %rdi, %rax
17123 - shrq $PUD_SHIFT, %rax
17124 - andq $(PTRS_PER_PUD - 1), %rax
17125 - jz ident_complete
17126 -
17127 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17128 - leaq level3_ident_pgt(%rip), %rbx
17129 - movq %rdx, 0(%rbx, %rax, 8)
17130 -
17131 - movq %rdi, %rax
17132 - shrq $PMD_SHIFT, %rax
17133 - andq $(PTRS_PER_PMD - 1), %rax
17134 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17135 - leaq level2_spare_pgt(%rip), %rbx
17136 - movq %rdx, 0(%rbx, %rax, 8)
17137 -ident_complete:
17138 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17139
17140 /*
17141 * Fixup the kernel text+data virtual addresses. Note that
17142 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17143 * after the boot processor executes this code.
17144 */
17145
17146 - /* Enable PAE mode and PGE */
17147 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17148 + /* Enable PAE mode and PSE/PGE */
17149 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17150 movq %rax, %cr4
17151
17152 /* Setup early boot stage 4 level pagetables. */
17153 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17154 movl $MSR_EFER, %ecx
17155 rdmsr
17156 btsl $_EFER_SCE, %eax /* Enable System Call */
17157 - btl $20,%edi /* No Execute supported? */
17158 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17159 jnc 1f
17160 btsl $_EFER_NX, %eax
17161 + leaq init_level4_pgt(%rip), %rdi
17162 +#ifndef CONFIG_EFI
17163 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17164 +#endif
17165 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17166 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17167 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17168 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17169 1: wrmsr /* Make changes effective */
17170
17171 /* Setup cr0 */
17172 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17173 * jump. In addition we need to ensure %cs is set so we make this
17174 * a far return.
17175 */
17176 + pax_set_fptr_mask
17177 movq initial_code(%rip),%rax
17178 pushq $0 # fake return address to stop unwinder
17179 pushq $__KERNEL_CS # set correct cs
17180 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17181 bad_address:
17182 jmp bad_address
17183
17184 - .section ".init.text","ax"
17185 + __INIT
17186 .globl early_idt_handlers
17187 early_idt_handlers:
17188 # 104(%rsp) %rflags
17189 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17190 addq $16,%rsp # drop vector number and error code
17191 decl early_recursion_flag(%rip)
17192 INTERRUPT_RETURN
17193 + .previous
17194
17195 + __INITDATA
17196 .balign 4
17197 early_recursion_flag:
17198 .long 0
17199 + .previous
17200
17201 + .section .rodata,"a",@progbits
17202 #ifdef CONFIG_EARLY_PRINTK
17203 early_idt_msg:
17204 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17205 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17206 #endif /* CONFIG_EARLY_PRINTK */
17207 .previous
17208
17209 + .section .rodata,"a",@progbits
17210 #define NEXT_PAGE(name) \
17211 .balign PAGE_SIZE; \
17212 ENTRY(name)
17213 @@ -372,7 +382,6 @@ ENTRY(name)
17214 i = i + 1 ; \
17215 .endr
17216
17217 - .data
17218 /*
17219 * This default setting generates an ident mapping at address 0x100000
17220 * and a mapping for the kernel that precisely maps virtual address
17221 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17222 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17223 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17224 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17225 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17226 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17227 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17228 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17229 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17230 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17231 .org init_level4_pgt + L4_START_KERNEL*8, 0
17232 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17233 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17234
17235 +#ifdef CONFIG_PAX_PER_CPU_PGD
17236 +NEXT_PAGE(cpu_pgd)
17237 + .rept NR_CPUS
17238 + .fill 512,8,0
17239 + .endr
17240 +#endif
17241 +
17242 NEXT_PAGE(level3_ident_pgt)
17243 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17244 +#ifdef CONFIG_XEN
17245 .fill 511,8,0
17246 +#else
17247 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17248 + .fill 510,8,0
17249 +#endif
17250 +
17251 +NEXT_PAGE(level3_vmalloc_start_pgt)
17252 + .fill 512,8,0
17253 +
17254 +NEXT_PAGE(level3_vmalloc_end_pgt)
17255 + .fill 512,8,0
17256 +
17257 +NEXT_PAGE(level3_vmemmap_pgt)
17258 + .fill L3_VMEMMAP_START,8,0
17259 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17260
17261 NEXT_PAGE(level3_kernel_pgt)
17262 .fill L3_START_KERNEL,8,0
17263 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17264 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17265 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17266
17267 +NEXT_PAGE(level2_vmemmap_pgt)
17268 + .fill 512,8,0
17269 +
17270 NEXT_PAGE(level2_fixmap_pgt)
17271 - .fill 506,8,0
17272 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17273 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17274 - .fill 5,8,0
17275 + .fill 507,8,0
17276 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17277 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17278 + .fill 4,8,0
17279
17280 -NEXT_PAGE(level1_fixmap_pgt)
17281 +NEXT_PAGE(level1_vsyscall_pgt)
17282 .fill 512,8,0
17283
17284 -NEXT_PAGE(level2_ident_pgt)
17285 - /* Since I easily can, map the first 1G.
17286 + /* Since I easily can, map the first 2G.
17287 * Don't set NX because code runs from these pages.
17288 */
17289 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17290 +NEXT_PAGE(level2_ident_pgt)
17291 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17292
17293 NEXT_PAGE(level2_kernel_pgt)
17294 /*
17295 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17296 * If you want to increase this then increase MODULES_VADDR
17297 * too.)
17298 */
17299 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17300 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17301 -
17302 -NEXT_PAGE(level2_spare_pgt)
17303 - .fill 512, 8, 0
17304 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17305
17306 #undef PMDS
17307 #undef NEXT_PAGE
17308
17309 - .data
17310 + .align PAGE_SIZE
17311 +ENTRY(cpu_gdt_table)
17312 + .rept NR_CPUS
17313 + .quad 0x0000000000000000 /* NULL descriptor */
17314 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17315 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17316 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17317 + .quad 0x00cffb000000ffff /* __USER32_CS */
17318 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17319 + .quad 0x00affb000000ffff /* __USER_CS */
17320 +
17321 +#ifdef CONFIG_PAX_KERNEXEC
17322 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17323 +#else
17324 + .quad 0x0 /* unused */
17325 +#endif
17326 +
17327 + .quad 0,0 /* TSS */
17328 + .quad 0,0 /* LDT */
17329 + .quad 0,0,0 /* three TLS descriptors */
17330 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17331 + /* asm/segment.h:GDT_ENTRIES must match this */
17332 +
17333 + /* zero the remaining page */
17334 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17335 + .endr
17336 +
17337 .align 16
17338 .globl early_gdt_descr
17339 early_gdt_descr:
17340 .word GDT_ENTRIES*8-1
17341 early_gdt_descr_base:
17342 - .quad INIT_PER_CPU_VAR(gdt_page)
17343 + .quad cpu_gdt_table
17344
17345 ENTRY(phys_base)
17346 /* This must match the first entry in level2_kernel_pgt */
17347 .quad 0x0000000000000000
17348
17349 #include "../../x86/xen/xen-head.S"
17350 -
17351 - .section .bss, "aw", @nobits
17352 +
17353 + .section .rodata,"a",@progbits
17354 .align L1_CACHE_BYTES
17355 ENTRY(idt_table)
17356 - .skip IDT_ENTRIES * 16
17357 + .fill 512,8,0
17358
17359 .align L1_CACHE_BYTES
17360 ENTRY(nmi_idt_table)
17361 - .skip IDT_ENTRIES * 16
17362 + .fill 512,8,0
17363
17364 __PAGE_ALIGNED_BSS
17365 .align PAGE_SIZE
17366 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17367 index 9c3bd4a..e1d9b35 100644
17368 --- a/arch/x86/kernel/i386_ksyms_32.c
17369 +++ b/arch/x86/kernel/i386_ksyms_32.c
17370 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17371 EXPORT_SYMBOL(cmpxchg8b_emu);
17372 #endif
17373
17374 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17375 +
17376 /* Networking helper routines. */
17377 EXPORT_SYMBOL(csum_partial_copy_generic);
17378 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17379 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17380
17381 EXPORT_SYMBOL(__get_user_1);
17382 EXPORT_SYMBOL(__get_user_2);
17383 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17384
17385 EXPORT_SYMBOL(csum_partial);
17386 EXPORT_SYMBOL(empty_zero_page);
17387 +
17388 +#ifdef CONFIG_PAX_KERNEXEC
17389 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17390 +#endif
17391 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17392 index f250431..54097e7 100644
17393 --- a/arch/x86/kernel/i387.c
17394 +++ b/arch/x86/kernel/i387.c
17395 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17396 static inline bool interrupted_user_mode(void)
17397 {
17398 struct pt_regs *regs = get_irq_regs();
17399 - return regs && user_mode_vm(regs);
17400 + return regs && user_mode(regs);
17401 }
17402
17403 /*
17404 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17405 index 36d1853..bf25736 100644
17406 --- a/arch/x86/kernel/i8259.c
17407 +++ b/arch/x86/kernel/i8259.c
17408 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17409 "spurious 8259A interrupt: IRQ%d.\n", irq);
17410 spurious_irq_mask |= irqmask;
17411 }
17412 - atomic_inc(&irq_err_count);
17413 + atomic_inc_unchecked(&irq_err_count);
17414 /*
17415 * Theoretically we do not have to handle this IRQ,
17416 * but in Linux this does not cause problems and is
17417 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17418 index 8c96897..be66bfa 100644
17419 --- a/arch/x86/kernel/ioport.c
17420 +++ b/arch/x86/kernel/ioport.c
17421 @@ -6,6 +6,7 @@
17422 #include <linux/sched.h>
17423 #include <linux/kernel.h>
17424 #include <linux/capability.h>
17425 +#include <linux/security.h>
17426 #include <linux/errno.h>
17427 #include <linux/types.h>
17428 #include <linux/ioport.h>
17429 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17430
17431 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17432 return -EINVAL;
17433 +#ifdef CONFIG_GRKERNSEC_IO
17434 + if (turn_on && grsec_disable_privio) {
17435 + gr_handle_ioperm();
17436 + return -EPERM;
17437 + }
17438 +#endif
17439 if (turn_on && !capable(CAP_SYS_RAWIO))
17440 return -EPERM;
17441
17442 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17443 * because the ->io_bitmap_max value must match the bitmap
17444 * contents:
17445 */
17446 - tss = &per_cpu(init_tss, get_cpu());
17447 + tss = init_tss + get_cpu();
17448
17449 if (turn_on)
17450 bitmap_clear(t->io_bitmap_ptr, from, num);
17451 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17452 return -EINVAL;
17453 /* Trying to gain more privileges? */
17454 if (level > old) {
17455 +#ifdef CONFIG_GRKERNSEC_IO
17456 + if (grsec_disable_privio) {
17457 + gr_handle_iopl();
17458 + return -EPERM;
17459 + }
17460 +#endif
17461 if (!capable(CAP_SYS_RAWIO))
17462 return -EPERM;
17463 }
17464 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17465 index 3dafc60..aa8e9c4 100644
17466 --- a/arch/x86/kernel/irq.c
17467 +++ b/arch/x86/kernel/irq.c
17468 @@ -18,7 +18,7 @@
17469 #include <asm/mce.h>
17470 #include <asm/hw_irq.h>
17471
17472 -atomic_t irq_err_count;
17473 +atomic_unchecked_t irq_err_count;
17474
17475 /* Function pointer for generic interrupt vector handling */
17476 void (*x86_platform_ipi_callback)(void) = NULL;
17477 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17478 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17479 seq_printf(p, " Machine check polls\n");
17480 #endif
17481 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17482 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17483 #if defined(CONFIG_X86_IO_APIC)
17484 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17485 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17486 #endif
17487 return 0;
17488 }
17489 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17490
17491 u64 arch_irq_stat(void)
17492 {
17493 - u64 sum = atomic_read(&irq_err_count);
17494 + u64 sum = atomic_read_unchecked(&irq_err_count);
17495
17496 #ifdef CONFIG_X86_IO_APIC
17497 - sum += atomic_read(&irq_mis_count);
17498 + sum += atomic_read_unchecked(&irq_mis_count);
17499 #endif
17500 return sum;
17501 }
17502 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17503 index 344faf8..355f60d 100644
17504 --- a/arch/x86/kernel/irq_32.c
17505 +++ b/arch/x86/kernel/irq_32.c
17506 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17507 __asm__ __volatile__("andl %%esp,%0" :
17508 "=r" (sp) : "0" (THREAD_SIZE - 1));
17509
17510 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17511 + return sp < STACK_WARN;
17512 }
17513
17514 static void print_stack_overflow(void)
17515 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17516 * per-CPU IRQ handling contexts (thread information and stack)
17517 */
17518 union irq_ctx {
17519 - struct thread_info tinfo;
17520 - u32 stack[THREAD_SIZE/sizeof(u32)];
17521 + unsigned long previous_esp;
17522 + u32 stack[THREAD_SIZE/sizeof(u32)];
17523 } __attribute__((aligned(THREAD_SIZE)));
17524
17525 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17526 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17527 static inline int
17528 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17529 {
17530 - union irq_ctx *curctx, *irqctx;
17531 + union irq_ctx *irqctx;
17532 u32 *isp, arg1, arg2;
17533
17534 - curctx = (union irq_ctx *) current_thread_info();
17535 irqctx = __this_cpu_read(hardirq_ctx);
17536
17537 /*
17538 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17539 * handler) we can't do that and just have to keep using the
17540 * current stack (which is the irq stack already after all)
17541 */
17542 - if (unlikely(curctx == irqctx))
17543 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17544 return 0;
17545
17546 /* build the stack frame on the IRQ stack */
17547 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17548 - irqctx->tinfo.task = curctx->tinfo.task;
17549 - irqctx->tinfo.previous_esp = current_stack_pointer;
17550 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17551 + irqctx->previous_esp = current_stack_pointer;
17552
17553 - /* Copy the preempt_count so that the [soft]irq checks work. */
17554 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17555 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17556 + __set_fs(MAKE_MM_SEG(0));
17557 +#endif
17558
17559 if (unlikely(overflow))
17560 call_on_stack(print_stack_overflow, isp);
17561 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17562 : "0" (irq), "1" (desc), "2" (isp),
17563 "D" (desc->handle_irq)
17564 : "memory", "cc", "ecx");
17565 +
17566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17567 + __set_fs(current_thread_info()->addr_limit);
17568 +#endif
17569 +
17570 return 1;
17571 }
17572
17573 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17574 */
17575 void __cpuinit irq_ctx_init(int cpu)
17576 {
17577 - union irq_ctx *irqctx;
17578 -
17579 if (per_cpu(hardirq_ctx, cpu))
17580 return;
17581
17582 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17583 - THREADINFO_GFP,
17584 - THREAD_SIZE_ORDER));
17585 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17586 - irqctx->tinfo.cpu = cpu;
17587 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17588 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17589 -
17590 - per_cpu(hardirq_ctx, cpu) = irqctx;
17591 -
17592 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17593 - THREADINFO_GFP,
17594 - THREAD_SIZE_ORDER));
17595 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17596 - irqctx->tinfo.cpu = cpu;
17597 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17598 -
17599 - per_cpu(softirq_ctx, cpu) = irqctx;
17600 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17601 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17602 +
17603 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17604 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17605
17606 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17607 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17608 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17609 asmlinkage void do_softirq(void)
17610 {
17611 unsigned long flags;
17612 - struct thread_info *curctx;
17613 union irq_ctx *irqctx;
17614 u32 *isp;
17615
17616 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17617 local_irq_save(flags);
17618
17619 if (local_softirq_pending()) {
17620 - curctx = current_thread_info();
17621 irqctx = __this_cpu_read(softirq_ctx);
17622 - irqctx->tinfo.task = curctx->task;
17623 - irqctx->tinfo.previous_esp = current_stack_pointer;
17624 + irqctx->previous_esp = current_stack_pointer;
17625
17626 /* build the stack frame on the softirq stack */
17627 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17628 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17629 +
17630 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17631 + __set_fs(MAKE_MM_SEG(0));
17632 +#endif
17633
17634 call_on_stack(__do_softirq, isp);
17635 +
17636 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17637 + __set_fs(current_thread_info()->addr_limit);
17638 +#endif
17639 +
17640 /*
17641 * Shouldn't happen, we returned above if in_interrupt():
17642 */
17643 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17644 if (unlikely(!desc))
17645 return false;
17646
17647 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17648 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17649 if (unlikely(overflow))
17650 print_stack_overflow();
17651 desc->handle_irq(irq, desc);
17652 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17653 index d04d3ec..ea4b374 100644
17654 --- a/arch/x86/kernel/irq_64.c
17655 +++ b/arch/x86/kernel/irq_64.c
17656 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17657 u64 estack_top, estack_bottom;
17658 u64 curbase = (u64)task_stack_page(current);
17659
17660 - if (user_mode_vm(regs))
17661 + if (user_mode(regs))
17662 return;
17663
17664 if (regs->sp >= curbase + sizeof(struct thread_info) +
17665 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17666 index 1d5d31e..ab846ed 100644
17667 --- a/arch/x86/kernel/kdebugfs.c
17668 +++ b/arch/x86/kernel/kdebugfs.c
17669 @@ -28,6 +28,8 @@ struct setup_data_node {
17670 };
17671
17672 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17673 + size_t count, loff_t *ppos) __size_overflow(3);
17674 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17675 size_t count, loff_t *ppos)
17676 {
17677 struct setup_data_node *node = file->private_data;
17678 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17679 index 3f61904..873cea9 100644
17680 --- a/arch/x86/kernel/kgdb.c
17681 +++ b/arch/x86/kernel/kgdb.c
17682 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17683 #ifdef CONFIG_X86_32
17684 switch (regno) {
17685 case GDB_SS:
17686 - if (!user_mode_vm(regs))
17687 + if (!user_mode(regs))
17688 *(unsigned long *)mem = __KERNEL_DS;
17689 break;
17690 case GDB_SP:
17691 - if (!user_mode_vm(regs))
17692 + if (!user_mode(regs))
17693 *(unsigned long *)mem = kernel_stack_pointer(regs);
17694 break;
17695 case GDB_GS:
17696 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17697 case 'k':
17698 /* clear the trace bit */
17699 linux_regs->flags &= ~X86_EFLAGS_TF;
17700 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17701 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17702
17703 /* set the trace bit if we're stepping */
17704 if (remcomInBuffer[0] == 's') {
17705 linux_regs->flags |= X86_EFLAGS_TF;
17706 - atomic_set(&kgdb_cpu_doing_single_step,
17707 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17708 raw_smp_processor_id());
17709 }
17710
17711 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17712
17713 switch (cmd) {
17714 case DIE_DEBUG:
17715 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17716 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17717 if (user_mode(regs))
17718 return single_step_cont(regs, args);
17719 break;
17720 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17721 index c5e410e..da6aaf9 100644
17722 --- a/arch/x86/kernel/kprobes-opt.c
17723 +++ b/arch/x86/kernel/kprobes-opt.c
17724 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17725 * Verify if the address gap is in 2GB range, because this uses
17726 * a relative jump.
17727 */
17728 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17729 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17730 if (abs(rel) > 0x7fffffff)
17731 return -ERANGE;
17732
17733 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17734 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17735
17736 /* Set probe function call */
17737 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17738 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17739
17740 /* Set returning jmp instruction at the tail of out-of-line buffer */
17741 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17742 - (u8 *)op->kp.addr + op->optinsn.size);
17743 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17744
17745 flush_icache_range((unsigned long) buf,
17746 (unsigned long) buf + TMPL_END_IDX +
17747 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17748 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17749
17750 /* Backup instructions which will be replaced by jump address */
17751 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17752 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17753 RELATIVE_ADDR_SIZE);
17754
17755 insn_buf[0] = RELATIVEJUMP_OPCODE;
17756 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17757 index e2f751e..dffa2a0 100644
17758 --- a/arch/x86/kernel/kprobes.c
17759 +++ b/arch/x86/kernel/kprobes.c
17760 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17761 } __attribute__((packed)) *insn;
17762
17763 insn = (struct __arch_relative_insn *)from;
17764 +
17765 + pax_open_kernel();
17766 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17767 insn->op = op;
17768 + pax_close_kernel();
17769 }
17770
17771 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17772 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17773 kprobe_opcode_t opcode;
17774 kprobe_opcode_t *orig_opcodes = opcodes;
17775
17776 - if (search_exception_tables((unsigned long)opcodes))
17777 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17778 return 0; /* Page fault may occur on this address. */
17779
17780 retry:
17781 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17782 /* Another subsystem puts a breakpoint, failed to recover */
17783 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17784 return 0;
17785 + pax_open_kernel();
17786 memcpy(dest, insn.kaddr, insn.length);
17787 + pax_close_kernel();
17788
17789 #ifdef CONFIG_X86_64
17790 if (insn_rip_relative(&insn)) {
17791 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17792 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17793 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17794 disp = (u8 *) dest + insn_offset_displacement(&insn);
17795 + pax_open_kernel();
17796 *(s32 *) disp = (s32) newdisp;
17797 + pax_close_kernel();
17798 }
17799 #endif
17800 return insn.length;
17801 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17802 * nor set current_kprobe, because it doesn't use single
17803 * stepping.
17804 */
17805 - regs->ip = (unsigned long)p->ainsn.insn;
17806 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17807 preempt_enable_no_resched();
17808 return;
17809 }
17810 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17811 if (p->opcode == BREAKPOINT_INSTRUCTION)
17812 regs->ip = (unsigned long)p->addr;
17813 else
17814 - regs->ip = (unsigned long)p->ainsn.insn;
17815 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17816 }
17817
17818 /*
17819 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17820 setup_singlestep(p, regs, kcb, 0);
17821 return 1;
17822 }
17823 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17824 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17825 /*
17826 * The breakpoint instruction was removed right
17827 * after we hit it. Another cpu has removed
17828 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17829 " movq %rax, 152(%rsp)\n"
17830 RESTORE_REGS_STRING
17831 " popfq\n"
17832 +#ifdef KERNEXEC_PLUGIN
17833 + " btsq $63,(%rsp)\n"
17834 +#endif
17835 #else
17836 " pushf\n"
17837 SAVE_REGS_STRING
17838 @@ -765,7 +775,7 @@ static void __kprobes
17839 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17840 {
17841 unsigned long *tos = stack_addr(regs);
17842 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17843 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17844 unsigned long orig_ip = (unsigned long)p->addr;
17845 kprobe_opcode_t *insn = p->ainsn.insn;
17846
17847 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17848 struct die_args *args = data;
17849 int ret = NOTIFY_DONE;
17850
17851 - if (args->regs && user_mode_vm(args->regs))
17852 + if (args->regs && user_mode(args->regs))
17853 return ret;
17854
17855 switch (val) {
17856 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17857 index ebc9873..1b9724b 100644
17858 --- a/arch/x86/kernel/ldt.c
17859 +++ b/arch/x86/kernel/ldt.c
17860 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17861 if (reload) {
17862 #ifdef CONFIG_SMP
17863 preempt_disable();
17864 - load_LDT(pc);
17865 + load_LDT_nolock(pc);
17866 if (!cpumask_equal(mm_cpumask(current->mm),
17867 cpumask_of(smp_processor_id())))
17868 smp_call_function(flush_ldt, current->mm, 1);
17869 preempt_enable();
17870 #else
17871 - load_LDT(pc);
17872 + load_LDT_nolock(pc);
17873 #endif
17874 }
17875 if (oldsize) {
17876 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17877 return err;
17878
17879 for (i = 0; i < old->size; i++)
17880 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17881 + write_ldt_entry(new->ldt, i, old->ldt + i);
17882 return 0;
17883 }
17884
17885 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17886 retval = copy_ldt(&mm->context, &old_mm->context);
17887 mutex_unlock(&old_mm->context.lock);
17888 }
17889 +
17890 + if (tsk == current) {
17891 + mm->context.vdso = 0;
17892 +
17893 +#ifdef CONFIG_X86_32
17894 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17895 + mm->context.user_cs_base = 0UL;
17896 + mm->context.user_cs_limit = ~0UL;
17897 +
17898 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17899 + cpus_clear(mm->context.cpu_user_cs_mask);
17900 +#endif
17901 +
17902 +#endif
17903 +#endif
17904 +
17905 + }
17906 +
17907 return retval;
17908 }
17909
17910 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17911 }
17912 }
17913
17914 +#ifdef CONFIG_PAX_SEGMEXEC
17915 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17916 + error = -EINVAL;
17917 + goto out_unlock;
17918 + }
17919 +#endif
17920 +
17921 fill_ldt(&ldt, &ldt_info);
17922 if (oldmode)
17923 ldt.avl = 0;
17924 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17925 index 5b19e4d..6476a76 100644
17926 --- a/arch/x86/kernel/machine_kexec_32.c
17927 +++ b/arch/x86/kernel/machine_kexec_32.c
17928 @@ -26,7 +26,7 @@
17929 #include <asm/cacheflush.h>
17930 #include <asm/debugreg.h>
17931
17932 -static void set_idt(void *newidt, __u16 limit)
17933 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17934 {
17935 struct desc_ptr curidt;
17936
17937 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17938 }
17939
17940
17941 -static void set_gdt(void *newgdt, __u16 limit)
17942 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17943 {
17944 struct desc_ptr curgdt;
17945
17946 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17947 }
17948
17949 control_page = page_address(image->control_code_page);
17950 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17951 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17952
17953 relocate_kernel_ptr = control_page;
17954 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17955 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17956 index 0327e2b..e43737b 100644
17957 --- a/arch/x86/kernel/microcode_intel.c
17958 +++ b/arch/x86/kernel/microcode_intel.c
17959 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17960
17961 static int get_ucode_user(void *to, const void *from, size_t n)
17962 {
17963 - return copy_from_user(to, from, n);
17964 + return copy_from_user(to, (const void __force_user *)from, n);
17965 }
17966
17967 static enum ucode_state
17968 request_microcode_user(int cpu, const void __user *buf, size_t size)
17969 {
17970 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17971 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17972 }
17973
17974 static void microcode_fini_cpu(int cpu)
17975 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17976 index f21fd94..61565cd 100644
17977 --- a/arch/x86/kernel/module.c
17978 +++ b/arch/x86/kernel/module.c
17979 @@ -35,15 +35,60 @@
17980 #define DEBUGP(fmt...)
17981 #endif
17982
17983 -void *module_alloc(unsigned long size)
17984 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17985 {
17986 - if (PAGE_ALIGN(size) > MODULES_LEN)
17987 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17988 return NULL;
17989 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17990 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17991 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17992 -1, __builtin_return_address(0));
17993 }
17994
17995 +void *module_alloc(unsigned long size)
17996 +{
17997 +
17998 +#ifdef CONFIG_PAX_KERNEXEC
17999 + return __module_alloc(size, PAGE_KERNEL);
18000 +#else
18001 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18002 +#endif
18003 +
18004 +}
18005 +
18006 +#ifdef CONFIG_PAX_KERNEXEC
18007 +#ifdef CONFIG_X86_32
18008 +void *module_alloc_exec(unsigned long size)
18009 +{
18010 + struct vm_struct *area;
18011 +
18012 + if (size == 0)
18013 + return NULL;
18014 +
18015 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18016 + return area ? area->addr : NULL;
18017 +}
18018 +EXPORT_SYMBOL(module_alloc_exec);
18019 +
18020 +void module_free_exec(struct module *mod, void *module_region)
18021 +{
18022 + vunmap(module_region);
18023 +}
18024 +EXPORT_SYMBOL(module_free_exec);
18025 +#else
18026 +void module_free_exec(struct module *mod, void *module_region)
18027 +{
18028 + module_free(mod, module_region);
18029 +}
18030 +EXPORT_SYMBOL(module_free_exec);
18031 +
18032 +void *module_alloc_exec(unsigned long size)
18033 +{
18034 + return __module_alloc(size, PAGE_KERNEL_RX);
18035 +}
18036 +EXPORT_SYMBOL(module_alloc_exec);
18037 +#endif
18038 +#endif
18039 +
18040 #ifdef CONFIG_X86_32
18041 int apply_relocate(Elf32_Shdr *sechdrs,
18042 const char *strtab,
18043 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18044 unsigned int i;
18045 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18046 Elf32_Sym *sym;
18047 - uint32_t *location;
18048 + uint32_t *plocation, location;
18049
18050 DEBUGP("Applying relocate section %u to %u\n", relsec,
18051 sechdrs[relsec].sh_info);
18052 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18053 /* This is where to make the change */
18054 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18055 - + rel[i].r_offset;
18056 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18057 + location = (uint32_t)plocation;
18058 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18059 + plocation = ktla_ktva((void *)plocation);
18060 /* This is the symbol it is referring to. Note that all
18061 undefined symbols have been resolved. */
18062 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18063 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18064 switch (ELF32_R_TYPE(rel[i].r_info)) {
18065 case R_386_32:
18066 /* We add the value into the location given */
18067 - *location += sym->st_value;
18068 + pax_open_kernel();
18069 + *plocation += sym->st_value;
18070 + pax_close_kernel();
18071 break;
18072 case R_386_PC32:
18073 /* Add the value, subtract its postition */
18074 - *location += sym->st_value - (uint32_t)location;
18075 + pax_open_kernel();
18076 + *plocation += sym->st_value - location;
18077 + pax_close_kernel();
18078 break;
18079 default:
18080 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18081 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18082 case R_X86_64_NONE:
18083 break;
18084 case R_X86_64_64:
18085 + pax_open_kernel();
18086 *(u64 *)loc = val;
18087 + pax_close_kernel();
18088 break;
18089 case R_X86_64_32:
18090 + pax_open_kernel();
18091 *(u32 *)loc = val;
18092 + pax_close_kernel();
18093 if (val != *(u32 *)loc)
18094 goto overflow;
18095 break;
18096 case R_X86_64_32S:
18097 + pax_open_kernel();
18098 *(s32 *)loc = val;
18099 + pax_close_kernel();
18100 if ((s64)val != *(s32 *)loc)
18101 goto overflow;
18102 break;
18103 case R_X86_64_PC32:
18104 val -= (u64)loc;
18105 + pax_open_kernel();
18106 *(u32 *)loc = val;
18107 + pax_close_kernel();
18108 +
18109 #if 0
18110 if ((s64)val != *(s32 *)loc)
18111 goto overflow;
18112 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18113 index a0b2f84..875ab81 100644
18114 --- a/arch/x86/kernel/nmi.c
18115 +++ b/arch/x86/kernel/nmi.c
18116 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18117 dotraplinkage notrace __kprobes void
18118 do_nmi(struct pt_regs *regs, long error_code)
18119 {
18120 +
18121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18122 + if (!user_mode(regs)) {
18123 + unsigned long cs = regs->cs & 0xFFFF;
18124 + unsigned long ip = ktva_ktla(regs->ip);
18125 +
18126 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18127 + regs->ip = ip;
18128 + }
18129 +#endif
18130 +
18131 nmi_nesting_preprocess(regs);
18132
18133 nmi_enter();
18134 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18135 index 676b8c7..870ba04 100644
18136 --- a/arch/x86/kernel/paravirt-spinlocks.c
18137 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18138 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18139 arch_spin_lock(lock);
18140 }
18141
18142 -struct pv_lock_ops pv_lock_ops = {
18143 +struct pv_lock_ops pv_lock_ops __read_only = {
18144 #ifdef CONFIG_SMP
18145 .spin_is_locked = __ticket_spin_is_locked,
18146 .spin_is_contended = __ticket_spin_is_contended,
18147 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18148 index 9ce8859..b49bf51 100644
18149 --- a/arch/x86/kernel/paravirt.c
18150 +++ b/arch/x86/kernel/paravirt.c
18151 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18152 {
18153 return x;
18154 }
18155 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18156 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18157 +#endif
18158
18159 void __init default_banner(void)
18160 {
18161 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18162 if (opfunc == NULL)
18163 /* If there's no function, patch it with a ud2a (BUG) */
18164 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18165 - else if (opfunc == _paravirt_nop)
18166 + else if (opfunc == (void *)_paravirt_nop)
18167 /* If the operation is a nop, then nop the callsite */
18168 ret = paravirt_patch_nop();
18169
18170 /* identity functions just return their single argument */
18171 - else if (opfunc == _paravirt_ident_32)
18172 + else if (opfunc == (void *)_paravirt_ident_32)
18173 ret = paravirt_patch_ident_32(insnbuf, len);
18174 - else if (opfunc == _paravirt_ident_64)
18175 + else if (opfunc == (void *)_paravirt_ident_64)
18176 ret = paravirt_patch_ident_64(insnbuf, len);
18177 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18178 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18179 + ret = paravirt_patch_ident_64(insnbuf, len);
18180 +#endif
18181
18182 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18183 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18184 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18185 if (insn_len > len || start == NULL)
18186 insn_len = len;
18187 else
18188 - memcpy(insnbuf, start, insn_len);
18189 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18190
18191 return insn_len;
18192 }
18193 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18194 preempt_enable();
18195 }
18196
18197 -struct pv_info pv_info = {
18198 +struct pv_info pv_info __read_only = {
18199 .name = "bare hardware",
18200 .paravirt_enabled = 0,
18201 .kernel_rpl = 0,
18202 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18203 #endif
18204 };
18205
18206 -struct pv_init_ops pv_init_ops = {
18207 +struct pv_init_ops pv_init_ops __read_only = {
18208 .patch = native_patch,
18209 };
18210
18211 -struct pv_time_ops pv_time_ops = {
18212 +struct pv_time_ops pv_time_ops __read_only = {
18213 .sched_clock = native_sched_clock,
18214 .steal_clock = native_steal_clock,
18215 };
18216
18217 -struct pv_irq_ops pv_irq_ops = {
18218 +struct pv_irq_ops pv_irq_ops __read_only = {
18219 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18220 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18221 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18222 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18223 #endif
18224 };
18225
18226 -struct pv_cpu_ops pv_cpu_ops = {
18227 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18228 .cpuid = native_cpuid,
18229 .get_debugreg = native_get_debugreg,
18230 .set_debugreg = native_set_debugreg,
18231 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18232 .end_context_switch = paravirt_nop,
18233 };
18234
18235 -struct pv_apic_ops pv_apic_ops = {
18236 +struct pv_apic_ops pv_apic_ops __read_only = {
18237 #ifdef CONFIG_X86_LOCAL_APIC
18238 .startup_ipi_hook = paravirt_nop,
18239 #endif
18240 };
18241
18242 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18243 +#ifdef CONFIG_X86_32
18244 +#ifdef CONFIG_X86_PAE
18245 +/* 64-bit pagetable entries */
18246 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18247 +#else
18248 /* 32-bit pagetable entries */
18249 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18250 +#endif
18251 #else
18252 /* 64-bit pagetable entries */
18253 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18254 #endif
18255
18256 -struct pv_mmu_ops pv_mmu_ops = {
18257 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18258
18259 .read_cr2 = native_read_cr2,
18260 .write_cr2 = native_write_cr2,
18261 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18262 .make_pud = PTE_IDENT,
18263
18264 .set_pgd = native_set_pgd,
18265 + .set_pgd_batched = native_set_pgd_batched,
18266 #endif
18267 #endif /* PAGETABLE_LEVELS >= 3 */
18268
18269 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18270 },
18271
18272 .set_fixmap = native_set_fixmap,
18273 +
18274 +#ifdef CONFIG_PAX_KERNEXEC
18275 + .pax_open_kernel = native_pax_open_kernel,
18276 + .pax_close_kernel = native_pax_close_kernel,
18277 +#endif
18278 +
18279 };
18280
18281 EXPORT_SYMBOL_GPL(pv_time_ops);
18282 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18283 index 35ccf75..7a15747 100644
18284 --- a/arch/x86/kernel/pci-iommu_table.c
18285 +++ b/arch/x86/kernel/pci-iommu_table.c
18286 @@ -2,7 +2,7 @@
18287 #include <asm/iommu_table.h>
18288 #include <linux/string.h>
18289 #include <linux/kallsyms.h>
18290 -
18291 +#include <linux/sched.h>
18292
18293 #define DEBUG 1
18294
18295 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18296 index 735279e..5008677 100644
18297 --- a/arch/x86/kernel/process.c
18298 +++ b/arch/x86/kernel/process.c
18299 @@ -34,7 +34,8 @@
18300 * section. Since TSS's are completely CPU-local, we want them
18301 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18302 */
18303 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18304 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18305 +EXPORT_SYMBOL(init_tss);
18306
18307 #ifdef CONFIG_X86_64
18308 static DEFINE_PER_CPU(unsigned char, is_idle);
18309 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18310 task_xstate_cachep =
18311 kmem_cache_create("task_xstate", xstate_size,
18312 __alignof__(union thread_xstate),
18313 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18314 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18315 }
18316
18317 static inline void drop_fpu(struct task_struct *tsk)
18318 @@ -115,7 +116,7 @@ void exit_thread(void)
18319 unsigned long *bp = t->io_bitmap_ptr;
18320
18321 if (bp) {
18322 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18323 + struct tss_struct *tss = init_tss + get_cpu();
18324
18325 t->io_bitmap_ptr = NULL;
18326 clear_thread_flag(TIF_IO_BITMAP);
18327 @@ -147,7 +148,7 @@ void show_regs_common(void)
18328
18329 printk(KERN_CONT "\n");
18330 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18331 - current->pid, current->comm, print_tainted(),
18332 + task_pid_nr(current), current->comm, print_tainted(),
18333 init_utsname()->release,
18334 (int)strcspn(init_utsname()->version, " "),
18335 init_utsname()->version);
18336 @@ -161,6 +162,9 @@ void flush_thread(void)
18337 {
18338 struct task_struct *tsk = current;
18339
18340 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18341 + loadsegment(gs, 0);
18342 +#endif
18343 flush_ptrace_hw_breakpoint(tsk);
18344 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18345 drop_fpu(tsk);
18346 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18347 regs.di = (unsigned long) arg;
18348
18349 #ifdef CONFIG_X86_32
18350 - regs.ds = __USER_DS;
18351 - regs.es = __USER_DS;
18352 + regs.ds = __KERNEL_DS;
18353 + regs.es = __KERNEL_DS;
18354 regs.fs = __KERNEL_PERCPU;
18355 - regs.gs = __KERNEL_STACK_CANARY;
18356 + savesegment(gs, regs.gs);
18357 #else
18358 regs.ss = __KERNEL_DS;
18359 #endif
18360 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18361 void exit_idle(void)
18362 {
18363 /* idle loop has pid 0 */
18364 - if (current->pid)
18365 + if (task_pid_nr(current))
18366 return;
18367 __exit_idle();
18368 }
18369 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18370
18371 return ret;
18372 }
18373 -void stop_this_cpu(void *dummy)
18374 +__noreturn void stop_this_cpu(void *dummy)
18375 {
18376 local_irq_disable();
18377 /*
18378 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18379 }
18380 early_param("idle", idle_setup);
18381
18382 -unsigned long arch_align_stack(unsigned long sp)
18383 +#ifdef CONFIG_PAX_RANDKSTACK
18384 +void pax_randomize_kstack(struct pt_regs *regs)
18385 {
18386 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18387 - sp -= get_random_int() % 8192;
18388 - return sp & ~0xf;
18389 -}
18390 + struct thread_struct *thread = &current->thread;
18391 + unsigned long time;
18392
18393 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18394 -{
18395 - unsigned long range_end = mm->brk + 0x02000000;
18396 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18397 -}
18398 + if (!randomize_va_space)
18399 + return;
18400 +
18401 + if (v8086_mode(regs))
18402 + return;
18403
18404 + rdtscl(time);
18405 +
18406 + /* P4 seems to return a 0 LSB, ignore it */
18407 +#ifdef CONFIG_MPENTIUM4
18408 + time &= 0x3EUL;
18409 + time <<= 2;
18410 +#elif defined(CONFIG_X86_64)
18411 + time &= 0xFUL;
18412 + time <<= 4;
18413 +#else
18414 + time &= 0x1FUL;
18415 + time <<= 3;
18416 +#endif
18417 +
18418 + thread->sp0 ^= time;
18419 + load_sp0(init_tss + smp_processor_id(), thread);
18420 +
18421 +#ifdef CONFIG_X86_64
18422 + this_cpu_write(kernel_stack, thread->sp0);
18423 +#endif
18424 +}
18425 +#endif
18426 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18427 index 516fa18..80bd9e6 100644
18428 --- a/arch/x86/kernel/process_32.c
18429 +++ b/arch/x86/kernel/process_32.c
18430 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18431 unsigned long thread_saved_pc(struct task_struct *tsk)
18432 {
18433 return ((unsigned long *)tsk->thread.sp)[3];
18434 +//XXX return tsk->thread.eip;
18435 }
18436
18437 void __show_regs(struct pt_regs *regs, int all)
18438 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18439 unsigned long sp;
18440 unsigned short ss, gs;
18441
18442 - if (user_mode_vm(regs)) {
18443 + if (user_mode(regs)) {
18444 sp = regs->sp;
18445 ss = regs->ss & 0xffff;
18446 - gs = get_user_gs(regs);
18447 } else {
18448 sp = kernel_stack_pointer(regs);
18449 savesegment(ss, ss);
18450 - savesegment(gs, gs);
18451 }
18452 + gs = get_user_gs(regs);
18453
18454 show_regs_common();
18455
18456 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18457 struct task_struct *tsk;
18458 int err;
18459
18460 - childregs = task_pt_regs(p);
18461 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18462 *childregs = *regs;
18463 childregs->ax = 0;
18464 childregs->sp = sp;
18465
18466 p->thread.sp = (unsigned long) childregs;
18467 p->thread.sp0 = (unsigned long) (childregs+1);
18468 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18469
18470 p->thread.ip = (unsigned long) ret_from_fork;
18471
18472 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18473 struct thread_struct *prev = &prev_p->thread,
18474 *next = &next_p->thread;
18475 int cpu = smp_processor_id();
18476 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18477 + struct tss_struct *tss = init_tss + cpu;
18478 fpu_switch_t fpu;
18479
18480 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18481 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18482 */
18483 lazy_save_gs(prev->gs);
18484
18485 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18486 + __set_fs(task_thread_info(next_p)->addr_limit);
18487 +#endif
18488 +
18489 /*
18490 * Load the per-thread Thread-Local Storage descriptor.
18491 */
18492 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18493 */
18494 arch_end_context_switch(next_p);
18495
18496 + this_cpu_write(current_task, next_p);
18497 + this_cpu_write(current_tinfo, &next_p->tinfo);
18498 +
18499 /*
18500 * Restore %gs if needed (which is common)
18501 */
18502 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18503
18504 switch_fpu_finish(next_p, fpu);
18505
18506 - this_cpu_write(current_task, next_p);
18507 -
18508 return prev_p;
18509 }
18510
18511 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18512 } while (count++ < 16);
18513 return 0;
18514 }
18515 -
18516 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18517 index 61cdf7f..797f06a 100644
18518 --- a/arch/x86/kernel/process_64.c
18519 +++ b/arch/x86/kernel/process_64.c
18520 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18521 struct pt_regs *childregs;
18522 struct task_struct *me = current;
18523
18524 - childregs = ((struct pt_regs *)
18525 - (THREAD_SIZE + task_stack_page(p))) - 1;
18526 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18527 *childregs = *regs;
18528
18529 childregs->ax = 0;
18530 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18531 p->thread.sp = (unsigned long) childregs;
18532 p->thread.sp0 = (unsigned long) (childregs+1);
18533 p->thread.usersp = me->thread.usersp;
18534 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18535
18536 set_tsk_thread_flag(p, TIF_FORK);
18537
18538 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18539 struct thread_struct *prev = &prev_p->thread;
18540 struct thread_struct *next = &next_p->thread;
18541 int cpu = smp_processor_id();
18542 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18543 + struct tss_struct *tss = init_tss + cpu;
18544 unsigned fsindex, gsindex;
18545 fpu_switch_t fpu;
18546
18547 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18548 prev->usersp = this_cpu_read(old_rsp);
18549 this_cpu_write(old_rsp, next->usersp);
18550 this_cpu_write(current_task, next_p);
18551 + this_cpu_write(current_tinfo, &next_p->tinfo);
18552
18553 - this_cpu_write(kernel_stack,
18554 - (unsigned long)task_stack_page(next_p) +
18555 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18556 + this_cpu_write(kernel_stack, next->sp0);
18557
18558 /*
18559 * Now maybe reload the debug registers and handle I/O bitmaps
18560 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18561 if (!p || p == current || p->state == TASK_RUNNING)
18562 return 0;
18563 stack = (unsigned long)task_stack_page(p);
18564 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18565 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18566 return 0;
18567 fp = *(u64 *)(p->thread.sp);
18568 do {
18569 - if (fp < (unsigned long)stack ||
18570 - fp >= (unsigned long)stack+THREAD_SIZE)
18571 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18572 return 0;
18573 ip = *(u64 *)(fp+8);
18574 if (!in_sched_functions(ip))
18575 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18576 index c4c6a5c..905f440 100644
18577 --- a/arch/x86/kernel/ptrace.c
18578 +++ b/arch/x86/kernel/ptrace.c
18579 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18580 unsigned long addr, unsigned long data)
18581 {
18582 int ret;
18583 - unsigned long __user *datap = (unsigned long __user *)data;
18584 + unsigned long __user *datap = (__force unsigned long __user *)data;
18585
18586 switch (request) {
18587 /* read the word at location addr in the USER area. */
18588 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18589 if ((int) addr < 0)
18590 return -EIO;
18591 ret = do_get_thread_area(child, addr,
18592 - (struct user_desc __user *)data);
18593 + (__force struct user_desc __user *) data);
18594 break;
18595
18596 case PTRACE_SET_THREAD_AREA:
18597 if ((int) addr < 0)
18598 return -EIO;
18599 ret = do_set_thread_area(child, addr,
18600 - (struct user_desc __user *)data, 0);
18601 + (__force struct user_desc __user *) data, 0);
18602 break;
18603 #endif
18604
18605 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18606 memset(info, 0, sizeof(*info));
18607 info->si_signo = SIGTRAP;
18608 info->si_code = si_code;
18609 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18610 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18611 }
18612
18613 void user_single_step_siginfo(struct task_struct *tsk,
18614 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18615 # define IS_IA32 0
18616 #endif
18617
18618 +#ifdef CONFIG_GRKERNSEC_SETXID
18619 +extern void gr_delayed_cred_worker(void);
18620 +#endif
18621 +
18622 /*
18623 * We must return the syscall number to actually look up in the table.
18624 * This can be -1L to skip running any syscall at all.
18625 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18626 {
18627 long ret = 0;
18628
18629 +#ifdef CONFIG_GRKERNSEC_SETXID
18630 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18631 + gr_delayed_cred_worker();
18632 +#endif
18633 +
18634 /*
18635 * If we stepped into a sysenter/syscall insn, it trapped in
18636 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18637 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18638 {
18639 bool step;
18640
18641 +#ifdef CONFIG_GRKERNSEC_SETXID
18642 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18643 + gr_delayed_cred_worker();
18644 +#endif
18645 +
18646 audit_syscall_exit(regs);
18647
18648 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18649 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18650 index 42eb330..139955c 100644
18651 --- a/arch/x86/kernel/pvclock.c
18652 +++ b/arch/x86/kernel/pvclock.c
18653 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18654 return pv_tsc_khz;
18655 }
18656
18657 -static atomic64_t last_value = ATOMIC64_INIT(0);
18658 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18659
18660 void pvclock_resume(void)
18661 {
18662 - atomic64_set(&last_value, 0);
18663 + atomic64_set_unchecked(&last_value, 0);
18664 }
18665
18666 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18667 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18668 * updating at the same time, and one of them could be slightly behind,
18669 * making the assumption that last_value always go forward fail to hold.
18670 */
18671 - last = atomic64_read(&last_value);
18672 + last = atomic64_read_unchecked(&last_value);
18673 do {
18674 if (ret < last)
18675 return last;
18676 - last = atomic64_cmpxchg(&last_value, last, ret);
18677 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18678 } while (unlikely(last != ret));
18679
18680 return ret;
18681 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18682 index 5de92f1..2732385 100644
18683 --- a/arch/x86/kernel/reboot.c
18684 +++ b/arch/x86/kernel/reboot.c
18685 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18686 EXPORT_SYMBOL(pm_power_off);
18687
18688 static const struct desc_ptr no_idt = {};
18689 -static int reboot_mode;
18690 +static unsigned short reboot_mode;
18691 enum reboot_type reboot_type = BOOT_ACPI;
18692 int reboot_force;
18693
18694 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18695 return 0;
18696 }
18697
18698 -void machine_real_restart(unsigned int type)
18699 +__noreturn void machine_real_restart(unsigned int type)
18700 {
18701 - void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18702 + void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18703 real_mode_header->machine_real_restart_asm;
18704
18705 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18706 + struct desc_struct *gdt;
18707 +#endif
18708 +
18709 local_irq_disable();
18710
18711 /*
18712 @@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18713 * boot)". This seems like a fairly standard thing that gets set by
18714 * REBOOT.COM programs, and the previous reset routine did this
18715 * too. */
18716 - *((unsigned short *)0x472) = reboot_mode;
18717 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18718
18719 /* Jump to the identity-mapped low memory code */
18720 +
18721 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18722 + gdt = get_cpu_gdt_table(smp_processor_id());
18723 + pax_open_kernel();
18724 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18725 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18726 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18727 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18728 +#endif
18729 +#ifdef CONFIG_PAX_KERNEXEC
18730 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18731 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18732 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18733 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18734 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18735 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18736 +#endif
18737 + pax_close_kernel();
18738 +#endif
18739 +
18740 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18741 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18742 + unreachable();
18743 +#else
18744 restart_lowmem(type);
18745 +#endif
18746 +
18747 }
18748 #ifdef CONFIG_APM_MODULE
18749 EXPORT_SYMBOL(machine_real_restart);
18750 @@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18751 * try to force a triple fault and then cycle between hitting the keyboard
18752 * controller and doing that
18753 */
18754 -static void native_machine_emergency_restart(void)
18755 +__noreturn static void native_machine_emergency_restart(void)
18756 {
18757 int i;
18758 int attempt = 0;
18759 @@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18760 #endif
18761 }
18762
18763 -static void __machine_emergency_restart(int emergency)
18764 +static __noreturn void __machine_emergency_restart(int emergency)
18765 {
18766 reboot_emergency = emergency;
18767 machine_ops.emergency_restart();
18768 }
18769
18770 -static void native_machine_restart(char *__unused)
18771 +static __noreturn void native_machine_restart(char *__unused)
18772 {
18773 printk("machine restart\n");
18774
18775 @@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18776 __machine_emergency_restart(0);
18777 }
18778
18779 -static void native_machine_halt(void)
18780 +static __noreturn void native_machine_halt(void)
18781 {
18782 /* Stop other cpus and apics */
18783 machine_shutdown();
18784 @@ -695,7 +725,7 @@ static void native_machine_halt(void)
18785 stop_this_cpu(NULL);
18786 }
18787
18788 -static void native_machine_power_off(void)
18789 +__noreturn static void native_machine_power_off(void)
18790 {
18791 if (pm_power_off) {
18792 if (!reboot_force)
18793 @@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18794 }
18795 /* A fallback in case there is no PM info available */
18796 tboot_shutdown(TB_SHUTDOWN_HALT);
18797 + unreachable();
18798 }
18799
18800 struct machine_ops machine_ops = {
18801 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18802 index 7a6f3b3..bed145d7 100644
18803 --- a/arch/x86/kernel/relocate_kernel_64.S
18804 +++ b/arch/x86/kernel/relocate_kernel_64.S
18805 @@ -11,6 +11,7 @@
18806 #include <asm/kexec.h>
18807 #include <asm/processor-flags.h>
18808 #include <asm/pgtable_types.h>
18809 +#include <asm/alternative-asm.h>
18810
18811 /*
18812 * Must be relocatable PIC code callable as a C function
18813 @@ -160,13 +161,14 @@ identity_mapped:
18814 xorq %rbp, %rbp
18815 xorq %r8, %r8
18816 xorq %r9, %r9
18817 - xorq %r10, %r9
18818 + xorq %r10, %r10
18819 xorq %r11, %r11
18820 xorq %r12, %r12
18821 xorq %r13, %r13
18822 xorq %r14, %r14
18823 xorq %r15, %r15
18824
18825 + pax_force_retaddr 0, 1
18826 ret
18827
18828 1:
18829 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18830 index 16be6dc..4686132 100644
18831 --- a/arch/x86/kernel/setup.c
18832 +++ b/arch/x86/kernel/setup.c
18833 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18834
18835 switch (data->type) {
18836 case SETUP_E820_EXT:
18837 - parse_e820_ext(data);
18838 + parse_e820_ext((struct setup_data __force_kernel *)data);
18839 break;
18840 case SETUP_DTB:
18841 add_dtb(pa_data);
18842 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18843 * area (640->1Mb) as ram even though it is not.
18844 * take them out.
18845 */
18846 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18847 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18848 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18849 }
18850
18851 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18852
18853 if (!boot_params.hdr.root_flags)
18854 root_mountflags &= ~MS_RDONLY;
18855 - init_mm.start_code = (unsigned long) _text;
18856 - init_mm.end_code = (unsigned long) _etext;
18857 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18858 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18859 init_mm.end_data = (unsigned long) _edata;
18860 init_mm.brk = _brk_end;
18861
18862 - code_resource.start = virt_to_phys(_text);
18863 - code_resource.end = virt_to_phys(_etext)-1;
18864 - data_resource.start = virt_to_phys(_etext);
18865 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18866 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18867 + data_resource.start = virt_to_phys(_sdata);
18868 data_resource.end = virt_to_phys(_edata)-1;
18869 bss_resource.start = virt_to_phys(&__bss_start);
18870 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18871 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18872 index 5a98aa2..2f9288d 100644
18873 --- a/arch/x86/kernel/setup_percpu.c
18874 +++ b/arch/x86/kernel/setup_percpu.c
18875 @@ -21,19 +21,17 @@
18876 #include <asm/cpu.h>
18877 #include <asm/stackprotector.h>
18878
18879 -DEFINE_PER_CPU(int, cpu_number);
18880 +#ifdef CONFIG_SMP
18881 +DEFINE_PER_CPU(unsigned int, cpu_number);
18882 EXPORT_PER_CPU_SYMBOL(cpu_number);
18883 +#endif
18884
18885 -#ifdef CONFIG_X86_64
18886 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18887 -#else
18888 -#define BOOT_PERCPU_OFFSET 0
18889 -#endif
18890
18891 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18892 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18893
18894 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18895 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18896 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18897 };
18898 EXPORT_SYMBOL(__per_cpu_offset);
18899 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18900 {
18901 #ifdef CONFIG_X86_32
18902 struct desc_struct gdt;
18903 + unsigned long base = per_cpu_offset(cpu);
18904
18905 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18906 - 0x2 | DESCTYPE_S, 0x8);
18907 - gdt.s = 1;
18908 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18909 + 0x83 | DESCTYPE_S, 0xC);
18910 write_gdt_entry(get_cpu_gdt_table(cpu),
18911 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18912 #endif
18913 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18914 /* alrighty, percpu areas up and running */
18915 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18916 for_each_possible_cpu(cpu) {
18917 +#ifdef CONFIG_CC_STACKPROTECTOR
18918 +#ifdef CONFIG_X86_32
18919 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18920 +#endif
18921 +#endif
18922 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18923 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18924 per_cpu(cpu_number, cpu) = cpu;
18925 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18926 */
18927 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18928 #endif
18929 +#ifdef CONFIG_CC_STACKPROTECTOR
18930 +#ifdef CONFIG_X86_32
18931 + if (!cpu)
18932 + per_cpu(stack_canary.canary, cpu) = canary;
18933 +#endif
18934 +#endif
18935 /*
18936 * Up to this point, the boot CPU has been using .init.data
18937 * area. Reload any changed state for the boot CPU.
18938 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18939 index 21af737..fb45e22 100644
18940 --- a/arch/x86/kernel/signal.c
18941 +++ b/arch/x86/kernel/signal.c
18942 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18943 * Align the stack pointer according to the i386 ABI,
18944 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18945 */
18946 - sp = ((sp + 4) & -16ul) - 4;
18947 + sp = ((sp - 12) & -16ul) - 4;
18948 #else /* !CONFIG_X86_32 */
18949 sp = round_down(sp, 16) - 8;
18950 #endif
18951 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18952 * Return an always-bogus address instead so we will die with SIGSEGV.
18953 */
18954 if (onsigstack && !likely(on_sig_stack(sp)))
18955 - return (void __user *)-1L;
18956 + return (__force void __user *)-1L;
18957
18958 /* save i387 state */
18959 if (used_math() && save_i387_xstate(*fpstate) < 0)
18960 - return (void __user *)-1L;
18961 + return (__force void __user *)-1L;
18962
18963 return (void __user *)sp;
18964 }
18965 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18966 }
18967
18968 if (current->mm->context.vdso)
18969 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18970 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18971 else
18972 - restorer = &frame->retcode;
18973 + restorer = (void __user *)&frame->retcode;
18974 if (ka->sa.sa_flags & SA_RESTORER)
18975 restorer = ka->sa.sa_restorer;
18976
18977 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18978 * reasons and because gdb uses it as a signature to notice
18979 * signal handler stack frames.
18980 */
18981 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18982 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18983
18984 if (err)
18985 return -EFAULT;
18986 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18987 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18988
18989 /* Set up to return from userspace. */
18990 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18991 + if (current->mm->context.vdso)
18992 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18993 + else
18994 + restorer = (void __user *)&frame->retcode;
18995 if (ka->sa.sa_flags & SA_RESTORER)
18996 restorer = ka->sa.sa_restorer;
18997 put_user_ex(restorer, &frame->pretcode);
18998 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18999 * reasons and because gdb uses it as a signature to notice
19000 * signal handler stack frames.
19001 */
19002 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19003 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19004 } put_user_catch(err);
19005
19006 if (err)
19007 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19008 index 7bd8a08..2659b5b 100644
19009 --- a/arch/x86/kernel/smpboot.c
19010 +++ b/arch/x86/kernel/smpboot.c
19011 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19012 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19013 (THREAD_SIZE + task_stack_page(idle))) - 1);
19014 per_cpu(current_task, cpu) = idle;
19015 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19016
19017 #ifdef CONFIG_X86_32
19018 /* Stack for startup_32 can be just as for start_secondary onwards */
19019 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19020 #else
19021 clear_tsk_thread_flag(idle, TIF_FORK);
19022 initial_gs = per_cpu_offset(cpu);
19023 - per_cpu(kernel_stack, cpu) =
19024 - (unsigned long)task_stack_page(idle) -
19025 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19026 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19027 #endif
19028 +
19029 + pax_open_kernel();
19030 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19031 + pax_close_kernel();
19032 +
19033 initial_code = (unsigned long)start_secondary;
19034 stack_start = idle->thread.sp;
19035
19036 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19037
19038 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19039
19040 +#ifdef CONFIG_PAX_PER_CPU_PGD
19041 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19042 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19043 + KERNEL_PGD_PTRS);
19044 +#endif
19045 +
19046 err = do_boot_cpu(apicid, cpu, tidle);
19047 if (err) {
19048 pr_debug("do_boot_cpu failed %d\n", err);
19049 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19050 index c346d11..d43b163 100644
19051 --- a/arch/x86/kernel/step.c
19052 +++ b/arch/x86/kernel/step.c
19053 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19054 struct desc_struct *desc;
19055 unsigned long base;
19056
19057 - seg &= ~7UL;
19058 + seg >>= 3;
19059
19060 mutex_lock(&child->mm->context.lock);
19061 - if (unlikely((seg >> 3) >= child->mm->context.size))
19062 + if (unlikely(seg >= child->mm->context.size))
19063 addr = -1L; /* bogus selector, access would fault */
19064 else {
19065 desc = child->mm->context.ldt + seg;
19066 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19067 addr += base;
19068 }
19069 mutex_unlock(&child->mm->context.lock);
19070 - }
19071 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19072 + addr = ktla_ktva(addr);
19073
19074 return addr;
19075 }
19076 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19077 unsigned char opcode[15];
19078 unsigned long addr = convert_ip_to_linear(child, regs);
19079
19080 + if (addr == -EINVAL)
19081 + return 0;
19082 +
19083 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19084 for (i = 0; i < copied; i++) {
19085 switch (opcode[i]) {
19086 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19087 index 0b0cb5f..db6b9ed 100644
19088 --- a/arch/x86/kernel/sys_i386_32.c
19089 +++ b/arch/x86/kernel/sys_i386_32.c
19090 @@ -24,17 +24,224 @@
19091
19092 #include <asm/syscalls.h>
19093
19094 -/*
19095 - * Do a system call from kernel instead of calling sys_execve so we
19096 - * end up with proper pt_regs.
19097 - */
19098 -int kernel_execve(const char *filename,
19099 - const char *const argv[],
19100 - const char *const envp[])
19101 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19102 {
19103 - long __res;
19104 - asm volatile ("int $0x80"
19105 - : "=a" (__res)
19106 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19107 - return __res;
19108 + unsigned long pax_task_size = TASK_SIZE;
19109 +
19110 +#ifdef CONFIG_PAX_SEGMEXEC
19111 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19112 + pax_task_size = SEGMEXEC_TASK_SIZE;
19113 +#endif
19114 +
19115 + if (len > pax_task_size || addr > pax_task_size - len)
19116 + return -EINVAL;
19117 +
19118 + return 0;
19119 +}
19120 +
19121 +unsigned long
19122 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19123 + unsigned long len, unsigned long pgoff, unsigned long flags)
19124 +{
19125 + struct mm_struct *mm = current->mm;
19126 + struct vm_area_struct *vma;
19127 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19128 +
19129 +#ifdef CONFIG_PAX_SEGMEXEC
19130 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19131 + pax_task_size = SEGMEXEC_TASK_SIZE;
19132 +#endif
19133 +
19134 + pax_task_size -= PAGE_SIZE;
19135 +
19136 + if (len > pax_task_size)
19137 + return -ENOMEM;
19138 +
19139 + if (flags & MAP_FIXED)
19140 + return addr;
19141 +
19142 +#ifdef CONFIG_PAX_RANDMMAP
19143 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19144 +#endif
19145 +
19146 + if (addr) {
19147 + addr = PAGE_ALIGN(addr);
19148 + if (pax_task_size - len >= addr) {
19149 + vma = find_vma(mm, addr);
19150 + if (check_heap_stack_gap(vma, addr, len))
19151 + return addr;
19152 + }
19153 + }
19154 + if (len > mm->cached_hole_size) {
19155 + start_addr = addr = mm->free_area_cache;
19156 + } else {
19157 + start_addr = addr = mm->mmap_base;
19158 + mm->cached_hole_size = 0;
19159 + }
19160 +
19161 +#ifdef CONFIG_PAX_PAGEEXEC
19162 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19163 + start_addr = 0x00110000UL;
19164 +
19165 +#ifdef CONFIG_PAX_RANDMMAP
19166 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19167 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19168 +#endif
19169 +
19170 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19171 + start_addr = addr = mm->mmap_base;
19172 + else
19173 + addr = start_addr;
19174 + }
19175 +#endif
19176 +
19177 +full_search:
19178 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19179 + /* At this point: (!vma || addr < vma->vm_end). */
19180 + if (pax_task_size - len < addr) {
19181 + /*
19182 + * Start a new search - just in case we missed
19183 + * some holes.
19184 + */
19185 + if (start_addr != mm->mmap_base) {
19186 + start_addr = addr = mm->mmap_base;
19187 + mm->cached_hole_size = 0;
19188 + goto full_search;
19189 + }
19190 + return -ENOMEM;
19191 + }
19192 + if (check_heap_stack_gap(vma, addr, len))
19193 + break;
19194 + if (addr + mm->cached_hole_size < vma->vm_start)
19195 + mm->cached_hole_size = vma->vm_start - addr;
19196 + addr = vma->vm_end;
19197 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19198 + start_addr = addr = mm->mmap_base;
19199 + mm->cached_hole_size = 0;
19200 + goto full_search;
19201 + }
19202 + }
19203 +
19204 + /*
19205 + * Remember the place where we stopped the search:
19206 + */
19207 + mm->free_area_cache = addr + len;
19208 + return addr;
19209 +}
19210 +
19211 +unsigned long
19212 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19213 + const unsigned long len, const unsigned long pgoff,
19214 + const unsigned long flags)
19215 +{
19216 + struct vm_area_struct *vma;
19217 + struct mm_struct *mm = current->mm;
19218 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19219 +
19220 +#ifdef CONFIG_PAX_SEGMEXEC
19221 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19222 + pax_task_size = SEGMEXEC_TASK_SIZE;
19223 +#endif
19224 +
19225 + pax_task_size -= PAGE_SIZE;
19226 +
19227 + /* requested length too big for entire address space */
19228 + if (len > pax_task_size)
19229 + return -ENOMEM;
19230 +
19231 + if (flags & MAP_FIXED)
19232 + return addr;
19233 +
19234 +#ifdef CONFIG_PAX_PAGEEXEC
19235 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19236 + goto bottomup;
19237 +#endif
19238 +
19239 +#ifdef CONFIG_PAX_RANDMMAP
19240 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19241 +#endif
19242 +
19243 + /* requesting a specific address */
19244 + if (addr) {
19245 + addr = PAGE_ALIGN(addr);
19246 + if (pax_task_size - len >= addr) {
19247 + vma = find_vma(mm, addr);
19248 + if (check_heap_stack_gap(vma, addr, len))
19249 + return addr;
19250 + }
19251 + }
19252 +
19253 + /* check if free_area_cache is useful for us */
19254 + if (len <= mm->cached_hole_size) {
19255 + mm->cached_hole_size = 0;
19256 + mm->free_area_cache = mm->mmap_base;
19257 + }
19258 +
19259 + /* either no address requested or can't fit in requested address hole */
19260 + addr = mm->free_area_cache;
19261 +
19262 + /* make sure it can fit in the remaining address space */
19263 + if (addr > len) {
19264 + vma = find_vma(mm, addr-len);
19265 + if (check_heap_stack_gap(vma, addr - len, len))
19266 + /* remember the address as a hint for next time */
19267 + return (mm->free_area_cache = addr-len);
19268 + }
19269 +
19270 + if (mm->mmap_base < len)
19271 + goto bottomup;
19272 +
19273 + addr = mm->mmap_base-len;
19274 +
19275 + do {
19276 + /*
19277 + * Lookup failure means no vma is above this address,
19278 + * else if new region fits below vma->vm_start,
19279 + * return with success:
19280 + */
19281 + vma = find_vma(mm, addr);
19282 + if (check_heap_stack_gap(vma, addr, len))
19283 + /* remember the address as a hint for next time */
19284 + return (mm->free_area_cache = addr);
19285 +
19286 + /* remember the largest hole we saw so far */
19287 + if (addr + mm->cached_hole_size < vma->vm_start)
19288 + mm->cached_hole_size = vma->vm_start - addr;
19289 +
19290 + /* try just below the current vma->vm_start */
19291 + addr = skip_heap_stack_gap(vma, len);
19292 + } while (!IS_ERR_VALUE(addr));
19293 +
19294 +bottomup:
19295 + /*
19296 + * A failed mmap() very likely causes application failure,
19297 + * so fall back to the bottom-up function here. This scenario
19298 + * can happen with large stack limits and large mmap()
19299 + * allocations.
19300 + */
19301 +
19302 +#ifdef CONFIG_PAX_SEGMEXEC
19303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19304 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19305 + else
19306 +#endif
19307 +
19308 + mm->mmap_base = TASK_UNMAPPED_BASE;
19309 +
19310 +#ifdef CONFIG_PAX_RANDMMAP
19311 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19312 + mm->mmap_base += mm->delta_mmap;
19313 +#endif
19314 +
19315 + mm->free_area_cache = mm->mmap_base;
19316 + mm->cached_hole_size = ~0UL;
19317 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19318 + /*
19319 + * Restore the topdown base:
19320 + */
19321 + mm->mmap_base = base;
19322 + mm->free_area_cache = base;
19323 + mm->cached_hole_size = ~0UL;
19324 +
19325 + return addr;
19326 }
19327 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19328 index b4d3c39..82bb73b 100644
19329 --- a/arch/x86/kernel/sys_x86_64.c
19330 +++ b/arch/x86/kernel/sys_x86_64.c
19331 @@ -95,8 +95,8 @@ out:
19332 return error;
19333 }
19334
19335 -static void find_start_end(unsigned long flags, unsigned long *begin,
19336 - unsigned long *end)
19337 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19338 + unsigned long *begin, unsigned long *end)
19339 {
19340 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19341 unsigned long new_begin;
19342 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19343 *begin = new_begin;
19344 }
19345 } else {
19346 - *begin = TASK_UNMAPPED_BASE;
19347 + *begin = mm->mmap_base;
19348 *end = TASK_SIZE;
19349 }
19350 }
19351 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19352 if (flags & MAP_FIXED)
19353 return addr;
19354
19355 - find_start_end(flags, &begin, &end);
19356 + find_start_end(mm, flags, &begin, &end);
19357
19358 if (len > end)
19359 return -ENOMEM;
19360
19361 +#ifdef CONFIG_PAX_RANDMMAP
19362 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19363 +#endif
19364 +
19365 if (addr) {
19366 addr = PAGE_ALIGN(addr);
19367 vma = find_vma(mm, addr);
19368 - if (end - len >= addr &&
19369 - (!vma || addr + len <= vma->vm_start))
19370 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19371 return addr;
19372 }
19373 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19374 @@ -172,7 +175,7 @@ full_search:
19375 }
19376 return -ENOMEM;
19377 }
19378 - if (!vma || addr + len <= vma->vm_start) {
19379 + if (check_heap_stack_gap(vma, addr, len)) {
19380 /*
19381 * Remember the place where we stopped the search:
19382 */
19383 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19384 {
19385 struct vm_area_struct *vma;
19386 struct mm_struct *mm = current->mm;
19387 - unsigned long addr = addr0, start_addr;
19388 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19389
19390 /* requested length too big for entire address space */
19391 if (len > TASK_SIZE)
19392 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19393 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19394 goto bottomup;
19395
19396 +#ifdef CONFIG_PAX_RANDMMAP
19397 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19398 +#endif
19399 +
19400 /* requesting a specific address */
19401 if (addr) {
19402 addr = PAGE_ALIGN(addr);
19403 - vma = find_vma(mm, addr);
19404 - if (TASK_SIZE - len >= addr &&
19405 - (!vma || addr + len <= vma->vm_start))
19406 - return addr;
19407 + if (TASK_SIZE - len >= addr) {
19408 + vma = find_vma(mm, addr);
19409 + if (check_heap_stack_gap(vma, addr, len))
19410 + return addr;
19411 + }
19412 }
19413
19414 /* check if free_area_cache is useful for us */
19415 @@ -240,7 +248,7 @@ try_again:
19416 * return with success:
19417 */
19418 vma = find_vma(mm, addr);
19419 - if (!vma || addr+len <= vma->vm_start)
19420 + if (check_heap_stack_gap(vma, addr, len))
19421 /* remember the address as a hint for next time */
19422 return mm->free_area_cache = addr;
19423
19424 @@ -249,8 +257,8 @@ try_again:
19425 mm->cached_hole_size = vma->vm_start - addr;
19426
19427 /* try just below the current vma->vm_start */
19428 - addr = vma->vm_start-len;
19429 - } while (len < vma->vm_start);
19430 + addr = skip_heap_stack_gap(vma, len);
19431 + } while (!IS_ERR_VALUE(addr));
19432
19433 fail:
19434 /*
19435 @@ -270,13 +278,21 @@ bottomup:
19436 * can happen with large stack limits and large mmap()
19437 * allocations.
19438 */
19439 + mm->mmap_base = TASK_UNMAPPED_BASE;
19440 +
19441 +#ifdef CONFIG_PAX_RANDMMAP
19442 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19443 + mm->mmap_base += mm->delta_mmap;
19444 +#endif
19445 +
19446 + mm->free_area_cache = mm->mmap_base;
19447 mm->cached_hole_size = ~0UL;
19448 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19449 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19450 /*
19451 * Restore the topdown base:
19452 */
19453 - mm->free_area_cache = mm->mmap_base;
19454 + mm->mmap_base = base;
19455 + mm->free_area_cache = base;
19456 mm->cached_hole_size = ~0UL;
19457
19458 return addr;
19459 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19460 index f84fe00..93fe08f 100644
19461 --- a/arch/x86/kernel/tboot.c
19462 +++ b/arch/x86/kernel/tboot.c
19463 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19464
19465 void tboot_shutdown(u32 shutdown_type)
19466 {
19467 - void (*shutdown)(void);
19468 + void (* __noreturn shutdown)(void);
19469
19470 if (!tboot_enabled())
19471 return;
19472 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19473
19474 switch_to_tboot_pt();
19475
19476 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19477 + shutdown = (void *)tboot->shutdown_entry;
19478 shutdown();
19479
19480 /* should not reach here */
19481 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19482 return 0;
19483 }
19484
19485 -static atomic_t ap_wfs_count;
19486 +static atomic_unchecked_t ap_wfs_count;
19487
19488 static int tboot_wait_for_aps(int num_aps)
19489 {
19490 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19491 {
19492 switch (action) {
19493 case CPU_DYING:
19494 - atomic_inc(&ap_wfs_count);
19495 + atomic_inc_unchecked(&ap_wfs_count);
19496 if (num_online_cpus() == 1)
19497 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19498 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19499 return NOTIFY_BAD;
19500 break;
19501 }
19502 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19503
19504 tboot_create_trampoline();
19505
19506 - atomic_set(&ap_wfs_count, 0);
19507 + atomic_set_unchecked(&ap_wfs_count, 0);
19508 register_hotcpu_notifier(&tboot_cpu_notifier);
19509
19510 acpi_os_set_prepare_sleep(&tboot_sleep);
19511 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19512 index 24d3c91..d06b473 100644
19513 --- a/arch/x86/kernel/time.c
19514 +++ b/arch/x86/kernel/time.c
19515 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19516 {
19517 unsigned long pc = instruction_pointer(regs);
19518
19519 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19520 + if (!user_mode(regs) && in_lock_functions(pc)) {
19521 #ifdef CONFIG_FRAME_POINTER
19522 - return *(unsigned long *)(regs->bp + sizeof(long));
19523 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19524 #else
19525 unsigned long *sp =
19526 (unsigned long *)kernel_stack_pointer(regs);
19527 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19528 * or above a saved flags. Eflags has bits 22-31 zero,
19529 * kernel addresses don't.
19530 */
19531 +
19532 +#ifdef CONFIG_PAX_KERNEXEC
19533 + return ktla_ktva(sp[0]);
19534 +#else
19535 if (sp[0] >> 22)
19536 return sp[0];
19537 if (sp[1] >> 22)
19538 return sp[1];
19539 #endif
19540 +
19541 +#endif
19542 }
19543 return pc;
19544 }
19545 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19546 index 9d9d2f9..ed344e4 100644
19547 --- a/arch/x86/kernel/tls.c
19548 +++ b/arch/x86/kernel/tls.c
19549 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19550 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19551 return -EINVAL;
19552
19553 +#ifdef CONFIG_PAX_SEGMEXEC
19554 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19555 + return -EINVAL;
19556 +#endif
19557 +
19558 set_tls_desc(p, idx, &info, 1);
19559
19560 return 0;
19561 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19562 index 05b31d9..501d3ba 100644
19563 --- a/arch/x86/kernel/traps.c
19564 +++ b/arch/x86/kernel/traps.c
19565 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19566
19567 /* Do we ignore FPU interrupts ? */
19568 char ignore_fpu_irq;
19569 -
19570 -/*
19571 - * The IDT has to be page-aligned to simplify the Pentium
19572 - * F0 0F bug workaround.
19573 - */
19574 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19575 #endif
19576
19577 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19578 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19579 }
19580
19581 static void __kprobes
19582 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19583 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19584 long error_code, siginfo_t *info)
19585 {
19586 struct task_struct *tsk = current;
19587
19588 #ifdef CONFIG_X86_32
19589 - if (regs->flags & X86_VM_MASK) {
19590 + if (v8086_mode(regs)) {
19591 /*
19592 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19593 * On nmi (interrupt 2), do_trap should not be called.
19594 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19595 }
19596 #endif
19597
19598 - if (!user_mode(regs))
19599 + if (!user_mode_novm(regs))
19600 goto kernel_trap;
19601
19602 #ifdef CONFIG_X86_32
19603 @@ -145,7 +139,7 @@ trap_signal:
19604 printk_ratelimit()) {
19605 printk(KERN_INFO
19606 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19607 - tsk->comm, tsk->pid, str,
19608 + tsk->comm, task_pid_nr(tsk), str,
19609 regs->ip, regs->sp, error_code);
19610 print_vma_addr(" in ", regs->ip);
19611 printk("\n");
19612 @@ -162,8 +156,20 @@ kernel_trap:
19613 if (!fixup_exception(regs)) {
19614 tsk->thread.error_code = error_code;
19615 tsk->thread.trap_nr = trapnr;
19616 +
19617 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19618 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19619 + str = "PAX: suspicious stack segment fault";
19620 +#endif
19621 +
19622 die(str, regs, error_code);
19623 }
19624 +
19625 +#ifdef CONFIG_PAX_REFCOUNT
19626 + if (trapnr == 4)
19627 + pax_report_refcount_overflow(regs);
19628 +#endif
19629 +
19630 return;
19631
19632 #ifdef CONFIG_X86_32
19633 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19634 conditional_sti(regs);
19635
19636 #ifdef CONFIG_X86_32
19637 - if (regs->flags & X86_VM_MASK)
19638 + if (v8086_mode(regs))
19639 goto gp_in_vm86;
19640 #endif
19641
19642 tsk = current;
19643 - if (!user_mode(regs))
19644 + if (!user_mode_novm(regs))
19645 goto gp_in_kernel;
19646
19647 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19648 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19649 + struct mm_struct *mm = tsk->mm;
19650 + unsigned long limit;
19651 +
19652 + down_write(&mm->mmap_sem);
19653 + limit = mm->context.user_cs_limit;
19654 + if (limit < TASK_SIZE) {
19655 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19656 + up_write(&mm->mmap_sem);
19657 + return;
19658 + }
19659 + up_write(&mm->mmap_sem);
19660 + }
19661 +#endif
19662 +
19663 tsk->thread.error_code = error_code;
19664 tsk->thread.trap_nr = X86_TRAP_GP;
19665
19666 @@ -296,6 +318,13 @@ gp_in_kernel:
19667 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19668 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19669 return;
19670 +
19671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19672 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19673 + die("PAX: suspicious general protection fault", regs, error_code);
19674 + else
19675 +#endif
19676 +
19677 die("general protection fault", regs, error_code);
19678 }
19679
19680 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19681 /* It's safe to allow irq's after DR6 has been saved */
19682 preempt_conditional_sti(regs);
19683
19684 - if (regs->flags & X86_VM_MASK) {
19685 + if (v8086_mode(regs)) {
19686 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19687 X86_TRAP_DB);
19688 preempt_conditional_cli(regs);
19689 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19690 * We already checked v86 mode above, so we can check for kernel mode
19691 * by just checking the CPL of CS.
19692 */
19693 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19694 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19695 tsk->thread.debugreg6 &= ~DR_STEP;
19696 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19697 regs->flags &= ~X86_EFLAGS_TF;
19698 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19699 return;
19700 conditional_sti(regs);
19701
19702 - if (!user_mode_vm(regs))
19703 + if (!user_mode(regs))
19704 {
19705 if (!fixup_exception(regs)) {
19706 task->thread.error_code = error_code;
19707 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19708 index dc4e910..c9dedab 100644
19709 --- a/arch/x86/kernel/uprobes.c
19710 +++ b/arch/x86/kernel/uprobes.c
19711 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19712 int ret = NOTIFY_DONE;
19713
19714 /* We are only interested in userspace traps */
19715 - if (regs && !user_mode_vm(regs))
19716 + if (regs && !user_mode(regs))
19717 return NOTIFY_DONE;
19718
19719 switch (val) {
19720 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19721 index b9242ba..50c5edd 100644
19722 --- a/arch/x86/kernel/verify_cpu.S
19723 +++ b/arch/x86/kernel/verify_cpu.S
19724 @@ -20,6 +20,7 @@
19725 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19726 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19727 * arch/x86/kernel/head_32.S: processor startup
19728 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19729 *
19730 * verify_cpu, returns the status of longmode and SSE in register %eax.
19731 * 0: Success 1: Failure
19732 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19733 index 255f58a..5e91150 100644
19734 --- a/arch/x86/kernel/vm86_32.c
19735 +++ b/arch/x86/kernel/vm86_32.c
19736 @@ -41,6 +41,7 @@
19737 #include <linux/ptrace.h>
19738 #include <linux/audit.h>
19739 #include <linux/stddef.h>
19740 +#include <linux/grsecurity.h>
19741
19742 #include <asm/uaccess.h>
19743 #include <asm/io.h>
19744 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19745 do_exit(SIGSEGV);
19746 }
19747
19748 - tss = &per_cpu(init_tss, get_cpu());
19749 + tss = init_tss + get_cpu();
19750 current->thread.sp0 = current->thread.saved_sp0;
19751 current->thread.sysenter_cs = __KERNEL_CS;
19752 load_sp0(tss, &current->thread);
19753 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19754 struct task_struct *tsk;
19755 int tmp, ret = -EPERM;
19756
19757 +#ifdef CONFIG_GRKERNSEC_VM86
19758 + if (!capable(CAP_SYS_RAWIO)) {
19759 + gr_handle_vm86();
19760 + goto out;
19761 + }
19762 +#endif
19763 +
19764 tsk = current;
19765 if (tsk->thread.saved_sp0)
19766 goto out;
19767 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19768 int tmp, ret;
19769 struct vm86plus_struct __user *v86;
19770
19771 +#ifdef CONFIG_GRKERNSEC_VM86
19772 + if (!capable(CAP_SYS_RAWIO)) {
19773 + gr_handle_vm86();
19774 + ret = -EPERM;
19775 + goto out;
19776 + }
19777 +#endif
19778 +
19779 tsk = current;
19780 switch (cmd) {
19781 case VM86_REQUEST_IRQ:
19782 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19783 tsk->thread.saved_fs = info->regs32->fs;
19784 tsk->thread.saved_gs = get_user_gs(info->regs32);
19785
19786 - tss = &per_cpu(init_tss, get_cpu());
19787 + tss = init_tss + get_cpu();
19788 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19789 if (cpu_has_sep)
19790 tsk->thread.sysenter_cs = 0;
19791 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19792 goto cannot_handle;
19793 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19794 goto cannot_handle;
19795 - intr_ptr = (unsigned long __user *) (i << 2);
19796 + intr_ptr = (__force unsigned long __user *) (i << 2);
19797 if (get_user(segoffs, intr_ptr))
19798 goto cannot_handle;
19799 if ((segoffs >> 16) == BIOSSEG)
19800 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19801 index 22a1530..8fbaaad 100644
19802 --- a/arch/x86/kernel/vmlinux.lds.S
19803 +++ b/arch/x86/kernel/vmlinux.lds.S
19804 @@ -26,6 +26,13 @@
19805 #include <asm/page_types.h>
19806 #include <asm/cache.h>
19807 #include <asm/boot.h>
19808 +#include <asm/segment.h>
19809 +
19810 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19811 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19812 +#else
19813 +#define __KERNEL_TEXT_OFFSET 0
19814 +#endif
19815
19816 #undef i386 /* in case the preprocessor is a 32bit one */
19817
19818 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19819
19820 PHDRS {
19821 text PT_LOAD FLAGS(5); /* R_E */
19822 +#ifdef CONFIG_X86_32
19823 + module PT_LOAD FLAGS(5); /* R_E */
19824 +#endif
19825 +#ifdef CONFIG_XEN
19826 + rodata PT_LOAD FLAGS(5); /* R_E */
19827 +#else
19828 + rodata PT_LOAD FLAGS(4); /* R__ */
19829 +#endif
19830 data PT_LOAD FLAGS(6); /* RW_ */
19831 -#ifdef CONFIG_X86_64
19832 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19833 #ifdef CONFIG_SMP
19834 percpu PT_LOAD FLAGS(6); /* RW_ */
19835 #endif
19836 + text.init PT_LOAD FLAGS(5); /* R_E */
19837 + text.exit PT_LOAD FLAGS(5); /* R_E */
19838 init PT_LOAD FLAGS(7); /* RWE */
19839 -#endif
19840 note PT_NOTE FLAGS(0); /* ___ */
19841 }
19842
19843 SECTIONS
19844 {
19845 #ifdef CONFIG_X86_32
19846 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19847 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19848 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19849 #else
19850 - . = __START_KERNEL;
19851 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19852 + . = __START_KERNEL;
19853 #endif
19854
19855 /* Text and read-only data */
19856 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19857 - _text = .;
19858 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19859 /* bootstrapping code */
19860 +#ifdef CONFIG_X86_32
19861 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19862 +#else
19863 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19864 +#endif
19865 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19866 + _text = .;
19867 HEAD_TEXT
19868 #ifdef CONFIG_X86_32
19869 . = ALIGN(PAGE_SIZE);
19870 @@ -108,13 +128,48 @@ SECTIONS
19871 IRQENTRY_TEXT
19872 *(.fixup)
19873 *(.gnu.warning)
19874 - /* End of text section */
19875 - _etext = .;
19876 } :text = 0x9090
19877
19878 - NOTES :text :note
19879 + . += __KERNEL_TEXT_OFFSET;
19880
19881 - EXCEPTION_TABLE(16) :text = 0x9090
19882 +#ifdef CONFIG_X86_32
19883 + . = ALIGN(PAGE_SIZE);
19884 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19885 +
19886 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19887 + MODULES_EXEC_VADDR = .;
19888 + BYTE(0)
19889 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19890 + . = ALIGN(HPAGE_SIZE) - 1;
19891 + MODULES_EXEC_END = .;
19892 +#endif
19893 +
19894 + } :module
19895 +#endif
19896 +
19897 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19898 + /* End of text section */
19899 + BYTE(0)
19900 + _etext = . - __KERNEL_TEXT_OFFSET;
19901 + }
19902 +
19903 +#ifdef CONFIG_X86_32
19904 + . = ALIGN(PAGE_SIZE);
19905 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19906 + *(.idt)
19907 + . = ALIGN(PAGE_SIZE);
19908 + *(.empty_zero_page)
19909 + *(.initial_pg_fixmap)
19910 + *(.initial_pg_pmd)
19911 + *(.initial_page_table)
19912 + *(.swapper_pg_dir)
19913 + } :rodata
19914 +#endif
19915 +
19916 + . = ALIGN(PAGE_SIZE);
19917 + NOTES :rodata :note
19918 +
19919 + EXCEPTION_TABLE(16) :rodata
19920
19921 #if defined(CONFIG_DEBUG_RODATA)
19922 /* .text should occupy whole number of pages */
19923 @@ -126,16 +181,20 @@ SECTIONS
19924
19925 /* Data */
19926 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19927 +
19928 +#ifdef CONFIG_PAX_KERNEXEC
19929 + . = ALIGN(HPAGE_SIZE);
19930 +#else
19931 + . = ALIGN(PAGE_SIZE);
19932 +#endif
19933 +
19934 /* Start of data section */
19935 _sdata = .;
19936
19937 /* init_task */
19938 INIT_TASK_DATA(THREAD_SIZE)
19939
19940 -#ifdef CONFIG_X86_32
19941 - /* 32 bit has nosave before _edata */
19942 NOSAVE_DATA
19943 -#endif
19944
19945 PAGE_ALIGNED_DATA(PAGE_SIZE)
19946
19947 @@ -176,12 +235,19 @@ SECTIONS
19948 #endif /* CONFIG_X86_64 */
19949
19950 /* Init code and data - will be freed after init */
19951 - . = ALIGN(PAGE_SIZE);
19952 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19953 + BYTE(0)
19954 +
19955 +#ifdef CONFIG_PAX_KERNEXEC
19956 + . = ALIGN(HPAGE_SIZE);
19957 +#else
19958 + . = ALIGN(PAGE_SIZE);
19959 +#endif
19960 +
19961 __init_begin = .; /* paired with __init_end */
19962 - }
19963 + } :init.begin
19964
19965 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19966 +#ifdef CONFIG_SMP
19967 /*
19968 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19969 * output PHDR, so the next output section - .init.text - should
19970 @@ -190,12 +256,27 @@ SECTIONS
19971 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19972 #endif
19973
19974 - INIT_TEXT_SECTION(PAGE_SIZE)
19975 -#ifdef CONFIG_X86_64
19976 - :init
19977 -#endif
19978 + . = ALIGN(PAGE_SIZE);
19979 + init_begin = .;
19980 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19981 + VMLINUX_SYMBOL(_sinittext) = .;
19982 + INIT_TEXT
19983 + VMLINUX_SYMBOL(_einittext) = .;
19984 + . = ALIGN(PAGE_SIZE);
19985 + } :text.init
19986
19987 - INIT_DATA_SECTION(16)
19988 + /*
19989 + * .exit.text is discard at runtime, not link time, to deal with
19990 + * references from .altinstructions and .eh_frame
19991 + */
19992 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19993 + EXIT_TEXT
19994 + . = ALIGN(16);
19995 + } :text.exit
19996 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19997 +
19998 + . = ALIGN(PAGE_SIZE);
19999 + INIT_DATA_SECTION(16) :init
20000
20001 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20002 __x86_cpu_dev_start = .;
20003 @@ -257,19 +338,12 @@ SECTIONS
20004 }
20005
20006 . = ALIGN(8);
20007 - /*
20008 - * .exit.text is discard at runtime, not link time, to deal with
20009 - * references from .altinstructions and .eh_frame
20010 - */
20011 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20012 - EXIT_TEXT
20013 - }
20014
20015 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20016 EXIT_DATA
20017 }
20018
20019 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20020 +#ifndef CONFIG_SMP
20021 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20022 #endif
20023
20024 @@ -288,16 +362,10 @@ SECTIONS
20025 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20026 __smp_locks = .;
20027 *(.smp_locks)
20028 - . = ALIGN(PAGE_SIZE);
20029 __smp_locks_end = .;
20030 + . = ALIGN(PAGE_SIZE);
20031 }
20032
20033 -#ifdef CONFIG_X86_64
20034 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20035 - NOSAVE_DATA
20036 - }
20037 -#endif
20038 -
20039 /* BSS */
20040 . = ALIGN(PAGE_SIZE);
20041 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20042 @@ -313,6 +381,7 @@ SECTIONS
20043 __brk_base = .;
20044 . += 64 * 1024; /* 64k alignment slop space */
20045 *(.brk_reservation) /* areas brk users have reserved */
20046 + . = ALIGN(HPAGE_SIZE);
20047 __brk_limit = .;
20048 }
20049
20050 @@ -339,13 +408,12 @@ SECTIONS
20051 * for the boot processor.
20052 */
20053 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20054 -INIT_PER_CPU(gdt_page);
20055 INIT_PER_CPU(irq_stack_union);
20056
20057 /*
20058 * Build-time check on the image size:
20059 */
20060 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20061 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20062 "kernel image bigger than KERNEL_IMAGE_SIZE");
20063
20064 #ifdef CONFIG_SMP
20065 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20066 index 5db36ca..2938af9 100644
20067 --- a/arch/x86/kernel/vsyscall_64.c
20068 +++ b/arch/x86/kernel/vsyscall_64.c
20069 @@ -54,15 +54,13 @@
20070 DEFINE_VVAR(int, vgetcpu_mode);
20071 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20072
20073 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20074 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20075
20076 static int __init vsyscall_setup(char *str)
20077 {
20078 if (str) {
20079 if (!strcmp("emulate", str))
20080 vsyscall_mode = EMULATE;
20081 - else if (!strcmp("native", str))
20082 - vsyscall_mode = NATIVE;
20083 else if (!strcmp("none", str))
20084 vsyscall_mode = NONE;
20085 else
20086 @@ -309,8 +307,7 @@ done:
20087 return true;
20088
20089 sigsegv:
20090 - force_sig(SIGSEGV, current);
20091 - return true;
20092 + do_group_exit(SIGKILL);
20093 }
20094
20095 /*
20096 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20097 extern char __vvar_page;
20098 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20099
20100 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20101 - vsyscall_mode == NATIVE
20102 - ? PAGE_KERNEL_VSYSCALL
20103 - : PAGE_KERNEL_VVAR);
20104 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20105 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20106 (unsigned long)VSYSCALL_START);
20107
20108 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20109 index 9796c2f..f686fbf 100644
20110 --- a/arch/x86/kernel/x8664_ksyms_64.c
20111 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20112 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20113 EXPORT_SYMBOL(copy_user_generic_string);
20114 EXPORT_SYMBOL(copy_user_generic_unrolled);
20115 EXPORT_SYMBOL(__copy_user_nocache);
20116 -EXPORT_SYMBOL(_copy_from_user);
20117 -EXPORT_SYMBOL(_copy_to_user);
20118
20119 EXPORT_SYMBOL(copy_page);
20120 EXPORT_SYMBOL(clear_page);
20121 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20122 index bd18149..2ea0183 100644
20123 --- a/arch/x86/kernel/xsave.c
20124 +++ b/arch/x86/kernel/xsave.c
20125 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20126 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20127 return -EINVAL;
20128
20129 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20130 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20131 fx_sw_user->extended_size -
20132 FP_XSTATE_MAGIC2_SIZE));
20133 if (err)
20134 @@ -265,7 +265,7 @@ fx_only:
20135 * the other extended state.
20136 */
20137 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20138 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20139 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20140 }
20141
20142 /*
20143 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20144 if (use_xsave())
20145 err = restore_user_xstate(buf);
20146 else
20147 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20148 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20149 buf);
20150 if (unlikely(err)) {
20151 /*
20152 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20153 index 7df1c6d..9ea7c79 100644
20154 --- a/arch/x86/kvm/cpuid.c
20155 +++ b/arch/x86/kvm/cpuid.c
20156 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20157 struct kvm_cpuid2 *cpuid,
20158 struct kvm_cpuid_entry2 __user *entries)
20159 {
20160 - int r;
20161 + int r, i;
20162
20163 r = -E2BIG;
20164 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20165 goto out;
20166 r = -EFAULT;
20167 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20168 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20169 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20170 goto out;
20171 + for (i = 0; i < cpuid->nent; ++i) {
20172 + struct kvm_cpuid_entry2 cpuid_entry;
20173 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20174 + goto out;
20175 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20176 + }
20177 vcpu->arch.cpuid_nent = cpuid->nent;
20178 kvm_apic_set_version(vcpu);
20179 kvm_x86_ops->cpuid_update(vcpu);
20180 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20181 struct kvm_cpuid2 *cpuid,
20182 struct kvm_cpuid_entry2 __user *entries)
20183 {
20184 - int r;
20185 + int r, i;
20186
20187 r = -E2BIG;
20188 if (cpuid->nent < vcpu->arch.cpuid_nent)
20189 goto out;
20190 r = -EFAULT;
20191 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20192 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20193 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20194 goto out;
20195 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20196 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20197 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20198 + goto out;
20199 + }
20200 return 0;
20201
20202 out:
20203 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20204 index f95d242..3b49a90 100644
20205 --- a/arch/x86/kvm/emulate.c
20206 +++ b/arch/x86/kvm/emulate.c
20207 @@ -256,6 +256,7 @@ struct gprefix {
20208
20209 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20210 do { \
20211 + unsigned long _tmp; \
20212 __asm__ __volatile__ ( \
20213 _PRE_EFLAGS("0", "4", "2") \
20214 _op _suffix " %"_x"3,%1; " \
20215 @@ -270,8 +271,6 @@ struct gprefix {
20216 /* Raw emulation: instruction has two explicit operands. */
20217 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20218 do { \
20219 - unsigned long _tmp; \
20220 - \
20221 switch ((ctxt)->dst.bytes) { \
20222 case 2: \
20223 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20224 @@ -287,7 +286,6 @@ struct gprefix {
20225
20226 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20227 do { \
20228 - unsigned long _tmp; \
20229 switch ((ctxt)->dst.bytes) { \
20230 case 1: \
20231 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20232 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20233 index 93c1574..d6097dc 100644
20234 --- a/arch/x86/kvm/lapic.c
20235 +++ b/arch/x86/kvm/lapic.c
20236 @@ -54,7 +54,7 @@
20237 #define APIC_BUS_CYCLE_NS 1
20238
20239 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20240 -#define apic_debug(fmt, arg...)
20241 +#define apic_debug(fmt, arg...) do {} while (0)
20242
20243 #define APIC_LVT_NUM 6
20244 /* 14 is the version for Xeon and Pentium 8.4.8*/
20245 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20246 index 34f9709..8eca2d5 100644
20247 --- a/arch/x86/kvm/paging_tmpl.h
20248 +++ b/arch/x86/kvm/paging_tmpl.h
20249 @@ -197,7 +197,7 @@ retry_walk:
20250 if (unlikely(kvm_is_error_hva(host_addr)))
20251 goto error;
20252
20253 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20254 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20255 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20256 goto error;
20257
20258 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20259 index f75af40..285b18f 100644
20260 --- a/arch/x86/kvm/svm.c
20261 +++ b/arch/x86/kvm/svm.c
20262 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20263 int cpu = raw_smp_processor_id();
20264
20265 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20266 +
20267 + pax_open_kernel();
20268 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20269 + pax_close_kernel();
20270 +
20271 load_TR_desc();
20272 }
20273
20274 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20275 #endif
20276 #endif
20277
20278 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20279 + __set_fs(current_thread_info()->addr_limit);
20280 +#endif
20281 +
20282 reload_tss(vcpu);
20283
20284 local_irq_disable();
20285 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20286 index 32eb588..19c4fe3 100644
20287 --- a/arch/x86/kvm/vmx.c
20288 +++ b/arch/x86/kvm/vmx.c
20289 @@ -1313,7 +1313,11 @@ static void reload_tss(void)
20290 struct desc_struct *descs;
20291
20292 descs = (void *)gdt->address;
20293 +
20294 + pax_open_kernel();
20295 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20296 + pax_close_kernel();
20297 +
20298 load_TR_desc();
20299 }
20300
20301 @@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20302 * The sysexit path does not restore ds/es, so we must set them to
20303 * a reasonable value ourselves.
20304 */
20305 - loadsegment(ds, __USER_DS);
20306 - loadsegment(es, __USER_DS);
20307 + loadsegment(ds, __KERNEL_DS);
20308 + loadsegment(es, __KERNEL_DS);
20309 #endif
20310 reload_tss();
20311 #ifdef CONFIG_X86_64
20312 @@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20313 if (!cpu_has_vmx_flexpriority())
20314 flexpriority_enabled = 0;
20315
20316 - if (!cpu_has_vmx_tpr_shadow())
20317 - kvm_x86_ops->update_cr8_intercept = NULL;
20318 + if (!cpu_has_vmx_tpr_shadow()) {
20319 + pax_open_kernel();
20320 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20321 + pax_close_kernel();
20322 + }
20323
20324 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20325 kvm_disable_largepages();
20326 @@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20327 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20328
20329 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20330 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20331 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20332
20333 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20334 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20335 @@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20336 "jmp .Lkvm_vmx_return \n\t"
20337 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20338 ".Lkvm_vmx_return: "
20339 +
20340 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20341 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20342 + ".Lkvm_vmx_return2: "
20343 +#endif
20344 +
20345 /* Save guest registers, load host registers, keep flags */
20346 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20347 "pop %0 \n\t"
20348 @@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20349 #endif
20350 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20351 [wordsize]"i"(sizeof(ulong))
20352 +
20353 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20354 + ,[cs]"i"(__KERNEL_CS)
20355 +#endif
20356 +
20357 : "cc", "memory"
20358 , R"ax", R"bx", R"di", R"si"
20359 #ifdef CONFIG_X86_64
20360 @@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20361 }
20362 }
20363
20364 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20365 +
20366 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20367 + loadsegment(fs, __KERNEL_PERCPU);
20368 +#endif
20369 +
20370 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20371 + __set_fs(current_thread_info()->addr_limit);
20372 +#endif
20373 +
20374 vmx->loaded_vmcs->launched = 1;
20375
20376 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20377 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20378 index be6d549..b0ba2bf 100644
20379 --- a/arch/x86/kvm/x86.c
20380 +++ b/arch/x86/kvm/x86.c
20381 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20382 {
20383 struct kvm *kvm = vcpu->kvm;
20384 int lm = is_long_mode(vcpu);
20385 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20386 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20387 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20388 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20389 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20390 : kvm->arch.xen_hvm_config.blob_size_32;
20391 u32 page_num = data & ~PAGE_MASK;
20392 @@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20393 if (n < msr_list.nmsrs)
20394 goto out;
20395 r = -EFAULT;
20396 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20397 + goto out;
20398 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20399 num_msrs_to_save * sizeof(u32)))
20400 goto out;
20401 @@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20402 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20403 struct kvm_interrupt *irq)
20404 {
20405 - if (irq->irq < 0 || irq->irq >= 256)
20406 + if (irq->irq >= 256)
20407 return -EINVAL;
20408 if (irqchip_in_kernel(vcpu->kvm))
20409 return -ENXIO;
20410 @@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20411 kvm_mmu_set_mmio_spte_mask(mask);
20412 }
20413
20414 -int kvm_arch_init(void *opaque)
20415 +int kvm_arch_init(const void *opaque)
20416 {
20417 int r;
20418 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20419 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20420 index 642d880..44e0f3f 100644
20421 --- a/arch/x86/lguest/boot.c
20422 +++ b/arch/x86/lguest/boot.c
20423 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20424 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20425 * Launcher to reboot us.
20426 */
20427 -static void lguest_restart(char *reason)
20428 +static __noreturn void lguest_restart(char *reason)
20429 {
20430 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20431 + BUG();
20432 }
20433
20434 /*G:050
20435 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20436 index 00933d5..3a64af9 100644
20437 --- a/arch/x86/lib/atomic64_386_32.S
20438 +++ b/arch/x86/lib/atomic64_386_32.S
20439 @@ -48,6 +48,10 @@ BEGIN(read)
20440 movl (v), %eax
20441 movl 4(v), %edx
20442 RET_ENDP
20443 +BEGIN(read_unchecked)
20444 + movl (v), %eax
20445 + movl 4(v), %edx
20446 +RET_ENDP
20447 #undef v
20448
20449 #define v %esi
20450 @@ -55,6 +59,10 @@ BEGIN(set)
20451 movl %ebx, (v)
20452 movl %ecx, 4(v)
20453 RET_ENDP
20454 +BEGIN(set_unchecked)
20455 + movl %ebx, (v)
20456 + movl %ecx, 4(v)
20457 +RET_ENDP
20458 #undef v
20459
20460 #define v %esi
20461 @@ -70,6 +78,20 @@ RET_ENDP
20462 BEGIN(add)
20463 addl %eax, (v)
20464 adcl %edx, 4(v)
20465 +
20466 +#ifdef CONFIG_PAX_REFCOUNT
20467 + jno 0f
20468 + subl %eax, (v)
20469 + sbbl %edx, 4(v)
20470 + int $4
20471 +0:
20472 + _ASM_EXTABLE(0b, 0b)
20473 +#endif
20474 +
20475 +RET_ENDP
20476 +BEGIN(add_unchecked)
20477 + addl %eax, (v)
20478 + adcl %edx, 4(v)
20479 RET_ENDP
20480 #undef v
20481
20482 @@ -77,6 +99,24 @@ RET_ENDP
20483 BEGIN(add_return)
20484 addl (v), %eax
20485 adcl 4(v), %edx
20486 +
20487 +#ifdef CONFIG_PAX_REFCOUNT
20488 + into
20489 +1234:
20490 + _ASM_EXTABLE(1234b, 2f)
20491 +#endif
20492 +
20493 + movl %eax, (v)
20494 + movl %edx, 4(v)
20495 +
20496 +#ifdef CONFIG_PAX_REFCOUNT
20497 +2:
20498 +#endif
20499 +
20500 +RET_ENDP
20501 +BEGIN(add_return_unchecked)
20502 + addl (v), %eax
20503 + adcl 4(v), %edx
20504 movl %eax, (v)
20505 movl %edx, 4(v)
20506 RET_ENDP
20507 @@ -86,6 +126,20 @@ RET_ENDP
20508 BEGIN(sub)
20509 subl %eax, (v)
20510 sbbl %edx, 4(v)
20511 +
20512 +#ifdef CONFIG_PAX_REFCOUNT
20513 + jno 0f
20514 + addl %eax, (v)
20515 + adcl %edx, 4(v)
20516 + int $4
20517 +0:
20518 + _ASM_EXTABLE(0b, 0b)
20519 +#endif
20520 +
20521 +RET_ENDP
20522 +BEGIN(sub_unchecked)
20523 + subl %eax, (v)
20524 + sbbl %edx, 4(v)
20525 RET_ENDP
20526 #undef v
20527
20528 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20529 sbbl $0, %edx
20530 addl (v), %eax
20531 adcl 4(v), %edx
20532 +
20533 +#ifdef CONFIG_PAX_REFCOUNT
20534 + into
20535 +1234:
20536 + _ASM_EXTABLE(1234b, 2f)
20537 +#endif
20538 +
20539 + movl %eax, (v)
20540 + movl %edx, 4(v)
20541 +
20542 +#ifdef CONFIG_PAX_REFCOUNT
20543 +2:
20544 +#endif
20545 +
20546 +RET_ENDP
20547 +BEGIN(sub_return_unchecked)
20548 + negl %edx
20549 + negl %eax
20550 + sbbl $0, %edx
20551 + addl (v), %eax
20552 + adcl 4(v), %edx
20553 movl %eax, (v)
20554 movl %edx, 4(v)
20555 RET_ENDP
20556 @@ -105,6 +180,20 @@ RET_ENDP
20557 BEGIN(inc)
20558 addl $1, (v)
20559 adcl $0, 4(v)
20560 +
20561 +#ifdef CONFIG_PAX_REFCOUNT
20562 + jno 0f
20563 + subl $1, (v)
20564 + sbbl $0, 4(v)
20565 + int $4
20566 +0:
20567 + _ASM_EXTABLE(0b, 0b)
20568 +#endif
20569 +
20570 +RET_ENDP
20571 +BEGIN(inc_unchecked)
20572 + addl $1, (v)
20573 + adcl $0, 4(v)
20574 RET_ENDP
20575 #undef v
20576
20577 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20578 movl 4(v), %edx
20579 addl $1, %eax
20580 adcl $0, %edx
20581 +
20582 +#ifdef CONFIG_PAX_REFCOUNT
20583 + into
20584 +1234:
20585 + _ASM_EXTABLE(1234b, 2f)
20586 +#endif
20587 +
20588 + movl %eax, (v)
20589 + movl %edx, 4(v)
20590 +
20591 +#ifdef CONFIG_PAX_REFCOUNT
20592 +2:
20593 +#endif
20594 +
20595 +RET_ENDP
20596 +BEGIN(inc_return_unchecked)
20597 + movl (v), %eax
20598 + movl 4(v), %edx
20599 + addl $1, %eax
20600 + adcl $0, %edx
20601 movl %eax, (v)
20602 movl %edx, 4(v)
20603 RET_ENDP
20604 @@ -123,6 +232,20 @@ RET_ENDP
20605 BEGIN(dec)
20606 subl $1, (v)
20607 sbbl $0, 4(v)
20608 +
20609 +#ifdef CONFIG_PAX_REFCOUNT
20610 + jno 0f
20611 + addl $1, (v)
20612 + adcl $0, 4(v)
20613 + int $4
20614 +0:
20615 + _ASM_EXTABLE(0b, 0b)
20616 +#endif
20617 +
20618 +RET_ENDP
20619 +BEGIN(dec_unchecked)
20620 + subl $1, (v)
20621 + sbbl $0, 4(v)
20622 RET_ENDP
20623 #undef v
20624
20625 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20626 movl 4(v), %edx
20627 subl $1, %eax
20628 sbbl $0, %edx
20629 +
20630 +#ifdef CONFIG_PAX_REFCOUNT
20631 + into
20632 +1234:
20633 + _ASM_EXTABLE(1234b, 2f)
20634 +#endif
20635 +
20636 + movl %eax, (v)
20637 + movl %edx, 4(v)
20638 +
20639 +#ifdef CONFIG_PAX_REFCOUNT
20640 +2:
20641 +#endif
20642 +
20643 +RET_ENDP
20644 +BEGIN(dec_return_unchecked)
20645 + movl (v), %eax
20646 + movl 4(v), %edx
20647 + subl $1, %eax
20648 + sbbl $0, %edx
20649 movl %eax, (v)
20650 movl %edx, 4(v)
20651 RET_ENDP
20652 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20653 adcl %edx, %edi
20654 addl (v), %eax
20655 adcl 4(v), %edx
20656 +
20657 +#ifdef CONFIG_PAX_REFCOUNT
20658 + into
20659 +1234:
20660 + _ASM_EXTABLE(1234b, 2f)
20661 +#endif
20662 +
20663 cmpl %eax, %ecx
20664 je 3f
20665 1:
20666 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20667 1:
20668 addl $1, %eax
20669 adcl $0, %edx
20670 +
20671 +#ifdef CONFIG_PAX_REFCOUNT
20672 + into
20673 +1234:
20674 + _ASM_EXTABLE(1234b, 2f)
20675 +#endif
20676 +
20677 movl %eax, (v)
20678 movl %edx, 4(v)
20679 movl $1, %eax
20680 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20681 movl 4(v), %edx
20682 subl $1, %eax
20683 sbbl $0, %edx
20684 +
20685 +#ifdef CONFIG_PAX_REFCOUNT
20686 + into
20687 +1234:
20688 + _ASM_EXTABLE(1234b, 1f)
20689 +#endif
20690 +
20691 js 1f
20692 movl %eax, (v)
20693 movl %edx, 4(v)
20694 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20695 index f5cc9eb..51fa319 100644
20696 --- a/arch/x86/lib/atomic64_cx8_32.S
20697 +++ b/arch/x86/lib/atomic64_cx8_32.S
20698 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20699 CFI_STARTPROC
20700
20701 read64 %ecx
20702 + pax_force_retaddr
20703 ret
20704 CFI_ENDPROC
20705 ENDPROC(atomic64_read_cx8)
20706
20707 +ENTRY(atomic64_read_unchecked_cx8)
20708 + CFI_STARTPROC
20709 +
20710 + read64 %ecx
20711 + pax_force_retaddr
20712 + ret
20713 + CFI_ENDPROC
20714 +ENDPROC(atomic64_read_unchecked_cx8)
20715 +
20716 ENTRY(atomic64_set_cx8)
20717 CFI_STARTPROC
20718
20719 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20720 cmpxchg8b (%esi)
20721 jne 1b
20722
20723 + pax_force_retaddr
20724 ret
20725 CFI_ENDPROC
20726 ENDPROC(atomic64_set_cx8)
20727
20728 +ENTRY(atomic64_set_unchecked_cx8)
20729 + CFI_STARTPROC
20730 +
20731 +1:
20732 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20733 + * are atomic on 586 and newer */
20734 + cmpxchg8b (%esi)
20735 + jne 1b
20736 +
20737 + pax_force_retaddr
20738 + ret
20739 + CFI_ENDPROC
20740 +ENDPROC(atomic64_set_unchecked_cx8)
20741 +
20742 ENTRY(atomic64_xchg_cx8)
20743 CFI_STARTPROC
20744
20745 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20746 cmpxchg8b (%esi)
20747 jne 1b
20748
20749 + pax_force_retaddr
20750 ret
20751 CFI_ENDPROC
20752 ENDPROC(atomic64_xchg_cx8)
20753
20754 -.macro addsub_return func ins insc
20755 -ENTRY(atomic64_\func\()_return_cx8)
20756 +.macro addsub_return func ins insc unchecked=""
20757 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20758 CFI_STARTPROC
20759 SAVE ebp
20760 SAVE ebx
20761 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20762 movl %edx, %ecx
20763 \ins\()l %esi, %ebx
20764 \insc\()l %edi, %ecx
20765 +
20766 +.ifb \unchecked
20767 +#ifdef CONFIG_PAX_REFCOUNT
20768 + into
20769 +2:
20770 + _ASM_EXTABLE(2b, 3f)
20771 +#endif
20772 +.endif
20773 +
20774 LOCK_PREFIX
20775 cmpxchg8b (%ebp)
20776 jne 1b
20777 -
20778 -10:
20779 movl %ebx, %eax
20780 movl %ecx, %edx
20781 +
20782 +.ifb \unchecked
20783 +#ifdef CONFIG_PAX_REFCOUNT
20784 +3:
20785 +#endif
20786 +.endif
20787 +
20788 RESTORE edi
20789 RESTORE esi
20790 RESTORE ebx
20791 RESTORE ebp
20792 + pax_force_retaddr
20793 ret
20794 CFI_ENDPROC
20795 -ENDPROC(atomic64_\func\()_return_cx8)
20796 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20797 .endm
20798
20799 addsub_return add add adc
20800 addsub_return sub sub sbb
20801 +addsub_return add add adc _unchecked
20802 +addsub_return sub sub sbb _unchecked
20803
20804 -.macro incdec_return func ins insc
20805 -ENTRY(atomic64_\func\()_return_cx8)
20806 +.macro incdec_return func ins insc unchecked=""
20807 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20808 CFI_STARTPROC
20809 SAVE ebx
20810
20811 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20812 movl %edx, %ecx
20813 \ins\()l $1, %ebx
20814 \insc\()l $0, %ecx
20815 +
20816 +.ifb \unchecked
20817 +#ifdef CONFIG_PAX_REFCOUNT
20818 + into
20819 +2:
20820 + _ASM_EXTABLE(2b, 3f)
20821 +#endif
20822 +.endif
20823 +
20824 LOCK_PREFIX
20825 cmpxchg8b (%esi)
20826 jne 1b
20827
20828 -10:
20829 movl %ebx, %eax
20830 movl %ecx, %edx
20831 +
20832 +.ifb \unchecked
20833 +#ifdef CONFIG_PAX_REFCOUNT
20834 +3:
20835 +#endif
20836 +.endif
20837 +
20838 RESTORE ebx
20839 + pax_force_retaddr
20840 ret
20841 CFI_ENDPROC
20842 -ENDPROC(atomic64_\func\()_return_cx8)
20843 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20844 .endm
20845
20846 incdec_return inc add adc
20847 incdec_return dec sub sbb
20848 +incdec_return inc add adc _unchecked
20849 +incdec_return dec sub sbb _unchecked
20850
20851 ENTRY(atomic64_dec_if_positive_cx8)
20852 CFI_STARTPROC
20853 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20854 movl %edx, %ecx
20855 subl $1, %ebx
20856 sbb $0, %ecx
20857 +
20858 +#ifdef CONFIG_PAX_REFCOUNT
20859 + into
20860 +1234:
20861 + _ASM_EXTABLE(1234b, 2f)
20862 +#endif
20863 +
20864 js 2f
20865 LOCK_PREFIX
20866 cmpxchg8b (%esi)
20867 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20868 movl %ebx, %eax
20869 movl %ecx, %edx
20870 RESTORE ebx
20871 + pax_force_retaddr
20872 ret
20873 CFI_ENDPROC
20874 ENDPROC(atomic64_dec_if_positive_cx8)
20875 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20876 movl %edx, %ecx
20877 addl %ebp, %ebx
20878 adcl %edi, %ecx
20879 +
20880 +#ifdef CONFIG_PAX_REFCOUNT
20881 + into
20882 +1234:
20883 + _ASM_EXTABLE(1234b, 3f)
20884 +#endif
20885 +
20886 LOCK_PREFIX
20887 cmpxchg8b (%esi)
20888 jne 1b
20889 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20890 CFI_ADJUST_CFA_OFFSET -8
20891 RESTORE ebx
20892 RESTORE ebp
20893 + pax_force_retaddr
20894 ret
20895 4:
20896 cmpl %edx, 4(%esp)
20897 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20898 xorl %ecx, %ecx
20899 addl $1, %ebx
20900 adcl %edx, %ecx
20901 +
20902 +#ifdef CONFIG_PAX_REFCOUNT
20903 + into
20904 +1234:
20905 + _ASM_EXTABLE(1234b, 3f)
20906 +#endif
20907 +
20908 LOCK_PREFIX
20909 cmpxchg8b (%esi)
20910 jne 1b
20911 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20912 movl $1, %eax
20913 3:
20914 RESTORE ebx
20915 + pax_force_retaddr
20916 ret
20917 CFI_ENDPROC
20918 ENDPROC(atomic64_inc_not_zero_cx8)
20919 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20920 index 2af5df3..62b1a5a 100644
20921 --- a/arch/x86/lib/checksum_32.S
20922 +++ b/arch/x86/lib/checksum_32.S
20923 @@ -29,7 +29,8 @@
20924 #include <asm/dwarf2.h>
20925 #include <asm/errno.h>
20926 #include <asm/asm.h>
20927 -
20928 +#include <asm/segment.h>
20929 +
20930 /*
20931 * computes a partial checksum, e.g. for TCP/UDP fragments
20932 */
20933 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20934
20935 #define ARGBASE 16
20936 #define FP 12
20937 -
20938 -ENTRY(csum_partial_copy_generic)
20939 +
20940 +ENTRY(csum_partial_copy_generic_to_user)
20941 CFI_STARTPROC
20942 +
20943 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20944 + pushl_cfi %gs
20945 + popl_cfi %es
20946 + jmp csum_partial_copy_generic
20947 +#endif
20948 +
20949 +ENTRY(csum_partial_copy_generic_from_user)
20950 +
20951 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20952 + pushl_cfi %gs
20953 + popl_cfi %ds
20954 +#endif
20955 +
20956 +ENTRY(csum_partial_copy_generic)
20957 subl $4,%esp
20958 CFI_ADJUST_CFA_OFFSET 4
20959 pushl_cfi %edi
20960 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20961 jmp 4f
20962 SRC(1: movw (%esi), %bx )
20963 addl $2, %esi
20964 -DST( movw %bx, (%edi) )
20965 +DST( movw %bx, %es:(%edi) )
20966 addl $2, %edi
20967 addw %bx, %ax
20968 adcl $0, %eax
20969 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20970 SRC(1: movl (%esi), %ebx )
20971 SRC( movl 4(%esi), %edx )
20972 adcl %ebx, %eax
20973 -DST( movl %ebx, (%edi) )
20974 +DST( movl %ebx, %es:(%edi) )
20975 adcl %edx, %eax
20976 -DST( movl %edx, 4(%edi) )
20977 +DST( movl %edx, %es:4(%edi) )
20978
20979 SRC( movl 8(%esi), %ebx )
20980 SRC( movl 12(%esi), %edx )
20981 adcl %ebx, %eax
20982 -DST( movl %ebx, 8(%edi) )
20983 +DST( movl %ebx, %es:8(%edi) )
20984 adcl %edx, %eax
20985 -DST( movl %edx, 12(%edi) )
20986 +DST( movl %edx, %es:12(%edi) )
20987
20988 SRC( movl 16(%esi), %ebx )
20989 SRC( movl 20(%esi), %edx )
20990 adcl %ebx, %eax
20991 -DST( movl %ebx, 16(%edi) )
20992 +DST( movl %ebx, %es:16(%edi) )
20993 adcl %edx, %eax
20994 -DST( movl %edx, 20(%edi) )
20995 +DST( movl %edx, %es:20(%edi) )
20996
20997 SRC( movl 24(%esi), %ebx )
20998 SRC( movl 28(%esi), %edx )
20999 adcl %ebx, %eax
21000 -DST( movl %ebx, 24(%edi) )
21001 +DST( movl %ebx, %es:24(%edi) )
21002 adcl %edx, %eax
21003 -DST( movl %edx, 28(%edi) )
21004 +DST( movl %edx, %es:28(%edi) )
21005
21006 lea 32(%esi), %esi
21007 lea 32(%edi), %edi
21008 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21009 shrl $2, %edx # This clears CF
21010 SRC(3: movl (%esi), %ebx )
21011 adcl %ebx, %eax
21012 -DST( movl %ebx, (%edi) )
21013 +DST( movl %ebx, %es:(%edi) )
21014 lea 4(%esi), %esi
21015 lea 4(%edi), %edi
21016 dec %edx
21017 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21018 jb 5f
21019 SRC( movw (%esi), %cx )
21020 leal 2(%esi), %esi
21021 -DST( movw %cx, (%edi) )
21022 +DST( movw %cx, %es:(%edi) )
21023 leal 2(%edi), %edi
21024 je 6f
21025 shll $16,%ecx
21026 SRC(5: movb (%esi), %cl )
21027 -DST( movb %cl, (%edi) )
21028 +DST( movb %cl, %es:(%edi) )
21029 6: addl %ecx, %eax
21030 adcl $0, %eax
21031 7:
21032 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21033
21034 6001:
21035 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21036 - movl $-EFAULT, (%ebx)
21037 + movl $-EFAULT, %ss:(%ebx)
21038
21039 # zero the complete destination - computing the rest
21040 # is too much work
21041 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21042
21043 6002:
21044 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21045 - movl $-EFAULT,(%ebx)
21046 + movl $-EFAULT,%ss:(%ebx)
21047 jmp 5000b
21048
21049 .previous
21050
21051 + pushl_cfi %ss
21052 + popl_cfi %ds
21053 + pushl_cfi %ss
21054 + popl_cfi %es
21055 popl_cfi %ebx
21056 CFI_RESTORE ebx
21057 popl_cfi %esi
21058 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21059 popl_cfi %ecx # equivalent to addl $4,%esp
21060 ret
21061 CFI_ENDPROC
21062 -ENDPROC(csum_partial_copy_generic)
21063 +ENDPROC(csum_partial_copy_generic_to_user)
21064
21065 #else
21066
21067 /* Version for PentiumII/PPro */
21068
21069 #define ROUND1(x) \
21070 + nop; nop; nop; \
21071 SRC(movl x(%esi), %ebx ) ; \
21072 addl %ebx, %eax ; \
21073 - DST(movl %ebx, x(%edi) ) ;
21074 + DST(movl %ebx, %es:x(%edi)) ;
21075
21076 #define ROUND(x) \
21077 + nop; nop; nop; \
21078 SRC(movl x(%esi), %ebx ) ; \
21079 adcl %ebx, %eax ; \
21080 - DST(movl %ebx, x(%edi) ) ;
21081 + DST(movl %ebx, %es:x(%edi)) ;
21082
21083 #define ARGBASE 12
21084 -
21085 -ENTRY(csum_partial_copy_generic)
21086 +
21087 +ENTRY(csum_partial_copy_generic_to_user)
21088 CFI_STARTPROC
21089 +
21090 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21091 + pushl_cfi %gs
21092 + popl_cfi %es
21093 + jmp csum_partial_copy_generic
21094 +#endif
21095 +
21096 +ENTRY(csum_partial_copy_generic_from_user)
21097 +
21098 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21099 + pushl_cfi %gs
21100 + popl_cfi %ds
21101 +#endif
21102 +
21103 +ENTRY(csum_partial_copy_generic)
21104 pushl_cfi %ebx
21105 CFI_REL_OFFSET ebx, 0
21106 pushl_cfi %edi
21107 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21108 subl %ebx, %edi
21109 lea -1(%esi),%edx
21110 andl $-32,%edx
21111 - lea 3f(%ebx,%ebx), %ebx
21112 + lea 3f(%ebx,%ebx,2), %ebx
21113 testl %esi, %esi
21114 jmp *%ebx
21115 1: addl $64,%esi
21116 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21117 jb 5f
21118 SRC( movw (%esi), %dx )
21119 leal 2(%esi), %esi
21120 -DST( movw %dx, (%edi) )
21121 +DST( movw %dx, %es:(%edi) )
21122 leal 2(%edi), %edi
21123 je 6f
21124 shll $16,%edx
21125 5:
21126 SRC( movb (%esi), %dl )
21127 -DST( movb %dl, (%edi) )
21128 +DST( movb %dl, %es:(%edi) )
21129 6: addl %edx, %eax
21130 adcl $0, %eax
21131 7:
21132 .section .fixup, "ax"
21133 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21134 - movl $-EFAULT, (%ebx)
21135 + movl $-EFAULT, %ss:(%ebx)
21136 # zero the complete destination (computing the rest is too much work)
21137 movl ARGBASE+8(%esp),%edi # dst
21138 movl ARGBASE+12(%esp),%ecx # len
21139 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21140 rep; stosb
21141 jmp 7b
21142 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21143 - movl $-EFAULT, (%ebx)
21144 + movl $-EFAULT, %ss:(%ebx)
21145 jmp 7b
21146 .previous
21147
21148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21149 + pushl_cfi %ss
21150 + popl_cfi %ds
21151 + pushl_cfi %ss
21152 + popl_cfi %es
21153 +#endif
21154 +
21155 popl_cfi %esi
21156 CFI_RESTORE esi
21157 popl_cfi %edi
21158 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21159 CFI_RESTORE ebx
21160 ret
21161 CFI_ENDPROC
21162 -ENDPROC(csum_partial_copy_generic)
21163 +ENDPROC(csum_partial_copy_generic_to_user)
21164
21165 #undef ROUND
21166 #undef ROUND1
21167 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21168 index f2145cf..cea889d 100644
21169 --- a/arch/x86/lib/clear_page_64.S
21170 +++ b/arch/x86/lib/clear_page_64.S
21171 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21172 movl $4096/8,%ecx
21173 xorl %eax,%eax
21174 rep stosq
21175 + pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(clear_page_c)
21179 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21180 movl $4096,%ecx
21181 xorl %eax,%eax
21182 rep stosb
21183 + pax_force_retaddr
21184 ret
21185 CFI_ENDPROC
21186 ENDPROC(clear_page_c_e)
21187 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21188 leaq 64(%rdi),%rdi
21189 jnz .Lloop
21190 nop
21191 + pax_force_retaddr
21192 ret
21193 CFI_ENDPROC
21194 .Lclear_page_end:
21195 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21196
21197 #include <asm/cpufeature.h>
21198
21199 - .section .altinstr_replacement,"ax"
21200 + .section .altinstr_replacement,"a"
21201 1: .byte 0xeb /* jmp <disp8> */
21202 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21203 2: .byte 0xeb /* jmp <disp8> */
21204 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21205 index 1e572c5..2a162cd 100644
21206 --- a/arch/x86/lib/cmpxchg16b_emu.S
21207 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21208 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21209
21210 popf
21211 mov $1, %al
21212 + pax_force_retaddr
21213 ret
21214
21215 not_same:
21216 popf
21217 xor %al,%al
21218 + pax_force_retaddr
21219 ret
21220
21221 CFI_ENDPROC
21222 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21223 index 6b34d04..dccb07f 100644
21224 --- a/arch/x86/lib/copy_page_64.S
21225 +++ b/arch/x86/lib/copy_page_64.S
21226 @@ -9,6 +9,7 @@ copy_page_c:
21227 CFI_STARTPROC
21228 movl $4096/8,%ecx
21229 rep movsq
21230 + pax_force_retaddr
21231 ret
21232 CFI_ENDPROC
21233 ENDPROC(copy_page_c)
21234 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21235
21236 ENTRY(copy_page)
21237 CFI_STARTPROC
21238 - subq $2*8,%rsp
21239 - CFI_ADJUST_CFA_OFFSET 2*8
21240 + subq $3*8,%rsp
21241 + CFI_ADJUST_CFA_OFFSET 3*8
21242 movq %rbx,(%rsp)
21243 CFI_REL_OFFSET rbx, 0
21244 movq %r12,1*8(%rsp)
21245 CFI_REL_OFFSET r12, 1*8
21246 + movq %r13,2*8(%rsp)
21247 + CFI_REL_OFFSET r13, 2*8
21248
21249 movl $(4096/64)-5,%ecx
21250 .p2align 4
21251 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21252 movq 16 (%rsi), %rdx
21253 movq 24 (%rsi), %r8
21254 movq 32 (%rsi), %r9
21255 - movq 40 (%rsi), %r10
21256 + movq 40 (%rsi), %r13
21257 movq 48 (%rsi), %r11
21258 movq 56 (%rsi), %r12
21259
21260 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21261 movq %rdx, 16 (%rdi)
21262 movq %r8, 24 (%rdi)
21263 movq %r9, 32 (%rdi)
21264 - movq %r10, 40 (%rdi)
21265 + movq %r13, 40 (%rdi)
21266 movq %r11, 48 (%rdi)
21267 movq %r12, 56 (%rdi)
21268
21269 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21270 movq 16 (%rsi), %rdx
21271 movq 24 (%rsi), %r8
21272 movq 32 (%rsi), %r9
21273 - movq 40 (%rsi), %r10
21274 + movq 40 (%rsi), %r13
21275 movq 48 (%rsi), %r11
21276 movq 56 (%rsi), %r12
21277
21278 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21279 movq %rdx, 16 (%rdi)
21280 movq %r8, 24 (%rdi)
21281 movq %r9, 32 (%rdi)
21282 - movq %r10, 40 (%rdi)
21283 + movq %r13, 40 (%rdi)
21284 movq %r11, 48 (%rdi)
21285 movq %r12, 56 (%rdi)
21286
21287 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21288 CFI_RESTORE rbx
21289 movq 1*8(%rsp),%r12
21290 CFI_RESTORE r12
21291 - addq $2*8,%rsp
21292 - CFI_ADJUST_CFA_OFFSET -2*8
21293 + movq 2*8(%rsp),%r13
21294 + CFI_RESTORE r13
21295 + addq $3*8,%rsp
21296 + CFI_ADJUST_CFA_OFFSET -3*8
21297 + pax_force_retaddr
21298 ret
21299 .Lcopy_page_end:
21300 CFI_ENDPROC
21301 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21302
21303 #include <asm/cpufeature.h>
21304
21305 - .section .altinstr_replacement,"ax"
21306 + .section .altinstr_replacement,"a"
21307 1: .byte 0xeb /* jmp <disp8> */
21308 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21309 2:
21310 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21311 index 5b2995f..78e7644 100644
21312 --- a/arch/x86/lib/copy_user_64.S
21313 +++ b/arch/x86/lib/copy_user_64.S
21314 @@ -17,6 +17,7 @@
21315 #include <asm/cpufeature.h>
21316 #include <asm/alternative-asm.h>
21317 #include <asm/asm.h>
21318 +#include <asm/pgtable.h>
21319
21320 /*
21321 * By placing feature2 after feature1 in altinstructions section, we logically
21322 @@ -30,7 +31,7 @@
21323 .byte 0xe9 /* 32bit jump */
21324 .long \orig-1f /* by default jump to orig */
21325 1:
21326 - .section .altinstr_replacement,"ax"
21327 + .section .altinstr_replacement,"a"
21328 2: .byte 0xe9 /* near jump with 32bit immediate */
21329 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21330 3: .byte 0xe9 /* near jump with 32bit immediate */
21331 @@ -69,47 +70,20 @@
21332 #endif
21333 .endm
21334
21335 -/* Standard copy_to_user with segment limit checking */
21336 -ENTRY(_copy_to_user)
21337 - CFI_STARTPROC
21338 - GET_THREAD_INFO(%rax)
21339 - movq %rdi,%rcx
21340 - addq %rdx,%rcx
21341 - jc bad_to_user
21342 - cmpq TI_addr_limit(%rax),%rcx
21343 - ja bad_to_user
21344 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21345 - copy_user_generic_unrolled,copy_user_generic_string, \
21346 - copy_user_enhanced_fast_string
21347 - CFI_ENDPROC
21348 -ENDPROC(_copy_to_user)
21349 -
21350 -/* Standard copy_from_user with segment limit checking */
21351 -ENTRY(_copy_from_user)
21352 - CFI_STARTPROC
21353 - GET_THREAD_INFO(%rax)
21354 - movq %rsi,%rcx
21355 - addq %rdx,%rcx
21356 - jc bad_from_user
21357 - cmpq TI_addr_limit(%rax),%rcx
21358 - ja bad_from_user
21359 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21360 - copy_user_generic_unrolled,copy_user_generic_string, \
21361 - copy_user_enhanced_fast_string
21362 - CFI_ENDPROC
21363 -ENDPROC(_copy_from_user)
21364 -
21365 .section .fixup,"ax"
21366 /* must zero dest */
21367 ENTRY(bad_from_user)
21368 bad_from_user:
21369 CFI_STARTPROC
21370 + testl %edx,%edx
21371 + js bad_to_user
21372 movl %edx,%ecx
21373 xorl %eax,%eax
21374 rep
21375 stosb
21376 bad_to_user:
21377 movl %edx,%eax
21378 + pax_force_retaddr
21379 ret
21380 CFI_ENDPROC
21381 ENDPROC(bad_from_user)
21382 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21383 jz 17f
21384 1: movq (%rsi),%r8
21385 2: movq 1*8(%rsi),%r9
21386 -3: movq 2*8(%rsi),%r10
21387 +3: movq 2*8(%rsi),%rax
21388 4: movq 3*8(%rsi),%r11
21389 5: movq %r8,(%rdi)
21390 6: movq %r9,1*8(%rdi)
21391 -7: movq %r10,2*8(%rdi)
21392 +7: movq %rax,2*8(%rdi)
21393 8: movq %r11,3*8(%rdi)
21394 9: movq 4*8(%rsi),%r8
21395 10: movq 5*8(%rsi),%r9
21396 -11: movq 6*8(%rsi),%r10
21397 +11: movq 6*8(%rsi),%rax
21398 12: movq 7*8(%rsi),%r11
21399 13: movq %r8,4*8(%rdi)
21400 14: movq %r9,5*8(%rdi)
21401 -15: movq %r10,6*8(%rdi)
21402 +15: movq %rax,6*8(%rdi)
21403 16: movq %r11,7*8(%rdi)
21404 leaq 64(%rsi),%rsi
21405 leaq 64(%rdi),%rdi
21406 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21407 decl %ecx
21408 jnz 21b
21409 23: xor %eax,%eax
21410 + pax_force_retaddr
21411 ret
21412
21413 .section .fixup,"ax"
21414 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21415 3: rep
21416 movsb
21417 4: xorl %eax,%eax
21418 + pax_force_retaddr
21419 ret
21420
21421 .section .fixup,"ax"
21422 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21423 1: rep
21424 movsb
21425 2: xorl %eax,%eax
21426 + pax_force_retaddr
21427 ret
21428
21429 .section .fixup,"ax"
21430 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21431 index cacddc7..09d49e4 100644
21432 --- a/arch/x86/lib/copy_user_nocache_64.S
21433 +++ b/arch/x86/lib/copy_user_nocache_64.S
21434 @@ -8,6 +8,7 @@
21435
21436 #include <linux/linkage.h>
21437 #include <asm/dwarf2.h>
21438 +#include <asm/alternative-asm.h>
21439
21440 #define FIX_ALIGNMENT 1
21441
21442 @@ -15,6 +16,7 @@
21443 #include <asm/asm-offsets.h>
21444 #include <asm/thread_info.h>
21445 #include <asm/asm.h>
21446 +#include <asm/pgtable.h>
21447
21448 .macro ALIGN_DESTINATION
21449 #ifdef FIX_ALIGNMENT
21450 @@ -48,6 +50,15 @@
21451 */
21452 ENTRY(__copy_user_nocache)
21453 CFI_STARTPROC
21454 +
21455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21456 + mov $PAX_USER_SHADOW_BASE,%rcx
21457 + cmp %rcx,%rsi
21458 + jae 1f
21459 + add %rcx,%rsi
21460 +1:
21461 +#endif
21462 +
21463 cmpl $8,%edx
21464 jb 20f /* less then 8 bytes, go to byte copy loop */
21465 ALIGN_DESTINATION
21466 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21467 jz 17f
21468 1: movq (%rsi),%r8
21469 2: movq 1*8(%rsi),%r9
21470 -3: movq 2*8(%rsi),%r10
21471 +3: movq 2*8(%rsi),%rax
21472 4: movq 3*8(%rsi),%r11
21473 5: movnti %r8,(%rdi)
21474 6: movnti %r9,1*8(%rdi)
21475 -7: movnti %r10,2*8(%rdi)
21476 +7: movnti %rax,2*8(%rdi)
21477 8: movnti %r11,3*8(%rdi)
21478 9: movq 4*8(%rsi),%r8
21479 10: movq 5*8(%rsi),%r9
21480 -11: movq 6*8(%rsi),%r10
21481 +11: movq 6*8(%rsi),%rax
21482 12: movq 7*8(%rsi),%r11
21483 13: movnti %r8,4*8(%rdi)
21484 14: movnti %r9,5*8(%rdi)
21485 -15: movnti %r10,6*8(%rdi)
21486 +15: movnti %rax,6*8(%rdi)
21487 16: movnti %r11,7*8(%rdi)
21488 leaq 64(%rsi),%rsi
21489 leaq 64(%rdi),%rdi
21490 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21491 jnz 21b
21492 23: xorl %eax,%eax
21493 sfence
21494 + pax_force_retaddr
21495 ret
21496
21497 .section .fixup,"ax"
21498 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21499 index 2419d5f..953ee51 100644
21500 --- a/arch/x86/lib/csum-copy_64.S
21501 +++ b/arch/x86/lib/csum-copy_64.S
21502 @@ -9,6 +9,7 @@
21503 #include <asm/dwarf2.h>
21504 #include <asm/errno.h>
21505 #include <asm/asm.h>
21506 +#include <asm/alternative-asm.h>
21507
21508 /*
21509 * Checksum copy with exception handling.
21510 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21511 CFI_RESTORE rbp
21512 addq $7*8, %rsp
21513 CFI_ADJUST_CFA_OFFSET -7*8
21514 + pax_force_retaddr 0, 1
21515 ret
21516 CFI_RESTORE_STATE
21517
21518 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21519 index 25b7ae8..3b52ccd 100644
21520 --- a/arch/x86/lib/csum-wrappers_64.c
21521 +++ b/arch/x86/lib/csum-wrappers_64.c
21522 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21523 len -= 2;
21524 }
21525 }
21526 - isum = csum_partial_copy_generic((__force const void *)src,
21527 +
21528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21529 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21530 + src += PAX_USER_SHADOW_BASE;
21531 +#endif
21532 +
21533 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21534 dst, len, isum, errp, NULL);
21535 if (unlikely(*errp))
21536 goto out_err;
21537 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21538 }
21539
21540 *errp = 0;
21541 - return csum_partial_copy_generic(src, (void __force *)dst,
21542 +
21543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21544 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21545 + dst += PAX_USER_SHADOW_BASE;
21546 +#endif
21547 +
21548 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21549 len, isum, NULL, errp);
21550 }
21551 EXPORT_SYMBOL(csum_partial_copy_to_user);
21552 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21553 index b33b1fb..219f389 100644
21554 --- a/arch/x86/lib/getuser.S
21555 +++ b/arch/x86/lib/getuser.S
21556 @@ -33,15 +33,38 @@
21557 #include <asm/asm-offsets.h>
21558 #include <asm/thread_info.h>
21559 #include <asm/asm.h>
21560 +#include <asm/segment.h>
21561 +#include <asm/pgtable.h>
21562 +#include <asm/alternative-asm.h>
21563 +
21564 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21565 +#define __copyuser_seg gs;
21566 +#else
21567 +#define __copyuser_seg
21568 +#endif
21569
21570 .text
21571 ENTRY(__get_user_1)
21572 CFI_STARTPROC
21573 +
21574 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21575 GET_THREAD_INFO(%_ASM_DX)
21576 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21577 jae bad_get_user
21578 -1: movzb (%_ASM_AX),%edx
21579 +
21580 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21581 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21582 + cmp %_ASM_DX,%_ASM_AX
21583 + jae 1234f
21584 + add %_ASM_DX,%_ASM_AX
21585 +1234:
21586 +#endif
21587 +
21588 +#endif
21589 +
21590 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21591 xor %eax,%eax
21592 + pax_force_retaddr
21593 ret
21594 CFI_ENDPROC
21595 ENDPROC(__get_user_1)
21596 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21597 ENTRY(__get_user_2)
21598 CFI_STARTPROC
21599 add $1,%_ASM_AX
21600 +
21601 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21602 jc bad_get_user
21603 GET_THREAD_INFO(%_ASM_DX)
21604 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21605 jae bad_get_user
21606 -2: movzwl -1(%_ASM_AX),%edx
21607 +
21608 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21609 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21610 + cmp %_ASM_DX,%_ASM_AX
21611 + jae 1234f
21612 + add %_ASM_DX,%_ASM_AX
21613 +1234:
21614 +#endif
21615 +
21616 +#endif
21617 +
21618 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21619 xor %eax,%eax
21620 + pax_force_retaddr
21621 ret
21622 CFI_ENDPROC
21623 ENDPROC(__get_user_2)
21624 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21625 ENTRY(__get_user_4)
21626 CFI_STARTPROC
21627 add $3,%_ASM_AX
21628 +
21629 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21630 jc bad_get_user
21631 GET_THREAD_INFO(%_ASM_DX)
21632 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21633 jae bad_get_user
21634 -3: mov -3(%_ASM_AX),%edx
21635 +
21636 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21637 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21638 + cmp %_ASM_DX,%_ASM_AX
21639 + jae 1234f
21640 + add %_ASM_DX,%_ASM_AX
21641 +1234:
21642 +#endif
21643 +
21644 +#endif
21645 +
21646 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21647 xor %eax,%eax
21648 + pax_force_retaddr
21649 ret
21650 CFI_ENDPROC
21651 ENDPROC(__get_user_4)
21652 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21653 GET_THREAD_INFO(%_ASM_DX)
21654 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21655 jae bad_get_user
21656 +
21657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21658 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21659 + cmp %_ASM_DX,%_ASM_AX
21660 + jae 1234f
21661 + add %_ASM_DX,%_ASM_AX
21662 +1234:
21663 +#endif
21664 +
21665 4: movq -7(%_ASM_AX),%_ASM_DX
21666 xor %eax,%eax
21667 + pax_force_retaddr
21668 ret
21669 CFI_ENDPROC
21670 ENDPROC(__get_user_8)
21671 @@ -91,6 +152,7 @@ bad_get_user:
21672 CFI_STARTPROC
21673 xor %edx,%edx
21674 mov $(-EFAULT),%_ASM_AX
21675 + pax_force_retaddr
21676 ret
21677 CFI_ENDPROC
21678 END(bad_get_user)
21679 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21680 index b1e6c4b..21ae8fc 100644
21681 --- a/arch/x86/lib/insn.c
21682 +++ b/arch/x86/lib/insn.c
21683 @@ -21,6 +21,11 @@
21684 #include <linux/string.h>
21685 #include <asm/inat.h>
21686 #include <asm/insn.h>
21687 +#ifdef __KERNEL__
21688 +#include <asm/pgtable_types.h>
21689 +#else
21690 +#define ktla_ktva(addr) addr
21691 +#endif
21692
21693 /* Verify next sizeof(t) bytes can be on the same instruction */
21694 #define validate_next(t, insn, n) \
21695 @@ -49,8 +54,8 @@
21696 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21697 {
21698 memset(insn, 0, sizeof(*insn));
21699 - insn->kaddr = kaddr;
21700 - insn->next_byte = kaddr;
21701 + insn->kaddr = ktla_ktva(kaddr);
21702 + insn->next_byte = ktla_ktva(kaddr);
21703 insn->x86_64 = x86_64 ? 1 : 0;
21704 insn->opnd_bytes = 4;
21705 if (x86_64)
21706 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21707 index 05a95e7..326f2fa 100644
21708 --- a/arch/x86/lib/iomap_copy_64.S
21709 +++ b/arch/x86/lib/iomap_copy_64.S
21710 @@ -17,6 +17,7 @@
21711
21712 #include <linux/linkage.h>
21713 #include <asm/dwarf2.h>
21714 +#include <asm/alternative-asm.h>
21715
21716 /*
21717 * override generic version in lib/iomap_copy.c
21718 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21719 CFI_STARTPROC
21720 movl %edx,%ecx
21721 rep movsd
21722 + pax_force_retaddr
21723 ret
21724 CFI_ENDPROC
21725 ENDPROC(__iowrite32_copy)
21726 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21727 index 1c273be..da9cc0e 100644
21728 --- a/arch/x86/lib/memcpy_64.S
21729 +++ b/arch/x86/lib/memcpy_64.S
21730 @@ -33,6 +33,7 @@
21731 rep movsq
21732 movl %edx, %ecx
21733 rep movsb
21734 + pax_force_retaddr
21735 ret
21736 .Lmemcpy_e:
21737 .previous
21738 @@ -49,6 +50,7 @@
21739 movq %rdi, %rax
21740 movq %rdx, %rcx
21741 rep movsb
21742 + pax_force_retaddr
21743 ret
21744 .Lmemcpy_e_e:
21745 .previous
21746 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21747 */
21748 movq 0*8(%rsi), %r8
21749 movq 1*8(%rsi), %r9
21750 - movq 2*8(%rsi), %r10
21751 + movq 2*8(%rsi), %rcx
21752 movq 3*8(%rsi), %r11
21753 leaq 4*8(%rsi), %rsi
21754
21755 movq %r8, 0*8(%rdi)
21756 movq %r9, 1*8(%rdi)
21757 - movq %r10, 2*8(%rdi)
21758 + movq %rcx, 2*8(%rdi)
21759 movq %r11, 3*8(%rdi)
21760 leaq 4*8(%rdi), %rdi
21761 jae .Lcopy_forward_loop
21762 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21763 subq $0x20, %rdx
21764 movq -1*8(%rsi), %r8
21765 movq -2*8(%rsi), %r9
21766 - movq -3*8(%rsi), %r10
21767 + movq -3*8(%rsi), %rcx
21768 movq -4*8(%rsi), %r11
21769 leaq -4*8(%rsi), %rsi
21770 movq %r8, -1*8(%rdi)
21771 movq %r9, -2*8(%rdi)
21772 - movq %r10, -3*8(%rdi)
21773 + movq %rcx, -3*8(%rdi)
21774 movq %r11, -4*8(%rdi)
21775 leaq -4*8(%rdi), %rdi
21776 jae .Lcopy_backward_loop
21777 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21778 */
21779 movq 0*8(%rsi), %r8
21780 movq 1*8(%rsi), %r9
21781 - movq -2*8(%rsi, %rdx), %r10
21782 + movq -2*8(%rsi, %rdx), %rcx
21783 movq -1*8(%rsi, %rdx), %r11
21784 movq %r8, 0*8(%rdi)
21785 movq %r9, 1*8(%rdi)
21786 - movq %r10, -2*8(%rdi, %rdx)
21787 + movq %rcx, -2*8(%rdi, %rdx)
21788 movq %r11, -1*8(%rdi, %rdx)
21789 + pax_force_retaddr
21790 retq
21791 .p2align 4
21792 .Lless_16bytes:
21793 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21794 movq -1*8(%rsi, %rdx), %r9
21795 movq %r8, 0*8(%rdi)
21796 movq %r9, -1*8(%rdi, %rdx)
21797 + pax_force_retaddr
21798 retq
21799 .p2align 4
21800 .Lless_8bytes:
21801 @@ -161,6 +165,7 @@ ENTRY(memcpy)
21802 movl -4(%rsi, %rdx), %r8d
21803 movl %ecx, (%rdi)
21804 movl %r8d, -4(%rdi, %rdx)
21805 + pax_force_retaddr
21806 retq
21807 .p2align 4
21808 .Lless_3bytes:
21809 @@ -179,6 +184,7 @@ ENTRY(memcpy)
21810 movb %cl, (%rdi)
21811
21812 .Lend:
21813 + pax_force_retaddr
21814 retq
21815 CFI_ENDPROC
21816 ENDPROC(memcpy)
21817 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21818 index ee16461..c39c199 100644
21819 --- a/arch/x86/lib/memmove_64.S
21820 +++ b/arch/x86/lib/memmove_64.S
21821 @@ -61,13 +61,13 @@ ENTRY(memmove)
21822 5:
21823 sub $0x20, %rdx
21824 movq 0*8(%rsi), %r11
21825 - movq 1*8(%rsi), %r10
21826 + movq 1*8(%rsi), %rcx
21827 movq 2*8(%rsi), %r9
21828 movq 3*8(%rsi), %r8
21829 leaq 4*8(%rsi), %rsi
21830
21831 movq %r11, 0*8(%rdi)
21832 - movq %r10, 1*8(%rdi)
21833 + movq %rcx, 1*8(%rdi)
21834 movq %r9, 2*8(%rdi)
21835 movq %r8, 3*8(%rdi)
21836 leaq 4*8(%rdi), %rdi
21837 @@ -81,10 +81,10 @@ ENTRY(memmove)
21838 4:
21839 movq %rdx, %rcx
21840 movq -8(%rsi, %rdx), %r11
21841 - lea -8(%rdi, %rdx), %r10
21842 + lea -8(%rdi, %rdx), %r9
21843 shrq $3, %rcx
21844 rep movsq
21845 - movq %r11, (%r10)
21846 + movq %r11, (%r9)
21847 jmp 13f
21848 .Lmemmove_end_forward:
21849
21850 @@ -95,14 +95,14 @@ ENTRY(memmove)
21851 7:
21852 movq %rdx, %rcx
21853 movq (%rsi), %r11
21854 - movq %rdi, %r10
21855 + movq %rdi, %r9
21856 leaq -8(%rsi, %rdx), %rsi
21857 leaq -8(%rdi, %rdx), %rdi
21858 shrq $3, %rcx
21859 std
21860 rep movsq
21861 cld
21862 - movq %r11, (%r10)
21863 + movq %r11, (%r9)
21864 jmp 13f
21865
21866 /*
21867 @@ -127,13 +127,13 @@ ENTRY(memmove)
21868 8:
21869 subq $0x20, %rdx
21870 movq -1*8(%rsi), %r11
21871 - movq -2*8(%rsi), %r10
21872 + movq -2*8(%rsi), %rcx
21873 movq -3*8(%rsi), %r9
21874 movq -4*8(%rsi), %r8
21875 leaq -4*8(%rsi), %rsi
21876
21877 movq %r11, -1*8(%rdi)
21878 - movq %r10, -2*8(%rdi)
21879 + movq %rcx, -2*8(%rdi)
21880 movq %r9, -3*8(%rdi)
21881 movq %r8, -4*8(%rdi)
21882 leaq -4*8(%rdi), %rdi
21883 @@ -151,11 +151,11 @@ ENTRY(memmove)
21884 * Move data from 16 bytes to 31 bytes.
21885 */
21886 movq 0*8(%rsi), %r11
21887 - movq 1*8(%rsi), %r10
21888 + movq 1*8(%rsi), %rcx
21889 movq -2*8(%rsi, %rdx), %r9
21890 movq -1*8(%rsi, %rdx), %r8
21891 movq %r11, 0*8(%rdi)
21892 - movq %r10, 1*8(%rdi)
21893 + movq %rcx, 1*8(%rdi)
21894 movq %r9, -2*8(%rdi, %rdx)
21895 movq %r8, -1*8(%rdi, %rdx)
21896 jmp 13f
21897 @@ -167,9 +167,9 @@ ENTRY(memmove)
21898 * Move data from 8 bytes to 15 bytes.
21899 */
21900 movq 0*8(%rsi), %r11
21901 - movq -1*8(%rsi, %rdx), %r10
21902 + movq -1*8(%rsi, %rdx), %r9
21903 movq %r11, 0*8(%rdi)
21904 - movq %r10, -1*8(%rdi, %rdx)
21905 + movq %r9, -1*8(%rdi, %rdx)
21906 jmp 13f
21907 10:
21908 cmpq $4, %rdx
21909 @@ -178,9 +178,9 @@ ENTRY(memmove)
21910 * Move data from 4 bytes to 7 bytes.
21911 */
21912 movl (%rsi), %r11d
21913 - movl -4(%rsi, %rdx), %r10d
21914 + movl -4(%rsi, %rdx), %r9d
21915 movl %r11d, (%rdi)
21916 - movl %r10d, -4(%rdi, %rdx)
21917 + movl %r9d, -4(%rdi, %rdx)
21918 jmp 13f
21919 11:
21920 cmp $2, %rdx
21921 @@ -189,9 +189,9 @@ ENTRY(memmove)
21922 * Move data from 2 bytes to 3 bytes.
21923 */
21924 movw (%rsi), %r11w
21925 - movw -2(%rsi, %rdx), %r10w
21926 + movw -2(%rsi, %rdx), %r9w
21927 movw %r11w, (%rdi)
21928 - movw %r10w, -2(%rdi, %rdx)
21929 + movw %r9w, -2(%rdi, %rdx)
21930 jmp 13f
21931 12:
21932 cmp $1, %rdx
21933 @@ -202,6 +202,7 @@ ENTRY(memmove)
21934 movb (%rsi), %r11b
21935 movb %r11b, (%rdi)
21936 13:
21937 + pax_force_retaddr
21938 retq
21939 CFI_ENDPROC
21940
21941 @@ -210,6 +211,7 @@ ENTRY(memmove)
21942 /* Forward moving data. */
21943 movq %rdx, %rcx
21944 rep movsb
21945 + pax_force_retaddr
21946 retq
21947 .Lmemmove_end_forward_efs:
21948 .previous
21949 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21950 index 2dcb380..963660a 100644
21951 --- a/arch/x86/lib/memset_64.S
21952 +++ b/arch/x86/lib/memset_64.S
21953 @@ -30,6 +30,7 @@
21954 movl %edx,%ecx
21955 rep stosb
21956 movq %r9,%rax
21957 + pax_force_retaddr
21958 ret
21959 .Lmemset_e:
21960 .previous
21961 @@ -52,6 +53,7 @@
21962 movq %rdx,%rcx
21963 rep stosb
21964 movq %r9,%rax
21965 + pax_force_retaddr
21966 ret
21967 .Lmemset_e_e:
21968 .previous
21969 @@ -59,7 +61,7 @@
21970 ENTRY(memset)
21971 ENTRY(__memset)
21972 CFI_STARTPROC
21973 - movq %rdi,%r10
21974 + movq %rdi,%r11
21975
21976 /* expand byte value */
21977 movzbl %sil,%ecx
21978 @@ -117,7 +119,8 @@ ENTRY(__memset)
21979 jnz .Lloop_1
21980
21981 .Lende:
21982 - movq %r10,%rax
21983 + movq %r11,%rax
21984 + pax_force_retaddr
21985 ret
21986
21987 CFI_RESTORE_STATE
21988 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21989 index c9f2d9b..e7fd2c0 100644
21990 --- a/arch/x86/lib/mmx_32.c
21991 +++ b/arch/x86/lib/mmx_32.c
21992 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21993 {
21994 void *p;
21995 int i;
21996 + unsigned long cr0;
21997
21998 if (unlikely(in_interrupt()))
21999 return __memcpy(to, from, len);
22000 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22001 kernel_fpu_begin();
22002
22003 __asm__ __volatile__ (
22004 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22005 - " prefetch 64(%0)\n"
22006 - " prefetch 128(%0)\n"
22007 - " prefetch 192(%0)\n"
22008 - " prefetch 256(%0)\n"
22009 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22010 + " prefetch 64(%1)\n"
22011 + " prefetch 128(%1)\n"
22012 + " prefetch 192(%1)\n"
22013 + " prefetch 256(%1)\n"
22014 "2: \n"
22015 ".section .fixup, \"ax\"\n"
22016 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22017 + "3: \n"
22018 +
22019 +#ifdef CONFIG_PAX_KERNEXEC
22020 + " movl %%cr0, %0\n"
22021 + " movl %0, %%eax\n"
22022 + " andl $0xFFFEFFFF, %%eax\n"
22023 + " movl %%eax, %%cr0\n"
22024 +#endif
22025 +
22026 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22027 +
22028 +#ifdef CONFIG_PAX_KERNEXEC
22029 + " movl %0, %%cr0\n"
22030 +#endif
22031 +
22032 " jmp 2b\n"
22033 ".previous\n"
22034 _ASM_EXTABLE(1b, 3b)
22035 - : : "r" (from));
22036 + : "=&r" (cr0) : "r" (from) : "ax");
22037
22038 for ( ; i > 5; i--) {
22039 __asm__ __volatile__ (
22040 - "1: prefetch 320(%0)\n"
22041 - "2: movq (%0), %%mm0\n"
22042 - " movq 8(%0), %%mm1\n"
22043 - " movq 16(%0), %%mm2\n"
22044 - " movq 24(%0), %%mm3\n"
22045 - " movq %%mm0, (%1)\n"
22046 - " movq %%mm1, 8(%1)\n"
22047 - " movq %%mm2, 16(%1)\n"
22048 - " movq %%mm3, 24(%1)\n"
22049 - " movq 32(%0), %%mm0\n"
22050 - " movq 40(%0), %%mm1\n"
22051 - " movq 48(%0), %%mm2\n"
22052 - " movq 56(%0), %%mm3\n"
22053 - " movq %%mm0, 32(%1)\n"
22054 - " movq %%mm1, 40(%1)\n"
22055 - " movq %%mm2, 48(%1)\n"
22056 - " movq %%mm3, 56(%1)\n"
22057 + "1: prefetch 320(%1)\n"
22058 + "2: movq (%1), %%mm0\n"
22059 + " movq 8(%1), %%mm1\n"
22060 + " movq 16(%1), %%mm2\n"
22061 + " movq 24(%1), %%mm3\n"
22062 + " movq %%mm0, (%2)\n"
22063 + " movq %%mm1, 8(%2)\n"
22064 + " movq %%mm2, 16(%2)\n"
22065 + " movq %%mm3, 24(%2)\n"
22066 + " movq 32(%1), %%mm0\n"
22067 + " movq 40(%1), %%mm1\n"
22068 + " movq 48(%1), %%mm2\n"
22069 + " movq 56(%1), %%mm3\n"
22070 + " movq %%mm0, 32(%2)\n"
22071 + " movq %%mm1, 40(%2)\n"
22072 + " movq %%mm2, 48(%2)\n"
22073 + " movq %%mm3, 56(%2)\n"
22074 ".section .fixup, \"ax\"\n"
22075 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22076 + "3:\n"
22077 +
22078 +#ifdef CONFIG_PAX_KERNEXEC
22079 + " movl %%cr0, %0\n"
22080 + " movl %0, %%eax\n"
22081 + " andl $0xFFFEFFFF, %%eax\n"
22082 + " movl %%eax, %%cr0\n"
22083 +#endif
22084 +
22085 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22086 +
22087 +#ifdef CONFIG_PAX_KERNEXEC
22088 + " movl %0, %%cr0\n"
22089 +#endif
22090 +
22091 " jmp 2b\n"
22092 ".previous\n"
22093 _ASM_EXTABLE(1b, 3b)
22094 - : : "r" (from), "r" (to) : "memory");
22095 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22096
22097 from += 64;
22098 to += 64;
22099 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22100 static void fast_copy_page(void *to, void *from)
22101 {
22102 int i;
22103 + unsigned long cr0;
22104
22105 kernel_fpu_begin();
22106
22107 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22108 * but that is for later. -AV
22109 */
22110 __asm__ __volatile__(
22111 - "1: prefetch (%0)\n"
22112 - " prefetch 64(%0)\n"
22113 - " prefetch 128(%0)\n"
22114 - " prefetch 192(%0)\n"
22115 - " prefetch 256(%0)\n"
22116 + "1: prefetch (%1)\n"
22117 + " prefetch 64(%1)\n"
22118 + " prefetch 128(%1)\n"
22119 + " prefetch 192(%1)\n"
22120 + " prefetch 256(%1)\n"
22121 "2: \n"
22122 ".section .fixup, \"ax\"\n"
22123 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22124 + "3: \n"
22125 +
22126 +#ifdef CONFIG_PAX_KERNEXEC
22127 + " movl %%cr0, %0\n"
22128 + " movl %0, %%eax\n"
22129 + " andl $0xFFFEFFFF, %%eax\n"
22130 + " movl %%eax, %%cr0\n"
22131 +#endif
22132 +
22133 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22134 +
22135 +#ifdef CONFIG_PAX_KERNEXEC
22136 + " movl %0, %%cr0\n"
22137 +#endif
22138 +
22139 " jmp 2b\n"
22140 ".previous\n"
22141 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22142 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22143
22144 for (i = 0; i < (4096-320)/64; i++) {
22145 __asm__ __volatile__ (
22146 - "1: prefetch 320(%0)\n"
22147 - "2: movq (%0), %%mm0\n"
22148 - " movntq %%mm0, (%1)\n"
22149 - " movq 8(%0), %%mm1\n"
22150 - " movntq %%mm1, 8(%1)\n"
22151 - " movq 16(%0), %%mm2\n"
22152 - " movntq %%mm2, 16(%1)\n"
22153 - " movq 24(%0), %%mm3\n"
22154 - " movntq %%mm3, 24(%1)\n"
22155 - " movq 32(%0), %%mm4\n"
22156 - " movntq %%mm4, 32(%1)\n"
22157 - " movq 40(%0), %%mm5\n"
22158 - " movntq %%mm5, 40(%1)\n"
22159 - " movq 48(%0), %%mm6\n"
22160 - " movntq %%mm6, 48(%1)\n"
22161 - " movq 56(%0), %%mm7\n"
22162 - " movntq %%mm7, 56(%1)\n"
22163 + "1: prefetch 320(%1)\n"
22164 + "2: movq (%1), %%mm0\n"
22165 + " movntq %%mm0, (%2)\n"
22166 + " movq 8(%1), %%mm1\n"
22167 + " movntq %%mm1, 8(%2)\n"
22168 + " movq 16(%1), %%mm2\n"
22169 + " movntq %%mm2, 16(%2)\n"
22170 + " movq 24(%1), %%mm3\n"
22171 + " movntq %%mm3, 24(%2)\n"
22172 + " movq 32(%1), %%mm4\n"
22173 + " movntq %%mm4, 32(%2)\n"
22174 + " movq 40(%1), %%mm5\n"
22175 + " movntq %%mm5, 40(%2)\n"
22176 + " movq 48(%1), %%mm6\n"
22177 + " movntq %%mm6, 48(%2)\n"
22178 + " movq 56(%1), %%mm7\n"
22179 + " movntq %%mm7, 56(%2)\n"
22180 ".section .fixup, \"ax\"\n"
22181 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22182 + "3:\n"
22183 +
22184 +#ifdef CONFIG_PAX_KERNEXEC
22185 + " movl %%cr0, %0\n"
22186 + " movl %0, %%eax\n"
22187 + " andl $0xFFFEFFFF, %%eax\n"
22188 + " movl %%eax, %%cr0\n"
22189 +#endif
22190 +
22191 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22192 +
22193 +#ifdef CONFIG_PAX_KERNEXEC
22194 + " movl %0, %%cr0\n"
22195 +#endif
22196 +
22197 " jmp 2b\n"
22198 ".previous\n"
22199 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22200 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22201
22202 from += 64;
22203 to += 64;
22204 @@ -280,47 +338,76 @@ 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 __asm__ __volatile__ (
22213 - "1: prefetch (%0)\n"
22214 - " prefetch 64(%0)\n"
22215 - " prefetch 128(%0)\n"
22216 - " prefetch 192(%0)\n"
22217 - " prefetch 256(%0)\n"
22218 + "1: prefetch (%1)\n"
22219 + " prefetch 64(%1)\n"
22220 + " prefetch 128(%1)\n"
22221 + " prefetch 192(%1)\n"
22222 + " prefetch 256(%1)\n"
22223 "2: \n"
22224 ".section .fixup, \"ax\"\n"
22225 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22226 + "3: \n"
22227 +
22228 +#ifdef CONFIG_PAX_KERNEXEC
22229 + " movl %%cr0, %0\n"
22230 + " movl %0, %%eax\n"
22231 + " andl $0xFFFEFFFF, %%eax\n"
22232 + " movl %%eax, %%cr0\n"
22233 +#endif
22234 +
22235 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22236 +
22237 +#ifdef CONFIG_PAX_KERNEXEC
22238 + " movl %0, %%cr0\n"
22239 +#endif
22240 +
22241 " jmp 2b\n"
22242 ".previous\n"
22243 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22244 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22245
22246 for (i = 0; i < 4096/64; i++) {
22247 __asm__ __volatile__ (
22248 - "1: prefetch 320(%0)\n"
22249 - "2: movq (%0), %%mm0\n"
22250 - " movq 8(%0), %%mm1\n"
22251 - " movq 16(%0), %%mm2\n"
22252 - " movq 24(%0), %%mm3\n"
22253 - " movq %%mm0, (%1)\n"
22254 - " movq %%mm1, 8(%1)\n"
22255 - " movq %%mm2, 16(%1)\n"
22256 - " movq %%mm3, 24(%1)\n"
22257 - " movq 32(%0), %%mm0\n"
22258 - " movq 40(%0), %%mm1\n"
22259 - " movq 48(%0), %%mm2\n"
22260 - " movq 56(%0), %%mm3\n"
22261 - " movq %%mm0, 32(%1)\n"
22262 - " movq %%mm1, 40(%1)\n"
22263 - " movq %%mm2, 48(%1)\n"
22264 - " movq %%mm3, 56(%1)\n"
22265 + "1: prefetch 320(%1)\n"
22266 + "2: movq (%1), %%mm0\n"
22267 + " movq 8(%1), %%mm1\n"
22268 + " movq 16(%1), %%mm2\n"
22269 + " movq 24(%1), %%mm3\n"
22270 + " movq %%mm0, (%2)\n"
22271 + " movq %%mm1, 8(%2)\n"
22272 + " movq %%mm2, 16(%2)\n"
22273 + " movq %%mm3, 24(%2)\n"
22274 + " movq 32(%1), %%mm0\n"
22275 + " movq 40(%1), %%mm1\n"
22276 + " movq 48(%1), %%mm2\n"
22277 + " movq 56(%1), %%mm3\n"
22278 + " movq %%mm0, 32(%2)\n"
22279 + " movq %%mm1, 40(%2)\n"
22280 + " movq %%mm2, 48(%2)\n"
22281 + " movq %%mm3, 56(%2)\n"
22282 ".section .fixup, \"ax\"\n"
22283 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22284 + "3:\n"
22285 +
22286 +#ifdef CONFIG_PAX_KERNEXEC
22287 + " movl %%cr0, %0\n"
22288 + " movl %0, %%eax\n"
22289 + " andl $0xFFFEFFFF, %%eax\n"
22290 + " movl %%eax, %%cr0\n"
22291 +#endif
22292 +
22293 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22294 +
22295 +#ifdef CONFIG_PAX_KERNEXEC
22296 + " movl %0, %%cr0\n"
22297 +#endif
22298 +
22299 " jmp 2b\n"
22300 ".previous\n"
22301 _ASM_EXTABLE(1b, 3b)
22302 - : : "r" (from), "r" (to) : "memory");
22303 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22304
22305 from += 64;
22306 to += 64;
22307 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22308 index 69fa106..adda88b 100644
22309 --- a/arch/x86/lib/msr-reg.S
22310 +++ b/arch/x86/lib/msr-reg.S
22311 @@ -3,6 +3,7 @@
22312 #include <asm/dwarf2.h>
22313 #include <asm/asm.h>
22314 #include <asm/msr.h>
22315 +#include <asm/alternative-asm.h>
22316
22317 #ifdef CONFIG_X86_64
22318 /*
22319 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22320 CFI_STARTPROC
22321 pushq_cfi %rbx
22322 pushq_cfi %rbp
22323 - movq %rdi, %r10 /* Save pointer */
22324 + movq %rdi, %r9 /* Save pointer */
22325 xorl %r11d, %r11d /* Return value */
22326 movl (%rdi), %eax
22327 movl 4(%rdi), %ecx
22328 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22329 movl 28(%rdi), %edi
22330 CFI_REMEMBER_STATE
22331 1: \op
22332 -2: movl %eax, (%r10)
22333 +2: movl %eax, (%r9)
22334 movl %r11d, %eax /* Return value */
22335 - movl %ecx, 4(%r10)
22336 - movl %edx, 8(%r10)
22337 - movl %ebx, 12(%r10)
22338 - movl %ebp, 20(%r10)
22339 - movl %esi, 24(%r10)
22340 - movl %edi, 28(%r10)
22341 + movl %ecx, 4(%r9)
22342 + movl %edx, 8(%r9)
22343 + movl %ebx, 12(%r9)
22344 + movl %ebp, 20(%r9)
22345 + movl %esi, 24(%r9)
22346 + movl %edi, 28(%r9)
22347 popq_cfi %rbp
22348 popq_cfi %rbx
22349 + pax_force_retaddr
22350 ret
22351 3:
22352 CFI_RESTORE_STATE
22353 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22354 index 7f951c8..ebd573a 100644
22355 --- a/arch/x86/lib/putuser.S
22356 +++ b/arch/x86/lib/putuser.S
22357 @@ -15,7 +15,9 @@
22358 #include <asm/thread_info.h>
22359 #include <asm/errno.h>
22360 #include <asm/asm.h>
22361 -
22362 +#include <asm/segment.h>
22363 +#include <asm/pgtable.h>
22364 +#include <asm/alternative-asm.h>
22365
22366 /*
22367 * __put_user_X
22368 @@ -29,52 +31,119 @@
22369 * as they get called from within inline assembly.
22370 */
22371
22372 -#define ENTER CFI_STARTPROC ; \
22373 - GET_THREAD_INFO(%_ASM_BX)
22374 -#define EXIT ret ; \
22375 +#define ENTER CFI_STARTPROC
22376 +#define EXIT pax_force_retaddr; ret ; \
22377 CFI_ENDPROC
22378
22379 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22380 +#define _DEST %_ASM_CX,%_ASM_BX
22381 +#else
22382 +#define _DEST %_ASM_CX
22383 +#endif
22384 +
22385 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22386 +#define __copyuser_seg gs;
22387 +#else
22388 +#define __copyuser_seg
22389 +#endif
22390 +
22391 .text
22392 ENTRY(__put_user_1)
22393 ENTER
22394 +
22395 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22396 + GET_THREAD_INFO(%_ASM_BX)
22397 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22398 jae bad_put_user
22399 -1: movb %al,(%_ASM_CX)
22400 +
22401 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22402 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22403 + cmp %_ASM_BX,%_ASM_CX
22404 + jb 1234f
22405 + xor %ebx,%ebx
22406 +1234:
22407 +#endif
22408 +
22409 +#endif
22410 +
22411 +1: __copyuser_seg movb %al,(_DEST)
22412 xor %eax,%eax
22413 EXIT
22414 ENDPROC(__put_user_1)
22415
22416 ENTRY(__put_user_2)
22417 ENTER
22418 +
22419 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22420 + GET_THREAD_INFO(%_ASM_BX)
22421 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22422 sub $1,%_ASM_BX
22423 cmp %_ASM_BX,%_ASM_CX
22424 jae bad_put_user
22425 -2: movw %ax,(%_ASM_CX)
22426 +
22427 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22428 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22429 + cmp %_ASM_BX,%_ASM_CX
22430 + jb 1234f
22431 + xor %ebx,%ebx
22432 +1234:
22433 +#endif
22434 +
22435 +#endif
22436 +
22437 +2: __copyuser_seg movw %ax,(_DEST)
22438 xor %eax,%eax
22439 EXIT
22440 ENDPROC(__put_user_2)
22441
22442 ENTRY(__put_user_4)
22443 ENTER
22444 +
22445 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22446 + GET_THREAD_INFO(%_ASM_BX)
22447 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22448 sub $3,%_ASM_BX
22449 cmp %_ASM_BX,%_ASM_CX
22450 jae bad_put_user
22451 -3: movl %eax,(%_ASM_CX)
22452 +
22453 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22454 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22455 + cmp %_ASM_BX,%_ASM_CX
22456 + jb 1234f
22457 + xor %ebx,%ebx
22458 +1234:
22459 +#endif
22460 +
22461 +#endif
22462 +
22463 +3: __copyuser_seg movl %eax,(_DEST)
22464 xor %eax,%eax
22465 EXIT
22466 ENDPROC(__put_user_4)
22467
22468 ENTRY(__put_user_8)
22469 ENTER
22470 +
22471 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22472 + GET_THREAD_INFO(%_ASM_BX)
22473 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22474 sub $7,%_ASM_BX
22475 cmp %_ASM_BX,%_ASM_CX
22476 jae bad_put_user
22477 -4: mov %_ASM_AX,(%_ASM_CX)
22478 +
22479 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22480 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22481 + cmp %_ASM_BX,%_ASM_CX
22482 + jb 1234f
22483 + xor %ebx,%ebx
22484 +1234:
22485 +#endif
22486 +
22487 +#endif
22488 +
22489 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22490 #ifdef CONFIG_X86_32
22491 -5: movl %edx,4(%_ASM_CX)
22492 +5: __copyuser_seg movl %edx,4(_DEST)
22493 #endif
22494 xor %eax,%eax
22495 EXIT
22496 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22497 index 1cad221..de671ee 100644
22498 --- a/arch/x86/lib/rwlock.S
22499 +++ b/arch/x86/lib/rwlock.S
22500 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22501 FRAME
22502 0: LOCK_PREFIX
22503 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22504 +
22505 +#ifdef CONFIG_PAX_REFCOUNT
22506 + jno 1234f
22507 + LOCK_PREFIX
22508 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22509 + int $4
22510 +1234:
22511 + _ASM_EXTABLE(1234b, 1234b)
22512 +#endif
22513 +
22514 1: rep; nop
22515 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22516 jne 1b
22517 LOCK_PREFIX
22518 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22519 +
22520 +#ifdef CONFIG_PAX_REFCOUNT
22521 + jno 1234f
22522 + LOCK_PREFIX
22523 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22524 + int $4
22525 +1234:
22526 + _ASM_EXTABLE(1234b, 1234b)
22527 +#endif
22528 +
22529 jnz 0b
22530 ENDFRAME
22531 + pax_force_retaddr
22532 ret
22533 CFI_ENDPROC
22534 END(__write_lock_failed)
22535 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22536 FRAME
22537 0: LOCK_PREFIX
22538 READ_LOCK_SIZE(inc) (%__lock_ptr)
22539 +
22540 +#ifdef CONFIG_PAX_REFCOUNT
22541 + jno 1234f
22542 + LOCK_PREFIX
22543 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22544 + int $4
22545 +1234:
22546 + _ASM_EXTABLE(1234b, 1234b)
22547 +#endif
22548 +
22549 1: rep; nop
22550 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22551 js 1b
22552 LOCK_PREFIX
22553 READ_LOCK_SIZE(dec) (%__lock_ptr)
22554 +
22555 +#ifdef CONFIG_PAX_REFCOUNT
22556 + jno 1234f
22557 + LOCK_PREFIX
22558 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22559 + int $4
22560 +1234:
22561 + _ASM_EXTABLE(1234b, 1234b)
22562 +#endif
22563 +
22564 js 0b
22565 ENDFRAME
22566 + pax_force_retaddr
22567 ret
22568 CFI_ENDPROC
22569 END(__read_lock_failed)
22570 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22571 index 5dff5f0..cadebf4 100644
22572 --- a/arch/x86/lib/rwsem.S
22573 +++ b/arch/x86/lib/rwsem.S
22574 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22575 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22576 CFI_RESTORE __ASM_REG(dx)
22577 restore_common_regs
22578 + pax_force_retaddr
22579 ret
22580 CFI_ENDPROC
22581 ENDPROC(call_rwsem_down_read_failed)
22582 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22583 movq %rax,%rdi
22584 call rwsem_down_write_failed
22585 restore_common_regs
22586 + pax_force_retaddr
22587 ret
22588 CFI_ENDPROC
22589 ENDPROC(call_rwsem_down_write_failed)
22590 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22591 movq %rax,%rdi
22592 call rwsem_wake
22593 restore_common_regs
22594 -1: ret
22595 +1: pax_force_retaddr
22596 + ret
22597 CFI_ENDPROC
22598 ENDPROC(call_rwsem_wake)
22599
22600 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22601 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22602 CFI_RESTORE __ASM_REG(dx)
22603 restore_common_regs
22604 + pax_force_retaddr
22605 ret
22606 CFI_ENDPROC
22607 ENDPROC(call_rwsem_downgrade_wake)
22608 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22609 index a63efd6..ccecad8 100644
22610 --- a/arch/x86/lib/thunk_64.S
22611 +++ b/arch/x86/lib/thunk_64.S
22612 @@ -8,6 +8,7 @@
22613 #include <linux/linkage.h>
22614 #include <asm/dwarf2.h>
22615 #include <asm/calling.h>
22616 +#include <asm/alternative-asm.h>
22617
22618 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22619 .macro THUNK name, func, put_ret_addr_in_rdi=0
22620 @@ -41,5 +42,6 @@
22621 SAVE_ARGS
22622 restore:
22623 RESTORE_ARGS
22624 + pax_force_retaddr
22625 ret
22626 CFI_ENDPROC
22627 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22628 index 1781b2f..18e3040 100644
22629 --- a/arch/x86/lib/usercopy_32.c
22630 +++ b/arch/x86/lib/usercopy_32.c
22631 @@ -42,10 +42,12 @@ do { \
22632 int __d0; \
22633 might_fault(); \
22634 __asm__ __volatile__( \
22635 + __COPYUSER_SET_ES \
22636 "0: rep; stosl\n" \
22637 " movl %2,%0\n" \
22638 "1: rep; stosb\n" \
22639 "2:\n" \
22640 + __COPYUSER_RESTORE_ES \
22641 ".section .fixup,\"ax\"\n" \
22642 "3: lea 0(%2,%0,4),%0\n" \
22643 " jmp 2b\n" \
22644 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22645
22646 #ifdef CONFIG_X86_INTEL_USERCOPY
22647 static unsigned long
22648 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22649 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22650 {
22651 int d0, d1;
22652 __asm__ __volatile__(
22653 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22654 " .align 2,0x90\n"
22655 "3: movl 0(%4), %%eax\n"
22656 "4: movl 4(%4), %%edx\n"
22657 - "5: movl %%eax, 0(%3)\n"
22658 - "6: movl %%edx, 4(%3)\n"
22659 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22660 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22661 "7: movl 8(%4), %%eax\n"
22662 "8: movl 12(%4),%%edx\n"
22663 - "9: movl %%eax, 8(%3)\n"
22664 - "10: movl %%edx, 12(%3)\n"
22665 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22666 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22667 "11: movl 16(%4), %%eax\n"
22668 "12: movl 20(%4), %%edx\n"
22669 - "13: movl %%eax, 16(%3)\n"
22670 - "14: movl %%edx, 20(%3)\n"
22671 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22672 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22673 "15: movl 24(%4), %%eax\n"
22674 "16: movl 28(%4), %%edx\n"
22675 - "17: movl %%eax, 24(%3)\n"
22676 - "18: movl %%edx, 28(%3)\n"
22677 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22678 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22679 "19: movl 32(%4), %%eax\n"
22680 "20: movl 36(%4), %%edx\n"
22681 - "21: movl %%eax, 32(%3)\n"
22682 - "22: movl %%edx, 36(%3)\n"
22683 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22684 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22685 "23: movl 40(%4), %%eax\n"
22686 "24: movl 44(%4), %%edx\n"
22687 - "25: movl %%eax, 40(%3)\n"
22688 - "26: movl %%edx, 44(%3)\n"
22689 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22690 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22691 "27: movl 48(%4), %%eax\n"
22692 "28: movl 52(%4), %%edx\n"
22693 - "29: movl %%eax, 48(%3)\n"
22694 - "30: movl %%edx, 52(%3)\n"
22695 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22696 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22697 "31: movl 56(%4), %%eax\n"
22698 "32: movl 60(%4), %%edx\n"
22699 - "33: movl %%eax, 56(%3)\n"
22700 - "34: movl %%edx, 60(%3)\n"
22701 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22702 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22703 " addl $-64, %0\n"
22704 " addl $64, %4\n"
22705 " addl $64, %3\n"
22706 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22707 " shrl $2, %0\n"
22708 " andl $3, %%eax\n"
22709 " cld\n"
22710 + __COPYUSER_SET_ES
22711 "99: rep; movsl\n"
22712 "36: movl %%eax, %0\n"
22713 "37: rep; movsb\n"
22714 "100:\n"
22715 + __COPYUSER_RESTORE_ES
22716 ".section .fixup,\"ax\"\n"
22717 "101: lea 0(%%eax,%0,4),%0\n"
22718 " jmp 100b\n"
22719 @@ -201,46 +205,152 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22720 }
22721
22722 static unsigned long
22723 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22724 +{
22725 + int d0, d1;
22726 + __asm__ __volatile__(
22727 + " .align 2,0x90\n"
22728 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22729 + " cmpl $67, %0\n"
22730 + " jbe 3f\n"
22731 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22732 + " .align 2,0x90\n"
22733 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22734 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22735 + "5: movl %%eax, 0(%3)\n"
22736 + "6: movl %%edx, 4(%3)\n"
22737 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22738 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22739 + "9: movl %%eax, 8(%3)\n"
22740 + "10: movl %%edx, 12(%3)\n"
22741 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22742 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22743 + "13: movl %%eax, 16(%3)\n"
22744 + "14: movl %%edx, 20(%3)\n"
22745 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22746 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22747 + "17: movl %%eax, 24(%3)\n"
22748 + "18: movl %%edx, 28(%3)\n"
22749 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22750 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22751 + "21: movl %%eax, 32(%3)\n"
22752 + "22: movl %%edx, 36(%3)\n"
22753 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22754 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22755 + "25: movl %%eax, 40(%3)\n"
22756 + "26: movl %%edx, 44(%3)\n"
22757 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22758 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22759 + "29: movl %%eax, 48(%3)\n"
22760 + "30: movl %%edx, 52(%3)\n"
22761 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22762 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22763 + "33: movl %%eax, 56(%3)\n"
22764 + "34: movl %%edx, 60(%3)\n"
22765 + " addl $-64, %0\n"
22766 + " addl $64, %4\n"
22767 + " addl $64, %3\n"
22768 + " cmpl $63, %0\n"
22769 + " ja 1b\n"
22770 + "35: movl %0, %%eax\n"
22771 + " shrl $2, %0\n"
22772 + " andl $3, %%eax\n"
22773 + " cld\n"
22774 + "99: rep; "__copyuser_seg" movsl\n"
22775 + "36: movl %%eax, %0\n"
22776 + "37: rep; "__copyuser_seg" movsb\n"
22777 + "100:\n"
22778 + ".section .fixup,\"ax\"\n"
22779 + "101: lea 0(%%eax,%0,4),%0\n"
22780 + " jmp 100b\n"
22781 + ".previous\n"
22782 + _ASM_EXTABLE(1b,100b)
22783 + _ASM_EXTABLE(2b,100b)
22784 + _ASM_EXTABLE(3b,100b)
22785 + _ASM_EXTABLE(4b,100b)
22786 + _ASM_EXTABLE(5b,100b)
22787 + _ASM_EXTABLE(6b,100b)
22788 + _ASM_EXTABLE(7b,100b)
22789 + _ASM_EXTABLE(8b,100b)
22790 + _ASM_EXTABLE(9b,100b)
22791 + _ASM_EXTABLE(10b,100b)
22792 + _ASM_EXTABLE(11b,100b)
22793 + _ASM_EXTABLE(12b,100b)
22794 + _ASM_EXTABLE(13b,100b)
22795 + _ASM_EXTABLE(14b,100b)
22796 + _ASM_EXTABLE(15b,100b)
22797 + _ASM_EXTABLE(16b,100b)
22798 + _ASM_EXTABLE(17b,100b)
22799 + _ASM_EXTABLE(18b,100b)
22800 + _ASM_EXTABLE(19b,100b)
22801 + _ASM_EXTABLE(20b,100b)
22802 + _ASM_EXTABLE(21b,100b)
22803 + _ASM_EXTABLE(22b,100b)
22804 + _ASM_EXTABLE(23b,100b)
22805 + _ASM_EXTABLE(24b,100b)
22806 + _ASM_EXTABLE(25b,100b)
22807 + _ASM_EXTABLE(26b,100b)
22808 + _ASM_EXTABLE(27b,100b)
22809 + _ASM_EXTABLE(28b,100b)
22810 + _ASM_EXTABLE(29b,100b)
22811 + _ASM_EXTABLE(30b,100b)
22812 + _ASM_EXTABLE(31b,100b)
22813 + _ASM_EXTABLE(32b,100b)
22814 + _ASM_EXTABLE(33b,100b)
22815 + _ASM_EXTABLE(34b,100b)
22816 + _ASM_EXTABLE(35b,100b)
22817 + _ASM_EXTABLE(36b,100b)
22818 + _ASM_EXTABLE(37b,100b)
22819 + _ASM_EXTABLE(99b,101b)
22820 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22821 + : "1"(to), "2"(from), "0"(size)
22822 + : "eax", "edx", "memory");
22823 + return size;
22824 +}
22825 +
22826 +static unsigned long
22827 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22828 +static unsigned long
22829 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22830 {
22831 int d0, d1;
22832 __asm__ __volatile__(
22833 " .align 2,0x90\n"
22834 - "0: movl 32(%4), %%eax\n"
22835 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22836 " cmpl $67, %0\n"
22837 " jbe 2f\n"
22838 - "1: movl 64(%4), %%eax\n"
22839 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22840 " .align 2,0x90\n"
22841 - "2: movl 0(%4), %%eax\n"
22842 - "21: movl 4(%4), %%edx\n"
22843 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22844 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22845 " movl %%eax, 0(%3)\n"
22846 " movl %%edx, 4(%3)\n"
22847 - "3: movl 8(%4), %%eax\n"
22848 - "31: movl 12(%4),%%edx\n"
22849 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22850 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22851 " movl %%eax, 8(%3)\n"
22852 " movl %%edx, 12(%3)\n"
22853 - "4: movl 16(%4), %%eax\n"
22854 - "41: movl 20(%4), %%edx\n"
22855 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22856 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22857 " movl %%eax, 16(%3)\n"
22858 " movl %%edx, 20(%3)\n"
22859 - "10: movl 24(%4), %%eax\n"
22860 - "51: movl 28(%4), %%edx\n"
22861 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22862 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22863 " movl %%eax, 24(%3)\n"
22864 " movl %%edx, 28(%3)\n"
22865 - "11: movl 32(%4), %%eax\n"
22866 - "61: movl 36(%4), %%edx\n"
22867 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22868 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22869 " movl %%eax, 32(%3)\n"
22870 " movl %%edx, 36(%3)\n"
22871 - "12: movl 40(%4), %%eax\n"
22872 - "71: movl 44(%4), %%edx\n"
22873 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22874 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22875 " movl %%eax, 40(%3)\n"
22876 " movl %%edx, 44(%3)\n"
22877 - "13: movl 48(%4), %%eax\n"
22878 - "81: movl 52(%4), %%edx\n"
22879 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22880 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22881 " movl %%eax, 48(%3)\n"
22882 " movl %%edx, 52(%3)\n"
22883 - "14: movl 56(%4), %%eax\n"
22884 - "91: movl 60(%4), %%edx\n"
22885 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22886 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22887 " movl %%eax, 56(%3)\n"
22888 " movl %%edx, 60(%3)\n"
22889 " addl $-64, %0\n"
22890 @@ -252,9 +362,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22891 " shrl $2, %0\n"
22892 " andl $3, %%eax\n"
22893 " cld\n"
22894 - "6: rep; movsl\n"
22895 + "6: rep; "__copyuser_seg" movsl\n"
22896 " movl %%eax,%0\n"
22897 - "7: rep; movsb\n"
22898 + "7: rep; "__copyuser_seg" movsb\n"
22899 "8:\n"
22900 ".section .fixup,\"ax\"\n"
22901 "9: lea 0(%%eax,%0,4),%0\n"
22902 @@ -298,47 +408,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22903 */
22904
22905 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22906 + const void __user *from, unsigned long size) __size_overflow(3);
22907 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22908 const void __user *from, unsigned long size)
22909 {
22910 int d0, d1;
22911
22912 __asm__ __volatile__(
22913 " .align 2,0x90\n"
22914 - "0: movl 32(%4), %%eax\n"
22915 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22916 " cmpl $67, %0\n"
22917 " jbe 2f\n"
22918 - "1: movl 64(%4), %%eax\n"
22919 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22920 " .align 2,0x90\n"
22921 - "2: movl 0(%4), %%eax\n"
22922 - "21: movl 4(%4), %%edx\n"
22923 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22924 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22925 " movnti %%eax, 0(%3)\n"
22926 " movnti %%edx, 4(%3)\n"
22927 - "3: movl 8(%4), %%eax\n"
22928 - "31: movl 12(%4),%%edx\n"
22929 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22930 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22931 " movnti %%eax, 8(%3)\n"
22932 " movnti %%edx, 12(%3)\n"
22933 - "4: movl 16(%4), %%eax\n"
22934 - "41: movl 20(%4), %%edx\n"
22935 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22936 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22937 " movnti %%eax, 16(%3)\n"
22938 " movnti %%edx, 20(%3)\n"
22939 - "10: movl 24(%4), %%eax\n"
22940 - "51: movl 28(%4), %%edx\n"
22941 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22942 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22943 " movnti %%eax, 24(%3)\n"
22944 " movnti %%edx, 28(%3)\n"
22945 - "11: movl 32(%4), %%eax\n"
22946 - "61: movl 36(%4), %%edx\n"
22947 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22948 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22949 " movnti %%eax, 32(%3)\n"
22950 " movnti %%edx, 36(%3)\n"
22951 - "12: movl 40(%4), %%eax\n"
22952 - "71: movl 44(%4), %%edx\n"
22953 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22954 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22955 " movnti %%eax, 40(%3)\n"
22956 " movnti %%edx, 44(%3)\n"
22957 - "13: movl 48(%4), %%eax\n"
22958 - "81: movl 52(%4), %%edx\n"
22959 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22960 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22961 " movnti %%eax, 48(%3)\n"
22962 " movnti %%edx, 52(%3)\n"
22963 - "14: movl 56(%4), %%eax\n"
22964 - "91: movl 60(%4), %%edx\n"
22965 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22966 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22967 " movnti %%eax, 56(%3)\n"
22968 " movnti %%edx, 60(%3)\n"
22969 " addl $-64, %0\n"
22970 @@ -351,9 +463,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22971 " shrl $2, %0\n"
22972 " andl $3, %%eax\n"
22973 " cld\n"
22974 - "6: rep; movsl\n"
22975 + "6: rep; "__copyuser_seg" movsl\n"
22976 " movl %%eax,%0\n"
22977 - "7: rep; movsb\n"
22978 + "7: rep; "__copyuser_seg" movsb\n"
22979 "8:\n"
22980 ".section .fixup,\"ax\"\n"
22981 "9: lea 0(%%eax,%0,4),%0\n"
22982 @@ -392,47 +504,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22983 }
22984
22985 static unsigned long __copy_user_intel_nocache(void *to,
22986 + const void __user *from, unsigned long size) __size_overflow(3);
22987 +static unsigned long __copy_user_intel_nocache(void *to,
22988 const void __user *from, unsigned long size)
22989 {
22990 int d0, d1;
22991
22992 __asm__ __volatile__(
22993 " .align 2,0x90\n"
22994 - "0: movl 32(%4), %%eax\n"
22995 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22996 " cmpl $67, %0\n"
22997 " jbe 2f\n"
22998 - "1: movl 64(%4), %%eax\n"
22999 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23000 " .align 2,0x90\n"
23001 - "2: movl 0(%4), %%eax\n"
23002 - "21: movl 4(%4), %%edx\n"
23003 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23004 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23005 " movnti %%eax, 0(%3)\n"
23006 " movnti %%edx, 4(%3)\n"
23007 - "3: movl 8(%4), %%eax\n"
23008 - "31: movl 12(%4),%%edx\n"
23009 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23010 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23011 " movnti %%eax, 8(%3)\n"
23012 " movnti %%edx, 12(%3)\n"
23013 - "4: movl 16(%4), %%eax\n"
23014 - "41: movl 20(%4), %%edx\n"
23015 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23016 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23017 " movnti %%eax, 16(%3)\n"
23018 " movnti %%edx, 20(%3)\n"
23019 - "10: movl 24(%4), %%eax\n"
23020 - "51: movl 28(%4), %%edx\n"
23021 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23022 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23023 " movnti %%eax, 24(%3)\n"
23024 " movnti %%edx, 28(%3)\n"
23025 - "11: movl 32(%4), %%eax\n"
23026 - "61: movl 36(%4), %%edx\n"
23027 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23028 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23029 " movnti %%eax, 32(%3)\n"
23030 " movnti %%edx, 36(%3)\n"
23031 - "12: movl 40(%4), %%eax\n"
23032 - "71: movl 44(%4), %%edx\n"
23033 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23034 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23035 " movnti %%eax, 40(%3)\n"
23036 " movnti %%edx, 44(%3)\n"
23037 - "13: movl 48(%4), %%eax\n"
23038 - "81: movl 52(%4), %%edx\n"
23039 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23040 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23041 " movnti %%eax, 48(%3)\n"
23042 " movnti %%edx, 52(%3)\n"
23043 - "14: movl 56(%4), %%eax\n"
23044 - "91: movl 60(%4), %%edx\n"
23045 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23046 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23047 " movnti %%eax, 56(%3)\n"
23048 " movnti %%edx, 60(%3)\n"
23049 " addl $-64, %0\n"
23050 @@ -445,9 +559,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23051 " shrl $2, %0\n"
23052 " andl $3, %%eax\n"
23053 " cld\n"
23054 - "6: rep; movsl\n"
23055 + "6: rep; "__copyuser_seg" movsl\n"
23056 " movl %%eax,%0\n"
23057 - "7: rep; movsb\n"
23058 + "7: rep; "__copyuser_seg" movsb\n"
23059 "8:\n"
23060 ".section .fixup,\"ax\"\n"
23061 "9: lea 0(%%eax,%0,4),%0\n"
23062 @@ -487,32 +601,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23063 */
23064 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23065 unsigned long size);
23066 -unsigned long __copy_user_intel(void __user *to, const void *from,
23067 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23068 + unsigned long size);
23069 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23070 unsigned long size);
23071 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23072 const void __user *from, unsigned long size);
23073 #endif /* CONFIG_X86_INTEL_USERCOPY */
23074
23075 /* Generic arbitrary sized copy. */
23076 -#define __copy_user(to, from, size) \
23077 +#define __copy_user(to, from, size, prefix, set, restore) \
23078 do { \
23079 int __d0, __d1, __d2; \
23080 __asm__ __volatile__( \
23081 + set \
23082 " cmp $7,%0\n" \
23083 " jbe 1f\n" \
23084 " movl %1,%0\n" \
23085 " negl %0\n" \
23086 " andl $7,%0\n" \
23087 " subl %0,%3\n" \
23088 - "4: rep; movsb\n" \
23089 + "4: rep; "prefix"movsb\n" \
23090 " movl %3,%0\n" \
23091 " shrl $2,%0\n" \
23092 " andl $3,%3\n" \
23093 " .align 2,0x90\n" \
23094 - "0: rep; movsl\n" \
23095 + "0: rep; "prefix"movsl\n" \
23096 " movl %3,%0\n" \
23097 - "1: rep; movsb\n" \
23098 + "1: rep; "prefix"movsb\n" \
23099 "2:\n" \
23100 + restore \
23101 ".section .fixup,\"ax\"\n" \
23102 "5: addl %3,%0\n" \
23103 " jmp 2b\n" \
23104 @@ -537,14 +655,14 @@ do { \
23105 " negl %0\n" \
23106 " andl $7,%0\n" \
23107 " subl %0,%3\n" \
23108 - "4: rep; movsb\n" \
23109 + "4: rep; "__copyuser_seg"movsb\n" \
23110 " movl %3,%0\n" \
23111 " shrl $2,%0\n" \
23112 " andl $3,%3\n" \
23113 " .align 2,0x90\n" \
23114 - "0: rep; movsl\n" \
23115 + "0: rep; "__copyuser_seg"movsl\n" \
23116 " movl %3,%0\n" \
23117 - "1: rep; movsb\n" \
23118 + "1: rep; "__copyuser_seg"movsb\n" \
23119 "2:\n" \
23120 ".section .fixup,\"ax\"\n" \
23121 "5: addl %3,%0\n" \
23122 @@ -627,9 +745,9 @@ survive:
23123 }
23124 #endif
23125 if (movsl_is_ok(to, from, n))
23126 - __copy_user(to, from, n);
23127 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23128 else
23129 - n = __copy_user_intel(to, from, n);
23130 + n = __generic_copy_to_user_intel(to, from, n);
23131 return n;
23132 }
23133 EXPORT_SYMBOL(__copy_to_user_ll);
23134 @@ -649,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23135 unsigned long n)
23136 {
23137 if (movsl_is_ok(to, from, n))
23138 - __copy_user(to, from, n);
23139 + __copy_user(to, from, n, __copyuser_seg, "", "");
23140 else
23141 - n = __copy_user_intel((void __user *)to,
23142 - (const void *)from, n);
23143 + n = __generic_copy_from_user_intel(to, from, n);
23144 return n;
23145 }
23146 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23147 @@ -679,65 +796,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23148 if (n > 64 && cpu_has_xmm2)
23149 n = __copy_user_intel_nocache(to, from, n);
23150 else
23151 - __copy_user(to, from, n);
23152 + __copy_user(to, from, n, __copyuser_seg, "", "");
23153 #else
23154 - __copy_user(to, from, n);
23155 + __copy_user(to, from, n, __copyuser_seg, "", "");
23156 #endif
23157 return n;
23158 }
23159 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23160
23161 -/**
23162 - * copy_to_user: - Copy a block of data into user space.
23163 - * @to: Destination address, in user space.
23164 - * @from: Source address, in kernel space.
23165 - * @n: Number of bytes to copy.
23166 - *
23167 - * Context: User context only. This function may sleep.
23168 - *
23169 - * Copy data from kernel space to user space.
23170 - *
23171 - * Returns number of bytes that could not be copied.
23172 - * On success, this will be zero.
23173 - */
23174 -unsigned long
23175 -copy_to_user(void __user *to, const void *from, unsigned long n)
23176 -{
23177 - if (access_ok(VERIFY_WRITE, to, n))
23178 - n = __copy_to_user(to, from, n);
23179 - return n;
23180 -}
23181 -EXPORT_SYMBOL(copy_to_user);
23182 -
23183 -/**
23184 - * copy_from_user: - Copy a block of data from user space.
23185 - * @to: Destination address, in kernel space.
23186 - * @from: Source address, in user space.
23187 - * @n: Number of bytes to copy.
23188 - *
23189 - * Context: User context only. This function may sleep.
23190 - *
23191 - * Copy data from user space to kernel space.
23192 - *
23193 - * Returns number of bytes that could not be copied.
23194 - * On success, this will be zero.
23195 - *
23196 - * If some data could not be copied, this function will pad the copied
23197 - * data to the requested size using zero bytes.
23198 - */
23199 -unsigned long
23200 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23201 -{
23202 - if (access_ok(VERIFY_READ, from, n))
23203 - n = __copy_from_user(to, from, n);
23204 - else
23205 - memset(to, 0, n);
23206 - return n;
23207 -}
23208 -EXPORT_SYMBOL(_copy_from_user);
23209 -
23210 void copy_from_user_overflow(void)
23211 {
23212 WARN(1, "Buffer overflow detected!\n");
23213 }
23214 EXPORT_SYMBOL(copy_from_user_overflow);
23215 +
23216 +void copy_to_user_overflow(void)
23217 +{
23218 + WARN(1, "Buffer overflow detected!\n");
23219 +}
23220 +EXPORT_SYMBOL(copy_to_user_overflow);
23221 +
23222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23223 +void __set_fs(mm_segment_t x)
23224 +{
23225 + switch (x.seg) {
23226 + case 0:
23227 + loadsegment(gs, 0);
23228 + break;
23229 + case TASK_SIZE_MAX:
23230 + loadsegment(gs, __USER_DS);
23231 + break;
23232 + case -1UL:
23233 + loadsegment(gs, __KERNEL_DS);
23234 + break;
23235 + default:
23236 + BUG();
23237 + }
23238 + return;
23239 +}
23240 +EXPORT_SYMBOL(__set_fs);
23241 +
23242 +void set_fs(mm_segment_t x)
23243 +{
23244 + current_thread_info()->addr_limit = x;
23245 + __set_fs(x);
23246 +}
23247 +EXPORT_SYMBOL(set_fs);
23248 +#endif
23249 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23250 index e5b130b..6690d31 100644
23251 --- a/arch/x86/lib/usercopy_64.c
23252 +++ b/arch/x86/lib/usercopy_64.c
23253 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23254 {
23255 long __d0;
23256 might_fault();
23257 +
23258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23259 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23260 + addr += PAX_USER_SHADOW_BASE;
23261 +#endif
23262 +
23263 /* no memory constraint because it doesn't change any memory gcc knows
23264 about */
23265 asm volatile(
23266 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23267 }
23268 EXPORT_SYMBOL(clear_user);
23269
23270 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23271 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23272 {
23273 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23274 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23275 - }
23276 - return len;
23277 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23278 +
23279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23280 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23281 + to += PAX_USER_SHADOW_BASE;
23282 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23283 + from += PAX_USER_SHADOW_BASE;
23284 +#endif
23285 +
23286 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23287 + }
23288 + return len;
23289 }
23290 EXPORT_SYMBOL(copy_in_user);
23291
23292 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23293 * it is not necessary to optimize tail handling.
23294 */
23295 unsigned long
23296 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23297 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23298 {
23299 char c;
23300 unsigned zero_len;
23301 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23302 break;
23303 return len;
23304 }
23305 +
23306 +void copy_from_user_overflow(void)
23307 +{
23308 + WARN(1, "Buffer overflow detected!\n");
23309 +}
23310 +EXPORT_SYMBOL(copy_from_user_overflow);
23311 +
23312 +void copy_to_user_overflow(void)
23313 +{
23314 + WARN(1, "Buffer overflow detected!\n");
23315 +}
23316 +EXPORT_SYMBOL(copy_to_user_overflow);
23317 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23318 index 903ec1e..833f340 100644
23319 --- a/arch/x86/mm/extable.c
23320 +++ b/arch/x86/mm/extable.c
23321 @@ -6,12 +6,25 @@
23322 static inline unsigned long
23323 ex_insn_addr(const struct exception_table_entry *x)
23324 {
23325 - return (unsigned long)&x->insn + x->insn;
23326 +//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23327 + unsigned long reloc = 0;
23328 +
23329 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23330 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23331 +#endif
23332 +
23333 + return (unsigned long)&x->insn + x->insn + reloc;
23334 }
23335 static inline unsigned long
23336 ex_fixup_addr(const struct exception_table_entry *x)
23337 {
23338 - return (unsigned long)&x->fixup + x->fixup;
23339 + unsigned long reloc = 0;
23340 +
23341 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23342 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23343 +#endif
23344 +
23345 + return (unsigned long)&x->fixup + x->fixup + reloc;
23346 }
23347
23348 int fixup_exception(struct pt_regs *regs)
23349 @@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23350 unsigned long new_ip;
23351
23352 #ifdef CONFIG_PNPBIOS
23353 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23354 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23355 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23356 extern u32 pnp_bios_is_utter_crap;
23357 pnp_bios_is_utter_crap = 1;
23358 @@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23359 #endif
23360
23361 fixup = search_exception_tables(regs->ip);
23362 +//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23363 if (fixup) {
23364 new_ip = ex_fixup_addr(fixup);
23365
23366 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23367 index 76dcd9d..e9dffde 100644
23368 --- a/arch/x86/mm/fault.c
23369 +++ b/arch/x86/mm/fault.c
23370 @@ -13,11 +13,18 @@
23371 #include <linux/perf_event.h> /* perf_sw_event */
23372 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23373 #include <linux/prefetch.h> /* prefetchw */
23374 +#include <linux/unistd.h>
23375 +#include <linux/compiler.h>
23376
23377 #include <asm/traps.h> /* dotraplinkage, ... */
23378 #include <asm/pgalloc.h> /* pgd_*(), ... */
23379 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23380 #include <asm/fixmap.h> /* VSYSCALL_START */
23381 +#include <asm/tlbflush.h>
23382 +
23383 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23384 +#include <asm/stacktrace.h>
23385 +#endif
23386
23387 /*
23388 * Page fault error code bits:
23389 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23390 int ret = 0;
23391
23392 /* kprobe_running() needs smp_processor_id() */
23393 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23394 + if (kprobes_built_in() && !user_mode(regs)) {
23395 preempt_disable();
23396 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23397 ret = 1;
23398 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23399 return !instr_lo || (instr_lo>>1) == 1;
23400 case 0x00:
23401 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23402 - if (probe_kernel_address(instr, opcode))
23403 + if (user_mode(regs)) {
23404 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23405 + return 0;
23406 + } else if (probe_kernel_address(instr, opcode))
23407 return 0;
23408
23409 *prefetch = (instr_lo == 0xF) &&
23410 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23411 while (instr < max_instr) {
23412 unsigned char opcode;
23413
23414 - if (probe_kernel_address(instr, opcode))
23415 + if (user_mode(regs)) {
23416 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23417 + break;
23418 + } else if (probe_kernel_address(instr, opcode))
23419 break;
23420
23421 instr++;
23422 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23423 force_sig_info(si_signo, &info, tsk);
23424 }
23425
23426 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23427 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23428 +#endif
23429 +
23430 +#ifdef CONFIG_PAX_EMUTRAMP
23431 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23432 +#endif
23433 +
23434 +#ifdef CONFIG_PAX_PAGEEXEC
23435 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23436 +{
23437 + pgd_t *pgd;
23438 + pud_t *pud;
23439 + pmd_t *pmd;
23440 +
23441 + pgd = pgd_offset(mm, address);
23442 + if (!pgd_present(*pgd))
23443 + return NULL;
23444 + pud = pud_offset(pgd, address);
23445 + if (!pud_present(*pud))
23446 + return NULL;
23447 + pmd = pmd_offset(pud, address);
23448 + if (!pmd_present(*pmd))
23449 + return NULL;
23450 + return pmd;
23451 +}
23452 +#endif
23453 +
23454 DEFINE_SPINLOCK(pgd_lock);
23455 LIST_HEAD(pgd_list);
23456
23457 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23458 for (address = VMALLOC_START & PMD_MASK;
23459 address >= TASK_SIZE && address < FIXADDR_TOP;
23460 address += PMD_SIZE) {
23461 +
23462 +#ifdef CONFIG_PAX_PER_CPU_PGD
23463 + unsigned long cpu;
23464 +#else
23465 struct page *page;
23466 +#endif
23467
23468 spin_lock(&pgd_lock);
23469 +
23470 +#ifdef CONFIG_PAX_PER_CPU_PGD
23471 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23472 + pgd_t *pgd = get_cpu_pgd(cpu);
23473 + pmd_t *ret;
23474 +#else
23475 list_for_each_entry(page, &pgd_list, lru) {
23476 + pgd_t *pgd = page_address(page);
23477 spinlock_t *pgt_lock;
23478 pmd_t *ret;
23479
23480 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23481 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23482
23483 spin_lock(pgt_lock);
23484 - ret = vmalloc_sync_one(page_address(page), address);
23485 +#endif
23486 +
23487 + ret = vmalloc_sync_one(pgd, address);
23488 +
23489 +#ifndef CONFIG_PAX_PER_CPU_PGD
23490 spin_unlock(pgt_lock);
23491 +#endif
23492
23493 if (!ret)
23494 break;
23495 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23496 * an interrupt in the middle of a task switch..
23497 */
23498 pgd_paddr = read_cr3();
23499 +
23500 +#ifdef CONFIG_PAX_PER_CPU_PGD
23501 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23502 +#endif
23503 +
23504 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23505 if (!pmd_k)
23506 return -1;
23507 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23508 * happen within a race in page table update. In the later
23509 * case just flush:
23510 */
23511 +
23512 +#ifdef CONFIG_PAX_PER_CPU_PGD
23513 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23514 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23515 +#else
23516 pgd = pgd_offset(current->active_mm, address);
23517 +#endif
23518 +
23519 pgd_ref = pgd_offset_k(address);
23520 if (pgd_none(*pgd_ref))
23521 return -1;
23522 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23523 static int is_errata100(struct pt_regs *regs, unsigned long address)
23524 {
23525 #ifdef CONFIG_X86_64
23526 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23527 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23528 return 1;
23529 #endif
23530 return 0;
23531 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23532 }
23533
23534 static const char nx_warning[] = KERN_CRIT
23535 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23536 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23537
23538 static void
23539 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23540 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23541 if (!oops_may_print())
23542 return;
23543
23544 - if (error_code & PF_INSTR) {
23545 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23546 unsigned int level;
23547
23548 pte_t *pte = lookup_address(address, &level);
23549
23550 if (pte && pte_present(*pte) && !pte_exec(*pte))
23551 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23552 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23553 }
23554
23555 +#ifdef CONFIG_PAX_KERNEXEC
23556 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23557 + if (current->signal->curr_ip)
23558 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23559 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23560 + else
23561 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23562 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23563 + }
23564 +#endif
23565 +
23566 printk(KERN_ALERT "BUG: unable to handle kernel ");
23567 if (address < PAGE_SIZE)
23568 printk(KERN_CONT "NULL pointer dereference");
23569 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23570 }
23571 #endif
23572
23573 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23574 + if (pax_is_fetch_fault(regs, error_code, address)) {
23575 +
23576 +#ifdef CONFIG_PAX_EMUTRAMP
23577 + switch (pax_handle_fetch_fault(regs)) {
23578 + case 2:
23579 + return;
23580 + }
23581 +#endif
23582 +
23583 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23584 + do_group_exit(SIGKILL);
23585 + }
23586 +#endif
23587 +
23588 if (unlikely(show_unhandled_signals))
23589 show_signal_msg(regs, error_code, address, tsk);
23590
23591 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23592 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23593 printk(KERN_ERR
23594 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23595 - tsk->comm, tsk->pid, address);
23596 + tsk->comm, task_pid_nr(tsk), address);
23597 code = BUS_MCEERR_AR;
23598 }
23599 #endif
23600 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23601 return 1;
23602 }
23603
23604 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23605 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23606 +{
23607 + pte_t *pte;
23608 + pmd_t *pmd;
23609 + spinlock_t *ptl;
23610 + unsigned char pte_mask;
23611 +
23612 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23613 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23614 + return 0;
23615 +
23616 + /* PaX: it's our fault, let's handle it if we can */
23617 +
23618 + /* PaX: take a look at read faults before acquiring any locks */
23619 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23620 + /* instruction fetch attempt from a protected page in user mode */
23621 + up_read(&mm->mmap_sem);
23622 +
23623 +#ifdef CONFIG_PAX_EMUTRAMP
23624 + switch (pax_handle_fetch_fault(regs)) {
23625 + case 2:
23626 + return 1;
23627 + }
23628 +#endif
23629 +
23630 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23631 + do_group_exit(SIGKILL);
23632 + }
23633 +
23634 + pmd = pax_get_pmd(mm, address);
23635 + if (unlikely(!pmd))
23636 + return 0;
23637 +
23638 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23639 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23640 + pte_unmap_unlock(pte, ptl);
23641 + return 0;
23642 + }
23643 +
23644 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23645 + /* write attempt to a protected page in user mode */
23646 + pte_unmap_unlock(pte, ptl);
23647 + return 0;
23648 + }
23649 +
23650 +#ifdef CONFIG_SMP
23651 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23652 +#else
23653 + if (likely(address > get_limit(regs->cs)))
23654 +#endif
23655 + {
23656 + set_pte(pte, pte_mkread(*pte));
23657 + __flush_tlb_one(address);
23658 + pte_unmap_unlock(pte, ptl);
23659 + up_read(&mm->mmap_sem);
23660 + return 1;
23661 + }
23662 +
23663 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23664 +
23665 + /*
23666 + * PaX: fill DTLB with user rights and retry
23667 + */
23668 + __asm__ __volatile__ (
23669 + "orb %2,(%1)\n"
23670 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23671 +/*
23672 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23673 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23674 + * page fault when examined during a TLB load attempt. this is true not only
23675 + * for PTEs holding a non-present entry but also present entries that will
23676 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23677 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23678 + * for our target pages since their PTEs are simply not in the TLBs at all.
23679 +
23680 + * the best thing in omitting it is that we gain around 15-20% speed in the
23681 + * fast path of the page fault handler and can get rid of tracing since we
23682 + * can no longer flush unintended entries.
23683 + */
23684 + "invlpg (%0)\n"
23685 +#endif
23686 + __copyuser_seg"testb $0,(%0)\n"
23687 + "xorb %3,(%1)\n"
23688 + :
23689 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23690 + : "memory", "cc");
23691 + pte_unmap_unlock(pte, ptl);
23692 + up_read(&mm->mmap_sem);
23693 + return 1;
23694 +}
23695 +#endif
23696 +
23697 /*
23698 * Handle a spurious fault caused by a stale TLB entry.
23699 *
23700 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23701 static inline int
23702 access_error(unsigned long error_code, struct vm_area_struct *vma)
23703 {
23704 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23705 + return 1;
23706 +
23707 if (error_code & PF_WRITE) {
23708 /* write, present and write, not present: */
23709 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23710 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23711 {
23712 struct vm_area_struct *vma;
23713 struct task_struct *tsk;
23714 - unsigned long address;
23715 struct mm_struct *mm;
23716 int fault;
23717 int write = error_code & PF_WRITE;
23718 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23719 (write ? FAULT_FLAG_WRITE : 0);
23720
23721 - tsk = current;
23722 - mm = tsk->mm;
23723 -
23724 /* Get the faulting address: */
23725 - address = read_cr2();
23726 + unsigned long address = read_cr2();
23727 +
23728 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23729 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23730 + if (!search_exception_tables(regs->ip)) {
23731 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23732 + bad_area_nosemaphore(regs, error_code, address);
23733 + return;
23734 + }
23735 + if (address < PAX_USER_SHADOW_BASE) {
23736 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23737 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23738 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23739 + } else
23740 + address -= PAX_USER_SHADOW_BASE;
23741 + }
23742 +#endif
23743 +
23744 + tsk = current;
23745 + mm = tsk->mm;
23746
23747 /*
23748 * Detect and handle instructions that would cause a page fault for
23749 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23750 * User-mode registers count as a user access even for any
23751 * potential system fault or CPU buglet:
23752 */
23753 - if (user_mode_vm(regs)) {
23754 + if (user_mode(regs)) {
23755 local_irq_enable();
23756 error_code |= PF_USER;
23757 } else {
23758 @@ -1132,6 +1339,11 @@ retry:
23759 might_sleep();
23760 }
23761
23762 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23763 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23764 + return;
23765 +#endif
23766 +
23767 vma = find_vma(mm, address);
23768 if (unlikely(!vma)) {
23769 bad_area(regs, error_code, address);
23770 @@ -1143,18 +1355,24 @@ retry:
23771 bad_area(regs, error_code, address);
23772 return;
23773 }
23774 - if (error_code & PF_USER) {
23775 - /*
23776 - * Accessing the stack below %sp is always a bug.
23777 - * The large cushion allows instructions like enter
23778 - * and pusha to work. ("enter $65535, $31" pushes
23779 - * 32 pointers and then decrements %sp by 65535.)
23780 - */
23781 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23782 - bad_area(regs, error_code, address);
23783 - return;
23784 - }
23785 + /*
23786 + * Accessing the stack below %sp is always a bug.
23787 + * The large cushion allows instructions like enter
23788 + * and pusha to work. ("enter $65535, $31" pushes
23789 + * 32 pointers and then decrements %sp by 65535.)
23790 + */
23791 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23792 + bad_area(regs, error_code, address);
23793 + return;
23794 }
23795 +
23796 +#ifdef CONFIG_PAX_SEGMEXEC
23797 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23798 + bad_area(regs, error_code, address);
23799 + return;
23800 + }
23801 +#endif
23802 +
23803 if (unlikely(expand_stack(vma, address))) {
23804 bad_area(regs, error_code, address);
23805 return;
23806 @@ -1209,3 +1427,292 @@ good_area:
23807
23808 up_read(&mm->mmap_sem);
23809 }
23810 +
23811 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23812 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23813 +{
23814 + struct mm_struct *mm = current->mm;
23815 + unsigned long ip = regs->ip;
23816 +
23817 + if (v8086_mode(regs))
23818 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23819 +
23820 +#ifdef CONFIG_PAX_PAGEEXEC
23821 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23822 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23823 + return true;
23824 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23825 + return true;
23826 + return false;
23827 + }
23828 +#endif
23829 +
23830 +#ifdef CONFIG_PAX_SEGMEXEC
23831 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23832 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23833 + return true;
23834 + return false;
23835 + }
23836 +#endif
23837 +
23838 + return false;
23839 +}
23840 +#endif
23841 +
23842 +#ifdef CONFIG_PAX_EMUTRAMP
23843 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23844 +{
23845 + int err;
23846 +
23847 + do { /* PaX: libffi trampoline emulation */
23848 + unsigned char mov, jmp;
23849 + unsigned int addr1, addr2;
23850 +
23851 +#ifdef CONFIG_X86_64
23852 + if ((regs->ip + 9) >> 32)
23853 + break;
23854 +#endif
23855 +
23856 + err = get_user(mov, (unsigned char __user *)regs->ip);
23857 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23858 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23859 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23860 +
23861 + if (err)
23862 + break;
23863 +
23864 + if (mov == 0xB8 && jmp == 0xE9) {
23865 + regs->ax = addr1;
23866 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23867 + return 2;
23868 + }
23869 + } while (0);
23870 +
23871 + do { /* PaX: gcc trampoline emulation #1 */
23872 + unsigned char mov1, mov2;
23873 + unsigned short jmp;
23874 + unsigned int addr1, addr2;
23875 +
23876 +#ifdef CONFIG_X86_64
23877 + if ((regs->ip + 11) >> 32)
23878 + break;
23879 +#endif
23880 +
23881 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23882 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23883 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23884 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23885 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23886 +
23887 + if (err)
23888 + break;
23889 +
23890 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23891 + regs->cx = addr1;
23892 + regs->ax = addr2;
23893 + regs->ip = addr2;
23894 + return 2;
23895 + }
23896 + } while (0);
23897 +
23898 + do { /* PaX: gcc trampoline emulation #2 */
23899 + unsigned char mov, jmp;
23900 + unsigned int addr1, addr2;
23901 +
23902 +#ifdef CONFIG_X86_64
23903 + if ((regs->ip + 9) >> 32)
23904 + break;
23905 +#endif
23906 +
23907 + err = get_user(mov, (unsigned char __user *)regs->ip);
23908 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23909 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23910 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23911 +
23912 + if (err)
23913 + break;
23914 +
23915 + if (mov == 0xB9 && jmp == 0xE9) {
23916 + regs->cx = addr1;
23917 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23918 + return 2;
23919 + }
23920 + } while (0);
23921 +
23922 + return 1; /* PaX in action */
23923 +}
23924 +
23925 +#ifdef CONFIG_X86_64
23926 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23927 +{
23928 + int err;
23929 +
23930 + do { /* PaX: libffi trampoline emulation */
23931 + unsigned short mov1, mov2, jmp1;
23932 + unsigned char stcclc, jmp2;
23933 + unsigned long addr1, addr2;
23934 +
23935 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23936 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23937 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23938 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23939 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23940 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23941 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23942 +
23943 + if (err)
23944 + break;
23945 +
23946 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23947 + regs->r11 = addr1;
23948 + regs->r10 = addr2;
23949 + if (stcclc == 0xF8)
23950 + regs->flags &= ~X86_EFLAGS_CF;
23951 + else
23952 + regs->flags |= X86_EFLAGS_CF;
23953 + regs->ip = addr1;
23954 + return 2;
23955 + }
23956 + } while (0);
23957 +
23958 + do { /* PaX: gcc trampoline emulation #1 */
23959 + unsigned short mov1, mov2, jmp1;
23960 + unsigned char jmp2;
23961 + unsigned int addr1;
23962 + unsigned long addr2;
23963 +
23964 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23965 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23966 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23967 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23968 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23969 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23970 +
23971 + if (err)
23972 + break;
23973 +
23974 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23975 + regs->r11 = addr1;
23976 + regs->r10 = addr2;
23977 + regs->ip = addr1;
23978 + return 2;
23979 + }
23980 + } while (0);
23981 +
23982 + do { /* PaX: gcc trampoline emulation #2 */
23983 + unsigned short mov1, mov2, jmp1;
23984 + unsigned char jmp2;
23985 + unsigned long addr1, addr2;
23986 +
23987 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23988 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23989 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23990 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23991 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23992 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23993 +
23994 + if (err)
23995 + break;
23996 +
23997 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23998 + regs->r11 = addr1;
23999 + regs->r10 = addr2;
24000 + regs->ip = addr1;
24001 + return 2;
24002 + }
24003 + } while (0);
24004 +
24005 + return 1; /* PaX in action */
24006 +}
24007 +#endif
24008 +
24009 +/*
24010 + * PaX: decide what to do with offenders (regs->ip = fault address)
24011 + *
24012 + * returns 1 when task should be killed
24013 + * 2 when gcc trampoline was detected
24014 + */
24015 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24016 +{
24017 + if (v8086_mode(regs))
24018 + return 1;
24019 +
24020 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24021 + return 1;
24022 +
24023 +#ifdef CONFIG_X86_32
24024 + return pax_handle_fetch_fault_32(regs);
24025 +#else
24026 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24027 + return pax_handle_fetch_fault_32(regs);
24028 + else
24029 + return pax_handle_fetch_fault_64(regs);
24030 +#endif
24031 +}
24032 +#endif
24033 +
24034 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24035 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24036 +{
24037 + long i;
24038 +
24039 + printk(KERN_ERR "PAX: bytes at PC: ");
24040 + for (i = 0; i < 20; i++) {
24041 + unsigned char c;
24042 + if (get_user(c, (unsigned char __force_user *)pc+i))
24043 + printk(KERN_CONT "?? ");
24044 + else
24045 + printk(KERN_CONT "%02x ", c);
24046 + }
24047 + printk("\n");
24048 +
24049 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24050 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24051 + unsigned long c;
24052 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24053 +#ifdef CONFIG_X86_32
24054 + printk(KERN_CONT "???????? ");
24055 +#else
24056 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24057 + printk(KERN_CONT "???????? ???????? ");
24058 + else
24059 + printk(KERN_CONT "???????????????? ");
24060 +#endif
24061 + } else {
24062 +#ifdef CONFIG_X86_64
24063 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24064 + printk(KERN_CONT "%08x ", (unsigned int)c);
24065 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24066 + } else
24067 +#endif
24068 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24069 + }
24070 + }
24071 + printk("\n");
24072 +}
24073 +#endif
24074 +
24075 +/**
24076 + * probe_kernel_write(): safely attempt to write to a location
24077 + * @dst: address to write to
24078 + * @src: pointer to the data that shall be written
24079 + * @size: size of the data chunk
24080 + *
24081 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24082 + * happens, handle that and return -EFAULT.
24083 + */
24084 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24085 +{
24086 + long ret;
24087 + mm_segment_t old_fs = get_fs();
24088 +
24089 + set_fs(KERNEL_DS);
24090 + pagefault_disable();
24091 + pax_open_kernel();
24092 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24093 + pax_close_kernel();
24094 + pagefault_enable();
24095 + set_fs(old_fs);
24096 +
24097 + return ret ? -EFAULT : 0;
24098 +}
24099 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24100 index dd74e46..7d26398 100644
24101 --- a/arch/x86/mm/gup.c
24102 +++ b/arch/x86/mm/gup.c
24103 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24104 addr = start;
24105 len = (unsigned long) nr_pages << PAGE_SHIFT;
24106 end = start + len;
24107 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24108 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24109 (void __user *)start, len)))
24110 return 0;
24111
24112 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24113 index 6f31ee5..8ee4164 100644
24114 --- a/arch/x86/mm/highmem_32.c
24115 +++ b/arch/x86/mm/highmem_32.c
24116 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24117 idx = type + KM_TYPE_NR*smp_processor_id();
24118 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24119 BUG_ON(!pte_none(*(kmap_pte-idx)));
24120 +
24121 + pax_open_kernel();
24122 set_pte(kmap_pte-idx, mk_pte(page, prot));
24123 + pax_close_kernel();
24124 +
24125 arch_flush_lazy_mmu_mode();
24126
24127 return (void *)vaddr;
24128 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24129 index f6679a7..8f795a3 100644
24130 --- a/arch/x86/mm/hugetlbpage.c
24131 +++ b/arch/x86/mm/hugetlbpage.c
24132 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24133 struct hstate *h = hstate_file(file);
24134 struct mm_struct *mm = current->mm;
24135 struct vm_area_struct *vma;
24136 - unsigned long start_addr;
24137 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24138 +
24139 +#ifdef CONFIG_PAX_SEGMEXEC
24140 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24141 + pax_task_size = SEGMEXEC_TASK_SIZE;
24142 +#endif
24143 +
24144 + pax_task_size -= PAGE_SIZE;
24145
24146 if (len > mm->cached_hole_size) {
24147 - start_addr = mm->free_area_cache;
24148 + start_addr = mm->free_area_cache;
24149 } else {
24150 - start_addr = TASK_UNMAPPED_BASE;
24151 - mm->cached_hole_size = 0;
24152 + start_addr = mm->mmap_base;
24153 + mm->cached_hole_size = 0;
24154 }
24155
24156 full_search:
24157 @@ -280,26 +287,27 @@ full_search:
24158
24159 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24160 /* At this point: (!vma || addr < vma->vm_end). */
24161 - if (TASK_SIZE - len < addr) {
24162 + if (pax_task_size - len < addr) {
24163 /*
24164 * Start a new search - just in case we missed
24165 * some holes.
24166 */
24167 - if (start_addr != TASK_UNMAPPED_BASE) {
24168 - start_addr = TASK_UNMAPPED_BASE;
24169 + if (start_addr != mm->mmap_base) {
24170 + start_addr = mm->mmap_base;
24171 mm->cached_hole_size = 0;
24172 goto full_search;
24173 }
24174 return -ENOMEM;
24175 }
24176 - if (!vma || addr + len <= vma->vm_start) {
24177 - mm->free_area_cache = addr + len;
24178 - return addr;
24179 - }
24180 + if (check_heap_stack_gap(vma, addr, len))
24181 + break;
24182 if (addr + mm->cached_hole_size < vma->vm_start)
24183 mm->cached_hole_size = vma->vm_start - addr;
24184 addr = ALIGN(vma->vm_end, huge_page_size(h));
24185 }
24186 +
24187 + mm->free_area_cache = addr + len;
24188 + return addr;
24189 }
24190
24191 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24192 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24193 struct mm_struct *mm = current->mm;
24194 struct vm_area_struct *vma;
24195 unsigned long base = mm->mmap_base;
24196 - unsigned long addr = addr0;
24197 + unsigned long addr;
24198 unsigned long largest_hole = mm->cached_hole_size;
24199 - unsigned long start_addr;
24200
24201 /* don't allow allocations above current base */
24202 if (mm->free_area_cache > base)
24203 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24204 largest_hole = 0;
24205 mm->free_area_cache = base;
24206 }
24207 -try_again:
24208 - start_addr = mm->free_area_cache;
24209
24210 /* make sure it can fit in the remaining address space */
24211 if (mm->free_area_cache < len)
24212 goto fail;
24213
24214 /* either no address requested or can't fit in requested address hole */
24215 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24216 + addr = mm->free_area_cache - len;
24217 do {
24218 + addr &= huge_page_mask(h);
24219 /*
24220 * Lookup failure means no vma is above this address,
24221 * i.e. return with success:
24222 @@ -340,10 +346,10 @@ try_again:
24223 if (!vma)
24224 return addr;
24225
24226 - if (addr + len <= vma->vm_start) {
24227 + if (check_heap_stack_gap(vma, addr, len)) {
24228 /* remember the address as a hint for next time */
24229 - mm->cached_hole_size = largest_hole;
24230 - return (mm->free_area_cache = addr);
24231 + mm->cached_hole_size = largest_hole;
24232 + return (mm->free_area_cache = addr);
24233 } else if (mm->free_area_cache == vma->vm_end) {
24234 /* pull free_area_cache down to the first hole */
24235 mm->free_area_cache = vma->vm_start;
24236 @@ -352,29 +358,34 @@ try_again:
24237
24238 /* remember the largest hole we saw so far */
24239 if (addr + largest_hole < vma->vm_start)
24240 - largest_hole = vma->vm_start - addr;
24241 + largest_hole = vma->vm_start - addr;
24242
24243 /* try just below the current vma->vm_start */
24244 - addr = (vma->vm_start - len) & huge_page_mask(h);
24245 - } while (len <= vma->vm_start);
24246 + addr = skip_heap_stack_gap(vma, len);
24247 + } while (!IS_ERR_VALUE(addr));
24248
24249 fail:
24250 /*
24251 - * if hint left us with no space for the requested
24252 - * mapping then try again:
24253 - */
24254 - if (start_addr != base) {
24255 - mm->free_area_cache = base;
24256 - largest_hole = 0;
24257 - goto try_again;
24258 - }
24259 - /*
24260 * A failed mmap() very likely causes application failure,
24261 * so fall back to the bottom-up function here. This scenario
24262 * can happen with large stack limits and large mmap()
24263 * allocations.
24264 */
24265 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24266 +
24267 +#ifdef CONFIG_PAX_SEGMEXEC
24268 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24269 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24270 + else
24271 +#endif
24272 +
24273 + mm->mmap_base = TASK_UNMAPPED_BASE;
24274 +
24275 +#ifdef CONFIG_PAX_RANDMMAP
24276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24277 + mm->mmap_base += mm->delta_mmap;
24278 +#endif
24279 +
24280 + mm->free_area_cache = mm->mmap_base;
24281 mm->cached_hole_size = ~0UL;
24282 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24283 len, pgoff, flags);
24284 @@ -382,6 +393,7 @@ fail:
24285 /*
24286 * Restore the topdown base:
24287 */
24288 + mm->mmap_base = base;
24289 mm->free_area_cache = base;
24290 mm->cached_hole_size = ~0UL;
24291
24292 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24293 struct hstate *h = hstate_file(file);
24294 struct mm_struct *mm = current->mm;
24295 struct vm_area_struct *vma;
24296 + unsigned long pax_task_size = TASK_SIZE;
24297
24298 if (len & ~huge_page_mask(h))
24299 return -EINVAL;
24300 - if (len > TASK_SIZE)
24301 +
24302 +#ifdef CONFIG_PAX_SEGMEXEC
24303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24304 + pax_task_size = SEGMEXEC_TASK_SIZE;
24305 +#endif
24306 +
24307 + pax_task_size -= PAGE_SIZE;
24308 +
24309 + if (len > pax_task_size)
24310 return -ENOMEM;
24311
24312 if (flags & MAP_FIXED) {
24313 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24314 if (addr) {
24315 addr = ALIGN(addr, huge_page_size(h));
24316 vma = find_vma(mm, addr);
24317 - if (TASK_SIZE - len >= addr &&
24318 - (!vma || addr + len <= vma->vm_start))
24319 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24320 return addr;
24321 }
24322 if (mm->get_unmapped_area == arch_get_unmapped_area)
24323 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24324 index bc4e9d8..ca4c14b 100644
24325 --- a/arch/x86/mm/init.c
24326 +++ b/arch/x86/mm/init.c
24327 @@ -16,6 +16,8 @@
24328 #include <asm/tlb.h>
24329 #include <asm/proto.h>
24330 #include <asm/dma.h> /* for MAX_DMA_PFN */
24331 +#include <asm/desc.h>
24332 +#include <asm/bios_ebda.h>
24333
24334 unsigned long __initdata pgt_buf_start;
24335 unsigned long __meminitdata pgt_buf_end;
24336 @@ -38,7 +40,7 @@ struct map_range {
24337 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24338 int use_pse, int use_gbpages)
24339 {
24340 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24341 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24342 phys_addr_t base;
24343
24344 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24345 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24346 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24347 * mmio resources as well as potential bios/acpi data regions.
24348 */
24349 +
24350 +#ifdef CONFIG_GRKERNSEC_KMEM
24351 +static unsigned int ebda_start __read_only;
24352 +static unsigned int ebda_end __read_only;
24353 +#endif
24354 +
24355 int devmem_is_allowed(unsigned long pagenr)
24356 {
24357 +#ifdef CONFIG_GRKERNSEC_KMEM
24358 + /* allow BDA */
24359 + if (!pagenr)
24360 + return 1;
24361 + /* allow EBDA */
24362 + if (pagenr >= ebda_start && pagenr < ebda_end)
24363 + return 1;
24364 +#else
24365 + if (!pagenr)
24366 + return 1;
24367 +#ifdef CONFIG_VM86
24368 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24369 + return 1;
24370 +#endif
24371 +#endif
24372 +
24373 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24374 + return 1;
24375 +#ifdef CONFIG_GRKERNSEC_KMEM
24376 + /* throw out everything else below 1MB */
24377 if (pagenr <= 256)
24378 - return 1;
24379 + return 0;
24380 +#endif
24381 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24382 return 0;
24383 if (!page_is_ram(pagenr))
24384 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24385 #endif
24386 }
24387
24388 +#ifdef CONFIG_GRKERNSEC_KMEM
24389 +static inline void gr_init_ebda(void)
24390 +{
24391 + unsigned int ebda_addr;
24392 + unsigned int ebda_size = 0;
24393 +
24394 + ebda_addr = get_bios_ebda();
24395 + if (ebda_addr) {
24396 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24397 + ebda_size <<= 10;
24398 + }
24399 + if (ebda_addr && ebda_size) {
24400 + ebda_start = ebda_addr >> PAGE_SHIFT;
24401 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24402 + } else {
24403 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24404 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24405 + }
24406 +}
24407 +#else
24408 +static inline void gr_init_ebda(void) { }
24409 +#endif
24410 +
24411 void free_initmem(void)
24412 {
24413 +#ifdef CONFIG_PAX_KERNEXEC
24414 +#ifdef CONFIG_X86_32
24415 + /* PaX: limit KERNEL_CS to actual size */
24416 + unsigned long addr, limit;
24417 + struct desc_struct d;
24418 + int cpu;
24419 +#else
24420 + pgd_t *pgd;
24421 + pud_t *pud;
24422 + pmd_t *pmd;
24423 + unsigned long addr, end;
24424 +#endif
24425 +#endif
24426 +
24427 + gr_init_ebda();
24428 +
24429 +#ifdef CONFIG_PAX_KERNEXEC
24430 +#ifdef CONFIG_X86_32
24431 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24432 + limit = (limit - 1UL) >> PAGE_SHIFT;
24433 +
24434 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24435 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24436 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24437 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24438 + }
24439 +
24440 + /* PaX: make KERNEL_CS read-only */
24441 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24442 + if (!paravirt_enabled())
24443 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24444 +/*
24445 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24446 + pgd = pgd_offset_k(addr);
24447 + pud = pud_offset(pgd, addr);
24448 + pmd = pmd_offset(pud, addr);
24449 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24450 + }
24451 +*/
24452 +#ifdef CONFIG_X86_PAE
24453 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24454 +/*
24455 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24456 + pgd = pgd_offset_k(addr);
24457 + pud = pud_offset(pgd, addr);
24458 + pmd = pmd_offset(pud, addr);
24459 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24460 + }
24461 +*/
24462 +#endif
24463 +
24464 +#ifdef CONFIG_MODULES
24465 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24466 +#endif
24467 +
24468 +#else
24469 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24470 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24471 + pgd = pgd_offset_k(addr);
24472 + pud = pud_offset(pgd, addr);
24473 + pmd = pmd_offset(pud, addr);
24474 + if (!pmd_present(*pmd))
24475 + continue;
24476 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24477 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24478 + else
24479 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24480 + }
24481 +
24482 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24483 + end = addr + KERNEL_IMAGE_SIZE;
24484 + for (; addr < end; addr += PMD_SIZE) {
24485 + pgd = pgd_offset_k(addr);
24486 + pud = pud_offset(pgd, addr);
24487 + pmd = pmd_offset(pud, addr);
24488 + if (!pmd_present(*pmd))
24489 + continue;
24490 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24491 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24492 + }
24493 +#endif
24494 +
24495 + flush_tlb_all();
24496 +#endif
24497 +
24498 free_init_pages("unused kernel memory",
24499 (unsigned long)(&__init_begin),
24500 (unsigned long)(&__init_end));
24501 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24502 index 575d86f..4987469 100644
24503 --- a/arch/x86/mm/init_32.c
24504 +++ b/arch/x86/mm/init_32.c
24505 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24506 }
24507
24508 /*
24509 - * Creates a middle page table and puts a pointer to it in the
24510 - * given global directory entry. This only returns the gd entry
24511 - * in non-PAE compilation mode, since the middle layer is folded.
24512 - */
24513 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24514 -{
24515 - pud_t *pud;
24516 - pmd_t *pmd_table;
24517 -
24518 -#ifdef CONFIG_X86_PAE
24519 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24520 - if (after_bootmem)
24521 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24522 - else
24523 - pmd_table = (pmd_t *)alloc_low_page();
24524 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24525 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24526 - pud = pud_offset(pgd, 0);
24527 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24528 -
24529 - return pmd_table;
24530 - }
24531 -#endif
24532 - pud = pud_offset(pgd, 0);
24533 - pmd_table = pmd_offset(pud, 0);
24534 -
24535 - return pmd_table;
24536 -}
24537 -
24538 -/*
24539 * Create a page table and place a pointer to it in a middle page
24540 * directory entry:
24541 */
24542 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24543 page_table = (pte_t *)alloc_low_page();
24544
24545 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24546 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24547 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24548 +#else
24549 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24550 +#endif
24551 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24552 }
24553
24554 return pte_offset_kernel(pmd, 0);
24555 }
24556
24557 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24558 +{
24559 + pud_t *pud;
24560 + pmd_t *pmd_table;
24561 +
24562 + pud = pud_offset(pgd, 0);
24563 + pmd_table = pmd_offset(pud, 0);
24564 +
24565 + return pmd_table;
24566 +}
24567 +
24568 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24569 {
24570 int pgd_idx = pgd_index(vaddr);
24571 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24572 int pgd_idx, pmd_idx;
24573 unsigned long vaddr;
24574 pgd_t *pgd;
24575 + pud_t *pud;
24576 pmd_t *pmd;
24577 pte_t *pte = NULL;
24578
24579 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24580 pgd = pgd_base + pgd_idx;
24581
24582 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24583 - pmd = one_md_table_init(pgd);
24584 - pmd = pmd + pmd_index(vaddr);
24585 + pud = pud_offset(pgd, vaddr);
24586 + pmd = pmd_offset(pud, vaddr);
24587 +
24588 +#ifdef CONFIG_X86_PAE
24589 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24590 +#endif
24591 +
24592 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24593 pmd++, pmd_idx++) {
24594 pte = page_table_kmap_check(one_page_table_init(pmd),
24595 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24596 }
24597 }
24598
24599 -static inline int is_kernel_text(unsigned long addr)
24600 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24601 {
24602 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24603 - return 1;
24604 - return 0;
24605 + if ((start > ktla_ktva((unsigned long)_etext) ||
24606 + end <= ktla_ktva((unsigned long)_stext)) &&
24607 + (start > ktla_ktva((unsigned long)_einittext) ||
24608 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24609 +
24610 +#ifdef CONFIG_ACPI_SLEEP
24611 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24612 +#endif
24613 +
24614 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24615 + return 0;
24616 + return 1;
24617 }
24618
24619 /*
24620 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24621 unsigned long last_map_addr = end;
24622 unsigned long start_pfn, end_pfn;
24623 pgd_t *pgd_base = swapper_pg_dir;
24624 - int pgd_idx, pmd_idx, pte_ofs;
24625 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24626 unsigned long pfn;
24627 pgd_t *pgd;
24628 + pud_t *pud;
24629 pmd_t *pmd;
24630 pte_t *pte;
24631 unsigned pages_2m, pages_4k;
24632 @@ -280,8 +281,13 @@ repeat:
24633 pfn = start_pfn;
24634 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24635 pgd = pgd_base + pgd_idx;
24636 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24637 - pmd = one_md_table_init(pgd);
24638 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24639 + pud = pud_offset(pgd, 0);
24640 + pmd = pmd_offset(pud, 0);
24641 +
24642 +#ifdef CONFIG_X86_PAE
24643 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24644 +#endif
24645
24646 if (pfn >= end_pfn)
24647 continue;
24648 @@ -293,14 +299,13 @@ repeat:
24649 #endif
24650 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24651 pmd++, pmd_idx++) {
24652 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24653 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24654
24655 /*
24656 * Map with big pages if possible, otherwise
24657 * create normal page tables:
24658 */
24659 if (use_pse) {
24660 - unsigned int addr2;
24661 pgprot_t prot = PAGE_KERNEL_LARGE;
24662 /*
24663 * first pass will use the same initial
24664 @@ -310,11 +315,7 @@ repeat:
24665 __pgprot(PTE_IDENT_ATTR |
24666 _PAGE_PSE);
24667
24668 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24669 - PAGE_OFFSET + PAGE_SIZE-1;
24670 -
24671 - if (is_kernel_text(addr) ||
24672 - is_kernel_text(addr2))
24673 + if (is_kernel_text(address, address + PMD_SIZE))
24674 prot = PAGE_KERNEL_LARGE_EXEC;
24675
24676 pages_2m++;
24677 @@ -331,7 +332,7 @@ repeat:
24678 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24679 pte += pte_ofs;
24680 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24681 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24682 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24683 pgprot_t prot = PAGE_KERNEL;
24684 /*
24685 * first pass will use the same initial
24686 @@ -339,7 +340,7 @@ repeat:
24687 */
24688 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24689
24690 - if (is_kernel_text(addr))
24691 + if (is_kernel_text(address, address + PAGE_SIZE))
24692 prot = PAGE_KERNEL_EXEC;
24693
24694 pages_4k++;
24695 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24696
24697 pud = pud_offset(pgd, va);
24698 pmd = pmd_offset(pud, va);
24699 - if (!pmd_present(*pmd))
24700 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24701 break;
24702
24703 pte = pte_offset_kernel(pmd, va);
24704 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24705
24706 static void __init pagetable_init(void)
24707 {
24708 - pgd_t *pgd_base = swapper_pg_dir;
24709 -
24710 - permanent_kmaps_init(pgd_base);
24711 + permanent_kmaps_init(swapper_pg_dir);
24712 }
24713
24714 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24715 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24716 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24717
24718 /* user-defined highmem size */
24719 @@ -734,6 +733,12 @@ void __init mem_init(void)
24720
24721 pci_iommu_alloc();
24722
24723 +#ifdef CONFIG_PAX_PER_CPU_PGD
24724 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24725 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24726 + KERNEL_PGD_PTRS);
24727 +#endif
24728 +
24729 #ifdef CONFIG_FLATMEM
24730 BUG_ON(!mem_map);
24731 #endif
24732 @@ -760,7 +765,7 @@ void __init mem_init(void)
24733 reservedpages++;
24734
24735 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24736 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24737 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24738 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24739
24740 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24741 @@ -801,10 +806,10 @@ void __init mem_init(void)
24742 ((unsigned long)&__init_end -
24743 (unsigned long)&__init_begin) >> 10,
24744
24745 - (unsigned long)&_etext, (unsigned long)&_edata,
24746 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24747 + (unsigned long)&_sdata, (unsigned long)&_edata,
24748 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24749
24750 - (unsigned long)&_text, (unsigned long)&_etext,
24751 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24752 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24753
24754 /*
24755 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24756 if (!kernel_set_to_readonly)
24757 return;
24758
24759 + start = ktla_ktva(start);
24760 pr_debug("Set kernel text: %lx - %lx for read write\n",
24761 start, start+size);
24762
24763 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24764 if (!kernel_set_to_readonly)
24765 return;
24766
24767 + start = ktla_ktva(start);
24768 pr_debug("Set kernel text: %lx - %lx for read only\n",
24769 start, start+size);
24770
24771 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24772 unsigned long start = PFN_ALIGN(_text);
24773 unsigned long size = PFN_ALIGN(_etext) - start;
24774
24775 + start = ktla_ktva(start);
24776 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24777 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24778 size >> 10);
24779 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24780 index 2b6b4a3..c17210d 100644
24781 --- a/arch/x86/mm/init_64.c
24782 +++ b/arch/x86/mm/init_64.c
24783 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24784 * around without checking the pgd every time.
24785 */
24786
24787 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24788 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24789 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24790
24791 int force_personality32;
24792 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24793
24794 for (address = start; address <= end; address += PGDIR_SIZE) {
24795 const pgd_t *pgd_ref = pgd_offset_k(address);
24796 +
24797 +#ifdef CONFIG_PAX_PER_CPU_PGD
24798 + unsigned long cpu;
24799 +#else
24800 struct page *page;
24801 +#endif
24802
24803 if (pgd_none(*pgd_ref))
24804 continue;
24805
24806 spin_lock(&pgd_lock);
24807 +
24808 +#ifdef CONFIG_PAX_PER_CPU_PGD
24809 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24810 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24811 +#else
24812 list_for_each_entry(page, &pgd_list, lru) {
24813 pgd_t *pgd;
24814 spinlock_t *pgt_lock;
24815 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24816 /* the pgt_lock only for Xen */
24817 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24818 spin_lock(pgt_lock);
24819 +#endif
24820
24821 if (pgd_none(*pgd))
24822 set_pgd(pgd, *pgd_ref);
24823 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24824 BUG_ON(pgd_page_vaddr(*pgd)
24825 != pgd_page_vaddr(*pgd_ref));
24826
24827 +#ifndef CONFIG_PAX_PER_CPU_PGD
24828 spin_unlock(pgt_lock);
24829 +#endif
24830 +
24831 }
24832 spin_unlock(&pgd_lock);
24833 }
24834 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24835 {
24836 if (pgd_none(*pgd)) {
24837 pud_t *pud = (pud_t *)spp_getpage();
24838 - pgd_populate(&init_mm, pgd, pud);
24839 + pgd_populate_kernel(&init_mm, pgd, pud);
24840 if (pud != pud_offset(pgd, 0))
24841 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24842 pud, pud_offset(pgd, 0));
24843 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24844 {
24845 if (pud_none(*pud)) {
24846 pmd_t *pmd = (pmd_t *) spp_getpage();
24847 - pud_populate(&init_mm, pud, pmd);
24848 + pud_populate_kernel(&init_mm, pud, pmd);
24849 if (pmd != pmd_offset(pud, 0))
24850 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24851 pmd, pmd_offset(pud, 0));
24852 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24853 pmd = fill_pmd(pud, vaddr);
24854 pte = fill_pte(pmd, vaddr);
24855
24856 + pax_open_kernel();
24857 set_pte(pte, new_pte);
24858 + pax_close_kernel();
24859
24860 /*
24861 * It's enough to flush this one mapping.
24862 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24863 pgd = pgd_offset_k((unsigned long)__va(phys));
24864 if (pgd_none(*pgd)) {
24865 pud = (pud_t *) spp_getpage();
24866 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24867 - _PAGE_USER));
24868 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24869 }
24870 pud = pud_offset(pgd, (unsigned long)__va(phys));
24871 if (pud_none(*pud)) {
24872 pmd = (pmd_t *) spp_getpage();
24873 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24874 - _PAGE_USER));
24875 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24876 }
24877 pmd = pmd_offset(pud, phys);
24878 BUG_ON(!pmd_none(*pmd));
24879 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24880 if (pfn >= pgt_buf_top)
24881 panic("alloc_low_page: ran out of memory");
24882
24883 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24884 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24885 clear_page(adr);
24886 *phys = pfn * PAGE_SIZE;
24887 return adr;
24888 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24889
24890 phys = __pa(virt);
24891 left = phys & (PAGE_SIZE - 1);
24892 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24893 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24894 adr = (void *)(((unsigned long)adr) | left);
24895
24896 return adr;
24897 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24898 unmap_low_page(pmd);
24899
24900 spin_lock(&init_mm.page_table_lock);
24901 - pud_populate(&init_mm, pud, __va(pmd_phys));
24902 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24903 spin_unlock(&init_mm.page_table_lock);
24904 }
24905 __flush_tlb_all();
24906 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24907 unmap_low_page(pud);
24908
24909 spin_lock(&init_mm.page_table_lock);
24910 - pgd_populate(&init_mm, pgd, __va(pud_phys));
24911 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24912 spin_unlock(&init_mm.page_table_lock);
24913 pgd_changed = true;
24914 }
24915 @@ -686,6 +700,12 @@ void __init mem_init(void)
24916
24917 pci_iommu_alloc();
24918
24919 +#ifdef CONFIG_PAX_PER_CPU_PGD
24920 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24921 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24922 + KERNEL_PGD_PTRS);
24923 +#endif
24924 +
24925 /* clear_bss() already clear the empty_zero_page */
24926
24927 reservedpages = 0;
24928 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24929 static struct vm_area_struct gate_vma = {
24930 .vm_start = VSYSCALL_START,
24931 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24932 - .vm_page_prot = PAGE_READONLY_EXEC,
24933 - .vm_flags = VM_READ | VM_EXEC
24934 + .vm_page_prot = PAGE_READONLY,
24935 + .vm_flags = VM_READ
24936 };
24937
24938 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24939 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24940
24941 const char *arch_vma_name(struct vm_area_struct *vma)
24942 {
24943 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24944 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24945 return "[vdso]";
24946 if (vma == &gate_vma)
24947 return "[vsyscall]";
24948 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24949 index 7b179b4..6bd1777 100644
24950 --- a/arch/x86/mm/iomap_32.c
24951 +++ b/arch/x86/mm/iomap_32.c
24952 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24953 type = kmap_atomic_idx_push();
24954 idx = type + KM_TYPE_NR * smp_processor_id();
24955 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24956 +
24957 + pax_open_kernel();
24958 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24959 + pax_close_kernel();
24960 +
24961 arch_flush_lazy_mmu_mode();
24962
24963 return (void *)vaddr;
24964 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24965 index 78fe3f1..8293b6f 100644
24966 --- a/arch/x86/mm/ioremap.c
24967 +++ b/arch/x86/mm/ioremap.c
24968 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24969 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24970 int is_ram = page_is_ram(pfn);
24971
24972 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24973 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24974 return NULL;
24975 WARN_ON_ONCE(is_ram);
24976 }
24977 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24978
24979 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24980 if (page_is_ram(start >> PAGE_SHIFT))
24981 +#ifdef CONFIG_HIGHMEM
24982 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24983 +#endif
24984 return __va(phys);
24985
24986 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24987 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24988 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24989
24990 static __initdata int after_paging_init;
24991 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24992 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24993
24994 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24995 {
24996 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24997 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24998
24999 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25000 - memset(bm_pte, 0, sizeof(bm_pte));
25001 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25002 + pmd_populate_user(&init_mm, pmd, bm_pte);
25003
25004 /*
25005 * The boot-ioremap range spans multiple pmds, for which
25006 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25007 index d87dd6d..bf3fa66 100644
25008 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25009 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25010 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25011 * memory (e.g. tracked pages)? For now, we need this to avoid
25012 * invoking kmemcheck for PnP BIOS calls.
25013 */
25014 - if (regs->flags & X86_VM_MASK)
25015 + if (v8086_mode(regs))
25016 return false;
25017 - if (regs->cs != __KERNEL_CS)
25018 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25019 return false;
25020
25021 pte = kmemcheck_pte_lookup(address);
25022 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25023 index 845df68..1d8d29f 100644
25024 --- a/arch/x86/mm/mmap.c
25025 +++ b/arch/x86/mm/mmap.c
25026 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25027 * Leave an at least ~128 MB hole with possible stack randomization.
25028 */
25029 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25030 -#define MAX_GAP (TASK_SIZE/6*5)
25031 +#define MAX_GAP (pax_task_size/6*5)
25032
25033 static int mmap_is_legacy(void)
25034 {
25035 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25036 return rnd << PAGE_SHIFT;
25037 }
25038
25039 -static unsigned long mmap_base(void)
25040 +static unsigned long mmap_base(struct mm_struct *mm)
25041 {
25042 unsigned long gap = rlimit(RLIMIT_STACK);
25043 + unsigned long pax_task_size = TASK_SIZE;
25044 +
25045 +#ifdef CONFIG_PAX_SEGMEXEC
25046 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25047 + pax_task_size = SEGMEXEC_TASK_SIZE;
25048 +#endif
25049
25050 if (gap < MIN_GAP)
25051 gap = MIN_GAP;
25052 else if (gap > MAX_GAP)
25053 gap = MAX_GAP;
25054
25055 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25056 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25057 }
25058
25059 /*
25060 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25061 * does, but not when emulating X86_32
25062 */
25063 -static unsigned long mmap_legacy_base(void)
25064 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25065 {
25066 - if (mmap_is_ia32())
25067 + if (mmap_is_ia32()) {
25068 +
25069 +#ifdef CONFIG_PAX_SEGMEXEC
25070 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25071 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25072 + else
25073 +#endif
25074 +
25075 return TASK_UNMAPPED_BASE;
25076 - else
25077 + } else
25078 return TASK_UNMAPPED_BASE + mmap_rnd();
25079 }
25080
25081 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25082 void arch_pick_mmap_layout(struct mm_struct *mm)
25083 {
25084 if (mmap_is_legacy()) {
25085 - mm->mmap_base = mmap_legacy_base();
25086 + mm->mmap_base = mmap_legacy_base(mm);
25087 +
25088 +#ifdef CONFIG_PAX_RANDMMAP
25089 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25090 + mm->mmap_base += mm->delta_mmap;
25091 +#endif
25092 +
25093 mm->get_unmapped_area = arch_get_unmapped_area;
25094 mm->unmap_area = arch_unmap_area;
25095 } else {
25096 - mm->mmap_base = mmap_base();
25097 + mm->mmap_base = mmap_base(mm);
25098 +
25099 +#ifdef CONFIG_PAX_RANDMMAP
25100 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25101 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25102 +#endif
25103 +
25104 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25105 mm->unmap_area = arch_unmap_area_topdown;
25106 }
25107 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25108 index dc0b727..dc9d71a 100644
25109 --- a/arch/x86/mm/mmio-mod.c
25110 +++ b/arch/x86/mm/mmio-mod.c
25111 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25112 break;
25113 default:
25114 {
25115 - unsigned char *ip = (unsigned char *)instptr;
25116 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25117 my_trace->opcode = MMIO_UNKNOWN_OP;
25118 my_trace->width = 0;
25119 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25120 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25121 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25122 void __iomem *addr)
25123 {
25124 - static atomic_t next_id;
25125 + static atomic_unchecked_t next_id;
25126 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25127 /* These are page-unaligned. */
25128 struct mmiotrace_map map = {
25129 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25130 .private = trace
25131 },
25132 .phys = offset,
25133 - .id = atomic_inc_return(&next_id)
25134 + .id = atomic_inc_return_unchecked(&next_id)
25135 };
25136 map.map_id = trace->id;
25137
25138 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25139 index b008656..773eac2 100644
25140 --- a/arch/x86/mm/pageattr-test.c
25141 +++ b/arch/x86/mm/pageattr-test.c
25142 @@ -36,7 +36,7 @@ enum {
25143
25144 static int pte_testbit(pte_t pte)
25145 {
25146 - return pte_flags(pte) & _PAGE_UNUSED1;
25147 + return pte_flags(pte) & _PAGE_CPA_TEST;
25148 }
25149
25150 struct split_state {
25151 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25152 index a718e0d..45efc32 100644
25153 --- a/arch/x86/mm/pageattr.c
25154 +++ b/arch/x86/mm/pageattr.c
25155 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25156 */
25157 #ifdef CONFIG_PCI_BIOS
25158 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25159 - pgprot_val(forbidden) |= _PAGE_NX;
25160 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25161 #endif
25162
25163 /*
25164 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25165 * Does not cover __inittext since that is gone later on. On
25166 * 64bit we do not enforce !NX on the low mapping
25167 */
25168 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25169 - pgprot_val(forbidden) |= _PAGE_NX;
25170 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25171 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25172
25173 +#ifdef CONFIG_DEBUG_RODATA
25174 /*
25175 * The .rodata section needs to be read-only. Using the pfn
25176 * catches all aliases.
25177 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25178 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25179 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25180 pgprot_val(forbidden) |= _PAGE_RW;
25181 +#endif
25182
25183 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25184 /*
25185 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25186 }
25187 #endif
25188
25189 +#ifdef CONFIG_PAX_KERNEXEC
25190 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25191 + pgprot_val(forbidden) |= _PAGE_RW;
25192 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25193 + }
25194 +#endif
25195 +
25196 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25197
25198 return prot;
25199 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25200 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25201 {
25202 /* change init_mm */
25203 + pax_open_kernel();
25204 set_pte_atomic(kpte, pte);
25205 +
25206 #ifdef CONFIG_X86_32
25207 if (!SHARED_KERNEL_PMD) {
25208 +
25209 +#ifdef CONFIG_PAX_PER_CPU_PGD
25210 + unsigned long cpu;
25211 +#else
25212 struct page *page;
25213 +#endif
25214
25215 +#ifdef CONFIG_PAX_PER_CPU_PGD
25216 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25217 + pgd_t *pgd = get_cpu_pgd(cpu);
25218 +#else
25219 list_for_each_entry(page, &pgd_list, lru) {
25220 - pgd_t *pgd;
25221 + pgd_t *pgd = (pgd_t *)page_address(page);
25222 +#endif
25223 +
25224 pud_t *pud;
25225 pmd_t *pmd;
25226
25227 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25228 + pgd += pgd_index(address);
25229 pud = pud_offset(pgd, address);
25230 pmd = pmd_offset(pud, address);
25231 set_pte_atomic((pte_t *)pmd, pte);
25232 }
25233 }
25234 #endif
25235 + pax_close_kernel();
25236 }
25237
25238 static int
25239 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25240 index 3d68ef6..7f69136 100644
25241 --- a/arch/x86/mm/pat.c
25242 +++ b/arch/x86/mm/pat.c
25243 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25244
25245 if (!entry) {
25246 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25247 - current->comm, current->pid, start, end - 1);
25248 + current->comm, task_pid_nr(current), start, end - 1);
25249 return -EINVAL;
25250 }
25251
25252 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25253
25254 while (cursor < to) {
25255 if (!devmem_is_allowed(pfn)) {
25256 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25257 - current->comm, from, to - 1);
25258 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25259 + current->comm, from, to - 1, cursor);
25260 return 0;
25261 }
25262 cursor += PAGE_SIZE;
25263 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25264 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25265 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25266 "for [mem %#010Lx-%#010Lx]\n",
25267 - current->comm, current->pid,
25268 + current->comm, task_pid_nr(current),
25269 cattr_name(flags),
25270 base, (unsigned long long)(base + size-1));
25271 return -EINVAL;
25272 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25273 flags = lookup_memtype(paddr);
25274 if (want_flags != flags) {
25275 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25276 - current->comm, current->pid,
25277 + current->comm, task_pid_nr(current),
25278 cattr_name(want_flags),
25279 (unsigned long long)paddr,
25280 (unsigned long long)(paddr + size - 1),
25281 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25282 free_memtype(paddr, paddr + size);
25283 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25284 " for [mem %#010Lx-%#010Lx], got %s\n",
25285 - current->comm, current->pid,
25286 + current->comm, task_pid_nr(current),
25287 cattr_name(want_flags),
25288 (unsigned long long)paddr,
25289 (unsigned long long)(paddr + size - 1),
25290 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25291 index 9f0614d..92ae64a 100644
25292 --- a/arch/x86/mm/pf_in.c
25293 +++ b/arch/x86/mm/pf_in.c
25294 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25295 int i;
25296 enum reason_type rv = OTHERS;
25297
25298 - p = (unsigned char *)ins_addr;
25299 + p = (unsigned char *)ktla_ktva(ins_addr);
25300 p += skip_prefix(p, &prf);
25301 p += get_opcode(p, &opcode);
25302
25303 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25304 struct prefix_bits prf;
25305 int i;
25306
25307 - p = (unsigned char *)ins_addr;
25308 + p = (unsigned char *)ktla_ktva(ins_addr);
25309 p += skip_prefix(p, &prf);
25310 p += get_opcode(p, &opcode);
25311
25312 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25313 struct prefix_bits prf;
25314 int i;
25315
25316 - p = (unsigned char *)ins_addr;
25317 + p = (unsigned char *)ktla_ktva(ins_addr);
25318 p += skip_prefix(p, &prf);
25319 p += get_opcode(p, &opcode);
25320
25321 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25322 struct prefix_bits prf;
25323 int i;
25324
25325 - p = (unsigned char *)ins_addr;
25326 + p = (unsigned char *)ktla_ktva(ins_addr);
25327 p += skip_prefix(p, &prf);
25328 p += get_opcode(p, &opcode);
25329 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25330 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25331 struct prefix_bits prf;
25332 int i;
25333
25334 - p = (unsigned char *)ins_addr;
25335 + p = (unsigned char *)ktla_ktva(ins_addr);
25336 p += skip_prefix(p, &prf);
25337 p += get_opcode(p, &opcode);
25338 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25339 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25340 index 8573b83..4f3ed7e 100644
25341 --- a/arch/x86/mm/pgtable.c
25342 +++ b/arch/x86/mm/pgtable.c
25343 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25344 list_del(&page->lru);
25345 }
25346
25347 -#define UNSHARED_PTRS_PER_PGD \
25348 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25349 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25350 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25351
25352 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25353 +{
25354 + unsigned int count = USER_PGD_PTRS;
25355
25356 + while (count--)
25357 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25358 +}
25359 +#endif
25360 +
25361 +#ifdef CONFIG_PAX_PER_CPU_PGD
25362 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25363 +{
25364 + unsigned int count = USER_PGD_PTRS;
25365 +
25366 + while (count--) {
25367 + pgd_t pgd;
25368 +
25369 +#ifdef CONFIG_X86_64
25370 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25371 +#else
25372 + pgd = *src++;
25373 +#endif
25374 +
25375 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25376 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25377 +#endif
25378 +
25379 + *dst++ = pgd;
25380 + }
25381 +
25382 +}
25383 +#endif
25384 +
25385 +#ifdef CONFIG_X86_64
25386 +#define pxd_t pud_t
25387 +#define pyd_t pgd_t
25388 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25389 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25390 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25391 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25392 +#define PYD_SIZE PGDIR_SIZE
25393 +#else
25394 +#define pxd_t pmd_t
25395 +#define pyd_t pud_t
25396 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25397 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25398 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25399 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25400 +#define PYD_SIZE PUD_SIZE
25401 +#endif
25402 +
25403 +#ifdef CONFIG_PAX_PER_CPU_PGD
25404 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25405 +static inline void pgd_dtor(pgd_t *pgd) {}
25406 +#else
25407 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25408 {
25409 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25410 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25411 pgd_list_del(pgd);
25412 spin_unlock(&pgd_lock);
25413 }
25414 +#endif
25415
25416 /*
25417 * List of all pgd's needed for non-PAE so it can invalidate entries
25418 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25419 * -- wli
25420 */
25421
25422 -#ifdef CONFIG_X86_PAE
25423 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25424 /*
25425 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25426 * updating the top-level pagetable entries to guarantee the
25427 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25428 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25429 * and initialize the kernel pmds here.
25430 */
25431 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25432 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25433
25434 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25435 {
25436 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25437 */
25438 flush_tlb_mm(mm);
25439 }
25440 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25441 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25442 #else /* !CONFIG_X86_PAE */
25443
25444 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25445 -#define PREALLOCATED_PMDS 0
25446 +#define PREALLOCATED_PXDS 0
25447
25448 #endif /* CONFIG_X86_PAE */
25449
25450 -static void free_pmds(pmd_t *pmds[])
25451 +static void free_pxds(pxd_t *pxds[])
25452 {
25453 int i;
25454
25455 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25456 - if (pmds[i])
25457 - free_page((unsigned long)pmds[i]);
25458 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25459 + if (pxds[i])
25460 + free_page((unsigned long)pxds[i]);
25461 }
25462
25463 -static int preallocate_pmds(pmd_t *pmds[])
25464 +static int preallocate_pxds(pxd_t *pxds[])
25465 {
25466 int i;
25467 bool failed = false;
25468
25469 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25470 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25471 - if (pmd == NULL)
25472 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25473 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25474 + if (pxd == NULL)
25475 failed = true;
25476 - pmds[i] = pmd;
25477 + pxds[i] = pxd;
25478 }
25479
25480 if (failed) {
25481 - free_pmds(pmds);
25482 + free_pxds(pxds);
25483 return -ENOMEM;
25484 }
25485
25486 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25487 * preallocate which never got a corresponding vma will need to be
25488 * freed manually.
25489 */
25490 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25491 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25492 {
25493 int i;
25494
25495 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25496 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25497 pgd_t pgd = pgdp[i];
25498
25499 if (pgd_val(pgd) != 0) {
25500 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25501 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25502
25503 - pgdp[i] = native_make_pgd(0);
25504 + set_pgd(pgdp + i, native_make_pgd(0));
25505
25506 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25507 - pmd_free(mm, pmd);
25508 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25509 + pxd_free(mm, pxd);
25510 }
25511 }
25512 }
25513
25514 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25515 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25516 {
25517 - pud_t *pud;
25518 + pyd_t *pyd;
25519 unsigned long addr;
25520 int i;
25521
25522 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25523 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25524 return;
25525
25526 - pud = pud_offset(pgd, 0);
25527 +#ifdef CONFIG_X86_64
25528 + pyd = pyd_offset(mm, 0L);
25529 +#else
25530 + pyd = pyd_offset(pgd, 0L);
25531 +#endif
25532
25533 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25534 - i++, pud++, addr += PUD_SIZE) {
25535 - pmd_t *pmd = pmds[i];
25536 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25537 + i++, pyd++, addr += PYD_SIZE) {
25538 + pxd_t *pxd = pxds[i];
25539
25540 if (i >= KERNEL_PGD_BOUNDARY)
25541 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25542 - sizeof(pmd_t) * PTRS_PER_PMD);
25543 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25544 + sizeof(pxd_t) * PTRS_PER_PMD);
25545
25546 - pud_populate(mm, pud, pmd);
25547 + pyd_populate(mm, pyd, pxd);
25548 }
25549 }
25550
25551 pgd_t *pgd_alloc(struct mm_struct *mm)
25552 {
25553 pgd_t *pgd;
25554 - pmd_t *pmds[PREALLOCATED_PMDS];
25555 + pxd_t *pxds[PREALLOCATED_PXDS];
25556
25557 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25558
25559 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25560
25561 mm->pgd = pgd;
25562
25563 - if (preallocate_pmds(pmds) != 0)
25564 + if (preallocate_pxds(pxds) != 0)
25565 goto out_free_pgd;
25566
25567 if (paravirt_pgd_alloc(mm) != 0)
25568 - goto out_free_pmds;
25569 + goto out_free_pxds;
25570
25571 /*
25572 * Make sure that pre-populating the pmds is atomic with
25573 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25574 spin_lock(&pgd_lock);
25575
25576 pgd_ctor(mm, pgd);
25577 - pgd_prepopulate_pmd(mm, pgd, pmds);
25578 + pgd_prepopulate_pxd(mm, pgd, pxds);
25579
25580 spin_unlock(&pgd_lock);
25581
25582 return pgd;
25583
25584 -out_free_pmds:
25585 - free_pmds(pmds);
25586 +out_free_pxds:
25587 + free_pxds(pxds);
25588 out_free_pgd:
25589 free_page((unsigned long)pgd);
25590 out:
25591 @@ -295,7 +356,7 @@ out:
25592
25593 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25594 {
25595 - pgd_mop_up_pmds(mm, pgd);
25596 + pgd_mop_up_pxds(mm, pgd);
25597 pgd_dtor(pgd);
25598 paravirt_pgd_free(mm, pgd);
25599 free_page((unsigned long)pgd);
25600 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25601 index a69bcb8..19068ab 100644
25602 --- a/arch/x86/mm/pgtable_32.c
25603 +++ b/arch/x86/mm/pgtable_32.c
25604 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25605 return;
25606 }
25607 pte = pte_offset_kernel(pmd, vaddr);
25608 +
25609 + pax_open_kernel();
25610 if (pte_val(pteval))
25611 set_pte_at(&init_mm, vaddr, pte, pteval);
25612 else
25613 pte_clear(&init_mm, vaddr, pte);
25614 + pax_close_kernel();
25615
25616 /*
25617 * It's enough to flush this one mapping.
25618 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25619 index 410531d..0f16030 100644
25620 --- a/arch/x86/mm/setup_nx.c
25621 +++ b/arch/x86/mm/setup_nx.c
25622 @@ -5,8 +5,10 @@
25623 #include <asm/pgtable.h>
25624 #include <asm/proto.h>
25625
25626 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25627 static int disable_nx __cpuinitdata;
25628
25629 +#ifndef CONFIG_PAX_PAGEEXEC
25630 /*
25631 * noexec = on|off
25632 *
25633 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25634 return 0;
25635 }
25636 early_param("noexec", noexec_setup);
25637 +#endif
25638 +
25639 +#endif
25640
25641 void __cpuinit x86_configure_nx(void)
25642 {
25643 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25644 if (cpu_has_nx && !disable_nx)
25645 __supported_pte_mask |= _PAGE_NX;
25646 else
25647 +#endif
25648 __supported_pte_mask &= ~_PAGE_NX;
25649 }
25650
25651 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25652 index 5e57e11..64874249 100644
25653 --- a/arch/x86/mm/tlb.c
25654 +++ b/arch/x86/mm/tlb.c
25655 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25656 BUG();
25657 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25658 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25659 +
25660 +#ifndef CONFIG_PAX_PER_CPU_PGD
25661 load_cr3(swapper_pg_dir);
25662 +#endif
25663 +
25664 }
25665 }
25666 EXPORT_SYMBOL_GPL(leave_mm);
25667 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25668 index 877b9a1..a8ecf42 100644
25669 --- a/arch/x86/net/bpf_jit.S
25670 +++ b/arch/x86/net/bpf_jit.S
25671 @@ -9,6 +9,7 @@
25672 */
25673 #include <linux/linkage.h>
25674 #include <asm/dwarf2.h>
25675 +#include <asm/alternative-asm.h>
25676
25677 /*
25678 * Calling convention :
25679 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25680 jle bpf_slow_path_word
25681 mov (SKBDATA,%rsi),%eax
25682 bswap %eax /* ntohl() */
25683 + pax_force_retaddr
25684 ret
25685
25686 sk_load_half:
25687 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25688 jle bpf_slow_path_half
25689 movzwl (SKBDATA,%rsi),%eax
25690 rol $8,%ax # ntohs()
25691 + pax_force_retaddr
25692 ret
25693
25694 sk_load_byte:
25695 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25696 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25697 jle bpf_slow_path_byte
25698 movzbl (SKBDATA,%rsi),%eax
25699 + pax_force_retaddr
25700 ret
25701
25702 /**
25703 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25704 movzbl (SKBDATA,%rsi),%ebx
25705 and $15,%bl
25706 shl $2,%bl
25707 + pax_force_retaddr
25708 ret
25709
25710 /* rsi contains offset and can be scratched */
25711 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25712 js bpf_error
25713 mov -12(%rbp),%eax
25714 bswap %eax
25715 + pax_force_retaddr
25716 ret
25717
25718 bpf_slow_path_half:
25719 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25720 mov -12(%rbp),%ax
25721 rol $8,%ax
25722 movzwl %ax,%eax
25723 + pax_force_retaddr
25724 ret
25725
25726 bpf_slow_path_byte:
25727 bpf_slow_path_common(1)
25728 js bpf_error
25729 movzbl -12(%rbp),%eax
25730 + pax_force_retaddr
25731 ret
25732
25733 bpf_slow_path_byte_msh:
25734 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25735 and $15,%al
25736 shl $2,%al
25737 xchg %eax,%ebx
25738 + pax_force_retaddr
25739 ret
25740
25741 #define sk_negative_common(SIZE) \
25742 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25743 sk_negative_common(4)
25744 mov (%rax), %eax
25745 bswap %eax
25746 + pax_force_retaddr
25747 ret
25748
25749 bpf_slow_path_half_neg:
25750 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25751 mov (%rax),%ax
25752 rol $8,%ax
25753 movzwl %ax,%eax
25754 + pax_force_retaddr
25755 ret
25756
25757 bpf_slow_path_byte_neg:
25758 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25759 .globl sk_load_byte_negative_offset
25760 sk_negative_common(1)
25761 movzbl (%rax), %eax
25762 + pax_force_retaddr
25763 ret
25764
25765 bpf_slow_path_byte_msh_neg:
25766 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25767 and $15,%al
25768 shl $2,%al
25769 xchg %eax,%ebx
25770 + pax_force_retaddr
25771 ret
25772
25773 bpf_error:
25774 @@ -197,4 +210,5 @@ bpf_error:
25775 xor %eax,%eax
25776 mov -8(%rbp),%rbx
25777 leaveq
25778 + pax_force_retaddr
25779 ret
25780 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25781 index 0597f95..a12c36e 100644
25782 --- a/arch/x86/net/bpf_jit_comp.c
25783 +++ b/arch/x86/net/bpf_jit_comp.c
25784 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25785 set_fs(old_fs);
25786 }
25787
25788 +struct bpf_jit_work {
25789 + struct work_struct work;
25790 + void *image;
25791 +};
25792 +
25793 #define CHOOSE_LOAD_FUNC(K, func) \
25794 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25795
25796 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25797 if (addrs == NULL)
25798 return;
25799
25800 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25801 + if (!fp->work)
25802 + goto out;
25803 +
25804 /* Before first pass, make a rough estimation of addrs[]
25805 * each bpf instruction is translated to less than 64 bytes
25806 */
25807 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25808 break;
25809 default:
25810 /* hmm, too complex filter, give up with jit compiler */
25811 - goto out;
25812 + goto error;
25813 }
25814 ilen = prog - temp;
25815 if (image) {
25816 if (unlikely(proglen + ilen > oldproglen)) {
25817 pr_err("bpb_jit_compile fatal error\n");
25818 - kfree(addrs);
25819 - module_free(NULL, image);
25820 - return;
25821 + module_free_exec(NULL, image);
25822 + goto error;
25823 }
25824 + pax_open_kernel();
25825 memcpy(image + proglen, temp, ilen);
25826 + pax_close_kernel();
25827 }
25828 proglen += ilen;
25829 addrs[i] = proglen;
25830 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25831 break;
25832 }
25833 if (proglen == oldproglen) {
25834 - image = module_alloc(max_t(unsigned int,
25835 - proglen,
25836 - sizeof(struct work_struct)));
25837 + image = module_alloc_exec(proglen);
25838 if (!image)
25839 - goto out;
25840 + goto error;
25841 }
25842 oldproglen = proglen;
25843 }
25844 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25845 bpf_flush_icache(image, image + proglen);
25846
25847 fp->bpf_func = (void *)image;
25848 - }
25849 + } else
25850 +error:
25851 + kfree(fp->work);
25852 +
25853 out:
25854 kfree(addrs);
25855 return;
25856 @@ -648,18 +659,20 @@ out:
25857
25858 static void jit_free_defer(struct work_struct *arg)
25859 {
25860 - module_free(NULL, arg);
25861 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25862 + kfree(arg);
25863 }
25864
25865 /* run from softirq, we must use a work_struct to call
25866 - * module_free() from process context
25867 + * module_free_exec() from process context
25868 */
25869 void bpf_jit_free(struct sk_filter *fp)
25870 {
25871 if (fp->bpf_func != sk_run_filter) {
25872 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25873 + struct work_struct *work = &fp->work->work;
25874
25875 INIT_WORK(work, jit_free_defer);
25876 + fp->work->image = fp->bpf_func;
25877 schedule_work(work);
25878 }
25879 }
25880 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25881 index d6aa6e8..266395a 100644
25882 --- a/arch/x86/oprofile/backtrace.c
25883 +++ b/arch/x86/oprofile/backtrace.c
25884 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25885 struct stack_frame_ia32 *fp;
25886 unsigned long bytes;
25887
25888 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25889 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25890 if (bytes != sizeof(bufhead))
25891 return NULL;
25892
25893 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25894 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25895
25896 oprofile_add_trace(bufhead[0].return_address);
25897
25898 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25899 struct stack_frame bufhead[2];
25900 unsigned long bytes;
25901
25902 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25903 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25904 if (bytes != sizeof(bufhead))
25905 return NULL;
25906
25907 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25908 {
25909 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25910
25911 - if (!user_mode_vm(regs)) {
25912 + if (!user_mode(regs)) {
25913 unsigned long stack = kernel_stack_pointer(regs);
25914 if (depth)
25915 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25916 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25917 index 140942f..8a5cc55 100644
25918 --- a/arch/x86/pci/mrst.c
25919 +++ b/arch/x86/pci/mrst.c
25920 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25921 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25922 pci_mmcfg_late_init();
25923 pcibios_enable_irq = mrst_pci_irq_enable;
25924 - pci_root_ops = pci_mrst_ops;
25925 + pax_open_kernel();
25926 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25927 + pax_close_kernel();
25928 pci_soc_mode = 1;
25929 /* Continue with standard init */
25930 return 1;
25931 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25932 index da8fe05..7ee6704 100644
25933 --- a/arch/x86/pci/pcbios.c
25934 +++ b/arch/x86/pci/pcbios.c
25935 @@ -79,50 +79,93 @@ union bios32 {
25936 static struct {
25937 unsigned long address;
25938 unsigned short segment;
25939 -} bios32_indirect = { 0, __KERNEL_CS };
25940 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25941
25942 /*
25943 * Returns the entry point for the given service, NULL on error
25944 */
25945
25946 -static unsigned long bios32_service(unsigned long service)
25947 +static unsigned long __devinit bios32_service(unsigned long service)
25948 {
25949 unsigned char return_code; /* %al */
25950 unsigned long address; /* %ebx */
25951 unsigned long length; /* %ecx */
25952 unsigned long entry; /* %edx */
25953 unsigned long flags;
25954 + struct desc_struct d, *gdt;
25955
25956 local_irq_save(flags);
25957 - __asm__("lcall *(%%edi); cld"
25958 +
25959 + gdt = get_cpu_gdt_table(smp_processor_id());
25960 +
25961 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25962 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25963 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25964 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25965 +
25966 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25967 : "=a" (return_code),
25968 "=b" (address),
25969 "=c" (length),
25970 "=d" (entry)
25971 : "0" (service),
25972 "1" (0),
25973 - "D" (&bios32_indirect));
25974 + "D" (&bios32_indirect),
25975 + "r"(__PCIBIOS_DS)
25976 + : "memory");
25977 +
25978 + pax_open_kernel();
25979 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25980 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25981 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25982 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25983 + pax_close_kernel();
25984 +
25985 local_irq_restore(flags);
25986
25987 switch (return_code) {
25988 - case 0:
25989 - return address + entry;
25990 - case 0x80: /* Not present */
25991 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25992 - return 0;
25993 - default: /* Shouldn't happen */
25994 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25995 - service, return_code);
25996 + case 0: {
25997 + int cpu;
25998 + unsigned char flags;
25999 +
26000 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26001 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26002 + printk(KERN_WARNING "bios32_service: not valid\n");
26003 return 0;
26004 + }
26005 + address = address + PAGE_OFFSET;
26006 + length += 16UL; /* some BIOSs underreport this... */
26007 + flags = 4;
26008 + if (length >= 64*1024*1024) {
26009 + length >>= PAGE_SHIFT;
26010 + flags |= 8;
26011 + }
26012 +
26013 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26014 + gdt = get_cpu_gdt_table(cpu);
26015 + pack_descriptor(&d, address, length, 0x9b, flags);
26016 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26017 + pack_descriptor(&d, address, length, 0x93, flags);
26018 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26019 + }
26020 + return entry;
26021 + }
26022 + case 0x80: /* Not present */
26023 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26024 + return 0;
26025 + default: /* Shouldn't happen */
26026 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26027 + service, return_code);
26028 + return 0;
26029 }
26030 }
26031
26032 static struct {
26033 unsigned long address;
26034 unsigned short segment;
26035 -} pci_indirect = { 0, __KERNEL_CS };
26036 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26037
26038 -static int pci_bios_present;
26039 +static int pci_bios_present __read_only;
26040
26041 static int __devinit check_pcibios(void)
26042 {
26043 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26044 unsigned long flags, pcibios_entry;
26045
26046 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26047 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26048 + pci_indirect.address = pcibios_entry;
26049
26050 local_irq_save(flags);
26051 - __asm__(
26052 - "lcall *(%%edi); cld\n\t"
26053 + __asm__("movw %w6, %%ds\n\t"
26054 + "lcall *%%ss:(%%edi); cld\n\t"
26055 + "push %%ss\n\t"
26056 + "pop %%ds\n\t"
26057 "jc 1f\n\t"
26058 "xor %%ah, %%ah\n"
26059 "1:"
26060 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26061 "=b" (ebx),
26062 "=c" (ecx)
26063 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26064 - "D" (&pci_indirect)
26065 + "D" (&pci_indirect),
26066 + "r" (__PCIBIOS_DS)
26067 : "memory");
26068 local_irq_restore(flags);
26069
26070 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26071
26072 switch (len) {
26073 case 1:
26074 - __asm__("lcall *(%%esi); cld\n\t"
26075 + __asm__("movw %w6, %%ds\n\t"
26076 + "lcall *%%ss:(%%esi); cld\n\t"
26077 + "push %%ss\n\t"
26078 + "pop %%ds\n\t"
26079 "jc 1f\n\t"
26080 "xor %%ah, %%ah\n"
26081 "1:"
26082 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26083 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26084 "b" (bx),
26085 "D" ((long)reg),
26086 - "S" (&pci_indirect));
26087 + "S" (&pci_indirect),
26088 + "r" (__PCIBIOS_DS));
26089 /*
26090 * Zero-extend the result beyond 8 bits, do not trust the
26091 * BIOS having done it:
26092 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26093 *value &= 0xff;
26094 break;
26095 case 2:
26096 - __asm__("lcall *(%%esi); cld\n\t"
26097 + __asm__("movw %w6, %%ds\n\t"
26098 + "lcall *%%ss:(%%esi); cld\n\t"
26099 + "push %%ss\n\t"
26100 + "pop %%ds\n\t"
26101 "jc 1f\n\t"
26102 "xor %%ah, %%ah\n"
26103 "1:"
26104 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26105 : "1" (PCIBIOS_READ_CONFIG_WORD),
26106 "b" (bx),
26107 "D" ((long)reg),
26108 - "S" (&pci_indirect));
26109 + "S" (&pci_indirect),
26110 + "r" (__PCIBIOS_DS));
26111 /*
26112 * Zero-extend the result beyond 16 bits, do not trust the
26113 * BIOS having done it:
26114 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26115 *value &= 0xffff;
26116 break;
26117 case 4:
26118 - __asm__("lcall *(%%esi); cld\n\t"
26119 + __asm__("movw %w6, %%ds\n\t"
26120 + "lcall *%%ss:(%%esi); cld\n\t"
26121 + "push %%ss\n\t"
26122 + "pop %%ds\n\t"
26123 "jc 1f\n\t"
26124 "xor %%ah, %%ah\n"
26125 "1:"
26126 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26127 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26128 "b" (bx),
26129 "D" ((long)reg),
26130 - "S" (&pci_indirect));
26131 + "S" (&pci_indirect),
26132 + "r" (__PCIBIOS_DS));
26133 break;
26134 }
26135
26136 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26137
26138 switch (len) {
26139 case 1:
26140 - __asm__("lcall *(%%esi); cld\n\t"
26141 + __asm__("movw %w6, %%ds\n\t"
26142 + "lcall *%%ss:(%%esi); cld\n\t"
26143 + "push %%ss\n\t"
26144 + "pop %%ds\n\t"
26145 "jc 1f\n\t"
26146 "xor %%ah, %%ah\n"
26147 "1:"
26148 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26149 "c" (value),
26150 "b" (bx),
26151 "D" ((long)reg),
26152 - "S" (&pci_indirect));
26153 + "S" (&pci_indirect),
26154 + "r" (__PCIBIOS_DS));
26155 break;
26156 case 2:
26157 - __asm__("lcall *(%%esi); cld\n\t"
26158 + __asm__("movw %w6, %%ds\n\t"
26159 + "lcall *%%ss:(%%esi); cld\n\t"
26160 + "push %%ss\n\t"
26161 + "pop %%ds\n\t"
26162 "jc 1f\n\t"
26163 "xor %%ah, %%ah\n"
26164 "1:"
26165 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26166 "c" (value),
26167 "b" (bx),
26168 "D" ((long)reg),
26169 - "S" (&pci_indirect));
26170 + "S" (&pci_indirect),
26171 + "r" (__PCIBIOS_DS));
26172 break;
26173 case 4:
26174 - __asm__("lcall *(%%esi); cld\n\t"
26175 + __asm__("movw %w6, %%ds\n\t"
26176 + "lcall *%%ss:(%%esi); cld\n\t"
26177 + "push %%ss\n\t"
26178 + "pop %%ds\n\t"
26179 "jc 1f\n\t"
26180 "xor %%ah, %%ah\n"
26181 "1:"
26182 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26183 "c" (value),
26184 "b" (bx),
26185 "D" ((long)reg),
26186 - "S" (&pci_indirect));
26187 + "S" (&pci_indirect),
26188 + "r" (__PCIBIOS_DS));
26189 break;
26190 }
26191
26192 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26193
26194 DBG("PCI: Fetching IRQ routing table... ");
26195 __asm__("push %%es\n\t"
26196 + "movw %w8, %%ds\n\t"
26197 "push %%ds\n\t"
26198 "pop %%es\n\t"
26199 - "lcall *(%%esi); cld\n\t"
26200 + "lcall *%%ss:(%%esi); cld\n\t"
26201 "pop %%es\n\t"
26202 + "push %%ss\n\t"
26203 + "pop %%ds\n"
26204 "jc 1f\n\t"
26205 "xor %%ah, %%ah\n"
26206 "1:"
26207 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26208 "1" (0),
26209 "D" ((long) &opt),
26210 "S" (&pci_indirect),
26211 - "m" (opt)
26212 + "m" (opt),
26213 + "r" (__PCIBIOS_DS)
26214 : "memory");
26215 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26216 if (ret & 0xff00)
26217 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26218 {
26219 int ret;
26220
26221 - __asm__("lcall *(%%esi); cld\n\t"
26222 + __asm__("movw %w5, %%ds\n\t"
26223 + "lcall *%%ss:(%%esi); cld\n\t"
26224 + "push %%ss\n\t"
26225 + "pop %%ds\n"
26226 "jc 1f\n\t"
26227 "xor %%ah, %%ah\n"
26228 "1:"
26229 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26230 : "0" (PCIBIOS_SET_PCI_HW_INT),
26231 "b" ((dev->bus->number << 8) | dev->devfn),
26232 "c" ((irq << 8) | (pin + 10)),
26233 - "S" (&pci_indirect));
26234 + "S" (&pci_indirect),
26235 + "r" (__PCIBIOS_DS));
26236 return !(ret & 0xff00);
26237 }
26238 EXPORT_SYMBOL(pcibios_set_irq_routing);
26239 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26240 index 40e4469..1ab536e 100644
26241 --- a/arch/x86/platform/efi/efi_32.c
26242 +++ b/arch/x86/platform/efi/efi_32.c
26243 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26244 {
26245 struct desc_ptr gdt_descr;
26246
26247 +#ifdef CONFIG_PAX_KERNEXEC
26248 + struct desc_struct d;
26249 +#endif
26250 +
26251 local_irq_save(efi_rt_eflags);
26252
26253 load_cr3(initial_page_table);
26254 __flush_tlb_all();
26255
26256 +#ifdef CONFIG_PAX_KERNEXEC
26257 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26258 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26259 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26260 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26261 +#endif
26262 +
26263 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26264 gdt_descr.size = GDT_SIZE - 1;
26265 load_gdt(&gdt_descr);
26266 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26267 {
26268 struct desc_ptr gdt_descr;
26269
26270 +#ifdef CONFIG_PAX_KERNEXEC
26271 + struct desc_struct d;
26272 +
26273 + memset(&d, 0, sizeof d);
26274 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26275 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26276 +#endif
26277 +
26278 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26279 gdt_descr.size = GDT_SIZE - 1;
26280 load_gdt(&gdt_descr);
26281 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26282 index fbe66e6..c5c0dd2 100644
26283 --- a/arch/x86/platform/efi/efi_stub_32.S
26284 +++ b/arch/x86/platform/efi/efi_stub_32.S
26285 @@ -6,7 +6,9 @@
26286 */
26287
26288 #include <linux/linkage.h>
26289 +#include <linux/init.h>
26290 #include <asm/page_types.h>
26291 +#include <asm/segment.h>
26292
26293 /*
26294 * efi_call_phys(void *, ...) is a function with variable parameters.
26295 @@ -20,7 +22,7 @@
26296 * service functions will comply with gcc calling convention, too.
26297 */
26298
26299 -.text
26300 +__INIT
26301 ENTRY(efi_call_phys)
26302 /*
26303 * 0. The function can only be called in Linux kernel. So CS has been
26304 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26305 * The mapping of lower virtual memory has been created in prelog and
26306 * epilog.
26307 */
26308 - movl $1f, %edx
26309 - subl $__PAGE_OFFSET, %edx
26310 - jmp *%edx
26311 + movl $(__KERNEXEC_EFI_DS), %edx
26312 + mov %edx, %ds
26313 + mov %edx, %es
26314 + mov %edx, %ss
26315 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26316 1:
26317
26318 /*
26319 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26320 * parameter 2, ..., param n. To make things easy, we save the return
26321 * address of efi_call_phys in a global variable.
26322 */
26323 - popl %edx
26324 - movl %edx, saved_return_addr
26325 - /* get the function pointer into ECX*/
26326 - popl %ecx
26327 - movl %ecx, efi_rt_function_ptr
26328 - movl $2f, %edx
26329 - subl $__PAGE_OFFSET, %edx
26330 - pushl %edx
26331 + popl (saved_return_addr)
26332 + popl (efi_rt_function_ptr)
26333
26334 /*
26335 * 3. Clear PG bit in %CR0.
26336 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26337 /*
26338 * 5. Call the physical function.
26339 */
26340 - jmp *%ecx
26341 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26342
26343 -2:
26344 /*
26345 * 6. After EFI runtime service returns, control will return to
26346 * following instruction. We'd better readjust stack pointer first.
26347 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26348 movl %cr0, %edx
26349 orl $0x80000000, %edx
26350 movl %edx, %cr0
26351 - jmp 1f
26352 -1:
26353 +
26354 /*
26355 * 8. Now restore the virtual mode from flat mode by
26356 * adding EIP with PAGE_OFFSET.
26357 */
26358 - movl $1f, %edx
26359 - jmp *%edx
26360 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26361 1:
26362 + movl $(__KERNEL_DS), %edx
26363 + mov %edx, %ds
26364 + mov %edx, %es
26365 + mov %edx, %ss
26366
26367 /*
26368 * 9. Balance the stack. And because EAX contain the return value,
26369 * we'd better not clobber it.
26370 */
26371 - leal efi_rt_function_ptr, %edx
26372 - movl (%edx), %ecx
26373 - pushl %ecx
26374 + pushl (efi_rt_function_ptr)
26375
26376 /*
26377 - * 10. Push the saved return address onto the stack and return.
26378 + * 10. Return to the saved return address.
26379 */
26380 - leal saved_return_addr, %edx
26381 - movl (%edx), %ecx
26382 - pushl %ecx
26383 - ret
26384 + jmpl *(saved_return_addr)
26385 ENDPROC(efi_call_phys)
26386 .previous
26387
26388 -.data
26389 +__INITDATA
26390 saved_return_addr:
26391 .long 0
26392 efi_rt_function_ptr:
26393 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26394 index 4c07cca..2c8427d 100644
26395 --- a/arch/x86/platform/efi/efi_stub_64.S
26396 +++ b/arch/x86/platform/efi/efi_stub_64.S
26397 @@ -7,6 +7,7 @@
26398 */
26399
26400 #include <linux/linkage.h>
26401 +#include <asm/alternative-asm.h>
26402
26403 #define SAVE_XMM \
26404 mov %rsp, %rax; \
26405 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26406 call *%rdi
26407 addq $32, %rsp
26408 RESTORE_XMM
26409 + pax_force_retaddr 0, 1
26410 ret
26411 ENDPROC(efi_call0)
26412
26413 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26414 call *%rdi
26415 addq $32, %rsp
26416 RESTORE_XMM
26417 + pax_force_retaddr 0, 1
26418 ret
26419 ENDPROC(efi_call1)
26420
26421 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26422 call *%rdi
26423 addq $32, %rsp
26424 RESTORE_XMM
26425 + pax_force_retaddr 0, 1
26426 ret
26427 ENDPROC(efi_call2)
26428
26429 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26430 call *%rdi
26431 addq $32, %rsp
26432 RESTORE_XMM
26433 + pax_force_retaddr 0, 1
26434 ret
26435 ENDPROC(efi_call3)
26436
26437 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26438 call *%rdi
26439 addq $32, %rsp
26440 RESTORE_XMM
26441 + pax_force_retaddr 0, 1
26442 ret
26443 ENDPROC(efi_call4)
26444
26445 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26446 call *%rdi
26447 addq $48, %rsp
26448 RESTORE_XMM
26449 + pax_force_retaddr 0, 1
26450 ret
26451 ENDPROC(efi_call5)
26452
26453 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26454 call *%rdi
26455 addq $48, %rsp
26456 RESTORE_XMM
26457 + pax_force_retaddr 0, 1
26458 ret
26459 ENDPROC(efi_call6)
26460 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26461 index fd41a92..9c33628 100644
26462 --- a/arch/x86/platform/mrst/mrst.c
26463 +++ b/arch/x86/platform/mrst/mrst.c
26464 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26465 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26466 int sfi_mrtc_num;
26467
26468 -static void mrst_power_off(void)
26469 +static __noreturn void mrst_power_off(void)
26470 {
26471 + BUG();
26472 }
26473
26474 -static void mrst_reboot(void)
26475 +static __noreturn void mrst_reboot(void)
26476 {
26477 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26478 + BUG();
26479 }
26480
26481 /* parse all the mtimer info to a static mtimer array */
26482 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26483 index 218cdb1..fd55c08 100644
26484 --- a/arch/x86/power/cpu.c
26485 +++ b/arch/x86/power/cpu.c
26486 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26487 static void fix_processor_context(void)
26488 {
26489 int cpu = smp_processor_id();
26490 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26491 + struct tss_struct *t = init_tss + cpu;
26492
26493 set_tss_desc(cpu, t); /*
26494 * This just modifies memory; should not be
26495 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26496 */
26497
26498 #ifdef CONFIG_X86_64
26499 + pax_open_kernel();
26500 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26501 + pax_close_kernel();
26502
26503 syscall_init(); /* This sets MSR_*STAR and related */
26504 #endif
26505 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26506 index cbca565..913a0fe 100644
26507 --- a/arch/x86/realmode/init.c
26508 +++ b/arch/x86/realmode/init.c
26509 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26510 __va(real_mode_header->trampoline_header);
26511
26512 #ifdef CONFIG_X86_32
26513 - trampoline_header->start = __pa(startup_32_smp);
26514 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26515 +
26516 +#ifdef CONFIG_PAX_KERNEXEC
26517 + trampoline_header->start -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26518 +#endif
26519 +
26520 + trampoline_header->boot_cs = __BOOT_CS;
26521 trampoline_header->gdt_limit = __BOOT_DS + 7;
26522 trampoline_header->gdt_base = __pa(boot_gdt);
26523 #else
26524 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26525 index 5b84a2d..a004393 100644
26526 --- a/arch/x86/realmode/rm/Makefile
26527 +++ b/arch/x86/realmode/rm/Makefile
26528 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26529 $(call cc-option, -fno-unit-at-a-time)) \
26530 $(call cc-option, -fno-stack-protector) \
26531 $(call cc-option, -mpreferred-stack-boundary=2)
26532 +ifdef CONSTIFY_PLUGIN
26533 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26534 +endif
26535 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26536 GCOV_PROFILE := n
26537 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26538 index c1b2791..f9e31c7 100644
26539 --- a/arch/x86/realmode/rm/trampoline_32.S
26540 +++ b/arch/x86/realmode/rm/trampoline_32.S
26541 @@ -25,6 +25,12 @@
26542 #include <asm/page_types.h>
26543 #include "realmode.h"
26544
26545 +#ifdef CONFIG_PAX_KERNEXEC
26546 +#define ta(X) (X)
26547 +#else
26548 +#define ta(X) (pa_ ## X)
26549 +#endif
26550 +
26551 .text
26552 .code16
26553
26554 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26555
26556 cli # We should be safe anyway
26557
26558 - movl tr_start, %eax # where we need to go
26559 -
26560 movl $0xA5A5A5A5, trampoline_status
26561 # write marker for master knows we're running
26562
26563 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26564 movw $1, %dx # protected mode (PE) bit
26565 lmsw %dx # into protected mode
26566
26567 - ljmpl $__BOOT_CS, $pa_startup_32
26568 + ljmpl *(trampoline_header)
26569
26570 .section ".text32","ax"
26571 .code32
26572 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26573 .balign 8
26574 GLOBAL(trampoline_header)
26575 tr_start: .space 4
26576 - tr_gdt_pad: .space 2
26577 + tr_boot_cs: .space 2
26578 tr_gdt: .space 6
26579 END(trampoline_header)
26580
26581 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26582 index bb360dc..3e5945f 100644
26583 --- a/arch/x86/realmode/rm/trampoline_64.S
26584 +++ b/arch/x86/realmode/rm/trampoline_64.S
26585 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26586 wrmsr
26587
26588 # Enable paging and in turn activate Long Mode
26589 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26590 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26591 movl %eax, %cr0
26592
26593 /*
26594 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26595 index 5a1847d..deccb30 100644
26596 --- a/arch/x86/tools/relocs.c
26597 +++ b/arch/x86/tools/relocs.c
26598 @@ -12,10 +12,13 @@
26599 #include <regex.h>
26600 #include <tools/le_byteshift.h>
26601
26602 +#include "../../../include/generated/autoconf.h"
26603 +
26604 static void die(char *fmt, ...);
26605
26606 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26607 static Elf32_Ehdr ehdr;
26608 +static Elf32_Phdr *phdr;
26609 static unsigned long reloc_count, reloc_idx;
26610 static unsigned long *relocs;
26611 static unsigned long reloc16_count, reloc16_idx;
26612 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26613 }
26614 }
26615
26616 +static void read_phdrs(FILE *fp)
26617 +{
26618 + unsigned int i;
26619 +
26620 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26621 + if (!phdr) {
26622 + die("Unable to allocate %d program headers\n",
26623 + ehdr.e_phnum);
26624 + }
26625 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26626 + die("Seek to %d failed: %s\n",
26627 + ehdr.e_phoff, strerror(errno));
26628 + }
26629 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26630 + die("Cannot read ELF program headers: %s\n",
26631 + strerror(errno));
26632 + }
26633 + for(i = 0; i < ehdr.e_phnum; i++) {
26634 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26635 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26636 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26637 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26638 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26639 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26640 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26641 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26642 + }
26643 +
26644 +}
26645 +
26646 static void read_shdrs(FILE *fp)
26647 {
26648 - int i;
26649 + unsigned int i;
26650 Elf32_Shdr shdr;
26651
26652 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26653 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26654
26655 static void read_strtabs(FILE *fp)
26656 {
26657 - int i;
26658 + unsigned int i;
26659 for (i = 0; i < ehdr.e_shnum; i++) {
26660 struct section *sec = &secs[i];
26661 if (sec->shdr.sh_type != SHT_STRTAB) {
26662 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26663
26664 static void read_symtabs(FILE *fp)
26665 {
26666 - int i,j;
26667 + unsigned int i,j;
26668 for (i = 0; i < ehdr.e_shnum; i++) {
26669 struct section *sec = &secs[i];
26670 if (sec->shdr.sh_type != SHT_SYMTAB) {
26671 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26672 }
26673
26674
26675 -static void read_relocs(FILE *fp)
26676 +static void read_relocs(FILE *fp, int use_real_mode)
26677 {
26678 - int i,j;
26679 + unsigned int i,j;
26680 + uint32_t base;
26681 +
26682 for (i = 0; i < ehdr.e_shnum; i++) {
26683 struct section *sec = &secs[i];
26684 if (sec->shdr.sh_type != SHT_REL) {
26685 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26686 die("Cannot read symbol table: %s\n",
26687 strerror(errno));
26688 }
26689 + base = 0;
26690 +
26691 +#ifdef CONFIG_X86_32
26692 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26693 + if (phdr[j].p_type != PT_LOAD )
26694 + continue;
26695 + 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)
26696 + continue;
26697 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26698 + break;
26699 + }
26700 +#endif
26701 +
26702 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26703 Elf32_Rel *rel = &sec->reltab[j];
26704 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26705 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26706 rel->r_info = elf32_to_cpu(rel->r_info);
26707 }
26708 }
26709 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26710
26711 static void print_absolute_symbols(void)
26712 {
26713 - int i;
26714 + unsigned int i;
26715 printf("Absolute symbols\n");
26716 printf(" Num: Value Size Type Bind Visibility Name\n");
26717 for (i = 0; i < ehdr.e_shnum; i++) {
26718 struct section *sec = &secs[i];
26719 char *sym_strtab;
26720 - int j;
26721 + unsigned int j;
26722
26723 if (sec->shdr.sh_type != SHT_SYMTAB) {
26724 continue;
26725 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26726
26727 static void print_absolute_relocs(void)
26728 {
26729 - int i, printed = 0;
26730 + unsigned int i, printed = 0;
26731
26732 for (i = 0; i < ehdr.e_shnum; i++) {
26733 struct section *sec = &secs[i];
26734 struct section *sec_applies, *sec_symtab;
26735 char *sym_strtab;
26736 Elf32_Sym *sh_symtab;
26737 - int j;
26738 + unsigned int j;
26739 if (sec->shdr.sh_type != SHT_REL) {
26740 continue;
26741 }
26742 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26743 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26744 int use_real_mode)
26745 {
26746 - int i;
26747 + unsigned int i;
26748 /* Walk through the relocations */
26749 for (i = 0; i < ehdr.e_shnum; i++) {
26750 char *sym_strtab;
26751 Elf32_Sym *sh_symtab;
26752 struct section *sec_applies, *sec_symtab;
26753 - int j;
26754 + unsigned int j;
26755 struct section *sec = &secs[i];
26756
26757 if (sec->shdr.sh_type != SHT_REL) {
26758 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26759 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26760 r_type = ELF32_R_TYPE(rel->r_info);
26761
26762 + if (!use_real_mode) {
26763 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26764 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26765 + continue;
26766 +
26767 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26768 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26769 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26770 + continue;
26771 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26772 + continue;
26773 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26774 + continue;
26775 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26776 + continue;
26777 +#endif
26778 + }
26779 +
26780 shn_abs = sym->st_shndx == SHN_ABS;
26781
26782 switch (r_type) {
26783 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26784
26785 static void emit_relocs(int as_text, int use_real_mode)
26786 {
26787 - int i;
26788 + unsigned int i;
26789 /* Count how many relocations I have and allocate space for them. */
26790 reloc_count = 0;
26791 walk_relocs(count_reloc, use_real_mode);
26792 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
26793 fname, strerror(errno));
26794 }
26795 read_ehdr(fp);
26796 + read_phdrs(fp);
26797 read_shdrs(fp);
26798 read_strtabs(fp);
26799 read_symtabs(fp);
26800 - read_relocs(fp);
26801 + read_relocs(fp, use_real_mode);
26802 if (show_absolute_syms) {
26803 print_absolute_symbols();
26804 return 0;
26805 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26806 index fd14be1..e3c79c0 100644
26807 --- a/arch/x86/vdso/Makefile
26808 +++ b/arch/x86/vdso/Makefile
26809 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26810 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26811 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26812
26813 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26814 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26815 GCOV_PROFILE := n
26816
26817 #
26818 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26819 index 66e6d93..587f435 100644
26820 --- a/arch/x86/vdso/vdso32-setup.c
26821 +++ b/arch/x86/vdso/vdso32-setup.c
26822 @@ -25,6 +25,7 @@
26823 #include <asm/tlbflush.h>
26824 #include <asm/vdso.h>
26825 #include <asm/proto.h>
26826 +#include <asm/mman.h>
26827
26828 enum {
26829 VDSO_DISABLED = 0,
26830 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26831 void enable_sep_cpu(void)
26832 {
26833 int cpu = get_cpu();
26834 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26835 + struct tss_struct *tss = init_tss + cpu;
26836
26837 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26838 put_cpu();
26839 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26840 gate_vma.vm_start = FIXADDR_USER_START;
26841 gate_vma.vm_end = FIXADDR_USER_END;
26842 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26843 - gate_vma.vm_page_prot = __P101;
26844 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26845
26846 return 0;
26847 }
26848 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26849 if (compat)
26850 addr = VDSO_HIGH_BASE;
26851 else {
26852 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26853 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26854 if (IS_ERR_VALUE(addr)) {
26855 ret = addr;
26856 goto up_fail;
26857 }
26858 }
26859
26860 - current->mm->context.vdso = (void *)addr;
26861 + current->mm->context.vdso = addr;
26862
26863 if (compat_uses_vma || !compat) {
26864 /*
26865 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26866 }
26867
26868 current_thread_info()->sysenter_return =
26869 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26870 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26871
26872 up_fail:
26873 if (ret)
26874 - current->mm->context.vdso = NULL;
26875 + current->mm->context.vdso = 0;
26876
26877 up_write(&mm->mmap_sem);
26878
26879 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26880
26881 const char *arch_vma_name(struct vm_area_struct *vma)
26882 {
26883 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26884 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26885 return "[vdso]";
26886 +
26887 +#ifdef CONFIG_PAX_SEGMEXEC
26888 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26889 + return "[vdso]";
26890 +#endif
26891 +
26892 return NULL;
26893 }
26894
26895 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26896 * Check to see if the corresponding task was created in compat vdso
26897 * mode.
26898 */
26899 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26900 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26901 return &gate_vma;
26902 return NULL;
26903 }
26904 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26905 index 00aaf04..4a26505 100644
26906 --- a/arch/x86/vdso/vma.c
26907 +++ b/arch/x86/vdso/vma.c
26908 @@ -16,8 +16,6 @@
26909 #include <asm/vdso.h>
26910 #include <asm/page.h>
26911
26912 -unsigned int __read_mostly vdso_enabled = 1;
26913 -
26914 extern char vdso_start[], vdso_end[];
26915 extern unsigned short vdso_sync_cpuid;
26916
26917 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26918 * unaligned here as a result of stack start randomization.
26919 */
26920 addr = PAGE_ALIGN(addr);
26921 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26922
26923 return addr;
26924 }
26925 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26926 unsigned size)
26927 {
26928 struct mm_struct *mm = current->mm;
26929 - unsigned long addr;
26930 + unsigned long addr = 0;
26931 int ret;
26932
26933 - if (!vdso_enabled)
26934 - return 0;
26935 -
26936 down_write(&mm->mmap_sem);
26937 +
26938 +#ifdef CONFIG_PAX_RANDMMAP
26939 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26940 +#endif
26941 +
26942 addr = vdso_addr(mm->start_stack, size);
26943 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26944 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26945 if (IS_ERR_VALUE(addr)) {
26946 ret = addr;
26947 goto up_fail;
26948 }
26949
26950 - current->mm->context.vdso = (void *)addr;
26951 + mm->context.vdso = addr;
26952
26953 ret = install_special_mapping(mm, addr, size,
26954 VM_READ|VM_EXEC|
26955 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26956 pages);
26957 - if (ret) {
26958 - current->mm->context.vdso = NULL;
26959 - goto up_fail;
26960 - }
26961 + if (ret)
26962 + mm->context.vdso = 0;
26963
26964 up_fail:
26965 up_write(&mm->mmap_sem);
26966 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26967 vdsox32_size);
26968 }
26969 #endif
26970 -
26971 -static __init int vdso_setup(char *s)
26972 -{
26973 - vdso_enabled = simple_strtoul(s, NULL, 0);
26974 - return 0;
26975 -}
26976 -__setup("vdso=", vdso_setup);
26977 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26978 index ff962d4..2bb5e83 100644
26979 --- a/arch/x86/xen/enlighten.c
26980 +++ b/arch/x86/xen/enlighten.c
26981 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26982
26983 struct shared_info xen_dummy_shared_info;
26984
26985 -void *xen_initial_gdt;
26986 -
26987 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26988 __read_mostly int xen_have_vector_callback;
26989 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26990 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26991 #endif
26992 };
26993
26994 -static void xen_reboot(int reason)
26995 +static __noreturn void xen_reboot(int reason)
26996 {
26997 struct sched_shutdown r = { .reason = reason };
26998
26999 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27000 - BUG();
27001 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27002 + BUG();
27003 }
27004
27005 -static void xen_restart(char *msg)
27006 +static __noreturn void xen_restart(char *msg)
27007 {
27008 xen_reboot(SHUTDOWN_reboot);
27009 }
27010
27011 -static void xen_emergency_restart(void)
27012 +static __noreturn void xen_emergency_restart(void)
27013 {
27014 xen_reboot(SHUTDOWN_reboot);
27015 }
27016
27017 -static void xen_machine_halt(void)
27018 +static __noreturn void xen_machine_halt(void)
27019 {
27020 xen_reboot(SHUTDOWN_poweroff);
27021 }
27022
27023 -static void xen_machine_power_off(void)
27024 +static __noreturn void xen_machine_power_off(void)
27025 {
27026 if (pm_power_off)
27027 pm_power_off();
27028 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27029 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27030
27031 /* Work out if we support NX */
27032 - x86_configure_nx();
27033 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27034 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27035 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27036 + unsigned l, h;
27037 +
27038 + __supported_pte_mask |= _PAGE_NX;
27039 + rdmsr(MSR_EFER, l, h);
27040 + l |= EFER_NX;
27041 + wrmsr(MSR_EFER, l, h);
27042 + }
27043 +#endif
27044
27045 xen_setup_features();
27046
27047 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27048
27049 machine_ops = xen_machine_ops;
27050
27051 - /*
27052 - * The only reliable way to retain the initial address of the
27053 - * percpu gdt_page is to remember it here, so we can go and
27054 - * mark it RW later, when the initial percpu area is freed.
27055 - */
27056 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27057 -
27058 xen_smp_init();
27059
27060 #ifdef CONFIG_ACPI_NUMA
27061 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27062 index 3a73785..0d30df2 100644
27063 --- a/arch/x86/xen/mmu.c
27064 +++ b/arch/x86/xen/mmu.c
27065 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27066 convert_pfn_mfn(init_level4_pgt);
27067 convert_pfn_mfn(level3_ident_pgt);
27068 convert_pfn_mfn(level3_kernel_pgt);
27069 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27070 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27071 + convert_pfn_mfn(level3_vmemmap_pgt);
27072
27073 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27074 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27075 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27076 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27077 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27078 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27079 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27080 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27081 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27082 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27083 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27084 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27085 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27086
27087 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27088 pv_mmu_ops.set_pud = xen_set_pud;
27089 #if PAGETABLE_LEVELS == 4
27090 pv_mmu_ops.set_pgd = xen_set_pgd;
27091 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27092 #endif
27093
27094 /* This will work as long as patching hasn't happened yet
27095 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27096 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27097 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27098 .set_pgd = xen_set_pgd_hyper,
27099 + .set_pgd_batched = xen_set_pgd_hyper,
27100
27101 .alloc_pud = xen_alloc_pmd_init,
27102 .release_pud = xen_release_pmd_init,
27103 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27104 index afb250d..627075f 100644
27105 --- a/arch/x86/xen/smp.c
27106 +++ b/arch/x86/xen/smp.c
27107 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27108 {
27109 BUG_ON(smp_processor_id() != 0);
27110 native_smp_prepare_boot_cpu();
27111 -
27112 - /* We've switched to the "real" per-cpu gdt, so make sure the
27113 - old memory can be recycled */
27114 - make_lowmem_page_readwrite(xen_initial_gdt);
27115 -
27116 xen_filter_cpu_maps();
27117 xen_setup_vcpu_info_placement();
27118 }
27119 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27120 gdt = get_cpu_gdt_table(cpu);
27121
27122 ctxt->flags = VGCF_IN_KERNEL;
27123 - ctxt->user_regs.ds = __USER_DS;
27124 - ctxt->user_regs.es = __USER_DS;
27125 + ctxt->user_regs.ds = __KERNEL_DS;
27126 + ctxt->user_regs.es = __KERNEL_DS;
27127 ctxt->user_regs.ss = __KERNEL_DS;
27128 #ifdef CONFIG_X86_32
27129 ctxt->user_regs.fs = __KERNEL_PERCPU;
27130 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27131 + savesegment(gs, ctxt->user_regs.gs);
27132 #else
27133 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27134 #endif
27135 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27136 int rc;
27137
27138 per_cpu(current_task, cpu) = idle;
27139 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27140 #ifdef CONFIG_X86_32
27141 irq_ctx_init(cpu);
27142 #else
27143 clear_tsk_thread_flag(idle, TIF_FORK);
27144 - per_cpu(kernel_stack, cpu) =
27145 - (unsigned long)task_stack_page(idle) -
27146 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27147 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27148 #endif
27149 xen_setup_runstate_info(cpu);
27150 xen_setup_timer(cpu);
27151 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27152 index f9643fc..602e8af 100644
27153 --- a/arch/x86/xen/xen-asm_32.S
27154 +++ b/arch/x86/xen/xen-asm_32.S
27155 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27156 ESP_OFFSET=4 # bytes pushed onto stack
27157
27158 /*
27159 - * Store vcpu_info pointer for easy access. Do it this way to
27160 - * avoid having to reload %fs
27161 + * Store vcpu_info pointer for easy access.
27162 */
27163 #ifdef CONFIG_SMP
27164 - GET_THREAD_INFO(%eax)
27165 - movl TI_cpu(%eax), %eax
27166 - movl __per_cpu_offset(,%eax,4), %eax
27167 - mov xen_vcpu(%eax), %eax
27168 + push %fs
27169 + mov $(__KERNEL_PERCPU), %eax
27170 + mov %eax, %fs
27171 + mov PER_CPU_VAR(xen_vcpu), %eax
27172 + pop %fs
27173 #else
27174 movl xen_vcpu, %eax
27175 #endif
27176 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27177 index aaa7291..3f77960 100644
27178 --- a/arch/x86/xen/xen-head.S
27179 +++ b/arch/x86/xen/xen-head.S
27180 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27181 #ifdef CONFIG_X86_32
27182 mov %esi,xen_start_info
27183 mov $init_thread_union+THREAD_SIZE,%esp
27184 +#ifdef CONFIG_SMP
27185 + movl $cpu_gdt_table,%edi
27186 + movl $__per_cpu_load,%eax
27187 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27188 + rorl $16,%eax
27189 + movb %al,__KERNEL_PERCPU + 4(%edi)
27190 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27191 + movl $__per_cpu_end - 1,%eax
27192 + subl $__per_cpu_start,%eax
27193 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27194 +#endif
27195 #else
27196 mov %rsi,xen_start_info
27197 mov $init_thread_union+THREAD_SIZE,%rsp
27198 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27199 index 202d4c1..99b072a 100644
27200 --- a/arch/x86/xen/xen-ops.h
27201 +++ b/arch/x86/xen/xen-ops.h
27202 @@ -10,8 +10,6 @@
27203 extern const char xen_hypervisor_callback[];
27204 extern const char xen_failsafe_callback[];
27205
27206 -extern void *xen_initial_gdt;
27207 -
27208 struct trap_info;
27209 void xen_copy_trap_info(struct trap_info *traps);
27210
27211 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27212 index 525bd3d..ef888b1 100644
27213 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27214 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27215 @@ -119,9 +119,9 @@
27216 ----------------------------------------------------------------------*/
27217
27218 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27219 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27220 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27221 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27222 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27223
27224 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27225 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27226 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27227 index 2f33760..835e50a 100644
27228 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27229 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27230 @@ -11,6 +11,7 @@
27231 #ifndef _XTENSA_CORE_H
27232 #define _XTENSA_CORE_H
27233
27234 +#include <linux/const.h>
27235
27236 /****************************************************************************
27237 Parameters Useful for Any Code, USER or PRIVILEGED
27238 @@ -112,9 +113,9 @@
27239 ----------------------------------------------------------------------*/
27240
27241 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27242 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27243 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27244 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27245 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27246
27247 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27248 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27249 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27250 index af00795..2bb8105 100644
27251 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27252 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27253 @@ -11,6 +11,7 @@
27254 #ifndef _XTENSA_CORE_CONFIGURATION_H
27255 #define _XTENSA_CORE_CONFIGURATION_H
27256
27257 +#include <linux/const.h>
27258
27259 /****************************************************************************
27260 Parameters Useful for Any Code, USER or PRIVILEGED
27261 @@ -118,9 +119,9 @@
27262 ----------------------------------------------------------------------*/
27263
27264 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27265 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27266 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27267 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27268 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27269
27270 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27271 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27272 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27273 index 58916af..9cb880b 100644
27274 --- a/block/blk-iopoll.c
27275 +++ b/block/blk-iopoll.c
27276 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27277 }
27278 EXPORT_SYMBOL(blk_iopoll_complete);
27279
27280 -static void blk_iopoll_softirq(struct softirq_action *h)
27281 +static void blk_iopoll_softirq(void)
27282 {
27283 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27284 int rearm = 0, budget = blk_iopoll_budget;
27285 diff --git a/block/blk-map.c b/block/blk-map.c
27286 index 623e1cd..ca1e109 100644
27287 --- a/block/blk-map.c
27288 +++ b/block/blk-map.c
27289 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27290 if (!len || !kbuf)
27291 return -EINVAL;
27292
27293 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27294 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27295 if (do_copy)
27296 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27297 else
27298 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27299 index 467c8de..4bddc6d 100644
27300 --- a/block/blk-softirq.c
27301 +++ b/block/blk-softirq.c
27302 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27303 * Softirq action handler - move entries to local list and loop over them
27304 * while passing them to the queue registered handler.
27305 */
27306 -static void blk_done_softirq(struct softirq_action *h)
27307 +static void blk_done_softirq(void)
27308 {
27309 struct list_head *cpu_list, local_list;
27310
27311 diff --git a/block/bsg.c b/block/bsg.c
27312 index ff64ae3..593560c 100644
27313 --- a/block/bsg.c
27314 +++ b/block/bsg.c
27315 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27316 struct sg_io_v4 *hdr, struct bsg_device *bd,
27317 fmode_t has_write_perm)
27318 {
27319 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27320 + unsigned char *cmdptr;
27321 +
27322 if (hdr->request_len > BLK_MAX_CDB) {
27323 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27324 if (!rq->cmd)
27325 return -ENOMEM;
27326 - }
27327 + cmdptr = rq->cmd;
27328 + } else
27329 + cmdptr = tmpcmd;
27330
27331 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27332 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27333 hdr->request_len))
27334 return -EFAULT;
27335
27336 + if (cmdptr != rq->cmd)
27337 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27338 +
27339 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27340 if (blk_verify_command(rq->cmd, has_write_perm))
27341 return -EPERM;
27342 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27343 index 7c668c8..db3521c 100644
27344 --- a/block/compat_ioctl.c
27345 +++ b/block/compat_ioctl.c
27346 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27347 err |= __get_user(f->spec1, &uf->spec1);
27348 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27349 err |= __get_user(name, &uf->name);
27350 - f->name = compat_ptr(name);
27351 + f->name = (void __force_kernel *)compat_ptr(name);
27352 if (err) {
27353 err = -EFAULT;
27354 goto out;
27355 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27356 index 6296b40..417c00f 100644
27357 --- a/block/partitions/efi.c
27358 +++ b/block/partitions/efi.c
27359 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27360 if (!gpt)
27361 return NULL;
27362
27363 + if (!le32_to_cpu(gpt->num_partition_entries))
27364 + return NULL;
27365 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27366 + if (!pte)
27367 + return NULL;
27368 +
27369 count = le32_to_cpu(gpt->num_partition_entries) *
27370 le32_to_cpu(gpt->sizeof_partition_entry);
27371 - if (!count)
27372 - return NULL;
27373 - pte = kzalloc(count, GFP_KERNEL);
27374 - if (!pte)
27375 - return NULL;
27376 -
27377 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27378 (u8 *) pte,
27379 count) < count) {
27380 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27381 index 9a87daa..fb17486 100644
27382 --- a/block/scsi_ioctl.c
27383 +++ b/block/scsi_ioctl.c
27384 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27385 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27386 struct sg_io_hdr *hdr, fmode_t mode)
27387 {
27388 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27389 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27390 + unsigned char *cmdptr;
27391 +
27392 + if (rq->cmd != rq->__cmd)
27393 + cmdptr = rq->cmd;
27394 + else
27395 + cmdptr = tmpcmd;
27396 +
27397 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27398 return -EFAULT;
27399 +
27400 + if (cmdptr != rq->cmd)
27401 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27402 +
27403 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27404 return -EPERM;
27405
27406 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27407 int err;
27408 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27409 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27410 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27411 + unsigned char *cmdptr;
27412
27413 if (!sic)
27414 return -EINVAL;
27415 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27416 */
27417 err = -EFAULT;
27418 rq->cmd_len = cmdlen;
27419 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27420 +
27421 + if (rq->cmd != rq->__cmd)
27422 + cmdptr = rq->cmd;
27423 + else
27424 + cmdptr = tmpcmd;
27425 +
27426 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27427 goto error;
27428
27429 + if (rq->cmd != cmdptr)
27430 + memcpy(rq->cmd, cmdptr, cmdlen);
27431 +
27432 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27433 goto error;
27434
27435 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27436 index 671d4d6..5f24030 100644
27437 --- a/crypto/cryptd.c
27438 +++ b/crypto/cryptd.c
27439 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27440
27441 struct cryptd_blkcipher_request_ctx {
27442 crypto_completion_t complete;
27443 -};
27444 +} __no_const;
27445
27446 struct cryptd_hash_ctx {
27447 struct crypto_shash *child;
27448 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27449
27450 struct cryptd_aead_request_ctx {
27451 crypto_completion_t complete;
27452 -};
27453 +} __no_const;
27454
27455 static void cryptd_queue_worker(struct work_struct *work);
27456
27457 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27458 index e6defd8..c26a225 100644
27459 --- a/drivers/acpi/apei/cper.c
27460 +++ b/drivers/acpi/apei/cper.c
27461 @@ -38,12 +38,12 @@
27462 */
27463 u64 cper_next_record_id(void)
27464 {
27465 - static atomic64_t seq;
27466 + static atomic64_unchecked_t seq;
27467
27468 - if (!atomic64_read(&seq))
27469 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27470 + if (!atomic64_read_unchecked(&seq))
27471 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27472
27473 - return atomic64_inc_return(&seq);
27474 + return atomic64_inc_return_unchecked(&seq);
27475 }
27476 EXPORT_SYMBOL_GPL(cper_next_record_id);
27477
27478 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27479 index 7586544..636a2f0 100644
27480 --- a/drivers/acpi/ec_sys.c
27481 +++ b/drivers/acpi/ec_sys.c
27482 @@ -12,6 +12,7 @@
27483 #include <linux/acpi.h>
27484 #include <linux/debugfs.h>
27485 #include <linux/module.h>
27486 +#include <linux/uaccess.h>
27487 #include "internal.h"
27488
27489 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27490 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27491 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27492 */
27493 unsigned int size = EC_SPACE_SIZE;
27494 - u8 *data = (u8 *) buf;
27495 + u8 data;
27496 loff_t init_off = *off;
27497 int err = 0;
27498
27499 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27500 size = count;
27501
27502 while (size) {
27503 - err = ec_read(*off, &data[*off - init_off]);
27504 + err = ec_read(*off, &data);
27505 if (err)
27506 return err;
27507 + if (put_user(data, &buf[*off - init_off]))
27508 + return -EFAULT;
27509 *off += 1;
27510 size--;
27511 }
27512 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27513
27514 unsigned int size = count;
27515 loff_t init_off = *off;
27516 - u8 *data = (u8 *) buf;
27517 int err = 0;
27518
27519 if (*off >= EC_SPACE_SIZE)
27520 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27521 }
27522
27523 while (size) {
27524 - u8 byte_write = data[*off - init_off];
27525 + u8 byte_write;
27526 + if (get_user(byte_write, &buf[*off - init_off]))
27527 + return -EFAULT;
27528 err = ec_write(*off, byte_write);
27529 if (err)
27530 return err;
27531 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27532 index 251c7b62..000462d 100644
27533 --- a/drivers/acpi/proc.c
27534 +++ b/drivers/acpi/proc.c
27535 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27536 size_t count, loff_t * ppos)
27537 {
27538 struct list_head *node, *next;
27539 - char strbuf[5];
27540 - char str[5] = "";
27541 - unsigned int len = count;
27542 + char strbuf[5] = {0};
27543
27544 - if (len > 4)
27545 - len = 4;
27546 - if (len < 0)
27547 + if (count > 4)
27548 + count = 4;
27549 + if (copy_from_user(strbuf, buffer, count))
27550 return -EFAULT;
27551 -
27552 - if (copy_from_user(strbuf, buffer, len))
27553 - return -EFAULT;
27554 - strbuf[len] = '\0';
27555 - sscanf(strbuf, "%s", str);
27556 + strbuf[count] = '\0';
27557
27558 mutex_lock(&acpi_device_lock);
27559 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27560 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27561 if (!dev->wakeup.flags.valid)
27562 continue;
27563
27564 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27565 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27566 if (device_can_wakeup(&dev->dev)) {
27567 bool enable = !device_may_wakeup(&dev->dev);
27568 device_set_wakeup_enable(&dev->dev, enable);
27569 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27570 index 0734086..3ad3e4c 100644
27571 --- a/drivers/acpi/processor_driver.c
27572 +++ b/drivers/acpi/processor_driver.c
27573 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27574 return 0;
27575 #endif
27576
27577 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27578 + BUG_ON(pr->id >= nr_cpu_ids);
27579
27580 /*
27581 * Buggy BIOS check
27582 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27583 index cece3a4..0845256 100644
27584 --- a/drivers/ata/libata-core.c
27585 +++ b/drivers/ata/libata-core.c
27586 @@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27587 struct ata_port *ap;
27588 unsigned int tag;
27589
27590 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27591 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27592 ap = qc->ap;
27593
27594 qc->flags = 0;
27595 @@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27596 struct ata_port *ap;
27597 struct ata_link *link;
27598
27599 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27600 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27601 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27602 ap = qc->ap;
27603 link = qc->dev->link;
27604 @@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27605 return;
27606
27607 spin_lock(&lock);
27608 + pax_open_kernel();
27609
27610 for (cur = ops->inherits; cur; cur = cur->inherits) {
27611 void **inherit = (void **)cur;
27612 @@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27613 if (IS_ERR(*pp))
27614 *pp = NULL;
27615
27616 - ops->inherits = NULL;
27617 + *(struct ata_port_operations **)&ops->inherits = NULL;
27618
27619 + pax_close_kernel();
27620 spin_unlock(&lock);
27621 }
27622
27623 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27624 index ac6a5be..c7176b1 100644
27625 --- a/drivers/ata/pata_arasan_cf.c
27626 +++ b/drivers/ata/pata_arasan_cf.c
27627 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27628 /* Handle platform specific quirks */
27629 if (pdata->quirk) {
27630 if (pdata->quirk & CF_BROKEN_PIO) {
27631 - ap->ops->set_piomode = NULL;
27632 + pax_open_kernel();
27633 + *(void **)&ap->ops->set_piomode = NULL;
27634 + pax_close_kernel();
27635 ap->pio_mask = 0;
27636 }
27637 if (pdata->quirk & CF_BROKEN_MWDMA)
27638 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27639 index f9b983a..887b9d8 100644
27640 --- a/drivers/atm/adummy.c
27641 +++ b/drivers/atm/adummy.c
27642 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27643 vcc->pop(vcc, skb);
27644 else
27645 dev_kfree_skb_any(skb);
27646 - atomic_inc(&vcc->stats->tx);
27647 + atomic_inc_unchecked(&vcc->stats->tx);
27648
27649 return 0;
27650 }
27651 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27652 index 89b30f3..7964211 100644
27653 --- a/drivers/atm/ambassador.c
27654 +++ b/drivers/atm/ambassador.c
27655 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27656 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27657
27658 // VC layer stats
27659 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27660 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27661
27662 // free the descriptor
27663 kfree (tx_descr);
27664 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27665 dump_skb ("<<<", vc, skb);
27666
27667 // VC layer stats
27668 - atomic_inc(&atm_vcc->stats->rx);
27669 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27670 __net_timestamp(skb);
27671 // end of our responsibility
27672 atm_vcc->push (atm_vcc, skb);
27673 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27674 } else {
27675 PRINTK (KERN_INFO, "dropped over-size frame");
27676 // should we count this?
27677 - atomic_inc(&atm_vcc->stats->rx_drop);
27678 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27679 }
27680
27681 } else {
27682 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27683 }
27684
27685 if (check_area (skb->data, skb->len)) {
27686 - atomic_inc(&atm_vcc->stats->tx_err);
27687 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27688 return -ENOMEM; // ?
27689 }
27690
27691 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27692 index b22d71c..d6e1049 100644
27693 --- a/drivers/atm/atmtcp.c
27694 +++ b/drivers/atm/atmtcp.c
27695 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27696 if (vcc->pop) vcc->pop(vcc,skb);
27697 else dev_kfree_skb(skb);
27698 if (dev_data) return 0;
27699 - atomic_inc(&vcc->stats->tx_err);
27700 + atomic_inc_unchecked(&vcc->stats->tx_err);
27701 return -ENOLINK;
27702 }
27703 size = skb->len+sizeof(struct atmtcp_hdr);
27704 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27705 if (!new_skb) {
27706 if (vcc->pop) vcc->pop(vcc,skb);
27707 else dev_kfree_skb(skb);
27708 - atomic_inc(&vcc->stats->tx_err);
27709 + atomic_inc_unchecked(&vcc->stats->tx_err);
27710 return -ENOBUFS;
27711 }
27712 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27713 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27714 if (vcc->pop) vcc->pop(vcc,skb);
27715 else dev_kfree_skb(skb);
27716 out_vcc->push(out_vcc,new_skb);
27717 - atomic_inc(&vcc->stats->tx);
27718 - atomic_inc(&out_vcc->stats->rx);
27719 + atomic_inc_unchecked(&vcc->stats->tx);
27720 + atomic_inc_unchecked(&out_vcc->stats->rx);
27721 return 0;
27722 }
27723
27724 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27725 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27726 read_unlock(&vcc_sklist_lock);
27727 if (!out_vcc) {
27728 - atomic_inc(&vcc->stats->tx_err);
27729 + atomic_inc_unchecked(&vcc->stats->tx_err);
27730 goto done;
27731 }
27732 skb_pull(skb,sizeof(struct atmtcp_hdr));
27733 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27734 __net_timestamp(new_skb);
27735 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27736 out_vcc->push(out_vcc,new_skb);
27737 - atomic_inc(&vcc->stats->tx);
27738 - atomic_inc(&out_vcc->stats->rx);
27739 + atomic_inc_unchecked(&vcc->stats->tx);
27740 + atomic_inc_unchecked(&out_vcc->stats->rx);
27741 done:
27742 if (vcc->pop) vcc->pop(vcc,skb);
27743 else dev_kfree_skb(skb);
27744 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27745 index 2059ee4..faf51c7 100644
27746 --- a/drivers/atm/eni.c
27747 +++ b/drivers/atm/eni.c
27748 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27749 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27750 vcc->dev->number);
27751 length = 0;
27752 - atomic_inc(&vcc->stats->rx_err);
27753 + atomic_inc_unchecked(&vcc->stats->rx_err);
27754 }
27755 else {
27756 length = ATM_CELL_SIZE-1; /* no HEC */
27757 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27758 size);
27759 }
27760 eff = length = 0;
27761 - atomic_inc(&vcc->stats->rx_err);
27762 + atomic_inc_unchecked(&vcc->stats->rx_err);
27763 }
27764 else {
27765 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27766 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27767 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27768 vcc->dev->number,vcc->vci,length,size << 2,descr);
27769 length = eff = 0;
27770 - atomic_inc(&vcc->stats->rx_err);
27771 + atomic_inc_unchecked(&vcc->stats->rx_err);
27772 }
27773 }
27774 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27775 @@ -767,7 +767,7 @@ rx_dequeued++;
27776 vcc->push(vcc,skb);
27777 pushed++;
27778 }
27779 - atomic_inc(&vcc->stats->rx);
27780 + atomic_inc_unchecked(&vcc->stats->rx);
27781 }
27782 wake_up(&eni_dev->rx_wait);
27783 }
27784 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27785 PCI_DMA_TODEVICE);
27786 if (vcc->pop) vcc->pop(vcc,skb);
27787 else dev_kfree_skb_irq(skb);
27788 - atomic_inc(&vcc->stats->tx);
27789 + atomic_inc_unchecked(&vcc->stats->tx);
27790 wake_up(&eni_dev->tx_wait);
27791 dma_complete++;
27792 }
27793 @@ -1567,7 +1567,7 @@ tx_complete++;
27794 /*--------------------------------- entries ---------------------------------*/
27795
27796
27797 -static const char *media_name[] __devinitdata = {
27798 +static const char *media_name[] __devinitconst = {
27799 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27800 "UTP", "05?", "06?", "07?", /* 4- 7 */
27801 "TAXI","09?", "10?", "11?", /* 8-11 */
27802 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27803 index 86fed1b..6dc4721 100644
27804 --- a/drivers/atm/firestream.c
27805 +++ b/drivers/atm/firestream.c
27806 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27807 }
27808 }
27809
27810 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27811 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27812
27813 fs_dprintk (FS_DEBUG_TXMEM, "i");
27814 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27815 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27816 #endif
27817 skb_put (skb, qe->p1 & 0xffff);
27818 ATM_SKB(skb)->vcc = atm_vcc;
27819 - atomic_inc(&atm_vcc->stats->rx);
27820 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27821 __net_timestamp(skb);
27822 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27823 atm_vcc->push (atm_vcc, skb);
27824 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27825 kfree (pe);
27826 }
27827 if (atm_vcc)
27828 - atomic_inc(&atm_vcc->stats->rx_drop);
27829 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27830 break;
27831 case 0x1f: /* Reassembly abort: no buffers. */
27832 /* Silently increment error counter. */
27833 if (atm_vcc)
27834 - atomic_inc(&atm_vcc->stats->rx_drop);
27835 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27836 break;
27837 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27838 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27839 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27840 index 361f5ae..7fc552d 100644
27841 --- a/drivers/atm/fore200e.c
27842 +++ b/drivers/atm/fore200e.c
27843 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27844 #endif
27845 /* check error condition */
27846 if (*entry->status & STATUS_ERROR)
27847 - atomic_inc(&vcc->stats->tx_err);
27848 + atomic_inc_unchecked(&vcc->stats->tx_err);
27849 else
27850 - atomic_inc(&vcc->stats->tx);
27851 + atomic_inc_unchecked(&vcc->stats->tx);
27852 }
27853 }
27854
27855 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27856 if (skb == NULL) {
27857 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27858
27859 - atomic_inc(&vcc->stats->rx_drop);
27860 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27861 return -ENOMEM;
27862 }
27863
27864 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27865
27866 dev_kfree_skb_any(skb);
27867
27868 - atomic_inc(&vcc->stats->rx_drop);
27869 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27870 return -ENOMEM;
27871 }
27872
27873 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27874
27875 vcc->push(vcc, skb);
27876 - atomic_inc(&vcc->stats->rx);
27877 + atomic_inc_unchecked(&vcc->stats->rx);
27878
27879 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27880
27881 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27882 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27883 fore200e->atm_dev->number,
27884 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27885 - atomic_inc(&vcc->stats->rx_err);
27886 + atomic_inc_unchecked(&vcc->stats->rx_err);
27887 }
27888 }
27889
27890 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27891 goto retry_here;
27892 }
27893
27894 - atomic_inc(&vcc->stats->tx_err);
27895 + atomic_inc_unchecked(&vcc->stats->tx_err);
27896
27897 fore200e->tx_sat++;
27898 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27899 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27900 index b182c2f..1c6fa8a 100644
27901 --- a/drivers/atm/he.c
27902 +++ b/drivers/atm/he.c
27903 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27904
27905 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27906 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27907 - atomic_inc(&vcc->stats->rx_drop);
27908 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27909 goto return_host_buffers;
27910 }
27911
27912 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27913 RBRQ_LEN_ERR(he_dev->rbrq_head)
27914 ? "LEN_ERR" : "",
27915 vcc->vpi, vcc->vci);
27916 - atomic_inc(&vcc->stats->rx_err);
27917 + atomic_inc_unchecked(&vcc->stats->rx_err);
27918 goto return_host_buffers;
27919 }
27920
27921 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27922 vcc->push(vcc, skb);
27923 spin_lock(&he_dev->global_lock);
27924
27925 - atomic_inc(&vcc->stats->rx);
27926 + atomic_inc_unchecked(&vcc->stats->rx);
27927
27928 return_host_buffers:
27929 ++pdus_assembled;
27930 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27931 tpd->vcc->pop(tpd->vcc, tpd->skb);
27932 else
27933 dev_kfree_skb_any(tpd->skb);
27934 - atomic_inc(&tpd->vcc->stats->tx_err);
27935 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27936 }
27937 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27938 return;
27939 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27940 vcc->pop(vcc, skb);
27941 else
27942 dev_kfree_skb_any(skb);
27943 - atomic_inc(&vcc->stats->tx_err);
27944 + atomic_inc_unchecked(&vcc->stats->tx_err);
27945 return -EINVAL;
27946 }
27947
27948 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27949 vcc->pop(vcc, skb);
27950 else
27951 dev_kfree_skb_any(skb);
27952 - atomic_inc(&vcc->stats->tx_err);
27953 + atomic_inc_unchecked(&vcc->stats->tx_err);
27954 return -EINVAL;
27955 }
27956 #endif
27957 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27958 vcc->pop(vcc, skb);
27959 else
27960 dev_kfree_skb_any(skb);
27961 - atomic_inc(&vcc->stats->tx_err);
27962 + atomic_inc_unchecked(&vcc->stats->tx_err);
27963 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27964 return -ENOMEM;
27965 }
27966 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27967 vcc->pop(vcc, skb);
27968 else
27969 dev_kfree_skb_any(skb);
27970 - atomic_inc(&vcc->stats->tx_err);
27971 + atomic_inc_unchecked(&vcc->stats->tx_err);
27972 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27973 return -ENOMEM;
27974 }
27975 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27976 __enqueue_tpd(he_dev, tpd, cid);
27977 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27978
27979 - atomic_inc(&vcc->stats->tx);
27980 + atomic_inc_unchecked(&vcc->stats->tx);
27981
27982 return 0;
27983 }
27984 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27985 index 7d01c2a..4e3ac01 100644
27986 --- a/drivers/atm/horizon.c
27987 +++ b/drivers/atm/horizon.c
27988 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27989 {
27990 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27991 // VC layer stats
27992 - atomic_inc(&vcc->stats->rx);
27993 + atomic_inc_unchecked(&vcc->stats->rx);
27994 __net_timestamp(skb);
27995 // end of our responsibility
27996 vcc->push (vcc, skb);
27997 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27998 dev->tx_iovec = NULL;
27999
28000 // VC layer stats
28001 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28002 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28003
28004 // free the skb
28005 hrz_kfree_skb (skb);
28006 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28007 index 8974bd2..b856f85 100644
28008 --- a/drivers/atm/idt77252.c
28009 +++ b/drivers/atm/idt77252.c
28010 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28011 else
28012 dev_kfree_skb(skb);
28013
28014 - atomic_inc(&vcc->stats->tx);
28015 + atomic_inc_unchecked(&vcc->stats->tx);
28016 }
28017
28018 atomic_dec(&scq->used);
28019 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28020 if ((sb = dev_alloc_skb(64)) == NULL) {
28021 printk("%s: Can't allocate buffers for aal0.\n",
28022 card->name);
28023 - atomic_add(i, &vcc->stats->rx_drop);
28024 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28025 break;
28026 }
28027 if (!atm_charge(vcc, sb->truesize)) {
28028 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28029 card->name);
28030 - atomic_add(i - 1, &vcc->stats->rx_drop);
28031 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28032 dev_kfree_skb(sb);
28033 break;
28034 }
28035 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28036 ATM_SKB(sb)->vcc = vcc;
28037 __net_timestamp(sb);
28038 vcc->push(vcc, sb);
28039 - atomic_inc(&vcc->stats->rx);
28040 + atomic_inc_unchecked(&vcc->stats->rx);
28041
28042 cell += ATM_CELL_PAYLOAD;
28043 }
28044 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28045 "(CDC: %08x)\n",
28046 card->name, len, rpp->len, readl(SAR_REG_CDC));
28047 recycle_rx_pool_skb(card, rpp);
28048 - atomic_inc(&vcc->stats->rx_err);
28049 + atomic_inc_unchecked(&vcc->stats->rx_err);
28050 return;
28051 }
28052 if (stat & SAR_RSQE_CRC) {
28053 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28054 recycle_rx_pool_skb(card, rpp);
28055 - atomic_inc(&vcc->stats->rx_err);
28056 + atomic_inc_unchecked(&vcc->stats->rx_err);
28057 return;
28058 }
28059 if (skb_queue_len(&rpp->queue) > 1) {
28060 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28061 RXPRINTK("%s: Can't alloc RX skb.\n",
28062 card->name);
28063 recycle_rx_pool_skb(card, rpp);
28064 - atomic_inc(&vcc->stats->rx_err);
28065 + atomic_inc_unchecked(&vcc->stats->rx_err);
28066 return;
28067 }
28068 if (!atm_charge(vcc, skb->truesize)) {
28069 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28070 __net_timestamp(skb);
28071
28072 vcc->push(vcc, skb);
28073 - atomic_inc(&vcc->stats->rx);
28074 + atomic_inc_unchecked(&vcc->stats->rx);
28075
28076 return;
28077 }
28078 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28079 __net_timestamp(skb);
28080
28081 vcc->push(vcc, skb);
28082 - atomic_inc(&vcc->stats->rx);
28083 + atomic_inc_unchecked(&vcc->stats->rx);
28084
28085 if (skb->truesize > SAR_FB_SIZE_3)
28086 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28087 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28088 if (vcc->qos.aal != ATM_AAL0) {
28089 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28090 card->name, vpi, vci);
28091 - atomic_inc(&vcc->stats->rx_drop);
28092 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28093 goto drop;
28094 }
28095
28096 if ((sb = dev_alloc_skb(64)) == NULL) {
28097 printk("%s: Can't allocate buffers for AAL0.\n",
28098 card->name);
28099 - atomic_inc(&vcc->stats->rx_err);
28100 + atomic_inc_unchecked(&vcc->stats->rx_err);
28101 goto drop;
28102 }
28103
28104 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28105 ATM_SKB(sb)->vcc = vcc;
28106 __net_timestamp(sb);
28107 vcc->push(vcc, sb);
28108 - atomic_inc(&vcc->stats->rx);
28109 + atomic_inc_unchecked(&vcc->stats->rx);
28110
28111 drop:
28112 skb_pull(queue, 64);
28113 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28114
28115 if (vc == NULL) {
28116 printk("%s: NULL connection in send().\n", card->name);
28117 - atomic_inc(&vcc->stats->tx_err);
28118 + atomic_inc_unchecked(&vcc->stats->tx_err);
28119 dev_kfree_skb(skb);
28120 return -EINVAL;
28121 }
28122 if (!test_bit(VCF_TX, &vc->flags)) {
28123 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28124 - atomic_inc(&vcc->stats->tx_err);
28125 + atomic_inc_unchecked(&vcc->stats->tx_err);
28126 dev_kfree_skb(skb);
28127 return -EINVAL;
28128 }
28129 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28130 break;
28131 default:
28132 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28133 - atomic_inc(&vcc->stats->tx_err);
28134 + atomic_inc_unchecked(&vcc->stats->tx_err);
28135 dev_kfree_skb(skb);
28136 return -EINVAL;
28137 }
28138
28139 if (skb_shinfo(skb)->nr_frags != 0) {
28140 printk("%s: No scatter-gather yet.\n", card->name);
28141 - atomic_inc(&vcc->stats->tx_err);
28142 + atomic_inc_unchecked(&vcc->stats->tx_err);
28143 dev_kfree_skb(skb);
28144 return -EINVAL;
28145 }
28146 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28147
28148 err = queue_skb(card, vc, skb, oam);
28149 if (err) {
28150 - atomic_inc(&vcc->stats->tx_err);
28151 + atomic_inc_unchecked(&vcc->stats->tx_err);
28152 dev_kfree_skb(skb);
28153 return err;
28154 }
28155 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28156 skb = dev_alloc_skb(64);
28157 if (!skb) {
28158 printk("%s: Out of memory in send_oam().\n", card->name);
28159 - atomic_inc(&vcc->stats->tx_err);
28160 + atomic_inc_unchecked(&vcc->stats->tx_err);
28161 return -ENOMEM;
28162 }
28163 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28164 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28165 index d438601..8b98495 100644
28166 --- a/drivers/atm/iphase.c
28167 +++ b/drivers/atm/iphase.c
28168 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28169 status = (u_short) (buf_desc_ptr->desc_mode);
28170 if (status & (RX_CER | RX_PTE | RX_OFL))
28171 {
28172 - atomic_inc(&vcc->stats->rx_err);
28173 + atomic_inc_unchecked(&vcc->stats->rx_err);
28174 IF_ERR(printk("IA: bad packet, dropping it");)
28175 if (status & RX_CER) {
28176 IF_ERR(printk(" cause: packet CRC error\n");)
28177 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28178 len = dma_addr - buf_addr;
28179 if (len > iadev->rx_buf_sz) {
28180 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28181 - atomic_inc(&vcc->stats->rx_err);
28182 + atomic_inc_unchecked(&vcc->stats->rx_err);
28183 goto out_free_desc;
28184 }
28185
28186 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28187 ia_vcc = INPH_IA_VCC(vcc);
28188 if (ia_vcc == NULL)
28189 {
28190 - atomic_inc(&vcc->stats->rx_err);
28191 + atomic_inc_unchecked(&vcc->stats->rx_err);
28192 atm_return(vcc, skb->truesize);
28193 dev_kfree_skb_any(skb);
28194 goto INCR_DLE;
28195 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28196 if ((length > iadev->rx_buf_sz) || (length >
28197 (skb->len - sizeof(struct cpcs_trailer))))
28198 {
28199 - atomic_inc(&vcc->stats->rx_err);
28200 + atomic_inc_unchecked(&vcc->stats->rx_err);
28201 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28202 length, skb->len);)
28203 atm_return(vcc, skb->truesize);
28204 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28205
28206 IF_RX(printk("rx_dle_intr: skb push");)
28207 vcc->push(vcc,skb);
28208 - atomic_inc(&vcc->stats->rx);
28209 + atomic_inc_unchecked(&vcc->stats->rx);
28210 iadev->rx_pkt_cnt++;
28211 }
28212 INCR_DLE:
28213 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28214 {
28215 struct k_sonet_stats *stats;
28216 stats = &PRIV(_ia_dev[board])->sonet_stats;
28217 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28218 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28219 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28220 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28221 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28222 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28223 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28224 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28225 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28226 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28227 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28228 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28229 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28230 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28231 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28232 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28233 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28234 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28235 }
28236 ia_cmds.status = 0;
28237 break;
28238 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28239 if ((desc == 0) || (desc > iadev->num_tx_desc))
28240 {
28241 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28242 - atomic_inc(&vcc->stats->tx);
28243 + atomic_inc_unchecked(&vcc->stats->tx);
28244 if (vcc->pop)
28245 vcc->pop(vcc, skb);
28246 else
28247 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28248 ATM_DESC(skb) = vcc->vci;
28249 skb_queue_tail(&iadev->tx_dma_q, skb);
28250
28251 - atomic_inc(&vcc->stats->tx);
28252 + atomic_inc_unchecked(&vcc->stats->tx);
28253 iadev->tx_pkt_cnt++;
28254 /* Increment transaction counter */
28255 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28256
28257 #if 0
28258 /* add flow control logic */
28259 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28260 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28261 if (iavcc->vc_desc_cnt > 10) {
28262 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28263 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28264 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28265 index 68c7588..7036683 100644
28266 --- a/drivers/atm/lanai.c
28267 +++ b/drivers/atm/lanai.c
28268 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28269 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28270 lanai_endtx(lanai, lvcc);
28271 lanai_free_skb(lvcc->tx.atmvcc, skb);
28272 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28273 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28274 }
28275
28276 /* Try to fill the buffer - don't call unless there is backlog */
28277 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28278 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28279 __net_timestamp(skb);
28280 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28281 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28282 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28283 out:
28284 lvcc->rx.buf.ptr = end;
28285 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28286 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28287 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28288 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28289 lanai->stats.service_rxnotaal5++;
28290 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28291 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28292 return 0;
28293 }
28294 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28295 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28296 int bytes;
28297 read_unlock(&vcc_sklist_lock);
28298 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28299 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28300 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28301 lvcc->stats.x.aal5.service_trash++;
28302 bytes = (SERVICE_GET_END(s) * 16) -
28303 (((unsigned long) lvcc->rx.buf.ptr) -
28304 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28305 }
28306 if (s & SERVICE_STREAM) {
28307 read_unlock(&vcc_sklist_lock);
28308 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28309 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28310 lvcc->stats.x.aal5.service_stream++;
28311 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28312 "PDU on VCI %d!\n", lanai->number, vci);
28313 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28314 return 0;
28315 }
28316 DPRINTK("got rx crc error on vci %d\n", vci);
28317 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28318 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28319 lvcc->stats.x.aal5.service_rxcrc++;
28320 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28321 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28322 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28323 index 1c70c45..300718d 100644
28324 --- a/drivers/atm/nicstar.c
28325 +++ b/drivers/atm/nicstar.c
28326 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28327 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28328 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28329 card->index);
28330 - atomic_inc(&vcc->stats->tx_err);
28331 + atomic_inc_unchecked(&vcc->stats->tx_err);
28332 dev_kfree_skb_any(skb);
28333 return -EINVAL;
28334 }
28335 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28336 if (!vc->tx) {
28337 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28338 card->index);
28339 - atomic_inc(&vcc->stats->tx_err);
28340 + atomic_inc_unchecked(&vcc->stats->tx_err);
28341 dev_kfree_skb_any(skb);
28342 return -EINVAL;
28343 }
28344 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28345 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28346 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28347 card->index);
28348 - atomic_inc(&vcc->stats->tx_err);
28349 + atomic_inc_unchecked(&vcc->stats->tx_err);
28350 dev_kfree_skb_any(skb);
28351 return -EINVAL;
28352 }
28353
28354 if (skb_shinfo(skb)->nr_frags != 0) {
28355 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28356 - atomic_inc(&vcc->stats->tx_err);
28357 + atomic_inc_unchecked(&vcc->stats->tx_err);
28358 dev_kfree_skb_any(skb);
28359 return -EINVAL;
28360 }
28361 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28362 }
28363
28364 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28365 - atomic_inc(&vcc->stats->tx_err);
28366 + atomic_inc_unchecked(&vcc->stats->tx_err);
28367 dev_kfree_skb_any(skb);
28368 return -EIO;
28369 }
28370 - atomic_inc(&vcc->stats->tx);
28371 + atomic_inc_unchecked(&vcc->stats->tx);
28372
28373 return 0;
28374 }
28375 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28376 printk
28377 ("nicstar%d: Can't allocate buffers for aal0.\n",
28378 card->index);
28379 - atomic_add(i, &vcc->stats->rx_drop);
28380 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28381 break;
28382 }
28383 if (!atm_charge(vcc, sb->truesize)) {
28384 RXPRINTK
28385 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28386 card->index);
28387 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28388 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28389 dev_kfree_skb_any(sb);
28390 break;
28391 }
28392 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28393 ATM_SKB(sb)->vcc = vcc;
28394 __net_timestamp(sb);
28395 vcc->push(vcc, sb);
28396 - atomic_inc(&vcc->stats->rx);
28397 + atomic_inc_unchecked(&vcc->stats->rx);
28398 cell += ATM_CELL_PAYLOAD;
28399 }
28400
28401 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28402 if (iovb == NULL) {
28403 printk("nicstar%d: Out of iovec buffers.\n",
28404 card->index);
28405 - atomic_inc(&vcc->stats->rx_drop);
28406 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28407 recycle_rx_buf(card, skb);
28408 return;
28409 }
28410 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28411 small or large buffer itself. */
28412 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28413 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28414 - atomic_inc(&vcc->stats->rx_err);
28415 + atomic_inc_unchecked(&vcc->stats->rx_err);
28416 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28417 NS_MAX_IOVECS);
28418 NS_PRV_IOVCNT(iovb) = 0;
28419 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28420 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28421 card->index);
28422 which_list(card, skb);
28423 - atomic_inc(&vcc->stats->rx_err);
28424 + atomic_inc_unchecked(&vcc->stats->rx_err);
28425 recycle_rx_buf(card, skb);
28426 vc->rx_iov = NULL;
28427 recycle_iov_buf(card, iovb);
28428 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28429 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28430 card->index);
28431 which_list(card, skb);
28432 - atomic_inc(&vcc->stats->rx_err);
28433 + atomic_inc_unchecked(&vcc->stats->rx_err);
28434 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28435 NS_PRV_IOVCNT(iovb));
28436 vc->rx_iov = NULL;
28437 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28438 printk(" - PDU size mismatch.\n");
28439 else
28440 printk(".\n");
28441 - atomic_inc(&vcc->stats->rx_err);
28442 + atomic_inc_unchecked(&vcc->stats->rx_err);
28443 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28444 NS_PRV_IOVCNT(iovb));
28445 vc->rx_iov = NULL;
28446 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28447 /* skb points to a small buffer */
28448 if (!atm_charge(vcc, skb->truesize)) {
28449 push_rxbufs(card, skb);
28450 - atomic_inc(&vcc->stats->rx_drop);
28451 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28452 } else {
28453 skb_put(skb, len);
28454 dequeue_sm_buf(card, skb);
28455 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28456 ATM_SKB(skb)->vcc = vcc;
28457 __net_timestamp(skb);
28458 vcc->push(vcc, skb);
28459 - atomic_inc(&vcc->stats->rx);
28460 + atomic_inc_unchecked(&vcc->stats->rx);
28461 }
28462 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28463 struct sk_buff *sb;
28464 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28465 if (len <= NS_SMBUFSIZE) {
28466 if (!atm_charge(vcc, sb->truesize)) {
28467 push_rxbufs(card, sb);
28468 - atomic_inc(&vcc->stats->rx_drop);
28469 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28470 } else {
28471 skb_put(sb, len);
28472 dequeue_sm_buf(card, sb);
28473 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28474 ATM_SKB(sb)->vcc = vcc;
28475 __net_timestamp(sb);
28476 vcc->push(vcc, sb);
28477 - atomic_inc(&vcc->stats->rx);
28478 + atomic_inc_unchecked(&vcc->stats->rx);
28479 }
28480
28481 push_rxbufs(card, skb);
28482 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28483
28484 if (!atm_charge(vcc, skb->truesize)) {
28485 push_rxbufs(card, skb);
28486 - atomic_inc(&vcc->stats->rx_drop);
28487 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28488 } else {
28489 dequeue_lg_buf(card, skb);
28490 #ifdef NS_USE_DESTRUCTORS
28491 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28492 ATM_SKB(skb)->vcc = vcc;
28493 __net_timestamp(skb);
28494 vcc->push(vcc, skb);
28495 - atomic_inc(&vcc->stats->rx);
28496 + atomic_inc_unchecked(&vcc->stats->rx);
28497 }
28498
28499 push_rxbufs(card, sb);
28500 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28501 printk
28502 ("nicstar%d: Out of huge buffers.\n",
28503 card->index);
28504 - atomic_inc(&vcc->stats->rx_drop);
28505 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28506 recycle_iovec_rx_bufs(card,
28507 (struct iovec *)
28508 iovb->data,
28509 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28510 card->hbpool.count++;
28511 } else
28512 dev_kfree_skb_any(hb);
28513 - atomic_inc(&vcc->stats->rx_drop);
28514 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28515 } else {
28516 /* Copy the small buffer to the huge buffer */
28517 sb = (struct sk_buff *)iov->iov_base;
28518 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28519 #endif /* NS_USE_DESTRUCTORS */
28520 __net_timestamp(hb);
28521 vcc->push(vcc, hb);
28522 - atomic_inc(&vcc->stats->rx);
28523 + atomic_inc_unchecked(&vcc->stats->rx);
28524 }
28525 }
28526
28527 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28528 index 9851093..adb2b1e 100644
28529 --- a/drivers/atm/solos-pci.c
28530 +++ b/drivers/atm/solos-pci.c
28531 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28532 }
28533 atm_charge(vcc, skb->truesize);
28534 vcc->push(vcc, skb);
28535 - atomic_inc(&vcc->stats->rx);
28536 + atomic_inc_unchecked(&vcc->stats->rx);
28537 break;
28538
28539 case PKT_STATUS:
28540 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28541 vcc = SKB_CB(oldskb)->vcc;
28542
28543 if (vcc) {
28544 - atomic_inc(&vcc->stats->tx);
28545 + atomic_inc_unchecked(&vcc->stats->tx);
28546 solos_pop(vcc, oldskb);
28547 } else
28548 dev_kfree_skb_irq(oldskb);
28549 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28550 index 0215934..ce9f5b1 100644
28551 --- a/drivers/atm/suni.c
28552 +++ b/drivers/atm/suni.c
28553 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28554
28555
28556 #define ADD_LIMITED(s,v) \
28557 - atomic_add((v),&stats->s); \
28558 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28559 + atomic_add_unchecked((v),&stats->s); \
28560 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28561
28562
28563 static void suni_hz(unsigned long from_timer)
28564 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28565 index 5120a96..e2572bd 100644
28566 --- a/drivers/atm/uPD98402.c
28567 +++ b/drivers/atm/uPD98402.c
28568 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28569 struct sonet_stats tmp;
28570 int error = 0;
28571
28572 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28573 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28574 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28575 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28576 if (zero && !error) {
28577 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28578
28579
28580 #define ADD_LIMITED(s,v) \
28581 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28582 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28583 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28584 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28585 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28586 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28587
28588
28589 static void stat_event(struct atm_dev *dev)
28590 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28591 if (reason & uPD98402_INT_PFM) stat_event(dev);
28592 if (reason & uPD98402_INT_PCO) {
28593 (void) GET(PCOCR); /* clear interrupt cause */
28594 - atomic_add(GET(HECCT),
28595 + atomic_add_unchecked(GET(HECCT),
28596 &PRIV(dev)->sonet_stats.uncorr_hcs);
28597 }
28598 if ((reason & uPD98402_INT_RFO) &&
28599 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28600 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28601 uPD98402_INT_LOS),PIMR); /* enable them */
28602 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28603 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28604 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28605 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28606 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28607 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28608 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28609 return 0;
28610 }
28611
28612 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28613 index abe4e20..83c4727 100644
28614 --- a/drivers/atm/zatm.c
28615 +++ b/drivers/atm/zatm.c
28616 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28617 }
28618 if (!size) {
28619 dev_kfree_skb_irq(skb);
28620 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28621 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28622 continue;
28623 }
28624 if (!atm_charge(vcc,skb->truesize)) {
28625 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28626 skb->len = size;
28627 ATM_SKB(skb)->vcc = vcc;
28628 vcc->push(vcc,skb);
28629 - atomic_inc(&vcc->stats->rx);
28630 + atomic_inc_unchecked(&vcc->stats->rx);
28631 }
28632 zout(pos & 0xffff,MTA(mbx));
28633 #if 0 /* probably a stupid idea */
28634 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28635 skb_queue_head(&zatm_vcc->backlog,skb);
28636 break;
28637 }
28638 - atomic_inc(&vcc->stats->tx);
28639 + atomic_inc_unchecked(&vcc->stats->tx);
28640 wake_up(&zatm_vcc->tx_wait);
28641 }
28642
28643 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28644 index 765c3a2..771ace6 100644
28645 --- a/drivers/base/devtmpfs.c
28646 +++ b/drivers/base/devtmpfs.c
28647 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28648 if (!thread)
28649 return 0;
28650
28651 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28652 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28653 if (err)
28654 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28655 else
28656 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28657 index cbb463b..babe2cf 100644
28658 --- a/drivers/base/power/wakeup.c
28659 +++ b/drivers/base/power/wakeup.c
28660 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28661 * They need to be modified together atomically, so it's better to use one
28662 * atomic variable to hold them both.
28663 */
28664 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28665 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28666
28667 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28668 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28669
28670 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28671 {
28672 - unsigned int comb = atomic_read(&combined_event_count);
28673 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28674
28675 *cnt = (comb >> IN_PROGRESS_BITS);
28676 *inpr = comb & MAX_IN_PROGRESS;
28677 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28678 ws->start_prevent_time = ws->last_time;
28679
28680 /* Increment the counter of events in progress. */
28681 - cec = atomic_inc_return(&combined_event_count);
28682 + cec = atomic_inc_return_unchecked(&combined_event_count);
28683
28684 trace_wakeup_source_activate(ws->name, cec);
28685 }
28686 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28687 * Increment the counter of registered wakeup events and decrement the
28688 * couter of wakeup events in progress simultaneously.
28689 */
28690 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28691 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28692 trace_wakeup_source_deactivate(ws->name, cec);
28693
28694 split_counters(&cnt, &inpr);
28695 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28696 index b0f553b..77b928b 100644
28697 --- a/drivers/block/cciss.c
28698 +++ b/drivers/block/cciss.c
28699 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28700 int err;
28701 u32 cp;
28702
28703 + memset(&arg64, 0, sizeof(arg64));
28704 +
28705 err = 0;
28706 err |=
28707 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28708 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28709 while (!list_empty(&h->reqQ)) {
28710 c = list_entry(h->reqQ.next, CommandList_struct, list);
28711 /* can't do anything if fifo is full */
28712 - if ((h->access.fifo_full(h))) {
28713 + if ((h->access->fifo_full(h))) {
28714 dev_warn(&h->pdev->dev, "fifo full\n");
28715 break;
28716 }
28717 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28718 h->Qdepth--;
28719
28720 /* Tell the controller execute command */
28721 - h->access.submit_command(h, c);
28722 + h->access->submit_command(h, c);
28723
28724 /* Put job onto the completed Q */
28725 addQ(&h->cmpQ, c);
28726 @@ -3443,17 +3445,17 @@ startio:
28727
28728 static inline unsigned long get_next_completion(ctlr_info_t *h)
28729 {
28730 - return h->access.command_completed(h);
28731 + return h->access->command_completed(h);
28732 }
28733
28734 static inline int interrupt_pending(ctlr_info_t *h)
28735 {
28736 - return h->access.intr_pending(h);
28737 + return h->access->intr_pending(h);
28738 }
28739
28740 static inline long interrupt_not_for_us(ctlr_info_t *h)
28741 {
28742 - return ((h->access.intr_pending(h) == 0) ||
28743 + return ((h->access->intr_pending(h) == 0) ||
28744 (h->interrupts_enabled == 0));
28745 }
28746
28747 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28748 u32 a;
28749
28750 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28751 - return h->access.command_completed(h);
28752 + return h->access->command_completed(h);
28753
28754 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28755 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28756 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28757 trans_support & CFGTBL_Trans_use_short_tags);
28758
28759 /* Change the access methods to the performant access methods */
28760 - h->access = SA5_performant_access;
28761 + h->access = &SA5_performant_access;
28762 h->transMethod = CFGTBL_Trans_Performant;
28763
28764 return;
28765 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28766 if (prod_index < 0)
28767 return -ENODEV;
28768 h->product_name = products[prod_index].product_name;
28769 - h->access = *(products[prod_index].access);
28770 + h->access = products[prod_index].access;
28771
28772 if (cciss_board_disabled(h)) {
28773 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28774 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28775 }
28776
28777 /* make sure the board interrupts are off */
28778 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28779 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28780 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28781 if (rc)
28782 goto clean2;
28783 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28784 * fake ones to scoop up any residual completions.
28785 */
28786 spin_lock_irqsave(&h->lock, flags);
28787 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28788 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28789 spin_unlock_irqrestore(&h->lock, flags);
28790 free_irq(h->intr[h->intr_mode], h);
28791 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28792 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28793 dev_info(&h->pdev->dev, "Board READY.\n");
28794 dev_info(&h->pdev->dev,
28795 "Waiting for stale completions to drain.\n");
28796 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28797 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28798 msleep(10000);
28799 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28800 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28801
28802 rc = controller_reset_failed(h->cfgtable);
28803 if (rc)
28804 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28805 cciss_scsi_setup(h);
28806
28807 /* Turn the interrupts on so we can service requests */
28808 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28809 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28810
28811 /* Get the firmware version */
28812 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28813 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28814 kfree(flush_buf);
28815 if (return_code != IO_OK)
28816 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28817 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28818 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28819 free_irq(h->intr[h->intr_mode], h);
28820 }
28821
28822 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28823 index 7fda30e..eb5dfe0 100644
28824 --- a/drivers/block/cciss.h
28825 +++ b/drivers/block/cciss.h
28826 @@ -101,7 +101,7 @@ struct ctlr_info
28827 /* information about each logical volume */
28828 drive_info_struct *drv[CISS_MAX_LUN];
28829
28830 - struct access_method access;
28831 + struct access_method *access;
28832
28833 /* queue and queue Info */
28834 struct list_head reqQ;
28835 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28836 index 9125bbe..eede5c8 100644
28837 --- a/drivers/block/cpqarray.c
28838 +++ b/drivers/block/cpqarray.c
28839 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28840 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28841 goto Enomem4;
28842 }
28843 - hba[i]->access.set_intr_mask(hba[i], 0);
28844 + hba[i]->access->set_intr_mask(hba[i], 0);
28845 if (request_irq(hba[i]->intr, do_ida_intr,
28846 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28847 {
28848 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28849 add_timer(&hba[i]->timer);
28850
28851 /* Enable IRQ now that spinlock and rate limit timer are set up */
28852 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28853 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28854
28855 for(j=0; j<NWD; j++) {
28856 struct gendisk *disk = ida_gendisk[i][j];
28857 @@ -694,7 +694,7 @@ DBGINFO(
28858 for(i=0; i<NR_PRODUCTS; i++) {
28859 if (board_id == products[i].board_id) {
28860 c->product_name = products[i].product_name;
28861 - c->access = *(products[i].access);
28862 + c->access = products[i].access;
28863 break;
28864 }
28865 }
28866 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28867 hba[ctlr]->intr = intr;
28868 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28869 hba[ctlr]->product_name = products[j].product_name;
28870 - hba[ctlr]->access = *(products[j].access);
28871 + hba[ctlr]->access = products[j].access;
28872 hba[ctlr]->ctlr = ctlr;
28873 hba[ctlr]->board_id = board_id;
28874 hba[ctlr]->pci_dev = NULL; /* not PCI */
28875 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28876
28877 while((c = h->reqQ) != NULL) {
28878 /* Can't do anything if we're busy */
28879 - if (h->access.fifo_full(h) == 0)
28880 + if (h->access->fifo_full(h) == 0)
28881 return;
28882
28883 /* Get the first entry from the request Q */
28884 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28885 h->Qdepth--;
28886
28887 /* Tell the controller to do our bidding */
28888 - h->access.submit_command(h, c);
28889 + h->access->submit_command(h, c);
28890
28891 /* Get onto the completion Q */
28892 addQ(&h->cmpQ, c);
28893 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28894 unsigned long flags;
28895 __u32 a,a1;
28896
28897 - istat = h->access.intr_pending(h);
28898 + istat = h->access->intr_pending(h);
28899 /* Is this interrupt for us? */
28900 if (istat == 0)
28901 return IRQ_NONE;
28902 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28903 */
28904 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28905 if (istat & FIFO_NOT_EMPTY) {
28906 - while((a = h->access.command_completed(h))) {
28907 + while((a = h->access->command_completed(h))) {
28908 a1 = a; a &= ~3;
28909 if ((c = h->cmpQ) == NULL)
28910 {
28911 @@ -1449,11 +1449,11 @@ static int sendcmd(
28912 /*
28913 * Disable interrupt
28914 */
28915 - info_p->access.set_intr_mask(info_p, 0);
28916 + info_p->access->set_intr_mask(info_p, 0);
28917 /* Make sure there is room in the command FIFO */
28918 /* Actually it should be completely empty at this time. */
28919 for (i = 200000; i > 0; i--) {
28920 - temp = info_p->access.fifo_full(info_p);
28921 + temp = info_p->access->fifo_full(info_p);
28922 if (temp != 0) {
28923 break;
28924 }
28925 @@ -1466,7 +1466,7 @@ DBG(
28926 /*
28927 * Send the cmd
28928 */
28929 - info_p->access.submit_command(info_p, c);
28930 + info_p->access->submit_command(info_p, c);
28931 complete = pollcomplete(ctlr);
28932
28933 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28934 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28935 * we check the new geometry. Then turn interrupts back on when
28936 * we're done.
28937 */
28938 - host->access.set_intr_mask(host, 0);
28939 + host->access->set_intr_mask(host, 0);
28940 getgeometry(ctlr);
28941 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28942 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28943
28944 for(i=0; i<NWD; i++) {
28945 struct gendisk *disk = ida_gendisk[ctlr][i];
28946 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28947 /* Wait (up to 2 seconds) for a command to complete */
28948
28949 for (i = 200000; i > 0; i--) {
28950 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28951 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28952 if (done == 0) {
28953 udelay(10); /* a short fixed delay */
28954 } else
28955 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28956 index be73e9d..7fbf140 100644
28957 --- a/drivers/block/cpqarray.h
28958 +++ b/drivers/block/cpqarray.h
28959 @@ -99,7 +99,7 @@ struct ctlr_info {
28960 drv_info_t drv[NWD];
28961 struct proc_dir_entry *proc;
28962
28963 - struct access_method access;
28964 + struct access_method *access;
28965
28966 cmdlist_t *reqQ;
28967 cmdlist_t *cmpQ;
28968 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28969 index 02f013a..afeba24 100644
28970 --- a/drivers/block/drbd/drbd_int.h
28971 +++ b/drivers/block/drbd/drbd_int.h
28972 @@ -735,7 +735,7 @@ struct drbd_request;
28973 struct drbd_epoch {
28974 struct list_head list;
28975 unsigned int barrier_nr;
28976 - atomic_t epoch_size; /* increased on every request added. */
28977 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28978 atomic_t active; /* increased on every req. added, and dec on every finished. */
28979 unsigned long flags;
28980 };
28981 @@ -1110,7 +1110,7 @@ struct drbd_conf {
28982 void *int_dig_in;
28983 void *int_dig_vv;
28984 wait_queue_head_t seq_wait;
28985 - atomic_t packet_seq;
28986 + atomic_unchecked_t packet_seq;
28987 unsigned int peer_seq;
28988 spinlock_t peer_seq_lock;
28989 unsigned int minor;
28990 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28991
28992 static inline void drbd_tcp_cork(struct socket *sock)
28993 {
28994 - int __user val = 1;
28995 + int val = 1;
28996 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28997 - (char __user *)&val, sizeof(val));
28998 + (char __force_user *)&val, sizeof(val));
28999 }
29000
29001 static inline void drbd_tcp_uncork(struct socket *sock)
29002 {
29003 - int __user val = 0;
29004 + int val = 0;
29005 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29006 - (char __user *)&val, sizeof(val));
29007 + (char __force_user *)&val, sizeof(val));
29008 }
29009
29010 static inline void drbd_tcp_nodelay(struct socket *sock)
29011 {
29012 - int __user val = 1;
29013 + int val = 1;
29014 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29015 - (char __user *)&val, sizeof(val));
29016 + (char __force_user *)&val, sizeof(val));
29017 }
29018
29019 static inline void drbd_tcp_quickack(struct socket *sock)
29020 {
29021 - int __user val = 2;
29022 + int val = 2;
29023 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29024 - (char __user *)&val, sizeof(val));
29025 + (char __force_user *)&val, sizeof(val));
29026 }
29027
29028 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29029 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29030 index 920ede2..cb827ba 100644
29031 --- a/drivers/block/drbd/drbd_main.c
29032 +++ b/drivers/block/drbd/drbd_main.c
29033 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29034 p.sector = sector;
29035 p.block_id = block_id;
29036 p.blksize = blksize;
29037 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29038 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29039
29040 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29041 return false;
29042 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29043
29044 p.sector = cpu_to_be64(req->sector);
29045 p.block_id = (unsigned long)req;
29046 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29047 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29048
29049 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29050
29051 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29052 atomic_set(&mdev->unacked_cnt, 0);
29053 atomic_set(&mdev->local_cnt, 0);
29054 atomic_set(&mdev->net_cnt, 0);
29055 - atomic_set(&mdev->packet_seq, 0);
29056 + atomic_set_unchecked(&mdev->packet_seq, 0);
29057 atomic_set(&mdev->pp_in_use, 0);
29058 atomic_set(&mdev->pp_in_use_by_net, 0);
29059 atomic_set(&mdev->rs_sect_in, 0);
29060 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29061 mdev->receiver.t_state);
29062
29063 /* no need to lock it, I'm the only thread alive */
29064 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29065 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29066 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29067 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29068 mdev->al_writ_cnt =
29069 mdev->bm_writ_cnt =
29070 mdev->read_cnt =
29071 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29072 index 6d4de6a..7b7ad4b 100644
29073 --- a/drivers/block/drbd/drbd_nl.c
29074 +++ b/drivers/block/drbd/drbd_nl.c
29075 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29076 module_put(THIS_MODULE);
29077 }
29078
29079 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29080 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29081
29082 static unsigned short *
29083 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29084 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29085 cn_reply->id.idx = CN_IDX_DRBD;
29086 cn_reply->id.val = CN_VAL_DRBD;
29087
29088 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29089 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29090 cn_reply->ack = 0; /* not used here. */
29091 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29092 (int)((char *)tl - (char *)reply->tag_list);
29093 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29094 cn_reply->id.idx = CN_IDX_DRBD;
29095 cn_reply->id.val = CN_VAL_DRBD;
29096
29097 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29098 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29099 cn_reply->ack = 0; /* not used here. */
29100 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29101 (int)((char *)tl - (char *)reply->tag_list);
29102 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29103 cn_reply->id.idx = CN_IDX_DRBD;
29104 cn_reply->id.val = CN_VAL_DRBD;
29105
29106 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29107 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29108 cn_reply->ack = 0; // not used here.
29109 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29110 (int)((char*)tl - (char*)reply->tag_list);
29111 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29112 cn_reply->id.idx = CN_IDX_DRBD;
29113 cn_reply->id.val = CN_VAL_DRBD;
29114
29115 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29116 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29117 cn_reply->ack = 0; /* not used here. */
29118 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29119 (int)((char *)tl - (char *)reply->tag_list);
29120 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29121 index ea4836e..272d72a 100644
29122 --- a/drivers/block/drbd/drbd_receiver.c
29123 +++ b/drivers/block/drbd/drbd_receiver.c
29124 @@ -893,7 +893,7 @@ retry:
29125 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29126 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29127
29128 - atomic_set(&mdev->packet_seq, 0);
29129 + atomic_set_unchecked(&mdev->packet_seq, 0);
29130 mdev->peer_seq = 0;
29131
29132 if (drbd_send_protocol(mdev) == -1)
29133 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29134 do {
29135 next_epoch = NULL;
29136
29137 - epoch_size = atomic_read(&epoch->epoch_size);
29138 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29139
29140 switch (ev & ~EV_CLEANUP) {
29141 case EV_PUT:
29142 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29143 rv = FE_DESTROYED;
29144 } else {
29145 epoch->flags = 0;
29146 - atomic_set(&epoch->epoch_size, 0);
29147 + atomic_set_unchecked(&epoch->epoch_size, 0);
29148 /* atomic_set(&epoch->active, 0); is already zero */
29149 if (rv == FE_STILL_LIVE)
29150 rv = FE_RECYCLED;
29151 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29152 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29153 drbd_flush(mdev);
29154
29155 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29156 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29157 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29158 if (epoch)
29159 break;
29160 }
29161
29162 epoch = mdev->current_epoch;
29163 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29164 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29165
29166 D_ASSERT(atomic_read(&epoch->active) == 0);
29167 D_ASSERT(epoch->flags == 0);
29168 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29169 }
29170
29171 epoch->flags = 0;
29172 - atomic_set(&epoch->epoch_size, 0);
29173 + atomic_set_unchecked(&epoch->epoch_size, 0);
29174 atomic_set(&epoch->active, 0);
29175
29176 spin_lock(&mdev->epoch_lock);
29177 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29178 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29179 list_add(&epoch->list, &mdev->current_epoch->list);
29180 mdev->current_epoch = epoch;
29181 mdev->epochs++;
29182 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29183 spin_unlock(&mdev->peer_seq_lock);
29184
29185 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29186 - atomic_inc(&mdev->current_epoch->epoch_size);
29187 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29188 return drbd_drain_block(mdev, data_size);
29189 }
29190
29191 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29192
29193 spin_lock(&mdev->epoch_lock);
29194 e->epoch = mdev->current_epoch;
29195 - atomic_inc(&e->epoch->epoch_size);
29196 + atomic_inc_unchecked(&e->epoch->epoch_size);
29197 atomic_inc(&e->epoch->active);
29198 spin_unlock(&mdev->epoch_lock);
29199
29200 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29201 D_ASSERT(list_empty(&mdev->done_ee));
29202
29203 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29204 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29205 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29206 D_ASSERT(list_empty(&mdev->current_epoch->list));
29207 }
29208
29209 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29210 index 3bba655..6151b66 100644
29211 --- a/drivers/block/loop.c
29212 +++ b/drivers/block/loop.c
29213 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29214 mm_segment_t old_fs = get_fs();
29215
29216 set_fs(get_ds());
29217 - bw = file->f_op->write(file, buf, len, &pos);
29218 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29219 set_fs(old_fs);
29220 if (likely(bw == len))
29221 return 0;
29222 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29223 index ea6f632..eafb192 100644
29224 --- a/drivers/char/Kconfig
29225 +++ b/drivers/char/Kconfig
29226 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29227
29228 config DEVKMEM
29229 bool "/dev/kmem virtual device support"
29230 - default y
29231 + default n
29232 + depends on !GRKERNSEC_KMEM
29233 help
29234 Say Y here if you want to support the /dev/kmem device. The
29235 /dev/kmem device is rarely used, but can be used for certain
29236 @@ -581,6 +582,7 @@ config DEVPORT
29237 bool
29238 depends on !M68K
29239 depends on ISA || PCI
29240 + depends on !GRKERNSEC_KMEM
29241 default y
29242
29243 source "drivers/s390/char/Kconfig"
29244 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29245 index 2e04433..22afc64 100644
29246 --- a/drivers/char/agp/frontend.c
29247 +++ b/drivers/char/agp/frontend.c
29248 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29249 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29250 return -EFAULT;
29251
29252 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29253 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29254 return -EFAULT;
29255
29256 client = agp_find_client_by_pid(reserve.pid);
29257 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29258 index 21cb980..f15107c 100644
29259 --- a/drivers/char/genrtc.c
29260 +++ b/drivers/char/genrtc.c
29261 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29262 switch (cmd) {
29263
29264 case RTC_PLL_GET:
29265 + memset(&pll, 0, sizeof(pll));
29266 if (get_rtc_pll(&pll))
29267 return -EINVAL;
29268 else
29269 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29270 index dfd7876..c0b0885 100644
29271 --- a/drivers/char/hpet.c
29272 +++ b/drivers/char/hpet.c
29273 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29274 }
29275
29276 static int
29277 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29278 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29279 struct hpet_info *info)
29280 {
29281 struct hpet_timer __iomem *timer;
29282 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29283 index 2c29942..604c5ba 100644
29284 --- a/drivers/char/ipmi/ipmi_msghandler.c
29285 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29286 @@ -420,7 +420,7 @@ struct ipmi_smi {
29287 struct proc_dir_entry *proc_dir;
29288 char proc_dir_name[10];
29289
29290 - atomic_t stats[IPMI_NUM_STATS];
29291 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29292
29293 /*
29294 * run_to_completion duplicate of smb_info, smi_info
29295 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29296
29297
29298 #define ipmi_inc_stat(intf, stat) \
29299 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29300 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29301 #define ipmi_get_stat(intf, stat) \
29302 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29303 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29304
29305 static int is_lan_addr(struct ipmi_addr *addr)
29306 {
29307 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29308 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29309 init_waitqueue_head(&intf->waitq);
29310 for (i = 0; i < IPMI_NUM_STATS; i++)
29311 - atomic_set(&intf->stats[i], 0);
29312 + atomic_set_unchecked(&intf->stats[i], 0);
29313
29314 intf->proc_dir = NULL;
29315
29316 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29317 index 1e638ff..a869ef5 100644
29318 --- a/drivers/char/ipmi/ipmi_si_intf.c
29319 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29320 @@ -275,7 +275,7 @@ struct smi_info {
29321 unsigned char slave_addr;
29322
29323 /* Counters and things for the proc filesystem. */
29324 - atomic_t stats[SI_NUM_STATS];
29325 + atomic_unchecked_t stats[SI_NUM_STATS];
29326
29327 struct task_struct *thread;
29328
29329 @@ -284,9 +284,9 @@ struct smi_info {
29330 };
29331
29332 #define smi_inc_stat(smi, stat) \
29333 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29334 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29335 #define smi_get_stat(smi, stat) \
29336 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29337 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29338
29339 #define SI_MAX_PARMS 4
29340
29341 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29342 atomic_set(&new_smi->req_events, 0);
29343 new_smi->run_to_completion = 0;
29344 for (i = 0; i < SI_NUM_STATS; i++)
29345 - atomic_set(&new_smi->stats[i], 0);
29346 + atomic_set_unchecked(&new_smi->stats[i], 0);
29347
29348 new_smi->interrupt_disabled = 1;
29349 atomic_set(&new_smi->stop_operation, 0);
29350 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29351 index 47ff7e4..0c7d340 100644
29352 --- a/drivers/char/mbcs.c
29353 +++ b/drivers/char/mbcs.c
29354 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29355 return 0;
29356 }
29357
29358 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29359 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29360 {
29361 .part_num = MBCS_PART_NUM,
29362 .mfg_num = MBCS_MFG_NUM,
29363 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29364 index 67c3371..ba8429d 100644
29365 --- a/drivers/char/mem.c
29366 +++ b/drivers/char/mem.c
29367 @@ -18,6 +18,7 @@
29368 #include <linux/raw.h>
29369 #include <linux/tty.h>
29370 #include <linux/capability.h>
29371 +#include <linux/security.h>
29372 #include <linux/ptrace.h>
29373 #include <linux/device.h>
29374 #include <linux/highmem.h>
29375 @@ -35,6 +36,10 @@
29376 # include <linux/efi.h>
29377 #endif
29378
29379 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29380 +extern const struct file_operations grsec_fops;
29381 +#endif
29382 +
29383 static inline unsigned long size_inside_page(unsigned long start,
29384 unsigned long size)
29385 {
29386 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29387
29388 while (cursor < to) {
29389 if (!devmem_is_allowed(pfn)) {
29390 +#ifdef CONFIG_GRKERNSEC_KMEM
29391 + gr_handle_mem_readwrite(from, to);
29392 +#else
29393 printk(KERN_INFO
29394 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29395 current->comm, from, to);
29396 +#endif
29397 return 0;
29398 }
29399 cursor += PAGE_SIZE;
29400 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29401 }
29402 return 1;
29403 }
29404 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29405 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29406 +{
29407 + return 0;
29408 +}
29409 #else
29410 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29411 {
29412 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29413
29414 while (count > 0) {
29415 unsigned long remaining;
29416 + char *temp;
29417
29418 sz = size_inside_page(p, count);
29419
29420 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29421 if (!ptr)
29422 return -EFAULT;
29423
29424 - remaining = copy_to_user(buf, ptr, sz);
29425 +#ifdef CONFIG_PAX_USERCOPY
29426 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29427 + if (!temp) {
29428 + unxlate_dev_mem_ptr(p, ptr);
29429 + return -ENOMEM;
29430 + }
29431 + memcpy(temp, ptr, sz);
29432 +#else
29433 + temp = ptr;
29434 +#endif
29435 +
29436 + remaining = copy_to_user(buf, temp, sz);
29437 +
29438 +#ifdef CONFIG_PAX_USERCOPY
29439 + kfree(temp);
29440 +#endif
29441 +
29442 unxlate_dev_mem_ptr(p, ptr);
29443 if (remaining)
29444 return -EFAULT;
29445 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29446 size_t count, loff_t *ppos)
29447 {
29448 unsigned long p = *ppos;
29449 - ssize_t low_count, read, sz;
29450 + ssize_t low_count, read, sz, err = 0;
29451 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29452 - int err = 0;
29453
29454 read = 0;
29455 if (p < (unsigned long) high_memory) {
29456 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29457 }
29458 #endif
29459 while (low_count > 0) {
29460 + char *temp;
29461 +
29462 sz = size_inside_page(p, low_count);
29463
29464 /*
29465 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29466 */
29467 kbuf = xlate_dev_kmem_ptr((char *)p);
29468
29469 - if (copy_to_user(buf, kbuf, sz))
29470 +#ifdef CONFIG_PAX_USERCOPY
29471 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29472 + if (!temp)
29473 + return -ENOMEM;
29474 + memcpy(temp, kbuf, sz);
29475 +#else
29476 + temp = kbuf;
29477 +#endif
29478 +
29479 + err = copy_to_user(buf, temp, sz);
29480 +
29481 +#ifdef CONFIG_PAX_USERCOPY
29482 + kfree(temp);
29483 +#endif
29484 +
29485 + if (err)
29486 return -EFAULT;
29487 buf += sz;
29488 p += sz;
29489 @@ -831,6 +878,9 @@ static const struct memdev {
29490 #ifdef CONFIG_CRASH_DUMP
29491 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29492 #endif
29493 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29494 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29495 +#endif
29496 };
29497
29498 static int memory_open(struct inode *inode, struct file *filp)
29499 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29500 index 9df78e2..01ba9ae 100644
29501 --- a/drivers/char/nvram.c
29502 +++ b/drivers/char/nvram.c
29503 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29504
29505 spin_unlock_irq(&rtc_lock);
29506
29507 - if (copy_to_user(buf, contents, tmp - contents))
29508 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29509 return -EFAULT;
29510
29511 *ppos = i;
29512 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29513 index 0a484b4..f48ccd1 100644
29514 --- a/drivers/char/pcmcia/synclink_cs.c
29515 +++ b/drivers/char/pcmcia/synclink_cs.c
29516 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29517
29518 if (debug_level >= DEBUG_LEVEL_INFO)
29519 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29520 - __FILE__,__LINE__, info->device_name, port->count);
29521 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29522
29523 - WARN_ON(!port->count);
29524 + WARN_ON(!atomic_read(&port->count));
29525
29526 if (tty_port_close_start(port, tty, filp) == 0)
29527 goto cleanup;
29528 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29529 cleanup:
29530 if (debug_level >= DEBUG_LEVEL_INFO)
29531 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29532 - tty->driver->name, port->count);
29533 + tty->driver->name, atomic_read(&port->count));
29534 }
29535
29536 /* Wait until the transmitter is empty.
29537 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29538
29539 if (debug_level >= DEBUG_LEVEL_INFO)
29540 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29541 - __FILE__,__LINE__,tty->driver->name, port->count);
29542 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29543
29544 /* If port is closing, signal caller to try again */
29545 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29546 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29547 goto cleanup;
29548 }
29549 spin_lock(&port->lock);
29550 - port->count++;
29551 + atomic_inc(&port->count);
29552 spin_unlock(&port->lock);
29553 spin_unlock_irqrestore(&info->netlock, flags);
29554
29555 - if (port->count == 1) {
29556 + if (atomic_read(&port->count) == 1) {
29557 /* 1st open on this device, init hardware */
29558 retval = startup(info, tty);
29559 if (retval < 0)
29560 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29561 unsigned short new_crctype;
29562
29563 /* return error if TTY interface open */
29564 - if (info->port.count)
29565 + if (atomic_read(&info->port.count))
29566 return -EBUSY;
29567
29568 switch (encoding)
29569 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29570
29571 /* arbitrate between network and tty opens */
29572 spin_lock_irqsave(&info->netlock, flags);
29573 - if (info->port.count != 0 || info->netcount != 0) {
29574 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29575 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29576 spin_unlock_irqrestore(&info->netlock, flags);
29577 return -EBUSY;
29578 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29579 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29580
29581 /* return error if TTY interface open */
29582 - if (info->port.count)
29583 + if (atomic_read(&info->port.count))
29584 return -EBUSY;
29585
29586 if (cmd != SIOCWANDEV)
29587 diff --git a/drivers/char/random.c b/drivers/char/random.c
29588 index 4ec04a7..9918387 100644
29589 --- a/drivers/char/random.c
29590 +++ b/drivers/char/random.c
29591 @@ -261,8 +261,13 @@
29592 /*
29593 * Configuration information
29594 */
29595 +#ifdef CONFIG_GRKERNSEC_RANDNET
29596 +#define INPUT_POOL_WORDS 512
29597 +#define OUTPUT_POOL_WORDS 128
29598 +#else
29599 #define INPUT_POOL_WORDS 128
29600 #define OUTPUT_POOL_WORDS 32
29601 +#endif
29602 #define SEC_XFER_SIZE 512
29603 #define EXTRACT_SIZE 10
29604
29605 @@ -300,10 +305,17 @@ static struct poolinfo {
29606 int poolwords;
29607 int tap1, tap2, tap3, tap4, tap5;
29608 } poolinfo_table[] = {
29609 +#ifdef CONFIG_GRKERNSEC_RANDNET
29610 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29611 + { 512, 411, 308, 208, 104, 1 },
29612 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29613 + { 128, 103, 76, 51, 25, 1 },
29614 +#else
29615 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29616 { 128, 103, 76, 51, 25, 1 },
29617 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29618 { 32, 26, 20, 14, 7, 1 },
29619 +#endif
29620 #if 0
29621 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29622 { 2048, 1638, 1231, 819, 411, 1 },
29623 @@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29624 }
29625 #endif
29626
29627 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29628 +u64 latent_entropy;
29629 +
29630 +__init void transfer_latent_entropy(void)
29631 +{
29632 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29633 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29634 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29635 +}
29636 +#endif
29637 +
29638 /*********************************************************************
29639 *
29640 * Entropy extraction routines
29641 @@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29642
29643 extract_buf(r, tmp);
29644 i = min_t(int, nbytes, EXTRACT_SIZE);
29645 - if (copy_to_user(buf, tmp, i)) {
29646 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29647 ret = -EFAULT;
29648 break;
29649 }
29650 @@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29651 #include <linux/sysctl.h>
29652
29653 static int min_read_thresh = 8, min_write_thresh;
29654 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29655 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29656 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29657 static char sysctl_bootid[16];
29658
29659 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29660 index 45713f0..8286d21 100644
29661 --- a/drivers/char/sonypi.c
29662 +++ b/drivers/char/sonypi.c
29663 @@ -54,6 +54,7 @@
29664
29665 #include <asm/uaccess.h>
29666 #include <asm/io.h>
29667 +#include <asm/local.h>
29668
29669 #include <linux/sonypi.h>
29670
29671 @@ -490,7 +491,7 @@ static struct sonypi_device {
29672 spinlock_t fifo_lock;
29673 wait_queue_head_t fifo_proc_list;
29674 struct fasync_struct *fifo_async;
29675 - int open_count;
29676 + local_t open_count;
29677 int model;
29678 struct input_dev *input_jog_dev;
29679 struct input_dev *input_key_dev;
29680 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29681 static int sonypi_misc_release(struct inode *inode, struct file *file)
29682 {
29683 mutex_lock(&sonypi_device.lock);
29684 - sonypi_device.open_count--;
29685 + local_dec(&sonypi_device.open_count);
29686 mutex_unlock(&sonypi_device.lock);
29687 return 0;
29688 }
29689 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29690 {
29691 mutex_lock(&sonypi_device.lock);
29692 /* Flush input queue on first open */
29693 - if (!sonypi_device.open_count)
29694 + if (!local_read(&sonypi_device.open_count))
29695 kfifo_reset(&sonypi_device.fifo);
29696 - sonypi_device.open_count++;
29697 + local_inc(&sonypi_device.open_count);
29698 mutex_unlock(&sonypi_device.lock);
29699
29700 return 0;
29701 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29702 index ad7c732..5aa8054 100644
29703 --- a/drivers/char/tpm/tpm.c
29704 +++ b/drivers/char/tpm/tpm.c
29705 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29706 chip->vendor.req_complete_val)
29707 goto out_recv;
29708
29709 - if ((status == chip->vendor.req_canceled)) {
29710 + if (status == chip->vendor.req_canceled) {
29711 dev_err(chip->dev, "Operation Canceled\n");
29712 rc = -ECANCELED;
29713 goto out;
29714 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29715 index 0636520..169c1d0 100644
29716 --- a/drivers/char/tpm/tpm_bios.c
29717 +++ b/drivers/char/tpm/tpm_bios.c
29718 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29719 event = addr;
29720
29721 if ((event->event_type == 0 && event->event_size == 0) ||
29722 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29723 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29724 return NULL;
29725
29726 return addr;
29727 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29728 return NULL;
29729
29730 if ((event->event_type == 0 && event->event_size == 0) ||
29731 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29732 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29733 return NULL;
29734
29735 (*pos)++;
29736 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29737 int i;
29738
29739 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29740 - seq_putc(m, data[i]);
29741 + if (!seq_putc(m, data[i]))
29742 + return -EFAULT;
29743
29744 return 0;
29745 }
29746 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29747 log->bios_event_log_end = log->bios_event_log + len;
29748
29749 virt = acpi_os_map_memory(start, len);
29750 + if (!virt) {
29751 + kfree(log->bios_event_log);
29752 + log->bios_event_log = NULL;
29753 + return -EFAULT;
29754 + }
29755
29756 - memcpy(log->bios_event_log, virt, len);
29757 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29758
29759 acpi_os_unmap_memory(virt, len);
29760 return 0;
29761 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29762 index cdf2f54..e55c197 100644
29763 --- a/drivers/char/virtio_console.c
29764 +++ b/drivers/char/virtio_console.c
29765 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29766 if (to_user) {
29767 ssize_t ret;
29768
29769 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29770 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29771 if (ret)
29772 return -EFAULT;
29773 } else {
29774 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29775 if (!port_has_data(port) && !port->host_connected)
29776 return 0;
29777
29778 - return fill_readbuf(port, ubuf, count, true);
29779 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29780 }
29781
29782 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29783 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29784 index 97f5064..202b6e6 100644
29785 --- a/drivers/edac/edac_pci_sysfs.c
29786 +++ b/drivers/edac/edac_pci_sysfs.c
29787 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29788 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29789 static int edac_pci_poll_msec = 1000; /* one second workq period */
29790
29791 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29792 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29793 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29794 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29795
29796 static struct kobject *edac_pci_top_main_kobj;
29797 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29798 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29799 edac_printk(KERN_CRIT, EDAC_PCI,
29800 "Signaled System Error on %s\n",
29801 pci_name(dev));
29802 - atomic_inc(&pci_nonparity_count);
29803 + atomic_inc_unchecked(&pci_nonparity_count);
29804 }
29805
29806 if (status & (PCI_STATUS_PARITY)) {
29807 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29808 "Master Data Parity Error on %s\n",
29809 pci_name(dev));
29810
29811 - atomic_inc(&pci_parity_count);
29812 + atomic_inc_unchecked(&pci_parity_count);
29813 }
29814
29815 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29816 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29817 "Detected Parity Error on %s\n",
29818 pci_name(dev));
29819
29820 - atomic_inc(&pci_parity_count);
29821 + atomic_inc_unchecked(&pci_parity_count);
29822 }
29823 }
29824
29825 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29826 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29827 "Signaled System Error on %s\n",
29828 pci_name(dev));
29829 - atomic_inc(&pci_nonparity_count);
29830 + atomic_inc_unchecked(&pci_nonparity_count);
29831 }
29832
29833 if (status & (PCI_STATUS_PARITY)) {
29834 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29835 "Master Data Parity Error on "
29836 "%s\n", pci_name(dev));
29837
29838 - atomic_inc(&pci_parity_count);
29839 + atomic_inc_unchecked(&pci_parity_count);
29840 }
29841
29842 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29843 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29844 "Detected Parity Error on %s\n",
29845 pci_name(dev));
29846
29847 - atomic_inc(&pci_parity_count);
29848 + atomic_inc_unchecked(&pci_parity_count);
29849 }
29850 }
29851 }
29852 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29853 if (!check_pci_errors)
29854 return;
29855
29856 - before_count = atomic_read(&pci_parity_count);
29857 + before_count = atomic_read_unchecked(&pci_parity_count);
29858
29859 /* scan all PCI devices looking for a Parity Error on devices and
29860 * bridges.
29861 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29862 /* Only if operator has selected panic on PCI Error */
29863 if (edac_pci_get_panic_on_pe()) {
29864 /* If the count is different 'after' from 'before' */
29865 - if (before_count != atomic_read(&pci_parity_count))
29866 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29867 panic("EDAC: PCI Parity Error");
29868 }
29869 }
29870 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29871 index 8c87a5e..a19cbd7 100644
29872 --- a/drivers/edac/mce_amd.h
29873 +++ b/drivers/edac/mce_amd.h
29874 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29875 struct amd_decoder_ops {
29876 bool (*dc_mce)(u16, u8);
29877 bool (*ic_mce)(u16, u8);
29878 -};
29879 +} __no_const;
29880
29881 void amd_report_gart_errors(bool);
29882 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29883 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29884 index 57ea7f4..789e3c3 100644
29885 --- a/drivers/firewire/core-card.c
29886 +++ b/drivers/firewire/core-card.c
29887 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29888
29889 void fw_core_remove_card(struct fw_card *card)
29890 {
29891 - struct fw_card_driver dummy_driver = dummy_driver_template;
29892 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29893
29894 card->driver->update_phy_reg(card, 4,
29895 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29896 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29897 index 2783f69..9f4b0cc 100644
29898 --- a/drivers/firewire/core-cdev.c
29899 +++ b/drivers/firewire/core-cdev.c
29900 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29901 int ret;
29902
29903 if ((request->channels == 0 && request->bandwidth == 0) ||
29904 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29905 - request->bandwidth < 0)
29906 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29907 return -EINVAL;
29908
29909 r = kmalloc(sizeof(*r), GFP_KERNEL);
29910 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29911 index 780708d..ad60a66 100644
29912 --- a/drivers/firewire/core-transaction.c
29913 +++ b/drivers/firewire/core-transaction.c
29914 @@ -37,6 +37,7 @@
29915 #include <linux/timer.h>
29916 #include <linux/types.h>
29917 #include <linux/workqueue.h>
29918 +#include <linux/sched.h>
29919
29920 #include <asm/byteorder.h>
29921
29922 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29923 index 515a42c..5ecf3ba 100644
29924 --- a/drivers/firewire/core.h
29925 +++ b/drivers/firewire/core.h
29926 @@ -111,6 +111,7 @@ struct fw_card_driver {
29927
29928 int (*stop_iso)(struct fw_iso_context *ctx);
29929 };
29930 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29931
29932 void fw_card_initialize(struct fw_card *card,
29933 const struct fw_card_driver *driver, struct device *device);
29934 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29935 index 153980b..4b4d046 100644
29936 --- a/drivers/firmware/dmi_scan.c
29937 +++ b/drivers/firmware/dmi_scan.c
29938 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29939 }
29940 }
29941 else {
29942 - /*
29943 - * no iounmap() for that ioremap(); it would be a no-op, but
29944 - * it's so early in setup that sucker gets confused into doing
29945 - * what it shouldn't if we actually call it.
29946 - */
29947 p = dmi_ioremap(0xF0000, 0x10000);
29948 if (p == NULL)
29949 goto error;
29950 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29951 if (buf == NULL)
29952 return -1;
29953
29954 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29955 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29956
29957 iounmap(buf);
29958 return 0;
29959 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29960 index 82d5c20..44a7177 100644
29961 --- a/drivers/gpio/gpio-vr41xx.c
29962 +++ b/drivers/gpio/gpio-vr41xx.c
29963 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29964 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29965 maskl, pendl, maskh, pendh);
29966
29967 - atomic_inc(&irq_err_count);
29968 + atomic_inc_unchecked(&irq_err_count);
29969
29970 return -EINVAL;
29971 }
29972 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29973 index 3252e70..b5314ace 100644
29974 --- a/drivers/gpu/drm/drm_crtc_helper.c
29975 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29976 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29977 struct drm_crtc *tmp;
29978 int crtc_mask = 1;
29979
29980 - WARN(!crtc, "checking null crtc?\n");
29981 + BUG_ON(!crtc);
29982
29983 dev = crtc->dev;
29984
29985 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29986 index 8a9d079..606cdd5 100644
29987 --- a/drivers/gpu/drm/drm_drv.c
29988 +++ b/drivers/gpu/drm/drm_drv.c
29989 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
29990 /**
29991 * Copy and IOCTL return string to user space
29992 */
29993 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29994 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29995 {
29996 int len;
29997
29998 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
29999 return -ENODEV;
30000
30001 atomic_inc(&dev->ioctl_count);
30002 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30003 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30004 ++file_priv->ioctl_count;
30005
30006 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30007 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30008 index 123de28..43a0897 100644
30009 --- a/drivers/gpu/drm/drm_fops.c
30010 +++ b/drivers/gpu/drm/drm_fops.c
30011 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30012 }
30013
30014 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30015 - atomic_set(&dev->counts[i], 0);
30016 + atomic_set_unchecked(&dev->counts[i], 0);
30017
30018 dev->sigdata.lock = NULL;
30019
30020 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30021
30022 retcode = drm_open_helper(inode, filp, dev);
30023 if (!retcode) {
30024 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30025 - if (!dev->open_count++)
30026 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30027 + if (local_inc_return(&dev->open_count) == 1)
30028 retcode = drm_setup(dev);
30029 }
30030 if (!retcode) {
30031 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30032
30033 mutex_lock(&drm_global_mutex);
30034
30035 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30036 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30037
30038 if (dev->driver->preclose)
30039 dev->driver->preclose(dev, file_priv);
30040 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30041 * Begin inline drm_release
30042 */
30043
30044 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30045 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30046 task_pid_nr(current),
30047 (long)old_encode_dev(file_priv->minor->device),
30048 - dev->open_count);
30049 + local_read(&dev->open_count));
30050
30051 /* Release any auth tokens that might point to this file_priv,
30052 (do that under the drm_global_mutex) */
30053 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30054 * End inline drm_release
30055 */
30056
30057 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30058 - if (!--dev->open_count) {
30059 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30060 + if (local_dec_and_test(&dev->open_count)) {
30061 if (atomic_read(&dev->ioctl_count)) {
30062 DRM_ERROR("Device busy: %d\n",
30063 atomic_read(&dev->ioctl_count));
30064 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30065 index c87dc96..326055d 100644
30066 --- a/drivers/gpu/drm/drm_global.c
30067 +++ b/drivers/gpu/drm/drm_global.c
30068 @@ -36,7 +36,7 @@
30069 struct drm_global_item {
30070 struct mutex mutex;
30071 void *object;
30072 - int refcount;
30073 + atomic_t refcount;
30074 };
30075
30076 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30077 @@ -49,7 +49,7 @@ void drm_global_init(void)
30078 struct drm_global_item *item = &glob[i];
30079 mutex_init(&item->mutex);
30080 item->object = NULL;
30081 - item->refcount = 0;
30082 + atomic_set(&item->refcount, 0);
30083 }
30084 }
30085
30086 @@ -59,7 +59,7 @@ void drm_global_release(void)
30087 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30088 struct drm_global_item *item = &glob[i];
30089 BUG_ON(item->object != NULL);
30090 - BUG_ON(item->refcount != 0);
30091 + BUG_ON(atomic_read(&item->refcount) != 0);
30092 }
30093 }
30094
30095 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30096 void *object;
30097
30098 mutex_lock(&item->mutex);
30099 - if (item->refcount == 0) {
30100 + if (atomic_read(&item->refcount) == 0) {
30101 item->object = kzalloc(ref->size, GFP_KERNEL);
30102 if (unlikely(item->object == NULL)) {
30103 ret = -ENOMEM;
30104 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30105 goto out_err;
30106
30107 }
30108 - ++item->refcount;
30109 + atomic_inc(&item->refcount);
30110 ref->object = item->object;
30111 object = item->object;
30112 mutex_unlock(&item->mutex);
30113 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30114 struct drm_global_item *item = &glob[ref->global_type];
30115
30116 mutex_lock(&item->mutex);
30117 - BUG_ON(item->refcount == 0);
30118 + BUG_ON(atomic_read(&item->refcount) == 0);
30119 BUG_ON(ref->object != item->object);
30120 - if (--item->refcount == 0) {
30121 + if (atomic_dec_and_test(&item->refcount)) {
30122 ref->release(ref);
30123 item->object = NULL;
30124 }
30125 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30126 index ab1162d..42587b2 100644
30127 --- a/drivers/gpu/drm/drm_info.c
30128 +++ b/drivers/gpu/drm/drm_info.c
30129 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30130 struct drm_local_map *map;
30131 struct drm_map_list *r_list;
30132
30133 - /* Hardcoded from _DRM_FRAME_BUFFER,
30134 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30135 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30136 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30137 + static const char * const types[] = {
30138 + [_DRM_FRAME_BUFFER] = "FB",
30139 + [_DRM_REGISTERS] = "REG",
30140 + [_DRM_SHM] = "SHM",
30141 + [_DRM_AGP] = "AGP",
30142 + [_DRM_SCATTER_GATHER] = "SG",
30143 + [_DRM_CONSISTENT] = "PCI",
30144 + [_DRM_GEM] = "GEM" };
30145 const char *type;
30146 int i;
30147
30148 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30149 map = r_list->map;
30150 if (!map)
30151 continue;
30152 - if (map->type < 0 || map->type > 5)
30153 + if (map->type >= ARRAY_SIZE(types))
30154 type = "??";
30155 else
30156 type = types[map->type];
30157 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30158 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30159 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30160 vma->vm_flags & VM_IO ? 'i' : '-',
30161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30162 + 0);
30163 +#else
30164 vma->vm_pgoff);
30165 +#endif
30166
30167 #if defined(__i386__)
30168 pgprot = pgprot_val(vma->vm_page_prot);
30169 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30170 index 637fcc3..e890b33 100644
30171 --- a/drivers/gpu/drm/drm_ioc32.c
30172 +++ b/drivers/gpu/drm/drm_ioc32.c
30173 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30174 request = compat_alloc_user_space(nbytes);
30175 if (!access_ok(VERIFY_WRITE, request, nbytes))
30176 return -EFAULT;
30177 - list = (struct drm_buf_desc *) (request + 1);
30178 + list = (struct drm_buf_desc __user *) (request + 1);
30179
30180 if (__put_user(count, &request->count)
30181 || __put_user(list, &request->list))
30182 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30183 request = compat_alloc_user_space(nbytes);
30184 if (!access_ok(VERIFY_WRITE, request, nbytes))
30185 return -EFAULT;
30186 - list = (struct drm_buf_pub *) (request + 1);
30187 + list = (struct drm_buf_pub __user *) (request + 1);
30188
30189 if (__put_user(count, &request->count)
30190 || __put_user(list, &request->list))
30191 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30192 index 64a62c6..ceab35e 100644
30193 --- a/drivers/gpu/drm/drm_ioctl.c
30194 +++ b/drivers/gpu/drm/drm_ioctl.c
30195 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30196 stats->data[i].value =
30197 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30198 else
30199 - stats->data[i].value = atomic_read(&dev->counts[i]);
30200 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30201 stats->data[i].type = dev->types[i];
30202 }
30203
30204 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30205 index 5211520..c744d85 100644
30206 --- a/drivers/gpu/drm/drm_lock.c
30207 +++ b/drivers/gpu/drm/drm_lock.c
30208 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30209 if (drm_lock_take(&master->lock, lock->context)) {
30210 master->lock.file_priv = file_priv;
30211 master->lock.lock_time = jiffies;
30212 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30213 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30214 break; /* Got lock */
30215 }
30216
30217 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30218 return -EINVAL;
30219 }
30220
30221 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30222 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30223
30224 if (drm_lock_free(&master->lock, lock->context)) {
30225 /* FIXME: Should really bail out here. */
30226 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30227 index 21bcd4a..8e074e0 100644
30228 --- a/drivers/gpu/drm/drm_stub.c
30229 +++ b/drivers/gpu/drm/drm_stub.c
30230 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30231
30232 drm_device_set_unplugged(dev);
30233
30234 - if (dev->open_count == 0) {
30235 + if (local_read(&dev->open_count) == 0) {
30236 drm_put_dev(dev);
30237 }
30238 mutex_unlock(&drm_global_mutex);
30239 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30240 index fa94391..ed26ec8 100644
30241 --- a/drivers/gpu/drm/i810/i810_dma.c
30242 +++ b/drivers/gpu/drm/i810/i810_dma.c
30243 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30244 dma->buflist[vertex->idx],
30245 vertex->discard, vertex->used);
30246
30247 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30248 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30249 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30250 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30251 sarea_priv->last_enqueue = dev_priv->counter - 1;
30252 sarea_priv->last_dispatch = (int)hw_status[5];
30253
30254 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30255 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30256 mc->last_render);
30257
30258 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30259 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30260 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30261 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30262 sarea_priv->last_enqueue = dev_priv->counter - 1;
30263 sarea_priv->last_dispatch = (int)hw_status[5];
30264
30265 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30266 index c9339f4..f5e1b9d 100644
30267 --- a/drivers/gpu/drm/i810/i810_drv.h
30268 +++ b/drivers/gpu/drm/i810/i810_drv.h
30269 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30270 int page_flipping;
30271
30272 wait_queue_head_t irq_queue;
30273 - atomic_t irq_received;
30274 - atomic_t irq_emitted;
30275 + atomic_unchecked_t irq_received;
30276 + atomic_unchecked_t irq_emitted;
30277
30278 int front_offset;
30279 } drm_i810_private_t;
30280 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30281 index 5363e9c..59360d1 100644
30282 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30283 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30284 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30285 I915_READ(GTIMR));
30286 }
30287 seq_printf(m, "Interrupts received: %d\n",
30288 - atomic_read(&dev_priv->irq_received));
30289 + atomic_read_unchecked(&dev_priv->irq_received));
30290 for (i = 0; i < I915_NUM_RINGS; i++) {
30291 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30292 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30293 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30294 index 36822b9..b725e1b 100644
30295 --- a/drivers/gpu/drm/i915/i915_dma.c
30296 +++ b/drivers/gpu/drm/i915/i915_dma.c
30297 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30298 bool can_switch;
30299
30300 spin_lock(&dev->count_lock);
30301 - can_switch = (dev->open_count == 0);
30302 + can_switch = (local_read(&dev->open_count) == 0);
30303 spin_unlock(&dev->count_lock);
30304 return can_switch;
30305 }
30306 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30307 index b0b676a..d107105 100644
30308 --- a/drivers/gpu/drm/i915/i915_drv.h
30309 +++ b/drivers/gpu/drm/i915/i915_drv.h
30310 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30311 /* render clock increase/decrease */
30312 /* display clock increase/decrease */
30313 /* pll clock increase/decrease */
30314 -};
30315 +} __no_const;
30316
30317 struct intel_device_info {
30318 u8 gen;
30319 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30320 int current_page;
30321 int page_flipping;
30322
30323 - atomic_t irq_received;
30324 + atomic_unchecked_t irq_received;
30325
30326 /* protects the irq masks */
30327 spinlock_t irq_lock;
30328 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30329 * will be page flipped away on the next vblank. When it
30330 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30331 */
30332 - atomic_t pending_flip;
30333 + atomic_unchecked_t pending_flip;
30334 };
30335
30336 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30337 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30338 struct drm_i915_private *dev_priv, unsigned port);
30339 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30340 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30341 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30342 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30343 {
30344 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30345 }
30346 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30347 index 974a9f1..b3ebd45 100644
30348 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30349 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30350 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30351 i915_gem_clflush_object(obj);
30352
30353 if (obj->base.pending_write_domain)
30354 - cd->flips |= atomic_read(&obj->pending_flip);
30355 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30356
30357 /* The actual obj->write_domain will be updated with
30358 * pending_write_domain after we emit the accumulated flush for all
30359 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30360
30361 static int
30362 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30363 - int count)
30364 + unsigned int count)
30365 {
30366 - int i;
30367 + unsigned int i;
30368
30369 for (i = 0; i < count; i++) {
30370 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30371 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30372 index ed3224c..6618589 100644
30373 --- a/drivers/gpu/drm/i915/i915_irq.c
30374 +++ b/drivers/gpu/drm/i915/i915_irq.c
30375 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30376 int vblank = 0;
30377 bool blc_event;
30378
30379 - atomic_inc(&dev_priv->irq_received);
30380 + atomic_inc_unchecked(&dev_priv->irq_received);
30381
30382 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30383 PIPE_VBLANK_INTERRUPT_STATUS;
30384 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30385 irqreturn_t ret = IRQ_NONE;
30386 int i;
30387
30388 - atomic_inc(&dev_priv->irq_received);
30389 + atomic_inc_unchecked(&dev_priv->irq_received);
30390
30391 /* disable master interrupt before clearing iir */
30392 de_ier = I915_READ(DEIER);
30393 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30394 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30395 u32 hotplug_mask;
30396
30397 - atomic_inc(&dev_priv->irq_received);
30398 + atomic_inc_unchecked(&dev_priv->irq_received);
30399
30400 /* disable master interrupt before clearing iir */
30401 de_ier = I915_READ(DEIER);
30402 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30403 {
30404 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30405
30406 - atomic_set(&dev_priv->irq_received, 0);
30407 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30408
30409
30410 I915_WRITE(HWSTAM, 0xeffe);
30411 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30412 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30413 int pipe;
30414
30415 - atomic_set(&dev_priv->irq_received, 0);
30416 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30417
30418 /* VLV magic */
30419 I915_WRITE(VLV_IMR, 0);
30420 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30421 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30422 int pipe;
30423
30424 - atomic_set(&dev_priv->irq_received, 0);
30425 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30426
30427 for_each_pipe(pipe)
30428 I915_WRITE(PIPESTAT(pipe), 0);
30429 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30430 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30431 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30432
30433 - atomic_inc(&dev_priv->irq_received);
30434 + atomic_inc_unchecked(&dev_priv->irq_received);
30435
30436 iir = I915_READ16(IIR);
30437 if (iir == 0)
30438 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30439 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30440 int pipe;
30441
30442 - atomic_set(&dev_priv->irq_received, 0);
30443 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30444
30445 if (I915_HAS_HOTPLUG(dev)) {
30446 I915_WRITE(PORT_HOTPLUG_EN, 0);
30447 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30448 };
30449 int pipe, ret = IRQ_NONE;
30450
30451 - atomic_inc(&dev_priv->irq_received);
30452 + atomic_inc_unchecked(&dev_priv->irq_received);
30453
30454 iir = I915_READ(IIR);
30455 do {
30456 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30457 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30458 int pipe;
30459
30460 - atomic_set(&dev_priv->irq_received, 0);
30461 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30462
30463 if (I915_HAS_HOTPLUG(dev)) {
30464 I915_WRITE(PORT_HOTPLUG_EN, 0);
30465 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30466 int irq_received;
30467 int ret = IRQ_NONE, pipe;
30468
30469 - atomic_inc(&dev_priv->irq_received);
30470 + atomic_inc_unchecked(&dev_priv->irq_received);
30471
30472 iir = I915_READ(IIR);
30473
30474 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30475 index a8538ac..4868a05 100644
30476 --- a/drivers/gpu/drm/i915/intel_display.c
30477 +++ b/drivers/gpu/drm/i915/intel_display.c
30478 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30479
30480 wait_event(dev_priv->pending_flip_queue,
30481 atomic_read(&dev_priv->mm.wedged) ||
30482 - atomic_read(&obj->pending_flip) == 0);
30483 + atomic_read_unchecked(&obj->pending_flip) == 0);
30484
30485 /* Big Hammer, we also need to ensure that any pending
30486 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30487 @@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30488
30489 obj = work->old_fb_obj;
30490
30491 - atomic_clear_mask(1 << intel_crtc->plane,
30492 - &obj->pending_flip.counter);
30493 - if (atomic_read(&obj->pending_flip) == 0)
30494 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30495 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30496 wake_up(&dev_priv->pending_flip_queue);
30497
30498 schedule_work(&work->work);
30499 @@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30500 /* Block clients from rendering to the new back buffer until
30501 * the flip occurs and the object is no longer visible.
30502 */
30503 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30504 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30505
30506 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30507 if (ret)
30508 @@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30509 return 0;
30510
30511 cleanup_pending:
30512 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30513 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30514 drm_gem_object_unreference(&work->old_fb_obj->base);
30515 drm_gem_object_unreference(&obj->base);
30516 mutex_unlock(&dev->struct_mutex);
30517 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30518 index 54558a0..2d97005 100644
30519 --- a/drivers/gpu/drm/mga/mga_drv.h
30520 +++ b/drivers/gpu/drm/mga/mga_drv.h
30521 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30522 u32 clear_cmd;
30523 u32 maccess;
30524
30525 - atomic_t vbl_received; /**< Number of vblanks received. */
30526 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30527 wait_queue_head_t fence_queue;
30528 - atomic_t last_fence_retired;
30529 + atomic_unchecked_t last_fence_retired;
30530 u32 next_fence_to_post;
30531
30532 unsigned int fb_cpp;
30533 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30534 index 2581202..f230a8d9 100644
30535 --- a/drivers/gpu/drm/mga/mga_irq.c
30536 +++ b/drivers/gpu/drm/mga/mga_irq.c
30537 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30538 if (crtc != 0)
30539 return 0;
30540
30541 - return atomic_read(&dev_priv->vbl_received);
30542 + return atomic_read_unchecked(&dev_priv->vbl_received);
30543 }
30544
30545
30546 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30547 /* VBLANK interrupt */
30548 if (status & MGA_VLINEPEN) {
30549 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30550 - atomic_inc(&dev_priv->vbl_received);
30551 + atomic_inc_unchecked(&dev_priv->vbl_received);
30552 drm_handle_vblank(dev, 0);
30553 handled = 1;
30554 }
30555 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30556 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30557 MGA_WRITE(MGA_PRIMEND, prim_end);
30558
30559 - atomic_inc(&dev_priv->last_fence_retired);
30560 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30561 DRM_WAKEUP(&dev_priv->fence_queue);
30562 handled = 1;
30563 }
30564 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30565 * using fences.
30566 */
30567 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30568 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30569 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30570 - *sequence) <= (1 << 23)));
30571
30572 *sequence = cur_fence;
30573 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30574 index 2f11e16..191267e 100644
30575 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30576 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30577 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30578 struct bit_table {
30579 const char id;
30580 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30581 -};
30582 +} __no_const;
30583
30584 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30585
30586 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30587 index 8613cb2..ea038e7 100644
30588 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30589 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30590 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30591 u32 handle, u16 class);
30592 void (*set_tile_region)(struct drm_device *dev, int i);
30593 void (*tlb_flush)(struct drm_device *, int engine);
30594 -};
30595 +} __no_const;
30596
30597 struct nouveau_instmem_engine {
30598 void *priv;
30599 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30600 struct nouveau_mc_engine {
30601 int (*init)(struct drm_device *dev);
30602 void (*takedown)(struct drm_device *dev);
30603 -};
30604 +} __no_const;
30605
30606 struct nouveau_timer_engine {
30607 int (*init)(struct drm_device *dev);
30608 void (*takedown)(struct drm_device *dev);
30609 uint64_t (*read)(struct drm_device *dev);
30610 -};
30611 +} __no_const;
30612
30613 struct nouveau_fb_engine {
30614 int num_tiles;
30615 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30616 void (*put)(struct drm_device *, struct nouveau_mem **);
30617
30618 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30619 -};
30620 +} __no_const;
30621
30622 struct nouveau_engine {
30623 struct nouveau_instmem_engine instmem;
30624 @@ -695,7 +695,7 @@ struct drm_nouveau_private {
30625 struct drm_global_reference mem_global_ref;
30626 struct ttm_bo_global_ref bo_global_ref;
30627 struct ttm_bo_device bdev;
30628 - atomic_t validate_sequence;
30629 + atomic_unchecked_t validate_sequence;
30630 int (*move)(struct nouveau_channel *,
30631 struct ttm_buffer_object *,
30632 struct ttm_mem_reg *, struct ttm_mem_reg *);
30633 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30634 index 30f5423..abca136 100644
30635 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30636 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30637 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30638 int trycnt = 0;
30639 int ret, i;
30640
30641 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30642 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30643 retry:
30644 if (++trycnt > 100000) {
30645 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30646 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30647 index 19706f0..f257368 100644
30648 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30649 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30650 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30651 bool can_switch;
30652
30653 spin_lock(&dev->count_lock);
30654 - can_switch = (dev->open_count == 0);
30655 + can_switch = (local_read(&dev->open_count) == 0);
30656 spin_unlock(&dev->count_lock);
30657 return can_switch;
30658 }
30659 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30660 index a9514ea..369d511 100644
30661 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30662 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30663 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30664 }
30665
30666 if (nv_encoder->dcb->type == OUTPUT_DP) {
30667 - struct dp_train_func func = {
30668 + static struct dp_train_func func = {
30669 .link_set = nv50_sor_dp_link_set,
30670 .train_set = nv50_sor_dp_train_set,
30671 .train_adj = nv50_sor_dp_train_adj
30672 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30673 index c486d3c..3a7d6f4 100644
30674 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30675 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30676 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30677 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30678
30679 if (nv_encoder->dcb->type == OUTPUT_DP) {
30680 - struct dp_train_func func = {
30681 + static struct dp_train_func func = {
30682 .link_set = nvd0_sor_dp_link_set,
30683 .train_set = nvd0_sor_dp_train_set,
30684 .train_adj = nvd0_sor_dp_train_adj
30685 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30686 index bcac90b..53bfc76 100644
30687 --- a/drivers/gpu/drm/r128/r128_cce.c
30688 +++ b/drivers/gpu/drm/r128/r128_cce.c
30689 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30690
30691 /* GH: Simple idle check.
30692 */
30693 - atomic_set(&dev_priv->idle_count, 0);
30694 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30695
30696 /* We don't support anything other than bus-mastering ring mode,
30697 * but the ring can be in either AGP or PCI space for the ring
30698 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30699 index 930c71b..499aded 100644
30700 --- a/drivers/gpu/drm/r128/r128_drv.h
30701 +++ b/drivers/gpu/drm/r128/r128_drv.h
30702 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30703 int is_pci;
30704 unsigned long cce_buffers_offset;
30705
30706 - atomic_t idle_count;
30707 + atomic_unchecked_t idle_count;
30708
30709 int page_flipping;
30710 int current_page;
30711 u32 crtc_offset;
30712 u32 crtc_offset_cntl;
30713
30714 - atomic_t vbl_received;
30715 + atomic_unchecked_t vbl_received;
30716
30717 u32 color_fmt;
30718 unsigned int front_offset;
30719 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30720 index 429d5a0..7e899ed 100644
30721 --- a/drivers/gpu/drm/r128/r128_irq.c
30722 +++ b/drivers/gpu/drm/r128/r128_irq.c
30723 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30724 if (crtc != 0)
30725 return 0;
30726
30727 - return atomic_read(&dev_priv->vbl_received);
30728 + return atomic_read_unchecked(&dev_priv->vbl_received);
30729 }
30730
30731 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30732 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30733 /* VBLANK interrupt */
30734 if (status & R128_CRTC_VBLANK_INT) {
30735 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30736 - atomic_inc(&dev_priv->vbl_received);
30737 + atomic_inc_unchecked(&dev_priv->vbl_received);
30738 drm_handle_vblank(dev, 0);
30739 return IRQ_HANDLED;
30740 }
30741 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30742 index a9e33ce..09edd4b 100644
30743 --- a/drivers/gpu/drm/r128/r128_state.c
30744 +++ b/drivers/gpu/drm/r128/r128_state.c
30745 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30746
30747 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30748 {
30749 - if (atomic_read(&dev_priv->idle_count) == 0)
30750 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30751 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30752 else
30753 - atomic_set(&dev_priv->idle_count, 0);
30754 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30755 }
30756
30757 #endif
30758 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30759 index 5a82b6b..9e69c73 100644
30760 --- a/drivers/gpu/drm/radeon/mkregtable.c
30761 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30762 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30763 regex_t mask_rex;
30764 regmatch_t match[4];
30765 char buf[1024];
30766 - size_t end;
30767 + long end;
30768 int len;
30769 int done = 0;
30770 int r;
30771 unsigned o;
30772 struct offset *offset;
30773 char last_reg_s[10];
30774 - int last_reg;
30775 + unsigned long last_reg;
30776
30777 if (regcomp
30778 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30779 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30780 index fefcca5..20a5b90 100644
30781 --- a/drivers/gpu/drm/radeon/radeon.h
30782 +++ b/drivers/gpu/drm/radeon/radeon.h
30783 @@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30784 int x2, int y2);
30785 void (*draw_auto)(struct radeon_device *rdev);
30786 void (*set_default_state)(struct radeon_device *rdev);
30787 -};
30788 +} __no_const;
30789
30790 struct r600_blit {
30791 struct radeon_bo *shader_obj;
30792 @@ -1244,7 +1244,7 @@ struct radeon_asic {
30793 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30794 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30795 } pflip;
30796 -};
30797 +} __no_const;
30798
30799 /*
30800 * Asic structures
30801 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30802 index 066c98b..96ab858 100644
30803 --- a/drivers/gpu/drm/radeon/radeon_device.c
30804 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30805 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30806 bool can_switch;
30807
30808 spin_lock(&dev->count_lock);
30809 - can_switch = (dev->open_count == 0);
30810 + can_switch = (local_read(&dev->open_count) == 0);
30811 spin_unlock(&dev->count_lock);
30812 return can_switch;
30813 }
30814 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30815 index a1b59ca..86f2d44 100644
30816 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30817 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30818 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30819
30820 /* SW interrupt */
30821 wait_queue_head_t swi_queue;
30822 - atomic_t swi_emitted;
30823 + atomic_unchecked_t swi_emitted;
30824 int vblank_crtc;
30825 uint32_t irq_enable_reg;
30826 uint32_t r500_disp_irq_reg;
30827 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30828 index 48b7cea..342236f 100644
30829 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30830 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30831 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30832 request = compat_alloc_user_space(sizeof(*request));
30833 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30834 || __put_user(req32.param, &request->param)
30835 - || __put_user((void __user *)(unsigned long)req32.value,
30836 + || __put_user((unsigned long)req32.value,
30837 &request->value))
30838 return -EFAULT;
30839
30840 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30841 index 00da384..32f972d 100644
30842 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30843 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30844 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30845 unsigned int ret;
30846 RING_LOCALS;
30847
30848 - atomic_inc(&dev_priv->swi_emitted);
30849 - ret = atomic_read(&dev_priv->swi_emitted);
30850 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30851 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30852
30853 BEGIN_RING(4);
30854 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30855 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30856 drm_radeon_private_t *dev_priv =
30857 (drm_radeon_private_t *) dev->dev_private;
30858
30859 - atomic_set(&dev_priv->swi_emitted, 0);
30860 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30861 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30862
30863 dev->max_vblank_count = 0x001fffff;
30864 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30865 index e8422ae..d22d4a8 100644
30866 --- a/drivers/gpu/drm/radeon/radeon_state.c
30867 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30868 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30869 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30870 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30871
30872 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30873 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30874 sarea_priv->nbox * sizeof(depth_boxes[0])))
30875 return -EFAULT;
30876
30877 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30878 {
30879 drm_radeon_private_t *dev_priv = dev->dev_private;
30880 drm_radeon_getparam_t *param = data;
30881 - int value;
30882 + int value = 0;
30883
30884 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30885
30886 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30887 index c94a225..5795d34 100644
30888 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30889 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30890 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30891 }
30892 if (unlikely(ttm_vm_ops == NULL)) {
30893 ttm_vm_ops = vma->vm_ops;
30894 - radeon_ttm_vm_ops = *ttm_vm_ops;
30895 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30896 + pax_open_kernel();
30897 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30898 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30899 + pax_close_kernel();
30900 }
30901 vma->vm_ops = &radeon_ttm_vm_ops;
30902 return 0;
30903 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30904 index 159b6a4..fa82487 100644
30905 --- a/drivers/gpu/drm/radeon/rs690.c
30906 +++ b/drivers/gpu/drm/radeon/rs690.c
30907 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30908 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30909 rdev->pm.sideport_bandwidth.full)
30910 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30911 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30912 + read_delay_latency.full = dfixed_const(800 * 1000);
30913 read_delay_latency.full = dfixed_div(read_delay_latency,
30914 rdev->pm.igp_sideport_mclk);
30915 + a.full = dfixed_const(370);
30916 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30917 } else {
30918 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30919 rdev->pm.k8_bandwidth.full)
30920 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30921 index ebc6fac..a8313ed 100644
30922 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30923 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30924 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30925 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30926 struct shrink_control *sc)
30927 {
30928 - static atomic_t start_pool = ATOMIC_INIT(0);
30929 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30930 unsigned i;
30931 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30932 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30933 struct ttm_page_pool *pool;
30934 int shrink_pages = sc->nr_to_scan;
30935
30936 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30937 index 88edacc..1e5412b 100644
30938 --- a/drivers/gpu/drm/via/via_drv.h
30939 +++ b/drivers/gpu/drm/via/via_drv.h
30940 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30941 typedef uint32_t maskarray_t[5];
30942
30943 typedef struct drm_via_irq {
30944 - atomic_t irq_received;
30945 + atomic_unchecked_t irq_received;
30946 uint32_t pending_mask;
30947 uint32_t enable_mask;
30948 wait_queue_head_t irq_queue;
30949 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30950 struct timeval last_vblank;
30951 int last_vblank_valid;
30952 unsigned usec_per_vblank;
30953 - atomic_t vbl_received;
30954 + atomic_unchecked_t vbl_received;
30955 drm_via_state_t hc_state;
30956 char pci_buf[VIA_PCI_BUF_SIZE];
30957 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30958 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30959 index d391f48..10c8ca3 100644
30960 --- a/drivers/gpu/drm/via/via_irq.c
30961 +++ b/drivers/gpu/drm/via/via_irq.c
30962 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30963 if (crtc != 0)
30964 return 0;
30965
30966 - return atomic_read(&dev_priv->vbl_received);
30967 + return atomic_read_unchecked(&dev_priv->vbl_received);
30968 }
30969
30970 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30971 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30972
30973 status = VIA_READ(VIA_REG_INTERRUPT);
30974 if (status & VIA_IRQ_VBLANK_PENDING) {
30975 - atomic_inc(&dev_priv->vbl_received);
30976 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30977 + atomic_inc_unchecked(&dev_priv->vbl_received);
30978 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30979 do_gettimeofday(&cur_vblank);
30980 if (dev_priv->last_vblank_valid) {
30981 dev_priv->usec_per_vblank =
30982 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30983 dev_priv->last_vblank = cur_vblank;
30984 dev_priv->last_vblank_valid = 1;
30985 }
30986 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30987 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30988 DRM_DEBUG("US per vblank is: %u\n",
30989 dev_priv->usec_per_vblank);
30990 }
30991 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30992
30993 for (i = 0; i < dev_priv->num_irqs; ++i) {
30994 if (status & cur_irq->pending_mask) {
30995 - atomic_inc(&cur_irq->irq_received);
30996 + atomic_inc_unchecked(&cur_irq->irq_received);
30997 DRM_WAKEUP(&cur_irq->irq_queue);
30998 handled = 1;
30999 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31000 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31001 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31002 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31003 masks[irq][4]));
31004 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31005 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31006 } else {
31007 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31008 (((cur_irq_sequence =
31009 - atomic_read(&cur_irq->irq_received)) -
31010 + atomic_read_unchecked(&cur_irq->irq_received)) -
31011 *sequence) <= (1 << 23)));
31012 }
31013 *sequence = cur_irq_sequence;
31014 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31015 }
31016
31017 for (i = 0; i < dev_priv->num_irqs; ++i) {
31018 - atomic_set(&cur_irq->irq_received, 0);
31019 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31020 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31021 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31022 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31023 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31024 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31025 case VIA_IRQ_RELATIVE:
31026 irqwait->request.sequence +=
31027 - atomic_read(&cur_irq->irq_received);
31028 + atomic_read_unchecked(&cur_irq->irq_received);
31029 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31030 case VIA_IRQ_ABSOLUTE:
31031 break;
31032 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31033 index d0f2c07..9ebd9c3 100644
31034 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31035 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31036 @@ -263,7 +263,7 @@ struct vmw_private {
31037 * Fencing and IRQs.
31038 */
31039
31040 - atomic_t marker_seq;
31041 + atomic_unchecked_t marker_seq;
31042 wait_queue_head_t fence_queue;
31043 wait_queue_head_t fifo_queue;
31044 int fence_queue_waiters; /* Protected by hw_mutex */
31045 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31046 index a0c2f12..68ae6cb 100644
31047 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31048 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31049 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31050 (unsigned int) min,
31051 (unsigned int) fifo->capabilities);
31052
31053 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31054 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31055 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31056 vmw_marker_queue_init(&fifo->marker_queue);
31057 return vmw_fifo_send_fence(dev_priv, &dummy);
31058 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31059 if (reserveable)
31060 iowrite32(bytes, fifo_mem +
31061 SVGA_FIFO_RESERVED);
31062 - return fifo_mem + (next_cmd >> 2);
31063 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31064 } else {
31065 need_bounce = true;
31066 }
31067 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31068
31069 fm = vmw_fifo_reserve(dev_priv, bytes);
31070 if (unlikely(fm == NULL)) {
31071 - *seqno = atomic_read(&dev_priv->marker_seq);
31072 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31073 ret = -ENOMEM;
31074 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31075 false, 3*HZ);
31076 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31077 }
31078
31079 do {
31080 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31081 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31082 } while (*seqno == 0);
31083
31084 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31085 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31086 index cabc95f..14b3d77 100644
31087 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31088 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31089 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31090 * emitted. Then the fence is stale and signaled.
31091 */
31092
31093 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31094 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31095 > VMW_FENCE_WRAP);
31096
31097 return ret;
31098 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31099
31100 if (fifo_idle)
31101 down_read(&fifo_state->rwsem);
31102 - signal_seq = atomic_read(&dev_priv->marker_seq);
31103 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31104 ret = 0;
31105
31106 for (;;) {
31107 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31108 index 8a8725c..afed796 100644
31109 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31110 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31111 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31112 while (!vmw_lag_lt(queue, us)) {
31113 spin_lock(&queue->lock);
31114 if (list_empty(&queue->head))
31115 - seqno = atomic_read(&dev_priv->marker_seq);
31116 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31117 else {
31118 marker = list_first_entry(&queue->head,
31119 struct vmw_marker, head);
31120 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31121 index 4c87276..9ecc3c7 100644
31122 --- a/drivers/hid/hid-core.c
31123 +++ b/drivers/hid/hid-core.c
31124 @@ -2151,7 +2151,7 @@ static bool hid_ignore(struct hid_device *hdev)
31125
31126 int hid_add_device(struct hid_device *hdev)
31127 {
31128 - static atomic_t id = ATOMIC_INIT(0);
31129 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31130 int ret;
31131
31132 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31133 @@ -2186,7 +2186,7 @@ int hid_add_device(struct hid_device *hdev)
31134 /* XXX hack, any other cleaner solution after the driver core
31135 * is converted to allow more than 20 bytes as the device name? */
31136 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31137 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31138 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31139
31140 hid_debug_register(hdev, dev_name(&hdev->dev));
31141 ret = device_add(&hdev->dev);
31142 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31143 index eec3291..8ed706b 100644
31144 --- a/drivers/hid/hid-wiimote-debug.c
31145 +++ b/drivers/hid/hid-wiimote-debug.c
31146 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31147 else if (size == 0)
31148 return -EIO;
31149
31150 - if (copy_to_user(u, buf, size))
31151 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31152 return -EFAULT;
31153
31154 *off += size;
31155 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31156 index 14599e2..711c965 100644
31157 --- a/drivers/hid/usbhid/hiddev.c
31158 +++ b/drivers/hid/usbhid/hiddev.c
31159 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31160 break;
31161
31162 case HIDIOCAPPLICATION:
31163 - if (arg < 0 || arg >= hid->maxapplication)
31164 + if (arg >= hid->maxapplication)
31165 break;
31166
31167 for (i = 0; i < hid->maxcollection; i++)
31168 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31169 index 4065374..10ed7dc 100644
31170 --- a/drivers/hv/channel.c
31171 +++ b/drivers/hv/channel.c
31172 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31173 int ret = 0;
31174 int t;
31175
31176 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31177 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31178 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31179 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31180
31181 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31182 if (ret)
31183 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31184 index 86f8885..ab9cb2b 100644
31185 --- a/drivers/hv/hv.c
31186 +++ b/drivers/hv/hv.c
31187 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31188 u64 output_address = (output) ? virt_to_phys(output) : 0;
31189 u32 output_address_hi = output_address >> 32;
31190 u32 output_address_lo = output_address & 0xFFFFFFFF;
31191 - void *hypercall_page = hv_context.hypercall_page;
31192 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31193
31194 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31195 "=a"(hv_status_lo) : "d" (control_hi),
31196 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31197 index b9426a6..677ce34 100644
31198 --- a/drivers/hv/hyperv_vmbus.h
31199 +++ b/drivers/hv/hyperv_vmbus.h
31200 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31201 struct vmbus_connection {
31202 enum vmbus_connect_state conn_state;
31203
31204 - atomic_t next_gpadl_handle;
31205 + atomic_unchecked_t next_gpadl_handle;
31206
31207 /*
31208 * Represents channel interrupts. Each bit position represents a
31209 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31210 index a220e57..428f54d 100644
31211 --- a/drivers/hv/vmbus_drv.c
31212 +++ b/drivers/hv/vmbus_drv.c
31213 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31214 {
31215 int ret = 0;
31216
31217 - static atomic_t device_num = ATOMIC_INIT(0);
31218 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31219
31220 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31221 - atomic_inc_return(&device_num));
31222 + atomic_inc_return_unchecked(&device_num));
31223
31224 child_device_obj->device.bus = &hv_bus;
31225 child_device_obj->device.parent = &hv_acpi_dev->dev;
31226 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31227 index 34ad5a2..e2b0ae8 100644
31228 --- a/drivers/hwmon/acpi_power_meter.c
31229 +++ b/drivers/hwmon/acpi_power_meter.c
31230 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31231 return res;
31232
31233 temp /= 1000;
31234 - if (temp < 0)
31235 - return -EINVAL;
31236
31237 mutex_lock(&resource->lock);
31238 resource->trip[attr->index - 7] = temp;
31239 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31240 index 8b011d0..3de24a1 100644
31241 --- a/drivers/hwmon/sht15.c
31242 +++ b/drivers/hwmon/sht15.c
31243 @@ -166,7 +166,7 @@ struct sht15_data {
31244 int supply_uV;
31245 bool supply_uV_valid;
31246 struct work_struct update_supply_work;
31247 - atomic_t interrupt_handled;
31248 + atomic_unchecked_t interrupt_handled;
31249 };
31250
31251 /**
31252 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31253 return ret;
31254
31255 gpio_direction_input(data->pdata->gpio_data);
31256 - atomic_set(&data->interrupt_handled, 0);
31257 + atomic_set_unchecked(&data->interrupt_handled, 0);
31258
31259 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31260 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31261 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31262 /* Only relevant if the interrupt hasn't occurred. */
31263 - if (!atomic_read(&data->interrupt_handled))
31264 + if (!atomic_read_unchecked(&data->interrupt_handled))
31265 schedule_work(&data->read_work);
31266 }
31267 ret = wait_event_timeout(data->wait_queue,
31268 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31269
31270 /* First disable the interrupt */
31271 disable_irq_nosync(irq);
31272 - atomic_inc(&data->interrupt_handled);
31273 + atomic_inc_unchecked(&data->interrupt_handled);
31274 /* Then schedule a reading work struct */
31275 if (data->state != SHT15_READING_NOTHING)
31276 schedule_work(&data->read_work);
31277 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31278 * If not, then start the interrupt again - care here as could
31279 * have gone low in meantime so verify it hasn't!
31280 */
31281 - atomic_set(&data->interrupt_handled, 0);
31282 + atomic_set_unchecked(&data->interrupt_handled, 0);
31283 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31284 /* If still not occurred or another handler was scheduled */
31285 if (gpio_get_value(data->pdata->gpio_data)
31286 - || atomic_read(&data->interrupt_handled))
31287 + || atomic_read_unchecked(&data->interrupt_handled))
31288 return;
31289 }
31290
31291 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31292 index 378fcb5..5e91fa8 100644
31293 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31294 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31295 @@ -43,7 +43,7 @@
31296 extern struct i2c_adapter amd756_smbus;
31297
31298 static struct i2c_adapter *s4882_adapter;
31299 -static struct i2c_algorithm *s4882_algo;
31300 +static i2c_algorithm_no_const *s4882_algo;
31301
31302 /* Wrapper access functions for multiplexed SMBus */
31303 static DEFINE_MUTEX(amd756_lock);
31304 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31305 index 29015eb..af2d8e9 100644
31306 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31307 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31308 @@ -41,7 +41,7 @@
31309 extern struct i2c_adapter *nforce2_smbus;
31310
31311 static struct i2c_adapter *s4985_adapter;
31312 -static struct i2c_algorithm *s4985_algo;
31313 +static i2c_algorithm_no_const *s4985_algo;
31314
31315 /* Wrapper access functions for multiplexed SMBus */
31316 static DEFINE_MUTEX(nforce2_lock);
31317 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31318 index 1038c38..eb92f51 100644
31319 --- a/drivers/i2c/i2c-mux.c
31320 +++ b/drivers/i2c/i2c-mux.c
31321 @@ -30,7 +30,7 @@
31322 /* multiplexer per channel data */
31323 struct i2c_mux_priv {
31324 struct i2c_adapter adap;
31325 - struct i2c_algorithm algo;
31326 + i2c_algorithm_no_const algo;
31327
31328 struct i2c_adapter *parent;
31329 void *mux_priv; /* the mux chip/device */
31330 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31331 index 57d00ca..0145194 100644
31332 --- a/drivers/ide/aec62xx.c
31333 +++ b/drivers/ide/aec62xx.c
31334 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31335 .cable_detect = atp86x_cable_detect,
31336 };
31337
31338 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31339 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31340 { /* 0: AEC6210 */
31341 .name = DRV_NAME,
31342 .init_chipset = init_chipset_aec62xx,
31343 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31344 index 2c8016a..911a27c 100644
31345 --- a/drivers/ide/alim15x3.c
31346 +++ b/drivers/ide/alim15x3.c
31347 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31348 .dma_sff_read_status = ide_dma_sff_read_status,
31349 };
31350
31351 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31352 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31353 .name = DRV_NAME,
31354 .init_chipset = init_chipset_ali15x3,
31355 .init_hwif = init_hwif_ali15x3,
31356 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31357 index 3747b25..56fc995 100644
31358 --- a/drivers/ide/amd74xx.c
31359 +++ b/drivers/ide/amd74xx.c
31360 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31361 .udma_mask = udma, \
31362 }
31363
31364 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31365 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31366 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31367 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31368 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31369 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31370 index 15f0ead..cb43480 100644
31371 --- a/drivers/ide/atiixp.c
31372 +++ b/drivers/ide/atiixp.c
31373 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31374 .cable_detect = atiixp_cable_detect,
31375 };
31376
31377 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31378 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31379 { /* 0: IXP200/300/400/700 */
31380 .name = DRV_NAME,
31381 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31382 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31383 index 5f80312..d1fc438 100644
31384 --- a/drivers/ide/cmd64x.c
31385 +++ b/drivers/ide/cmd64x.c
31386 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31387 .dma_sff_read_status = ide_dma_sff_read_status,
31388 };
31389
31390 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31391 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31392 { /* 0: CMD643 */
31393 .name = DRV_NAME,
31394 .init_chipset = init_chipset_cmd64x,
31395 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31396 index 2c1e5f7..1444762 100644
31397 --- a/drivers/ide/cs5520.c
31398 +++ b/drivers/ide/cs5520.c
31399 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31400 .set_dma_mode = cs5520_set_dma_mode,
31401 };
31402
31403 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31404 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31405 .name = DRV_NAME,
31406 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31407 .port_ops = &cs5520_port_ops,
31408 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31409 index 4dc4eb9..49b40ad 100644
31410 --- a/drivers/ide/cs5530.c
31411 +++ b/drivers/ide/cs5530.c
31412 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31413 .udma_filter = cs5530_udma_filter,
31414 };
31415
31416 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31417 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31418 .name = DRV_NAME,
31419 .init_chipset = init_chipset_cs5530,
31420 .init_hwif = init_hwif_cs5530,
31421 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31422 index 5059faf..18d4c85 100644
31423 --- a/drivers/ide/cs5535.c
31424 +++ b/drivers/ide/cs5535.c
31425 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31426 .cable_detect = cs5535_cable_detect,
31427 };
31428
31429 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31430 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31431 .name = DRV_NAME,
31432 .port_ops = &cs5535_port_ops,
31433 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31434 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31435 index 847553f..3ffb49d 100644
31436 --- a/drivers/ide/cy82c693.c
31437 +++ b/drivers/ide/cy82c693.c
31438 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31439 .set_dma_mode = cy82c693_set_dma_mode,
31440 };
31441
31442 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31443 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31444 .name = DRV_NAME,
31445 .init_iops = init_iops_cy82c693,
31446 .port_ops = &cy82c693_port_ops,
31447 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31448 index 58c51cd..4aec3b8 100644
31449 --- a/drivers/ide/hpt366.c
31450 +++ b/drivers/ide/hpt366.c
31451 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31452 }
31453 };
31454
31455 -static const struct hpt_info hpt36x __devinitdata = {
31456 +static const struct hpt_info hpt36x __devinitconst = {
31457 .chip_name = "HPT36x",
31458 .chip_type = HPT36x,
31459 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31460 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31461 .timings = &hpt36x_timings
31462 };
31463
31464 -static const struct hpt_info hpt370 __devinitdata = {
31465 +static const struct hpt_info hpt370 __devinitconst = {
31466 .chip_name = "HPT370",
31467 .chip_type = HPT370,
31468 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31469 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31470 .timings = &hpt37x_timings
31471 };
31472
31473 -static const struct hpt_info hpt370a __devinitdata = {
31474 +static const struct hpt_info hpt370a __devinitconst = {
31475 .chip_name = "HPT370A",
31476 .chip_type = HPT370A,
31477 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31478 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31479 .timings = &hpt37x_timings
31480 };
31481
31482 -static const struct hpt_info hpt374 __devinitdata = {
31483 +static const struct hpt_info hpt374 __devinitconst = {
31484 .chip_name = "HPT374",
31485 .chip_type = HPT374,
31486 .udma_mask = ATA_UDMA5,
31487 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31488 .timings = &hpt37x_timings
31489 };
31490
31491 -static const struct hpt_info hpt372 __devinitdata = {
31492 +static const struct hpt_info hpt372 __devinitconst = {
31493 .chip_name = "HPT372",
31494 .chip_type = HPT372,
31495 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31496 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31497 .timings = &hpt37x_timings
31498 };
31499
31500 -static const struct hpt_info hpt372a __devinitdata = {
31501 +static const struct hpt_info hpt372a __devinitconst = {
31502 .chip_name = "HPT372A",
31503 .chip_type = HPT372A,
31504 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31505 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31506 .timings = &hpt37x_timings
31507 };
31508
31509 -static const struct hpt_info hpt302 __devinitdata = {
31510 +static const struct hpt_info hpt302 __devinitconst = {
31511 .chip_name = "HPT302",
31512 .chip_type = HPT302,
31513 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31514 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31515 .timings = &hpt37x_timings
31516 };
31517
31518 -static const struct hpt_info hpt371 __devinitdata = {
31519 +static const struct hpt_info hpt371 __devinitconst = {
31520 .chip_name = "HPT371",
31521 .chip_type = HPT371,
31522 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31523 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31524 .timings = &hpt37x_timings
31525 };
31526
31527 -static const struct hpt_info hpt372n __devinitdata = {
31528 +static const struct hpt_info hpt372n __devinitconst = {
31529 .chip_name = "HPT372N",
31530 .chip_type = HPT372N,
31531 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31532 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31533 .timings = &hpt37x_timings
31534 };
31535
31536 -static const struct hpt_info hpt302n __devinitdata = {
31537 +static const struct hpt_info hpt302n __devinitconst = {
31538 .chip_name = "HPT302N",
31539 .chip_type = HPT302N,
31540 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31541 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31542 .timings = &hpt37x_timings
31543 };
31544
31545 -static const struct hpt_info hpt371n __devinitdata = {
31546 +static const struct hpt_info hpt371n __devinitconst = {
31547 .chip_name = "HPT371N",
31548 .chip_type = HPT371N,
31549 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31550 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31551 .dma_sff_read_status = ide_dma_sff_read_status,
31552 };
31553
31554 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31555 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31556 { /* 0: HPT36x */
31557 .name = DRV_NAME,
31558 .init_chipset = init_chipset_hpt366,
31559 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31560 index 8126824..55a2798 100644
31561 --- a/drivers/ide/ide-cd.c
31562 +++ b/drivers/ide/ide-cd.c
31563 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31564 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31565 if ((unsigned long)buf & alignment
31566 || blk_rq_bytes(rq) & q->dma_pad_mask
31567 - || object_is_on_stack(buf))
31568 + || object_starts_on_stack(buf))
31569 drive->dma = 0;
31570 }
31571 }
31572 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31573 index 7f56b73..dab5b67 100644
31574 --- a/drivers/ide/ide-pci-generic.c
31575 +++ b/drivers/ide/ide-pci-generic.c
31576 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31577 .udma_mask = ATA_UDMA6, \
31578 }
31579
31580 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31581 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31582 /* 0: Unknown */
31583 DECLARE_GENERIC_PCI_DEV(0),
31584
31585 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31586 index 560e66d..d5dd180 100644
31587 --- a/drivers/ide/it8172.c
31588 +++ b/drivers/ide/it8172.c
31589 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31590 .set_dma_mode = it8172_set_dma_mode,
31591 };
31592
31593 -static const struct ide_port_info it8172_port_info __devinitdata = {
31594 +static const struct ide_port_info it8172_port_info __devinitconst = {
31595 .name = DRV_NAME,
31596 .port_ops = &it8172_port_ops,
31597 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31598 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31599 index 46816ba..1847aeb 100644
31600 --- a/drivers/ide/it8213.c
31601 +++ b/drivers/ide/it8213.c
31602 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31603 .cable_detect = it8213_cable_detect,
31604 };
31605
31606 -static const struct ide_port_info it8213_chipset __devinitdata = {
31607 +static const struct ide_port_info it8213_chipset __devinitconst = {
31608 .name = DRV_NAME,
31609 .enablebits = { {0x41, 0x80, 0x80} },
31610 .port_ops = &it8213_port_ops,
31611 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31612 index 2e3169f..c5611db 100644
31613 --- a/drivers/ide/it821x.c
31614 +++ b/drivers/ide/it821x.c
31615 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31616 .cable_detect = it821x_cable_detect,
31617 };
31618
31619 -static const struct ide_port_info it821x_chipset __devinitdata = {
31620 +static const struct ide_port_info it821x_chipset __devinitconst = {
31621 .name = DRV_NAME,
31622 .init_chipset = init_chipset_it821x,
31623 .init_hwif = init_hwif_it821x,
31624 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31625 index 74c2c4a..efddd7d 100644
31626 --- a/drivers/ide/jmicron.c
31627 +++ b/drivers/ide/jmicron.c
31628 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31629 .cable_detect = jmicron_cable_detect,
31630 };
31631
31632 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31633 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31634 .name = DRV_NAME,
31635 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31636 .port_ops = &jmicron_port_ops,
31637 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31638 index 95327a2..73f78d8 100644
31639 --- a/drivers/ide/ns87415.c
31640 +++ b/drivers/ide/ns87415.c
31641 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31642 .dma_sff_read_status = superio_dma_sff_read_status,
31643 };
31644
31645 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31646 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31647 .name = DRV_NAME,
31648 .init_hwif = init_hwif_ns87415,
31649 .tp_ops = &ns87415_tp_ops,
31650 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31651 index 1a53a4c..39edc66 100644
31652 --- a/drivers/ide/opti621.c
31653 +++ b/drivers/ide/opti621.c
31654 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31655 .set_pio_mode = opti621_set_pio_mode,
31656 };
31657
31658 -static const struct ide_port_info opti621_chipset __devinitdata = {
31659 +static const struct ide_port_info opti621_chipset __devinitconst = {
31660 .name = DRV_NAME,
31661 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31662 .port_ops = &opti621_port_ops,
31663 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31664 index 9546fe2..2e5ceb6 100644
31665 --- a/drivers/ide/pdc202xx_new.c
31666 +++ b/drivers/ide/pdc202xx_new.c
31667 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31668 .udma_mask = udma, \
31669 }
31670
31671 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31672 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31673 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31674 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31675 };
31676 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31677 index 3a35ec6..5634510 100644
31678 --- a/drivers/ide/pdc202xx_old.c
31679 +++ b/drivers/ide/pdc202xx_old.c
31680 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31681 .max_sectors = sectors, \
31682 }
31683
31684 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31685 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31686 { /* 0: PDC20246 */
31687 .name = DRV_NAME,
31688 .init_chipset = init_chipset_pdc202xx,
31689 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31690 index 1892e81..fe0fd60 100644
31691 --- a/drivers/ide/piix.c
31692 +++ b/drivers/ide/piix.c
31693 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31694 .udma_mask = udma, \
31695 }
31696
31697 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31698 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31699 /* 0: MPIIX */
31700 { /*
31701 * MPIIX actually has only a single IDE channel mapped to
31702 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31703 index a6414a8..c04173e 100644
31704 --- a/drivers/ide/rz1000.c
31705 +++ b/drivers/ide/rz1000.c
31706 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31707 }
31708 }
31709
31710 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31711 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31712 .name = DRV_NAME,
31713 .host_flags = IDE_HFLAG_NO_DMA,
31714 };
31715 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31716 index 356b9b5..d4758eb 100644
31717 --- a/drivers/ide/sc1200.c
31718 +++ b/drivers/ide/sc1200.c
31719 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31720 .dma_sff_read_status = ide_dma_sff_read_status,
31721 };
31722
31723 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31724 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31725 .name = DRV_NAME,
31726 .port_ops = &sc1200_port_ops,
31727 .dma_ops = &sc1200_dma_ops,
31728 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31729 index b7f5b0c..9701038 100644
31730 --- a/drivers/ide/scc_pata.c
31731 +++ b/drivers/ide/scc_pata.c
31732 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31733 .dma_sff_read_status = scc_dma_sff_read_status,
31734 };
31735
31736 -static const struct ide_port_info scc_chipset __devinitdata = {
31737 +static const struct ide_port_info scc_chipset __devinitconst = {
31738 .name = "sccIDE",
31739 .init_iops = init_iops_scc,
31740 .init_dma = scc_init_dma,
31741 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31742 index 35fb8da..24d72ef 100644
31743 --- a/drivers/ide/serverworks.c
31744 +++ b/drivers/ide/serverworks.c
31745 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31746 .cable_detect = svwks_cable_detect,
31747 };
31748
31749 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31750 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31751 { /* 0: OSB4 */
31752 .name = DRV_NAME,
31753 .init_chipset = init_chipset_svwks,
31754 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31755 index ddeda44..46f7e30 100644
31756 --- a/drivers/ide/siimage.c
31757 +++ b/drivers/ide/siimage.c
31758 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31759 .udma_mask = ATA_UDMA6, \
31760 }
31761
31762 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31763 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31764 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31765 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31766 };
31767 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31768 index 4a00225..09e61b4 100644
31769 --- a/drivers/ide/sis5513.c
31770 +++ b/drivers/ide/sis5513.c
31771 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31772 .cable_detect = sis_cable_detect,
31773 };
31774
31775 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31776 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31777 .name = DRV_NAME,
31778 .init_chipset = init_chipset_sis5513,
31779 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31780 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31781 index f21dc2a..d051cd2 100644
31782 --- a/drivers/ide/sl82c105.c
31783 +++ b/drivers/ide/sl82c105.c
31784 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31785 .dma_sff_read_status = ide_dma_sff_read_status,
31786 };
31787
31788 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31789 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31790 .name = DRV_NAME,
31791 .init_chipset = init_chipset_sl82c105,
31792 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31793 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31794 index 864ffe0..863a5e9 100644
31795 --- a/drivers/ide/slc90e66.c
31796 +++ b/drivers/ide/slc90e66.c
31797 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31798 .cable_detect = slc90e66_cable_detect,
31799 };
31800
31801 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31802 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31803 .name = DRV_NAME,
31804 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31805 .port_ops = &slc90e66_port_ops,
31806 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31807 index 4799d5c..1794678 100644
31808 --- a/drivers/ide/tc86c001.c
31809 +++ b/drivers/ide/tc86c001.c
31810 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31811 .dma_sff_read_status = ide_dma_sff_read_status,
31812 };
31813
31814 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31815 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31816 .name = DRV_NAME,
31817 .init_hwif = init_hwif_tc86c001,
31818 .port_ops = &tc86c001_port_ops,
31819 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31820 index 281c914..55ce1b8 100644
31821 --- a/drivers/ide/triflex.c
31822 +++ b/drivers/ide/triflex.c
31823 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31824 .set_dma_mode = triflex_set_mode,
31825 };
31826
31827 -static const struct ide_port_info triflex_device __devinitdata = {
31828 +static const struct ide_port_info triflex_device __devinitconst = {
31829 .name = DRV_NAME,
31830 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31831 .port_ops = &triflex_port_ops,
31832 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31833 index 4b42ca0..e494a98 100644
31834 --- a/drivers/ide/trm290.c
31835 +++ b/drivers/ide/trm290.c
31836 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31837 .dma_check = trm290_dma_check,
31838 };
31839
31840 -static const struct ide_port_info trm290_chipset __devinitdata = {
31841 +static const struct ide_port_info trm290_chipset __devinitconst = {
31842 .name = DRV_NAME,
31843 .init_hwif = init_hwif_trm290,
31844 .tp_ops = &trm290_tp_ops,
31845 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31846 index f46f49c..eb77678 100644
31847 --- a/drivers/ide/via82cxxx.c
31848 +++ b/drivers/ide/via82cxxx.c
31849 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31850 .cable_detect = via82cxxx_cable_detect,
31851 };
31852
31853 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31854 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31855 .name = DRV_NAME,
31856 .init_chipset = init_chipset_via82cxxx,
31857 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31858 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31859 index 73d4531..c90cd2d 100644
31860 --- a/drivers/ieee802154/fakehard.c
31861 +++ b/drivers/ieee802154/fakehard.c
31862 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31863 phy->transmit_power = 0xbf;
31864
31865 dev->netdev_ops = &fake_ops;
31866 - dev->ml_priv = &fake_mlme;
31867 + dev->ml_priv = (void *)&fake_mlme;
31868
31869 priv = netdev_priv(dev);
31870 priv->phy = phy;
31871 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31872 index c889aae..6cf5aa7 100644
31873 --- a/drivers/infiniband/core/cm.c
31874 +++ b/drivers/infiniband/core/cm.c
31875 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31876
31877 struct cm_counter_group {
31878 struct kobject obj;
31879 - atomic_long_t counter[CM_ATTR_COUNT];
31880 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31881 };
31882
31883 struct cm_counter_attribute {
31884 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31885 struct ib_mad_send_buf *msg = NULL;
31886 int ret;
31887
31888 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31889 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31890 counter[CM_REQ_COUNTER]);
31891
31892 /* Quick state check to discard duplicate REQs. */
31893 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31894 if (!cm_id_priv)
31895 return;
31896
31897 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31898 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31899 counter[CM_REP_COUNTER]);
31900 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31901 if (ret)
31902 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31903 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31904 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31905 spin_unlock_irq(&cm_id_priv->lock);
31906 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31907 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31908 counter[CM_RTU_COUNTER]);
31909 goto out;
31910 }
31911 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31912 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31913 dreq_msg->local_comm_id);
31914 if (!cm_id_priv) {
31915 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31916 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31917 counter[CM_DREQ_COUNTER]);
31918 cm_issue_drep(work->port, work->mad_recv_wc);
31919 return -EINVAL;
31920 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31921 case IB_CM_MRA_REP_RCVD:
31922 break;
31923 case IB_CM_TIMEWAIT:
31924 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31925 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31926 counter[CM_DREQ_COUNTER]);
31927 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31928 goto unlock;
31929 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31930 cm_free_msg(msg);
31931 goto deref;
31932 case IB_CM_DREQ_RCVD:
31933 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31934 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31935 counter[CM_DREQ_COUNTER]);
31936 goto unlock;
31937 default:
31938 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31939 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31940 cm_id_priv->msg, timeout)) {
31941 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31942 - atomic_long_inc(&work->port->
31943 + atomic_long_inc_unchecked(&work->port->
31944 counter_group[CM_RECV_DUPLICATES].
31945 counter[CM_MRA_COUNTER]);
31946 goto out;
31947 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31948 break;
31949 case IB_CM_MRA_REQ_RCVD:
31950 case IB_CM_MRA_REP_RCVD:
31951 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31952 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31953 counter[CM_MRA_COUNTER]);
31954 /* fall through */
31955 default:
31956 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31957 case IB_CM_LAP_IDLE:
31958 break;
31959 case IB_CM_MRA_LAP_SENT:
31960 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31961 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31962 counter[CM_LAP_COUNTER]);
31963 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31964 goto unlock;
31965 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31966 cm_free_msg(msg);
31967 goto deref;
31968 case IB_CM_LAP_RCVD:
31969 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31970 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31971 counter[CM_LAP_COUNTER]);
31972 goto unlock;
31973 default:
31974 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31975 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31976 if (cur_cm_id_priv) {
31977 spin_unlock_irq(&cm.lock);
31978 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31979 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31980 counter[CM_SIDR_REQ_COUNTER]);
31981 goto out; /* Duplicate message. */
31982 }
31983 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31984 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31985 msg->retries = 1;
31986
31987 - atomic_long_add(1 + msg->retries,
31988 + atomic_long_add_unchecked(1 + msg->retries,
31989 &port->counter_group[CM_XMIT].counter[attr_index]);
31990 if (msg->retries)
31991 - atomic_long_add(msg->retries,
31992 + atomic_long_add_unchecked(msg->retries,
31993 &port->counter_group[CM_XMIT_RETRIES].
31994 counter[attr_index]);
31995
31996 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31997 }
31998
31999 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32000 - atomic_long_inc(&port->counter_group[CM_RECV].
32001 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32002 counter[attr_id - CM_ATTR_ID_OFFSET]);
32003
32004 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32005 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32006 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32007
32008 return sprintf(buf, "%ld\n",
32009 - atomic_long_read(&group->counter[cm_attr->index]));
32010 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32011 }
32012
32013 static const struct sysfs_ops cm_counter_ops = {
32014 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32015 index 176c8f9..2627b62 100644
32016 --- a/drivers/infiniband/core/fmr_pool.c
32017 +++ b/drivers/infiniband/core/fmr_pool.c
32018 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32019
32020 struct task_struct *thread;
32021
32022 - atomic_t req_ser;
32023 - atomic_t flush_ser;
32024 + atomic_unchecked_t req_ser;
32025 + atomic_unchecked_t flush_ser;
32026
32027 wait_queue_head_t force_wait;
32028 };
32029 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32030 struct ib_fmr_pool *pool = pool_ptr;
32031
32032 do {
32033 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32034 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32035 ib_fmr_batch_release(pool);
32036
32037 - atomic_inc(&pool->flush_ser);
32038 + atomic_inc_unchecked(&pool->flush_ser);
32039 wake_up_interruptible(&pool->force_wait);
32040
32041 if (pool->flush_function)
32042 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32043 }
32044
32045 set_current_state(TASK_INTERRUPTIBLE);
32046 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32047 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32048 !kthread_should_stop())
32049 schedule();
32050 __set_current_state(TASK_RUNNING);
32051 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32052 pool->dirty_watermark = params->dirty_watermark;
32053 pool->dirty_len = 0;
32054 spin_lock_init(&pool->pool_lock);
32055 - atomic_set(&pool->req_ser, 0);
32056 - atomic_set(&pool->flush_ser, 0);
32057 + atomic_set_unchecked(&pool->req_ser, 0);
32058 + atomic_set_unchecked(&pool->flush_ser, 0);
32059 init_waitqueue_head(&pool->force_wait);
32060
32061 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32062 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32063 }
32064 spin_unlock_irq(&pool->pool_lock);
32065
32066 - serial = atomic_inc_return(&pool->req_ser);
32067 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32068 wake_up_process(pool->thread);
32069
32070 if (wait_event_interruptible(pool->force_wait,
32071 - atomic_read(&pool->flush_ser) - serial >= 0))
32072 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32073 return -EINTR;
32074
32075 return 0;
32076 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32077 } else {
32078 list_add_tail(&fmr->list, &pool->dirty_list);
32079 if (++pool->dirty_len >= pool->dirty_watermark) {
32080 - atomic_inc(&pool->req_ser);
32081 + atomic_inc_unchecked(&pool->req_ser);
32082 wake_up_process(pool->thread);
32083 }
32084 }
32085 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32086 index 57e07c6..56d09d4 100644
32087 --- a/drivers/infiniband/hw/cxgb4/mem.c
32088 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32089 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32090 int err;
32091 struct fw_ri_tpte tpt;
32092 u32 stag_idx;
32093 - static atomic_t key;
32094 + static atomic_unchecked_t key;
32095
32096 if (c4iw_fatal_error(rdev))
32097 return -EIO;
32098 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32099 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32100 rdev->stats.stag.max = rdev->stats.stag.cur;
32101 mutex_unlock(&rdev->stats.lock);
32102 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32103 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32104 }
32105 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32106 __func__, stag_state, type, pdid, stag_idx);
32107 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32108 index 79b3dbc..96e5fcc 100644
32109 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32110 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32111 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32112 struct ib_atomic_eth *ateth;
32113 struct ipath_ack_entry *e;
32114 u64 vaddr;
32115 - atomic64_t *maddr;
32116 + atomic64_unchecked_t *maddr;
32117 u64 sdata;
32118 u32 rkey;
32119 u8 next;
32120 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32121 IB_ACCESS_REMOTE_ATOMIC)))
32122 goto nack_acc_unlck;
32123 /* Perform atomic OP and save result. */
32124 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32125 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32126 sdata = be64_to_cpu(ateth->swap_data);
32127 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32128 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32129 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32130 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32131 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32132 be64_to_cpu(ateth->compare_data),
32133 sdata);
32134 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32135 index 1f95bba..9530f87 100644
32136 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32137 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32138 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32139 unsigned long flags;
32140 struct ib_wc wc;
32141 u64 sdata;
32142 - atomic64_t *maddr;
32143 + atomic64_unchecked_t *maddr;
32144 enum ib_wc_status send_status;
32145
32146 /*
32147 @@ -382,11 +382,11 @@ again:
32148 IB_ACCESS_REMOTE_ATOMIC)))
32149 goto acc_err;
32150 /* Perform atomic OP and save result. */
32151 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32152 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32153 sdata = wqe->wr.wr.atomic.compare_add;
32154 *(u64 *) sqp->s_sge.sge.vaddr =
32155 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32156 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32157 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32158 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32159 sdata, wqe->wr.wr.atomic.swap);
32160 goto send_comp;
32161 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32162 index 7140199..da60063 100644
32163 --- a/drivers/infiniband/hw/nes/nes.c
32164 +++ b/drivers/infiniband/hw/nes/nes.c
32165 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32166 LIST_HEAD(nes_adapter_list);
32167 static LIST_HEAD(nes_dev_list);
32168
32169 -atomic_t qps_destroyed;
32170 +atomic_unchecked_t qps_destroyed;
32171
32172 static unsigned int ee_flsh_adapter;
32173 static unsigned int sysfs_nonidx_addr;
32174 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32175 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32176 struct nes_adapter *nesadapter = nesdev->nesadapter;
32177
32178 - atomic_inc(&qps_destroyed);
32179 + atomic_inc_unchecked(&qps_destroyed);
32180
32181 /* Free the control structures */
32182
32183 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32184 index c438e46..ca30356 100644
32185 --- a/drivers/infiniband/hw/nes/nes.h
32186 +++ b/drivers/infiniband/hw/nes/nes.h
32187 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32188 extern unsigned int wqm_quanta;
32189 extern struct list_head nes_adapter_list;
32190
32191 -extern atomic_t cm_connects;
32192 -extern atomic_t cm_accepts;
32193 -extern atomic_t cm_disconnects;
32194 -extern atomic_t cm_closes;
32195 -extern atomic_t cm_connecteds;
32196 -extern atomic_t cm_connect_reqs;
32197 -extern atomic_t cm_rejects;
32198 -extern atomic_t mod_qp_timouts;
32199 -extern atomic_t qps_created;
32200 -extern atomic_t qps_destroyed;
32201 -extern atomic_t sw_qps_destroyed;
32202 +extern atomic_unchecked_t cm_connects;
32203 +extern atomic_unchecked_t cm_accepts;
32204 +extern atomic_unchecked_t cm_disconnects;
32205 +extern atomic_unchecked_t cm_closes;
32206 +extern atomic_unchecked_t cm_connecteds;
32207 +extern atomic_unchecked_t cm_connect_reqs;
32208 +extern atomic_unchecked_t cm_rejects;
32209 +extern atomic_unchecked_t mod_qp_timouts;
32210 +extern atomic_unchecked_t qps_created;
32211 +extern atomic_unchecked_t qps_destroyed;
32212 +extern atomic_unchecked_t sw_qps_destroyed;
32213 extern u32 mh_detected;
32214 extern u32 mh_pauses_sent;
32215 extern u32 cm_packets_sent;
32216 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32217 extern u32 cm_packets_received;
32218 extern u32 cm_packets_dropped;
32219 extern u32 cm_packets_retrans;
32220 -extern atomic_t cm_listens_created;
32221 -extern atomic_t cm_listens_destroyed;
32222 +extern atomic_unchecked_t cm_listens_created;
32223 +extern atomic_unchecked_t cm_listens_destroyed;
32224 extern u32 cm_backlog_drops;
32225 -extern atomic_t cm_loopbacks;
32226 -extern atomic_t cm_nodes_created;
32227 -extern atomic_t cm_nodes_destroyed;
32228 -extern atomic_t cm_accel_dropped_pkts;
32229 -extern atomic_t cm_resets_recvd;
32230 -extern atomic_t pau_qps_created;
32231 -extern atomic_t pau_qps_destroyed;
32232 +extern atomic_unchecked_t cm_loopbacks;
32233 +extern atomic_unchecked_t cm_nodes_created;
32234 +extern atomic_unchecked_t cm_nodes_destroyed;
32235 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32236 +extern atomic_unchecked_t cm_resets_recvd;
32237 +extern atomic_unchecked_t pau_qps_created;
32238 +extern atomic_unchecked_t pau_qps_destroyed;
32239
32240 extern u32 int_mod_timer_init;
32241 extern u32 int_mod_cq_depth_256;
32242 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32243 index 020e95c..fbb3450 100644
32244 --- a/drivers/infiniband/hw/nes/nes_cm.c
32245 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32246 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32247 u32 cm_packets_retrans;
32248 u32 cm_packets_created;
32249 u32 cm_packets_received;
32250 -atomic_t cm_listens_created;
32251 -atomic_t cm_listens_destroyed;
32252 +atomic_unchecked_t cm_listens_created;
32253 +atomic_unchecked_t cm_listens_destroyed;
32254 u32 cm_backlog_drops;
32255 -atomic_t cm_loopbacks;
32256 -atomic_t cm_nodes_created;
32257 -atomic_t cm_nodes_destroyed;
32258 -atomic_t cm_accel_dropped_pkts;
32259 -atomic_t cm_resets_recvd;
32260 +atomic_unchecked_t cm_loopbacks;
32261 +atomic_unchecked_t cm_nodes_created;
32262 +atomic_unchecked_t cm_nodes_destroyed;
32263 +atomic_unchecked_t cm_accel_dropped_pkts;
32264 +atomic_unchecked_t cm_resets_recvd;
32265
32266 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32267 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32268 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32269
32270 static struct nes_cm_core *g_cm_core;
32271
32272 -atomic_t cm_connects;
32273 -atomic_t cm_accepts;
32274 -atomic_t cm_disconnects;
32275 -atomic_t cm_closes;
32276 -atomic_t cm_connecteds;
32277 -atomic_t cm_connect_reqs;
32278 -atomic_t cm_rejects;
32279 +atomic_unchecked_t cm_connects;
32280 +atomic_unchecked_t cm_accepts;
32281 +atomic_unchecked_t cm_disconnects;
32282 +atomic_unchecked_t cm_closes;
32283 +atomic_unchecked_t cm_connecteds;
32284 +atomic_unchecked_t cm_connect_reqs;
32285 +atomic_unchecked_t cm_rejects;
32286
32287 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32288 {
32289 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32290 kfree(listener);
32291 listener = NULL;
32292 ret = 0;
32293 - atomic_inc(&cm_listens_destroyed);
32294 + atomic_inc_unchecked(&cm_listens_destroyed);
32295 } else {
32296 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32297 }
32298 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32299 cm_node->rem_mac);
32300
32301 add_hte_node(cm_core, cm_node);
32302 - atomic_inc(&cm_nodes_created);
32303 + atomic_inc_unchecked(&cm_nodes_created);
32304
32305 return cm_node;
32306 }
32307 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32308 }
32309
32310 atomic_dec(&cm_core->node_cnt);
32311 - atomic_inc(&cm_nodes_destroyed);
32312 + atomic_inc_unchecked(&cm_nodes_destroyed);
32313 nesqp = cm_node->nesqp;
32314 if (nesqp) {
32315 nesqp->cm_node = NULL;
32316 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32317
32318 static void drop_packet(struct sk_buff *skb)
32319 {
32320 - atomic_inc(&cm_accel_dropped_pkts);
32321 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32322 dev_kfree_skb_any(skb);
32323 }
32324
32325 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32326 {
32327
32328 int reset = 0; /* whether to send reset in case of err.. */
32329 - atomic_inc(&cm_resets_recvd);
32330 + atomic_inc_unchecked(&cm_resets_recvd);
32331 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32332 " refcnt=%d\n", cm_node, cm_node->state,
32333 atomic_read(&cm_node->ref_count));
32334 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32335 rem_ref_cm_node(cm_node->cm_core, cm_node);
32336 return NULL;
32337 }
32338 - atomic_inc(&cm_loopbacks);
32339 + atomic_inc_unchecked(&cm_loopbacks);
32340 loopbackremotenode->loopbackpartner = cm_node;
32341 loopbackremotenode->tcp_cntxt.rcv_wscale =
32342 NES_CM_DEFAULT_RCV_WND_SCALE;
32343 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32344 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32345 else {
32346 rem_ref_cm_node(cm_core, cm_node);
32347 - atomic_inc(&cm_accel_dropped_pkts);
32348 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32349 dev_kfree_skb_any(skb);
32350 }
32351 break;
32352 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32353
32354 if ((cm_id) && (cm_id->event_handler)) {
32355 if (issue_disconn) {
32356 - atomic_inc(&cm_disconnects);
32357 + atomic_inc_unchecked(&cm_disconnects);
32358 cm_event.event = IW_CM_EVENT_DISCONNECT;
32359 cm_event.status = disconn_status;
32360 cm_event.local_addr = cm_id->local_addr;
32361 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32362 }
32363
32364 if (issue_close) {
32365 - atomic_inc(&cm_closes);
32366 + atomic_inc_unchecked(&cm_closes);
32367 nes_disconnect(nesqp, 1);
32368
32369 cm_id->provider_data = nesqp;
32370 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32371
32372 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32373 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32374 - atomic_inc(&cm_accepts);
32375 + atomic_inc_unchecked(&cm_accepts);
32376
32377 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32378 netdev_refcnt_read(nesvnic->netdev));
32379 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32380 struct nes_cm_core *cm_core;
32381 u8 *start_buff;
32382
32383 - atomic_inc(&cm_rejects);
32384 + atomic_inc_unchecked(&cm_rejects);
32385 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32386 loopback = cm_node->loopbackpartner;
32387 cm_core = cm_node->cm_core;
32388 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32389 ntohl(cm_id->local_addr.sin_addr.s_addr),
32390 ntohs(cm_id->local_addr.sin_port));
32391
32392 - atomic_inc(&cm_connects);
32393 + atomic_inc_unchecked(&cm_connects);
32394 nesqp->active_conn = 1;
32395
32396 /* cache the cm_id in the qp */
32397 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32398 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32399 return err;
32400 }
32401 - atomic_inc(&cm_listens_created);
32402 + atomic_inc_unchecked(&cm_listens_created);
32403 }
32404
32405 cm_id->add_ref(cm_id);
32406 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32407
32408 if (nesqp->destroyed)
32409 return;
32410 - atomic_inc(&cm_connecteds);
32411 + atomic_inc_unchecked(&cm_connecteds);
32412 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32413 " local port 0x%04X. jiffies = %lu.\n",
32414 nesqp->hwqp.qp_id,
32415 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32416
32417 cm_id->add_ref(cm_id);
32418 ret = cm_id->event_handler(cm_id, &cm_event);
32419 - atomic_inc(&cm_closes);
32420 + atomic_inc_unchecked(&cm_closes);
32421 cm_event.event = IW_CM_EVENT_CLOSE;
32422 cm_event.status = 0;
32423 cm_event.provider_data = cm_id->provider_data;
32424 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32425 return;
32426 cm_id = cm_node->cm_id;
32427
32428 - atomic_inc(&cm_connect_reqs);
32429 + atomic_inc_unchecked(&cm_connect_reqs);
32430 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32431 cm_node, cm_id, jiffies);
32432
32433 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32434 return;
32435 cm_id = cm_node->cm_id;
32436
32437 - atomic_inc(&cm_connect_reqs);
32438 + atomic_inc_unchecked(&cm_connect_reqs);
32439 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32440 cm_node, cm_id, jiffies);
32441
32442 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32443 index 3ba7be3..c81f6ff 100644
32444 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32445 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32446 @@ -40,8 +40,8 @@
32447 #include "nes.h"
32448 #include "nes_mgt.h"
32449
32450 -atomic_t pau_qps_created;
32451 -atomic_t pau_qps_destroyed;
32452 +atomic_unchecked_t pau_qps_created;
32453 +atomic_unchecked_t pau_qps_destroyed;
32454
32455 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32456 {
32457 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32458 {
32459 struct sk_buff *skb;
32460 unsigned long flags;
32461 - atomic_inc(&pau_qps_destroyed);
32462 + atomic_inc_unchecked(&pau_qps_destroyed);
32463
32464 /* Free packets that have not yet been forwarded */
32465 /* Lock is acquired by skb_dequeue when removing the skb */
32466 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32467 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32468 skb_queue_head_init(&nesqp->pau_list);
32469 spin_lock_init(&nesqp->pau_lock);
32470 - atomic_inc(&pau_qps_created);
32471 + atomic_inc_unchecked(&pau_qps_created);
32472 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32473 }
32474
32475 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32476 index f3a3ecf..57d311d 100644
32477 --- a/drivers/infiniband/hw/nes/nes_nic.c
32478 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32479 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32480 target_stat_values[++index] = mh_detected;
32481 target_stat_values[++index] = mh_pauses_sent;
32482 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32483 - target_stat_values[++index] = atomic_read(&cm_connects);
32484 - target_stat_values[++index] = atomic_read(&cm_accepts);
32485 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32486 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32487 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32488 - target_stat_values[++index] = atomic_read(&cm_rejects);
32489 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32490 - target_stat_values[++index] = atomic_read(&qps_created);
32491 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32492 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32493 - target_stat_values[++index] = atomic_read(&cm_closes);
32494 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32495 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32496 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32497 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32498 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32499 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32500 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32501 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32502 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32503 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32504 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32505 target_stat_values[++index] = cm_packets_sent;
32506 target_stat_values[++index] = cm_packets_bounced;
32507 target_stat_values[++index] = cm_packets_created;
32508 target_stat_values[++index] = cm_packets_received;
32509 target_stat_values[++index] = cm_packets_dropped;
32510 target_stat_values[++index] = cm_packets_retrans;
32511 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32512 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32513 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32514 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32515 target_stat_values[++index] = cm_backlog_drops;
32516 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32517 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32518 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32519 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32520 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32521 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32522 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32523 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32524 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32525 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32526 target_stat_values[++index] = nesadapter->free_4kpbl;
32527 target_stat_values[++index] = nesadapter->free_256pbl;
32528 target_stat_values[++index] = int_mod_timer_init;
32529 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32530 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32531 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32532 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32533 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32534 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32535 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32536 }
32537
32538 /**
32539 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32540 index 8b8812d..a5e1133 100644
32541 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32542 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32543 @@ -46,9 +46,9 @@
32544
32545 #include <rdma/ib_umem.h>
32546
32547 -atomic_t mod_qp_timouts;
32548 -atomic_t qps_created;
32549 -atomic_t sw_qps_destroyed;
32550 +atomic_unchecked_t mod_qp_timouts;
32551 +atomic_unchecked_t qps_created;
32552 +atomic_unchecked_t sw_qps_destroyed;
32553
32554 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32555
32556 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32557 if (init_attr->create_flags)
32558 return ERR_PTR(-EINVAL);
32559
32560 - atomic_inc(&qps_created);
32561 + atomic_inc_unchecked(&qps_created);
32562 switch (init_attr->qp_type) {
32563 case IB_QPT_RC:
32564 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32565 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32566 struct iw_cm_event cm_event;
32567 int ret = 0;
32568
32569 - atomic_inc(&sw_qps_destroyed);
32570 + atomic_inc_unchecked(&sw_qps_destroyed);
32571 nesqp->destroyed = 1;
32572
32573 /* Blow away the connection if it exists. */
32574 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32575 index 7e62f41..4c2b8e2 100644
32576 --- a/drivers/infiniband/hw/qib/qib.h
32577 +++ b/drivers/infiniband/hw/qib/qib.h
32578 @@ -51,6 +51,7 @@
32579 #include <linux/completion.h>
32580 #include <linux/kref.h>
32581 #include <linux/sched.h>
32582 +#include <linux/slab.h>
32583
32584 #include "qib_common.h"
32585 #include "qib_verbs.h"
32586 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32587 index da739d9..da1c7f4 100644
32588 --- a/drivers/input/gameport/gameport.c
32589 +++ b/drivers/input/gameport/gameport.c
32590 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32591 */
32592 static void gameport_init_port(struct gameport *gameport)
32593 {
32594 - static atomic_t gameport_no = ATOMIC_INIT(0);
32595 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32596
32597 __module_get(THIS_MODULE);
32598
32599 mutex_init(&gameport->drv_mutex);
32600 device_initialize(&gameport->dev);
32601 dev_set_name(&gameport->dev, "gameport%lu",
32602 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32603 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32604 gameport->dev.bus = &gameport_bus;
32605 gameport->dev.release = gameport_release_port;
32606 if (gameport->parent)
32607 diff --git a/drivers/input/input.c b/drivers/input/input.c
32608 index 8921c61..f5cd63d 100644
32609 --- a/drivers/input/input.c
32610 +++ b/drivers/input/input.c
32611 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32612 */
32613 int input_register_device(struct input_dev *dev)
32614 {
32615 - static atomic_t input_no = ATOMIC_INIT(0);
32616 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32617 struct input_handler *handler;
32618 const char *path;
32619 int error;
32620 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32621 dev->setkeycode = input_default_setkeycode;
32622
32623 dev_set_name(&dev->dev, "input%ld",
32624 - (unsigned long) atomic_inc_return(&input_no) - 1);
32625 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32626
32627 error = device_add(&dev->dev);
32628 if (error)
32629 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32630 index 04c69af..5f92d00 100644
32631 --- a/drivers/input/joystick/sidewinder.c
32632 +++ b/drivers/input/joystick/sidewinder.c
32633 @@ -30,6 +30,7 @@
32634 #include <linux/kernel.h>
32635 #include <linux/module.h>
32636 #include <linux/slab.h>
32637 +#include <linux/sched.h>
32638 #include <linux/init.h>
32639 #include <linux/input.h>
32640 #include <linux/gameport.h>
32641 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32642 index 83811e4..0822b90 100644
32643 --- a/drivers/input/joystick/xpad.c
32644 +++ b/drivers/input/joystick/xpad.c
32645 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32646
32647 static int xpad_led_probe(struct usb_xpad *xpad)
32648 {
32649 - static atomic_t led_seq = ATOMIC_INIT(0);
32650 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32651 long led_no;
32652 struct xpad_led *led;
32653 struct led_classdev *led_cdev;
32654 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32655 if (!led)
32656 return -ENOMEM;
32657
32658 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32659 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32660
32661 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32662 led->xpad = xpad;
32663 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32664 index 0110b5a..d3ad144 100644
32665 --- a/drivers/input/mousedev.c
32666 +++ b/drivers/input/mousedev.c
32667 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32668
32669 spin_unlock_irq(&client->packet_lock);
32670
32671 - if (copy_to_user(buffer, data, count))
32672 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32673 return -EFAULT;
32674
32675 return count;
32676 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32677 index d0f7533..fb8215b 100644
32678 --- a/drivers/input/serio/serio.c
32679 +++ b/drivers/input/serio/serio.c
32680 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32681 */
32682 static void serio_init_port(struct serio *serio)
32683 {
32684 - static atomic_t serio_no = ATOMIC_INIT(0);
32685 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32686
32687 __module_get(THIS_MODULE);
32688
32689 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32690 mutex_init(&serio->drv_mutex);
32691 device_initialize(&serio->dev);
32692 dev_set_name(&serio->dev, "serio%ld",
32693 - (long)atomic_inc_return(&serio_no) - 1);
32694 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32695 serio->dev.bus = &serio_bus;
32696 serio->dev.release = serio_release_port;
32697 serio->dev.groups = serio_device_attr_groups;
32698 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32699 index 38c4bd8..58965d9 100644
32700 --- a/drivers/isdn/capi/capi.c
32701 +++ b/drivers/isdn/capi/capi.c
32702 @@ -83,8 +83,8 @@ struct capiminor {
32703
32704 struct capi20_appl *ap;
32705 u32 ncci;
32706 - atomic_t datahandle;
32707 - atomic_t msgid;
32708 + atomic_unchecked_t datahandle;
32709 + atomic_unchecked_t msgid;
32710
32711 struct tty_port port;
32712 int ttyinstop;
32713 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32714 capimsg_setu16(s, 2, mp->ap->applid);
32715 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32716 capimsg_setu8 (s, 5, CAPI_RESP);
32717 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32718 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32719 capimsg_setu32(s, 8, mp->ncci);
32720 capimsg_setu16(s, 12, datahandle);
32721 }
32722 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32723 mp->outbytes -= len;
32724 spin_unlock_bh(&mp->outlock);
32725
32726 - datahandle = atomic_inc_return(&mp->datahandle);
32727 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32728 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32729 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32730 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32731 capimsg_setu16(skb->data, 2, mp->ap->applid);
32732 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32733 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32734 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32735 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32736 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32737 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32738 capimsg_setu16(skb->data, 16, len); /* Data length */
32739 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32740 index a6d9fd2..afdb8a3 100644
32741 --- a/drivers/isdn/gigaset/interface.c
32742 +++ b/drivers/isdn/gigaset/interface.c
32743 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32744 }
32745 tty->driver_data = cs;
32746
32747 - ++cs->port.count;
32748 + atomic_inc(&cs->port.count);
32749
32750 - if (cs->port.count == 1) {
32751 + if (atomic_read(&cs->port.count) == 1) {
32752 tty_port_tty_set(&cs->port, tty);
32753 tty->low_latency = 1;
32754 }
32755 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32756
32757 if (!cs->connected)
32758 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32759 - else if (!cs->port.count)
32760 + else if (!atomic_read(&cs->port.count))
32761 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32762 - else if (!--cs->port.count)
32763 + else if (!atomic_dec_return(&cs->port.count))
32764 tty_port_tty_set(&cs->port, NULL);
32765
32766 mutex_unlock(&cs->mutex);
32767 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32768 index 821f7ac..28d4030 100644
32769 --- a/drivers/isdn/hardware/avm/b1.c
32770 +++ b/drivers/isdn/hardware/avm/b1.c
32771 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32772 }
32773 if (left) {
32774 if (t4file->user) {
32775 - if (copy_from_user(buf, dp, left))
32776 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32777 return -EFAULT;
32778 } else {
32779 memcpy(buf, dp, left);
32780 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32781 }
32782 if (left) {
32783 if (config->user) {
32784 - if (copy_from_user(buf, dp, left))
32785 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32786 return -EFAULT;
32787 } else {
32788 memcpy(buf, dp, left);
32789 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32790 index dd6b53a..19d9ee6 100644
32791 --- a/drivers/isdn/hardware/eicon/divasync.h
32792 +++ b/drivers/isdn/hardware/eicon/divasync.h
32793 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32794 } diva_didd_add_adapter_t;
32795 typedef struct _diva_didd_remove_adapter {
32796 IDI_CALL p_request;
32797 -} diva_didd_remove_adapter_t;
32798 +} __no_const diva_didd_remove_adapter_t;
32799 typedef struct _diva_didd_read_adapter_array {
32800 void *buffer;
32801 dword length;
32802 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32803 index d303e65..28bcb7b 100644
32804 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32805 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32806 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32807 typedef struct _diva_os_idi_adapter_interface {
32808 diva_init_card_proc_t cleanup_adapter_proc;
32809 diva_cmd_card_proc_t cmd_proc;
32810 -} diva_os_idi_adapter_interface_t;
32811 +} __no_const diva_os_idi_adapter_interface_t;
32812
32813 typedef struct _diva_os_xdi_adapter {
32814 struct list_head link;
32815 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32816 index 7bc5067..fd36232 100644
32817 --- a/drivers/isdn/i4l/isdn_tty.c
32818 +++ b/drivers/isdn/i4l/isdn_tty.c
32819 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32820 port = &info->port;
32821 #ifdef ISDN_DEBUG_MODEM_OPEN
32822 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32823 - port->count);
32824 + atomic_read(&port->count))
32825 #endif
32826 - port->count++;
32827 + atomic_inc(&port->count);
32828 tty->driver_data = info;
32829 port->tty = tty;
32830 tty->port = port;
32831 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32832 #endif
32833 return;
32834 }
32835 - if ((tty->count == 1) && (port->count != 1)) {
32836 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32837 /*
32838 * Uh, oh. tty->count is 1, which means that the tty
32839 * structure will be freed. Info->count should always
32840 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32841 * serial port won't be shutdown.
32842 */
32843 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32844 - "info->count is %d\n", port->count);
32845 - port->count = 1;
32846 + "info->count is %d\n", atomic_read(&port->count));
32847 + atomic_set(&port->count, 1);
32848 }
32849 - if (--port->count < 0) {
32850 + if (atomic_dec_return(&port->count) < 0) {
32851 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32852 - info->line, port->count);
32853 - port->count = 0;
32854 + info->line, atomic_read(&port->count));
32855 + atomic_set(&port->count, 0);
32856 }
32857 - if (port->count) {
32858 + if (atomic_read(&port->count)) {
32859 #ifdef ISDN_DEBUG_MODEM_OPEN
32860 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32861 #endif
32862 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32863 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32864 return;
32865 isdn_tty_shutdown(info);
32866 - port->count = 0;
32867 + atomic_set(&port->count, 0);
32868 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32869 port->tty = NULL;
32870 wake_up_interruptible(&port->open_wait);
32871 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32872 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32873 modem_info *info = &dev->mdm.info[i];
32874
32875 - if (info->port.count == 0)
32876 + if (atomic_read(&info->port.count) == 0)
32877 continue;
32878 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32879 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32880 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32881 index e74df7c..03a03ba 100644
32882 --- a/drivers/isdn/icn/icn.c
32883 +++ b/drivers/isdn/icn/icn.c
32884 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32885 if (count > len)
32886 count = len;
32887 if (user) {
32888 - if (copy_from_user(msg, buf, count))
32889 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32890 return -EFAULT;
32891 } else
32892 memcpy(msg, buf, count);
32893 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32894 index b5fdcb7..5b6c59f 100644
32895 --- a/drivers/lguest/core.c
32896 +++ b/drivers/lguest/core.c
32897 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32898 * it's worked so far. The end address needs +1 because __get_vm_area
32899 * allocates an extra guard page, so we need space for that.
32900 */
32901 +
32902 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32903 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32904 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32905 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32906 +#else
32907 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32908 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32909 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32910 +#endif
32911 +
32912 if (!switcher_vma) {
32913 err = -ENOMEM;
32914 printk("lguest: could not map switcher pages high\n");
32915 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32916 * Now the Switcher is mapped at the right address, we can't fail!
32917 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32918 */
32919 - memcpy(switcher_vma->addr, start_switcher_text,
32920 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32921 end_switcher_text - start_switcher_text);
32922
32923 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32924 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32925 index 39809035..ce25c5e 100644
32926 --- a/drivers/lguest/x86/core.c
32927 +++ b/drivers/lguest/x86/core.c
32928 @@ -59,7 +59,7 @@ static struct {
32929 /* Offset from where switcher.S was compiled to where we've copied it */
32930 static unsigned long switcher_offset(void)
32931 {
32932 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32933 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32934 }
32935
32936 /* This cpu's struct lguest_pages. */
32937 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32938 * These copies are pretty cheap, so we do them unconditionally: */
32939 /* Save the current Host top-level page directory.
32940 */
32941 +
32942 +#ifdef CONFIG_PAX_PER_CPU_PGD
32943 + pages->state.host_cr3 = read_cr3();
32944 +#else
32945 pages->state.host_cr3 = __pa(current->mm->pgd);
32946 +#endif
32947 +
32948 /*
32949 * Set up the Guest's page tables to see this CPU's pages (and no
32950 * other CPU's pages).
32951 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32952 * compiled-in switcher code and the high-mapped copy we just made.
32953 */
32954 for (i = 0; i < IDT_ENTRIES; i++)
32955 - default_idt_entries[i] += switcher_offset();
32956 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32957
32958 /*
32959 * Set up the Switcher's per-cpu areas.
32960 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32961 * it will be undisturbed when we switch. To change %cs and jump we
32962 * need this structure to feed to Intel's "lcall" instruction.
32963 */
32964 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32965 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32966 lguest_entry.segment = LGUEST_CS;
32967
32968 /*
32969 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32970 index 40634b0..4f5855e 100644
32971 --- a/drivers/lguest/x86/switcher_32.S
32972 +++ b/drivers/lguest/x86/switcher_32.S
32973 @@ -87,6 +87,7 @@
32974 #include <asm/page.h>
32975 #include <asm/segment.h>
32976 #include <asm/lguest.h>
32977 +#include <asm/processor-flags.h>
32978
32979 // We mark the start of the code to copy
32980 // It's placed in .text tho it's never run here
32981 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32982 // Changes type when we load it: damn Intel!
32983 // For after we switch over our page tables
32984 // That entry will be read-only: we'd crash.
32985 +
32986 +#ifdef CONFIG_PAX_KERNEXEC
32987 + mov %cr0, %edx
32988 + xor $X86_CR0_WP, %edx
32989 + mov %edx, %cr0
32990 +#endif
32991 +
32992 movl $(GDT_ENTRY_TSS*8), %edx
32993 ltr %dx
32994
32995 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32996 // Let's clear it again for our return.
32997 // The GDT descriptor of the Host
32998 // Points to the table after two "size" bytes
32999 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33000 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33001 // Clear "used" from type field (byte 5, bit 2)
33002 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33003 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33004 +
33005 +#ifdef CONFIG_PAX_KERNEXEC
33006 + mov %cr0, %eax
33007 + xor $X86_CR0_WP, %eax
33008 + mov %eax, %cr0
33009 +#endif
33010
33011 // Once our page table's switched, the Guest is live!
33012 // The Host fades as we run this final step.
33013 @@ -295,13 +309,12 @@ deliver_to_host:
33014 // I consulted gcc, and it gave
33015 // These instructions, which I gladly credit:
33016 leal (%edx,%ebx,8), %eax
33017 - movzwl (%eax),%edx
33018 - movl 4(%eax), %eax
33019 - xorw %ax, %ax
33020 - orl %eax, %edx
33021 + movl 4(%eax), %edx
33022 + movw (%eax), %dx
33023 // Now the address of the handler's in %edx
33024 // We call it now: its "iret" drops us home.
33025 - jmp *%edx
33026 + ljmp $__KERNEL_CS, $1f
33027 +1: jmp *%edx
33028
33029 // Every interrupt can come to us here
33030 // But we must truly tell each apart.
33031 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33032 index 20e5c2c..9e849a9 100644
33033 --- a/drivers/macintosh/macio_asic.c
33034 +++ b/drivers/macintosh/macio_asic.c
33035 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33036 * MacIO is matched against any Apple ID, it's probe() function
33037 * will then decide wether it applies or not
33038 */
33039 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33040 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33041 .vendor = PCI_VENDOR_ID_APPLE,
33042 .device = PCI_ANY_ID,
33043 .subvendor = PCI_ANY_ID,
33044 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33045 index 15dbe03..743fc65 100644
33046 --- a/drivers/md/bitmap.c
33047 +++ b/drivers/md/bitmap.c
33048 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33049 chunk_kb ? "KB" : "B");
33050 if (bitmap->storage.file) {
33051 seq_printf(seq, ", file: ");
33052 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33053 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33054 }
33055
33056 seq_printf(seq, "\n");
33057 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33058 index a1a3e6d..1918bfc 100644
33059 --- a/drivers/md/dm-ioctl.c
33060 +++ b/drivers/md/dm-ioctl.c
33061 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33062 cmd == DM_LIST_VERSIONS_CMD)
33063 return 0;
33064
33065 - if ((cmd == DM_DEV_CREATE_CMD)) {
33066 + if (cmd == DM_DEV_CREATE_CMD) {
33067 if (!*param->name) {
33068 DMWARN("name not supplied when creating device");
33069 return -EINVAL;
33070 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33071 index b58b7a3..8018b19 100644
33072 --- a/drivers/md/dm-raid1.c
33073 +++ b/drivers/md/dm-raid1.c
33074 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33075
33076 struct mirror {
33077 struct mirror_set *ms;
33078 - atomic_t error_count;
33079 + atomic_unchecked_t error_count;
33080 unsigned long error_type;
33081 struct dm_dev *dev;
33082 sector_t offset;
33083 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33084 struct mirror *m;
33085
33086 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33087 - if (!atomic_read(&m->error_count))
33088 + if (!atomic_read_unchecked(&m->error_count))
33089 return m;
33090
33091 return NULL;
33092 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33093 * simple way to tell if a device has encountered
33094 * errors.
33095 */
33096 - atomic_inc(&m->error_count);
33097 + atomic_inc_unchecked(&m->error_count);
33098
33099 if (test_and_set_bit(error_type, &m->error_type))
33100 return;
33101 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33102 struct mirror *m = get_default_mirror(ms);
33103
33104 do {
33105 - if (likely(!atomic_read(&m->error_count)))
33106 + if (likely(!atomic_read_unchecked(&m->error_count)))
33107 return m;
33108
33109 if (m-- == ms->mirror)
33110 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33111 {
33112 struct mirror *default_mirror = get_default_mirror(m->ms);
33113
33114 - return !atomic_read(&default_mirror->error_count);
33115 + return !atomic_read_unchecked(&default_mirror->error_count);
33116 }
33117
33118 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33119 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33120 */
33121 if (likely(region_in_sync(ms, region, 1)))
33122 m = choose_mirror(ms, bio->bi_sector);
33123 - else if (m && atomic_read(&m->error_count))
33124 + else if (m && atomic_read_unchecked(&m->error_count))
33125 m = NULL;
33126
33127 if (likely(m))
33128 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33129 }
33130
33131 ms->mirror[mirror].ms = ms;
33132 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33133 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33134 ms->mirror[mirror].error_type = 0;
33135 ms->mirror[mirror].offset = offset;
33136
33137 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33138 */
33139 static char device_status_char(struct mirror *m)
33140 {
33141 - if (!atomic_read(&(m->error_count)))
33142 + if (!atomic_read_unchecked(&(m->error_count)))
33143 return 'A';
33144
33145 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33146 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33147 index 35c94ff..20d4c17 100644
33148 --- a/drivers/md/dm-stripe.c
33149 +++ b/drivers/md/dm-stripe.c
33150 @@ -20,7 +20,7 @@ struct stripe {
33151 struct dm_dev *dev;
33152 sector_t physical_start;
33153
33154 - atomic_t error_count;
33155 + atomic_unchecked_t error_count;
33156 };
33157
33158 struct stripe_c {
33159 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33160 kfree(sc);
33161 return r;
33162 }
33163 - atomic_set(&(sc->stripe[i].error_count), 0);
33164 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33165 }
33166
33167 ti->private = sc;
33168 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33169 DMEMIT("%d ", sc->stripes);
33170 for (i = 0; i < sc->stripes; i++) {
33171 DMEMIT("%s ", sc->stripe[i].dev->name);
33172 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33173 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33174 'D' : 'A';
33175 }
33176 buffer[i] = '\0';
33177 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33178 */
33179 for (i = 0; i < sc->stripes; i++)
33180 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33181 - atomic_inc(&(sc->stripe[i].error_count));
33182 - if (atomic_read(&(sc->stripe[i].error_count)) <
33183 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33184 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33185 DM_IO_ERROR_THRESHOLD)
33186 schedule_work(&sc->trigger_event);
33187 }
33188 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33189 index 2e227fb..44ead1f 100644
33190 --- a/drivers/md/dm-table.c
33191 +++ b/drivers/md/dm-table.c
33192 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33193 if (!dev_size)
33194 return 0;
33195
33196 - if ((start >= dev_size) || (start + len > dev_size)) {
33197 + if ((start >= dev_size) || (len > dev_size - start)) {
33198 DMWARN("%s: %s too small for target: "
33199 "start=%llu, len=%llu, dev_size=%llu",
33200 dm_device_name(ti->table->md), bdevname(bdev, b),
33201 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33202 index 3e2907f..c28851a 100644
33203 --- a/drivers/md/dm-thin-metadata.c
33204 +++ b/drivers/md/dm-thin-metadata.c
33205 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33206
33207 pmd->info.tm = tm;
33208 pmd->info.levels = 2;
33209 - pmd->info.value_type.context = pmd->data_sm;
33210 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33211 pmd->info.value_type.size = sizeof(__le64);
33212 pmd->info.value_type.inc = data_block_inc;
33213 pmd->info.value_type.dec = data_block_dec;
33214 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33215
33216 pmd->bl_info.tm = tm;
33217 pmd->bl_info.levels = 1;
33218 - pmd->bl_info.value_type.context = pmd->data_sm;
33219 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33220 pmd->bl_info.value_type.size = sizeof(__le64);
33221 pmd->bl_info.value_type.inc = data_block_inc;
33222 pmd->bl_info.value_type.dec = data_block_dec;
33223 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33224 index e24143c..ce2f21a1 100644
33225 --- a/drivers/md/dm.c
33226 +++ b/drivers/md/dm.c
33227 @@ -176,9 +176,9 @@ struct mapped_device {
33228 /*
33229 * Event handling.
33230 */
33231 - atomic_t event_nr;
33232 + atomic_unchecked_t event_nr;
33233 wait_queue_head_t eventq;
33234 - atomic_t uevent_seq;
33235 + atomic_unchecked_t uevent_seq;
33236 struct list_head uevent_list;
33237 spinlock_t uevent_lock; /* Protect access to uevent_list */
33238
33239 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33240 rwlock_init(&md->map_lock);
33241 atomic_set(&md->holders, 1);
33242 atomic_set(&md->open_count, 0);
33243 - atomic_set(&md->event_nr, 0);
33244 - atomic_set(&md->uevent_seq, 0);
33245 + atomic_set_unchecked(&md->event_nr, 0);
33246 + atomic_set_unchecked(&md->uevent_seq, 0);
33247 INIT_LIST_HEAD(&md->uevent_list);
33248 spin_lock_init(&md->uevent_lock);
33249
33250 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33251
33252 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33253
33254 - atomic_inc(&md->event_nr);
33255 + atomic_inc_unchecked(&md->event_nr);
33256 wake_up(&md->eventq);
33257 }
33258
33259 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33260
33261 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33262 {
33263 - return atomic_add_return(1, &md->uevent_seq);
33264 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33265 }
33266
33267 uint32_t dm_get_event_nr(struct mapped_device *md)
33268 {
33269 - return atomic_read(&md->event_nr);
33270 + return atomic_read_unchecked(&md->event_nr);
33271 }
33272
33273 int dm_wait_event(struct mapped_device *md, int event_nr)
33274 {
33275 return wait_event_interruptible(md->eventq,
33276 - (event_nr != atomic_read(&md->event_nr)));
33277 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33278 }
33279
33280 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33281 diff --git a/drivers/md/md.c b/drivers/md/md.c
33282 index d5ab449..7e9ed7b 100644
33283 --- a/drivers/md/md.c
33284 +++ b/drivers/md/md.c
33285 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33286 * start build, activate spare
33287 */
33288 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33289 -static atomic_t md_event_count;
33290 +static atomic_unchecked_t md_event_count;
33291 void md_new_event(struct mddev *mddev)
33292 {
33293 - atomic_inc(&md_event_count);
33294 + atomic_inc_unchecked(&md_event_count);
33295 wake_up(&md_event_waiters);
33296 }
33297 EXPORT_SYMBOL_GPL(md_new_event);
33298 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33299 */
33300 static void md_new_event_inintr(struct mddev *mddev)
33301 {
33302 - atomic_inc(&md_event_count);
33303 + atomic_inc_unchecked(&md_event_count);
33304 wake_up(&md_event_waiters);
33305 }
33306
33307 @@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33308 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33309 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33310 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33311 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33312 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33313
33314 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33315 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33316 @@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33317 else
33318 sb->resync_offset = cpu_to_le64(0);
33319
33320 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33321 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33322
33323 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33324 sb->size = cpu_to_le64(mddev->dev_sectors);
33325 @@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33326 static ssize_t
33327 errors_show(struct md_rdev *rdev, char *page)
33328 {
33329 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33330 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33331 }
33332
33333 static ssize_t
33334 @@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33335 char *e;
33336 unsigned long n = simple_strtoul(buf, &e, 10);
33337 if (*buf && (*e == 0 || *e == '\n')) {
33338 - atomic_set(&rdev->corrected_errors, n);
33339 + atomic_set_unchecked(&rdev->corrected_errors, n);
33340 return len;
33341 }
33342 return -EINVAL;
33343 @@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33344 rdev->sb_loaded = 0;
33345 rdev->bb_page = NULL;
33346 atomic_set(&rdev->nr_pending, 0);
33347 - atomic_set(&rdev->read_errors, 0);
33348 - atomic_set(&rdev->corrected_errors, 0);
33349 + atomic_set_unchecked(&rdev->read_errors, 0);
33350 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33351
33352 INIT_LIST_HEAD(&rdev->same_set);
33353 init_waitqueue_head(&rdev->blocked_wait);
33354 @@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33355
33356 spin_unlock(&pers_lock);
33357 seq_printf(seq, "\n");
33358 - seq->poll_event = atomic_read(&md_event_count);
33359 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33360 return 0;
33361 }
33362 if (v == (void*)2) {
33363 @@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33364 return error;
33365
33366 seq = file->private_data;
33367 - seq->poll_event = atomic_read(&md_event_count);
33368 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33369 return error;
33370 }
33371
33372 @@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33373 /* always allow read */
33374 mask = POLLIN | POLLRDNORM;
33375
33376 - if (seq->poll_event != atomic_read(&md_event_count))
33377 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33378 mask |= POLLERR | POLLPRI;
33379 return mask;
33380 }
33381 @@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33382 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33383 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33384 (int)part_stat_read(&disk->part0, sectors[1]) -
33385 - atomic_read(&disk->sync_io);
33386 + atomic_read_unchecked(&disk->sync_io);
33387 /* sync IO will cause sync_io to increase before the disk_stats
33388 * as sync_io is counted when a request starts, and
33389 * disk_stats is counted when it completes.
33390 diff --git a/drivers/md/md.h b/drivers/md/md.h
33391 index 7b4a3c3..994ad4f 100644
33392 --- a/drivers/md/md.h
33393 +++ b/drivers/md/md.h
33394 @@ -94,13 +94,13 @@ struct md_rdev {
33395 * only maintained for arrays that
33396 * support hot removal
33397 */
33398 - atomic_t read_errors; /* number of consecutive read errors that
33399 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33400 * we have tried to ignore.
33401 */
33402 struct timespec last_read_error; /* monotonic time since our
33403 * last read error
33404 */
33405 - atomic_t corrected_errors; /* number of corrected read errors,
33406 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33407 * for reporting to userspace and storing
33408 * in superblock.
33409 */
33410 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33411
33412 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33413 {
33414 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33415 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33416 }
33417
33418 struct md_personality
33419 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33420 index fc90c11..c8cd9a9 100644
33421 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33422 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33423 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33424 /*----------------------------------------------------------------*/
33425
33426 struct sm_checker {
33427 - struct dm_space_map sm;
33428 + dm_space_map_no_const sm;
33429
33430 struct count_array old_counts;
33431 struct count_array counts;
33432 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33433 index 3d0ed53..35dc592 100644
33434 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33435 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33436 @@ -23,7 +23,7 @@
33437 * Space map interface.
33438 */
33439 struct sm_disk {
33440 - struct dm_space_map sm;
33441 + dm_space_map_no_const sm;
33442
33443 struct ll_disk ll;
33444 struct ll_disk old_ll;
33445 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33446 index e89ae5e..062e4c2 100644
33447 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33448 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33449 @@ -43,7 +43,7 @@ struct block_op {
33450 };
33451
33452 struct sm_metadata {
33453 - struct dm_space_map sm;
33454 + dm_space_map_no_const sm;
33455
33456 struct ll_disk ll;
33457 struct ll_disk old_ll;
33458 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33459 index 1cbfc6b..56e1dbb 100644
33460 --- a/drivers/md/persistent-data/dm-space-map.h
33461 +++ b/drivers/md/persistent-data/dm-space-map.h
33462 @@ -60,6 +60,7 @@ struct dm_space_map {
33463 int (*root_size)(struct dm_space_map *sm, size_t *result);
33464 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33465 };
33466 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33467
33468 /*----------------------------------------------------------------*/
33469
33470 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33471 index cacd008..2823610 100644
33472 --- a/drivers/md/raid1.c
33473 +++ b/drivers/md/raid1.c
33474 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33475 if (r1_sync_page_io(rdev, sect, s,
33476 bio->bi_io_vec[idx].bv_page,
33477 READ) != 0)
33478 - atomic_add(s, &rdev->corrected_errors);
33479 + atomic_add_unchecked(s, &rdev->corrected_errors);
33480 }
33481 sectors -= s;
33482 sect += s;
33483 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33484 test_bit(In_sync, &rdev->flags)) {
33485 if (r1_sync_page_io(rdev, sect, s,
33486 conf->tmppage, READ)) {
33487 - atomic_add(s, &rdev->corrected_errors);
33488 + atomic_add_unchecked(s, &rdev->corrected_errors);
33489 printk(KERN_INFO
33490 "md/raid1:%s: read error corrected "
33491 "(%d sectors at %llu on %s)\n",
33492 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33493 index 8da6282..8ec7103 100644
33494 --- a/drivers/md/raid10.c
33495 +++ b/drivers/md/raid10.c
33496 @@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33497 /* The write handler will notice the lack of
33498 * R10BIO_Uptodate and record any errors etc
33499 */
33500 - atomic_add(r10_bio->sectors,
33501 + atomic_add_unchecked(r10_bio->sectors,
33502 &conf->mirrors[d].rdev->corrected_errors);
33503
33504 /* for reconstruct, we always reschedule after a read.
33505 @@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33506 {
33507 struct timespec cur_time_mon;
33508 unsigned long hours_since_last;
33509 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33510 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33511
33512 ktime_get_ts(&cur_time_mon);
33513
33514 @@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33515 * overflowing the shift of read_errors by hours_since_last.
33516 */
33517 if (hours_since_last >= 8 * sizeof(read_errors))
33518 - atomic_set(&rdev->read_errors, 0);
33519 + atomic_set_unchecked(&rdev->read_errors, 0);
33520 else
33521 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33522 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33523 }
33524
33525 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33526 @@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33527 return;
33528
33529 check_decay_read_errors(mddev, rdev);
33530 - atomic_inc(&rdev->read_errors);
33531 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33532 + atomic_inc_unchecked(&rdev->read_errors);
33533 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33534 char b[BDEVNAME_SIZE];
33535 bdevname(rdev->bdev, b);
33536
33537 @@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33538 "md/raid10:%s: %s: Raid device exceeded "
33539 "read_error threshold [cur %d:max %d]\n",
33540 mdname(mddev), b,
33541 - atomic_read(&rdev->read_errors), max_read_errors);
33542 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33543 printk(KERN_NOTICE
33544 "md/raid10:%s: %s: Failing raid device\n",
33545 mdname(mddev), b);
33546 @@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33547 sect +
33548 choose_data_offset(r10_bio, rdev)),
33549 bdevname(rdev->bdev, b));
33550 - atomic_add(s, &rdev->corrected_errors);
33551 + atomic_add_unchecked(s, &rdev->corrected_errors);
33552 }
33553
33554 rdev_dec_pending(rdev, mddev);
33555 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33556 index 04348d7..62a4b9b 100644
33557 --- a/drivers/md/raid5.c
33558 +++ b/drivers/md/raid5.c
33559 @@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33560 mdname(conf->mddev), STRIPE_SECTORS,
33561 (unsigned long long)s,
33562 bdevname(rdev->bdev, b));
33563 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33564 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33565 clear_bit(R5_ReadError, &sh->dev[i].flags);
33566 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33567 }
33568 - if (atomic_read(&rdev->read_errors))
33569 - atomic_set(&rdev->read_errors, 0);
33570 + if (atomic_read_unchecked(&rdev->read_errors))
33571 + atomic_set_unchecked(&rdev->read_errors, 0);
33572 } else {
33573 const char *bdn = bdevname(rdev->bdev, b);
33574 int retry = 0;
33575 int set_bad = 0;
33576
33577 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33578 - atomic_inc(&rdev->read_errors);
33579 + atomic_inc_unchecked(&rdev->read_errors);
33580 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33581 printk_ratelimited(
33582 KERN_WARNING
33583 @@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33584 mdname(conf->mddev),
33585 (unsigned long long)s,
33586 bdn);
33587 - } else if (atomic_read(&rdev->read_errors)
33588 + } else if (atomic_read_unchecked(&rdev->read_errors)
33589 > conf->max_nr_stripes)
33590 printk(KERN_WARNING
33591 "md/raid:%s: Too many read errors, failing device %s.\n",
33592 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33593 index 131b938..8572ed1 100644
33594 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33595 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33596 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33597 .subvendor = _subvend, .subdevice = _subdev, \
33598 .driver_data = (unsigned long)&_driverdata }
33599
33600 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33601 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33602 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33603 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33604 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33605 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33606 index fa7188a..04a045e 100644
33607 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33608 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33609 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33610 union {
33611 dmx_ts_cb ts;
33612 dmx_section_cb sec;
33613 - } cb;
33614 + } __no_const cb;
33615
33616 struct dvb_demux *demux;
33617 void *priv;
33618 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33619 index 39eab73..60033e7 100644
33620 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33621 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33622 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33623 const struct dvb_device *template, void *priv, int type)
33624 {
33625 struct dvb_device *dvbdev;
33626 - struct file_operations *dvbdevfops;
33627 + file_operations_no_const *dvbdevfops;
33628 struct device *clsdev;
33629 int minor;
33630 int id;
33631 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33632 index 4008b9c..ce714f5 100644
33633 --- a/drivers/media/dvb/dvb-usb/az6007.c
33634 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33635 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33636 int ret;
33637
33638 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33639 - memcpy(mac, st->data, sizeof(mac));
33640 + memcpy(mac, st->data, 6);
33641
33642 if (ret > 0)
33643 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33644 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33645 index 3940bb0..fb3952a 100644
33646 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33647 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33648 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33649
33650 struct dib0700_adapter_state {
33651 int (*set_param_save) (struct dvb_frontend *);
33652 -};
33653 +} __no_const;
33654
33655 static int dib7070_set_param_override(struct dvb_frontend *fe)
33656 {
33657 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33658 index 9382895..ac8093c 100644
33659 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33660 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33661 @@ -95,7 +95,7 @@ struct su3000_state {
33662
33663 struct s6x0_state {
33664 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33665 -};
33666 +} __no_const;
33667
33668 /* debug */
33669 static int dvb_usb_dw2102_debug;
33670 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33671 index 404f63a..4796533 100644
33672 --- a/drivers/media/dvb/frontends/dib3000.h
33673 +++ b/drivers/media/dvb/frontends/dib3000.h
33674 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33675 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33676 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33677 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33678 -};
33679 +} __no_const;
33680
33681 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33682 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33683 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33684 index 7539a5d..06531a6 100644
33685 --- a/drivers/media/dvb/ngene/ngene-cards.c
33686 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33687 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33688
33689 /****************************************************************************/
33690
33691 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33692 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33693 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33694 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33695 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33696 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33697 index 16a089f..1661b11 100644
33698 --- a/drivers/media/radio/radio-cadet.c
33699 +++ b/drivers/media/radio/radio-cadet.c
33700 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33701 unsigned char readbuf[RDS_BUFFER];
33702 int i = 0;
33703
33704 + if (count > RDS_BUFFER)
33705 + return -EFAULT;
33706 mutex_lock(&dev->lock);
33707 if (dev->rdsstat == 0) {
33708 dev->rdsstat = 1;
33709 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33710 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33711 mutex_unlock(&dev->lock);
33712
33713 - if (copy_to_user(data, readbuf, i))
33714 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33715 return -EFAULT;
33716 return i;
33717 }
33718 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33719 index 9cde353..8c6a1c3 100644
33720 --- a/drivers/media/video/au0828/au0828.h
33721 +++ b/drivers/media/video/au0828/au0828.h
33722 @@ -191,7 +191,7 @@ struct au0828_dev {
33723
33724 /* I2C */
33725 struct i2c_adapter i2c_adap;
33726 - struct i2c_algorithm i2c_algo;
33727 + i2c_algorithm_no_const i2c_algo;
33728 struct i2c_client i2c_client;
33729 u32 i2c_rc;
33730
33731 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33732 index 04bf662..e0ac026 100644
33733 --- a/drivers/media/video/cx88/cx88-alsa.c
33734 +++ b/drivers/media/video/cx88/cx88-alsa.c
33735 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33736 * Only boards with eeprom and byte 1 at eeprom=1 have it
33737 */
33738
33739 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33740 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33741 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33742 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33743 {0, }
33744 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33745 index 88cf9d9..bbc4b2c 100644
33746 --- a/drivers/media/video/omap/omap_vout.c
33747 +++ b/drivers/media/video/omap/omap_vout.c
33748 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33749 OMAP_VIDEO2,
33750 };
33751
33752 -static struct videobuf_queue_ops video_vbq_ops;
33753 /* Variables configurable through module params*/
33754 static u32 video1_numbuffers = 3;
33755 static u32 video2_numbuffers = 3;
33756 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33757 {
33758 struct videobuf_queue *q;
33759 struct omap_vout_device *vout = NULL;
33760 + static struct videobuf_queue_ops video_vbq_ops = {
33761 + .buf_setup = omap_vout_buffer_setup,
33762 + .buf_prepare = omap_vout_buffer_prepare,
33763 + .buf_release = omap_vout_buffer_release,
33764 + .buf_queue = omap_vout_buffer_queue,
33765 + };
33766
33767 vout = video_drvdata(file);
33768 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33769 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33770 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33771
33772 q = &vout->vbq;
33773 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33774 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33775 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33776 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33777 spin_lock_init(&vout->vbq_lock);
33778
33779 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33780 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33781 index 036952f..80d356d 100644
33782 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33783 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33784 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33785
33786 /* I2C stuff */
33787 struct i2c_adapter i2c_adap;
33788 - struct i2c_algorithm i2c_algo;
33789 + i2c_algorithm_no_const i2c_algo;
33790 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33791 int i2c_cx25840_hack_state;
33792 int i2c_linked;
33793 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33794 index 02194c0..091733b 100644
33795 --- a/drivers/media/video/timblogiw.c
33796 +++ b/drivers/media/video/timblogiw.c
33797 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33798
33799 /* Platform device functions */
33800
33801 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33802 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33803 .vidioc_querycap = timblogiw_querycap,
33804 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33805 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33806 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33807 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33808 };
33809
33810 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33811 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33812 .owner = THIS_MODULE,
33813 .open = timblogiw_open,
33814 .release = timblogiw_close,
33815 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33816 index d99db56..a16b959 100644
33817 --- a/drivers/message/fusion/mptbase.c
33818 +++ b/drivers/message/fusion/mptbase.c
33819 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33820 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33821 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33822
33823 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33824 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33825 +#else
33826 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33827 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33828 +#endif
33829 +
33830 /*
33831 * Rounding UP to nearest 4-kB boundary here...
33832 */
33833 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33834 index 551262e..7551198 100644
33835 --- a/drivers/message/fusion/mptsas.c
33836 +++ b/drivers/message/fusion/mptsas.c
33837 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33838 return 0;
33839 }
33840
33841 +static inline void
33842 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33843 +{
33844 + if (phy_info->port_details) {
33845 + phy_info->port_details->rphy = rphy;
33846 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33847 + ioc->name, rphy));
33848 + }
33849 +
33850 + if (rphy) {
33851 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33852 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33853 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33854 + ioc->name, rphy, rphy->dev.release));
33855 + }
33856 +}
33857 +
33858 /* no mutex */
33859 static void
33860 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33861 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33862 return NULL;
33863 }
33864
33865 -static inline void
33866 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33867 -{
33868 - if (phy_info->port_details) {
33869 - phy_info->port_details->rphy = rphy;
33870 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33871 - ioc->name, rphy));
33872 - }
33873 -
33874 - if (rphy) {
33875 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33876 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33877 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33878 - ioc->name, rphy, rphy->dev.release));
33879 - }
33880 -}
33881 -
33882 static inline struct sas_port *
33883 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33884 {
33885 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33886 index 0c3ced7..1fe34ec 100644
33887 --- a/drivers/message/fusion/mptscsih.c
33888 +++ b/drivers/message/fusion/mptscsih.c
33889 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33890
33891 h = shost_priv(SChost);
33892
33893 - if (h) {
33894 - if (h->info_kbuf == NULL)
33895 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33896 - return h->info_kbuf;
33897 - h->info_kbuf[0] = '\0';
33898 + if (!h)
33899 + return NULL;
33900
33901 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33902 - h->info_kbuf[size-1] = '\0';
33903 - }
33904 + if (h->info_kbuf == NULL)
33905 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33906 + return h->info_kbuf;
33907 + h->info_kbuf[0] = '\0';
33908 +
33909 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33910 + h->info_kbuf[size-1] = '\0';
33911
33912 return h->info_kbuf;
33913 }
33914 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33915 index 506c36f..b137580 100644
33916 --- a/drivers/message/i2o/i2o_proc.c
33917 +++ b/drivers/message/i2o/i2o_proc.c
33918 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33919 "Array Controller Device"
33920 };
33921
33922 -static char *chtostr(u8 * chars, int n)
33923 -{
33924 - char tmp[256];
33925 - tmp[0] = 0;
33926 - return strncat(tmp, (char *)chars, n);
33927 -}
33928 -
33929 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33930 char *group)
33931 {
33932 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33933
33934 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33935 seq_printf(seq, "%-#8x", ddm_table.module_id);
33936 - seq_printf(seq, "%-29s",
33937 - chtostr(ddm_table.module_name_version, 28));
33938 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33939 seq_printf(seq, "%9d ", ddm_table.data_size);
33940 seq_printf(seq, "%8d", ddm_table.code_size);
33941
33942 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33943
33944 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33945 seq_printf(seq, "%-#8x", dst->module_id);
33946 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33947 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33948 + seq_printf(seq, "%-.28s", dst->module_name_version);
33949 + seq_printf(seq, "%-.8s", dst->date);
33950 seq_printf(seq, "%8d ", dst->module_size);
33951 seq_printf(seq, "%8d ", dst->mpb_size);
33952 seq_printf(seq, "0x%04x", dst->module_flags);
33953 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33954 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33955 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33956 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33957 - seq_printf(seq, "Vendor info : %s\n",
33958 - chtostr((u8 *) (work32 + 2), 16));
33959 - seq_printf(seq, "Product info : %s\n",
33960 - chtostr((u8 *) (work32 + 6), 16));
33961 - seq_printf(seq, "Description : %s\n",
33962 - chtostr((u8 *) (work32 + 10), 16));
33963 - seq_printf(seq, "Product rev. : %s\n",
33964 - chtostr((u8 *) (work32 + 14), 8));
33965 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33966 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33967 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33968 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33969
33970 seq_printf(seq, "Serial number : ");
33971 print_serial_number(seq, (u8 *) (work32 + 16),
33972 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33973 }
33974
33975 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33976 - seq_printf(seq, "Module name : %s\n",
33977 - chtostr(result.module_name, 24));
33978 - seq_printf(seq, "Module revision : %s\n",
33979 - chtostr(result.module_rev, 8));
33980 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33981 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33982
33983 seq_printf(seq, "Serial number : ");
33984 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33985 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33986 return 0;
33987 }
33988
33989 - seq_printf(seq, "Device name : %s\n",
33990 - chtostr(result.device_name, 64));
33991 - seq_printf(seq, "Service name : %s\n",
33992 - chtostr(result.service_name, 64));
33993 - seq_printf(seq, "Physical name : %s\n",
33994 - chtostr(result.physical_location, 64));
33995 - seq_printf(seq, "Instance number : %s\n",
33996 - chtostr(result.instance_number, 4));
33997 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33998 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33999 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34000 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34001
34002 return 0;
34003 }
34004 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34005 index a8c08f3..155fe3d 100644
34006 --- a/drivers/message/i2o/iop.c
34007 +++ b/drivers/message/i2o/iop.c
34008 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34009
34010 spin_lock_irqsave(&c->context_list_lock, flags);
34011
34012 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34013 - atomic_inc(&c->context_list_counter);
34014 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34015 + atomic_inc_unchecked(&c->context_list_counter);
34016
34017 - entry->context = atomic_read(&c->context_list_counter);
34018 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34019
34020 list_add(&entry->list, &c->context_list);
34021
34022 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34023
34024 #if BITS_PER_LONG == 64
34025 spin_lock_init(&c->context_list_lock);
34026 - atomic_set(&c->context_list_counter, 0);
34027 + atomic_set_unchecked(&c->context_list_counter, 0);
34028 INIT_LIST_HEAD(&c->context_list);
34029 #endif
34030
34031 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34032 index 7ce65f4..e66e9bc 100644
34033 --- a/drivers/mfd/abx500-core.c
34034 +++ b/drivers/mfd/abx500-core.c
34035 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34036
34037 struct abx500_device_entry {
34038 struct list_head list;
34039 - struct abx500_ops ops;
34040 + abx500_ops_no_const ops;
34041 struct device *dev;
34042 };
34043
34044 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34045 index 2ea9998..51dabee 100644
34046 --- a/drivers/mfd/janz-cmodio.c
34047 +++ b/drivers/mfd/janz-cmodio.c
34048 @@ -13,6 +13,7 @@
34049
34050 #include <linux/kernel.h>
34051 #include <linux/module.h>
34052 +#include <linux/slab.h>
34053 #include <linux/init.h>
34054 #include <linux/pci.h>
34055 #include <linux/interrupt.h>
34056 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34057 index a981e2a..5ca0c8b 100644
34058 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34059 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34060 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34061 * the lid is closed. This leads to interrupts as soon as a little move
34062 * is done.
34063 */
34064 - atomic_inc(&lis3->count);
34065 + atomic_inc_unchecked(&lis3->count);
34066
34067 wake_up_interruptible(&lis3->misc_wait);
34068 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34069 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34070 if (lis3->pm_dev)
34071 pm_runtime_get_sync(lis3->pm_dev);
34072
34073 - atomic_set(&lis3->count, 0);
34074 + atomic_set_unchecked(&lis3->count, 0);
34075 return 0;
34076 }
34077
34078 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34079 add_wait_queue(&lis3->misc_wait, &wait);
34080 while (true) {
34081 set_current_state(TASK_INTERRUPTIBLE);
34082 - data = atomic_xchg(&lis3->count, 0);
34083 + data = atomic_xchg_unchecked(&lis3->count, 0);
34084 if (data)
34085 break;
34086
34087 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34088 struct lis3lv02d, miscdev);
34089
34090 poll_wait(file, &lis3->misc_wait, wait);
34091 - if (atomic_read(&lis3->count))
34092 + if (atomic_read_unchecked(&lis3->count))
34093 return POLLIN | POLLRDNORM;
34094 return 0;
34095 }
34096 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34097 index 2b1482a..5d33616 100644
34098 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34099 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34100 @@ -266,7 +266,7 @@ struct lis3lv02d {
34101 struct input_polled_dev *idev; /* input device */
34102 struct platform_device *pdev; /* platform device */
34103 struct regulator_bulk_data regulators[2];
34104 - atomic_t count; /* interrupt count after last read */
34105 + atomic_unchecked_t count; /* interrupt count after last read */
34106 union axis_conversion ac; /* hw -> logical axis */
34107 int mapped_btns[3];
34108
34109 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34110 index 28adefe..08aad69 100644
34111 --- a/drivers/misc/lkdtm.c
34112 +++ b/drivers/misc/lkdtm.c
34113 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34114 int i, n, out;
34115
34116 buf = (char *)__get_free_page(GFP_KERNEL);
34117 + if (buf == NULL)
34118 + return -ENOMEM;
34119
34120 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34121 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34122 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34123 index 2f30bad..c4c13d0 100644
34124 --- a/drivers/misc/sgi-gru/gruhandles.c
34125 +++ b/drivers/misc/sgi-gru/gruhandles.c
34126 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34127 unsigned long nsec;
34128
34129 nsec = CLKS2NSEC(clks);
34130 - atomic_long_inc(&mcs_op_statistics[op].count);
34131 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34132 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34133 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34134 if (mcs_op_statistics[op].max < nsec)
34135 mcs_op_statistics[op].max = nsec;
34136 }
34137 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34138 index 950dbe9..eeef0f8 100644
34139 --- a/drivers/misc/sgi-gru/gruprocfs.c
34140 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34141 @@ -32,9 +32,9 @@
34142
34143 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34144
34145 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34146 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34147 {
34148 - unsigned long val = atomic_long_read(v);
34149 + unsigned long val = atomic_long_read_unchecked(v);
34150
34151 seq_printf(s, "%16lu %s\n", val, id);
34152 }
34153 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34154
34155 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34156 for (op = 0; op < mcsop_last; op++) {
34157 - count = atomic_long_read(&mcs_op_statistics[op].count);
34158 - total = atomic_long_read(&mcs_op_statistics[op].total);
34159 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34160 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34161 max = mcs_op_statistics[op].max;
34162 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34163 count ? total / count : 0, max);
34164 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34165 index 5c3ce24..4915ccb 100644
34166 --- a/drivers/misc/sgi-gru/grutables.h
34167 +++ b/drivers/misc/sgi-gru/grutables.h
34168 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34169 * GRU statistics.
34170 */
34171 struct gru_stats_s {
34172 - atomic_long_t vdata_alloc;
34173 - atomic_long_t vdata_free;
34174 - atomic_long_t gts_alloc;
34175 - atomic_long_t gts_free;
34176 - atomic_long_t gms_alloc;
34177 - atomic_long_t gms_free;
34178 - atomic_long_t gts_double_allocate;
34179 - atomic_long_t assign_context;
34180 - atomic_long_t assign_context_failed;
34181 - atomic_long_t free_context;
34182 - atomic_long_t load_user_context;
34183 - atomic_long_t load_kernel_context;
34184 - atomic_long_t lock_kernel_context;
34185 - atomic_long_t unlock_kernel_context;
34186 - atomic_long_t steal_user_context;
34187 - atomic_long_t steal_kernel_context;
34188 - atomic_long_t steal_context_failed;
34189 - atomic_long_t nopfn;
34190 - atomic_long_t asid_new;
34191 - atomic_long_t asid_next;
34192 - atomic_long_t asid_wrap;
34193 - atomic_long_t asid_reuse;
34194 - atomic_long_t intr;
34195 - atomic_long_t intr_cbr;
34196 - atomic_long_t intr_tfh;
34197 - atomic_long_t intr_spurious;
34198 - atomic_long_t intr_mm_lock_failed;
34199 - atomic_long_t call_os;
34200 - atomic_long_t call_os_wait_queue;
34201 - atomic_long_t user_flush_tlb;
34202 - atomic_long_t user_unload_context;
34203 - atomic_long_t user_exception;
34204 - atomic_long_t set_context_option;
34205 - atomic_long_t check_context_retarget_intr;
34206 - atomic_long_t check_context_unload;
34207 - atomic_long_t tlb_dropin;
34208 - atomic_long_t tlb_preload_page;
34209 - atomic_long_t tlb_dropin_fail_no_asid;
34210 - atomic_long_t tlb_dropin_fail_upm;
34211 - atomic_long_t tlb_dropin_fail_invalid;
34212 - atomic_long_t tlb_dropin_fail_range_active;
34213 - atomic_long_t tlb_dropin_fail_idle;
34214 - atomic_long_t tlb_dropin_fail_fmm;
34215 - atomic_long_t tlb_dropin_fail_no_exception;
34216 - atomic_long_t tfh_stale_on_fault;
34217 - atomic_long_t mmu_invalidate_range;
34218 - atomic_long_t mmu_invalidate_page;
34219 - atomic_long_t flush_tlb;
34220 - atomic_long_t flush_tlb_gru;
34221 - atomic_long_t flush_tlb_gru_tgh;
34222 - atomic_long_t flush_tlb_gru_zero_asid;
34223 + atomic_long_unchecked_t vdata_alloc;
34224 + atomic_long_unchecked_t vdata_free;
34225 + atomic_long_unchecked_t gts_alloc;
34226 + atomic_long_unchecked_t gts_free;
34227 + atomic_long_unchecked_t gms_alloc;
34228 + atomic_long_unchecked_t gms_free;
34229 + atomic_long_unchecked_t gts_double_allocate;
34230 + atomic_long_unchecked_t assign_context;
34231 + atomic_long_unchecked_t assign_context_failed;
34232 + atomic_long_unchecked_t free_context;
34233 + atomic_long_unchecked_t load_user_context;
34234 + atomic_long_unchecked_t load_kernel_context;
34235 + atomic_long_unchecked_t lock_kernel_context;
34236 + atomic_long_unchecked_t unlock_kernel_context;
34237 + atomic_long_unchecked_t steal_user_context;
34238 + atomic_long_unchecked_t steal_kernel_context;
34239 + atomic_long_unchecked_t steal_context_failed;
34240 + atomic_long_unchecked_t nopfn;
34241 + atomic_long_unchecked_t asid_new;
34242 + atomic_long_unchecked_t asid_next;
34243 + atomic_long_unchecked_t asid_wrap;
34244 + atomic_long_unchecked_t asid_reuse;
34245 + atomic_long_unchecked_t intr;
34246 + atomic_long_unchecked_t intr_cbr;
34247 + atomic_long_unchecked_t intr_tfh;
34248 + atomic_long_unchecked_t intr_spurious;
34249 + atomic_long_unchecked_t intr_mm_lock_failed;
34250 + atomic_long_unchecked_t call_os;
34251 + atomic_long_unchecked_t call_os_wait_queue;
34252 + atomic_long_unchecked_t user_flush_tlb;
34253 + atomic_long_unchecked_t user_unload_context;
34254 + atomic_long_unchecked_t user_exception;
34255 + atomic_long_unchecked_t set_context_option;
34256 + atomic_long_unchecked_t check_context_retarget_intr;
34257 + atomic_long_unchecked_t check_context_unload;
34258 + atomic_long_unchecked_t tlb_dropin;
34259 + atomic_long_unchecked_t tlb_preload_page;
34260 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34261 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34262 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34263 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34264 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34265 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34266 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34267 + atomic_long_unchecked_t tfh_stale_on_fault;
34268 + atomic_long_unchecked_t mmu_invalidate_range;
34269 + atomic_long_unchecked_t mmu_invalidate_page;
34270 + atomic_long_unchecked_t flush_tlb;
34271 + atomic_long_unchecked_t flush_tlb_gru;
34272 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34273 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34274
34275 - atomic_long_t copy_gpa;
34276 - atomic_long_t read_gpa;
34277 + atomic_long_unchecked_t copy_gpa;
34278 + atomic_long_unchecked_t read_gpa;
34279
34280 - atomic_long_t mesq_receive;
34281 - atomic_long_t mesq_receive_none;
34282 - atomic_long_t mesq_send;
34283 - atomic_long_t mesq_send_failed;
34284 - atomic_long_t mesq_noop;
34285 - atomic_long_t mesq_send_unexpected_error;
34286 - atomic_long_t mesq_send_lb_overflow;
34287 - atomic_long_t mesq_send_qlimit_reached;
34288 - atomic_long_t mesq_send_amo_nacked;
34289 - atomic_long_t mesq_send_put_nacked;
34290 - atomic_long_t mesq_page_overflow;
34291 - atomic_long_t mesq_qf_locked;
34292 - atomic_long_t mesq_qf_noop_not_full;
34293 - atomic_long_t mesq_qf_switch_head_failed;
34294 - atomic_long_t mesq_qf_unexpected_error;
34295 - atomic_long_t mesq_noop_unexpected_error;
34296 - atomic_long_t mesq_noop_lb_overflow;
34297 - atomic_long_t mesq_noop_qlimit_reached;
34298 - atomic_long_t mesq_noop_amo_nacked;
34299 - atomic_long_t mesq_noop_put_nacked;
34300 - atomic_long_t mesq_noop_page_overflow;
34301 + atomic_long_unchecked_t mesq_receive;
34302 + atomic_long_unchecked_t mesq_receive_none;
34303 + atomic_long_unchecked_t mesq_send;
34304 + atomic_long_unchecked_t mesq_send_failed;
34305 + atomic_long_unchecked_t mesq_noop;
34306 + atomic_long_unchecked_t mesq_send_unexpected_error;
34307 + atomic_long_unchecked_t mesq_send_lb_overflow;
34308 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34309 + atomic_long_unchecked_t mesq_send_amo_nacked;
34310 + atomic_long_unchecked_t mesq_send_put_nacked;
34311 + atomic_long_unchecked_t mesq_page_overflow;
34312 + atomic_long_unchecked_t mesq_qf_locked;
34313 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34314 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34315 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34316 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34317 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34318 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34319 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34320 + atomic_long_unchecked_t mesq_noop_put_nacked;
34321 + atomic_long_unchecked_t mesq_noop_page_overflow;
34322
34323 };
34324
34325 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34326 tghop_invalidate, mcsop_last};
34327
34328 struct mcs_op_statistic {
34329 - atomic_long_t count;
34330 - atomic_long_t total;
34331 + atomic_long_unchecked_t count;
34332 + atomic_long_unchecked_t total;
34333 unsigned long max;
34334 };
34335
34336 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34337
34338 #define STAT(id) do { \
34339 if (gru_options & OPT_STATS) \
34340 - atomic_long_inc(&gru_stats.id); \
34341 + atomic_long_inc_unchecked(&gru_stats.id); \
34342 } while (0)
34343
34344 #ifdef CONFIG_SGI_GRU_DEBUG
34345 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34346 index c862cd4..0d176fe 100644
34347 --- a/drivers/misc/sgi-xp/xp.h
34348 +++ b/drivers/misc/sgi-xp/xp.h
34349 @@ -288,7 +288,7 @@ struct xpc_interface {
34350 xpc_notify_func, void *);
34351 void (*received) (short, int, void *);
34352 enum xp_retval (*partid_to_nasids) (short, void *);
34353 -};
34354 +} __no_const;
34355
34356 extern struct xpc_interface xpc_interface;
34357
34358 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34359 index b94d5f7..7f494c5 100644
34360 --- a/drivers/misc/sgi-xp/xpc.h
34361 +++ b/drivers/misc/sgi-xp/xpc.h
34362 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34363 void (*received_payload) (struct xpc_channel *, void *);
34364 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34365 };
34366 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34367
34368 /* struct xpc_partition act_state values (for XPC HB) */
34369
34370 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34371 /* found in xpc_main.c */
34372 extern struct device *xpc_part;
34373 extern struct device *xpc_chan;
34374 -extern struct xpc_arch_operations xpc_arch_ops;
34375 +extern xpc_arch_operations_no_const xpc_arch_ops;
34376 extern int xpc_disengage_timelimit;
34377 extern int xpc_disengage_timedout;
34378 extern int xpc_activate_IRQ_rcvd;
34379 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34380 index 8d082b4..aa749ae 100644
34381 --- a/drivers/misc/sgi-xp/xpc_main.c
34382 +++ b/drivers/misc/sgi-xp/xpc_main.c
34383 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34384 .notifier_call = xpc_system_die,
34385 };
34386
34387 -struct xpc_arch_operations xpc_arch_ops;
34388 +xpc_arch_operations_no_const xpc_arch_ops;
34389
34390 /*
34391 * Timer function to enforce the timelimit on the partition disengage.
34392 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34393 index 2b62232..acfaeeb 100644
34394 --- a/drivers/misc/ti-st/st_core.c
34395 +++ b/drivers/misc/ti-st/st_core.c
34396 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34397 st_gdata->rx_skb = alloc_skb(
34398 st_gdata->list[type]->max_frame_size,
34399 GFP_ATOMIC);
34400 + if (st_gdata->rx_skb == NULL) {
34401 + pr_err("out of memory: dropping\n");
34402 + goto done;
34403 + }
34404 +
34405 skb_reserve(st_gdata->rx_skb,
34406 st_gdata->list[type]->reserve);
34407 /* next 2 required for BT only */
34408 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34409 index 69ef0be..f3ef91e 100644
34410 --- a/drivers/mmc/host/sdhci-pci.c
34411 +++ b/drivers/mmc/host/sdhci-pci.c
34412 @@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34413 .probe = via_probe,
34414 };
34415
34416 -static const struct pci_device_id pci_ids[] __devinitdata = {
34417 +static const struct pci_device_id pci_ids[] __devinitconst = {
34418 {
34419 .vendor = PCI_VENDOR_ID_RICOH,
34420 .device = PCI_DEVICE_ID_RICOH_R5C822,
34421 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34422 index a4eb8b5..8c0628f 100644
34423 --- a/drivers/mtd/devices/doc2000.c
34424 +++ b/drivers/mtd/devices/doc2000.c
34425 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34426
34427 /* The ECC will not be calculated correctly if less than 512 is written */
34428 /* DBB-
34429 - if (len != 0x200 && eccbuf)
34430 + if (len != 0x200)
34431 printk(KERN_WARNING
34432 "ECC needs a full sector write (adr: %lx size %lx)\n",
34433 (long) to, (long) len);
34434 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34435 index 0650aaf..7718762 100644
34436 --- a/drivers/mtd/nand/denali.c
34437 +++ b/drivers/mtd/nand/denali.c
34438 @@ -26,6 +26,7 @@
34439 #include <linux/pci.h>
34440 #include <linux/mtd/mtd.h>
34441 #include <linux/module.h>
34442 +#include <linux/slab.h>
34443
34444 #include "denali.h"
34445
34446 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34447 index 51b9d6a..52af9a7 100644
34448 --- a/drivers/mtd/nftlmount.c
34449 +++ b/drivers/mtd/nftlmount.c
34450 @@ -24,6 +24,7 @@
34451 #include <asm/errno.h>
34452 #include <linux/delay.h>
34453 #include <linux/slab.h>
34454 +#include <linux/sched.h>
34455 #include <linux/mtd/mtd.h>
34456 #include <linux/mtd/nand.h>
34457 #include <linux/mtd/nftl.h>
34458 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34459 index 6762dc4..9956862 100644
34460 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34461 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34462 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34463 */
34464
34465 #define ATL2_PARAM(X, desc) \
34466 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34467 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34468 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34469 MODULE_PARM_DESC(X, desc);
34470 #else
34471 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34472 index efd80bd..21fcff0 100644
34473 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34474 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34475 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34476
34477 int (*wait_comp)(struct bnx2x *bp,
34478 struct bnx2x_rx_mode_ramrod_params *p);
34479 -};
34480 +} __no_const;
34481
34482 /********************** Set multicast group ***********************************/
34483
34484 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34485 index 93865f8..5448741 100644
34486 --- a/drivers/net/ethernet/broadcom/tg3.h
34487 +++ b/drivers/net/ethernet/broadcom/tg3.h
34488 @@ -140,6 +140,7 @@
34489 #define CHIPREV_ID_5750_A0 0x4000
34490 #define CHIPREV_ID_5750_A1 0x4001
34491 #define CHIPREV_ID_5750_A3 0x4003
34492 +#define CHIPREV_ID_5750_C1 0x4201
34493 #define CHIPREV_ID_5750_C2 0x4202
34494 #define CHIPREV_ID_5752_A0_HW 0x5000
34495 #define CHIPREV_ID_5752_A0 0x6000
34496 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34497 index c4e8643..0979484 100644
34498 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34499 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34500 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34501 */
34502 struct l2t_skb_cb {
34503 arp_failure_handler_func arp_failure_handler;
34504 -};
34505 +} __no_const;
34506
34507 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34508
34509 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34510 index d3cd489..0fd52dd 100644
34511 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34512 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34513 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34514 for (i=0; i<ETH_ALEN; i++) {
34515 tmp.addr[i] = dev->dev_addr[i];
34516 }
34517 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34518 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34519 break;
34520
34521 case DE4X5_SET_HWADDR: /* Set the hardware address */
34522 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34523 spin_lock_irqsave(&lp->lock, flags);
34524 memcpy(&statbuf, &lp->pktStats, ioc->len);
34525 spin_unlock_irqrestore(&lp->lock, flags);
34526 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34527 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34528 return -EFAULT;
34529 break;
34530 }
34531 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34532 index ed7d1dc..d426748 100644
34533 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34534 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34535 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34536 {NULL}};
34537
34538
34539 -static const char *block_name[] __devinitdata = {
34540 +static const char *block_name[] __devinitconst = {
34541 "21140 non-MII",
34542 "21140 MII PHY",
34543 "21142 Serial PHY",
34544 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34545 index 75d45f8..3d9c55b 100644
34546 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34547 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34548 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34549 struct uli_phy_ops {
34550 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34551 u16 (*read)(struct uli526x_board_info *, u8, u8);
34552 - } phy;
34553 + } __no_const phy;
34554 struct net_device *next_dev; /* next device */
34555 struct pci_dev *pdev; /* PCI device */
34556 spinlock_t lock;
34557 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34558 index 4d1ffca..7c1ec4d 100644
34559 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34560 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34561 @@ -236,7 +236,7 @@ struct pci_id_info {
34562 int drv_flags; /* Driver use, intended as capability flags. */
34563 };
34564
34565 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34566 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34567 { /* Sometime a Level-One switch card. */
34568 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34569 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34570 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34571 index d7bb52a..3b83588 100644
34572 --- a/drivers/net/ethernet/dlink/sundance.c
34573 +++ b/drivers/net/ethernet/dlink/sundance.c
34574 @@ -218,7 +218,7 @@ enum {
34575 struct pci_id_info {
34576 const char *name;
34577 };
34578 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34579 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34580 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34581 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34582 {"D-Link DFE-580TX 4 port Server Adapter"},
34583 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34584 index 501dfa9..aa9ec11 100644
34585 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34586 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34587 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34588
34589 if (wrapped)
34590 newacc += 65536;
34591 - ACCESS_ONCE(*acc) = newacc;
34592 + ACCESS_ONCE_RW(*acc) = newacc;
34593 }
34594
34595 void be_parse_stats(struct be_adapter *adapter)
34596 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34597 index 16b0704..d2c07d7 100644
34598 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34599 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34600 @@ -31,6 +31,8 @@
34601 #include <linux/netdevice.h>
34602 #include <linux/phy.h>
34603 #include <linux/platform_device.h>
34604 +#include <linux/interrupt.h>
34605 +#include <linux/irqreturn.h>
34606 #include <net/ip.h>
34607
34608 #include "ftgmac100.h"
34609 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34610 index 829b109..4ae5f6a 100644
34611 --- a/drivers/net/ethernet/faraday/ftmac100.c
34612 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34613 @@ -31,6 +31,8 @@
34614 #include <linux/module.h>
34615 #include <linux/netdevice.h>
34616 #include <linux/platform_device.h>
34617 +#include <linux/interrupt.h>
34618 +#include <linux/irqreturn.h>
34619
34620 #include "ftmac100.h"
34621
34622 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34623 index 9d71c9c..0e4a0ac 100644
34624 --- a/drivers/net/ethernet/fealnx.c
34625 +++ b/drivers/net/ethernet/fealnx.c
34626 @@ -150,7 +150,7 @@ struct chip_info {
34627 int flags;
34628 };
34629
34630 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34631 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34632 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34633 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34634 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34635 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34636 index 6e6fffb..588f361 100644
34637 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34638 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34639 @@ -181,7 +181,7 @@ struct e1000_info;
34640 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34641 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34642 E1000_TXDCTL_COUNT_DESC | \
34643 - (5 << 16) | /* wthresh must be +1 more than desired */\
34644 + (1 << 16) | /* wthresh must be +1 more than desired */\
34645 (1 << 8) | /* hthresh */ \
34646 0x1f) /* pthresh */
34647
34648 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34649 index ed5b409..ec37828 100644
34650 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34651 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34652 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34653 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34654 s32 (*read_mac_addr)(struct e1000_hw *);
34655 };
34656 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34657
34658 /*
34659 * When to use various PHY register access functions:
34660 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34661 void (*power_up)(struct e1000_hw *);
34662 void (*power_down)(struct e1000_hw *);
34663 };
34664 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34665
34666 /* Function pointers for the NVM. */
34667 struct e1000_nvm_operations {
34668 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34669 s32 (*validate)(struct e1000_hw *);
34670 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34671 };
34672 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34673
34674 struct e1000_mac_info {
34675 - struct e1000_mac_operations ops;
34676 + e1000_mac_operations_no_const ops;
34677 u8 addr[ETH_ALEN];
34678 u8 perm_addr[ETH_ALEN];
34679
34680 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34681 };
34682
34683 struct e1000_phy_info {
34684 - struct e1000_phy_operations ops;
34685 + e1000_phy_operations_no_const ops;
34686
34687 enum e1000_phy_type type;
34688
34689 @@ -926,7 +929,7 @@ struct e1000_phy_info {
34690 };
34691
34692 struct e1000_nvm_info {
34693 - struct e1000_nvm_operations ops;
34694 + e1000_nvm_operations_no_const ops;
34695
34696 enum e1000_nvm_type type;
34697 enum e1000_nvm_override override;
34698 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34699 index c2a51dc..c2bd262 100644
34700 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34701 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34702 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34703 void (*release_swfw_sync)(struct e1000_hw *, u16);
34704
34705 };
34706 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34707
34708 struct e1000_phy_operations {
34709 s32 (*acquire)(struct e1000_hw *);
34710 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34711 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34712 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34713 };
34714 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34715
34716 struct e1000_nvm_operations {
34717 s32 (*acquire)(struct e1000_hw *);
34718 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34719 s32 (*validate)(struct e1000_hw *);
34720 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34721 };
34722 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34723
34724 struct e1000_info {
34725 s32 (*get_invariants)(struct e1000_hw *);
34726 @@ -364,7 +367,7 @@ struct e1000_info {
34727 extern const struct e1000_info e1000_82575_info;
34728
34729 struct e1000_mac_info {
34730 - struct e1000_mac_operations ops;
34731 + e1000_mac_operations_no_const ops;
34732
34733 u8 addr[6];
34734 u8 perm_addr[6];
34735 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34736 };
34737
34738 struct e1000_phy_info {
34739 - struct e1000_phy_operations ops;
34740 + e1000_phy_operations_no_const ops;
34741
34742 enum e1000_phy_type type;
34743
34744 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34745 };
34746
34747 struct e1000_nvm_info {
34748 - struct e1000_nvm_operations ops;
34749 + e1000_nvm_operations_no_const ops;
34750 enum e1000_nvm_type type;
34751 enum e1000_nvm_override override;
34752
34753 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34754 s32 (*check_for_ack)(struct e1000_hw *, u16);
34755 s32 (*check_for_rst)(struct e1000_hw *, u16);
34756 };
34757 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34758
34759 struct e1000_mbx_stats {
34760 u32 msgs_tx;
34761 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34762 };
34763
34764 struct e1000_mbx_info {
34765 - struct e1000_mbx_operations ops;
34766 + e1000_mbx_operations_no_const ops;
34767 struct e1000_mbx_stats stats;
34768 u32 timeout;
34769 u32 usec_delay;
34770 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34771 index 57db3c6..aa825fc 100644
34772 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34773 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34774 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34775 s32 (*read_mac_addr)(struct e1000_hw *);
34776 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34777 };
34778 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34779
34780 struct e1000_mac_info {
34781 - struct e1000_mac_operations ops;
34782 + e1000_mac_operations_no_const ops;
34783 u8 addr[6];
34784 u8 perm_addr[6];
34785
34786 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34787 s32 (*check_for_ack)(struct e1000_hw *);
34788 s32 (*check_for_rst)(struct e1000_hw *);
34789 };
34790 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34791
34792 struct e1000_mbx_stats {
34793 u32 msgs_tx;
34794 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34795 };
34796
34797 struct e1000_mbx_info {
34798 - struct e1000_mbx_operations ops;
34799 + e1000_mbx_operations_no_const ops;
34800 struct e1000_mbx_stats stats;
34801 u32 timeout;
34802 u32 usec_delay;
34803 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34804 index dcebd12..c1fe8be 100644
34805 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34806 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34807 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34808 /* store the new cycle speed */
34809 adapter->cycle_speed = cycle_speed;
34810
34811 - ACCESS_ONCE(adapter->base_incval) = incval;
34812 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34813 smp_mb();
34814
34815 /* grab the ptp lock */
34816 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34817 index 204848d..d8aeaec 100644
34818 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34819 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34820 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34821 s32 (*update_checksum)(struct ixgbe_hw *);
34822 u16 (*calc_checksum)(struct ixgbe_hw *);
34823 };
34824 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34825
34826 struct ixgbe_mac_operations {
34827 s32 (*init_hw)(struct ixgbe_hw *);
34828 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34829 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34830 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34831 };
34832 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34833
34834 struct ixgbe_phy_operations {
34835 s32 (*identify)(struct ixgbe_hw *);
34836 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34837 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34838 s32 (*check_overtemp)(struct ixgbe_hw *);
34839 };
34840 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34841
34842 struct ixgbe_eeprom_info {
34843 - struct ixgbe_eeprom_operations ops;
34844 + ixgbe_eeprom_operations_no_const ops;
34845 enum ixgbe_eeprom_type type;
34846 u32 semaphore_delay;
34847 u16 word_size;
34848 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34849
34850 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34851 struct ixgbe_mac_info {
34852 - struct ixgbe_mac_operations ops;
34853 + ixgbe_mac_operations_no_const ops;
34854 enum ixgbe_mac_type type;
34855 u8 addr[ETH_ALEN];
34856 u8 perm_addr[ETH_ALEN];
34857 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34858 };
34859
34860 struct ixgbe_phy_info {
34861 - struct ixgbe_phy_operations ops;
34862 + ixgbe_phy_operations_no_const ops;
34863 struct mdio_if_info mdio;
34864 enum ixgbe_phy_type type;
34865 u32 id;
34866 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34867 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34868 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34869 };
34870 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34871
34872 struct ixgbe_mbx_stats {
34873 u32 msgs_tx;
34874 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34875 };
34876
34877 struct ixgbe_mbx_info {
34878 - struct ixgbe_mbx_operations ops;
34879 + ixgbe_mbx_operations_no_const ops;
34880 struct ixgbe_mbx_stats stats;
34881 u32 timeout;
34882 u32 usec_delay;
34883 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34884 index 25c951d..cc7cf33 100644
34885 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34886 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34887 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34888 s32 (*clear_vfta)(struct ixgbe_hw *);
34889 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34890 };
34891 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34892
34893 enum ixgbe_mac_type {
34894 ixgbe_mac_unknown = 0,
34895 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34896 };
34897
34898 struct ixgbe_mac_info {
34899 - struct ixgbe_mac_operations ops;
34900 + ixgbe_mac_operations_no_const ops;
34901 u8 addr[6];
34902 u8 perm_addr[6];
34903
34904 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34905 s32 (*check_for_ack)(struct ixgbe_hw *);
34906 s32 (*check_for_rst)(struct ixgbe_hw *);
34907 };
34908 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34909
34910 struct ixgbe_mbx_stats {
34911 u32 msgs_tx;
34912 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34913 };
34914
34915 struct ixgbe_mbx_info {
34916 - struct ixgbe_mbx_operations ops;
34917 + ixgbe_mbx_operations_no_const ops;
34918 struct ixgbe_mbx_stats stats;
34919 u32 timeout;
34920 u32 udelay;
34921 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34922 index a0313de..e83a572 100644
34923 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34924 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34925 @@ -41,6 +41,7 @@
34926 #include <linux/slab.h>
34927 #include <linux/io-mapping.h>
34928 #include <linux/delay.h>
34929 +#include <linux/sched.h>
34930
34931 #include <linux/mlx4/device.h>
34932 #include <linux/mlx4/doorbell.h>
34933 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34934 index 5046a64..71ca936 100644
34935 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34936 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34937 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34938 void (*link_down)(struct __vxge_hw_device *devh);
34939 void (*crit_err)(struct __vxge_hw_device *devh,
34940 enum vxge_hw_event type, u64 ext_data);
34941 -};
34942 +} __no_const;
34943
34944 /*
34945 * struct __vxge_hw_blockpool_entry - Block private data structure
34946 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34947 index 4a518a3..936b334 100644
34948 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34949 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34950 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34951 struct vxge_hw_mempool_dma *dma_object,
34952 u32 index,
34953 u32 is_last);
34954 -};
34955 +} __no_const;
34956
34957 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34958 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34959 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34960 index d7a04e0..76d0431 100644
34961 --- a/drivers/net/ethernet/realtek/r8169.c
34962 +++ b/drivers/net/ethernet/realtek/r8169.c
34963 @@ -723,22 +723,22 @@ struct rtl8169_private {
34964 struct mdio_ops {
34965 void (*write)(void __iomem *, int, int);
34966 int (*read)(void __iomem *, int);
34967 - } mdio_ops;
34968 + } __no_const mdio_ops;
34969
34970 struct pll_power_ops {
34971 void (*down)(struct rtl8169_private *);
34972 void (*up)(struct rtl8169_private *);
34973 - } pll_power_ops;
34974 + } __no_const pll_power_ops;
34975
34976 struct jumbo_ops {
34977 void (*enable)(struct rtl8169_private *);
34978 void (*disable)(struct rtl8169_private *);
34979 - } jumbo_ops;
34980 + } __no_const jumbo_ops;
34981
34982 struct csi_ops {
34983 void (*write)(void __iomem *, int, int);
34984 u32 (*read)(void __iomem *, int);
34985 - } csi_ops;
34986 + } __no_const csi_ops;
34987
34988 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34989 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34990 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34991 index 4613591..d816601 100644
34992 --- a/drivers/net/ethernet/sis/sis190.c
34993 +++ b/drivers/net/ethernet/sis/sis190.c
34994 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34995 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34996 struct net_device *dev)
34997 {
34998 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34999 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35000 struct sis190_private *tp = netdev_priv(dev);
35001 struct pci_dev *isa_bridge;
35002 u8 reg, tmp8;
35003 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35004 index c07cfe9..81cbf7e 100644
35005 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35006 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35007 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35008
35009 writel(value, ioaddr + MMC_CNTRL);
35010
35011 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35012 - MMC_CNTRL, value);
35013 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35014 +// MMC_CNTRL, value);
35015 }
35016
35017 /* To mask all all interrupts.*/
35018 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35019 index 2857ab0..9a1f9b0 100644
35020 --- a/drivers/net/hyperv/hyperv_net.h
35021 +++ b/drivers/net/hyperv/hyperv_net.h
35022 @@ -99,7 +99,7 @@ struct rndis_device {
35023
35024 enum rndis_device_state state;
35025 bool link_state;
35026 - atomic_t new_req_id;
35027 + atomic_unchecked_t new_req_id;
35028
35029 spinlock_t request_lock;
35030 struct list_head req_list;
35031 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35032 index 981ebb1..b34959b 100644
35033 --- a/drivers/net/hyperv/rndis_filter.c
35034 +++ b/drivers/net/hyperv/rndis_filter.c
35035 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35036 * template
35037 */
35038 set = &rndis_msg->msg.set_req;
35039 - set->req_id = atomic_inc_return(&dev->new_req_id);
35040 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35041
35042 /* Add to the request list */
35043 spin_lock_irqsave(&dev->request_lock, flags);
35044 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35045
35046 /* Setup the rndis set */
35047 halt = &request->request_msg.msg.halt_req;
35048 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35049 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35050
35051 /* Ignore return since this msg is optional. */
35052 rndis_filter_send_request(dev, request);
35053 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35054 index 5c05572..389610b 100644
35055 --- a/drivers/net/ppp/ppp_generic.c
35056 +++ b/drivers/net/ppp/ppp_generic.c
35057 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35058 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35059 struct ppp_stats stats;
35060 struct ppp_comp_stats cstats;
35061 - char *vers;
35062
35063 switch (cmd) {
35064 case SIOCGPPPSTATS:
35065 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35066 break;
35067
35068 case SIOCGPPPVER:
35069 - vers = PPP_VERSION;
35070 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35071 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35072 break;
35073 err = 0;
35074 break;
35075 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35076 index 62f30b4..ff99dfd 100644
35077 --- a/drivers/net/usb/hso.c
35078 +++ b/drivers/net/usb/hso.c
35079 @@ -71,7 +71,7 @@
35080 #include <asm/byteorder.h>
35081 #include <linux/serial_core.h>
35082 #include <linux/serial.h>
35083 -
35084 +#include <asm/local.h>
35085
35086 #define MOD_AUTHOR "Option Wireless"
35087 #define MOD_DESCRIPTION "USB High Speed Option driver"
35088 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35089 struct urb *urb;
35090
35091 urb = serial->rx_urb[0];
35092 - if (serial->port.count > 0) {
35093 + if (atomic_read(&serial->port.count) > 0) {
35094 count = put_rxbuf_data(urb, serial);
35095 if (count == -1)
35096 return;
35097 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35098 DUMP1(urb->transfer_buffer, urb->actual_length);
35099
35100 /* Anyone listening? */
35101 - if (serial->port.count == 0)
35102 + if (atomic_read(&serial->port.count) == 0)
35103 return;
35104
35105 if (status == 0) {
35106 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35107 tty_port_tty_set(&serial->port, tty);
35108
35109 /* check for port already opened, if not set the termios */
35110 - serial->port.count++;
35111 - if (serial->port.count == 1) {
35112 + if (atomic_inc_return(&serial->port.count) == 1) {
35113 serial->rx_state = RX_IDLE;
35114 /* Force default termio settings */
35115 _hso_serial_set_termios(tty, NULL);
35116 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35117 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35118 if (result) {
35119 hso_stop_serial_device(serial->parent);
35120 - serial->port.count--;
35121 + atomic_dec(&serial->port.count);
35122 kref_put(&serial->parent->ref, hso_serial_ref_free);
35123 }
35124 } else {
35125 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35126
35127 /* reset the rts and dtr */
35128 /* do the actual close */
35129 - serial->port.count--;
35130 + atomic_dec(&serial->port.count);
35131
35132 - if (serial->port.count <= 0) {
35133 - serial->port.count = 0;
35134 + if (atomic_read(&serial->port.count) <= 0) {
35135 + atomic_set(&serial->port.count, 0);
35136 tty_port_tty_set(&serial->port, NULL);
35137 if (!usb_gone)
35138 hso_stop_serial_device(serial->parent);
35139 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35140
35141 /* the actual setup */
35142 spin_lock_irqsave(&serial->serial_lock, flags);
35143 - if (serial->port.count)
35144 + if (atomic_read(&serial->port.count))
35145 _hso_serial_set_termios(tty, old);
35146 else
35147 tty->termios = old;
35148 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35149 D1("Pending read interrupt on port %d\n", i);
35150 spin_lock(&serial->serial_lock);
35151 if (serial->rx_state == RX_IDLE &&
35152 - serial->port.count > 0) {
35153 + atomic_read(&serial->port.count) > 0) {
35154 /* Setup and send a ctrl req read on
35155 * port i */
35156 if (!serial->rx_urb_filled[0]) {
35157 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35158 /* Start all serial ports */
35159 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35160 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35161 - if (dev2ser(serial_table[i])->port.count) {
35162 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35163 result =
35164 hso_start_serial_device(serial_table[i], GFP_NOIO);
35165 hso_kick_transmit(dev2ser(serial_table[i]));
35166 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35167 index 420d69b..74f90a2 100644
35168 --- a/drivers/net/wireless/ath/ath.h
35169 +++ b/drivers/net/wireless/ath/ath.h
35170 @@ -119,6 +119,7 @@ struct ath_ops {
35171 void (*write_flush) (void *);
35172 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35173 };
35174 +typedef struct ath_ops __no_const ath_ops_no_const;
35175
35176 struct ath_common;
35177 struct ath_bus_ops;
35178 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35179 index 8d78253..bebbb68 100644
35180 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35181 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35182 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35183 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35184 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35185
35186 - ACCESS_ONCE(ads->ds_link) = i->link;
35187 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35188 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35189 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35190
35191 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35192 ctl6 = SM(i->keytype, AR_EncrType);
35193 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35194
35195 if ((i->is_first || i->is_last) &&
35196 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35197 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35198 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35199 | set11nTries(i->rates, 1)
35200 | set11nTries(i->rates, 2)
35201 | set11nTries(i->rates, 3)
35202 | (i->dur_update ? AR_DurUpdateEna : 0)
35203 | SM(0, AR_BurstDur);
35204
35205 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35206 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35207 | set11nRate(i->rates, 1)
35208 | set11nRate(i->rates, 2)
35209 | set11nRate(i->rates, 3);
35210 } else {
35211 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35212 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35213 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35214 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35215 }
35216
35217 if (!i->is_first) {
35218 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35219 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35220 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35221 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35222 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35223 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35224 return;
35225 }
35226
35227 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35228 break;
35229 }
35230
35231 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35232 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35233 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35234 | SM(i->txpower, AR_XmitPower)
35235 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35236 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35237 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35238 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35239
35240 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35241 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35242 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35243 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35244
35245 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35246 return;
35247
35248 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35249 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35250 | set11nPktDurRTSCTS(i->rates, 1);
35251
35252 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35253 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35254 | set11nPktDurRTSCTS(i->rates, 3);
35255
35256 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35257 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35258 | set11nRateFlags(i->rates, 1)
35259 | set11nRateFlags(i->rates, 2)
35260 | set11nRateFlags(i->rates, 3)
35261 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35262 index d9e0824..1a874e7 100644
35263 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35264 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35265 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35266 (i->qcu << AR_TxQcuNum_S) | desc_len;
35267
35268 checksum += val;
35269 - ACCESS_ONCE(ads->info) = val;
35270 + ACCESS_ONCE_RW(ads->info) = val;
35271
35272 checksum += i->link;
35273 - ACCESS_ONCE(ads->link) = i->link;
35274 + ACCESS_ONCE_RW(ads->link) = i->link;
35275
35276 checksum += i->buf_addr[0];
35277 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35278 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35279 checksum += i->buf_addr[1];
35280 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35281 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35282 checksum += i->buf_addr[2];
35283 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35284 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35285 checksum += i->buf_addr[3];
35286 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35287 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35288
35289 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35290 - ACCESS_ONCE(ads->ctl3) = val;
35291 + ACCESS_ONCE_RW(ads->ctl3) = val;
35292 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35293 - ACCESS_ONCE(ads->ctl5) = val;
35294 + ACCESS_ONCE_RW(ads->ctl5) = val;
35295 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35296 - ACCESS_ONCE(ads->ctl7) = val;
35297 + ACCESS_ONCE_RW(ads->ctl7) = val;
35298 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35299 - ACCESS_ONCE(ads->ctl9) = val;
35300 + ACCESS_ONCE_RW(ads->ctl9) = val;
35301
35302 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35303 - ACCESS_ONCE(ads->ctl10) = checksum;
35304 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35305
35306 if (i->is_first || i->is_last) {
35307 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35308 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35309 | set11nTries(i->rates, 1)
35310 | set11nTries(i->rates, 2)
35311 | set11nTries(i->rates, 3)
35312 | (i->dur_update ? AR_DurUpdateEna : 0)
35313 | SM(0, AR_BurstDur);
35314
35315 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35316 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35317 | set11nRate(i->rates, 1)
35318 | set11nRate(i->rates, 2)
35319 | set11nRate(i->rates, 3);
35320 } else {
35321 - ACCESS_ONCE(ads->ctl13) = 0;
35322 - ACCESS_ONCE(ads->ctl14) = 0;
35323 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35324 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35325 }
35326
35327 ads->ctl20 = 0;
35328 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35329
35330 ctl17 = SM(i->keytype, AR_EncrType);
35331 if (!i->is_first) {
35332 - ACCESS_ONCE(ads->ctl11) = 0;
35333 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35334 - ACCESS_ONCE(ads->ctl15) = 0;
35335 - ACCESS_ONCE(ads->ctl16) = 0;
35336 - ACCESS_ONCE(ads->ctl17) = ctl17;
35337 - ACCESS_ONCE(ads->ctl18) = 0;
35338 - ACCESS_ONCE(ads->ctl19) = 0;
35339 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35340 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35341 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35342 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35343 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35344 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35345 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35346 return;
35347 }
35348
35349 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35350 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35351 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35352 | SM(i->txpower, AR_XmitPower)
35353 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35354 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35355 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35356 ctl12 |= SM(val, AR_PAPRDChainMask);
35357
35358 - ACCESS_ONCE(ads->ctl12) = ctl12;
35359 - ACCESS_ONCE(ads->ctl17) = ctl17;
35360 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35361 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35362
35363 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35364 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35365 | set11nPktDurRTSCTS(i->rates, 1);
35366
35367 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35368 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35369 | set11nPktDurRTSCTS(i->rates, 3);
35370
35371 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35372 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35373 | set11nRateFlags(i->rates, 1)
35374 | set11nRateFlags(i->rates, 2)
35375 | set11nRateFlags(i->rates, 3)
35376 | SM(i->rtscts_rate, AR_RTSCTSRate);
35377
35378 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35379 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35380 }
35381
35382 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35383 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35384 index b620c55..a76cd49 100644
35385 --- a/drivers/net/wireless/ath/ath9k/hw.h
35386 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35387 @@ -609,7 +609,7 @@ struct ath_hw_private_ops {
35388
35389 /* ANI */
35390 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35391 -};
35392 +} __no_const;
35393
35394 /**
35395 * struct ath_hw_ops - callbacks used by hardware code and driver code
35396 @@ -639,7 +639,7 @@ struct ath_hw_ops {
35397 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35398 struct ath_hw_antcomb_conf *antconf);
35399
35400 -};
35401 +} __no_const;
35402
35403 struct ath_nf_limits {
35404 s16 max;
35405 @@ -659,7 +659,7 @@ enum ath_cal_list {
35406 #define AH_FASTCC 0x4
35407
35408 struct ath_hw {
35409 - struct ath_ops reg_ops;
35410 + ath_ops_no_const reg_ops;
35411
35412 struct ieee80211_hw *hw;
35413 struct ath_common common;
35414 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35415 index af00e2c..ab04d34 100644
35416 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35417 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35418 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35419 void (*carrsuppr)(struct brcms_phy *);
35420 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35421 void (*detach)(struct brcms_phy *);
35422 -};
35423 +} __no_const;
35424
35425 struct brcms_phy {
35426 struct brcms_phy_pub pubpi_ro;
35427 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35428 index faec404..a5277f1 100644
35429 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35430 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35431 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35432 */
35433 if (il3945_mod_params.disable_hw_scan) {
35434 D_INFO("Disabling hw_scan\n");
35435 - il3945_mac_ops.hw_scan = NULL;
35436 + pax_open_kernel();
35437 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35438 + pax_close_kernel();
35439 }
35440
35441 D_INFO("*** LOAD DRIVER ***\n");
35442 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35443 index a0b7cfd..20b49f7 100644
35444 --- a/drivers/net/wireless/mac80211_hwsim.c
35445 +++ b/drivers/net/wireless/mac80211_hwsim.c
35446 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35447 return -EINVAL;
35448
35449 if (fake_hw_scan) {
35450 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35451 - mac80211_hwsim_ops.sw_scan_start = NULL;
35452 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35453 + pax_open_kernel();
35454 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35455 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35456 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35457 + pax_close_kernel();
35458 }
35459
35460 spin_lock_init(&hwsim_radio_lock);
35461 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35462 index bd3b0bf..f9db92a 100644
35463 --- a/drivers/net/wireless/mwifiex/main.h
35464 +++ b/drivers/net/wireless/mwifiex/main.h
35465 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35466 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35467 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35468 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35469 -};
35470 +} __no_const;
35471
35472 struct mwifiex_adapter {
35473 u8 iface_type;
35474 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35475 index dfcd02a..a42a59d 100644
35476 --- a/drivers/net/wireless/rndis_wlan.c
35477 +++ b/drivers/net/wireless/rndis_wlan.c
35478 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35479
35480 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35481
35482 - if (rts_threshold < 0 || rts_threshold > 2347)
35483 + if (rts_threshold > 2347)
35484 rts_threshold = 2347;
35485
35486 tmp = cpu_to_le32(rts_threshold);
35487 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35488 index 8f75402..eed109d 100644
35489 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35490 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35491 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35492 * for hardware which doesn't support hardware
35493 * sequence counting.
35494 */
35495 - atomic_t seqno;
35496 + atomic_unchecked_t seqno;
35497 };
35498
35499 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35500 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35501 index 2fd8301..9767e8c 100644
35502 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35503 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35504 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35505 * sequence counter given by mac80211.
35506 */
35507 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35508 - seqno = atomic_add_return(0x10, &intf->seqno);
35509 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35510 else
35511 - seqno = atomic_read(&intf->seqno);
35512 + seqno = atomic_read_unchecked(&intf->seqno);
35513
35514 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35515 hdr->seq_ctrl |= cpu_to_le16(seqno);
35516 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35517 index 9d8f581..0f6589e 100644
35518 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35519 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35520 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35521 void (*reset)(struct wl1251 *wl);
35522 void (*enable_irq)(struct wl1251 *wl);
35523 void (*disable_irq)(struct wl1251 *wl);
35524 -};
35525 +} __no_const;
35526
35527 struct wl1251 {
35528 struct ieee80211_hw *hw;
35529 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35530 index 0b3f0b5..62f68bd 100644
35531 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35532 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35533 @@ -61,7 +61,7 @@ struct wlcore_ops {
35534 struct wl12xx_vif *wlvif);
35535 s8 (*get_pg_ver)(struct wl1271 *wl);
35536 void (*get_mac)(struct wl1271 *wl);
35537 -};
35538 +} __no_const;
35539
35540 enum wlcore_partitions {
35541 PART_DOWN,
35542 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35543 index f34b5b2..b5abb9f 100644
35544 --- a/drivers/oprofile/buffer_sync.c
35545 +++ b/drivers/oprofile/buffer_sync.c
35546 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35547 if (cookie == NO_COOKIE)
35548 offset = pc;
35549 if (cookie == INVALID_COOKIE) {
35550 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35551 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35552 offset = pc;
35553 }
35554 if (cookie != last_cookie) {
35555 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35556 /* add userspace sample */
35557
35558 if (!mm) {
35559 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35560 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35561 return 0;
35562 }
35563
35564 cookie = lookup_dcookie(mm, s->eip, &offset);
35565
35566 if (cookie == INVALID_COOKIE) {
35567 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35568 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35569 return 0;
35570 }
35571
35572 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35573 /* ignore backtraces if failed to add a sample */
35574 if (state == sb_bt_start) {
35575 state = sb_bt_ignore;
35576 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35577 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35578 }
35579 }
35580 release_mm(mm);
35581 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35582 index c0cc4e7..44d4e54 100644
35583 --- a/drivers/oprofile/event_buffer.c
35584 +++ b/drivers/oprofile/event_buffer.c
35585 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35586 }
35587
35588 if (buffer_pos == buffer_size) {
35589 - atomic_inc(&oprofile_stats.event_lost_overflow);
35590 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35591 return;
35592 }
35593
35594 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35595 index ed2c3ec..deda85a 100644
35596 --- a/drivers/oprofile/oprof.c
35597 +++ b/drivers/oprofile/oprof.c
35598 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35599 if (oprofile_ops.switch_events())
35600 return;
35601
35602 - atomic_inc(&oprofile_stats.multiplex_counter);
35603 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35604 start_switch_worker();
35605 }
35606
35607 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35608 index 917d28e..d62d981 100644
35609 --- a/drivers/oprofile/oprofile_stats.c
35610 +++ b/drivers/oprofile/oprofile_stats.c
35611 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35612 cpu_buf->sample_invalid_eip = 0;
35613 }
35614
35615 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35616 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35617 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35618 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35619 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35620 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35621 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35622 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35623 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35624 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35625 }
35626
35627
35628 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35629 index 38b6fc0..b5cbfce 100644
35630 --- a/drivers/oprofile/oprofile_stats.h
35631 +++ b/drivers/oprofile/oprofile_stats.h
35632 @@ -13,11 +13,11 @@
35633 #include <linux/atomic.h>
35634
35635 struct oprofile_stat_struct {
35636 - atomic_t sample_lost_no_mm;
35637 - atomic_t sample_lost_no_mapping;
35638 - atomic_t bt_lost_no_mapping;
35639 - atomic_t event_lost_overflow;
35640 - atomic_t multiplex_counter;
35641 + atomic_unchecked_t sample_lost_no_mm;
35642 + atomic_unchecked_t sample_lost_no_mapping;
35643 + atomic_unchecked_t bt_lost_no_mapping;
35644 + atomic_unchecked_t event_lost_overflow;
35645 + atomic_unchecked_t multiplex_counter;
35646 };
35647
35648 extern struct oprofile_stat_struct oprofile_stats;
35649 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35650 index 849357c..b83c1e0 100644
35651 --- a/drivers/oprofile/oprofilefs.c
35652 +++ b/drivers/oprofile/oprofilefs.c
35653 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35654
35655
35656 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35657 - char const *name, atomic_t *val)
35658 + char const *name, atomic_unchecked_t *val)
35659 {
35660 return __oprofilefs_create_file(sb, root, name,
35661 &atomic_ro_fops, 0444, val);
35662 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35663 index 3f56bc0..707d642 100644
35664 --- a/drivers/parport/procfs.c
35665 +++ b/drivers/parport/procfs.c
35666 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35667
35668 *ppos += len;
35669
35670 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35671 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35672 }
35673
35674 #ifdef CONFIG_PARPORT_1284
35675 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35676
35677 *ppos += len;
35678
35679 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35680 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35681 }
35682 #endif /* IEEE1284.3 support. */
35683
35684 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35685 index 9fff878..ad0ad53 100644
35686 --- a/drivers/pci/hotplug/cpci_hotplug.h
35687 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35688 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35689 int (*hardware_test) (struct slot* slot, u32 value);
35690 u8 (*get_power) (struct slot* slot);
35691 int (*set_power) (struct slot* slot, int value);
35692 -};
35693 +} __no_const;
35694
35695 struct cpci_hp_controller {
35696 unsigned int irq;
35697 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35698 index 76ba8a1..20ca857 100644
35699 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35700 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35701 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35702
35703 void compaq_nvram_init (void __iomem *rom_start)
35704 {
35705 +
35706 +#ifndef CONFIG_PAX_KERNEXEC
35707 if (rom_start) {
35708 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35709 }
35710 +#endif
35711 +
35712 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35713
35714 /* initialize our int15 lock */
35715 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35716 index b500840..d7159d3 100644
35717 --- a/drivers/pci/pcie/aspm.c
35718 +++ b/drivers/pci/pcie/aspm.c
35719 @@ -27,9 +27,9 @@
35720 #define MODULE_PARAM_PREFIX "pcie_aspm."
35721
35722 /* Note: those are not register definitions */
35723 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35724 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35725 -#define ASPM_STATE_L1 (4) /* L1 state */
35726 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35727 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35728 +#define ASPM_STATE_L1 (4U) /* L1 state */
35729 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35730 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35731
35732 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35733 index 658ac97..05e1b90 100644
35734 --- a/drivers/pci/probe.c
35735 +++ b/drivers/pci/probe.c
35736 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35737 u16 orig_cmd;
35738 struct pci_bus_region region;
35739
35740 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35741 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35742
35743 if (!dev->mmio_always_on) {
35744 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35745 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35746 index 27911b5..5b6db88 100644
35747 --- a/drivers/pci/proc.c
35748 +++ b/drivers/pci/proc.c
35749 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35750 static int __init pci_proc_init(void)
35751 {
35752 struct pci_dev *dev = NULL;
35753 +
35754 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35755 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35756 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35757 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35758 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35759 +#endif
35760 +#else
35761 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35762 +#endif
35763 proc_create("devices", 0, proc_bus_pci_dir,
35764 &proc_bus_pci_dev_operations);
35765 proc_initialized = 1;
35766 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35767 index 8b5610d..a4c22bb 100644
35768 --- a/drivers/platform/x86/thinkpad_acpi.c
35769 +++ b/drivers/platform/x86/thinkpad_acpi.c
35770 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35771 return 0;
35772 }
35773
35774 -void static hotkey_mask_warn_incomplete_mask(void)
35775 +static void hotkey_mask_warn_incomplete_mask(void)
35776 {
35777 /* log only what the user can fix... */
35778 const u32 wantedmask = hotkey_driver_mask &
35779 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35780 }
35781 }
35782
35783 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35784 - struct tp_nvram_state *newn,
35785 - const u32 event_mask)
35786 -{
35787 -
35788 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35789 do { \
35790 if ((event_mask & (1 << __scancode)) && \
35791 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35792 tpacpi_hotkey_send_key(__scancode); \
35793 } while (0)
35794
35795 - void issue_volchange(const unsigned int oldvol,
35796 - const unsigned int newvol)
35797 - {
35798 - unsigned int i = oldvol;
35799 +static void issue_volchange(const unsigned int oldvol,
35800 + const unsigned int newvol,
35801 + const u32 event_mask)
35802 +{
35803 + unsigned int i = oldvol;
35804
35805 - while (i > newvol) {
35806 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35807 - i--;
35808 - }
35809 - while (i < newvol) {
35810 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35811 - i++;
35812 - }
35813 + while (i > newvol) {
35814 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35815 + i--;
35816 }
35817 + while (i < newvol) {
35818 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35819 + i++;
35820 + }
35821 +}
35822
35823 - void issue_brightnesschange(const unsigned int oldbrt,
35824 - const unsigned int newbrt)
35825 - {
35826 - unsigned int i = oldbrt;
35827 +static void issue_brightnesschange(const unsigned int oldbrt,
35828 + const unsigned int newbrt,
35829 + const u32 event_mask)
35830 +{
35831 + unsigned int i = oldbrt;
35832
35833 - while (i > newbrt) {
35834 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35835 - i--;
35836 - }
35837 - while (i < newbrt) {
35838 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35839 - i++;
35840 - }
35841 + while (i > newbrt) {
35842 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35843 + i--;
35844 + }
35845 + while (i < newbrt) {
35846 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35847 + i++;
35848 }
35849 +}
35850
35851 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35852 + struct tp_nvram_state *newn,
35853 + const u32 event_mask)
35854 +{
35855 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35856 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35857 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35858 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35859 oldn->volume_level != newn->volume_level) {
35860 /* recently muted, or repeated mute keypress, or
35861 * multiple presses ending in mute */
35862 - issue_volchange(oldn->volume_level, newn->volume_level);
35863 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35864 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35865 }
35866 } else {
35867 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35868 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35869 }
35870 if (oldn->volume_level != newn->volume_level) {
35871 - issue_volchange(oldn->volume_level, newn->volume_level);
35872 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35873 } else if (oldn->volume_toggle != newn->volume_toggle) {
35874 /* repeated vol up/down keypress at end of scale ? */
35875 if (newn->volume_level == 0)
35876 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35877 /* handle brightness */
35878 if (oldn->brightness_level != newn->brightness_level) {
35879 issue_brightnesschange(oldn->brightness_level,
35880 - newn->brightness_level);
35881 + newn->brightness_level,
35882 + event_mask);
35883 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35884 /* repeated key presses that didn't change state */
35885 if (newn->brightness_level == 0)
35886 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35887 && !tp_features.bright_unkfw)
35888 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35889 }
35890 +}
35891
35892 #undef TPACPI_COMPARE_KEY
35893 #undef TPACPI_MAY_SEND_KEY
35894 -}
35895
35896 /*
35897 * Polling driver
35898 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35899 index 769d265..a3a05ca 100644
35900 --- a/drivers/pnp/pnpbios/bioscalls.c
35901 +++ b/drivers/pnp/pnpbios/bioscalls.c
35902 @@ -58,7 +58,7 @@ do { \
35903 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35904 } while(0)
35905
35906 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35907 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35908 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35909
35910 /*
35911 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35912
35913 cpu = get_cpu();
35914 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35915 +
35916 + pax_open_kernel();
35917 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35918 + pax_close_kernel();
35919
35920 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35921 spin_lock_irqsave(&pnp_bios_lock, flags);
35922 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35923 :"memory");
35924 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35925
35926 + pax_open_kernel();
35927 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35928 + pax_close_kernel();
35929 +
35930 put_cpu();
35931
35932 /* If we get here and this is set then the PnP BIOS faulted on us. */
35933 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35934 return status;
35935 }
35936
35937 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35938 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35939 {
35940 int i;
35941
35942 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35943 pnp_bios_callpoint.offset = header->fields.pm16offset;
35944 pnp_bios_callpoint.segment = PNP_CS16;
35945
35946 + pax_open_kernel();
35947 +
35948 for_each_possible_cpu(i) {
35949 struct desc_struct *gdt = get_cpu_gdt_table(i);
35950 if (!gdt)
35951 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35952 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35953 (unsigned long)__va(header->fields.pm16dseg));
35954 }
35955 +
35956 + pax_close_kernel();
35957 }
35958 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35959 index b0ecacb..7c9da2e 100644
35960 --- a/drivers/pnp/resource.c
35961 +++ b/drivers/pnp/resource.c
35962 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35963 return 1;
35964
35965 /* check if the resource is valid */
35966 - if (*irq < 0 || *irq > 15)
35967 + if (*irq > 15)
35968 return 0;
35969
35970 /* check if the resource is reserved */
35971 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35972 return 1;
35973
35974 /* check if the resource is valid */
35975 - if (*dma < 0 || *dma == 4 || *dma > 7)
35976 + if (*dma == 4 || *dma > 7)
35977 return 0;
35978
35979 /* check if the resource is reserved */
35980 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35981 index f5d6d37..739f6a9 100644
35982 --- a/drivers/power/bq27x00_battery.c
35983 +++ b/drivers/power/bq27x00_battery.c
35984 @@ -72,7 +72,7 @@
35985 struct bq27x00_device_info;
35986 struct bq27x00_access_methods {
35987 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35988 -};
35989 +} __no_const;
35990
35991 enum bq27x00_chip { BQ27000, BQ27500 };
35992
35993 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35994 index 8d53174..04c65de 100644
35995 --- a/drivers/regulator/max8660.c
35996 +++ b/drivers/regulator/max8660.c
35997 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35998 max8660->shadow_regs[MAX8660_OVER1] = 5;
35999 } else {
36000 /* Otherwise devices can be toggled via software */
36001 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36002 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36003 + pax_open_kernel();
36004 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36005 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36006 + pax_close_kernel();
36007 }
36008
36009 /*
36010 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36011 index 970a233..ee1f241 100644
36012 --- a/drivers/regulator/mc13892-regulator.c
36013 +++ b/drivers/regulator/mc13892-regulator.c
36014 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36015 }
36016 mc13xxx_unlock(mc13892);
36017
36018 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36019 + pax_open_kernel();
36020 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36021 = mc13892_vcam_set_mode;
36022 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36023 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36024 = mc13892_vcam_get_mode;
36025 + pax_close_kernel();
36026
36027 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36028 ARRAY_SIZE(mc13892_regulators));
36029 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36030 index cace6d3..f623fda 100644
36031 --- a/drivers/rtc/rtc-dev.c
36032 +++ b/drivers/rtc/rtc-dev.c
36033 @@ -14,6 +14,7 @@
36034 #include <linux/module.h>
36035 #include <linux/rtc.h>
36036 #include <linux/sched.h>
36037 +#include <linux/grsecurity.h>
36038 #include "rtc-core.h"
36039
36040 static dev_t rtc_devt;
36041 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36042 if (copy_from_user(&tm, uarg, sizeof(tm)))
36043 return -EFAULT;
36044
36045 + gr_log_timechange();
36046 +
36047 return rtc_set_time(rtc, &tm);
36048
36049 case RTC_PIE_ON:
36050 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36051 index 3fcf627..f334910 100644
36052 --- a/drivers/scsi/aacraid/aacraid.h
36053 +++ b/drivers/scsi/aacraid/aacraid.h
36054 @@ -492,7 +492,7 @@ struct adapter_ops
36055 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36056 /* Administrative operations */
36057 int (*adapter_comm)(struct aac_dev * dev, int comm);
36058 -};
36059 +} __no_const;
36060
36061 /*
36062 * Define which interrupt handler needs to be installed
36063 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36064 index 0d279c44..3d25a97 100644
36065 --- a/drivers/scsi/aacraid/linit.c
36066 +++ b/drivers/scsi/aacraid/linit.c
36067 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36068 #elif defined(__devinitconst)
36069 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36070 #else
36071 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36072 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36073 #endif
36074 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36075 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36076 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36077 index ff80552..1c4120c 100644
36078 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36079 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36080 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36081 .lldd_ata_set_dmamode = asd_set_dmamode,
36082 };
36083
36084 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36085 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36086 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36087 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36088 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36089 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36090 index 4ad7e36..d004679 100644
36091 --- a/drivers/scsi/bfa/bfa.h
36092 +++ b/drivers/scsi/bfa/bfa.h
36093 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36094 u32 *end);
36095 int cpe_vec_q0;
36096 int rme_vec_q0;
36097 -};
36098 +} __no_const;
36099 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36100
36101 struct bfa_faa_cbfn_s {
36102 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36103 index f0f80e2..8ec946b 100644
36104 --- a/drivers/scsi/bfa/bfa_fcpim.c
36105 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36106 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36107
36108 bfa_iotag_attach(fcp);
36109
36110 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36111 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36112 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36113 (fcp->num_itns * sizeof(struct bfa_itn_s));
36114 memset(fcp->itn_arr, 0,
36115 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36116 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36117 {
36118 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36119 - struct bfa_itn_s *itn;
36120 + bfa_itn_s_no_const *itn;
36121
36122 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36123 itn->isr = isr;
36124 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36125 index 36f26da..38a34a8 100644
36126 --- a/drivers/scsi/bfa/bfa_fcpim.h
36127 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36128 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36129 struct bfa_itn_s {
36130 bfa_isr_func_t isr;
36131 };
36132 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36133
36134 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36135 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36136 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36137 struct list_head iotag_tio_free_q; /* free IO resources */
36138 struct list_head iotag_unused_q; /* unused IO resources*/
36139 struct bfa_iotag_s *iotag_arr;
36140 - struct bfa_itn_s *itn_arr;
36141 + bfa_itn_s_no_const *itn_arr;
36142 int num_ioim_reqs;
36143 int num_fwtio_reqs;
36144 int num_itns;
36145 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36146 index 1a99d4b..e85d64b 100644
36147 --- a/drivers/scsi/bfa/bfa_ioc.h
36148 +++ b/drivers/scsi/bfa/bfa_ioc.h
36149 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36150 bfa_ioc_disable_cbfn_t disable_cbfn;
36151 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36152 bfa_ioc_reset_cbfn_t reset_cbfn;
36153 -};
36154 +} __no_const;
36155
36156 /*
36157 * IOC event notification mechanism.
36158 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36159 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36160 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36161 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36162 -};
36163 +} __no_const;
36164
36165 /*
36166 * Queue element to wait for room in request queue. FIFO order is
36167 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36168 index a3a056a..b9bbc2f 100644
36169 --- a/drivers/scsi/hosts.c
36170 +++ b/drivers/scsi/hosts.c
36171 @@ -42,7 +42,7 @@
36172 #include "scsi_logging.h"
36173
36174
36175 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36176 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36177
36178
36179 static void scsi_host_cls_release(struct device *dev)
36180 @@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36181 * subtract one because we increment first then return, but we need to
36182 * know what the next host number was before increment
36183 */
36184 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36185 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36186 shost->dma_channel = 0xff;
36187
36188 /* These three are default values which can be overridden */
36189 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36190 index 796482b..d08435c 100644
36191 --- a/drivers/scsi/hpsa.c
36192 +++ b/drivers/scsi/hpsa.c
36193 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36194 unsigned long flags;
36195
36196 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36197 - return h->access.command_completed(h, q);
36198 + return h->access->command_completed(h, q);
36199
36200 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36201 a = rq->head[rq->current_entry];
36202 @@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36203 while (!list_empty(&h->reqQ)) {
36204 c = list_entry(h->reqQ.next, struct CommandList, list);
36205 /* can't do anything if fifo is full */
36206 - if ((h->access.fifo_full(h))) {
36207 + if ((h->access->fifo_full(h))) {
36208 dev_warn(&h->pdev->dev, "fifo full\n");
36209 break;
36210 }
36211 @@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36212
36213 /* Tell the controller execute command */
36214 spin_unlock_irqrestore(&h->lock, flags);
36215 - h->access.submit_command(h, c);
36216 + h->access->submit_command(h, c);
36217 spin_lock_irqsave(&h->lock, flags);
36218 }
36219 spin_unlock_irqrestore(&h->lock, flags);
36220 @@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36221
36222 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36223 {
36224 - return h->access.command_completed(h, q);
36225 + return h->access->command_completed(h, q);
36226 }
36227
36228 static inline bool interrupt_pending(struct ctlr_info *h)
36229 {
36230 - return h->access.intr_pending(h);
36231 + return h->access->intr_pending(h);
36232 }
36233
36234 static inline long interrupt_not_for_us(struct ctlr_info *h)
36235 {
36236 - return (h->access.intr_pending(h) == 0) ||
36237 + return (h->access->intr_pending(h) == 0) ||
36238 (h->interrupts_enabled == 0);
36239 }
36240
36241 @@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36242 if (prod_index < 0)
36243 return -ENODEV;
36244 h->product_name = products[prod_index].product_name;
36245 - h->access = *(products[prod_index].access);
36246 + h->access = products[prod_index].access;
36247
36248 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36249 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36250 @@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36251
36252 assert_spin_locked(&lockup_detector_lock);
36253 remove_ctlr_from_lockup_detector_list(h);
36254 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36255 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36256 spin_lock_irqsave(&h->lock, flags);
36257 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36258 spin_unlock_irqrestore(&h->lock, flags);
36259 @@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36260 }
36261
36262 /* make sure the board interrupts are off */
36263 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36264 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36265
36266 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36267 goto clean2;
36268 @@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36269 * fake ones to scoop up any residual completions.
36270 */
36271 spin_lock_irqsave(&h->lock, flags);
36272 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36273 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36274 spin_unlock_irqrestore(&h->lock, flags);
36275 free_irqs(h);
36276 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36277 @@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36278 dev_info(&h->pdev->dev, "Board READY.\n");
36279 dev_info(&h->pdev->dev,
36280 "Waiting for stale completions to drain.\n");
36281 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36282 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36283 msleep(10000);
36284 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36285 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36286
36287 rc = controller_reset_failed(h->cfgtable);
36288 if (rc)
36289 @@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36290 }
36291
36292 /* Turn the interrupts on so we can service requests */
36293 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36294 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36295
36296 hpsa_hba_inquiry(h);
36297 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36298 @@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36299 * To write all data in the battery backed cache to disks
36300 */
36301 hpsa_flush_cache(h);
36302 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36303 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36304 hpsa_free_irqs_and_disable_msix(h);
36305 }
36306
36307 @@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36308 return;
36309 }
36310 /* Change the access methods to the performant access methods */
36311 - h->access = SA5_performant_access;
36312 + h->access = &SA5_performant_access;
36313 h->transMethod = CFGTBL_Trans_Performant;
36314 }
36315
36316 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36317 index 9816479..c5d4e97 100644
36318 --- a/drivers/scsi/hpsa.h
36319 +++ b/drivers/scsi/hpsa.h
36320 @@ -79,7 +79,7 @@ struct ctlr_info {
36321 unsigned int msix_vector;
36322 unsigned int msi_vector;
36323 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36324 - struct access_method access;
36325 + struct access_method *access;
36326
36327 /* queue and queue Info */
36328 struct list_head reqQ;
36329 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36330 index f2df059..a3a9930 100644
36331 --- a/drivers/scsi/ips.h
36332 +++ b/drivers/scsi/ips.h
36333 @@ -1027,7 +1027,7 @@ typedef struct {
36334 int (*intr)(struct ips_ha *);
36335 void (*enableint)(struct ips_ha *);
36336 uint32_t (*statupd)(struct ips_ha *);
36337 -} ips_hw_func_t;
36338 +} __no_const ips_hw_func_t;
36339
36340 typedef struct ips_ha {
36341 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36342 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36343 index aceffad..c35c08d 100644
36344 --- a/drivers/scsi/libfc/fc_exch.c
36345 +++ b/drivers/scsi/libfc/fc_exch.c
36346 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36347 * all together if not used XXX
36348 */
36349 struct {
36350 - atomic_t no_free_exch;
36351 - atomic_t no_free_exch_xid;
36352 - atomic_t xid_not_found;
36353 - atomic_t xid_busy;
36354 - atomic_t seq_not_found;
36355 - atomic_t non_bls_resp;
36356 + atomic_unchecked_t no_free_exch;
36357 + atomic_unchecked_t no_free_exch_xid;
36358 + atomic_unchecked_t xid_not_found;
36359 + atomic_unchecked_t xid_busy;
36360 + atomic_unchecked_t seq_not_found;
36361 + atomic_unchecked_t non_bls_resp;
36362 } stats;
36363 };
36364
36365 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36366 /* allocate memory for exchange */
36367 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36368 if (!ep) {
36369 - atomic_inc(&mp->stats.no_free_exch);
36370 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36371 goto out;
36372 }
36373 memset(ep, 0, sizeof(*ep));
36374 @@ -780,7 +780,7 @@ out:
36375 return ep;
36376 err:
36377 spin_unlock_bh(&pool->lock);
36378 - atomic_inc(&mp->stats.no_free_exch_xid);
36379 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36380 mempool_free(ep, mp->ep_pool);
36381 return NULL;
36382 }
36383 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36384 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36385 ep = fc_exch_find(mp, xid);
36386 if (!ep) {
36387 - atomic_inc(&mp->stats.xid_not_found);
36388 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36389 reject = FC_RJT_OX_ID;
36390 goto out;
36391 }
36392 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36393 ep = fc_exch_find(mp, xid);
36394 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36395 if (ep) {
36396 - atomic_inc(&mp->stats.xid_busy);
36397 + atomic_inc_unchecked(&mp->stats.xid_busy);
36398 reject = FC_RJT_RX_ID;
36399 goto rel;
36400 }
36401 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36402 }
36403 xid = ep->xid; /* get our XID */
36404 } else if (!ep) {
36405 - atomic_inc(&mp->stats.xid_not_found);
36406 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36407 reject = FC_RJT_RX_ID; /* XID not found */
36408 goto out;
36409 }
36410 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36411 } else {
36412 sp = &ep->seq;
36413 if (sp->id != fh->fh_seq_id) {
36414 - atomic_inc(&mp->stats.seq_not_found);
36415 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36416 if (f_ctl & FC_FC_END_SEQ) {
36417 /*
36418 * Update sequence_id based on incoming last
36419 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36420
36421 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36422 if (!ep) {
36423 - atomic_inc(&mp->stats.xid_not_found);
36424 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36425 goto out;
36426 }
36427 if (ep->esb_stat & ESB_ST_COMPLETE) {
36428 - atomic_inc(&mp->stats.xid_not_found);
36429 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36430 goto rel;
36431 }
36432 if (ep->rxid == FC_XID_UNKNOWN)
36433 ep->rxid = ntohs(fh->fh_rx_id);
36434 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36435 - atomic_inc(&mp->stats.xid_not_found);
36436 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36437 goto rel;
36438 }
36439 if (ep->did != ntoh24(fh->fh_s_id) &&
36440 ep->did != FC_FID_FLOGI) {
36441 - atomic_inc(&mp->stats.xid_not_found);
36442 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36443 goto rel;
36444 }
36445 sof = fr_sof(fp);
36446 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36447 sp->ssb_stat |= SSB_ST_RESP;
36448 sp->id = fh->fh_seq_id;
36449 } else if (sp->id != fh->fh_seq_id) {
36450 - atomic_inc(&mp->stats.seq_not_found);
36451 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36452 goto rel;
36453 }
36454
36455 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36456 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36457
36458 if (!sp)
36459 - atomic_inc(&mp->stats.xid_not_found);
36460 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36461 else
36462 - atomic_inc(&mp->stats.non_bls_resp);
36463 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36464
36465 fc_frame_free(fp);
36466 }
36467 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36468 index d109cc3..09f4e7d 100644
36469 --- a/drivers/scsi/libsas/sas_ata.c
36470 +++ b/drivers/scsi/libsas/sas_ata.c
36471 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36472 .postreset = ata_std_postreset,
36473 .error_handler = ata_std_error_handler,
36474 .post_internal_cmd = sas_ata_post_internal,
36475 - .qc_defer = ata_std_qc_defer,
36476 + .qc_defer = ata_std_qc_defer,
36477 .qc_prep = ata_noop_qc_prep,
36478 .qc_issue = sas_ata_qc_issue,
36479 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36480 diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36481 index fe5d396..e93d526 100644
36482 --- a/drivers/scsi/lpfc/Makefile
36483 +++ b/drivers/scsi/lpfc/Makefile
36484 @@ -22,7 +22,7 @@
36485 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36486 ccflags-$(GCOV) += -O0
36487
36488 -ccflags-y += -Werror
36489 +#ccflags-y += -Werror
36490
36491 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36492
36493 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36494 index e5da6da..c888d48 100644
36495 --- a/drivers/scsi/lpfc/lpfc.h
36496 +++ b/drivers/scsi/lpfc/lpfc.h
36497 @@ -416,7 +416,7 @@ struct lpfc_vport {
36498 struct dentry *debug_nodelist;
36499 struct dentry *vport_debugfs_root;
36500 struct lpfc_debugfs_trc *disc_trc;
36501 - atomic_t disc_trc_cnt;
36502 + atomic_unchecked_t disc_trc_cnt;
36503 #endif
36504 uint8_t stat_data_enabled;
36505 uint8_t stat_data_blocked;
36506 @@ -830,8 +830,8 @@ struct lpfc_hba {
36507 struct timer_list fabric_block_timer;
36508 unsigned long bit_flags;
36509 #define FABRIC_COMANDS_BLOCKED 0
36510 - atomic_t num_rsrc_err;
36511 - atomic_t num_cmd_success;
36512 + atomic_unchecked_t num_rsrc_err;
36513 + atomic_unchecked_t num_cmd_success;
36514 unsigned long last_rsrc_error_time;
36515 unsigned long last_ramp_down_time;
36516 unsigned long last_ramp_up_time;
36517 @@ -867,7 +867,7 @@ struct lpfc_hba {
36518
36519 struct dentry *debug_slow_ring_trc;
36520 struct lpfc_debugfs_trc *slow_ring_trc;
36521 - atomic_t slow_ring_trc_cnt;
36522 + atomic_unchecked_t slow_ring_trc_cnt;
36523 /* iDiag debugfs sub-directory */
36524 struct dentry *idiag_root;
36525 struct dentry *idiag_pci_cfg;
36526 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36527 index 3217d63..c417981 100644
36528 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36529 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36530 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36531
36532 #include <linux/debugfs.h>
36533
36534 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36535 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36536 static unsigned long lpfc_debugfs_start_time = 0L;
36537
36538 /* iDiag */
36539 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36540 lpfc_debugfs_enable = 0;
36541
36542 len = 0;
36543 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36544 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36545 (lpfc_debugfs_max_disc_trc - 1);
36546 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36547 dtp = vport->disc_trc + i;
36548 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36549 lpfc_debugfs_enable = 0;
36550
36551 len = 0;
36552 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36553 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36554 (lpfc_debugfs_max_slow_ring_trc - 1);
36555 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36556 dtp = phba->slow_ring_trc + i;
36557 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36558 !vport || !vport->disc_trc)
36559 return;
36560
36561 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36562 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36563 (lpfc_debugfs_max_disc_trc - 1);
36564 dtp = vport->disc_trc + index;
36565 dtp->fmt = fmt;
36566 dtp->data1 = data1;
36567 dtp->data2 = data2;
36568 dtp->data3 = data3;
36569 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36570 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36571 dtp->jif = jiffies;
36572 #endif
36573 return;
36574 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36575 !phba || !phba->slow_ring_trc)
36576 return;
36577
36578 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36579 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36580 (lpfc_debugfs_max_slow_ring_trc - 1);
36581 dtp = phba->slow_ring_trc + index;
36582 dtp->fmt = fmt;
36583 dtp->data1 = data1;
36584 dtp->data2 = data2;
36585 dtp->data3 = data3;
36586 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36587 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36588 dtp->jif = jiffies;
36589 #endif
36590 return;
36591 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36592 "slow_ring buffer\n");
36593 goto debug_failed;
36594 }
36595 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36596 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36597 memset(phba->slow_ring_trc, 0,
36598 (sizeof(struct lpfc_debugfs_trc) *
36599 lpfc_debugfs_max_slow_ring_trc));
36600 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36601 "buffer\n");
36602 goto debug_failed;
36603 }
36604 - atomic_set(&vport->disc_trc_cnt, 0);
36605 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36606
36607 snprintf(name, sizeof(name), "discovery_trace");
36608 vport->debug_disc_trc =
36609 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36610 index 411ed48..967f553 100644
36611 --- a/drivers/scsi/lpfc/lpfc_init.c
36612 +++ b/drivers/scsi/lpfc/lpfc_init.c
36613 @@ -10341,8 +10341,10 @@ lpfc_init(void)
36614 "misc_register returned with status %d", error);
36615
36616 if (lpfc_enable_npiv) {
36617 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36618 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36619 + pax_open_kernel();
36620 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36621 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36622 + pax_close_kernel();
36623 }
36624 lpfc_transport_template =
36625 fc_attach_transport(&lpfc_transport_functions);
36626 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36627 index 66e0906..1620281 100644
36628 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36629 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36630 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36631 uint32_t evt_posted;
36632
36633 spin_lock_irqsave(&phba->hbalock, flags);
36634 - atomic_inc(&phba->num_rsrc_err);
36635 + atomic_inc_unchecked(&phba->num_rsrc_err);
36636 phba->last_rsrc_error_time = jiffies;
36637
36638 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36639 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36640 unsigned long flags;
36641 struct lpfc_hba *phba = vport->phba;
36642 uint32_t evt_posted;
36643 - atomic_inc(&phba->num_cmd_success);
36644 + atomic_inc_unchecked(&phba->num_cmd_success);
36645
36646 if (vport->cfg_lun_queue_depth <= queue_depth)
36647 return;
36648 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36649 unsigned long num_rsrc_err, num_cmd_success;
36650 int i;
36651
36652 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36653 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36654 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36655 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36656
36657 /*
36658 * The error and success command counters are global per
36659 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36660 }
36661 }
36662 lpfc_destroy_vport_work_array(phba, vports);
36663 - atomic_set(&phba->num_rsrc_err, 0);
36664 - atomic_set(&phba->num_cmd_success, 0);
36665 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36666 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36667 }
36668
36669 /**
36670 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36671 }
36672 }
36673 lpfc_destroy_vport_work_array(phba, vports);
36674 - atomic_set(&phba->num_rsrc_err, 0);
36675 - atomic_set(&phba->num_cmd_success, 0);
36676 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36677 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36678 }
36679
36680 /**
36681 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36682 index ea8a0b4..812a124 100644
36683 --- a/drivers/scsi/pmcraid.c
36684 +++ b/drivers/scsi/pmcraid.c
36685 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36686 res->scsi_dev = scsi_dev;
36687 scsi_dev->hostdata = res;
36688 res->change_detected = 0;
36689 - atomic_set(&res->read_failures, 0);
36690 - atomic_set(&res->write_failures, 0);
36691 + atomic_set_unchecked(&res->read_failures, 0);
36692 + atomic_set_unchecked(&res->write_failures, 0);
36693 rc = 0;
36694 }
36695 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36696 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36697
36698 /* If this was a SCSI read/write command keep count of errors */
36699 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36700 - atomic_inc(&res->read_failures);
36701 + atomic_inc_unchecked(&res->read_failures);
36702 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36703 - atomic_inc(&res->write_failures);
36704 + atomic_inc_unchecked(&res->write_failures);
36705
36706 if (!RES_IS_GSCSI(res->cfg_entry) &&
36707 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36708 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36709 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36710 * hrrq_id assigned here in queuecommand
36711 */
36712 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36713 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36714 pinstance->num_hrrq;
36715 cmd->cmd_done = pmcraid_io_done;
36716
36717 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36718 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36719 * hrrq_id assigned here in queuecommand
36720 */
36721 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36722 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36723 pinstance->num_hrrq;
36724
36725 if (request_size) {
36726 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36727
36728 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36729 /* add resources only after host is added into system */
36730 - if (!atomic_read(&pinstance->expose_resources))
36731 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36732 return;
36733
36734 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36735 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36736 init_waitqueue_head(&pinstance->reset_wait_q);
36737
36738 atomic_set(&pinstance->outstanding_cmds, 0);
36739 - atomic_set(&pinstance->last_message_id, 0);
36740 - atomic_set(&pinstance->expose_resources, 0);
36741 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36742 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36743
36744 INIT_LIST_HEAD(&pinstance->free_res_q);
36745 INIT_LIST_HEAD(&pinstance->used_res_q);
36746 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36747 /* Schedule worker thread to handle CCN and take care of adding and
36748 * removing devices to OS
36749 */
36750 - atomic_set(&pinstance->expose_resources, 1);
36751 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36752 schedule_work(&pinstance->worker_q);
36753 return rc;
36754
36755 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36756 index e1d150f..6c6df44 100644
36757 --- a/drivers/scsi/pmcraid.h
36758 +++ b/drivers/scsi/pmcraid.h
36759 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36760 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36761
36762 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36763 - atomic_t last_message_id;
36764 + atomic_unchecked_t last_message_id;
36765
36766 /* configuration table */
36767 struct pmcraid_config_table *cfg_table;
36768 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36769 atomic_t outstanding_cmds;
36770
36771 /* should add/delete resources to mid-layer now ?*/
36772 - atomic_t expose_resources;
36773 + atomic_unchecked_t expose_resources;
36774
36775
36776
36777 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36778 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36779 };
36780 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36781 - atomic_t read_failures; /* count of failed READ commands */
36782 - atomic_t write_failures; /* count of failed WRITE commands */
36783 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36784 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36785
36786 /* To indicate add/delete/modify during CCN */
36787 u8 change_detected;
36788 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36789 index 5ab9530..2dd80f7 100644
36790 --- a/drivers/scsi/qla2xxx/qla_attr.c
36791 +++ b/drivers/scsi/qla2xxx/qla_attr.c
36792 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36793 return 0;
36794 }
36795
36796 -struct fc_function_template qla2xxx_transport_functions = {
36797 +fc_function_template_no_const qla2xxx_transport_functions = {
36798
36799 .show_host_node_name = 1,
36800 .show_host_port_name = 1,
36801 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36802 .bsg_timeout = qla24xx_bsg_timeout,
36803 };
36804
36805 -struct fc_function_template qla2xxx_transport_vport_functions = {
36806 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
36807
36808 .show_host_node_name = 1,
36809 .show_host_port_name = 1,
36810 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36811 index 39007f5..7fafc64 100644
36812 --- a/drivers/scsi/qla2xxx/qla_def.h
36813 +++ b/drivers/scsi/qla2xxx/qla_def.h
36814 @@ -2284,7 +2284,7 @@ struct isp_operations {
36815 int (*start_scsi) (srb_t *);
36816 int (*abort_isp) (struct scsi_qla_host *);
36817 int (*iospace_config)(struct qla_hw_data*);
36818 -};
36819 +} __no_const;
36820
36821 /* MSI-X Support *************************************************************/
36822
36823 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36824 index 9eacd2d..d79629c 100644
36825 --- a/drivers/scsi/qla2xxx/qla_gbl.h
36826 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
36827 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36828 struct device_attribute;
36829 extern struct device_attribute *qla2x00_host_attrs[];
36830 struct fc_function_template;
36831 -extern struct fc_function_template qla2xxx_transport_functions;
36832 -extern struct fc_function_template qla2xxx_transport_vport_functions;
36833 +extern fc_function_template_no_const qla2xxx_transport_functions;
36834 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36835 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36836 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36837 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36838 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36839 index 96a5616..eeb185a 100644
36840 --- a/drivers/scsi/qla4xxx/ql4_def.h
36841 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36842 @@ -268,7 +268,7 @@ struct ddb_entry {
36843 * (4000 only) */
36844 atomic_t relogin_timer; /* Max Time to wait for
36845 * relogin to complete */
36846 - atomic_t relogin_retry_count; /* Num of times relogin has been
36847 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36848 * retried */
36849 uint32_t default_time2wait; /* Default Min time between
36850 * relogins (+aens) */
36851 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36852 index cd15678..f7e6846 100644
36853 --- a/drivers/scsi/qla4xxx/ql4_os.c
36854 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36855 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36856 */
36857 if (!iscsi_is_session_online(cls_sess)) {
36858 /* Reset retry relogin timer */
36859 - atomic_inc(&ddb_entry->relogin_retry_count);
36860 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36861 DEBUG2(ql4_printk(KERN_INFO, ha,
36862 "%s: index[%d] relogin timed out-retrying"
36863 " relogin (%d), retry (%d)\n", __func__,
36864 ddb_entry->fw_ddb_index,
36865 - atomic_read(&ddb_entry->relogin_retry_count),
36866 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36867 ddb_entry->default_time2wait + 4));
36868 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36869 atomic_set(&ddb_entry->retry_relogin_timer,
36870 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36871
36872 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36873 atomic_set(&ddb_entry->relogin_timer, 0);
36874 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36875 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36876 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36877 ddb_entry->default_relogin_timeout =
36878 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36879 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36880 index bbbc9c9..ce22f77 100644
36881 --- a/drivers/scsi/scsi.c
36882 +++ b/drivers/scsi/scsi.c
36883 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36884 unsigned long timeout;
36885 int rtn = 0;
36886
36887 - atomic_inc(&cmd->device->iorequest_cnt);
36888 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36889
36890 /* check if the device is still usable */
36891 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36892 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36893 index 6dfb978..ddc470e 100644
36894 --- a/drivers/scsi/scsi_lib.c
36895 +++ b/drivers/scsi/scsi_lib.c
36896 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36897 shost = sdev->host;
36898 scsi_init_cmd_errh(cmd);
36899 cmd->result = DID_NO_CONNECT << 16;
36900 - atomic_inc(&cmd->device->iorequest_cnt);
36901 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36902
36903 /*
36904 * SCSI request completion path will do scsi_device_unbusy(),
36905 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36906
36907 INIT_LIST_HEAD(&cmd->eh_entry);
36908
36909 - atomic_inc(&cmd->device->iodone_cnt);
36910 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36911 if (cmd->result)
36912 - atomic_inc(&cmd->device->ioerr_cnt);
36913 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36914
36915 disposition = scsi_decide_disposition(cmd);
36916 if (disposition != SUCCESS &&
36917 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36918 index 04c2a27..9d8bd66 100644
36919 --- a/drivers/scsi/scsi_sysfs.c
36920 +++ b/drivers/scsi/scsi_sysfs.c
36921 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36922 char *buf) \
36923 { \
36924 struct scsi_device *sdev = to_scsi_device(dev); \
36925 - unsigned long long count = atomic_read(&sdev->field); \
36926 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36927 return snprintf(buf, 20, "0x%llx\n", count); \
36928 } \
36929 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36930 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36931 index 84a1fdf..693b0d6 100644
36932 --- a/drivers/scsi/scsi_tgt_lib.c
36933 +++ b/drivers/scsi/scsi_tgt_lib.c
36934 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36935 int err;
36936
36937 dprintk("%lx %u\n", uaddr, len);
36938 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36939 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36940 if (err) {
36941 /*
36942 * TODO: need to fixup sg_tablesize, max_segment_size,
36943 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36944 index 5797604..289a5b5 100644
36945 --- a/drivers/scsi/scsi_transport_fc.c
36946 +++ b/drivers/scsi/scsi_transport_fc.c
36947 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36948 * Netlink Infrastructure
36949 */
36950
36951 -static atomic_t fc_event_seq;
36952 +static atomic_unchecked_t fc_event_seq;
36953
36954 /**
36955 * fc_get_event_number - Obtain the next sequential FC event number
36956 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36957 u32
36958 fc_get_event_number(void)
36959 {
36960 - return atomic_add_return(1, &fc_event_seq);
36961 + return atomic_add_return_unchecked(1, &fc_event_seq);
36962 }
36963 EXPORT_SYMBOL(fc_get_event_number);
36964
36965 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36966 {
36967 int error;
36968
36969 - atomic_set(&fc_event_seq, 0);
36970 + atomic_set_unchecked(&fc_event_seq, 0);
36971
36972 error = transport_class_register(&fc_host_class);
36973 if (error)
36974 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36975 char *cp;
36976
36977 *val = simple_strtoul(buf, &cp, 0);
36978 - if ((*cp && (*cp != '\n')) || (*val < 0))
36979 + if (*cp && (*cp != '\n'))
36980 return -EINVAL;
36981 /*
36982 * Check for overflow; dev_loss_tmo is u32
36983 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36984 index 1cf640e..78e9014 100644
36985 --- a/drivers/scsi/scsi_transport_iscsi.c
36986 +++ b/drivers/scsi/scsi_transport_iscsi.c
36987 @@ -79,7 +79,7 @@ struct iscsi_internal {
36988 struct transport_container session_cont;
36989 };
36990
36991 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36992 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36993 static struct workqueue_struct *iscsi_eh_timer_workq;
36994
36995 static DEFINE_IDA(iscsi_sess_ida);
36996 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36997 int err;
36998
36999 ihost = shost->shost_data;
37000 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37001 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37002
37003 if (target_id == ISCSI_MAX_TARGET) {
37004 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37005 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37006 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37007 ISCSI_TRANSPORT_VERSION);
37008
37009 - atomic_set(&iscsi_session_nr, 0);
37010 + atomic_set_unchecked(&iscsi_session_nr, 0);
37011
37012 err = class_register(&iscsi_transport_class);
37013 if (err)
37014 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37015 index 21a045e..ec89e03 100644
37016 --- a/drivers/scsi/scsi_transport_srp.c
37017 +++ b/drivers/scsi/scsi_transport_srp.c
37018 @@ -33,7 +33,7 @@
37019 #include "scsi_transport_srp_internal.h"
37020
37021 struct srp_host_attrs {
37022 - atomic_t next_port_id;
37023 + atomic_unchecked_t next_port_id;
37024 };
37025 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37026
37027 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37028 struct Scsi_Host *shost = dev_to_shost(dev);
37029 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37030
37031 - atomic_set(&srp_host->next_port_id, 0);
37032 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37033 return 0;
37034 }
37035
37036 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37037 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37038 rport->roles = ids->roles;
37039
37040 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37041 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37042 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37043
37044 transport_setup_device(&rport->dev);
37045 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37046 index 9c5c5f2..8414557 100644
37047 --- a/drivers/scsi/sg.c
37048 +++ b/drivers/scsi/sg.c
37049 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37050 sdp->disk->disk_name,
37051 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37052 NULL,
37053 - (char *)arg);
37054 + (char __user *)arg);
37055 case BLKTRACESTART:
37056 return blk_trace_startstop(sdp->device->request_queue, 1);
37057 case BLKTRACESTOP:
37058 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37059 index 1041cb8..4a946fa 100644
37060 --- a/drivers/spi/spi.c
37061 +++ b/drivers/spi/spi.c
37062 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37063 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37064
37065 /* portable code must never pass more than 32 bytes */
37066 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37067 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37068
37069 static u8 *buf;
37070
37071 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37072 index 34afc16..ffe44dd 100644
37073 --- a/drivers/staging/octeon/ethernet-rx.c
37074 +++ b/drivers/staging/octeon/ethernet-rx.c
37075 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37076 /* Increment RX stats for virtual ports */
37077 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37078 #ifdef CONFIG_64BIT
37079 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37080 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37081 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37082 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37083 #else
37084 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37085 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37086 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37087 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37088 #endif
37089 }
37090 netif_receive_skb(skb);
37091 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37092 dev->name);
37093 */
37094 #ifdef CONFIG_64BIT
37095 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37096 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37097 #else
37098 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37099 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37100 #endif
37101 dev_kfree_skb_irq(skb);
37102 }
37103 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37104 index 18f7a79..cc3bc24 100644
37105 --- a/drivers/staging/octeon/ethernet.c
37106 +++ b/drivers/staging/octeon/ethernet.c
37107 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37108 * since the RX tasklet also increments it.
37109 */
37110 #ifdef CONFIG_64BIT
37111 - atomic64_add(rx_status.dropped_packets,
37112 - (atomic64_t *)&priv->stats.rx_dropped);
37113 + atomic64_add_unchecked(rx_status.dropped_packets,
37114 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37115 #else
37116 - atomic_add(rx_status.dropped_packets,
37117 - (atomic_t *)&priv->stats.rx_dropped);
37118 + atomic_add_unchecked(rx_status.dropped_packets,
37119 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37120 #endif
37121 }
37122
37123 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37124 index dc23395..cf7e9b1 100644
37125 --- a/drivers/staging/rtl8712/rtl871x_io.h
37126 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37127 @@ -108,7 +108,7 @@ struct _io_ops {
37128 u8 *pmem);
37129 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37130 u8 *pmem);
37131 -};
37132 +} __no_const;
37133
37134 struct io_req {
37135 struct list_head list;
37136 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37137 index c7b5e8b..783d6cb 100644
37138 --- a/drivers/staging/sbe-2t3e3/netdev.c
37139 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37140 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37141 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37142
37143 if (rlen)
37144 - if (copy_to_user(data, &resp, rlen))
37145 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37146 return -EFAULT;
37147
37148 return 0;
37149 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37150 index 42cdafe..2769103 100644
37151 --- a/drivers/staging/speakup/speakup_soft.c
37152 +++ b/drivers/staging/speakup/speakup_soft.c
37153 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37154 break;
37155 } else if (!initialized) {
37156 if (*init) {
37157 - ch = *init;
37158 init++;
37159 } else {
37160 initialized = 1;
37161 }
37162 + ch = *init;
37163 } else {
37164 ch = synth_buffer_getc();
37165 }
37166 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37167 index 5d89c0f..9261317 100644
37168 --- a/drivers/staging/usbip/usbip_common.h
37169 +++ b/drivers/staging/usbip/usbip_common.h
37170 @@ -289,7 +289,7 @@ struct usbip_device {
37171 void (*shutdown)(struct usbip_device *);
37172 void (*reset)(struct usbip_device *);
37173 void (*unusable)(struct usbip_device *);
37174 - } eh_ops;
37175 + } __no_const eh_ops;
37176 };
37177
37178 #define kthread_get_run(threadfn, data, namefmt, ...) \
37179 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37180 index 88b3298..3783eee 100644
37181 --- a/drivers/staging/usbip/vhci.h
37182 +++ b/drivers/staging/usbip/vhci.h
37183 @@ -88,7 +88,7 @@ struct vhci_hcd {
37184 unsigned resuming:1;
37185 unsigned long re_timeout;
37186
37187 - atomic_t seqnum;
37188 + atomic_unchecked_t seqnum;
37189
37190 /*
37191 * NOTE:
37192 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37193 index f708cba..2de6d72 100644
37194 --- a/drivers/staging/usbip/vhci_hcd.c
37195 +++ b/drivers/staging/usbip/vhci_hcd.c
37196 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37197 return;
37198 }
37199
37200 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37201 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37202 if (priv->seqnum == 0xffff)
37203 dev_info(&urb->dev->dev, "seqnum max\n");
37204
37205 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37206 return -ENOMEM;
37207 }
37208
37209 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37210 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37211 if (unlink->seqnum == 0xffff)
37212 pr_info("seqnum max\n");
37213
37214 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37215 vdev->rhport = rhport;
37216 }
37217
37218 - atomic_set(&vhci->seqnum, 0);
37219 + atomic_set_unchecked(&vhci->seqnum, 0);
37220 spin_lock_init(&vhci->lock);
37221
37222 hcd->power_budget = 0; /* no limit */
37223 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37224 index f0eaf04..5a82e06 100644
37225 --- a/drivers/staging/usbip/vhci_rx.c
37226 +++ b/drivers/staging/usbip/vhci_rx.c
37227 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37228 if (!urb) {
37229 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37230 pr_info("max seqnum %d\n",
37231 - atomic_read(&the_controller->seqnum));
37232 + atomic_read_unchecked(&the_controller->seqnum));
37233 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37234 return;
37235 }
37236 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37237 index 7735027..30eed13 100644
37238 --- a/drivers/staging/vt6655/hostap.c
37239 +++ b/drivers/staging/vt6655/hostap.c
37240 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37241 *
37242 */
37243
37244 +static net_device_ops_no_const apdev_netdev_ops;
37245 +
37246 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37247 {
37248 PSDevice apdev_priv;
37249 struct net_device *dev = pDevice->dev;
37250 int ret;
37251 - const struct net_device_ops apdev_netdev_ops = {
37252 - .ndo_start_xmit = pDevice->tx_80211,
37253 - };
37254
37255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37256
37257 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37258 *apdev_priv = *pDevice;
37259 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37260
37261 + /* only half broken now */
37262 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37263 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37264
37265 pDevice->apdev->type = ARPHRD_IEEE80211;
37266 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37267 index 51b5adf..098e320 100644
37268 --- a/drivers/staging/vt6656/hostap.c
37269 +++ b/drivers/staging/vt6656/hostap.c
37270 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37271 *
37272 */
37273
37274 +static net_device_ops_no_const apdev_netdev_ops;
37275 +
37276 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37277 {
37278 PSDevice apdev_priv;
37279 struct net_device *dev = pDevice->dev;
37280 int ret;
37281 - const struct net_device_ops apdev_netdev_ops = {
37282 - .ndo_start_xmit = pDevice->tx_80211,
37283 - };
37284
37285 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37286
37287 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37288 *apdev_priv = *pDevice;
37289 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37290
37291 + /* only half broken now */
37292 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37293 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37294
37295 pDevice->apdev->type = ARPHRD_IEEE80211;
37296 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37297 index 7843dfd..3db105f 100644
37298 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37299 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37300 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37301
37302 struct usbctlx_completor {
37303 int (*complete) (struct usbctlx_completor *);
37304 -};
37305 +} __no_const;
37306
37307 static int
37308 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37309 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37310 index 1ca66ea..76f1343 100644
37311 --- a/drivers/staging/zcache/tmem.c
37312 +++ b/drivers/staging/zcache/tmem.c
37313 @@ -39,7 +39,7 @@
37314 * A tmem host implementation must use this function to register callbacks
37315 * for memory allocation.
37316 */
37317 -static struct tmem_hostops tmem_hostops;
37318 +static tmem_hostops_no_const tmem_hostops;
37319
37320 static void tmem_objnode_tree_init(void);
37321
37322 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37323 * A tmem host implementation must use this function to register
37324 * callbacks for a page-accessible memory (PAM) implementation
37325 */
37326 -static struct tmem_pamops tmem_pamops;
37327 +static tmem_pamops_no_const tmem_pamops;
37328
37329 void tmem_register_pamops(struct tmem_pamops *m)
37330 {
37331 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37332 index 0d4aa82..f7832d4 100644
37333 --- a/drivers/staging/zcache/tmem.h
37334 +++ b/drivers/staging/zcache/tmem.h
37335 @@ -180,6 +180,7 @@ struct tmem_pamops {
37336 void (*new_obj)(struct tmem_obj *);
37337 int (*replace_in_obj)(void *, struct tmem_obj *);
37338 };
37339 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37340 extern void tmem_register_pamops(struct tmem_pamops *m);
37341
37342 /* memory allocation methods provided by the host implementation */
37343 @@ -189,6 +190,7 @@ struct tmem_hostops {
37344 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37345 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37346 };
37347 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37348 extern void tmem_register_hostops(struct tmem_hostops *m);
37349
37350 /* core tmem accessor functions */
37351 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37352 index 634d0f3..efff61f 100644
37353 --- a/drivers/target/target_core_transport.c
37354 +++ b/drivers/target/target_core_transport.c
37355 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37356 spin_lock_init(&dev->se_port_lock);
37357 spin_lock_init(&dev->se_tmr_lock);
37358 spin_lock_init(&dev->qf_cmd_lock);
37359 - atomic_set(&dev->dev_ordered_id, 0);
37360 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37361
37362 se_dev_set_default_attribs(dev, dev_limits);
37363
37364 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37365 * Used to determine when ORDERED commands should go from
37366 * Dormant to Active status.
37367 */
37368 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37369 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37370 smp_mb__after_atomic_inc();
37371 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37372 cmd->se_ordered_id, cmd->sam_task_attr,
37373 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37374 index e61cabd..7617d26 100644
37375 --- a/drivers/tty/cyclades.c
37376 +++ b/drivers/tty/cyclades.c
37377 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37378 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37379 info->port.count);
37380 #endif
37381 - info->port.count++;
37382 + atomic_inc(&info->port.count);
37383 #ifdef CY_DEBUG_COUNT
37384 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37385 - current->pid, info->port.count);
37386 + current->pid, atomic_read(&info->port.count));
37387 #endif
37388
37389 /*
37390 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37391 for (j = 0; j < cy_card[i].nports; j++) {
37392 info = &cy_card[i].ports[j];
37393
37394 - if (info->port.count) {
37395 + if (atomic_read(&info->port.count)) {
37396 /* XXX is the ldisc num worth this? */
37397 struct tty_struct *tty;
37398 struct tty_ldisc *ld;
37399 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37400 index 2d691eb..be02ebd 100644
37401 --- a/drivers/tty/hvc/hvc_console.c
37402 +++ b/drivers/tty/hvc/hvc_console.c
37403 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37404
37405 spin_lock_irqsave(&hp->port.lock, flags);
37406 /* Check and then increment for fast path open. */
37407 - if (hp->port.count++ > 0) {
37408 + if (atomic_inc_return(&hp->port.count) > 1) {
37409 spin_unlock_irqrestore(&hp->port.lock, flags);
37410 hvc_kick();
37411 return 0;
37412 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37413
37414 spin_lock_irqsave(&hp->port.lock, flags);
37415
37416 - if (--hp->port.count == 0) {
37417 + if (atomic_dec_return(&hp->port.count) == 0) {
37418 spin_unlock_irqrestore(&hp->port.lock, flags);
37419 /* We are done with the tty pointer now. */
37420 tty_port_tty_set(&hp->port, NULL);
37421 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37422 */
37423 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37424 } else {
37425 - if (hp->port.count < 0)
37426 + if (atomic_read(&hp->port.count) < 0)
37427 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37428 - hp->vtermno, hp->port.count);
37429 + hp->vtermno, atomic_read(&hp->port.count));
37430 spin_unlock_irqrestore(&hp->port.lock, flags);
37431 }
37432
37433 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37434 * open->hangup case this can be called after the final close so prevent
37435 * that from happening for now.
37436 */
37437 - if (hp->port.count <= 0) {
37438 + if (atomic_read(&hp->port.count) <= 0) {
37439 spin_unlock_irqrestore(&hp->port.lock, flags);
37440 return;
37441 }
37442
37443 - temp_open_count = hp->port.count;
37444 - hp->port.count = 0;
37445 + temp_open_count = atomic_read(&hp->port.count);
37446 + atomic_set(&hp->port.count, 0);
37447 spin_unlock_irqrestore(&hp->port.lock, flags);
37448 tty_port_tty_set(&hp->port, NULL);
37449
37450 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37451 return -EPIPE;
37452
37453 /* FIXME what's this (unprotected) check for? */
37454 - if (hp->port.count <= 0)
37455 + if (atomic_read(&hp->port.count) <= 0)
37456 return -EIO;
37457
37458 spin_lock_irqsave(&hp->lock, flags);
37459 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37460 index d56788c..12d8f85 100644
37461 --- a/drivers/tty/hvc/hvcs.c
37462 +++ b/drivers/tty/hvc/hvcs.c
37463 @@ -83,6 +83,7 @@
37464 #include <asm/hvcserver.h>
37465 #include <asm/uaccess.h>
37466 #include <asm/vio.h>
37467 +#include <asm/local.h>
37468
37469 /*
37470 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37471 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37472
37473 spin_lock_irqsave(&hvcsd->lock, flags);
37474
37475 - if (hvcsd->port.count > 0) {
37476 + if (atomic_read(&hvcsd->port.count) > 0) {
37477 spin_unlock_irqrestore(&hvcsd->lock, flags);
37478 printk(KERN_INFO "HVCS: vterm state unchanged. "
37479 "The hvcs device node is still in use.\n");
37480 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37481 if ((retval = hvcs_partner_connect(hvcsd)))
37482 goto error_release;
37483
37484 - hvcsd->port.count = 1;
37485 + atomic_set(&hvcsd->port.count, 1);
37486 hvcsd->port.tty = tty;
37487 tty->driver_data = hvcsd;
37488
37489 @@ -1168,7 +1169,7 @@ fast_open:
37490
37491 spin_lock_irqsave(&hvcsd->lock, flags);
37492 tty_port_get(&hvcsd->port);
37493 - hvcsd->port.count++;
37494 + atomic_inc(&hvcsd->port.count);
37495 hvcsd->todo_mask |= HVCS_SCHED_READ;
37496 spin_unlock_irqrestore(&hvcsd->lock, flags);
37497
37498 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37499 hvcsd = tty->driver_data;
37500
37501 spin_lock_irqsave(&hvcsd->lock, flags);
37502 - if (--hvcsd->port.count == 0) {
37503 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37504
37505 vio_disable_interrupts(hvcsd->vdev);
37506
37507 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37508 free_irq(irq, hvcsd);
37509 tty_port_put(&hvcsd->port);
37510 return;
37511 - } else if (hvcsd->port.count < 0) {
37512 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37513 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37514 " is missmanaged.\n",
37515 - hvcsd->vdev->unit_address, hvcsd->port.count);
37516 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37517 }
37518
37519 spin_unlock_irqrestore(&hvcsd->lock, flags);
37520 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37521
37522 spin_lock_irqsave(&hvcsd->lock, flags);
37523 /* Preserve this so that we know how many kref refs to put */
37524 - temp_open_count = hvcsd->port.count;
37525 + temp_open_count = atomic_read(&hvcsd->port.count);
37526
37527 /*
37528 * Don't kref put inside the spinlock because the destruction
37529 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37530 tty->driver_data = NULL;
37531 hvcsd->port.tty = NULL;
37532
37533 - hvcsd->port.count = 0;
37534 + atomic_set(&hvcsd->port.count, 0);
37535
37536 /* This will drop any buffered data on the floor which is OK in a hangup
37537 * scenario. */
37538 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37539 * the middle of a write operation? This is a crummy place to do this
37540 * but we want to keep it all in the spinlock.
37541 */
37542 - if (hvcsd->port.count <= 0) {
37543 + if (atomic_read(&hvcsd->port.count) <= 0) {
37544 spin_unlock_irqrestore(&hvcsd->lock, flags);
37545 return -ENODEV;
37546 }
37547 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37548 {
37549 struct hvcs_struct *hvcsd = tty->driver_data;
37550
37551 - if (!hvcsd || hvcsd->port.count <= 0)
37552 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37553 return 0;
37554
37555 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37556 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37557 index f8b5fa0..4ba9f89 100644
37558 --- a/drivers/tty/ipwireless/tty.c
37559 +++ b/drivers/tty/ipwireless/tty.c
37560 @@ -29,6 +29,7 @@
37561 #include <linux/tty_driver.h>
37562 #include <linux/tty_flip.h>
37563 #include <linux/uaccess.h>
37564 +#include <asm/local.h>
37565
37566 #include "tty.h"
37567 #include "network.h"
37568 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37569 mutex_unlock(&tty->ipw_tty_mutex);
37570 return -ENODEV;
37571 }
37572 - if (tty->port.count == 0)
37573 + if (atomic_read(&tty->port.count) == 0)
37574 tty->tx_bytes_queued = 0;
37575
37576 - tty->port.count++;
37577 + atomic_inc(&tty->port.count);
37578
37579 tty->port.tty = linux_tty;
37580 linux_tty->driver_data = tty;
37581 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37582
37583 static void do_ipw_close(struct ipw_tty *tty)
37584 {
37585 - tty->port.count--;
37586 -
37587 - if (tty->port.count == 0) {
37588 + if (atomic_dec_return(&tty->port.count) == 0) {
37589 struct tty_struct *linux_tty = tty->port.tty;
37590
37591 if (linux_tty != NULL) {
37592 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37593 return;
37594
37595 mutex_lock(&tty->ipw_tty_mutex);
37596 - if (tty->port.count == 0) {
37597 + if (atomic_read(&tty->port.count) == 0) {
37598 mutex_unlock(&tty->ipw_tty_mutex);
37599 return;
37600 }
37601 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37602 return;
37603 }
37604
37605 - if (!tty->port.count) {
37606 + if (!atomic_read(&tty->port.count)) {
37607 mutex_unlock(&tty->ipw_tty_mutex);
37608 return;
37609 }
37610 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37611 return -ENODEV;
37612
37613 mutex_lock(&tty->ipw_tty_mutex);
37614 - if (!tty->port.count) {
37615 + if (!atomic_read(&tty->port.count)) {
37616 mutex_unlock(&tty->ipw_tty_mutex);
37617 return -EINVAL;
37618 }
37619 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37620 if (!tty)
37621 return -ENODEV;
37622
37623 - if (!tty->port.count)
37624 + if (!atomic_read(&tty->port.count))
37625 return -EINVAL;
37626
37627 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37628 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37629 if (!tty)
37630 return 0;
37631
37632 - if (!tty->port.count)
37633 + if (!atomic_read(&tty->port.count))
37634 return 0;
37635
37636 return tty->tx_bytes_queued;
37637 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37638 if (!tty)
37639 return -ENODEV;
37640
37641 - if (!tty->port.count)
37642 + if (!atomic_read(&tty->port.count))
37643 return -EINVAL;
37644
37645 return get_control_lines(tty);
37646 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37647 if (!tty)
37648 return -ENODEV;
37649
37650 - if (!tty->port.count)
37651 + if (!atomic_read(&tty->port.count))
37652 return -EINVAL;
37653
37654 return set_control_lines(tty, set, clear);
37655 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37656 if (!tty)
37657 return -ENODEV;
37658
37659 - if (!tty->port.count)
37660 + if (!atomic_read(&tty->port.count))
37661 return -EINVAL;
37662
37663 /* FIXME: Exactly how is the tty object locked here .. */
37664 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37665 * are gone */
37666 mutex_lock(&ttyj->ipw_tty_mutex);
37667 }
37668 - while (ttyj->port.count)
37669 + while (atomic_read(&ttyj->port.count))
37670 do_ipw_close(ttyj);
37671 ipwireless_disassociate_network_ttys(network,
37672 ttyj->channel_idx);
37673 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37674 index 324467d..504cc25 100644
37675 --- a/drivers/tty/moxa.c
37676 +++ b/drivers/tty/moxa.c
37677 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37678 }
37679
37680 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37681 - ch->port.count++;
37682 + atomic_inc(&ch->port.count);
37683 tty->driver_data = ch;
37684 tty_port_tty_set(&ch->port, tty);
37685 mutex_lock(&ch->port.mutex);
37686 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37687 index c43b683..4dab83e 100644
37688 --- a/drivers/tty/n_gsm.c
37689 +++ b/drivers/tty/n_gsm.c
37690 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37691 kref_init(&dlci->ref);
37692 mutex_init(&dlci->mutex);
37693 dlci->fifo = &dlci->_fifo;
37694 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37695 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37696 kfree(dlci);
37697 return NULL;
37698 }
37699 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37700 if (dlci == NULL)
37701 return -ENOMEM;
37702 port = &dlci->port;
37703 - port->count++;
37704 + atomic_inc(&port->count);
37705 tty->driver_data = dlci;
37706 dlci_get(dlci);
37707 dlci_get(dlci->gsm->dlci[0]);
37708 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37709 index ee1c268..0e97caf 100644
37710 --- a/drivers/tty/n_tty.c
37711 +++ b/drivers/tty/n_tty.c
37712 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37713 {
37714 *ops = tty_ldisc_N_TTY;
37715 ops->owner = NULL;
37716 - ops->refcount = ops->flags = 0;
37717 + atomic_set(&ops->refcount, 0);
37718 + ops->flags = 0;
37719 }
37720 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37721 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37722 index 5505ffc..7affff9 100644
37723 --- a/drivers/tty/pty.c
37724 +++ b/drivers/tty/pty.c
37725 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37726 panic("Couldn't register Unix98 pts driver");
37727
37728 /* Now create the /dev/ptmx special device */
37729 + pax_open_kernel();
37730 tty_default_fops(&ptmx_fops);
37731 - ptmx_fops.open = ptmx_open;
37732 + *(void **)&ptmx_fops.open = ptmx_open;
37733 + pax_close_kernel();
37734
37735 cdev_init(&ptmx_cdev, &ptmx_fops);
37736 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37737 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37738 index 777d5f9..56d67ca 100644
37739 --- a/drivers/tty/rocket.c
37740 +++ b/drivers/tty/rocket.c
37741 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37742 tty->driver_data = info;
37743 tty_port_tty_set(port, tty);
37744
37745 - if (port->count++ == 0) {
37746 + if (atomic_inc_return(&port->count) == 1) {
37747 atomic_inc(&rp_num_ports_open);
37748
37749 #ifdef ROCKET_DEBUG_OPEN
37750 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37751 #endif
37752 }
37753 #ifdef ROCKET_DEBUG_OPEN
37754 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37755 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37756 #endif
37757
37758 /*
37759 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37760 spin_unlock_irqrestore(&info->port.lock, flags);
37761 return;
37762 }
37763 - if (info->port.count)
37764 + if (atomic_read(&info->port.count))
37765 atomic_dec(&rp_num_ports_open);
37766 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37767 spin_unlock_irqrestore(&info->port.lock, flags);
37768 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37769 index 2b42a01..32a2ed3 100644
37770 --- a/drivers/tty/serial/kgdboc.c
37771 +++ b/drivers/tty/serial/kgdboc.c
37772 @@ -24,8 +24,9 @@
37773 #define MAX_CONFIG_LEN 40
37774
37775 static struct kgdb_io kgdboc_io_ops;
37776 +static struct kgdb_io kgdboc_io_ops_console;
37777
37778 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37779 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37780 static int configured = -1;
37781
37782 static char config[MAX_CONFIG_LEN];
37783 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37784 kgdboc_unregister_kbd();
37785 if (configured == 1)
37786 kgdb_unregister_io_module(&kgdboc_io_ops);
37787 + else if (configured == 2)
37788 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37789 }
37790
37791 static int configure_kgdboc(void)
37792 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37793 int err;
37794 char *cptr = config;
37795 struct console *cons;
37796 + int is_console = 0;
37797
37798 err = kgdboc_option_setup(config);
37799 if (err || !strlen(config) || isspace(config[0]))
37800 goto noconfig;
37801
37802 err = -ENODEV;
37803 - kgdboc_io_ops.is_console = 0;
37804 kgdb_tty_driver = NULL;
37805
37806 kgdboc_use_kms = 0;
37807 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37808 int idx;
37809 if (cons->device && cons->device(cons, &idx) == p &&
37810 idx == tty_line) {
37811 - kgdboc_io_ops.is_console = 1;
37812 + is_console = 1;
37813 break;
37814 }
37815 cons = cons->next;
37816 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37817 kgdb_tty_line = tty_line;
37818
37819 do_register:
37820 - err = kgdb_register_io_module(&kgdboc_io_ops);
37821 + if (is_console) {
37822 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37823 + configured = 2;
37824 + } else {
37825 + err = kgdb_register_io_module(&kgdboc_io_ops);
37826 + configured = 1;
37827 + }
37828 if (err)
37829 goto noconfig;
37830
37831 - configured = 1;
37832 -
37833 return 0;
37834
37835 noconfig:
37836 @@ -213,7 +220,7 @@ noconfig:
37837 static int __init init_kgdboc(void)
37838 {
37839 /* Already configured? */
37840 - if (configured == 1)
37841 + if (configured >= 1)
37842 return 0;
37843
37844 return configure_kgdboc();
37845 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37846 if (config[len - 1] == '\n')
37847 config[len - 1] = '\0';
37848
37849 - if (configured == 1)
37850 + if (configured >= 1)
37851 cleanup_kgdboc();
37852
37853 /* Go and configure with the new params. */
37854 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37855 .post_exception = kgdboc_post_exp_handler,
37856 };
37857
37858 +static struct kgdb_io kgdboc_io_ops_console = {
37859 + .name = "kgdboc",
37860 + .read_char = kgdboc_get_char,
37861 + .write_char = kgdboc_put_char,
37862 + .pre_exception = kgdboc_pre_exp_handler,
37863 + .post_exception = kgdboc_post_exp_handler,
37864 + .is_console = 1
37865 +};
37866 +
37867 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37868 /* This is only available if kgdboc is a built in for early debugging */
37869 static int __init kgdboc_early_init(char *opt)
37870 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37871 index 246b823..9e0db76 100644
37872 --- a/drivers/tty/serial/serial_core.c
37873 +++ b/drivers/tty/serial/serial_core.c
37874 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37875 uart_flush_buffer(tty);
37876 uart_shutdown(tty, state);
37877 spin_lock_irqsave(&port->lock, flags);
37878 - port->count = 0;
37879 + atomic_set(&port->count, 0);
37880 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37881 spin_unlock_irqrestore(&port->lock, flags);
37882 tty_port_tty_set(port, NULL);
37883 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37884 goto end;
37885 }
37886
37887 - port->count++;
37888 + atomic_inc(&port->count);
37889 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37890 retval = -ENXIO;
37891 goto err_dec_count;
37892 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37893 /*
37894 * Make sure the device is in D0 state.
37895 */
37896 - if (port->count == 1)
37897 + if (atomic_read(&port->count) == 1)
37898 uart_change_pm(state, 0);
37899
37900 /*
37901 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37902 end:
37903 return retval;
37904 err_dec_count:
37905 - port->count--;
37906 + atomic_inc(&port->count);
37907 mutex_unlock(&port->mutex);
37908 goto end;
37909 }
37910 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37911 index 593d40a..bdc61f3 100644
37912 --- a/drivers/tty/synclink.c
37913 +++ b/drivers/tty/synclink.c
37914 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37915
37916 if (debug_level >= DEBUG_LEVEL_INFO)
37917 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37918 - __FILE__,__LINE__, info->device_name, info->port.count);
37919 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37920
37921 if (tty_port_close_start(&info->port, tty, filp) == 0)
37922 goto cleanup;
37923 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37924 cleanup:
37925 if (debug_level >= DEBUG_LEVEL_INFO)
37926 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37927 - tty->driver->name, info->port.count);
37928 + tty->driver->name, atomic_read(&info->port.count));
37929
37930 } /* end of mgsl_close() */
37931
37932 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37933
37934 mgsl_flush_buffer(tty);
37935 shutdown(info);
37936 -
37937 - info->port.count = 0;
37938 +
37939 + atomic_set(&info->port.count, 0);
37940 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37941 info->port.tty = NULL;
37942
37943 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37944
37945 if (debug_level >= DEBUG_LEVEL_INFO)
37946 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37947 - __FILE__,__LINE__, tty->driver->name, port->count );
37948 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37949
37950 spin_lock_irqsave(&info->irq_spinlock, flags);
37951 if (!tty_hung_up_p(filp)) {
37952 extra_count = true;
37953 - port->count--;
37954 + atomic_dec(&port->count);
37955 }
37956 spin_unlock_irqrestore(&info->irq_spinlock, flags);
37957 port->blocked_open++;
37958 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37959
37960 if (debug_level >= DEBUG_LEVEL_INFO)
37961 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
37962 - __FILE__,__LINE__, tty->driver->name, port->count );
37963 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37964
37965 tty_unlock();
37966 schedule();
37967 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37968
37969 /* FIXME: Racy on hangup during close wait */
37970 if (extra_count)
37971 - port->count++;
37972 + atomic_inc(&port->count);
37973 port->blocked_open--;
37974
37975 if (debug_level >= DEBUG_LEVEL_INFO)
37976 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
37977 - __FILE__,__LINE__, tty->driver->name, port->count );
37978 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37979
37980 if (!retval)
37981 port->flags |= ASYNC_NORMAL_ACTIVE;
37982 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
37983
37984 if (debug_level >= DEBUG_LEVEL_INFO)
37985 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
37986 - __FILE__,__LINE__,tty->driver->name, info->port.count);
37987 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
37988
37989 /* If port is closing, signal caller to try again */
37990 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
37991 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
37992 spin_unlock_irqrestore(&info->netlock, flags);
37993 goto cleanup;
37994 }
37995 - info->port.count++;
37996 + atomic_inc(&info->port.count);
37997 spin_unlock_irqrestore(&info->netlock, flags);
37998
37999 - if (info->port.count == 1) {
38000 + if (atomic_read(&info->port.count) == 1) {
38001 /* 1st open on this device, init hardware */
38002 retval = startup(info);
38003 if (retval < 0)
38004 @@ -3444,8 +3444,8 @@ cleanup:
38005 if (retval) {
38006 if (tty->count == 1)
38007 info->port.tty = NULL; /* tty layer will release tty struct */
38008 - if(info->port.count)
38009 - info->port.count--;
38010 + if (atomic_read(&info->port.count))
38011 + atomic_dec(&info->port.count);
38012 }
38013
38014 return retval;
38015 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38016 unsigned short new_crctype;
38017
38018 /* return error if TTY interface open */
38019 - if (info->port.count)
38020 + if (atomic_read(&info->port.count))
38021 return -EBUSY;
38022
38023 switch (encoding)
38024 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38025
38026 /* arbitrate between network and tty opens */
38027 spin_lock_irqsave(&info->netlock, flags);
38028 - if (info->port.count != 0 || info->netcount != 0) {
38029 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38030 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38031 spin_unlock_irqrestore(&info->netlock, flags);
38032 return -EBUSY;
38033 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38034 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38035
38036 /* return error if TTY interface open */
38037 - if (info->port.count)
38038 + if (atomic_read(&info->port.count))
38039 return -EBUSY;
38040
38041 if (cmd != SIOCWANDEV)
38042 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38043 index aa1debf..9297a16 100644
38044 --- a/drivers/tty/synclink_gt.c
38045 +++ b/drivers/tty/synclink_gt.c
38046 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38047 tty->driver_data = info;
38048 info->port.tty = tty;
38049
38050 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38051 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38052
38053 /* If port is closing, signal caller to try again */
38054 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38055 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38056 mutex_unlock(&info->port.mutex);
38057 goto cleanup;
38058 }
38059 - info->port.count++;
38060 + atomic_inc(&info->port.count);
38061 spin_unlock_irqrestore(&info->netlock, flags);
38062
38063 - if (info->port.count == 1) {
38064 + if (atomic_read(&info->port.count) == 1) {
38065 /* 1st open on this device, init hardware */
38066 retval = startup(info);
38067 if (retval < 0) {
38068 @@ -716,8 +716,8 @@ cleanup:
38069 if (retval) {
38070 if (tty->count == 1)
38071 info->port.tty = NULL; /* tty layer will release tty struct */
38072 - if(info->port.count)
38073 - info->port.count--;
38074 + if(atomic_read(&info->port.count))
38075 + atomic_dec(&info->port.count);
38076 }
38077
38078 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38079 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38080
38081 if (sanity_check(info, tty->name, "close"))
38082 return;
38083 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38084 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38085
38086 if (tty_port_close_start(&info->port, tty, filp) == 0)
38087 goto cleanup;
38088 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38089 tty_port_close_end(&info->port, tty);
38090 info->port.tty = NULL;
38091 cleanup:
38092 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38093 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38094 }
38095
38096 static void hangup(struct tty_struct *tty)
38097 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38098 shutdown(info);
38099
38100 spin_lock_irqsave(&info->port.lock, flags);
38101 - info->port.count = 0;
38102 + atomic_set(&info->port.count, 0);
38103 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38104 info->port.tty = NULL;
38105 spin_unlock_irqrestore(&info->port.lock, flags);
38106 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38107 unsigned short new_crctype;
38108
38109 /* return error if TTY interface open */
38110 - if (info->port.count)
38111 + if (atomic_read(&info->port.count))
38112 return -EBUSY;
38113
38114 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38115 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38116
38117 /* arbitrate between network and tty opens */
38118 spin_lock_irqsave(&info->netlock, flags);
38119 - if (info->port.count != 0 || info->netcount != 0) {
38120 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38121 DBGINFO(("%s hdlc_open busy\n", dev->name));
38122 spin_unlock_irqrestore(&info->netlock, flags);
38123 return -EBUSY;
38124 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38125 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38126
38127 /* return error if TTY interface open */
38128 - if (info->port.count)
38129 + if (atomic_read(&info->port.count))
38130 return -EBUSY;
38131
38132 if (cmd != SIOCWANDEV)
38133 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38134 if (port == NULL)
38135 continue;
38136 spin_lock(&port->lock);
38137 - if ((port->port.count || port->netcount) &&
38138 + if ((atomic_read(&port->port.count) || port->netcount) &&
38139 port->pending_bh && !port->bh_running &&
38140 !port->bh_requested) {
38141 DBGISR(("%s bh queued\n", port->device_name));
38142 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38143 spin_lock_irqsave(&info->lock, flags);
38144 if (!tty_hung_up_p(filp)) {
38145 extra_count = true;
38146 - port->count--;
38147 + atomic_dec(&port->count);
38148 }
38149 spin_unlock_irqrestore(&info->lock, flags);
38150 port->blocked_open++;
38151 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38152 remove_wait_queue(&port->open_wait, &wait);
38153
38154 if (extra_count)
38155 - port->count++;
38156 + atomic_inc(&port->count);
38157 port->blocked_open--;
38158
38159 if (!retval)
38160 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38161 index a3dddc1..8905ab2 100644
38162 --- a/drivers/tty/synclinkmp.c
38163 +++ b/drivers/tty/synclinkmp.c
38164 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38165
38166 if (debug_level >= DEBUG_LEVEL_INFO)
38167 printk("%s(%d):%s open(), old ref count = %d\n",
38168 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38169 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38170
38171 /* If port is closing, signal caller to try again */
38172 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38173 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38174 spin_unlock_irqrestore(&info->netlock, flags);
38175 goto cleanup;
38176 }
38177 - info->port.count++;
38178 + atomic_inc(&info->port.count);
38179 spin_unlock_irqrestore(&info->netlock, flags);
38180
38181 - if (info->port.count == 1) {
38182 + if (atomic_read(&info->port.count) == 1) {
38183 /* 1st open on this device, init hardware */
38184 retval = startup(info);
38185 if (retval < 0)
38186 @@ -788,8 +788,8 @@ cleanup:
38187 if (retval) {
38188 if (tty->count == 1)
38189 info->port.tty = NULL; /* tty layer will release tty struct */
38190 - if(info->port.count)
38191 - info->port.count--;
38192 + if(atomic_read(&info->port.count))
38193 + atomic_dec(&info->port.count);
38194 }
38195
38196 return retval;
38197 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38198
38199 if (debug_level >= DEBUG_LEVEL_INFO)
38200 printk("%s(%d):%s close() entry, count=%d\n",
38201 - __FILE__,__LINE__, info->device_name, info->port.count);
38202 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38203
38204 if (tty_port_close_start(&info->port, tty, filp) == 0)
38205 goto cleanup;
38206 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38207 cleanup:
38208 if (debug_level >= DEBUG_LEVEL_INFO)
38209 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38210 - tty->driver->name, info->port.count);
38211 + tty->driver->name, atomic_read(&info->port.count));
38212 }
38213
38214 /* Called by tty_hangup() when a hangup is signaled.
38215 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38216 shutdown(info);
38217
38218 spin_lock_irqsave(&info->port.lock, flags);
38219 - info->port.count = 0;
38220 + atomic_set(&info->port.count, 0);
38221 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38222 info->port.tty = NULL;
38223 spin_unlock_irqrestore(&info->port.lock, flags);
38224 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38225 unsigned short new_crctype;
38226
38227 /* return error if TTY interface open */
38228 - if (info->port.count)
38229 + if (atomic_read(&info->port.count))
38230 return -EBUSY;
38231
38232 switch (encoding)
38233 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38234
38235 /* arbitrate between network and tty opens */
38236 spin_lock_irqsave(&info->netlock, flags);
38237 - if (info->port.count != 0 || info->netcount != 0) {
38238 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38239 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38240 spin_unlock_irqrestore(&info->netlock, flags);
38241 return -EBUSY;
38242 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38243 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
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 if (cmd != SIOCWANDEV)
38251 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38252 * do not request bottom half processing if the
38253 * device is not open in a normal mode.
38254 */
38255 - if ( port && (port->port.count || port->netcount) &&
38256 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38257 port->pending_bh && !port->bh_running &&
38258 !port->bh_requested ) {
38259 if ( debug_level >= DEBUG_LEVEL_ISR )
38260 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38261
38262 if (debug_level >= DEBUG_LEVEL_INFO)
38263 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38264 - __FILE__,__LINE__, tty->driver->name, port->count );
38265 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38266
38267 spin_lock_irqsave(&info->lock, flags);
38268 if (!tty_hung_up_p(filp)) {
38269 extra_count = true;
38270 - port->count--;
38271 + atomic_dec(&port->count);
38272 }
38273 spin_unlock_irqrestore(&info->lock, flags);
38274 port->blocked_open++;
38275 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38276
38277 if (debug_level >= DEBUG_LEVEL_INFO)
38278 printk("%s(%d):%s block_til_ready() count=%d\n",
38279 - __FILE__,__LINE__, tty->driver->name, port->count );
38280 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38281
38282 tty_unlock();
38283 schedule();
38284 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38285 remove_wait_queue(&port->open_wait, &wait);
38286
38287 if (extra_count)
38288 - port->count++;
38289 + atomic_inc(&port->count);
38290 port->blocked_open--;
38291
38292 if (debug_level >= DEBUG_LEVEL_INFO)
38293 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38294 - __FILE__,__LINE__, tty->driver->name, port->count );
38295 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38296
38297 if (!retval)
38298 port->flags |= ASYNC_NORMAL_ACTIVE;
38299 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38300 index 05728894..b9d44c6 100644
38301 --- a/drivers/tty/sysrq.c
38302 +++ b/drivers/tty/sysrq.c
38303 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38304 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38305 size_t count, loff_t *ppos)
38306 {
38307 - if (count) {
38308 + if (count && capable(CAP_SYS_ADMIN)) {
38309 char c;
38310
38311 if (get_user(c, buf))
38312 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38313 index b425c79..08a3f06 100644
38314 --- a/drivers/tty/tty_io.c
38315 +++ b/drivers/tty/tty_io.c
38316 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38317
38318 void tty_default_fops(struct file_operations *fops)
38319 {
38320 - *fops = tty_fops;
38321 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38322 }
38323
38324 /*
38325 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38326 index 9911eb6..5abe0e1 100644
38327 --- a/drivers/tty/tty_ldisc.c
38328 +++ b/drivers/tty/tty_ldisc.c
38329 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38330 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38331 struct tty_ldisc_ops *ldo = ld->ops;
38332
38333 - ldo->refcount--;
38334 + atomic_dec(&ldo->refcount);
38335 module_put(ldo->owner);
38336 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38337
38338 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38339 spin_lock_irqsave(&tty_ldisc_lock, flags);
38340 tty_ldiscs[disc] = new_ldisc;
38341 new_ldisc->num = disc;
38342 - new_ldisc->refcount = 0;
38343 + atomic_set(&new_ldisc->refcount, 0);
38344 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38345
38346 return ret;
38347 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38348 return -EINVAL;
38349
38350 spin_lock_irqsave(&tty_ldisc_lock, flags);
38351 - if (tty_ldiscs[disc]->refcount)
38352 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38353 ret = -EBUSY;
38354 else
38355 tty_ldiscs[disc] = NULL;
38356 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38357 if (ldops) {
38358 ret = ERR_PTR(-EAGAIN);
38359 if (try_module_get(ldops->owner)) {
38360 - ldops->refcount++;
38361 + atomic_inc(&ldops->refcount);
38362 ret = ldops;
38363 }
38364 }
38365 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38366 unsigned long flags;
38367
38368 spin_lock_irqsave(&tty_ldisc_lock, flags);
38369 - ldops->refcount--;
38370 + atomic_dec(&ldops->refcount);
38371 module_put(ldops->owner);
38372 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38373 }
38374 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38375 index bf6e238..d401c04 100644
38376 --- a/drivers/tty/tty_port.c
38377 +++ b/drivers/tty/tty_port.c
38378 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38379 unsigned long flags;
38380
38381 spin_lock_irqsave(&port->lock, flags);
38382 - port->count = 0;
38383 + atomic_set(&port->count, 0);
38384 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38385 if (port->tty) {
38386 set_bit(TTY_IO_ERROR, &port->tty->flags);
38387 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38388 /* The port lock protects the port counts */
38389 spin_lock_irqsave(&port->lock, flags);
38390 if (!tty_hung_up_p(filp))
38391 - port->count--;
38392 + atomic_dec(&port->count);
38393 port->blocked_open++;
38394 spin_unlock_irqrestore(&port->lock, flags);
38395
38396 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38397 we must not mess that up further */
38398 spin_lock_irqsave(&port->lock, flags);
38399 if (!tty_hung_up_p(filp))
38400 - port->count++;
38401 + atomic_inc(&port->count);
38402 port->blocked_open--;
38403 if (retval == 0)
38404 port->flags |= ASYNC_NORMAL_ACTIVE;
38405 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38406 return 0;
38407 }
38408
38409 - if (tty->count == 1 && port->count != 1) {
38410 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38411 printk(KERN_WARNING
38412 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38413 - port->count);
38414 - port->count = 1;
38415 + atomic_read(&port->count));
38416 + atomic_set(&port->count, 1);
38417 }
38418 - if (--port->count < 0) {
38419 + if (atomic_dec_return(&port->count) < 0) {
38420 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38421 - port->count);
38422 - port->count = 0;
38423 + atomic_read(&port->count));
38424 + atomic_set(&port->count, 0);
38425 }
38426
38427 - if (port->count) {
38428 + if (atomic_read(&port->count)) {
38429 spin_unlock_irqrestore(&port->lock, flags);
38430 if (port->ops->drop)
38431 port->ops->drop(port);
38432 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38433 {
38434 spin_lock_irq(&port->lock);
38435 if (!tty_hung_up_p(filp))
38436 - ++port->count;
38437 + atomic_inc(&port->count);
38438 spin_unlock_irq(&port->lock);
38439 tty_port_tty_set(port, tty);
38440
38441 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38442 index 48cc6f2..85584dd 100644
38443 --- a/drivers/tty/vt/keyboard.c
38444 +++ b/drivers/tty/vt/keyboard.c
38445 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38446 kbd->kbdmode == VC_OFF) &&
38447 value != KVAL(K_SAK))
38448 return; /* SAK is allowed even in raw mode */
38449 +
38450 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38451 + {
38452 + void *func = fn_handler[value];
38453 + if (func == fn_show_state || func == fn_show_ptregs ||
38454 + func == fn_show_mem)
38455 + return;
38456 + }
38457 +#endif
38458 +
38459 fn_handler[value](vc);
38460 }
38461
38462 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38463 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38464 return -EFAULT;
38465
38466 - if (!capable(CAP_SYS_TTY_CONFIG))
38467 - perm = 0;
38468 -
38469 switch (cmd) {
38470 case KDGKBENT:
38471 /* Ensure another thread doesn't free it under us */
38472 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38473 spin_unlock_irqrestore(&kbd_event_lock, flags);
38474 return put_user(val, &user_kbe->kb_value);
38475 case KDSKBENT:
38476 + if (!capable(CAP_SYS_TTY_CONFIG))
38477 + perm = 0;
38478 +
38479 if (!perm)
38480 return -EPERM;
38481 if (!i && v == K_NOSUCHMAP) {
38482 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38483 int i, j, k;
38484 int ret;
38485
38486 - if (!capable(CAP_SYS_TTY_CONFIG))
38487 - perm = 0;
38488 -
38489 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38490 if (!kbs) {
38491 ret = -ENOMEM;
38492 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38493 kfree(kbs);
38494 return ((p && *p) ? -EOVERFLOW : 0);
38495 case KDSKBSENT:
38496 + if (!capable(CAP_SYS_TTY_CONFIG))
38497 + perm = 0;
38498 +
38499 if (!perm) {
38500 ret = -EPERM;
38501 goto reterr;
38502 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38503 index a783d53..cb30d94 100644
38504 --- a/drivers/uio/uio.c
38505 +++ b/drivers/uio/uio.c
38506 @@ -25,6 +25,7 @@
38507 #include <linux/kobject.h>
38508 #include <linux/cdev.h>
38509 #include <linux/uio_driver.h>
38510 +#include <asm/local.h>
38511
38512 #define UIO_MAX_DEVICES (1U << MINORBITS)
38513
38514 @@ -32,10 +33,10 @@ struct uio_device {
38515 struct module *owner;
38516 struct device *dev;
38517 int minor;
38518 - atomic_t event;
38519 + atomic_unchecked_t event;
38520 struct fasync_struct *async_queue;
38521 wait_queue_head_t wait;
38522 - int vma_count;
38523 + local_t vma_count;
38524 struct uio_info *info;
38525 struct kobject *map_dir;
38526 struct kobject *portio_dir;
38527 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38528 struct device_attribute *attr, char *buf)
38529 {
38530 struct uio_device *idev = dev_get_drvdata(dev);
38531 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38532 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38533 }
38534
38535 static struct device_attribute uio_class_attributes[] = {
38536 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38537 {
38538 struct uio_device *idev = info->uio_dev;
38539
38540 - atomic_inc(&idev->event);
38541 + atomic_inc_unchecked(&idev->event);
38542 wake_up_interruptible(&idev->wait);
38543 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38544 }
38545 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38546 }
38547
38548 listener->dev = idev;
38549 - listener->event_count = atomic_read(&idev->event);
38550 + listener->event_count = atomic_read_unchecked(&idev->event);
38551 filep->private_data = listener;
38552
38553 if (idev->info->open) {
38554 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38555 return -EIO;
38556
38557 poll_wait(filep, &idev->wait, wait);
38558 - if (listener->event_count != atomic_read(&idev->event))
38559 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38560 return POLLIN | POLLRDNORM;
38561 return 0;
38562 }
38563 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38564 do {
38565 set_current_state(TASK_INTERRUPTIBLE);
38566
38567 - event_count = atomic_read(&idev->event);
38568 + event_count = atomic_read_unchecked(&idev->event);
38569 if (event_count != listener->event_count) {
38570 if (copy_to_user(buf, &event_count, count))
38571 retval = -EFAULT;
38572 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38573 static void uio_vma_open(struct vm_area_struct *vma)
38574 {
38575 struct uio_device *idev = vma->vm_private_data;
38576 - idev->vma_count++;
38577 + local_inc(&idev->vma_count);
38578 }
38579
38580 static void uio_vma_close(struct vm_area_struct *vma)
38581 {
38582 struct uio_device *idev = vma->vm_private_data;
38583 - idev->vma_count--;
38584 + local_dec(&idev->vma_count);
38585 }
38586
38587 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38588 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38589 idev->owner = owner;
38590 idev->info = info;
38591 init_waitqueue_head(&idev->wait);
38592 - atomic_set(&idev->event, 0);
38593 + atomic_set_unchecked(&idev->event, 0);
38594
38595 ret = uio_get_minor(idev);
38596 if (ret)
38597 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38598 index b7eb86a..36d28af 100644
38599 --- a/drivers/usb/atm/cxacru.c
38600 +++ b/drivers/usb/atm/cxacru.c
38601 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38602 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38603 if (ret < 2)
38604 return -EINVAL;
38605 - if (index < 0 || index > 0x7f)
38606 + if (index > 0x7f)
38607 return -EINVAL;
38608 pos += tmp;
38609
38610 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38611 index ee62b35..b663594 100644
38612 --- a/drivers/usb/atm/usbatm.c
38613 +++ b/drivers/usb/atm/usbatm.c
38614 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38615 if (printk_ratelimit())
38616 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38617 __func__, vpi, vci);
38618 - atomic_inc(&vcc->stats->rx_err);
38619 + atomic_inc_unchecked(&vcc->stats->rx_err);
38620 return;
38621 }
38622
38623 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38624 if (length > ATM_MAX_AAL5_PDU) {
38625 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38626 __func__, length, vcc);
38627 - atomic_inc(&vcc->stats->rx_err);
38628 + atomic_inc_unchecked(&vcc->stats->rx_err);
38629 goto out;
38630 }
38631
38632 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38633 if (sarb->len < pdu_length) {
38634 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38635 __func__, pdu_length, sarb->len, vcc);
38636 - atomic_inc(&vcc->stats->rx_err);
38637 + atomic_inc_unchecked(&vcc->stats->rx_err);
38638 goto out;
38639 }
38640
38641 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38642 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38643 __func__, vcc);
38644 - atomic_inc(&vcc->stats->rx_err);
38645 + atomic_inc_unchecked(&vcc->stats->rx_err);
38646 goto out;
38647 }
38648
38649 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38650 if (printk_ratelimit())
38651 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38652 __func__, length);
38653 - atomic_inc(&vcc->stats->rx_drop);
38654 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38655 goto out;
38656 }
38657
38658 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38659
38660 vcc->push(vcc, skb);
38661
38662 - atomic_inc(&vcc->stats->rx);
38663 + atomic_inc_unchecked(&vcc->stats->rx);
38664 out:
38665 skb_trim(sarb, 0);
38666 }
38667 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38668 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38669
38670 usbatm_pop(vcc, skb);
38671 - atomic_inc(&vcc->stats->tx);
38672 + atomic_inc_unchecked(&vcc->stats->tx);
38673
38674 skb = skb_dequeue(&instance->sndqueue);
38675 }
38676 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38677 if (!left--)
38678 return sprintf(page,
38679 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38680 - atomic_read(&atm_dev->stats.aal5.tx),
38681 - atomic_read(&atm_dev->stats.aal5.tx_err),
38682 - atomic_read(&atm_dev->stats.aal5.rx),
38683 - atomic_read(&atm_dev->stats.aal5.rx_err),
38684 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38685 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38686 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38687 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38688 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38689 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38690
38691 if (!left--) {
38692 if (instance->disconnected)
38693 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38694 index d956965..4179a77 100644
38695 --- a/drivers/usb/core/devices.c
38696 +++ b/drivers/usb/core/devices.c
38697 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38698 * time it gets called.
38699 */
38700 static struct device_connect_event {
38701 - atomic_t count;
38702 + atomic_unchecked_t count;
38703 wait_queue_head_t wait;
38704 } device_event = {
38705 .count = ATOMIC_INIT(1),
38706 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38707
38708 void usbfs_conn_disc_event(void)
38709 {
38710 - atomic_add(2, &device_event.count);
38711 + atomic_add_unchecked(2, &device_event.count);
38712 wake_up(&device_event.wait);
38713 }
38714
38715 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38716
38717 poll_wait(file, &device_event.wait, wait);
38718
38719 - event_count = atomic_read(&device_event.count);
38720 + event_count = atomic_read_unchecked(&device_event.count);
38721 if (file->f_version != event_count) {
38722 file->f_version = event_count;
38723 return POLLIN | POLLRDNORM;
38724 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38725 index 1fc8f12..20647c1 100644
38726 --- a/drivers/usb/early/ehci-dbgp.c
38727 +++ b/drivers/usb/early/ehci-dbgp.c
38728 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38729
38730 #ifdef CONFIG_KGDB
38731 static struct kgdb_io kgdbdbgp_io_ops;
38732 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38733 +static struct kgdb_io kgdbdbgp_io_ops_console;
38734 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38735 #else
38736 #define dbgp_kgdb_mode (0)
38737 #endif
38738 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38739 .write_char = kgdbdbgp_write_char,
38740 };
38741
38742 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38743 + .name = "kgdbdbgp",
38744 + .read_char = kgdbdbgp_read_char,
38745 + .write_char = kgdbdbgp_write_char,
38746 + .is_console = 1
38747 +};
38748 +
38749 static int kgdbdbgp_wait_time;
38750
38751 static int __init kgdbdbgp_parse_config(char *str)
38752 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38753 ptr++;
38754 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38755 }
38756 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38757 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38758 + if (early_dbgp_console.index != -1)
38759 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38760 + else
38761 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38762
38763 return 0;
38764 }
38765 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38766 index 5b3f5ff..6e00893 100644
38767 --- a/drivers/usb/gadget/u_serial.c
38768 +++ b/drivers/usb/gadget/u_serial.c
38769 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38770 spin_lock_irq(&port->port_lock);
38771
38772 /* already open? Great. */
38773 - if (port->port.count) {
38774 + if (atomic_read(&port->port.count)) {
38775 status = 0;
38776 - port->port.count++;
38777 + atomic_inc(&port->port.count);
38778
38779 /* currently opening/closing? wait ... */
38780 } else if (port->openclose) {
38781 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38782 tty->driver_data = port;
38783 port->port.tty = tty;
38784
38785 - port->port.count = 1;
38786 + atomic_set(&port->port.count, 1);
38787 port->openclose = false;
38788
38789 /* if connected, start the I/O stream */
38790 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38791
38792 spin_lock_irq(&port->port_lock);
38793
38794 - if (port->port.count != 1) {
38795 - if (port->port.count == 0)
38796 + if (atomic_read(&port->port.count) != 1) {
38797 + if (atomic_read(&port->port.count) == 0)
38798 WARN_ON(1);
38799 else
38800 - --port->port.count;
38801 + atomic_dec(&port->port.count);
38802 goto exit;
38803 }
38804
38805 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38806 * and sleep if necessary
38807 */
38808 port->openclose = true;
38809 - port->port.count = 0;
38810 + atomic_set(&port->port.count, 0);
38811
38812 gser = port->port_usb;
38813 if (gser && gser->disconnect)
38814 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38815 int cond;
38816
38817 spin_lock_irq(&port->port_lock);
38818 - cond = (port->port.count == 0) && !port->openclose;
38819 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38820 spin_unlock_irq(&port->port_lock);
38821 return cond;
38822 }
38823 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38824 /* if it's already open, start I/O ... and notify the serial
38825 * protocol about open/close status (connect/disconnect).
38826 */
38827 - if (port->port.count) {
38828 + if (atomic_read(&port->port.count)) {
38829 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38830 gs_start_io(port);
38831 if (gser->connect)
38832 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38833
38834 port->port_usb = NULL;
38835 gser->ioport = NULL;
38836 - if (port->port.count > 0 || port->openclose) {
38837 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
38838 wake_up_interruptible(&port->drain_wait);
38839 if (port->port.tty)
38840 tty_hangup(port->port.tty);
38841 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38842
38843 /* finally, free any unused/unusable I/O buffers */
38844 spin_lock_irqsave(&port->port_lock, flags);
38845 - if (port->port.count == 0 && !port->openclose)
38846 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
38847 gs_buf_free(&port->port_write_buf);
38848 gs_free_requests(gser->out, &port->read_pool, NULL);
38849 gs_free_requests(gser->out, &port->read_queue, NULL);
38850 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38851 index b9cca6d..75c75df 100644
38852 --- a/drivers/usb/serial/console.c
38853 +++ b/drivers/usb/serial/console.c
38854 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38855
38856 info->port = port;
38857
38858 - ++port->port.count;
38859 + atomic_inc(&port->port.count);
38860 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38861 if (serial->type->set_termios) {
38862 /*
38863 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38864 }
38865 /* Now that any required fake tty operations are completed restore
38866 * the tty port count */
38867 - --port->port.count;
38868 + atomic_dec(&port->port.count);
38869 /* The console is special in terms of closing the device so
38870 * indicate this port is now acting as a system console. */
38871 port->port.console = 1;
38872 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38873 free_tty:
38874 kfree(tty);
38875 reset_open_count:
38876 - port->port.count = 0;
38877 + atomic_set(&port->port.count, 0);
38878 usb_autopm_put_interface(serial->interface);
38879 error_get_interface:
38880 usb_serial_put(serial);
38881 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38882 index d6bea3e..60b250e 100644
38883 --- a/drivers/usb/wusbcore/wa-hc.h
38884 +++ b/drivers/usb/wusbcore/wa-hc.h
38885 @@ -192,7 +192,7 @@ struct wahc {
38886 struct list_head xfer_delayed_list;
38887 spinlock_t xfer_list_lock;
38888 struct work_struct xfer_work;
38889 - atomic_t xfer_id_count;
38890 + atomic_unchecked_t xfer_id_count;
38891 };
38892
38893
38894 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38895 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38896 spin_lock_init(&wa->xfer_list_lock);
38897 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38898 - atomic_set(&wa->xfer_id_count, 1);
38899 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38900 }
38901
38902 /**
38903 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38904 index 57c01ab..8a05959 100644
38905 --- a/drivers/usb/wusbcore/wa-xfer.c
38906 +++ b/drivers/usb/wusbcore/wa-xfer.c
38907 @@ -296,7 +296,7 @@ out:
38908 */
38909 static void wa_xfer_id_init(struct wa_xfer *xfer)
38910 {
38911 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38912 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38913 }
38914
38915 /*
38916 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38917 index 112156f..eb81154 100644
38918 --- a/drivers/vhost/vhost.c
38919 +++ b/drivers/vhost/vhost.c
38920 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38921 return 0;
38922 }
38923
38924 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38925 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38926 {
38927 struct file *eventfp, *filep = NULL,
38928 *pollstart = NULL, *pollstop = NULL;
38929 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38930 index b0b2ac3..89a4399 100644
38931 --- a/drivers/video/aty/aty128fb.c
38932 +++ b/drivers/video/aty/aty128fb.c
38933 @@ -148,7 +148,7 @@ enum {
38934 };
38935
38936 /* Must match above enum */
38937 -static const char *r128_family[] __devinitdata = {
38938 +static const char *r128_family[] __devinitconst = {
38939 "AGP",
38940 "PCI",
38941 "PRO AGP",
38942 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38943 index 5c3960d..15cf8fc 100644
38944 --- a/drivers/video/fbcmap.c
38945 +++ b/drivers/video/fbcmap.c
38946 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38947 rc = -ENODEV;
38948 goto out;
38949 }
38950 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38951 - !info->fbops->fb_setcmap)) {
38952 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38953 rc = -EINVAL;
38954 goto out1;
38955 }
38956 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38957 index 0dff12a..2ef47b3 100644
38958 --- a/drivers/video/fbmem.c
38959 +++ b/drivers/video/fbmem.c
38960 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38961 image->dx += image->width + 8;
38962 }
38963 } else if (rotate == FB_ROTATE_UD) {
38964 - for (x = 0; x < num && image->dx >= 0; x++) {
38965 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38966 info->fbops->fb_imageblit(info, image);
38967 image->dx -= image->width + 8;
38968 }
38969 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38970 image->dy += image->height + 8;
38971 }
38972 } else if (rotate == FB_ROTATE_CCW) {
38973 - for (x = 0; x < num && image->dy >= 0; x++) {
38974 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38975 info->fbops->fb_imageblit(info, image);
38976 image->dy -= image->height + 8;
38977 }
38978 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38979 return -EFAULT;
38980 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38981 return -EINVAL;
38982 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38983 + if (con2fb.framebuffer >= FB_MAX)
38984 return -EINVAL;
38985 if (!registered_fb[con2fb.framebuffer])
38986 request_module("fb%d", con2fb.framebuffer);
38987 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38988 index 5a5d092..265c5ed 100644
38989 --- a/drivers/video/geode/gx1fb_core.c
38990 +++ b/drivers/video/geode/gx1fb_core.c
38991 @@ -29,7 +29,7 @@ static int crt_option = 1;
38992 static char panel_option[32] = "";
38993
38994 /* Modes relevant to the GX1 (taken from modedb.c) */
38995 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38996 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38997 /* 640x480-60 VESA */
38998 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38999 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39000 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39001 index 0fad23f..0e9afa4 100644
39002 --- a/drivers/video/gxt4500.c
39003 +++ b/drivers/video/gxt4500.c
39004 @@ -156,7 +156,7 @@ struct gxt4500_par {
39005 static char *mode_option;
39006
39007 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39008 -static const struct fb_videomode defaultmode __devinitdata = {
39009 +static const struct fb_videomode defaultmode __devinitconst = {
39010 .refresh = 60,
39011 .xres = 1280,
39012 .yres = 1024,
39013 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39014 return 0;
39015 }
39016
39017 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39018 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39019 .id = "IBM GXT4500P",
39020 .type = FB_TYPE_PACKED_PIXELS,
39021 .visual = FB_VISUAL_PSEUDOCOLOR,
39022 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39023 index 7672d2e..b56437f 100644
39024 --- a/drivers/video/i810/i810_accel.c
39025 +++ b/drivers/video/i810/i810_accel.c
39026 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39027 }
39028 }
39029 printk("ringbuffer lockup!!!\n");
39030 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39031 i810_report_error(mmio);
39032 par->dev_flags |= LOCKUP;
39033 info->pixmap.scan_align = 1;
39034 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39035 index b83f361..2b05a91 100644
39036 --- a/drivers/video/i810/i810_main.c
39037 +++ b/drivers/video/i810/i810_main.c
39038 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39039 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39040
39041 /* PCI */
39042 -static const char *i810_pci_list[] __devinitdata = {
39043 +static const char *i810_pci_list[] __devinitconst = {
39044 "Intel(R) 810 Framebuffer Device" ,
39045 "Intel(R) 810-DC100 Framebuffer Device" ,
39046 "Intel(R) 810E Framebuffer Device" ,
39047 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39048 index de36693..3c63fc2 100644
39049 --- a/drivers/video/jz4740_fb.c
39050 +++ b/drivers/video/jz4740_fb.c
39051 @@ -136,7 +136,7 @@ struct jzfb {
39052 uint32_t pseudo_palette[16];
39053 };
39054
39055 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39056 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39057 .id = "JZ4740 FB",
39058 .type = FB_TYPE_PACKED_PIXELS,
39059 .visual = FB_VISUAL_TRUECOLOR,
39060 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39061 index 3c14e43..eafa544 100644
39062 --- a/drivers/video/logo/logo_linux_clut224.ppm
39063 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39064 @@ -1,1604 +1,1123 @@
39065 P3
39066 -# Standard 224-color Linux logo
39067 80 80
39068 255
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 0 0 0 0
39071 - 0 0 0 0 0 0 0 0 0 0 0 0
39072 - 0 0 0 0 0 0 0 0 0 0 0 0
39073 - 0 0 0 0 0 0 0 0 0 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 6 6 6 6 6 6 10 10 10 10 10 10
39079 - 10 10 10 6 6 6 6 6 6 6 6 6
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 0 0 0
39091 - 0 0 0 0 0 0 0 0 0 0 0 0
39092 - 0 0 0 0 0 0 0 0 0 0 0 0
39093 - 0 0 0 0 0 0 0 0 0 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 0 0 0
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 0 0 0
39097 - 0 0 0 6 6 6 10 10 10 14 14 14
39098 - 22 22 22 26 26 26 30 30 30 34 34 34
39099 - 30 30 30 30 30 30 26 26 26 18 18 18
39100 - 14 14 14 10 10 10 6 6 6 0 0 0
39101 - 0 0 0 0 0 0 0 0 0 0 0 0
39102 - 0 0 0 0 0 0 0 0 0 0 0 0
39103 - 0 0 0 0 0 0 0 0 0 0 0 0
39104 - 0 0 0 0 0 0 0 0 0 0 0 0
39105 - 0 0 0 0 0 0 0 0 0 0 0 0
39106 - 0 0 0 0 0 0 0 0 0 0 0 0
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 1 0 0 1 0 0 0
39111 - 0 0 0 0 0 0 0 0 0 0 0 0
39112 - 0 0 0 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 6 6 6 14 14 14 26 26 26 42 42 42
39118 - 54 54 54 66 66 66 78 78 78 78 78 78
39119 - 78 78 78 74 74 74 66 66 66 54 54 54
39120 - 42 42 42 26 26 26 18 18 18 10 10 10
39121 - 6 6 6 0 0 0 0 0 0 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 0 0 0
39123 - 0 0 0 0 0 0 0 0 0 0 0 0
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 1 0 0 0 0 0 0 0 0 0
39131 - 0 0 0 0 0 0 0 0 0 0 0 0
39132 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 10 10 10
39137 - 22 22 22 42 42 42 66 66 66 86 86 86
39138 - 66 66 66 38 38 38 38 38 38 22 22 22
39139 - 26 26 26 34 34 34 54 54 54 66 66 66
39140 - 86 86 86 70 70 70 46 46 46 26 26 26
39141 - 14 14 14 6 6 6 0 0 0 0 0 0
39142 - 0 0 0 0 0 0 0 0 0 0 0 0
39143 - 0 0 0 0 0 0 0 0 0 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 0 0 0
39150 - 0 0 1 0 0 1 0 0 1 0 0 0
39151 - 0 0 0 0 0 0 0 0 0 0 0 0
39152 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 10 10 10 26 26 26
39157 - 50 50 50 82 82 82 58 58 58 6 6 6
39158 - 2 2 6 2 2 6 2 2 6 2 2 6
39159 - 2 2 6 2 2 6 2 2 6 2 2 6
39160 - 6 6 6 54 54 54 86 86 86 66 66 66
39161 - 38 38 38 18 18 18 6 6 6 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 6 6 6 22 22 22 50 50 50
39177 - 78 78 78 34 34 34 2 2 6 2 2 6
39178 - 2 2 6 2 2 6 2 2 6 2 2 6
39179 - 2 2 6 2 2 6 2 2 6 2 2 6
39180 - 2 2 6 2 2 6 6 6 6 70 70 70
39181 - 78 78 78 46 46 46 22 22 22 6 6 6
39182 - 0 0 0 0 0 0 0 0 0 0 0 0
39183 - 0 0 0 0 0 0 0 0 0 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 1 0 0 1 0 0 1 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 0 0 0 0 0 0 0
39196 - 6 6 6 18 18 18 42 42 42 82 82 82
39197 - 26 26 26 2 2 6 2 2 6 2 2 6
39198 - 2 2 6 2 2 6 2 2 6 2 2 6
39199 - 2 2 6 2 2 6 2 2 6 14 14 14
39200 - 46 46 46 34 34 34 6 6 6 2 2 6
39201 - 42 42 42 78 78 78 42 42 42 18 18 18
39202 - 6 6 6 0 0 0 0 0 0 0 0 0
39203 - 0 0 0 0 0 0 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 1 0 0 0 0 0 1 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 0 0 0 0 0 0 0 0 0 0
39216 - 10 10 10 30 30 30 66 66 66 58 58 58
39217 - 2 2 6 2 2 6 2 2 6 2 2 6
39218 - 2 2 6 2 2 6 2 2 6 2 2 6
39219 - 2 2 6 2 2 6 2 2 6 26 26 26
39220 - 86 86 86 101 101 101 46 46 46 10 10 10
39221 - 2 2 6 58 58 58 70 70 70 34 34 34
39222 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39237 - 2 2 6 2 2 6 2 2 6 2 2 6
39238 - 2 2 6 2 2 6 2 2 6 2 2 6
39239 - 2 2 6 2 2 6 2 2 6 30 30 30
39240 - 94 94 94 94 94 94 58 58 58 26 26 26
39241 - 2 2 6 6 6 6 78 78 78 54 54 54
39242 - 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 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 6 6 6
39256 - 22 22 22 62 62 62 62 62 62 2 2 6
39257 - 2 2 6 2 2 6 2 2 6 2 2 6
39258 - 2 2 6 2 2 6 2 2 6 2 2 6
39259 - 2 2 6 2 2 6 2 2 6 26 26 26
39260 - 54 54 54 38 38 38 18 18 18 10 10 10
39261 - 2 2 6 2 2 6 34 34 34 82 82 82
39262 - 38 38 38 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 1 0 0 1 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 6 6 6
39276 - 30 30 30 78 78 78 30 30 30 2 2 6
39277 - 2 2 6 2 2 6 2 2 6 2 2 6
39278 - 2 2 6 2 2 6 2 2 6 2 2 6
39279 - 2 2 6 2 2 6 2 2 6 10 10 10
39280 - 10 10 10 2 2 6 2 2 6 2 2 6
39281 - 2 2 6 2 2 6 2 2 6 78 78 78
39282 - 50 50 50 18 18 18 6 6 6 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 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 1 0 0 0 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 10 10 10
39296 - 38 38 38 86 86 86 14 14 14 2 2 6
39297 - 2 2 6 2 2 6 2 2 6 2 2 6
39298 - 2 2 6 2 2 6 2 2 6 2 2 6
39299 - 2 2 6 2 2 6 2 2 6 2 2 6
39300 - 2 2 6 2 2 6 2 2 6 2 2 6
39301 - 2 2 6 2 2 6 2 2 6 54 54 54
39302 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 1 0 0 1 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 14 14 14
39316 - 42 42 42 82 82 82 2 2 6 2 2 6
39317 - 2 2 6 6 6 6 10 10 10 2 2 6
39318 - 2 2 6 2 2 6 2 2 6 2 2 6
39319 - 2 2 6 2 2 6 2 2 6 6 6 6
39320 - 14 14 14 10 10 10 2 2 6 2 2 6
39321 - 2 2 6 2 2 6 2 2 6 18 18 18
39322 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 1 0 0 0 0 0 0 0 0 0
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 14 14 14
39336 - 46 46 46 86 86 86 2 2 6 2 2 6
39337 - 6 6 6 6 6 6 22 22 22 34 34 34
39338 - 6 6 6 2 2 6 2 2 6 2 2 6
39339 - 2 2 6 2 2 6 18 18 18 34 34 34
39340 - 10 10 10 50 50 50 22 22 22 2 2 6
39341 - 2 2 6 2 2 6 2 2 6 10 10 10
39342 - 86 86 86 42 42 42 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 1 0 0 1 0 0 1 0 0 0
39351 - 0 0 0 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 14 14 14
39356 - 46 46 46 86 86 86 2 2 6 2 2 6
39357 - 38 38 38 116 116 116 94 94 94 22 22 22
39358 - 22 22 22 2 2 6 2 2 6 2 2 6
39359 - 14 14 14 86 86 86 138 138 138 162 162 162
39360 -154 154 154 38 38 38 26 26 26 6 6 6
39361 - 2 2 6 2 2 6 2 2 6 2 2 6
39362 - 86 86 86 46 46 46 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 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 14 14 14
39376 - 46 46 46 86 86 86 2 2 6 14 14 14
39377 -134 134 134 198 198 198 195 195 195 116 116 116
39378 - 10 10 10 2 2 6 2 2 6 6 6 6
39379 -101 98 89 187 187 187 210 210 210 218 218 218
39380 -214 214 214 134 134 134 14 14 14 6 6 6
39381 - 2 2 6 2 2 6 2 2 6 2 2 6
39382 - 86 86 86 50 50 50 18 18 18 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 1 0 0 0
39390 - 0 0 1 0 0 1 0 0 1 0 0 0
39391 - 0 0 0 0 0 0 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 14 14 14
39396 - 46 46 46 86 86 86 2 2 6 54 54 54
39397 -218 218 218 195 195 195 226 226 226 246 246 246
39398 - 58 58 58 2 2 6 2 2 6 30 30 30
39399 -210 210 210 253 253 253 174 174 174 123 123 123
39400 -221 221 221 234 234 234 74 74 74 2 2 6
39401 - 2 2 6 2 2 6 2 2 6 2 2 6
39402 - 70 70 70 58 58 58 22 22 22 6 6 6
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 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 14 14 14
39416 - 46 46 46 82 82 82 2 2 6 106 106 106
39417 -170 170 170 26 26 26 86 86 86 226 226 226
39418 -123 123 123 10 10 10 14 14 14 46 46 46
39419 -231 231 231 190 190 190 6 6 6 70 70 70
39420 - 90 90 90 238 238 238 158 158 158 2 2 6
39421 - 2 2 6 2 2 6 2 2 6 2 2 6
39422 - 70 70 70 58 58 58 22 22 22 6 6 6
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 0 0 0
39429 - 0 0 0 0 0 0 0 0 1 0 0 0
39430 - 0 0 1 0 0 1 0 0 1 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39436 - 42 42 42 86 86 86 6 6 6 116 116 116
39437 -106 106 106 6 6 6 70 70 70 149 149 149
39438 -128 128 128 18 18 18 38 38 38 54 54 54
39439 -221 221 221 106 106 106 2 2 6 14 14 14
39440 - 46 46 46 190 190 190 198 198 198 2 2 6
39441 - 2 2 6 2 2 6 2 2 6 2 2 6
39442 - 74 74 74 62 62 62 22 22 22 6 6 6
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 1 0 0 0
39450 - 0 0 1 0 0 0 0 0 1 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39456 - 42 42 42 94 94 94 14 14 14 101 101 101
39457 -128 128 128 2 2 6 18 18 18 116 116 116
39458 -118 98 46 121 92 8 121 92 8 98 78 10
39459 -162 162 162 106 106 106 2 2 6 2 2 6
39460 - 2 2 6 195 195 195 195 195 195 6 6 6
39461 - 2 2 6 2 2 6 2 2 6 2 2 6
39462 - 74 74 74 62 62 62 22 22 22 6 6 6
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 0 0 0 0
39469 - 0 0 0 0 0 0 0 0 1 0 0 1
39470 - 0 0 1 0 0 0 0 0 1 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39476 - 38 38 38 90 90 90 14 14 14 58 58 58
39477 -210 210 210 26 26 26 54 38 6 154 114 10
39478 -226 170 11 236 186 11 225 175 15 184 144 12
39479 -215 174 15 175 146 61 37 26 9 2 2 6
39480 - 70 70 70 246 246 246 138 138 138 2 2 6
39481 - 2 2 6 2 2 6 2 2 6 2 2 6
39482 - 70 70 70 66 66 66 26 26 26 6 6 6
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 0 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39496 - 38 38 38 86 86 86 14 14 14 10 10 10
39497 -195 195 195 188 164 115 192 133 9 225 175 15
39498 -239 182 13 234 190 10 232 195 16 232 200 30
39499 -245 207 45 241 208 19 232 195 16 184 144 12
39500 -218 194 134 211 206 186 42 42 42 2 2 6
39501 - 2 2 6 2 2 6 2 2 6 2 2 6
39502 - 50 50 50 74 74 74 30 30 30 6 6 6
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 0 0 0 0 0 0 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39516 - 34 34 34 86 86 86 14 14 14 2 2 6
39517 -121 87 25 192 133 9 219 162 10 239 182 13
39518 -236 186 11 232 195 16 241 208 19 244 214 54
39519 -246 218 60 246 218 38 246 215 20 241 208 19
39520 -241 208 19 226 184 13 121 87 25 2 2 6
39521 - 2 2 6 2 2 6 2 2 6 2 2 6
39522 - 50 50 50 82 82 82 34 34 34 10 10 10
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39536 - 34 34 34 82 82 82 30 30 30 61 42 6
39537 -180 123 7 206 145 10 230 174 11 239 182 13
39538 -234 190 10 238 202 15 241 208 19 246 218 74
39539 -246 218 38 246 215 20 246 215 20 246 215 20
39540 -226 184 13 215 174 15 184 144 12 6 6 6
39541 - 2 2 6 2 2 6 2 2 6 2 2 6
39542 - 26 26 26 94 94 94 42 42 42 14 14 14
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39556 - 30 30 30 78 78 78 50 50 50 104 69 6
39557 -192 133 9 216 158 10 236 178 12 236 186 11
39558 -232 195 16 241 208 19 244 214 54 245 215 43
39559 -246 215 20 246 215 20 241 208 19 198 155 10
39560 -200 144 11 216 158 10 156 118 10 2 2 6
39561 - 2 2 6 2 2 6 2 2 6 2 2 6
39562 - 6 6 6 90 90 90 54 54 54 18 18 18
39563 - 6 6 6 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39576 - 30 30 30 78 78 78 46 46 46 22 22 22
39577 -137 92 6 210 162 10 239 182 13 238 190 10
39578 -238 202 15 241 208 19 246 215 20 246 215 20
39579 -241 208 19 203 166 17 185 133 11 210 150 10
39580 -216 158 10 210 150 10 102 78 10 2 2 6
39581 - 6 6 6 54 54 54 14 14 14 2 2 6
39582 - 2 2 6 62 62 62 74 74 74 30 30 30
39583 - 10 10 10 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39596 - 34 34 34 78 78 78 50 50 50 6 6 6
39597 - 94 70 30 139 102 15 190 146 13 226 184 13
39598 -232 200 30 232 195 16 215 174 15 190 146 13
39599 -168 122 10 192 133 9 210 150 10 213 154 11
39600 -202 150 34 182 157 106 101 98 89 2 2 6
39601 - 2 2 6 78 78 78 116 116 116 58 58 58
39602 - 2 2 6 22 22 22 90 90 90 46 46 46
39603 - 18 18 18 6 6 6 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39616 - 38 38 38 86 86 86 50 50 50 6 6 6
39617 -128 128 128 174 154 114 156 107 11 168 122 10
39618 -198 155 10 184 144 12 197 138 11 200 144 11
39619 -206 145 10 206 145 10 197 138 11 188 164 115
39620 -195 195 195 198 198 198 174 174 174 14 14 14
39621 - 2 2 6 22 22 22 116 116 116 116 116 116
39622 - 22 22 22 2 2 6 74 74 74 70 70 70
39623 - 30 30 30 10 10 10 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
39636 - 50 50 50 101 101 101 26 26 26 10 10 10
39637 -138 138 138 190 190 190 174 154 114 156 107 11
39638 -197 138 11 200 144 11 197 138 11 192 133 9
39639 -180 123 7 190 142 34 190 178 144 187 187 187
39640 -202 202 202 221 221 221 214 214 214 66 66 66
39641 - 2 2 6 2 2 6 50 50 50 62 62 62
39642 - 6 6 6 2 2 6 10 10 10 90 90 90
39643 - 50 50 50 18 18 18 6 6 6 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
39656 - 74 74 74 74 74 74 2 2 6 6 6 6
39657 -144 144 144 198 198 198 190 190 190 178 166 146
39658 -154 121 60 156 107 11 156 107 11 168 124 44
39659 -174 154 114 187 187 187 190 190 190 210 210 210
39660 -246 246 246 253 253 253 253 253 253 182 182 182
39661 - 6 6 6 2 2 6 2 2 6 2 2 6
39662 - 2 2 6 2 2 6 2 2 6 62 62 62
39663 - 74 74 74 34 34 34 14 14 14 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 22 22 22 54 54 54
39676 - 94 94 94 18 18 18 2 2 6 46 46 46
39677 -234 234 234 221 221 221 190 190 190 190 190 190
39678 -190 190 190 187 187 187 187 187 187 190 190 190
39679 -190 190 190 195 195 195 214 214 214 242 242 242
39680 -253 253 253 253 253 253 253 253 253 253 253 253
39681 - 82 82 82 2 2 6 2 2 6 2 2 6
39682 - 2 2 6 2 2 6 2 2 6 14 14 14
39683 - 86 86 86 54 54 54 22 22 22 6 6 6
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 6 6 6 18 18 18 46 46 46 90 90 90
39696 - 46 46 46 18 18 18 6 6 6 182 182 182
39697 -253 253 253 246 246 246 206 206 206 190 190 190
39698 -190 190 190 190 190 190 190 190 190 190 190 190
39699 -206 206 206 231 231 231 250 250 250 253 253 253
39700 -253 253 253 253 253 253 253 253 253 253 253 253
39701 -202 202 202 14 14 14 2 2 6 2 2 6
39702 - 2 2 6 2 2 6 2 2 6 2 2 6
39703 - 42 42 42 86 86 86 42 42 42 18 18 18
39704 - 6 6 6 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 6 6 6
39715 - 14 14 14 38 38 38 74 74 74 66 66 66
39716 - 2 2 6 6 6 6 90 90 90 250 250 250
39717 -253 253 253 253 253 253 238 238 238 198 198 198
39718 -190 190 190 190 190 190 195 195 195 221 221 221
39719 -246 246 246 253 253 253 253 253 253 253 253 253
39720 -253 253 253 253 253 253 253 253 253 253 253 253
39721 -253 253 253 82 82 82 2 2 6 2 2 6
39722 - 2 2 6 2 2 6 2 2 6 2 2 6
39723 - 2 2 6 78 78 78 70 70 70 34 34 34
39724 - 14 14 14 6 6 6 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 14 14 14
39735 - 34 34 34 66 66 66 78 78 78 6 6 6
39736 - 2 2 6 18 18 18 218 218 218 253 253 253
39737 -253 253 253 253 253 253 253 253 253 246 246 246
39738 -226 226 226 231 231 231 246 246 246 253 253 253
39739 -253 253 253 253 253 253 253 253 253 253 253 253
39740 -253 253 253 253 253 253 253 253 253 253 253 253
39741 -253 253 253 178 178 178 2 2 6 2 2 6
39742 - 2 2 6 2 2 6 2 2 6 2 2 6
39743 - 2 2 6 18 18 18 90 90 90 62 62 62
39744 - 30 30 30 10 10 10 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 10 10 10 26 26 26
39755 - 58 58 58 90 90 90 18 18 18 2 2 6
39756 - 2 2 6 110 110 110 253 253 253 253 253 253
39757 -253 253 253 253 253 253 253 253 253 253 253 253
39758 -250 250 250 253 253 253 253 253 253 253 253 253
39759 -253 253 253 253 253 253 253 253 253 253 253 253
39760 -253 253 253 253 253 253 253 253 253 253 253 253
39761 -253 253 253 231 231 231 18 18 18 2 2 6
39762 - 2 2 6 2 2 6 2 2 6 2 2 6
39763 - 2 2 6 2 2 6 18 18 18 94 94 94
39764 - 54 54 54 26 26 26 10 10 10 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 6 6 6 22 22 22 50 50 50
39775 - 90 90 90 26 26 26 2 2 6 2 2 6
39776 - 14 14 14 195 195 195 250 250 250 253 253 253
39777 -253 253 253 253 253 253 253 253 253 253 253 253
39778 -253 253 253 253 253 253 253 253 253 253 253 253
39779 -253 253 253 253 253 253 253 253 253 253 253 253
39780 -253 253 253 253 253 253 253 253 253 253 253 253
39781 -250 250 250 242 242 242 54 54 54 2 2 6
39782 - 2 2 6 2 2 6 2 2 6 2 2 6
39783 - 2 2 6 2 2 6 2 2 6 38 38 38
39784 - 86 86 86 50 50 50 22 22 22 6 6 6
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 6 6 6 14 14 14 38 38 38 82 82 82
39795 - 34 34 34 2 2 6 2 2 6 2 2 6
39796 - 42 42 42 195 195 195 246 246 246 253 253 253
39797 -253 253 253 253 253 253 253 253 253 250 250 250
39798 -242 242 242 242 242 242 250 250 250 253 253 253
39799 -253 253 253 253 253 253 253 253 253 253 253 253
39800 -253 253 253 250 250 250 246 246 246 238 238 238
39801 -226 226 226 231 231 231 101 101 101 6 6 6
39802 - 2 2 6 2 2 6 2 2 6 2 2 6
39803 - 2 2 6 2 2 6 2 2 6 2 2 6
39804 - 38 38 38 82 82 82 42 42 42 14 14 14
39805 - 6 6 6 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 10 10 10 26 26 26 62 62 62 66 66 66
39815 - 2 2 6 2 2 6 2 2 6 6 6 6
39816 - 70 70 70 170 170 170 206 206 206 234 234 234
39817 -246 246 246 250 250 250 250 250 250 238 238 238
39818 -226 226 226 231 231 231 238 238 238 250 250 250
39819 -250 250 250 250 250 250 246 246 246 231 231 231
39820 -214 214 214 206 206 206 202 202 202 202 202 202
39821 -198 198 198 202 202 202 182 182 182 18 18 18
39822 - 2 2 6 2 2 6 2 2 6 2 2 6
39823 - 2 2 6 2 2 6 2 2 6 2 2 6
39824 - 2 2 6 62 62 62 66 66 66 30 30 30
39825 - 10 10 10 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 14 14 14 42 42 42 82 82 82 18 18 18
39835 - 2 2 6 2 2 6 2 2 6 10 10 10
39836 - 94 94 94 182 182 182 218 218 218 242 242 242
39837 -250 250 250 253 253 253 253 253 253 250 250 250
39838 -234 234 234 253 253 253 253 253 253 253 253 253
39839 -253 253 253 253 253 253 253 253 253 246 246 246
39840 -238 238 238 226 226 226 210 210 210 202 202 202
39841 -195 195 195 195 195 195 210 210 210 158 158 158
39842 - 6 6 6 14 14 14 50 50 50 14 14 14
39843 - 2 2 6 2 2 6 2 2 6 2 2 6
39844 - 2 2 6 6 6 6 86 86 86 46 46 46
39845 - 18 18 18 6 6 6 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 6 6 6
39854 - 22 22 22 54 54 54 70 70 70 2 2 6
39855 - 2 2 6 10 10 10 2 2 6 22 22 22
39856 -166 166 166 231 231 231 250 250 250 253 253 253
39857 -253 253 253 253 253 253 253 253 253 250 250 250
39858 -242 242 242 253 253 253 253 253 253 253 253 253
39859 -253 253 253 253 253 253 253 253 253 253 253 253
39860 -253 253 253 253 253 253 253 253 253 246 246 246
39861 -231 231 231 206 206 206 198 198 198 226 226 226
39862 - 94 94 94 2 2 6 6 6 6 38 38 38
39863 - 30 30 30 2 2 6 2 2 6 2 2 6
39864 - 2 2 6 2 2 6 62 62 62 66 66 66
39865 - 26 26 26 10 10 10 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 10 10 10
39874 - 30 30 30 74 74 74 50 50 50 2 2 6
39875 - 26 26 26 26 26 26 2 2 6 106 106 106
39876 -238 238 238 253 253 253 253 253 253 253 253 253
39877 -253 253 253 253 253 253 253 253 253 253 253 253
39878 -253 253 253 253 253 253 253 253 253 253 253 253
39879 -253 253 253 253 253 253 253 253 253 253 253 253
39880 -253 253 253 253 253 253 253 253 253 253 253 253
39881 -253 253 253 246 246 246 218 218 218 202 202 202
39882 -210 210 210 14 14 14 2 2 6 2 2 6
39883 - 30 30 30 22 22 22 2 2 6 2 2 6
39884 - 2 2 6 2 2 6 18 18 18 86 86 86
39885 - 42 42 42 14 14 14 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 14 14 14
39894 - 42 42 42 90 90 90 22 22 22 2 2 6
39895 - 42 42 42 2 2 6 18 18 18 218 218 218
39896 -253 253 253 253 253 253 253 253 253 253 253 253
39897 -253 253 253 253 253 253 253 253 253 253 253 253
39898 -253 253 253 253 253 253 253 253 253 253 253 253
39899 -253 253 253 253 253 253 253 253 253 253 253 253
39900 -253 253 253 253 253 253 253 253 253 253 253 253
39901 -253 253 253 253 253 253 250 250 250 221 221 221
39902 -218 218 218 101 101 101 2 2 6 14 14 14
39903 - 18 18 18 38 38 38 10 10 10 2 2 6
39904 - 2 2 6 2 2 6 2 2 6 78 78 78
39905 - 58 58 58 22 22 22 6 6 6 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 6 6 6 18 18 18
39914 - 54 54 54 82 82 82 2 2 6 26 26 26
39915 - 22 22 22 2 2 6 123 123 123 253 253 253
39916 -253 253 253 253 253 253 253 253 253 253 253 253
39917 -253 253 253 253 253 253 253 253 253 253 253 253
39918 -253 253 253 253 253 253 253 253 253 253 253 253
39919 -253 253 253 253 253 253 253 253 253 253 253 253
39920 -253 253 253 253 253 253 253 253 253 253 253 253
39921 -253 253 253 253 253 253 253 253 253 250 250 250
39922 -238 238 238 198 198 198 6 6 6 38 38 38
39923 - 58 58 58 26 26 26 38 38 38 2 2 6
39924 - 2 2 6 2 2 6 2 2 6 46 46 46
39925 - 78 78 78 30 30 30 10 10 10 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 10 10 10 30 30 30
39934 - 74 74 74 58 58 58 2 2 6 42 42 42
39935 - 2 2 6 22 22 22 231 231 231 253 253 253
39936 -253 253 253 253 253 253 253 253 253 253 253 253
39937 -253 253 253 253 253 253 253 253 253 250 250 250
39938 -253 253 253 253 253 253 253 253 253 253 253 253
39939 -253 253 253 253 253 253 253 253 253 253 253 253
39940 -253 253 253 253 253 253 253 253 253 253 253 253
39941 -253 253 253 253 253 253 253 253 253 253 253 253
39942 -253 253 253 246 246 246 46 46 46 38 38 38
39943 - 42 42 42 14 14 14 38 38 38 14 14 14
39944 - 2 2 6 2 2 6 2 2 6 6 6 6
39945 - 86 86 86 46 46 46 14 14 14 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 6 6 6 14 14 14 42 42 42
39954 - 90 90 90 18 18 18 18 18 18 26 26 26
39955 - 2 2 6 116 116 116 253 253 253 253 253 253
39956 -253 253 253 253 253 253 253 253 253 253 253 253
39957 -253 253 253 253 253 253 250 250 250 238 238 238
39958 -253 253 253 253 253 253 253 253 253 253 253 253
39959 -253 253 253 253 253 253 253 253 253 253 253 253
39960 -253 253 253 253 253 253 253 253 253 253 253 253
39961 -253 253 253 253 253 253 253 253 253 253 253 253
39962 -253 253 253 253 253 253 94 94 94 6 6 6
39963 - 2 2 6 2 2 6 10 10 10 34 34 34
39964 - 2 2 6 2 2 6 2 2 6 2 2 6
39965 - 74 74 74 58 58 58 22 22 22 6 6 6
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 10 10 10 26 26 26 66 66 66
39974 - 82 82 82 2 2 6 38 38 38 6 6 6
39975 - 14 14 14 210 210 210 253 253 253 253 253 253
39976 -253 253 253 253 253 253 253 253 253 253 253 253
39977 -253 253 253 253 253 253 246 246 246 242 242 242
39978 -253 253 253 253 253 253 253 253 253 253 253 253
39979 -253 253 253 253 253 253 253 253 253 253 253 253
39980 -253 253 253 253 253 253 253 253 253 253 253 253
39981 -253 253 253 253 253 253 253 253 253 253 253 253
39982 -253 253 253 253 253 253 144 144 144 2 2 6
39983 - 2 2 6 2 2 6 2 2 6 46 46 46
39984 - 2 2 6 2 2 6 2 2 6 2 2 6
39985 - 42 42 42 74 74 74 30 30 30 10 10 10
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 6 6 6 14 14 14 42 42 42 90 90 90
39994 - 26 26 26 6 6 6 42 42 42 2 2 6
39995 - 74 74 74 250 250 250 253 253 253 253 253 253
39996 -253 253 253 253 253 253 253 253 253 253 253 253
39997 -253 253 253 253 253 253 242 242 242 242 242 242
39998 -253 253 253 253 253 253 253 253 253 253 253 253
39999 -253 253 253 253 253 253 253 253 253 253 253 253
40000 -253 253 253 253 253 253 253 253 253 253 253 253
40001 -253 253 253 253 253 253 253 253 253 253 253 253
40002 -253 253 253 253 253 253 182 182 182 2 2 6
40003 - 2 2 6 2 2 6 2 2 6 46 46 46
40004 - 2 2 6 2 2 6 2 2 6 2 2 6
40005 - 10 10 10 86 86 86 38 38 38 10 10 10
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 10 10 10 26 26 26 66 66 66 82 82 82
40014 - 2 2 6 22 22 22 18 18 18 2 2 6
40015 -149 149 149 253 253 253 253 253 253 253 253 253
40016 -253 253 253 253 253 253 253 253 253 253 253 253
40017 -253 253 253 253 253 253 234 234 234 242 242 242
40018 -253 253 253 253 253 253 253 253 253 253 253 253
40019 -253 253 253 253 253 253 253 253 253 253 253 253
40020 -253 253 253 253 253 253 253 253 253 253 253 253
40021 -253 253 253 253 253 253 253 253 253 253 253 253
40022 -253 253 253 253 253 253 206 206 206 2 2 6
40023 - 2 2 6 2 2 6 2 2 6 38 38 38
40024 - 2 2 6 2 2 6 2 2 6 2 2 6
40025 - 6 6 6 86 86 86 46 46 46 14 14 14
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 6 6 6
40033 - 18 18 18 46 46 46 86 86 86 18 18 18
40034 - 2 2 6 34 34 34 10 10 10 6 6 6
40035 -210 210 210 253 253 253 253 253 253 253 253 253
40036 -253 253 253 253 253 253 253 253 253 253 253 253
40037 -253 253 253 253 253 253 234 234 234 242 242 242
40038 -253 253 253 253 253 253 253 253 253 253 253 253
40039 -253 253 253 253 253 253 253 253 253 253 253 253
40040 -253 253 253 253 253 253 253 253 253 253 253 253
40041 -253 253 253 253 253 253 253 253 253 253 253 253
40042 -253 253 253 253 253 253 221 221 221 6 6 6
40043 - 2 2 6 2 2 6 6 6 6 30 30 30
40044 - 2 2 6 2 2 6 2 2 6 2 2 6
40045 - 2 2 6 82 82 82 54 54 54 18 18 18
40046 - 6 6 6 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 10 10 10
40053 - 26 26 26 66 66 66 62 62 62 2 2 6
40054 - 2 2 6 38 38 38 10 10 10 26 26 26
40055 -238 238 238 253 253 253 253 253 253 253 253 253
40056 -253 253 253 253 253 253 253 253 253 253 253 253
40057 -253 253 253 253 253 253 231 231 231 238 238 238
40058 -253 253 253 253 253 253 253 253 253 253 253 253
40059 -253 253 253 253 253 253 253 253 253 253 253 253
40060 -253 253 253 253 253 253 253 253 253 253 253 253
40061 -253 253 253 253 253 253 253 253 253 253 253 253
40062 -253 253 253 253 253 253 231 231 231 6 6 6
40063 - 2 2 6 2 2 6 10 10 10 30 30 30
40064 - 2 2 6 2 2 6 2 2 6 2 2 6
40065 - 2 2 6 66 66 66 58 58 58 22 22 22
40066 - 6 6 6 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 10 10 10
40073 - 38 38 38 78 78 78 6 6 6 2 2 6
40074 - 2 2 6 46 46 46 14 14 14 42 42 42
40075 -246 246 246 253 253 253 253 253 253 253 253 253
40076 -253 253 253 253 253 253 253 253 253 253 253 253
40077 -253 253 253 253 253 253 231 231 231 242 242 242
40078 -253 253 253 253 253 253 253 253 253 253 253 253
40079 -253 253 253 253 253 253 253 253 253 253 253 253
40080 -253 253 253 253 253 253 253 253 253 253 253 253
40081 -253 253 253 253 253 253 253 253 253 253 253 253
40082 -253 253 253 253 253 253 234 234 234 10 10 10
40083 - 2 2 6 2 2 6 22 22 22 14 14 14
40084 - 2 2 6 2 2 6 2 2 6 2 2 6
40085 - 2 2 6 66 66 66 62 62 62 22 22 22
40086 - 6 6 6 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 6 6 6 18 18 18
40093 - 50 50 50 74 74 74 2 2 6 2 2 6
40094 - 14 14 14 70 70 70 34 34 34 62 62 62
40095 -250 250 250 253 253 253 253 253 253 253 253 253
40096 -253 253 253 253 253 253 253 253 253 253 253 253
40097 -253 253 253 253 253 253 231 231 231 246 246 246
40098 -253 253 253 253 253 253 253 253 253 253 253 253
40099 -253 253 253 253 253 253 253 253 253 253 253 253
40100 -253 253 253 253 253 253 253 253 253 253 253 253
40101 -253 253 253 253 253 253 253 253 253 253 253 253
40102 -253 253 253 253 253 253 234 234 234 14 14 14
40103 - 2 2 6 2 2 6 30 30 30 2 2 6
40104 - 2 2 6 2 2 6 2 2 6 2 2 6
40105 - 2 2 6 66 66 66 62 62 62 22 22 22
40106 - 6 6 6 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 6 6 6 18 18 18
40113 - 54 54 54 62 62 62 2 2 6 2 2 6
40114 - 2 2 6 30 30 30 46 46 46 70 70 70
40115 -250 250 250 253 253 253 253 253 253 253 253 253
40116 -253 253 253 253 253 253 253 253 253 253 253 253
40117 -253 253 253 253 253 253 231 231 231 246 246 246
40118 -253 253 253 253 253 253 253 253 253 253 253 253
40119 -253 253 253 253 253 253 253 253 253 253 253 253
40120 -253 253 253 253 253 253 253 253 253 253 253 253
40121 -253 253 253 253 253 253 253 253 253 253 253 253
40122 -253 253 253 253 253 253 226 226 226 10 10 10
40123 - 2 2 6 6 6 6 30 30 30 2 2 6
40124 - 2 2 6 2 2 6 2 2 6 2 2 6
40125 - 2 2 6 66 66 66 58 58 58 22 22 22
40126 - 6 6 6 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 6 6 6 22 22 22
40133 - 58 58 58 62 62 62 2 2 6 2 2 6
40134 - 2 2 6 2 2 6 30 30 30 78 78 78
40135 -250 250 250 253 253 253 253 253 253 253 253 253
40136 -253 253 253 253 253 253 253 253 253 253 253 253
40137 -253 253 253 253 253 253 231 231 231 246 246 246
40138 -253 253 253 253 253 253 253 253 253 253 253 253
40139 -253 253 253 253 253 253 253 253 253 253 253 253
40140 -253 253 253 253 253 253 253 253 253 253 253 253
40141 -253 253 253 253 253 253 253 253 253 253 253 253
40142 -253 253 253 253 253 253 206 206 206 2 2 6
40143 - 22 22 22 34 34 34 18 14 6 22 22 22
40144 - 26 26 26 18 18 18 6 6 6 2 2 6
40145 - 2 2 6 82 82 82 54 54 54 18 18 18
40146 - 6 6 6 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 6 6 6 26 26 26
40153 - 62 62 62 106 106 106 74 54 14 185 133 11
40154 -210 162 10 121 92 8 6 6 6 62 62 62
40155 -238 238 238 253 253 253 253 253 253 253 253 253
40156 -253 253 253 253 253 253 253 253 253 253 253 253
40157 -253 253 253 253 253 253 231 231 231 246 246 246
40158 -253 253 253 253 253 253 253 253 253 253 253 253
40159 -253 253 253 253 253 253 253 253 253 253 253 253
40160 -253 253 253 253 253 253 253 253 253 253 253 253
40161 -253 253 253 253 253 253 253 253 253 253 253 253
40162 -253 253 253 253 253 253 158 158 158 18 18 18
40163 - 14 14 14 2 2 6 2 2 6 2 2 6
40164 - 6 6 6 18 18 18 66 66 66 38 38 38
40165 - 6 6 6 94 94 94 50 50 50 18 18 18
40166 - 6 6 6 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 6 6 6
40172 - 10 10 10 10 10 10 18 18 18 38 38 38
40173 - 78 78 78 142 134 106 216 158 10 242 186 14
40174 -246 190 14 246 190 14 156 118 10 10 10 10
40175 - 90 90 90 238 238 238 253 253 253 253 253 253
40176 -253 253 253 253 253 253 253 253 253 253 253 253
40177 -253 253 253 253 253 253 231 231 231 250 250 250
40178 -253 253 253 253 253 253 253 253 253 253 253 253
40179 -253 253 253 253 253 253 253 253 253 253 253 253
40180 -253 253 253 253 253 253 253 253 253 253 253 253
40181 -253 253 253 253 253 253 253 253 253 246 230 190
40182 -238 204 91 238 204 91 181 142 44 37 26 9
40183 - 2 2 6 2 2 6 2 2 6 2 2 6
40184 - 2 2 6 2 2 6 38 38 38 46 46 46
40185 - 26 26 26 106 106 106 54 54 54 18 18 18
40186 - 6 6 6 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 6 6 6 14 14 14 22 22 22
40192 - 30 30 30 38 38 38 50 50 50 70 70 70
40193 -106 106 106 190 142 34 226 170 11 242 186 14
40194 -246 190 14 246 190 14 246 190 14 154 114 10
40195 - 6 6 6 74 74 74 226 226 226 253 253 253
40196 -253 253 253 253 253 253 253 253 253 253 253 253
40197 -253 253 253 253 253 253 231 231 231 250 250 250
40198 -253 253 253 253 253 253 253 253 253 253 253 253
40199 -253 253 253 253 253 253 253 253 253 253 253 253
40200 -253 253 253 253 253 253 253 253 253 253 253 253
40201 -253 253 253 253 253 253 253 253 253 228 184 62
40202 -241 196 14 241 208 19 232 195 16 38 30 10
40203 - 2 2 6 2 2 6 2 2 6 2 2 6
40204 - 2 2 6 6 6 6 30 30 30 26 26 26
40205 -203 166 17 154 142 90 66 66 66 26 26 26
40206 - 6 6 6 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 6 6 6 18 18 18 38 38 38 58 58 58
40212 - 78 78 78 86 86 86 101 101 101 123 123 123
40213 -175 146 61 210 150 10 234 174 13 246 186 14
40214 -246 190 14 246 190 14 246 190 14 238 190 10
40215 -102 78 10 2 2 6 46 46 46 198 198 198
40216 -253 253 253 253 253 253 253 253 253 253 253 253
40217 -253 253 253 253 253 253 234 234 234 242 242 242
40218 -253 253 253 253 253 253 253 253 253 253 253 253
40219 -253 253 253 253 253 253 253 253 253 253 253 253
40220 -253 253 253 253 253 253 253 253 253 253 253 253
40221 -253 253 253 253 253 253 253 253 253 224 178 62
40222 -242 186 14 241 196 14 210 166 10 22 18 6
40223 - 2 2 6 2 2 6 2 2 6 2 2 6
40224 - 2 2 6 2 2 6 6 6 6 121 92 8
40225 -238 202 15 232 195 16 82 82 82 34 34 34
40226 - 10 10 10 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 14 14 14 38 38 38 70 70 70 154 122 46
40232 -190 142 34 200 144 11 197 138 11 197 138 11
40233 -213 154 11 226 170 11 242 186 14 246 190 14
40234 -246 190 14 246 190 14 246 190 14 246 190 14
40235 -225 175 15 46 32 6 2 2 6 22 22 22
40236 -158 158 158 250 250 250 253 253 253 253 253 253
40237 -253 253 253 253 253 253 253 253 253 253 253 253
40238 -253 253 253 253 253 253 253 253 253 253 253 253
40239 -253 253 253 253 253 253 253 253 253 253 253 253
40240 -253 253 253 253 253 253 253 253 253 253 253 253
40241 -253 253 253 250 250 250 242 242 242 224 178 62
40242 -239 182 13 236 186 11 213 154 11 46 32 6
40243 - 2 2 6 2 2 6 2 2 6 2 2 6
40244 - 2 2 6 2 2 6 61 42 6 225 175 15
40245 -238 190 10 236 186 11 112 100 78 42 42 42
40246 - 14 14 14 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 6 6 6
40251 - 22 22 22 54 54 54 154 122 46 213 154 11
40252 -226 170 11 230 174 11 226 170 11 226 170 11
40253 -236 178 12 242 186 14 246 190 14 246 190 14
40254 -246 190 14 246 190 14 246 190 14 246 190 14
40255 -241 196 14 184 144 12 10 10 10 2 2 6
40256 - 6 6 6 116 116 116 242 242 242 253 253 253
40257 -253 253 253 253 253 253 253 253 253 253 253 253
40258 -253 253 253 253 253 253 253 253 253 253 253 253
40259 -253 253 253 253 253 253 253 253 253 253 253 253
40260 -253 253 253 253 253 253 253 253 253 253 253 253
40261 -253 253 253 231 231 231 198 198 198 214 170 54
40262 -236 178 12 236 178 12 210 150 10 137 92 6
40263 - 18 14 6 2 2 6 2 2 6 2 2 6
40264 - 6 6 6 70 47 6 200 144 11 236 178 12
40265 -239 182 13 239 182 13 124 112 88 58 58 58
40266 - 22 22 22 6 6 6 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 10 10 10
40271 - 30 30 30 70 70 70 180 133 36 226 170 11
40272 -239 182 13 242 186 14 242 186 14 246 186 14
40273 -246 190 14 246 190 14 246 190 14 246 190 14
40274 -246 190 14 246 190 14 246 190 14 246 190 14
40275 -246 190 14 232 195 16 98 70 6 2 2 6
40276 - 2 2 6 2 2 6 66 66 66 221 221 221
40277 -253 253 253 253 253 253 253 253 253 253 253 253
40278 -253 253 253 253 253 253 253 253 253 253 253 253
40279 -253 253 253 253 253 253 253 253 253 253 253 253
40280 -253 253 253 253 253 253 253 253 253 253 253 253
40281 -253 253 253 206 206 206 198 198 198 214 166 58
40282 -230 174 11 230 174 11 216 158 10 192 133 9
40283 -163 110 8 116 81 8 102 78 10 116 81 8
40284 -167 114 7 197 138 11 226 170 11 239 182 13
40285 -242 186 14 242 186 14 162 146 94 78 78 78
40286 - 34 34 34 14 14 14 6 6 6 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 6 6 6
40291 - 30 30 30 78 78 78 190 142 34 226 170 11
40292 -239 182 13 246 190 14 246 190 14 246 190 14
40293 -246 190 14 246 190 14 246 190 14 246 190 14
40294 -246 190 14 246 190 14 246 190 14 246 190 14
40295 -246 190 14 241 196 14 203 166 17 22 18 6
40296 - 2 2 6 2 2 6 2 2 6 38 38 38
40297 -218 218 218 253 253 253 253 253 253 253 253 253
40298 -253 253 253 253 253 253 253 253 253 253 253 253
40299 -253 253 253 253 253 253 253 253 253 253 253 253
40300 -253 253 253 253 253 253 253 253 253 253 253 253
40301 -250 250 250 206 206 206 198 198 198 202 162 69
40302 -226 170 11 236 178 12 224 166 10 210 150 10
40303 -200 144 11 197 138 11 192 133 9 197 138 11
40304 -210 150 10 226 170 11 242 186 14 246 190 14
40305 -246 190 14 246 186 14 225 175 15 124 112 88
40306 - 62 62 62 30 30 30 14 14 14 6 6 6
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 10 10 10
40311 - 30 30 30 78 78 78 174 135 50 224 166 10
40312 -239 182 13 246 190 14 246 190 14 246 190 14
40313 -246 190 14 246 190 14 246 190 14 246 190 14
40314 -246 190 14 246 190 14 246 190 14 246 190 14
40315 -246 190 14 246 190 14 241 196 14 139 102 15
40316 - 2 2 6 2 2 6 2 2 6 2 2 6
40317 - 78 78 78 250 250 250 253 253 253 253 253 253
40318 -253 253 253 253 253 253 253 253 253 253 253 253
40319 -253 253 253 253 253 253 253 253 253 253 253 253
40320 -253 253 253 253 253 253 253 253 253 253 253 253
40321 -250 250 250 214 214 214 198 198 198 190 150 46
40322 -219 162 10 236 178 12 234 174 13 224 166 10
40323 -216 158 10 213 154 11 213 154 11 216 158 10
40324 -226 170 11 239 182 13 246 190 14 246 190 14
40325 -246 190 14 246 190 14 242 186 14 206 162 42
40326 -101 101 101 58 58 58 30 30 30 14 14 14
40327 - 6 6 6 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 10 10 10
40331 - 30 30 30 74 74 74 174 135 50 216 158 10
40332 -236 178 12 246 190 14 246 190 14 246 190 14
40333 -246 190 14 246 190 14 246 190 14 246 190 14
40334 -246 190 14 246 190 14 246 190 14 246 190 14
40335 -246 190 14 246 190 14 241 196 14 226 184 13
40336 - 61 42 6 2 2 6 2 2 6 2 2 6
40337 - 22 22 22 238 238 238 253 253 253 253 253 253
40338 -253 253 253 253 253 253 253 253 253 253 253 253
40339 -253 253 253 253 253 253 253 253 253 253 253 253
40340 -253 253 253 253 253 253 253 253 253 253 253 253
40341 -253 253 253 226 226 226 187 187 187 180 133 36
40342 -216 158 10 236 178 12 239 182 13 236 178 12
40343 -230 174 11 226 170 11 226 170 11 230 174 11
40344 -236 178 12 242 186 14 246 190 14 246 190 14
40345 -246 190 14 246 190 14 246 186 14 239 182 13
40346 -206 162 42 106 106 106 66 66 66 34 34 34
40347 - 14 14 14 6 6 6 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 6 6 6
40351 - 26 26 26 70 70 70 163 133 67 213 154 11
40352 -236 178 12 246 190 14 246 190 14 246 190 14
40353 -246 190 14 246 190 14 246 190 14 246 190 14
40354 -246 190 14 246 190 14 246 190 14 246 190 14
40355 -246 190 14 246 190 14 246 190 14 241 196 14
40356 -190 146 13 18 14 6 2 2 6 2 2 6
40357 - 46 46 46 246 246 246 253 253 253 253 253 253
40358 -253 253 253 253 253 253 253 253 253 253 253 253
40359 -253 253 253 253 253 253 253 253 253 253 253 253
40360 -253 253 253 253 253 253 253 253 253 253 253 253
40361 -253 253 253 221 221 221 86 86 86 156 107 11
40362 -216 158 10 236 178 12 242 186 14 246 186 14
40363 -242 186 14 239 182 13 239 182 13 242 186 14
40364 -242 186 14 246 186 14 246 190 14 246 190 14
40365 -246 190 14 246 190 14 246 190 14 246 190 14
40366 -242 186 14 225 175 15 142 122 72 66 66 66
40367 - 30 30 30 10 10 10 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 6 6 6
40371 - 26 26 26 70 70 70 163 133 67 210 150 10
40372 -236 178 12 246 190 14 246 190 14 246 190 14
40373 -246 190 14 246 190 14 246 190 14 246 190 14
40374 -246 190 14 246 190 14 246 190 14 246 190 14
40375 -246 190 14 246 190 14 246 190 14 246 190 14
40376 -232 195 16 121 92 8 34 34 34 106 106 106
40377 -221 221 221 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 253 253 253 253 253 253
40379 -253 253 253 253 253 253 253 253 253 253 253 253
40380 -253 253 253 253 253 253 253 253 253 253 253 253
40381 -242 242 242 82 82 82 18 14 6 163 110 8
40382 -216 158 10 236 178 12 242 186 14 246 190 14
40383 -246 190 14 246 190 14 246 190 14 246 190 14
40384 -246 190 14 246 190 14 246 190 14 246 190 14
40385 -246 190 14 246 190 14 246 190 14 246 190 14
40386 -246 190 14 246 190 14 242 186 14 163 133 67
40387 - 46 46 46 18 18 18 6 6 6 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 10 10 10
40391 - 30 30 30 78 78 78 163 133 67 210 150 10
40392 -236 178 12 246 186 14 246 190 14 246 190 14
40393 -246 190 14 246 190 14 246 190 14 246 190 14
40394 -246 190 14 246 190 14 246 190 14 246 190 14
40395 -246 190 14 246 190 14 246 190 14 246 190 14
40396 -241 196 14 215 174 15 190 178 144 253 253 253
40397 -253 253 253 253 253 253 253 253 253 253 253 253
40398 -253 253 253 253 253 253 253 253 253 253 253 253
40399 -253 253 253 253 253 253 253 253 253 253 253 253
40400 -253 253 253 253 253 253 253 253 253 218 218 218
40401 - 58 58 58 2 2 6 22 18 6 167 114 7
40402 -216 158 10 236 178 12 246 186 14 246 190 14
40403 -246 190 14 246 190 14 246 190 14 246 190 14
40404 -246 190 14 246 190 14 246 190 14 246 190 14
40405 -246 190 14 246 190 14 246 190 14 246 190 14
40406 -246 190 14 246 186 14 242 186 14 190 150 46
40407 - 54 54 54 22 22 22 6 6 6 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 14 14 14
40411 - 38 38 38 86 86 86 180 133 36 213 154 11
40412 -236 178 12 246 186 14 246 190 14 246 190 14
40413 -246 190 14 246 190 14 246 190 14 246 190 14
40414 -246 190 14 246 190 14 246 190 14 246 190 14
40415 -246 190 14 246 190 14 246 190 14 246 190 14
40416 -246 190 14 232 195 16 190 146 13 214 214 214
40417 -253 253 253 253 253 253 253 253 253 253 253 253
40418 -253 253 253 253 253 253 253 253 253 253 253 253
40419 -253 253 253 253 253 253 253 253 253 253 253 253
40420 -253 253 253 250 250 250 170 170 170 26 26 26
40421 - 2 2 6 2 2 6 37 26 9 163 110 8
40422 -219 162 10 239 182 13 246 186 14 246 190 14
40423 -246 190 14 246 190 14 246 190 14 246 190 14
40424 -246 190 14 246 190 14 246 190 14 246 190 14
40425 -246 190 14 246 190 14 246 190 14 246 190 14
40426 -246 186 14 236 178 12 224 166 10 142 122 72
40427 - 46 46 46 18 18 18 6 6 6 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 6 6 6 18 18 18
40431 - 50 50 50 109 106 95 192 133 9 224 166 10
40432 -242 186 14 246 190 14 246 190 14 246 190 14
40433 -246 190 14 246 190 14 246 190 14 246 190 14
40434 -246 190 14 246 190 14 246 190 14 246 190 14
40435 -246 190 14 246 190 14 246 190 14 246 190 14
40436 -242 186 14 226 184 13 210 162 10 142 110 46
40437 -226 226 226 253 253 253 253 253 253 253 253 253
40438 -253 253 253 253 253 253 253 253 253 253 253 253
40439 -253 253 253 253 253 253 253 253 253 253 253 253
40440 -198 198 198 66 66 66 2 2 6 2 2 6
40441 - 2 2 6 2 2 6 50 34 6 156 107 11
40442 -219 162 10 239 182 13 246 186 14 246 190 14
40443 -246 190 14 246 190 14 246 190 14 246 190 14
40444 -246 190 14 246 190 14 246 190 14 246 190 14
40445 -246 190 14 246 190 14 246 190 14 242 186 14
40446 -234 174 13 213 154 11 154 122 46 66 66 66
40447 - 30 30 30 10 10 10 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 6 6 6 22 22 22
40451 - 58 58 58 154 121 60 206 145 10 234 174 13
40452 -242 186 14 246 186 14 246 190 14 246 190 14
40453 -246 190 14 246 190 14 246 190 14 246 190 14
40454 -246 190 14 246 190 14 246 190 14 246 190 14
40455 -246 190 14 246 190 14 246 190 14 246 190 14
40456 -246 186 14 236 178 12 210 162 10 163 110 8
40457 - 61 42 6 138 138 138 218 218 218 250 250 250
40458 -253 253 253 253 253 253 253 253 253 250 250 250
40459 -242 242 242 210 210 210 144 144 144 66 66 66
40460 - 6 6 6 2 2 6 2 2 6 2 2 6
40461 - 2 2 6 2 2 6 61 42 6 163 110 8
40462 -216 158 10 236 178 12 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 246 190 14 246 190 14
40465 -246 190 14 239 182 13 230 174 11 216 158 10
40466 -190 142 34 124 112 88 70 70 70 38 38 38
40467 - 18 18 18 6 6 6 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 0 0 0 0 0 0 6 6 6 22 22 22
40471 - 62 62 62 168 124 44 206 145 10 224 166 10
40472 -236 178 12 239 182 13 242 186 14 242 186 14
40473 -246 186 14 246 190 14 246 190 14 246 190 14
40474 -246 190 14 246 190 14 246 190 14 246 190 14
40475 -246 190 14 246 190 14 246 190 14 246 190 14
40476 -246 190 14 236 178 12 216 158 10 175 118 6
40477 - 80 54 7 2 2 6 6 6 6 30 30 30
40478 - 54 54 54 62 62 62 50 50 50 38 38 38
40479 - 14 14 14 2 2 6 2 2 6 2 2 6
40480 - 2 2 6 2 2 6 2 2 6 2 2 6
40481 - 2 2 6 6 6 6 80 54 7 167 114 7
40482 -213 154 11 236 178 12 246 190 14 246 190 14
40483 -246 190 14 246 190 14 246 190 14 246 190 14
40484 -246 190 14 242 186 14 239 182 13 239 182 13
40485 -230 174 11 210 150 10 174 135 50 124 112 88
40486 - 82 82 82 54 54 54 34 34 34 18 18 18
40487 - 6 6 6 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 0 0 0 0 0 0 6 6 6 18 18 18
40491 - 50 50 50 158 118 36 192 133 9 200 144 11
40492 -216 158 10 219 162 10 224 166 10 226 170 11
40493 -230 174 11 236 178 12 239 182 13 239 182 13
40494 -242 186 14 246 186 14 246 190 14 246 190 14
40495 -246 190 14 246 190 14 246 190 14 246 190 14
40496 -246 186 14 230 174 11 210 150 10 163 110 8
40497 -104 69 6 10 10 10 2 2 6 2 2 6
40498 - 2 2 6 2 2 6 2 2 6 2 2 6
40499 - 2 2 6 2 2 6 2 2 6 2 2 6
40500 - 2 2 6 2 2 6 2 2 6 2 2 6
40501 - 2 2 6 6 6 6 91 60 6 167 114 7
40502 -206 145 10 230 174 11 242 186 14 246 190 14
40503 -246 190 14 246 190 14 246 186 14 242 186 14
40504 -239 182 13 230 174 11 224 166 10 213 154 11
40505 -180 133 36 124 112 88 86 86 86 58 58 58
40506 - 38 38 38 22 22 22 10 10 10 6 6 6
40507 - 0 0 0 0 0 0 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 14 14 14
40511 - 34 34 34 70 70 70 138 110 50 158 118 36
40512 -167 114 7 180 123 7 192 133 9 197 138 11
40513 -200 144 11 206 145 10 213 154 11 219 162 10
40514 -224 166 10 230 174 11 239 182 13 242 186 14
40515 -246 186 14 246 186 14 246 186 14 246 186 14
40516 -239 182 13 216 158 10 185 133 11 152 99 6
40517 -104 69 6 18 14 6 2 2 6 2 2 6
40518 - 2 2 6 2 2 6 2 2 6 2 2 6
40519 - 2 2 6 2 2 6 2 2 6 2 2 6
40520 - 2 2 6 2 2 6 2 2 6 2 2 6
40521 - 2 2 6 6 6 6 80 54 7 152 99 6
40522 -192 133 9 219 162 10 236 178 12 239 182 13
40523 -246 186 14 242 186 14 239 182 13 236 178 12
40524 -224 166 10 206 145 10 192 133 9 154 121 60
40525 - 94 94 94 62 62 62 42 42 42 22 22 22
40526 - 14 14 14 6 6 6 0 0 0 0 0 0
40527 - 0 0 0 0 0 0 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 6 6 6
40531 - 18 18 18 34 34 34 58 58 58 78 78 78
40532 -101 98 89 124 112 88 142 110 46 156 107 11
40533 -163 110 8 167 114 7 175 118 6 180 123 7
40534 -185 133 11 197 138 11 210 150 10 219 162 10
40535 -226 170 11 236 178 12 236 178 12 234 174 13
40536 -219 162 10 197 138 11 163 110 8 130 83 6
40537 - 91 60 6 10 10 10 2 2 6 2 2 6
40538 - 18 18 18 38 38 38 38 38 38 38 38 38
40539 - 38 38 38 38 38 38 38 38 38 38 38 38
40540 - 38 38 38 38 38 38 26 26 26 2 2 6
40541 - 2 2 6 6 6 6 70 47 6 137 92 6
40542 -175 118 6 200 144 11 219 162 10 230 174 11
40543 -234 174 13 230 174 11 219 162 10 210 150 10
40544 -192 133 9 163 110 8 124 112 88 82 82 82
40545 - 50 50 50 30 30 30 14 14 14 6 6 6
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 0 0 0 0 0 0 0 0 0 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 6 6 6 14 14 14 22 22 22 34 34 34
40552 - 42 42 42 58 58 58 74 74 74 86 86 86
40553 -101 98 89 122 102 70 130 98 46 121 87 25
40554 -137 92 6 152 99 6 163 110 8 180 123 7
40555 -185 133 11 197 138 11 206 145 10 200 144 11
40556 -180 123 7 156 107 11 130 83 6 104 69 6
40557 - 50 34 6 54 54 54 110 110 110 101 98 89
40558 - 86 86 86 82 82 82 78 78 78 78 78 78
40559 - 78 78 78 78 78 78 78 78 78 78 78 78
40560 - 78 78 78 82 82 82 86 86 86 94 94 94
40561 -106 106 106 101 101 101 86 66 34 124 80 6
40562 -156 107 11 180 123 7 192 133 9 200 144 11
40563 -206 145 10 200 144 11 192 133 9 175 118 6
40564 -139 102 15 109 106 95 70 70 70 42 42 42
40565 - 22 22 22 10 10 10 0 0 0 0 0 0
40566 - 0 0 0 0 0 0 0 0 0 0 0 0
40567 - 0 0 0 0 0 0 0 0 0 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 0 0 0 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 6 6 6 10 10 10
40572 - 14 14 14 22 22 22 30 30 30 38 38 38
40573 - 50 50 50 62 62 62 74 74 74 90 90 90
40574 -101 98 89 112 100 78 121 87 25 124 80 6
40575 -137 92 6 152 99 6 152 99 6 152 99 6
40576 -138 86 6 124 80 6 98 70 6 86 66 30
40577 -101 98 89 82 82 82 58 58 58 46 46 46
40578 - 38 38 38 34 34 34 34 34 34 34 34 34
40579 - 34 34 34 34 34 34 34 34 34 34 34 34
40580 - 34 34 34 34 34 34 38 38 38 42 42 42
40581 - 54 54 54 82 82 82 94 86 76 91 60 6
40582 -134 86 6 156 107 11 167 114 7 175 118 6
40583 -175 118 6 167 114 7 152 99 6 121 87 25
40584 -101 98 89 62 62 62 34 34 34 18 18 18
40585 - 6 6 6 0 0 0 0 0 0 0 0 0
40586 - 0 0 0 0 0 0 0 0 0 0 0 0
40587 - 0 0 0 0 0 0 0 0 0 0 0 0
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 0 0 0 0 0 0
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 6 6 6 6 6 6 10 10 10
40593 - 18 18 18 22 22 22 30 30 30 42 42 42
40594 - 50 50 50 66 66 66 86 86 86 101 98 89
40595 -106 86 58 98 70 6 104 69 6 104 69 6
40596 -104 69 6 91 60 6 82 62 34 90 90 90
40597 - 62 62 62 38 38 38 22 22 22 14 14 14
40598 - 10 10 10 10 10 10 10 10 10 10 10 10
40599 - 10 10 10 10 10 10 6 6 6 10 10 10
40600 - 10 10 10 10 10 10 10 10 10 14 14 14
40601 - 22 22 22 42 42 42 70 70 70 89 81 66
40602 - 80 54 7 104 69 6 124 80 6 137 92 6
40603 -134 86 6 116 81 8 100 82 52 86 86 86
40604 - 58 58 58 30 30 30 14 14 14 6 6 6
40605 - 0 0 0 0 0 0 0 0 0 0 0 0
40606 - 0 0 0 0 0 0 0 0 0 0 0 0
40607 - 0 0 0 0 0 0 0 0 0 0 0 0
40608 - 0 0 0 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 6 6 6 10 10 10 14 14 14
40614 - 18 18 18 26 26 26 38 38 38 54 54 54
40615 - 70 70 70 86 86 86 94 86 76 89 81 66
40616 - 89 81 66 86 86 86 74 74 74 50 50 50
40617 - 30 30 30 14 14 14 6 6 6 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 6 6 6 18 18 18 34 34 34 58 58 58
40622 - 82 82 82 89 81 66 89 81 66 89 81 66
40623 - 94 86 66 94 86 76 74 74 74 50 50 50
40624 - 26 26 26 14 14 14 6 6 6 0 0 0
40625 - 0 0 0 0 0 0 0 0 0 0 0 0
40626 - 0 0 0 0 0 0 0 0 0 0 0 0
40627 - 0 0 0 0 0 0 0 0 0 0 0 0
40628 - 0 0 0 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 6 6 6 6 6 6 14 14 14 18 18 18
40635 - 30 30 30 38 38 38 46 46 46 54 54 54
40636 - 50 50 50 42 42 42 30 30 30 18 18 18
40637 - 10 10 10 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 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 6 6 6 14 14 14 26 26 26
40642 - 38 38 38 50 50 50 58 58 58 58 58 58
40643 - 54 54 54 42 42 42 30 30 30 18 18 18
40644 - 10 10 10 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 0 0 0
40646 - 0 0 0 0 0 0 0 0 0 0 0 0
40647 - 0 0 0 0 0 0 0 0 0 0 0 0
40648 - 0 0 0 0 0 0 0 0 0 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 6 6 6
40655 - 6 6 6 10 10 10 14 14 14 18 18 18
40656 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 6 6 6
40662 - 14 14 14 18 18 18 22 22 22 22 22 22
40663 - 18 18 18 14 14 14 10 10 10 6 6 6
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 0 0 0
40666 - 0 0 0 0 0 0 0 0 0 0 0 0
40667 - 0 0 0 0 0 0 0 0 0 0 0 0
40668 - 0 0 0 0 0 0 0 0 0 0 0 0
40669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40682 +4 4 4 4 4 4
40683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40696 +4 4 4 4 4 4
40697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710 +4 4 4 4 4 4
40711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724 +4 4 4 4 4 4
40725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738 +4 4 4 4 4 4
40739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752 +4 4 4 4 4 4
40753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40758 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40763 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40764 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766 +4 4 4 4 4 4
40767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40772 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40773 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40776 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40777 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40778 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40779 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780 +4 4 4 4 4 4
40781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40786 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40787 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40790 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40791 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40792 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40793 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40794 +4 4 4 4 4 4
40795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40799 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40800 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40801 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40803 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40804 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40805 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40806 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40807 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40808 +4 4 4 4 4 4
40809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40812 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40813 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40814 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40815 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40816 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40817 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40818 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40819 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40820 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40821 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40822 +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 5 5 5
40826 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40827 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40828 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40829 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40830 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40831 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40832 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40833 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40834 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40835 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40836 +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 5 5 5 3 3 3
40840 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40841 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40842 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40843 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40844 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40845 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40846 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40847 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40848 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40849 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40850 +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 2 2 2 0 0 0 4 0 0
40854 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40855 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40856 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40857 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40858 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40859 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40860 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40861 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40862 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40863 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40864 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40868 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40869 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40870 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40871 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40872 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40873 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40874 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40875 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40876 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40877 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40878 +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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40882 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40883 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40884 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40885 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40886 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40887 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40888 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40889 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40890 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40891 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40892 +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 3 3 3 0 0 0
40895 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40896 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40897 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40898 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40899 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40900 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40901 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40902 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40903 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40904 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40905 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40906 +4 4 4 4 4 4
40907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40908 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40909 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40910 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40911 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40912 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40913 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40914 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40915 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40916 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40917 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40918 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40919 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40920 +0 0 0 4 4 4
40921 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40922 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40923 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40924 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40925 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40926 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40927 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40928 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40929 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40930 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40931 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40932 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40933 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40934 +2 0 0 0 0 0
40935 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40936 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40937 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40938 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40939 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40940 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40941 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40942 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40943 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40944 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40945 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40946 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40947 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40948 +37 38 37 0 0 0
40949 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40950 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40951 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40952 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40953 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40954 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40955 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40956 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40957 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40958 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40959 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40960 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40961 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40962 +85 115 134 4 0 0
40963 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40964 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40965 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40966 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40967 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40968 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40969 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40970 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40971 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40972 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40973 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40974 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40975 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40976 +60 73 81 4 0 0
40977 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40978 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40979 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40980 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40981 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40982 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40983 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40984 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40985 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40986 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40987 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40988 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40989 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40990 +16 19 21 4 0 0
40991 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40992 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40993 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40994 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40995 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40996 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40997 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40998 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40999 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41000 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41001 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41002 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41003 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41004 +4 0 0 4 3 3
41005 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41006 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41007 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41009 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41010 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41011 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41012 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41013 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41014 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41015 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41016 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41017 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41018 +3 2 2 4 4 4
41019 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41020 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41021 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41022 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41023 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41024 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41025 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41026 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41027 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41028 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41029 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41030 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41031 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41032 +4 4 4 4 4 4
41033 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41034 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41035 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41036 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41037 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41038 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41039 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41040 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41041 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41042 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41043 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41044 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41045 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41046 +4 4 4 4 4 4
41047 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41048 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41049 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41050 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41051 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41052 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41053 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41054 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41055 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41056 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41057 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41058 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41059 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41060 +5 5 5 5 5 5
41061 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41062 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41063 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41064 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41065 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41066 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41067 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41068 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41069 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41070 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41071 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41072 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41073 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41074 +5 5 5 4 4 4
41075 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41076 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41077 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41078 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41079 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41080 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41081 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41082 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41083 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41084 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41085 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41086 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088 +4 4 4 4 4 4
41089 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41090 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41091 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41092 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41093 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41094 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41095 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41096 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41097 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41098 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41099 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41100 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102 +4 4 4 4 4 4
41103 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41104 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41105 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41106 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41107 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41108 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41109 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41110 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41111 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41112 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41113 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41116 +4 4 4 4 4 4
41117 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41118 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41119 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41120 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41121 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41122 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41123 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41124 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41125 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41126 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41127 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41130 +4 4 4 4 4 4
41131 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41132 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41133 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41134 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41135 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41136 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41137 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41138 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41139 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41140 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41141 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4
41145 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41146 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41147 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41148 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41149 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41150 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41151 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41152 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41153 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41154 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41155 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4
41159 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41160 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41161 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41162 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41163 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41164 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41165 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41166 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41167 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41168 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41169 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4
41173 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41174 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41175 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41176 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41177 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41178 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41179 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41180 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41181 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41182 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41183 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4
41187 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41188 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41189 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41190 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41191 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41192 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41193 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41194 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41195 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41196 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41197 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4
41201 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41202 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41203 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41204 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41205 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41206 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41207 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41208 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41209 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41210 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41211 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4
41215 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41216 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41217 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41218 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41219 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41220 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41221 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41222 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41223 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41224 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41225 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4
41229 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41230 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41231 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41232 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41233 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41234 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41235 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41236 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41237 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41238 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41239 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4
41243 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41244 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41245 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41246 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41247 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41248 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41249 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41250 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41251 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41252 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41253 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4
41257 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41258 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41259 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41260 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41261 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41262 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41263 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41264 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41265 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41266 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41267 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4
41271 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41272 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41273 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41274 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41275 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41276 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41277 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41278 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41279 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41280 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41281 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4
41285 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41286 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41287 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41288 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41289 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41290 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41291 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41292 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41293 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41294 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41295 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4
41299 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41300 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41301 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41302 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41303 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41304 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41305 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41306 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41307 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41308 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41309 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4
41313 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41314 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41315 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41316 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41317 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41318 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41319 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41320 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41321 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41322 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41323 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4
41327 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41328 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41329 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41330 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41331 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41332 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41333 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41334 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41335 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41336 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41337 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4
41341 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41342 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41343 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41344 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41345 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41346 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41347 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41348 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41349 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41350 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41351 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4
41355 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41356 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41357 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41358 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41359 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41360 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41361 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41362 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41363 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41364 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41365 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4
41369 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41370 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41371 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41372 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41373 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41374 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41375 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41376 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41377 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41378 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41379 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4
41383 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41384 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41385 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41386 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41387 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41388 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41389 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41390 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41391 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41392 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41393 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4
41397 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41398 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41399 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41400 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41401 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41402 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41403 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41404 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41405 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41406 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41407 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4
41411 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41412 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41413 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41415 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41416 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41417 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41418 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41419 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41420 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41421 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 4 4 4
41425 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41426 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41427 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41428 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41429 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41430 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41431 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41432 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41433 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41434 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41435 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 4 4 4
41439 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41440 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41441 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41442 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41443 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41444 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41445 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41446 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41447 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41448 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41449 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4
41453 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41454 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41455 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41456 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41457 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41458 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41459 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41461 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41462 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41463 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466 +4 4 4 4 4 4
41467 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41468 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41469 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41470 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41471 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41472 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41473 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41474 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41475 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41476 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41477 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480 +4 4 4 4 4 4
41481 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41482 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41483 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41484 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41485 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41486 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41487 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41488 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41489 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41490 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494 +4 4 4 4 4 4
41495 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41496 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41497 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41498 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41499 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41500 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41501 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41502 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41503 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41504 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508 +4 4 4 4 4 4
41509 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41510 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41511 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41512 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41513 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41514 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41515 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41516 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41517 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41518 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522 +4 4 4 4 4 4
41523 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41524 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41525 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41526 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41527 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41528 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41529 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41530 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41531 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41532 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536 +4 4 4 4 4 4
41537 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41538 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41539 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41540 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41541 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41542 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41543 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41544 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41545 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550 +4 4 4 4 4 4
41551 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41552 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41553 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41554 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41555 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41556 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41557 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41558 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41559 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4
41565 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41566 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41567 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41568 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41569 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41570 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41571 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41572 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41573 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4
41579 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41580 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41581 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41582 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41583 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41584 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41585 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41586 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4
41593 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41594 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41595 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41596 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41597 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41598 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41599 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41600 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4
41607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41608 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41609 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41610 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41611 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41612 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41613 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41614 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4
41621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41623 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41624 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41625 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41626 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41627 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41628 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4
41635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41637 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41638 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41639 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41640 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41641 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41642 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4
41649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41652 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41653 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41654 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41655 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41656 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4
41663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41666 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41667 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41668 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41669 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4
41677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41681 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41682 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41683 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4
41691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41695 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41696 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41697 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4
41705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41708 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41709 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41710 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41711 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4
41719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41723 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41724 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41725 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4
41733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41738 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41739 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4
41747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41752 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41753 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4
41761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41766 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4
41775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41778 +4 4 4 4 4 4 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 5 5 5 4 3 3
41780 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4
41789 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41790 index 8af6414..658c030 100644
41791 --- a/drivers/video/udlfb.c
41792 +++ b/drivers/video/udlfb.c
41793 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41794 dlfb_urb_completion(urb);
41795
41796 error:
41797 - atomic_add(bytes_sent, &dev->bytes_sent);
41798 - atomic_add(bytes_identical, &dev->bytes_identical);
41799 - atomic_add(width*height*2, &dev->bytes_rendered);
41800 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41801 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41802 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41803 end_cycles = get_cycles();
41804 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41805 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41806 >> 10)), /* Kcycles */
41807 &dev->cpu_kcycles_used);
41808
41809 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41810 dlfb_urb_completion(urb);
41811
41812 error:
41813 - atomic_add(bytes_sent, &dev->bytes_sent);
41814 - atomic_add(bytes_identical, &dev->bytes_identical);
41815 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41816 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41817 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41818 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41819 end_cycles = get_cycles();
41820 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41821 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41822 >> 10)), /* Kcycles */
41823 &dev->cpu_kcycles_used);
41824 }
41825 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41826 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41827 struct dlfb_data *dev = fb_info->par;
41828 return snprintf(buf, PAGE_SIZE, "%u\n",
41829 - atomic_read(&dev->bytes_rendered));
41830 + atomic_read_unchecked(&dev->bytes_rendered));
41831 }
41832
41833 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41834 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41835 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41836 struct dlfb_data *dev = fb_info->par;
41837 return snprintf(buf, PAGE_SIZE, "%u\n",
41838 - atomic_read(&dev->bytes_identical));
41839 + atomic_read_unchecked(&dev->bytes_identical));
41840 }
41841
41842 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41843 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41844 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41845 struct dlfb_data *dev = fb_info->par;
41846 return snprintf(buf, PAGE_SIZE, "%u\n",
41847 - atomic_read(&dev->bytes_sent));
41848 + atomic_read_unchecked(&dev->bytes_sent));
41849 }
41850
41851 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41852 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41853 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41854 struct dlfb_data *dev = fb_info->par;
41855 return snprintf(buf, PAGE_SIZE, "%u\n",
41856 - atomic_read(&dev->cpu_kcycles_used));
41857 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41858 }
41859
41860 static ssize_t edid_show(
41861 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41862 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41863 struct dlfb_data *dev = fb_info->par;
41864
41865 - atomic_set(&dev->bytes_rendered, 0);
41866 - atomic_set(&dev->bytes_identical, 0);
41867 - atomic_set(&dev->bytes_sent, 0);
41868 - atomic_set(&dev->cpu_kcycles_used, 0);
41869 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41870 + atomic_set_unchecked(&dev->bytes_identical, 0);
41871 + atomic_set_unchecked(&dev->bytes_sent, 0);
41872 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41873
41874 return count;
41875 }
41876 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41877 index b0e2a42..e2df3ad 100644
41878 --- a/drivers/video/uvesafb.c
41879 +++ b/drivers/video/uvesafb.c
41880 @@ -19,6 +19,7 @@
41881 #include <linux/io.h>
41882 #include <linux/mutex.h>
41883 #include <linux/slab.h>
41884 +#include <linux/moduleloader.h>
41885 #include <video/edid.h>
41886 #include <video/uvesafb.h>
41887 #ifdef CONFIG_X86
41888 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41889 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41890 par->pmi_setpal = par->ypan = 0;
41891 } else {
41892 +
41893 +#ifdef CONFIG_PAX_KERNEXEC
41894 +#ifdef CONFIG_MODULES
41895 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41896 +#endif
41897 + if (!par->pmi_code) {
41898 + par->pmi_setpal = par->ypan = 0;
41899 + return 0;
41900 + }
41901 +#endif
41902 +
41903 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41904 + task->t.regs.edi);
41905 +
41906 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41907 + pax_open_kernel();
41908 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41909 + pax_close_kernel();
41910 +
41911 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41912 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41913 +#else
41914 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41915 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41916 +#endif
41917 +
41918 printk(KERN_INFO "uvesafb: protected mode interface info at "
41919 "%04x:%04x\n",
41920 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41921 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41922 par->ypan = ypan;
41923
41924 if (par->pmi_setpal || par->ypan) {
41925 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41926 if (__supported_pte_mask & _PAGE_NX) {
41927 par->pmi_setpal = par->ypan = 0;
41928 printk(KERN_WARNING "uvesafb: NX protection is actively."
41929 "We have better not to use the PMI.\n");
41930 - } else {
41931 + } else
41932 +#endif
41933 uvesafb_vbe_getpmi(task, par);
41934 - }
41935 }
41936 #else
41937 /* The protected mode interface is not available on non-x86. */
41938 @@ -1836,6 +1860,11 @@ out:
41939 if (par->vbe_modes)
41940 kfree(par->vbe_modes);
41941
41942 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41943 + if (par->pmi_code)
41944 + module_free_exec(NULL, par->pmi_code);
41945 +#endif
41946 +
41947 framebuffer_release(info);
41948 return err;
41949 }
41950 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41951 kfree(par->vbe_state_orig);
41952 if (par->vbe_state_saved)
41953 kfree(par->vbe_state_saved);
41954 +
41955 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41956 + if (par->pmi_code)
41957 + module_free_exec(NULL, par->pmi_code);
41958 +#endif
41959 +
41960 }
41961
41962 framebuffer_release(info);
41963 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41964 index 501b340..86bd4cf 100644
41965 --- a/drivers/video/vesafb.c
41966 +++ b/drivers/video/vesafb.c
41967 @@ -9,6 +9,7 @@
41968 */
41969
41970 #include <linux/module.h>
41971 +#include <linux/moduleloader.h>
41972 #include <linux/kernel.h>
41973 #include <linux/errno.h>
41974 #include <linux/string.h>
41975 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41976 static int vram_total __initdata; /* Set total amount of memory */
41977 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41978 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41979 -static void (*pmi_start)(void) __read_mostly;
41980 -static void (*pmi_pal) (void) __read_mostly;
41981 +static void (*pmi_start)(void) __read_only;
41982 +static void (*pmi_pal) (void) __read_only;
41983 static int depth __read_mostly;
41984 static int vga_compat __read_mostly;
41985 /* --------------------------------------------------------------------- */
41986 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41987 unsigned int size_vmode;
41988 unsigned int size_remap;
41989 unsigned int size_total;
41990 + void *pmi_code = NULL;
41991
41992 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41993 return -ENODEV;
41994 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41995 size_remap = size_total;
41996 vesafb_fix.smem_len = size_remap;
41997
41998 -#ifndef __i386__
41999 - screen_info.vesapm_seg = 0;
42000 -#endif
42001 -
42002 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42003 printk(KERN_WARNING
42004 "vesafb: cannot reserve video memory at 0x%lx\n",
42005 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42006 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42007 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42008
42009 +#ifdef __i386__
42010 +
42011 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42012 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42013 + if (!pmi_code)
42014 +#elif !defined(CONFIG_PAX_KERNEXEC)
42015 + if (0)
42016 +#endif
42017 +
42018 +#endif
42019 + screen_info.vesapm_seg = 0;
42020 +
42021 if (screen_info.vesapm_seg) {
42022 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42023 - screen_info.vesapm_seg,screen_info.vesapm_off);
42024 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42025 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42026 }
42027
42028 if (screen_info.vesapm_seg < 0xc000)
42029 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42030
42031 if (ypan || pmi_setpal) {
42032 unsigned short *pmi_base;
42033 +
42034 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42035 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42036 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42037 +
42038 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42039 + pax_open_kernel();
42040 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42041 +#else
42042 + pmi_code = pmi_base;
42043 +#endif
42044 +
42045 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42046 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42047 +
42048 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42049 + pmi_start = ktva_ktla(pmi_start);
42050 + pmi_pal = ktva_ktla(pmi_pal);
42051 + pax_close_kernel();
42052 +#endif
42053 +
42054 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42055 if (pmi_base[3]) {
42056 printk(KERN_INFO "vesafb: pmi: ports = ");
42057 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42058 info->node, info->fix.id);
42059 return 0;
42060 err:
42061 +
42062 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42063 + module_free_exec(NULL, pmi_code);
42064 +#endif
42065 +
42066 if (info->screen_base)
42067 iounmap(info->screen_base);
42068 framebuffer_release(info);
42069 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42070 index 88714ae..16c2e11 100644
42071 --- a/drivers/video/via/via_clock.h
42072 +++ b/drivers/video/via/via_clock.h
42073 @@ -56,7 +56,7 @@ struct via_clock {
42074
42075 void (*set_engine_pll_state)(u8 state);
42076 void (*set_engine_pll)(struct via_pll_config config);
42077 -};
42078 +} __no_const;
42079
42080
42081 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42082 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42083 index e56c934..fc22f4b 100644
42084 --- a/drivers/xen/xen-pciback/conf_space.h
42085 +++ b/drivers/xen/xen-pciback/conf_space.h
42086 @@ -44,15 +44,15 @@ struct config_field {
42087 struct {
42088 conf_dword_write write;
42089 conf_dword_read read;
42090 - } dw;
42091 + } __no_const dw;
42092 struct {
42093 conf_word_write write;
42094 conf_word_read read;
42095 - } w;
42096 + } __no_const w;
42097 struct {
42098 conf_byte_write write;
42099 conf_byte_read read;
42100 - } b;
42101 + } __no_const b;
42102 } u;
42103 struct list_head list;
42104 };
42105 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42106 index 57ccb75..f6d05f8 100644
42107 --- a/fs/9p/vfs_inode.c
42108 +++ b/fs/9p/vfs_inode.c
42109 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42110 void
42111 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42112 {
42113 - char *s = nd_get_link(nd);
42114 + const char *s = nd_get_link(nd);
42115
42116 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42117 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42118 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42119 index 0225742..1cd4732 100644
42120 --- a/fs/Kconfig.binfmt
42121 +++ b/fs/Kconfig.binfmt
42122 @@ -89,7 +89,7 @@ config HAVE_AOUT
42123
42124 config BINFMT_AOUT
42125 tristate "Kernel support for a.out and ECOFF binaries"
42126 - depends on HAVE_AOUT
42127 + depends on HAVE_AOUT && BROKEN
42128 ---help---
42129 A.out (Assembler.OUTput) is a set of formats for libraries and
42130 executables used in the earliest versions of UNIX. Linux used
42131 diff --git a/fs/aio.c b/fs/aio.c
42132 index 55c4c76..11aee6f 100644
42133 --- a/fs/aio.c
42134 +++ b/fs/aio.c
42135 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42136 size += sizeof(struct io_event) * nr_events;
42137 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42138
42139 - if (nr_pages < 0)
42140 + if (nr_pages <= 0)
42141 return -EINVAL;
42142
42143 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42144 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42145 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42146 {
42147 ssize_t ret;
42148 + struct iovec iovstack;
42149
42150 #ifdef CONFIG_COMPAT
42151 if (compat)
42152 ret = compat_rw_copy_check_uvector(type,
42153 (struct compat_iovec __user *)kiocb->ki_buf,
42154 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42155 + kiocb->ki_nbytes, 1, &iovstack,
42156 &kiocb->ki_iovec);
42157 else
42158 #endif
42159 ret = rw_copy_check_uvector(type,
42160 (struct iovec __user *)kiocb->ki_buf,
42161 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42162 + kiocb->ki_nbytes, 1, &iovstack,
42163 &kiocb->ki_iovec);
42164 if (ret < 0)
42165 goto out;
42166 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42167 if (ret < 0)
42168 goto out;
42169
42170 + if (kiocb->ki_iovec == &iovstack) {
42171 + kiocb->ki_inline_vec = iovstack;
42172 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42173 + }
42174 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42175 kiocb->ki_cur_seg = 0;
42176 /* ki_nbytes/left now reflect bytes instead of segs */
42177 diff --git a/fs/attr.c b/fs/attr.c
42178 index 0da9095..1386693 100644
42179 --- a/fs/attr.c
42180 +++ b/fs/attr.c
42181 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42182 unsigned long limit;
42183
42184 limit = rlimit(RLIMIT_FSIZE);
42185 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42186 if (limit != RLIM_INFINITY && offset > limit)
42187 goto out_sig;
42188 if (offset > inode->i_sb->s_maxbytes)
42189 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42190 index da8876d..9f3e6d8 100644
42191 --- a/fs/autofs4/waitq.c
42192 +++ b/fs/autofs4/waitq.c
42193 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42194 {
42195 unsigned long sigpipe, flags;
42196 mm_segment_t fs;
42197 - const char *data = (const char *)addr;
42198 + const char __user *data = (const char __force_user *)addr;
42199 ssize_t wr = 0;
42200
42201 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42202 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42203 index e18da23..affc30e 100644
42204 --- a/fs/befs/linuxvfs.c
42205 +++ b/fs/befs/linuxvfs.c
42206 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42207 {
42208 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42209 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42210 - char *link = nd_get_link(nd);
42211 + const char *link = nd_get_link(nd);
42212 if (!IS_ERR(link))
42213 kfree(link);
42214 }
42215 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42216 index d146e18..12d1bd1 100644
42217 --- a/fs/binfmt_aout.c
42218 +++ b/fs/binfmt_aout.c
42219 @@ -16,6 +16,7 @@
42220 #include <linux/string.h>
42221 #include <linux/fs.h>
42222 #include <linux/file.h>
42223 +#include <linux/security.h>
42224 #include <linux/stat.h>
42225 #include <linux/fcntl.h>
42226 #include <linux/ptrace.h>
42227 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42228 #endif
42229 # define START_STACK(u) ((void __user *)u.start_stack)
42230
42231 + memset(&dump, 0, sizeof(dump));
42232 +
42233 fs = get_fs();
42234 set_fs(KERNEL_DS);
42235 has_dumped = 1;
42236 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42237
42238 /* If the size of the dump file exceeds the rlimit, then see what would happen
42239 if we wrote the stack, but not the data area. */
42240 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42241 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42242 dump.u_dsize = 0;
42243
42244 /* Make sure we have enough room to write the stack and data areas. */
42245 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42246 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42247 dump.u_ssize = 0;
42248
42249 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42250 rlim = rlimit(RLIMIT_DATA);
42251 if (rlim >= RLIM_INFINITY)
42252 rlim = ~0;
42253 +
42254 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42255 if (ex.a_data + ex.a_bss > rlim)
42256 return -ENOMEM;
42257
42258 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42259
42260 install_exec_creds(bprm);
42261
42262 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42263 + current->mm->pax_flags = 0UL;
42264 +#endif
42265 +
42266 +#ifdef CONFIG_PAX_PAGEEXEC
42267 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42268 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42269 +
42270 +#ifdef CONFIG_PAX_EMUTRAMP
42271 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42272 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42273 +#endif
42274 +
42275 +#ifdef CONFIG_PAX_MPROTECT
42276 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42277 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42278 +#endif
42279 +
42280 + }
42281 +#endif
42282 +
42283 if (N_MAGIC(ex) == OMAGIC) {
42284 unsigned long text_addr, map_size;
42285 loff_t pos;
42286 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42287 }
42288
42289 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42290 - PROT_READ | PROT_WRITE | PROT_EXEC,
42291 + PROT_READ | PROT_WRITE,
42292 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42293 fd_offset + ex.a_text);
42294 if (error != N_DATADDR(ex)) {
42295 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42296 index 1b52956..271266e 100644
42297 --- a/fs/binfmt_elf.c
42298 +++ b/fs/binfmt_elf.c
42299 @@ -32,6 +32,7 @@
42300 #include <linux/elf.h>
42301 #include <linux/utsname.h>
42302 #include <linux/coredump.h>
42303 +#include <linux/xattr.h>
42304 #include <asm/uaccess.h>
42305 #include <asm/param.h>
42306 #include <asm/page.h>
42307 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42308 #define elf_core_dump NULL
42309 #endif
42310
42311 +#ifdef CONFIG_PAX_MPROTECT
42312 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42313 +#endif
42314 +
42315 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42316 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42317 #else
42318 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42319 .load_binary = load_elf_binary,
42320 .load_shlib = load_elf_library,
42321 .core_dump = elf_core_dump,
42322 +
42323 +#ifdef CONFIG_PAX_MPROTECT
42324 + .handle_mprotect= elf_handle_mprotect,
42325 +#endif
42326 +
42327 .min_coredump = ELF_EXEC_PAGESIZE,
42328 };
42329
42330 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42331
42332 static int set_brk(unsigned long start, unsigned long end)
42333 {
42334 + unsigned long e = end;
42335 +
42336 start = ELF_PAGEALIGN(start);
42337 end = ELF_PAGEALIGN(end);
42338 if (end > start) {
42339 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42340 if (BAD_ADDR(addr))
42341 return addr;
42342 }
42343 - current->mm->start_brk = current->mm->brk = end;
42344 + current->mm->start_brk = current->mm->brk = e;
42345 return 0;
42346 }
42347
42348 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42349 elf_addr_t __user *u_rand_bytes;
42350 const char *k_platform = ELF_PLATFORM;
42351 const char *k_base_platform = ELF_BASE_PLATFORM;
42352 - unsigned char k_rand_bytes[16];
42353 + u32 k_rand_bytes[4];
42354 int items;
42355 elf_addr_t *elf_info;
42356 int ei_index = 0;
42357 const struct cred *cred = current_cred();
42358 struct vm_area_struct *vma;
42359 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42360
42361 /*
42362 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42363 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42364 * Generate 16 random bytes for userspace PRNG seeding.
42365 */
42366 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42367 - u_rand_bytes = (elf_addr_t __user *)
42368 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42369 + srandom32(k_rand_bytes[0] ^ random32());
42370 + srandom32(k_rand_bytes[1] ^ random32());
42371 + srandom32(k_rand_bytes[2] ^ random32());
42372 + srandom32(k_rand_bytes[3] ^ random32());
42373 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42374 + u_rand_bytes = (elf_addr_t __user *) p;
42375 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42376 return -EFAULT;
42377
42378 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42379 return -EFAULT;
42380 current->mm->env_end = p;
42381
42382 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42383 +
42384 /* Put the elf_info on the stack in the right place. */
42385 sp = (elf_addr_t __user *)envp + 1;
42386 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42387 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42388 return -EFAULT;
42389 return 0;
42390 }
42391 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42392 {
42393 struct elf_phdr *elf_phdata;
42394 struct elf_phdr *eppnt;
42395 - unsigned long load_addr = 0;
42396 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42397 int load_addr_set = 0;
42398 unsigned long last_bss = 0, elf_bss = 0;
42399 - unsigned long error = ~0UL;
42400 + unsigned long error = -EINVAL;
42401 unsigned long total_size;
42402 int retval, i, size;
42403
42404 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42405 goto out_close;
42406 }
42407
42408 +#ifdef CONFIG_PAX_SEGMEXEC
42409 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42410 + pax_task_size = SEGMEXEC_TASK_SIZE;
42411 +#endif
42412 +
42413 eppnt = elf_phdata;
42414 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42415 if (eppnt->p_type == PT_LOAD) {
42416 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42417 k = load_addr + eppnt->p_vaddr;
42418 if (BAD_ADDR(k) ||
42419 eppnt->p_filesz > eppnt->p_memsz ||
42420 - eppnt->p_memsz > TASK_SIZE ||
42421 - TASK_SIZE - eppnt->p_memsz < k) {
42422 + eppnt->p_memsz > pax_task_size ||
42423 + pax_task_size - eppnt->p_memsz < k) {
42424 error = -ENOMEM;
42425 goto out_close;
42426 }
42427 @@ -523,6 +547,311 @@ out:
42428 return error;
42429 }
42430
42431 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42432 +#ifdef CONFIG_PAX_SOFTMODE
42433 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42434 +{
42435 + unsigned long pax_flags = 0UL;
42436 +
42437 +#ifdef CONFIG_PAX_PAGEEXEC
42438 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42439 + pax_flags |= MF_PAX_PAGEEXEC;
42440 +#endif
42441 +
42442 +#ifdef CONFIG_PAX_SEGMEXEC
42443 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42444 + pax_flags |= MF_PAX_SEGMEXEC;
42445 +#endif
42446 +
42447 +#ifdef CONFIG_PAX_EMUTRAMP
42448 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42449 + pax_flags |= MF_PAX_EMUTRAMP;
42450 +#endif
42451 +
42452 +#ifdef CONFIG_PAX_MPROTECT
42453 + if (elf_phdata->p_flags & PF_MPROTECT)
42454 + pax_flags |= MF_PAX_MPROTECT;
42455 +#endif
42456 +
42457 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42458 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42459 + pax_flags |= MF_PAX_RANDMMAP;
42460 +#endif
42461 +
42462 + return pax_flags;
42463 +}
42464 +#endif
42465 +
42466 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42467 +{
42468 + unsigned long pax_flags = 0UL;
42469 +
42470 +#ifdef CONFIG_PAX_PAGEEXEC
42471 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42472 + pax_flags |= MF_PAX_PAGEEXEC;
42473 +#endif
42474 +
42475 +#ifdef CONFIG_PAX_SEGMEXEC
42476 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42477 + pax_flags |= MF_PAX_SEGMEXEC;
42478 +#endif
42479 +
42480 +#ifdef CONFIG_PAX_EMUTRAMP
42481 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42482 + pax_flags |= MF_PAX_EMUTRAMP;
42483 +#endif
42484 +
42485 +#ifdef CONFIG_PAX_MPROTECT
42486 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42487 + pax_flags |= MF_PAX_MPROTECT;
42488 +#endif
42489 +
42490 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42491 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42492 + pax_flags |= MF_PAX_RANDMMAP;
42493 +#endif
42494 +
42495 + return pax_flags;
42496 +}
42497 +#endif
42498 +
42499 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42500 +#ifdef CONFIG_PAX_SOFTMODE
42501 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42502 +{
42503 + unsigned long pax_flags = 0UL;
42504 +
42505 +#ifdef CONFIG_PAX_PAGEEXEC
42506 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42507 + pax_flags |= MF_PAX_PAGEEXEC;
42508 +#endif
42509 +
42510 +#ifdef CONFIG_PAX_SEGMEXEC
42511 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42512 + pax_flags |= MF_PAX_SEGMEXEC;
42513 +#endif
42514 +
42515 +#ifdef CONFIG_PAX_EMUTRAMP
42516 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42517 + pax_flags |= MF_PAX_EMUTRAMP;
42518 +#endif
42519 +
42520 +#ifdef CONFIG_PAX_MPROTECT
42521 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42522 + pax_flags |= MF_PAX_MPROTECT;
42523 +#endif
42524 +
42525 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42526 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42527 + pax_flags |= MF_PAX_RANDMMAP;
42528 +#endif
42529 +
42530 + return pax_flags;
42531 +}
42532 +#endif
42533 +
42534 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42535 +{
42536 + unsigned long pax_flags = 0UL;
42537 +
42538 +#ifdef CONFIG_PAX_PAGEEXEC
42539 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42540 + pax_flags |= MF_PAX_PAGEEXEC;
42541 +#endif
42542 +
42543 +#ifdef CONFIG_PAX_SEGMEXEC
42544 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42545 + pax_flags |= MF_PAX_SEGMEXEC;
42546 +#endif
42547 +
42548 +#ifdef CONFIG_PAX_EMUTRAMP
42549 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42550 + pax_flags |= MF_PAX_EMUTRAMP;
42551 +#endif
42552 +
42553 +#ifdef CONFIG_PAX_MPROTECT
42554 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42555 + pax_flags |= MF_PAX_MPROTECT;
42556 +#endif
42557 +
42558 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42559 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42560 + pax_flags |= MF_PAX_RANDMMAP;
42561 +#endif
42562 +
42563 + return pax_flags;
42564 +}
42565 +#endif
42566 +
42567 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42568 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42569 +{
42570 + unsigned long pax_flags = 0UL;
42571 +
42572 +#ifdef CONFIG_PAX_EI_PAX
42573 +
42574 +#ifdef CONFIG_PAX_PAGEEXEC
42575 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42576 + pax_flags |= MF_PAX_PAGEEXEC;
42577 +#endif
42578 +
42579 +#ifdef CONFIG_PAX_SEGMEXEC
42580 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42581 + pax_flags |= MF_PAX_SEGMEXEC;
42582 +#endif
42583 +
42584 +#ifdef CONFIG_PAX_EMUTRAMP
42585 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42586 + pax_flags |= MF_PAX_EMUTRAMP;
42587 +#endif
42588 +
42589 +#ifdef CONFIG_PAX_MPROTECT
42590 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42591 + pax_flags |= MF_PAX_MPROTECT;
42592 +#endif
42593 +
42594 +#ifdef CONFIG_PAX_ASLR
42595 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42596 + pax_flags |= MF_PAX_RANDMMAP;
42597 +#endif
42598 +
42599 +#else
42600 +
42601 +#ifdef CONFIG_PAX_PAGEEXEC
42602 + pax_flags |= MF_PAX_PAGEEXEC;
42603 +#endif
42604 +
42605 +#ifdef CONFIG_PAX_SEGMEXEC
42606 + pax_flags |= MF_PAX_SEGMEXEC;
42607 +#endif
42608 +
42609 +#ifdef CONFIG_PAX_MPROTECT
42610 + pax_flags |= MF_PAX_MPROTECT;
42611 +#endif
42612 +
42613 +#ifdef CONFIG_PAX_RANDMMAP
42614 + if (randomize_va_space)
42615 + pax_flags |= MF_PAX_RANDMMAP;
42616 +#endif
42617 +
42618 +#endif
42619 +
42620 + return pax_flags;
42621 +}
42622 +
42623 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42624 +{
42625 +
42626 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42627 + unsigned long i;
42628 +
42629 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42630 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42631 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42632 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42633 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42634 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42635 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42636 + return ~0UL;
42637 +
42638 +#ifdef CONFIG_PAX_SOFTMODE
42639 + if (pax_softmode)
42640 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42641 + else
42642 +#endif
42643 +
42644 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42645 + break;
42646 + }
42647 +#endif
42648 +
42649 + return ~0UL;
42650 +}
42651 +
42652 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42653 +{
42654 +
42655 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42656 + ssize_t xattr_size, i;
42657 + unsigned char xattr_value[5];
42658 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42659 +
42660 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42661 + if (xattr_size <= 0)
42662 + return ~0UL;
42663 +
42664 + for (i = 0; i < xattr_size; i++)
42665 + switch (xattr_value[i]) {
42666 + default:
42667 + return ~0UL;
42668 +
42669 +#define parse_flag(option1, option2, flag) \
42670 + case option1: \
42671 + pax_flags_hardmode |= MF_PAX_##flag; \
42672 + break; \
42673 + case option2: \
42674 + pax_flags_softmode |= MF_PAX_##flag; \
42675 + break;
42676 +
42677 + parse_flag('p', 'P', PAGEEXEC);
42678 + parse_flag('e', 'E', EMUTRAMP);
42679 + parse_flag('m', 'M', MPROTECT);
42680 + parse_flag('r', 'R', RANDMMAP);
42681 + parse_flag('s', 'S', SEGMEXEC);
42682 +
42683 +#undef parse_flag
42684 + }
42685 +
42686 + if (pax_flags_hardmode & pax_flags_softmode)
42687 + return ~0UL;
42688 +
42689 +#ifdef CONFIG_PAX_SOFTMODE
42690 + if (pax_softmode)
42691 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42692 + else
42693 +#endif
42694 +
42695 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42696 +#else
42697 + return ~0UL;
42698 +#endif
42699 +
42700 +}
42701 +
42702 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42703 +{
42704 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42705 +
42706 + pax_flags = pax_parse_ei_pax(elf_ex);
42707 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42708 + xattr_pax_flags = pax_parse_xattr_pax(file);
42709 +
42710 + if (pt_pax_flags == ~0UL)
42711 + pt_pax_flags = xattr_pax_flags;
42712 + else if (xattr_pax_flags == ~0UL)
42713 + xattr_pax_flags = pt_pax_flags;
42714 + if (pt_pax_flags != xattr_pax_flags)
42715 + return -EINVAL;
42716 + if (pt_pax_flags != ~0UL)
42717 + pax_flags = pt_pax_flags;
42718 +
42719 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42720 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42721 + if ((__supported_pte_mask & _PAGE_NX))
42722 + pax_flags &= ~MF_PAX_SEGMEXEC;
42723 + else
42724 + pax_flags &= ~MF_PAX_PAGEEXEC;
42725 + }
42726 +#endif
42727 +
42728 + if (0 > pax_check_flags(&pax_flags))
42729 + return -EINVAL;
42730 +
42731 + current->mm->pax_flags = pax_flags;
42732 + return 0;
42733 +}
42734 +#endif
42735 +
42736 /*
42737 * These are the functions used to load ELF style executables and shared
42738 * libraries. There is no binary dependent code anywhere else.
42739 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42740 {
42741 unsigned int random_variable = 0;
42742
42743 +#ifdef CONFIG_PAX_RANDUSTACK
42744 + if (randomize_va_space)
42745 + return stack_top - current->mm->delta_stack;
42746 +#endif
42747 +
42748 if ((current->flags & PF_RANDOMIZE) &&
42749 !(current->personality & ADDR_NO_RANDOMIZE)) {
42750 random_variable = get_random_int() & STACK_RND_MASK;
42751 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42752 unsigned long load_addr = 0, load_bias = 0;
42753 int load_addr_set = 0;
42754 char * elf_interpreter = NULL;
42755 - unsigned long error;
42756 + unsigned long error = 0;
42757 struct elf_phdr *elf_ppnt, *elf_phdata;
42758 unsigned long elf_bss, elf_brk;
42759 int retval, i;
42760 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42761 unsigned long start_code, end_code, start_data, end_data;
42762 unsigned long reloc_func_desc __maybe_unused = 0;
42763 int executable_stack = EXSTACK_DEFAULT;
42764 - unsigned long def_flags = 0;
42765 struct {
42766 struct elfhdr elf_ex;
42767 struct elfhdr interp_elf_ex;
42768 } *loc;
42769 + unsigned long pax_task_size = TASK_SIZE;
42770
42771 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42772 if (!loc) {
42773 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42774 goto out_free_dentry;
42775
42776 /* OK, This is the point of no return */
42777 - current->mm->def_flags = def_flags;
42778 +
42779 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42780 + current->mm->pax_flags = 0UL;
42781 +#endif
42782 +
42783 +#ifdef CONFIG_PAX_DLRESOLVE
42784 + current->mm->call_dl_resolve = 0UL;
42785 +#endif
42786 +
42787 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42788 + current->mm->call_syscall = 0UL;
42789 +#endif
42790 +
42791 +#ifdef CONFIG_PAX_ASLR
42792 + current->mm->delta_mmap = 0UL;
42793 + current->mm->delta_stack = 0UL;
42794 +#endif
42795 +
42796 + current->mm->def_flags = 0;
42797 +
42798 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42799 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42800 + send_sig(SIGKILL, current, 0);
42801 + goto out_free_dentry;
42802 + }
42803 +#endif
42804 +
42805 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42806 + pax_set_initial_flags(bprm);
42807 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42808 + if (pax_set_initial_flags_func)
42809 + (pax_set_initial_flags_func)(bprm);
42810 +#endif
42811 +
42812 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42813 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42814 + current->mm->context.user_cs_limit = PAGE_SIZE;
42815 + current->mm->def_flags |= VM_PAGEEXEC;
42816 + }
42817 +#endif
42818 +
42819 +#ifdef CONFIG_PAX_SEGMEXEC
42820 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42821 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42822 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42823 + pax_task_size = SEGMEXEC_TASK_SIZE;
42824 + current->mm->def_flags |= VM_NOHUGEPAGE;
42825 + }
42826 +#endif
42827 +
42828 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42829 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42830 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42831 + put_cpu();
42832 + }
42833 +#endif
42834
42835 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42836 may depend on the personality. */
42837 SET_PERSONALITY(loc->elf_ex);
42838 +
42839 +#ifdef CONFIG_PAX_ASLR
42840 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42841 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42842 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42843 + }
42844 +#endif
42845 +
42846 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42847 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42848 + executable_stack = EXSTACK_DISABLE_X;
42849 + current->personality &= ~READ_IMPLIES_EXEC;
42850 + } else
42851 +#endif
42852 +
42853 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42854 current->personality |= READ_IMPLIES_EXEC;
42855
42856 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42857 #else
42858 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42859 #endif
42860 +
42861 +#ifdef CONFIG_PAX_RANDMMAP
42862 + /* PaX: randomize base address at the default exe base if requested */
42863 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42864 +#ifdef CONFIG_SPARC64
42865 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42866 +#else
42867 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42868 +#endif
42869 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42870 + elf_flags |= MAP_FIXED;
42871 + }
42872 +#endif
42873 +
42874 }
42875
42876 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42877 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42878 * allowed task size. Note that p_filesz must always be
42879 * <= p_memsz so it is only necessary to check p_memsz.
42880 */
42881 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42882 - elf_ppnt->p_memsz > TASK_SIZE ||
42883 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42884 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42885 + elf_ppnt->p_memsz > pax_task_size ||
42886 + pax_task_size - elf_ppnt->p_memsz < k) {
42887 /* set_brk can never work. Avoid overflows. */
42888 send_sig(SIGKILL, current, 0);
42889 retval = -EINVAL;
42890 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42891 goto out_free_dentry;
42892 }
42893 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42894 - send_sig(SIGSEGV, current, 0);
42895 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42896 - goto out_free_dentry;
42897 + /*
42898 + * This bss-zeroing can fail if the ELF
42899 + * file specifies odd protections. So
42900 + * we don't check the return value
42901 + */
42902 }
42903
42904 +#ifdef CONFIG_PAX_RANDMMAP
42905 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42906 + unsigned long start, size;
42907 +
42908 + start = ELF_PAGEALIGN(elf_brk);
42909 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42910 + down_read(&current->mm->mmap_sem);
42911 + retval = -ENOMEM;
42912 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42913 + unsigned long prot = PROT_NONE;
42914 +
42915 + up_read(&current->mm->mmap_sem);
42916 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42917 +// if (current->personality & ADDR_NO_RANDOMIZE)
42918 +// prot = PROT_READ;
42919 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42920 + retval = IS_ERR_VALUE(start) ? start : 0;
42921 + } else
42922 + up_read(&current->mm->mmap_sem);
42923 + if (retval == 0)
42924 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42925 + if (retval < 0) {
42926 + send_sig(SIGKILL, current, 0);
42927 + goto out_free_dentry;
42928 + }
42929 + }
42930 +#endif
42931 +
42932 if (elf_interpreter) {
42933 unsigned long uninitialized_var(interp_map_addr);
42934
42935 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42936 * Decide what to dump of a segment, part, all or none.
42937 */
42938 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42939 - unsigned long mm_flags)
42940 + unsigned long mm_flags, long signr)
42941 {
42942 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42943
42944 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42945 if (vma->vm_file == NULL)
42946 return 0;
42947
42948 - if (FILTER(MAPPED_PRIVATE))
42949 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42950 goto whole;
42951
42952 /*
42953 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42954 {
42955 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42956 int i = 0;
42957 - do
42958 + do {
42959 i += 2;
42960 - while (auxv[i - 2] != AT_NULL);
42961 + } while (auxv[i - 2] != AT_NULL);
42962 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42963 }
42964
42965 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42966 }
42967
42968 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42969 - unsigned long mm_flags)
42970 + struct coredump_params *cprm)
42971 {
42972 struct vm_area_struct *vma;
42973 size_t size = 0;
42974
42975 for (vma = first_vma(current, gate_vma); vma != NULL;
42976 vma = next_vma(vma, gate_vma))
42977 - size += vma_dump_size(vma, mm_flags);
42978 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42979 return size;
42980 }
42981
42982 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42983
42984 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42985
42986 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42987 + offset += elf_core_vma_data_size(gate_vma, cprm);
42988 offset += elf_core_extra_data_size();
42989 e_shoff = offset;
42990
42991 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42992 offset = dataoff;
42993
42994 size += sizeof(*elf);
42995 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42996 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42997 goto end_coredump;
42998
42999 size += sizeof(*phdr4note);
43000 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43001 if (size > cprm->limit
43002 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43003 goto end_coredump;
43004 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43005 phdr.p_offset = offset;
43006 phdr.p_vaddr = vma->vm_start;
43007 phdr.p_paddr = 0;
43008 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43009 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43010 phdr.p_memsz = vma->vm_end - vma->vm_start;
43011 offset += phdr.p_filesz;
43012 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43013 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43014 phdr.p_align = ELF_EXEC_PAGESIZE;
43015
43016 size += sizeof(phdr);
43017 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43018 if (size > cprm->limit
43019 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43020 goto end_coredump;
43021 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43022 unsigned long addr;
43023 unsigned long end;
43024
43025 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43026 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43027
43028 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43029 struct page *page;
43030 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43031 page = get_dump_page(addr);
43032 if (page) {
43033 void *kaddr = kmap(page);
43034 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43035 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43036 !dump_write(cprm->file, kaddr,
43037 PAGE_SIZE);
43038 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43039
43040 if (e_phnum == PN_XNUM) {
43041 size += sizeof(*shdr4extnum);
43042 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43043 if (size > cprm->limit
43044 || !dump_write(cprm->file, shdr4extnum,
43045 sizeof(*shdr4extnum)))
43046 @@ -2103,6 +2556,97 @@ out:
43047
43048 #endif /* CONFIG_ELF_CORE */
43049
43050 +#ifdef CONFIG_PAX_MPROTECT
43051 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43052 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43053 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43054 + *
43055 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43056 + * basis because we want to allow the common case and not the special ones.
43057 + */
43058 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43059 +{
43060 + struct elfhdr elf_h;
43061 + struct elf_phdr elf_p;
43062 + unsigned long i;
43063 + unsigned long oldflags;
43064 + bool is_textrel_rw, is_textrel_rx, is_relro;
43065 +
43066 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43067 + return;
43068 +
43069 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43070 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43071 +
43072 +#ifdef CONFIG_PAX_ELFRELOCS
43073 + /* possible TEXTREL */
43074 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43075 + 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);
43076 +#else
43077 + is_textrel_rw = false;
43078 + is_textrel_rx = false;
43079 +#endif
43080 +
43081 + /* possible RELRO */
43082 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43083 +
43084 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43085 + return;
43086 +
43087 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43088 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43089 +
43090 +#ifdef CONFIG_PAX_ETEXECRELOCS
43091 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43092 +#else
43093 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43094 +#endif
43095 +
43096 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43097 + !elf_check_arch(&elf_h) ||
43098 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43099 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43100 + return;
43101 +
43102 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43103 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43104 + return;
43105 + switch (elf_p.p_type) {
43106 + case PT_DYNAMIC:
43107 + if (!is_textrel_rw && !is_textrel_rx)
43108 + continue;
43109 + i = 0UL;
43110 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43111 + elf_dyn dyn;
43112 +
43113 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43114 + return;
43115 + if (dyn.d_tag == DT_NULL)
43116 + return;
43117 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43118 + gr_log_textrel(vma);
43119 + if (is_textrel_rw)
43120 + vma->vm_flags |= VM_MAYWRITE;
43121 + else
43122 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43123 + vma->vm_flags &= ~VM_MAYWRITE;
43124 + return;
43125 + }
43126 + i++;
43127 + }
43128 + return;
43129 +
43130 + case PT_GNU_RELRO:
43131 + if (!is_relro)
43132 + continue;
43133 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43134 + vma->vm_flags &= ~VM_MAYWRITE;
43135 + return;
43136 + }
43137 + }
43138 +}
43139 +#endif
43140 +
43141 static int __init init_elf_binfmt(void)
43142 {
43143 register_binfmt(&elf_format);
43144 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43145 index 178cb70..8972997 100644
43146 --- a/fs/binfmt_flat.c
43147 +++ b/fs/binfmt_flat.c
43148 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43149 realdatastart = (unsigned long) -ENOMEM;
43150 printk("Unable to allocate RAM for process data, errno %d\n",
43151 (int)-realdatastart);
43152 + down_write(&current->mm->mmap_sem);
43153 vm_munmap(textpos, text_len);
43154 + up_write(&current->mm->mmap_sem);
43155 ret = realdatastart;
43156 goto err;
43157 }
43158 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43159 }
43160 if (IS_ERR_VALUE(result)) {
43161 printk("Unable to read data+bss, errno %d\n", (int)-result);
43162 + down_write(&current->mm->mmap_sem);
43163 vm_munmap(textpos, text_len);
43164 vm_munmap(realdatastart, len);
43165 + up_write(&current->mm->mmap_sem);
43166 ret = result;
43167 goto err;
43168 }
43169 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43170 }
43171 if (IS_ERR_VALUE(result)) {
43172 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43173 + down_write(&current->mm->mmap_sem);
43174 vm_munmap(textpos, text_len + data_len + extra +
43175 MAX_SHARED_LIBS * sizeof(unsigned long));
43176 + up_write(&current->mm->mmap_sem);
43177 ret = result;
43178 goto err;
43179 }
43180 diff --git a/fs/bio.c b/fs/bio.c
43181 index 73922ab..16642dd 100644
43182 --- a/fs/bio.c
43183 +++ b/fs/bio.c
43184 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43185 /*
43186 * Overflow, abort
43187 */
43188 - if (end < start)
43189 + if (end < start || end - start > INT_MAX - nr_pages)
43190 return ERR_PTR(-EINVAL);
43191
43192 nr_pages += end - start;
43193 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43194 /*
43195 * Overflow, abort
43196 */
43197 - if (end < start)
43198 + if (end < start || end - start > INT_MAX - nr_pages)
43199 return ERR_PTR(-EINVAL);
43200
43201 nr_pages += end - start;
43202 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43203 const int read = bio_data_dir(bio) == READ;
43204 struct bio_map_data *bmd = bio->bi_private;
43205 int i;
43206 - char *p = bmd->sgvecs[0].iov_base;
43207 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43208
43209 __bio_for_each_segment(bvec, bio, i, 0) {
43210 char *addr = page_address(bvec->bv_page);
43211 diff --git a/fs/block_dev.c b/fs/block_dev.c
43212 index c2bbe1f..9dfbc23 100644
43213 --- a/fs/block_dev.c
43214 +++ b/fs/block_dev.c
43215 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43216 else if (bdev->bd_contains == bdev)
43217 return true; /* is a whole device which isn't held */
43218
43219 - else if (whole->bd_holder == bd_may_claim)
43220 + else if (whole->bd_holder == (void *)bd_may_claim)
43221 return true; /* is a partition of a device that is being partitioned */
43222 else if (whole->bd_holder != NULL)
43223 return false; /* is a partition of a held device */
43224 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43225 index da6e936..1598dd0 100644
43226 --- a/fs/btrfs/check-integrity.c
43227 +++ b/fs/btrfs/check-integrity.c
43228 @@ -155,7 +155,7 @@ struct btrfsic_block {
43229 union {
43230 bio_end_io_t *bio;
43231 bh_end_io_t *bh;
43232 - } orig_bio_bh_end_io;
43233 + } __no_const orig_bio_bh_end_io;
43234 int submit_bio_bh_rw;
43235 u64 flush_gen; /* only valid if !never_written */
43236 };
43237 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43238 index 8206b39..06d5654 100644
43239 --- a/fs/btrfs/ctree.c
43240 +++ b/fs/btrfs/ctree.c
43241 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43242 free_extent_buffer(buf);
43243 add_root_to_dirty_list(root);
43244 } else {
43245 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43246 - parent_start = parent->start;
43247 - else
43248 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43249 + if (parent)
43250 + parent_start = parent->start;
43251 + else
43252 + parent_start = 0;
43253 + } else
43254 parent_start = 0;
43255
43256 WARN_ON(trans->transid != btrfs_header_generation(parent));
43257 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43258 index a7d1921..a32dba2 100644
43259 --- a/fs/btrfs/inode.c
43260 +++ b/fs/btrfs/inode.c
43261 @@ -7111,7 +7111,7 @@ fail:
43262 return -ENOMEM;
43263 }
43264
43265 -static int btrfs_getattr(struct vfsmount *mnt,
43266 +int btrfs_getattr(struct vfsmount *mnt,
43267 struct dentry *dentry, struct kstat *stat)
43268 {
43269 struct inode *inode = dentry->d_inode;
43270 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43271 return 0;
43272 }
43273
43274 +EXPORT_SYMBOL(btrfs_getattr);
43275 +
43276 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43277 +{
43278 + return BTRFS_I(inode)->root->anon_dev;
43279 +}
43280 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43281 +
43282 /*
43283 * If a file is moved, it will inherit the cow and compression flags of the new
43284 * directory.
43285 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43286 index 0e92e57..8b560de 100644
43287 --- a/fs/btrfs/ioctl.c
43288 +++ b/fs/btrfs/ioctl.c
43289 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43290 for (i = 0; i < num_types; i++) {
43291 struct btrfs_space_info *tmp;
43292
43293 + /* Don't copy in more than we allocated */
43294 if (!slot_count)
43295 break;
43296
43297 + slot_count--;
43298 +
43299 info = NULL;
43300 rcu_read_lock();
43301 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43302 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43303 memcpy(dest, &space, sizeof(space));
43304 dest++;
43305 space_args.total_spaces++;
43306 - slot_count--;
43307 }
43308 - if (!slot_count)
43309 - break;
43310 }
43311 up_read(&info->groups_sem);
43312 }
43313 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43314 index 646ee21..f020f87 100644
43315 --- a/fs/btrfs/relocation.c
43316 +++ b/fs/btrfs/relocation.c
43317 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43318 }
43319 spin_unlock(&rc->reloc_root_tree.lock);
43320
43321 - BUG_ON((struct btrfs_root *)node->data != root);
43322 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43323
43324 if (!del) {
43325 spin_lock(&rc->reloc_root_tree.lock);
43326 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43327 index 622f469..e8d2d55 100644
43328 --- a/fs/cachefiles/bind.c
43329 +++ b/fs/cachefiles/bind.c
43330 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43331 args);
43332
43333 /* start by checking things over */
43334 - ASSERT(cache->fstop_percent >= 0 &&
43335 - cache->fstop_percent < cache->fcull_percent &&
43336 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43337 cache->fcull_percent < cache->frun_percent &&
43338 cache->frun_percent < 100);
43339
43340 - ASSERT(cache->bstop_percent >= 0 &&
43341 - cache->bstop_percent < cache->bcull_percent &&
43342 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43343 cache->bcull_percent < cache->brun_percent &&
43344 cache->brun_percent < 100);
43345
43346 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43347 index 0a1467b..6a53245 100644
43348 --- a/fs/cachefiles/daemon.c
43349 +++ b/fs/cachefiles/daemon.c
43350 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43351 if (n > buflen)
43352 return -EMSGSIZE;
43353
43354 - if (copy_to_user(_buffer, buffer, n) != 0)
43355 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43356 return -EFAULT;
43357
43358 return n;
43359 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43360 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43361 return -EIO;
43362
43363 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43364 + if (datalen > PAGE_SIZE - 1)
43365 return -EOPNOTSUPP;
43366
43367 /* drag the command string into the kernel so we can parse it */
43368 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43369 if (args[0] != '%' || args[1] != '\0')
43370 return -EINVAL;
43371
43372 - if (fstop < 0 || fstop >= cache->fcull_percent)
43373 + if (fstop >= cache->fcull_percent)
43374 return cachefiles_daemon_range_error(cache, args);
43375
43376 cache->fstop_percent = fstop;
43377 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43378 if (args[0] != '%' || args[1] != '\0')
43379 return -EINVAL;
43380
43381 - if (bstop < 0 || bstop >= cache->bcull_percent)
43382 + if (bstop >= cache->bcull_percent)
43383 return cachefiles_daemon_range_error(cache, args);
43384
43385 cache->bstop_percent = bstop;
43386 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43387 index bd6bc1b..b627b53 100644
43388 --- a/fs/cachefiles/internal.h
43389 +++ b/fs/cachefiles/internal.h
43390 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43391 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43392 struct rb_root active_nodes; /* active nodes (can't be culled) */
43393 rwlock_t active_lock; /* lock for active_nodes */
43394 - atomic_t gravecounter; /* graveyard uniquifier */
43395 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43396 unsigned frun_percent; /* when to stop culling (% files) */
43397 unsigned fcull_percent; /* when to start culling (% files) */
43398 unsigned fstop_percent; /* when to stop allocating (% files) */
43399 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43400 * proc.c
43401 */
43402 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43403 -extern atomic_t cachefiles_lookup_histogram[HZ];
43404 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43405 -extern atomic_t cachefiles_create_histogram[HZ];
43406 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43407 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43408 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43409
43410 extern int __init cachefiles_proc_init(void);
43411 extern void cachefiles_proc_cleanup(void);
43412 static inline
43413 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43414 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43415 {
43416 unsigned long jif = jiffies - start_jif;
43417 if (jif >= HZ)
43418 jif = HZ - 1;
43419 - atomic_inc(&histogram[jif]);
43420 + atomic_inc_unchecked(&histogram[jif]);
43421 }
43422
43423 #else
43424 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43425 index 7f0771d..87d4f36 100644
43426 --- a/fs/cachefiles/namei.c
43427 +++ b/fs/cachefiles/namei.c
43428 @@ -318,7 +318,7 @@ try_again:
43429 /* first step is to make up a grave dentry in the graveyard */
43430 sprintf(nbuffer, "%08x%08x",
43431 (uint32_t) get_seconds(),
43432 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43433 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43434
43435 /* do the multiway lock magic */
43436 trap = lock_rename(cache->graveyard, dir);
43437 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43438 index eccd339..4c1d995 100644
43439 --- a/fs/cachefiles/proc.c
43440 +++ b/fs/cachefiles/proc.c
43441 @@ -14,9 +14,9 @@
43442 #include <linux/seq_file.h>
43443 #include "internal.h"
43444
43445 -atomic_t cachefiles_lookup_histogram[HZ];
43446 -atomic_t cachefiles_mkdir_histogram[HZ];
43447 -atomic_t cachefiles_create_histogram[HZ];
43448 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43449 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43450 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43451
43452 /*
43453 * display the latency histogram
43454 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43455 return 0;
43456 default:
43457 index = (unsigned long) v - 3;
43458 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43459 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43460 - z = atomic_read(&cachefiles_create_histogram[index]);
43461 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43462 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43463 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43464 if (x == 0 && y == 0 && z == 0)
43465 return 0;
43466
43467 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43468 index 0e3c092..818480e 100644
43469 --- a/fs/cachefiles/rdwr.c
43470 +++ b/fs/cachefiles/rdwr.c
43471 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43472 old_fs = get_fs();
43473 set_fs(KERNEL_DS);
43474 ret = file->f_op->write(
43475 - file, (const void __user *) data, len, &pos);
43476 + file, (const void __force_user *) data, len, &pos);
43477 set_fs(old_fs);
43478 kunmap(page);
43479 if (ret != len)
43480 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43481 index 3e8094b..cb3ff3d 100644
43482 --- a/fs/ceph/dir.c
43483 +++ b/fs/ceph/dir.c
43484 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43485 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43486 struct ceph_mds_client *mdsc = fsc->mdsc;
43487 unsigned frag = fpos_frag(filp->f_pos);
43488 - int off = fpos_off(filp->f_pos);
43489 + unsigned int off = fpos_off(filp->f_pos);
43490 int err;
43491 u32 ftype;
43492 struct ceph_mds_reply_info_parsed *rinfo;
43493 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43494 if (nd &&
43495 (nd->flags & LOOKUP_OPEN) &&
43496 !(nd->intent.open.flags & O_CREAT)) {
43497 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43498 + int mode = nd->intent.open.create_mode & ~current_umask();
43499 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43500 }
43501
43502 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43503 index e814052..28dcdf7 100644
43504 --- a/fs/cifs/cifs_debug.c
43505 +++ b/fs/cifs/cifs_debug.c
43506 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43507
43508 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43509 #ifdef CONFIG_CIFS_STATS2
43510 - atomic_set(&totBufAllocCount, 0);
43511 - atomic_set(&totSmBufAllocCount, 0);
43512 + atomic_set_unchecked(&totBufAllocCount, 0);
43513 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43514 #endif /* CONFIG_CIFS_STATS2 */
43515 spin_lock(&cifs_tcp_ses_lock);
43516 list_for_each(tmp1, &cifs_tcp_ses_list) {
43517 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43518 tcon = list_entry(tmp3,
43519 struct cifs_tcon,
43520 tcon_list);
43521 - atomic_set(&tcon->num_smbs_sent, 0);
43522 - atomic_set(&tcon->num_writes, 0);
43523 - atomic_set(&tcon->num_reads, 0);
43524 - atomic_set(&tcon->num_oplock_brks, 0);
43525 - atomic_set(&tcon->num_opens, 0);
43526 - atomic_set(&tcon->num_posixopens, 0);
43527 - atomic_set(&tcon->num_posixmkdirs, 0);
43528 - atomic_set(&tcon->num_closes, 0);
43529 - atomic_set(&tcon->num_deletes, 0);
43530 - atomic_set(&tcon->num_mkdirs, 0);
43531 - atomic_set(&tcon->num_rmdirs, 0);
43532 - atomic_set(&tcon->num_renames, 0);
43533 - atomic_set(&tcon->num_t2renames, 0);
43534 - atomic_set(&tcon->num_ffirst, 0);
43535 - atomic_set(&tcon->num_fnext, 0);
43536 - atomic_set(&tcon->num_fclose, 0);
43537 - atomic_set(&tcon->num_hardlinks, 0);
43538 - atomic_set(&tcon->num_symlinks, 0);
43539 - atomic_set(&tcon->num_locks, 0);
43540 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43541 + atomic_set_unchecked(&tcon->num_writes, 0);
43542 + atomic_set_unchecked(&tcon->num_reads, 0);
43543 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43544 + atomic_set_unchecked(&tcon->num_opens, 0);
43545 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43546 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43547 + atomic_set_unchecked(&tcon->num_closes, 0);
43548 + atomic_set_unchecked(&tcon->num_deletes, 0);
43549 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43550 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43551 + atomic_set_unchecked(&tcon->num_renames, 0);
43552 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43553 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43554 + atomic_set_unchecked(&tcon->num_fnext, 0);
43555 + atomic_set_unchecked(&tcon->num_fclose, 0);
43556 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43557 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43558 + atomic_set_unchecked(&tcon->num_locks, 0);
43559 }
43560 }
43561 }
43562 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43563 smBufAllocCount.counter, cifs_min_small);
43564 #ifdef CONFIG_CIFS_STATS2
43565 seq_printf(m, "Total Large %d Small %d Allocations\n",
43566 - atomic_read(&totBufAllocCount),
43567 - atomic_read(&totSmBufAllocCount));
43568 + atomic_read_unchecked(&totBufAllocCount),
43569 + atomic_read_unchecked(&totSmBufAllocCount));
43570 #endif /* CONFIG_CIFS_STATS2 */
43571
43572 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43573 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43574 if (tcon->need_reconnect)
43575 seq_puts(m, "\tDISCONNECTED ");
43576 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43577 - atomic_read(&tcon->num_smbs_sent),
43578 - atomic_read(&tcon->num_oplock_brks));
43579 + atomic_read_unchecked(&tcon->num_smbs_sent),
43580 + atomic_read_unchecked(&tcon->num_oplock_brks));
43581 seq_printf(m, "\nReads: %d Bytes: %lld",
43582 - atomic_read(&tcon->num_reads),
43583 + atomic_read_unchecked(&tcon->num_reads),
43584 (long long)(tcon->bytes_read));
43585 seq_printf(m, "\nWrites: %d Bytes: %lld",
43586 - atomic_read(&tcon->num_writes),
43587 + atomic_read_unchecked(&tcon->num_writes),
43588 (long long)(tcon->bytes_written));
43589 seq_printf(m, "\nFlushes: %d",
43590 - atomic_read(&tcon->num_flushes));
43591 + atomic_read_unchecked(&tcon->num_flushes));
43592 seq_printf(m, "\nLocks: %d HardLinks: %d "
43593 "Symlinks: %d",
43594 - atomic_read(&tcon->num_locks),
43595 - atomic_read(&tcon->num_hardlinks),
43596 - atomic_read(&tcon->num_symlinks));
43597 + atomic_read_unchecked(&tcon->num_locks),
43598 + atomic_read_unchecked(&tcon->num_hardlinks),
43599 + atomic_read_unchecked(&tcon->num_symlinks));
43600 seq_printf(m, "\nOpens: %d Closes: %d "
43601 "Deletes: %d",
43602 - atomic_read(&tcon->num_opens),
43603 - atomic_read(&tcon->num_closes),
43604 - atomic_read(&tcon->num_deletes));
43605 + atomic_read_unchecked(&tcon->num_opens),
43606 + atomic_read_unchecked(&tcon->num_closes),
43607 + atomic_read_unchecked(&tcon->num_deletes));
43608 seq_printf(m, "\nPosix Opens: %d "
43609 "Posix Mkdirs: %d",
43610 - atomic_read(&tcon->num_posixopens),
43611 - atomic_read(&tcon->num_posixmkdirs));
43612 + atomic_read_unchecked(&tcon->num_posixopens),
43613 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43614 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43615 - atomic_read(&tcon->num_mkdirs),
43616 - atomic_read(&tcon->num_rmdirs));
43617 + atomic_read_unchecked(&tcon->num_mkdirs),
43618 + atomic_read_unchecked(&tcon->num_rmdirs));
43619 seq_printf(m, "\nRenames: %d T2 Renames %d",
43620 - atomic_read(&tcon->num_renames),
43621 - atomic_read(&tcon->num_t2renames));
43622 + atomic_read_unchecked(&tcon->num_renames),
43623 + atomic_read_unchecked(&tcon->num_t2renames));
43624 seq_printf(m, "\nFindFirst: %d FNext %d "
43625 "FClose %d",
43626 - atomic_read(&tcon->num_ffirst),
43627 - atomic_read(&tcon->num_fnext),
43628 - atomic_read(&tcon->num_fclose));
43629 + atomic_read_unchecked(&tcon->num_ffirst),
43630 + atomic_read_unchecked(&tcon->num_fnext),
43631 + atomic_read_unchecked(&tcon->num_fclose));
43632 }
43633 }
43634 }
43635 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43636 index 8b6e344..303a662 100644
43637 --- a/fs/cifs/cifsfs.c
43638 +++ b/fs/cifs/cifsfs.c
43639 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43640 cifs_req_cachep = kmem_cache_create("cifs_request",
43641 CIFSMaxBufSize +
43642 MAX_CIFS_HDR_SIZE, 0,
43643 - SLAB_HWCACHE_ALIGN, NULL);
43644 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43645 if (cifs_req_cachep == NULL)
43646 return -ENOMEM;
43647
43648 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43649 efficient to alloc 1 per page off the slab compared to 17K (5page)
43650 alloc of large cifs buffers even when page debugging is on */
43651 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43652 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43653 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43654 NULL);
43655 if (cifs_sm_req_cachep == NULL) {
43656 mempool_destroy(cifs_req_poolp);
43657 @@ -1106,8 +1106,8 @@ init_cifs(void)
43658 atomic_set(&bufAllocCount, 0);
43659 atomic_set(&smBufAllocCount, 0);
43660 #ifdef CONFIG_CIFS_STATS2
43661 - atomic_set(&totBufAllocCount, 0);
43662 - atomic_set(&totSmBufAllocCount, 0);
43663 + atomic_set_unchecked(&totBufAllocCount, 0);
43664 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43665 #endif /* CONFIG_CIFS_STATS2 */
43666
43667 atomic_set(&midCount, 0);
43668 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43669 index 6df0cbe..eb7ecbb 100644
43670 --- a/fs/cifs/cifsglob.h
43671 +++ b/fs/cifs/cifsglob.h
43672 @@ -491,28 +491,28 @@ struct cifs_tcon {
43673 __u16 Flags; /* optional support bits */
43674 enum statusEnum tidStatus;
43675 #ifdef CONFIG_CIFS_STATS
43676 - atomic_t num_smbs_sent;
43677 - atomic_t num_writes;
43678 - atomic_t num_reads;
43679 - atomic_t num_flushes;
43680 - atomic_t num_oplock_brks;
43681 - atomic_t num_opens;
43682 - atomic_t num_closes;
43683 - atomic_t num_deletes;
43684 - atomic_t num_mkdirs;
43685 - atomic_t num_posixopens;
43686 - atomic_t num_posixmkdirs;
43687 - atomic_t num_rmdirs;
43688 - atomic_t num_renames;
43689 - atomic_t num_t2renames;
43690 - atomic_t num_ffirst;
43691 - atomic_t num_fnext;
43692 - atomic_t num_fclose;
43693 - atomic_t num_hardlinks;
43694 - atomic_t num_symlinks;
43695 - atomic_t num_locks;
43696 - atomic_t num_acl_get;
43697 - atomic_t num_acl_set;
43698 + atomic_unchecked_t num_smbs_sent;
43699 + atomic_unchecked_t num_writes;
43700 + atomic_unchecked_t num_reads;
43701 + atomic_unchecked_t num_flushes;
43702 + atomic_unchecked_t num_oplock_brks;
43703 + atomic_unchecked_t num_opens;
43704 + atomic_unchecked_t num_closes;
43705 + atomic_unchecked_t num_deletes;
43706 + atomic_unchecked_t num_mkdirs;
43707 + atomic_unchecked_t num_posixopens;
43708 + atomic_unchecked_t num_posixmkdirs;
43709 + atomic_unchecked_t num_rmdirs;
43710 + atomic_unchecked_t num_renames;
43711 + atomic_unchecked_t num_t2renames;
43712 + atomic_unchecked_t num_ffirst;
43713 + atomic_unchecked_t num_fnext;
43714 + atomic_unchecked_t num_fclose;
43715 + atomic_unchecked_t num_hardlinks;
43716 + atomic_unchecked_t num_symlinks;
43717 + atomic_unchecked_t num_locks;
43718 + atomic_unchecked_t num_acl_get;
43719 + atomic_unchecked_t num_acl_set;
43720 #ifdef CONFIG_CIFS_STATS2
43721 unsigned long long time_writes;
43722 unsigned long long time_reads;
43723 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43724 }
43725
43726 #ifdef CONFIG_CIFS_STATS
43727 -#define cifs_stats_inc atomic_inc
43728 +#define cifs_stats_inc atomic_inc_unchecked
43729
43730 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43731 unsigned int bytes)
43732 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43733 /* Various Debug counters */
43734 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43735 #ifdef CONFIG_CIFS_STATS2
43736 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43737 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43738 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43739 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43740 #endif
43741 GLOBAL_EXTERN atomic_t smBufAllocCount;
43742 GLOBAL_EXTERN atomic_t midCount;
43743 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43744 index 6b0e064..94e6c3c 100644
43745 --- a/fs/cifs/link.c
43746 +++ b/fs/cifs/link.c
43747 @@ -600,7 +600,7 @@ symlink_exit:
43748
43749 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43750 {
43751 - char *p = nd_get_link(nd);
43752 + const char *p = nd_get_link(nd);
43753 if (!IS_ERR(p))
43754 kfree(p);
43755 }
43756 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43757 index 557506a..2fd3816 100644
43758 --- a/fs/cifs/misc.c
43759 +++ b/fs/cifs/misc.c
43760 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43761 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43762 atomic_inc(&bufAllocCount);
43763 #ifdef CONFIG_CIFS_STATS2
43764 - atomic_inc(&totBufAllocCount);
43765 + atomic_inc_unchecked(&totBufAllocCount);
43766 #endif /* CONFIG_CIFS_STATS2 */
43767 }
43768
43769 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43770 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43771 atomic_inc(&smBufAllocCount);
43772 #ifdef CONFIG_CIFS_STATS2
43773 - atomic_inc(&totSmBufAllocCount);
43774 + atomic_inc_unchecked(&totSmBufAllocCount);
43775 #endif /* CONFIG_CIFS_STATS2 */
43776
43777 }
43778 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43779 index 6901578..d402eb5 100644
43780 --- a/fs/coda/cache.c
43781 +++ b/fs/coda/cache.c
43782 @@ -24,7 +24,7 @@
43783 #include "coda_linux.h"
43784 #include "coda_cache.h"
43785
43786 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43787 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43788
43789 /* replace or extend an acl cache hit */
43790 void coda_cache_enter(struct inode *inode, int mask)
43791 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43792 struct coda_inode_info *cii = ITOC(inode);
43793
43794 spin_lock(&cii->c_lock);
43795 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43796 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43797 if (cii->c_uid != current_fsuid()) {
43798 cii->c_uid = current_fsuid();
43799 cii->c_cached_perm = mask;
43800 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43801 {
43802 struct coda_inode_info *cii = ITOC(inode);
43803 spin_lock(&cii->c_lock);
43804 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43805 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43806 spin_unlock(&cii->c_lock);
43807 }
43808
43809 /* remove all acl caches */
43810 void coda_cache_clear_all(struct super_block *sb)
43811 {
43812 - atomic_inc(&permission_epoch);
43813 + atomic_inc_unchecked(&permission_epoch);
43814 }
43815
43816
43817 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43818 spin_lock(&cii->c_lock);
43819 hit = (mask & cii->c_cached_perm) == mask &&
43820 cii->c_uid == current_fsuid() &&
43821 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43822 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43823 spin_unlock(&cii->c_lock);
43824
43825 return hit;
43826 diff --git a/fs/compat.c b/fs/compat.c
43827 index 6161255..512b1a1 100644
43828 --- a/fs/compat.c
43829 +++ b/fs/compat.c
43830 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43831
43832 set_fs(KERNEL_DS);
43833 /* The __user pointer cast is valid because of the set_fs() */
43834 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43835 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43836 set_fs(oldfs);
43837 /* truncating is ok because it's a user address */
43838 if (!ret)
43839 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43840 goto out;
43841
43842 ret = -EINVAL;
43843 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43844 + if (nr_segs > UIO_MAXIOV)
43845 goto out;
43846 if (nr_segs > fast_segs) {
43847 ret = -ENOMEM;
43848 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43849
43850 struct compat_readdir_callback {
43851 struct compat_old_linux_dirent __user *dirent;
43852 + struct file * file;
43853 int result;
43854 };
43855
43856 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43857 buf->result = -EOVERFLOW;
43858 return -EOVERFLOW;
43859 }
43860 +
43861 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43862 + return 0;
43863 +
43864 buf->result++;
43865 dirent = buf->dirent;
43866 if (!access_ok(VERIFY_WRITE, dirent,
43867 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43868
43869 buf.result = 0;
43870 buf.dirent = dirent;
43871 + buf.file = file;
43872
43873 error = vfs_readdir(file, compat_fillonedir, &buf);
43874 if (buf.result)
43875 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
43876 struct compat_getdents_callback {
43877 struct compat_linux_dirent __user *current_dir;
43878 struct compat_linux_dirent __user *previous;
43879 + struct file * file;
43880 int count;
43881 int error;
43882 };
43883 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43884 buf->error = -EOVERFLOW;
43885 return -EOVERFLOW;
43886 }
43887 +
43888 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43889 + return 0;
43890 +
43891 dirent = buf->previous;
43892 if (dirent) {
43893 if (__put_user(offset, &dirent->d_off))
43894 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43895 buf.previous = NULL;
43896 buf.count = count;
43897 buf.error = 0;
43898 + buf.file = file;
43899
43900 error = vfs_readdir(file, compat_filldir, &buf);
43901 if (error >= 0)
43902 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43903 struct compat_getdents_callback64 {
43904 struct linux_dirent64 __user *current_dir;
43905 struct linux_dirent64 __user *previous;
43906 + struct file * file;
43907 int count;
43908 int error;
43909 };
43910 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43911 buf->error = -EINVAL; /* only used if we fail.. */
43912 if (reclen > buf->count)
43913 return -EINVAL;
43914 +
43915 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43916 + return 0;
43917 +
43918 dirent = buf->previous;
43919
43920 if (dirent) {
43921 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43922 buf.previous = NULL;
43923 buf.count = count;
43924 buf.error = 0;
43925 + buf.file = file;
43926
43927 error = vfs_readdir(file, compat_filldir64, &buf);
43928 if (error >= 0)
43929 error = buf.error;
43930 lastdirent = buf.previous;
43931 if (lastdirent) {
43932 - typeof(lastdirent->d_off) d_off = file->f_pos;
43933 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43934 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43935 error = -EFAULT;
43936 else
43937 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43938 index 112e45a..b59845b 100644
43939 --- a/fs/compat_binfmt_elf.c
43940 +++ b/fs/compat_binfmt_elf.c
43941 @@ -30,11 +30,13 @@
43942 #undef elf_phdr
43943 #undef elf_shdr
43944 #undef elf_note
43945 +#undef elf_dyn
43946 #undef elf_addr_t
43947 #define elfhdr elf32_hdr
43948 #define elf_phdr elf32_phdr
43949 #define elf_shdr elf32_shdr
43950 #define elf_note elf32_note
43951 +#define elf_dyn Elf32_Dyn
43952 #define elf_addr_t Elf32_Addr
43953
43954 /*
43955 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43956 index debdfe0..75d31d4 100644
43957 --- a/fs/compat_ioctl.c
43958 +++ b/fs/compat_ioctl.c
43959 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43960
43961 err = get_user(palp, &up->palette);
43962 err |= get_user(length, &up->length);
43963 + if (err)
43964 + return -EFAULT;
43965
43966 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43967 err = put_user(compat_ptr(palp), &up_native->palette);
43968 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43969 return -EFAULT;
43970 if (__get_user(udata, &ss32->iomem_base))
43971 return -EFAULT;
43972 - ss.iomem_base = compat_ptr(udata);
43973 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43974 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43975 __get_user(ss.port_high, &ss32->port_high))
43976 return -EFAULT;
43977 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43978 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43979 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43980 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43981 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43982 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43983 return -EFAULT;
43984
43985 return ioctl_preallocate(file, p);
43986 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43987 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43988 {
43989 unsigned int a, b;
43990 - a = *(unsigned int *)p;
43991 - b = *(unsigned int *)q;
43992 + a = *(const unsigned int *)p;
43993 + b = *(const unsigned int *)q;
43994 if (a > b)
43995 return 1;
43996 if (a < b)
43997 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43998 index 7e6c52d..94bc756 100644
43999 --- a/fs/configfs/dir.c
44000 +++ b/fs/configfs/dir.c
44001 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44002 }
44003 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44004 struct configfs_dirent *next;
44005 - const char * name;
44006 + const unsigned char * name;
44007 + char d_name[sizeof(next->s_dentry->d_iname)];
44008 int len;
44009 struct inode *inode = NULL;
44010
44011 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44012 continue;
44013
44014 name = configfs_get_name(next);
44015 - len = strlen(name);
44016 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44017 + len = next->s_dentry->d_name.len;
44018 + memcpy(d_name, name, len);
44019 + name = d_name;
44020 + } else
44021 + len = strlen(name);
44022
44023 /*
44024 * We'll have a dentry and an inode for
44025 diff --git a/fs/dcache.c b/fs/dcache.c
44026 index 4046904..5e31505 100644
44027 --- a/fs/dcache.c
44028 +++ b/fs/dcache.c
44029 @@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44030 mempages -= reserve;
44031
44032 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44033 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44034 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44035
44036 dcache_init();
44037 inode_init();
44038 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44039 index b80bc84..0d46d1a 100644
44040 --- a/fs/debugfs/inode.c
44041 +++ b/fs/debugfs/inode.c
44042 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44043 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44044 {
44045 return debugfs_create_file(name,
44046 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44047 + S_IFDIR | S_IRWXU,
44048 +#else
44049 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44050 +#endif
44051 parent, NULL, NULL);
44052 }
44053 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44054 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44055 index a07441a..046fc0d 100644
44056 --- a/fs/ecryptfs/inode.c
44057 +++ b/fs/ecryptfs/inode.c
44058 @@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44059 old_fs = get_fs();
44060 set_fs(get_ds());
44061 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44062 - (char __user *)lower_buf,
44063 + (char __force_user *)lower_buf,
44064 PATH_MAX);
44065 set_fs(old_fs);
44066 if (rc < 0)
44067 @@ -703,7 +703,7 @@ out:
44068 static void
44069 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44070 {
44071 - char *buf = nd_get_link(nd);
44072 + const char *buf = nd_get_link(nd);
44073 if (!IS_ERR(buf)) {
44074 /* Free the char* */
44075 kfree(buf);
44076 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44077 index c0038f6..47ab347 100644
44078 --- a/fs/ecryptfs/miscdev.c
44079 +++ b/fs/ecryptfs/miscdev.c
44080 @@ -355,7 +355,7 @@ check_list:
44081 goto out_unlock_msg_ctx;
44082 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44083 if (msg_ctx->msg) {
44084 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44085 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44086 goto out_unlock_msg_ctx;
44087 i += packet_length_size;
44088 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44089 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44090 index b2a34a1..162fa69 100644
44091 --- a/fs/ecryptfs/read_write.c
44092 +++ b/fs/ecryptfs/read_write.c
44093 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44094 return -EIO;
44095 fs_save = get_fs();
44096 set_fs(get_ds());
44097 - rc = vfs_write(lower_file, data, size, &offset);
44098 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44099 set_fs(fs_save);
44100 mark_inode_dirty_sync(ecryptfs_inode);
44101 return rc;
44102 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44103 return -EIO;
44104 fs_save = get_fs();
44105 set_fs(get_ds());
44106 - rc = vfs_read(lower_file, data, size, &offset);
44107 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44108 set_fs(fs_save);
44109 return rc;
44110 }
44111 diff --git a/fs/exec.c b/fs/exec.c
44112 index da27b91..5a05624 100644
44113 --- a/fs/exec.c
44114 +++ b/fs/exec.c
44115 @@ -55,6 +55,15 @@
44116 #include <linux/pipe_fs_i.h>
44117 #include <linux/oom.h>
44118 #include <linux/compat.h>
44119 +#include <linux/random.h>
44120 +#include <linux/seq_file.h>
44121 +
44122 +#ifdef CONFIG_PAX_REFCOUNT
44123 +#include <linux/kallsyms.h>
44124 +#include <linux/kdebug.h>
44125 +#endif
44126 +
44127 +#include <trace/events/fs.h>
44128
44129 #include <asm/uaccess.h>
44130 #include <asm/mmu_context.h>
44131 @@ -66,6 +75,18 @@
44132
44133 #include <trace/events/sched.h>
44134
44135 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44136 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44137 +{
44138 + 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");
44139 +}
44140 +#endif
44141 +
44142 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44143 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44144 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44145 +#endif
44146 +
44147 int core_uses_pid;
44148 char core_pattern[CORENAME_MAX_SIZE] = "core";
44149 unsigned int core_pipe_limit;
44150 @@ -75,7 +96,7 @@ struct core_name {
44151 char *corename;
44152 int used, size;
44153 };
44154 -static atomic_t call_count = ATOMIC_INIT(1);
44155 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44156
44157 /* The maximal length of core_pattern is also specified in sysctl.c */
44158
44159 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44160 int write)
44161 {
44162 struct page *page;
44163 - int ret;
44164
44165 -#ifdef CONFIG_STACK_GROWSUP
44166 - if (write) {
44167 - ret = expand_downwards(bprm->vma, pos);
44168 - if (ret < 0)
44169 - return NULL;
44170 - }
44171 -#endif
44172 - ret = get_user_pages(current, bprm->mm, pos,
44173 - 1, write, 1, &page, NULL);
44174 - if (ret <= 0)
44175 + if (0 > expand_downwards(bprm->vma, pos))
44176 + return NULL;
44177 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44178 return NULL;
44179
44180 if (write) {
44181 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44182 if (size <= ARG_MAX)
44183 return page;
44184
44185 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44186 + // only allow 512KB for argv+env on suid/sgid binaries
44187 + // to prevent easy ASLR exhaustion
44188 + if (((bprm->cred->euid != current_euid()) ||
44189 + (bprm->cred->egid != current_egid())) &&
44190 + (size > (512 * 1024))) {
44191 + put_page(page);
44192 + return NULL;
44193 + }
44194 +#endif
44195 +
44196 /*
44197 * Limit to 1/4-th the stack size for the argv+env strings.
44198 * This ensures that:
44199 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44200 vma->vm_end = STACK_TOP_MAX;
44201 vma->vm_start = vma->vm_end - PAGE_SIZE;
44202 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44203 +
44204 +#ifdef CONFIG_PAX_SEGMEXEC
44205 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44206 +#endif
44207 +
44208 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44209 INIT_LIST_HEAD(&vma->anon_vma_chain);
44210
44211 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44212 mm->stack_vm = mm->total_vm = 1;
44213 up_write(&mm->mmap_sem);
44214 bprm->p = vma->vm_end - sizeof(void *);
44215 +
44216 +#ifdef CONFIG_PAX_RANDUSTACK
44217 + if (randomize_va_space)
44218 + bprm->p ^= random32() & ~PAGE_MASK;
44219 +#endif
44220 +
44221 return 0;
44222 err:
44223 up_write(&mm->mmap_sem);
44224 @@ -395,19 +430,7 @@ err:
44225 return err;
44226 }
44227
44228 -struct user_arg_ptr {
44229 -#ifdef CONFIG_COMPAT
44230 - bool is_compat;
44231 -#endif
44232 - union {
44233 - const char __user *const __user *native;
44234 -#ifdef CONFIG_COMPAT
44235 - compat_uptr_t __user *compat;
44236 -#endif
44237 - } ptr;
44238 -};
44239 -
44240 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44241 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44242 {
44243 const char __user *native;
44244
44245 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44246 compat_uptr_t compat;
44247
44248 if (get_user(compat, argv.ptr.compat + nr))
44249 - return ERR_PTR(-EFAULT);
44250 + return (const char __force_user *)ERR_PTR(-EFAULT);
44251
44252 return compat_ptr(compat);
44253 }
44254 #endif
44255
44256 if (get_user(native, argv.ptr.native + nr))
44257 - return ERR_PTR(-EFAULT);
44258 + return (const char __force_user *)ERR_PTR(-EFAULT);
44259
44260 return native;
44261 }
44262 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44263 if (!p)
44264 break;
44265
44266 - if (IS_ERR(p))
44267 + if (IS_ERR((const char __force_kernel *)p))
44268 return -EFAULT;
44269
44270 if (i++ >= max)
44271 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44272
44273 ret = -EFAULT;
44274 str = get_user_arg_ptr(argv, argc);
44275 - if (IS_ERR(str))
44276 + if (IS_ERR((const char __force_kernel *)str))
44277 goto out;
44278
44279 len = strnlen_user(str, MAX_ARG_STRLEN);
44280 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44281 int r;
44282 mm_segment_t oldfs = get_fs();
44283 struct user_arg_ptr argv = {
44284 - .ptr.native = (const char __user *const __user *)__argv,
44285 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44286 };
44287
44288 set_fs(KERNEL_DS);
44289 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44290 unsigned long new_end = old_end - shift;
44291 struct mmu_gather tlb;
44292
44293 - BUG_ON(new_start > new_end);
44294 + if (new_start >= new_end || new_start < mmap_min_addr)
44295 + return -ENOMEM;
44296
44297 /*
44298 * ensure there are no vmas between where we want to go
44299 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44300 if (vma != find_vma(mm, new_start))
44301 return -EFAULT;
44302
44303 +#ifdef CONFIG_PAX_SEGMEXEC
44304 + BUG_ON(pax_find_mirror_vma(vma));
44305 +#endif
44306 +
44307 /*
44308 * cover the whole range: [new_start, old_end)
44309 */
44310 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44311 stack_top = arch_align_stack(stack_top);
44312 stack_top = PAGE_ALIGN(stack_top);
44313
44314 - if (unlikely(stack_top < mmap_min_addr) ||
44315 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44316 - return -ENOMEM;
44317 -
44318 stack_shift = vma->vm_end - stack_top;
44319
44320 bprm->p -= stack_shift;
44321 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44322 bprm->exec -= stack_shift;
44323
44324 down_write(&mm->mmap_sem);
44325 +
44326 + /* Move stack pages down in memory. */
44327 + if (stack_shift) {
44328 + ret = shift_arg_pages(vma, stack_shift);
44329 + if (ret)
44330 + goto out_unlock;
44331 + }
44332 +
44333 vm_flags = VM_STACK_FLAGS;
44334
44335 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44336 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44337 + vm_flags &= ~VM_EXEC;
44338 +
44339 +#ifdef CONFIG_PAX_MPROTECT
44340 + if (mm->pax_flags & MF_PAX_MPROTECT)
44341 + vm_flags &= ~VM_MAYEXEC;
44342 +#endif
44343 +
44344 + }
44345 +#endif
44346 +
44347 /*
44348 * Adjust stack execute permissions; explicitly enable for
44349 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44350 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44351 goto out_unlock;
44352 BUG_ON(prev != vma);
44353
44354 - /* Move stack pages down in memory. */
44355 - if (stack_shift) {
44356 - ret = shift_arg_pages(vma, stack_shift);
44357 - if (ret)
44358 - goto out_unlock;
44359 - }
44360 -
44361 /* mprotect_fixup is overkill to remove the temporary stack flags */
44362 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44363
44364 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44365
44366 fsnotify_open(file);
44367
44368 + trace_open_exec(name);
44369 +
44370 err = deny_write_access(file);
44371 if (err)
44372 goto exit;
44373 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44374 old_fs = get_fs();
44375 set_fs(get_ds());
44376 /* The cast to a user pointer is valid due to the set_fs() */
44377 - result = vfs_read(file, (void __user *)addr, count, &pos);
44378 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44379 set_fs(old_fs);
44380 return result;
44381 }
44382 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44383 }
44384 rcu_read_unlock();
44385
44386 - if (p->fs->users > n_fs) {
44387 + if (atomic_read(&p->fs->users) > n_fs) {
44388 bprm->unsafe |= LSM_UNSAFE_SHARE;
44389 } else {
44390 res = -EAGAIN;
44391 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44392
44393 EXPORT_SYMBOL(search_binary_handler);
44394
44395 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44396 +static DEFINE_PER_CPU(u64, exec_counter);
44397 +static int __init init_exec_counters(void)
44398 +{
44399 + unsigned int cpu;
44400 +
44401 + for_each_possible_cpu(cpu) {
44402 + per_cpu(exec_counter, cpu) = (u64)cpu;
44403 + }
44404 +
44405 + return 0;
44406 +}
44407 +early_initcall(init_exec_counters);
44408 +static inline void increment_exec_counter(void)
44409 +{
44410 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44411 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44412 +}
44413 +#else
44414 +static inline void increment_exec_counter(void) {}
44415 +#endif
44416 +
44417 /*
44418 * sys_execve() executes a new program.
44419 */
44420 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44421 struct user_arg_ptr envp,
44422 struct pt_regs *regs)
44423 {
44424 +#ifdef CONFIG_GRKERNSEC
44425 + struct file *old_exec_file;
44426 + struct acl_subject_label *old_acl;
44427 + struct rlimit old_rlim[RLIM_NLIMITS];
44428 +#endif
44429 struct linux_binprm *bprm;
44430 struct file *file;
44431 struct files_struct *displaced;
44432 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44433 int retval;
44434 const struct cred *cred = current_cred();
44435
44436 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44437 +
44438 /*
44439 * We move the actual failure in case of RLIMIT_NPROC excess from
44440 * set*uid() to execve() because too many poorly written programs
44441 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44442 if (IS_ERR(file))
44443 goto out_unmark;
44444
44445 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44446 + retval = -EPERM;
44447 + goto out_file;
44448 + }
44449 +
44450 sched_exec();
44451
44452 bprm->file = file;
44453 bprm->filename = filename;
44454 bprm->interp = filename;
44455
44456 + if (gr_process_user_ban()) {
44457 + retval = -EPERM;
44458 + goto out_file;
44459 + }
44460 +
44461 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44462 + retval = -EACCES;
44463 + goto out_file;
44464 + }
44465 +
44466 retval = bprm_mm_init(bprm);
44467 if (retval)
44468 goto out_file;
44469 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44470 if (retval < 0)
44471 goto out;
44472
44473 +#ifdef CONFIG_GRKERNSEC
44474 + old_acl = current->acl;
44475 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44476 + old_exec_file = current->exec_file;
44477 + get_file(file);
44478 + current->exec_file = file;
44479 +#endif
44480 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44481 + /* limit suid stack to 8MB
44482 + we saved the old limits above and will restore them if this exec fails
44483 + */
44484 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44485 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44486 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44487 +#endif
44488 +
44489 + if (!gr_tpe_allow(file)) {
44490 + retval = -EACCES;
44491 + goto out_fail;
44492 + }
44493 +
44494 + if (gr_check_crash_exec(file)) {
44495 + retval = -EACCES;
44496 + goto out_fail;
44497 + }
44498 +
44499 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44500 + bprm->unsafe);
44501 + if (retval < 0)
44502 + goto out_fail;
44503 +
44504 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44505 if (retval < 0)
44506 - goto out;
44507 + goto out_fail;
44508
44509 bprm->exec = bprm->p;
44510 retval = copy_strings(bprm->envc, envp, bprm);
44511 if (retval < 0)
44512 - goto out;
44513 + goto out_fail;
44514
44515 retval = copy_strings(bprm->argc, argv, bprm);
44516 if (retval < 0)
44517 - goto out;
44518 + goto out_fail;
44519 +
44520 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44521 +
44522 + gr_handle_exec_args(bprm, argv);
44523
44524 retval = search_binary_handler(bprm,regs);
44525 if (retval < 0)
44526 - goto out;
44527 + goto out_fail;
44528 +#ifdef CONFIG_GRKERNSEC
44529 + if (old_exec_file)
44530 + fput(old_exec_file);
44531 +#endif
44532
44533 /* execve succeeded */
44534 +
44535 + increment_exec_counter();
44536 current->fs->in_exec = 0;
44537 current->in_execve = 0;
44538 acct_update_integrals(current);
44539 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44540 put_files_struct(displaced);
44541 return retval;
44542
44543 +out_fail:
44544 +#ifdef CONFIG_GRKERNSEC
44545 + current->acl = old_acl;
44546 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44547 + fput(current->exec_file);
44548 + current->exec_file = old_exec_file;
44549 +#endif
44550 +
44551 out:
44552 if (bprm->mm) {
44553 acct_arg_size(bprm, 0);
44554 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44555 {
44556 char *old_corename = cn->corename;
44557
44558 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44559 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44560 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44561
44562 if (!cn->corename) {
44563 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44564 int pid_in_pattern = 0;
44565 int err = 0;
44566
44567 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44568 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44569 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44570 cn->used = 0;
44571
44572 @@ -1830,6 +1962,250 @@ out:
44573 return ispipe;
44574 }
44575
44576 +int pax_check_flags(unsigned long *flags)
44577 +{
44578 + int retval = 0;
44579 +
44580 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44581 + if (*flags & MF_PAX_SEGMEXEC)
44582 + {
44583 + *flags &= ~MF_PAX_SEGMEXEC;
44584 + retval = -EINVAL;
44585 + }
44586 +#endif
44587 +
44588 + if ((*flags & MF_PAX_PAGEEXEC)
44589 +
44590 +#ifdef CONFIG_PAX_PAGEEXEC
44591 + && (*flags & MF_PAX_SEGMEXEC)
44592 +#endif
44593 +
44594 + )
44595 + {
44596 + *flags &= ~MF_PAX_PAGEEXEC;
44597 + retval = -EINVAL;
44598 + }
44599 +
44600 + if ((*flags & MF_PAX_MPROTECT)
44601 +
44602 +#ifdef CONFIG_PAX_MPROTECT
44603 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44604 +#endif
44605 +
44606 + )
44607 + {
44608 + *flags &= ~MF_PAX_MPROTECT;
44609 + retval = -EINVAL;
44610 + }
44611 +
44612 + if ((*flags & MF_PAX_EMUTRAMP)
44613 +
44614 +#ifdef CONFIG_PAX_EMUTRAMP
44615 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44616 +#endif
44617 +
44618 + )
44619 + {
44620 + *flags &= ~MF_PAX_EMUTRAMP;
44621 + retval = -EINVAL;
44622 + }
44623 +
44624 + return retval;
44625 +}
44626 +
44627 +EXPORT_SYMBOL(pax_check_flags);
44628 +
44629 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44630 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44631 +{
44632 + struct task_struct *tsk = current;
44633 + struct mm_struct *mm = current->mm;
44634 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44635 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44636 + char *path_exec = NULL;
44637 + char *path_fault = NULL;
44638 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44639 +
44640 + if (buffer_exec && buffer_fault) {
44641 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44642 +
44643 + down_read(&mm->mmap_sem);
44644 + vma = mm->mmap;
44645 + while (vma && (!vma_exec || !vma_fault)) {
44646 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44647 + vma_exec = vma;
44648 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44649 + vma_fault = vma;
44650 + vma = vma->vm_next;
44651 + }
44652 + if (vma_exec) {
44653 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44654 + if (IS_ERR(path_exec))
44655 + path_exec = "<path too long>";
44656 + else {
44657 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44658 + if (path_exec) {
44659 + *path_exec = 0;
44660 + path_exec = buffer_exec;
44661 + } else
44662 + path_exec = "<path too long>";
44663 + }
44664 + }
44665 + if (vma_fault) {
44666 + start = vma_fault->vm_start;
44667 + end = vma_fault->vm_end;
44668 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44669 + if (vma_fault->vm_file) {
44670 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44671 + if (IS_ERR(path_fault))
44672 + path_fault = "<path too long>";
44673 + else {
44674 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44675 + if (path_fault) {
44676 + *path_fault = 0;
44677 + path_fault = buffer_fault;
44678 + } else
44679 + path_fault = "<path too long>";
44680 + }
44681 + } else
44682 + path_fault = "<anonymous mapping>";
44683 + }
44684 + up_read(&mm->mmap_sem);
44685 + }
44686 + if (tsk->signal->curr_ip)
44687 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44688 + else
44689 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44690 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44691 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44692 + task_uid(tsk), task_euid(tsk), pc, sp);
44693 + free_page((unsigned long)buffer_exec);
44694 + free_page((unsigned long)buffer_fault);
44695 + pax_report_insns(regs, pc, sp);
44696 + do_coredump(SIGKILL, SIGKILL, regs);
44697 +}
44698 +#endif
44699 +
44700 +#ifdef CONFIG_PAX_REFCOUNT
44701 +void pax_report_refcount_overflow(struct pt_regs *regs)
44702 +{
44703 + if (current->signal->curr_ip)
44704 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44705 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44706 + else
44707 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44708 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44709 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44710 + show_regs(regs);
44711 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44712 +}
44713 +#endif
44714 +
44715 +#ifdef CONFIG_PAX_USERCOPY
44716 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44717 +static noinline int check_stack_object(const void *obj, unsigned long len)
44718 +{
44719 + const void * const stack = task_stack_page(current);
44720 + const void * const stackend = stack + THREAD_SIZE;
44721 +
44722 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44723 + const void *frame = NULL;
44724 + const void *oldframe;
44725 +#endif
44726 +
44727 + if (obj + len < obj)
44728 + return -1;
44729 +
44730 + if (obj + len <= stack || stackend <= obj)
44731 + return 0;
44732 +
44733 + if (obj < stack || stackend < obj + len)
44734 + return -1;
44735 +
44736 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44737 + oldframe = __builtin_frame_address(1);
44738 + if (oldframe)
44739 + frame = __builtin_frame_address(2);
44740 + /*
44741 + low ----------------------------------------------> high
44742 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44743 + ^----------------^
44744 + allow copies only within here
44745 + */
44746 + while (stack <= frame && frame < stackend) {
44747 + /* if obj + len extends past the last frame, this
44748 + check won't pass and the next frame will be 0,
44749 + causing us to bail out and correctly report
44750 + the copy as invalid
44751 + */
44752 + if (obj + len <= frame)
44753 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44754 + oldframe = frame;
44755 + frame = *(const void * const *)frame;
44756 + }
44757 + return -1;
44758 +#else
44759 + return 1;
44760 +#endif
44761 +}
44762 +
44763 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44764 +{
44765 + if (current->signal->curr_ip)
44766 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44767 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44768 + else
44769 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44770 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44771 + dump_stack();
44772 + gr_handle_kernel_exploit();
44773 + do_group_exit(SIGKILL);
44774 +}
44775 +#endif
44776 +
44777 +void check_object_size(const void *ptr, unsigned long n, bool to)
44778 +{
44779 +
44780 +#ifdef CONFIG_PAX_USERCOPY
44781 + const char *type;
44782 +
44783 + if (!n)
44784 + return;
44785 +
44786 + type = check_heap_object(ptr, n, to);
44787 + if (!type) {
44788 + if (check_stack_object(ptr, n) != -1)
44789 + return;
44790 + type = "<process stack>";
44791 + }
44792 +
44793 + pax_report_usercopy(ptr, n, to, type);
44794 +#endif
44795 +
44796 +}
44797 +EXPORT_SYMBOL(check_object_size);
44798 +
44799 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44800 +void pax_track_stack(void)
44801 +{
44802 + unsigned long sp = (unsigned long)&sp;
44803 + if (sp < current_thread_info()->lowest_stack &&
44804 + sp > (unsigned long)task_stack_page(current))
44805 + current_thread_info()->lowest_stack = sp;
44806 +}
44807 +EXPORT_SYMBOL(pax_track_stack);
44808 +#endif
44809 +
44810 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44811 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44812 +{
44813 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44814 + dump_stack();
44815 + do_group_exit(SIGKILL);
44816 +}
44817 +EXPORT_SYMBOL(report_size_overflow);
44818 +#endif
44819 +
44820 static int zap_process(struct task_struct *start, int exit_code)
44821 {
44822 struct task_struct *t;
44823 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44824 void set_dumpable(struct mm_struct *mm, int value)
44825 {
44826 switch (value) {
44827 - case 0:
44828 + case SUID_DUMPABLE_DISABLED:
44829 clear_bit(MMF_DUMPABLE, &mm->flags);
44830 smp_wmb();
44831 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44832 break;
44833 - case 1:
44834 + case SUID_DUMPABLE_ENABLED:
44835 set_bit(MMF_DUMPABLE, &mm->flags);
44836 smp_wmb();
44837 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44838 break;
44839 - case 2:
44840 + case SUID_DUMPABLE_SAFE:
44841 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44842 smp_wmb();
44843 set_bit(MMF_DUMPABLE, &mm->flags);
44844 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44845 int ret;
44846
44847 ret = mm_flags & MMF_DUMPABLE_MASK;
44848 - return (ret >= 2) ? 2 : ret;
44849 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44850 }
44851
44852 int get_dumpable(struct mm_struct *mm)
44853 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44854 pipe = file->f_path.dentry->d_inode->i_pipe;
44855
44856 pipe_lock(pipe);
44857 - pipe->readers++;
44858 - pipe->writers--;
44859 + atomic_inc(&pipe->readers);
44860 + atomic_dec(&pipe->writers);
44861
44862 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44863 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44864 wake_up_interruptible_sync(&pipe->wait);
44865 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44866 pipe_wait(pipe);
44867 }
44868
44869 - pipe->readers--;
44870 - pipe->writers++;
44871 + atomic_dec(&pipe->readers);
44872 + atomic_inc(&pipe->writers);
44873 pipe_unlock(pipe);
44874
44875 }
44876 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44877 int retval = 0;
44878 int flag = 0;
44879 int ispipe;
44880 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44881 + bool need_nonrelative = false;
44882 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44883 struct coredump_params cprm = {
44884 .signr = signr,
44885 .regs = regs,
44886 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44887
44888 audit_core_dumps(signr);
44889
44890 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44891 + gr_handle_brute_attach(current, cprm.mm_flags);
44892 +
44893 binfmt = mm->binfmt;
44894 if (!binfmt || !binfmt->core_dump)
44895 goto fail;
44896 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44897 if (!cred)
44898 goto fail;
44899 /*
44900 - * We cannot trust fsuid as being the "true" uid of the
44901 - * process nor do we know its entire history. We only know it
44902 - * was tainted so we dump it as root in mode 2.
44903 + * We cannot trust fsuid as being the "true" uid of the process
44904 + * nor do we know its entire history. We only know it was tainted
44905 + * so we dump it as root in mode 2, and only into a controlled
44906 + * environment (pipe handler or fully qualified path).
44907 */
44908 - if (__get_dumpable(cprm.mm_flags) == 2) {
44909 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44910 /* Setuid core dump mode */
44911 flag = O_EXCL; /* Stop rewrite attacks */
44912 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44913 + need_nonrelative = true;
44914 }
44915
44916 retval = coredump_wait(exit_code, &core_state);
44917 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44918 }
44919 cprm.limit = RLIM_INFINITY;
44920
44921 - dump_count = atomic_inc_return(&core_dump_count);
44922 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44923 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44924 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44925 task_tgid_vnr(current), current->comm);
44926 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44927 } else {
44928 struct inode *inode;
44929
44930 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44931 +
44932 if (cprm.limit < binfmt->min_coredump)
44933 goto fail_unlock;
44934
44935 + if (need_nonrelative && cn.corename[0] != '/') {
44936 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44937 + "to fully qualified path!\n",
44938 + task_tgid_vnr(current), current->comm);
44939 + printk(KERN_WARNING "Skipping core dump\n");
44940 + goto fail_unlock;
44941 + }
44942 +
44943 cprm.file = filp_open(cn.corename,
44944 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44945 0600);
44946 @@ -2263,7 +2655,7 @@ close_fail:
44947 filp_close(cprm.file, NULL);
44948 fail_dropcount:
44949 if (ispipe)
44950 - atomic_dec(&core_dump_count);
44951 + atomic_dec_unchecked(&core_dump_count);
44952 fail_unlock:
44953 kfree(cn.corename);
44954 fail_corename:
44955 @@ -2282,7 +2674,7 @@ fail:
44956 */
44957 int dump_write(struct file *file, const void *addr, int nr)
44958 {
44959 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44960 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44961 }
44962 EXPORT_SYMBOL(dump_write);
44963
44964 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44965 index 1c36139..cf6b350 100644
44966 --- a/fs/ext2/balloc.c
44967 +++ b/fs/ext2/balloc.c
44968 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44969
44970 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44971 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44972 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44973 + if (free_blocks < root_blocks + 1 &&
44974 !uid_eq(sbi->s_resuid, current_fsuid()) &&
44975 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
44976 - !in_group_p (sbi->s_resgid))) {
44977 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
44978 return 0;
44979 }
44980 return 1;
44981 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44982 index 25cd608..9ed5294 100644
44983 --- a/fs/ext3/balloc.c
44984 +++ b/fs/ext3/balloc.c
44985 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44986
44987 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44988 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44989 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44990 + if (free_blocks < root_blocks + 1 &&
44991 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
44992 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
44993 - !in_group_p (sbi->s_resgid))) {
44994 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
44995 return 0;
44996 }
44997 return 1;
44998 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44999 index cee7812..0e8e65c 100644
45000 --- a/fs/ext4/balloc.c
45001 +++ b/fs/ext4/balloc.c
45002 @@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45003 /* Hm, nope. Are (enough) root reserved clusters available? */
45004 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45005 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45006 - capable(CAP_SYS_RESOURCE) ||
45007 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45008 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45009 + capable_nolog(CAP_SYS_RESOURCE)) {
45010
45011 if (free_clusters >= (nclusters + dirty_clusters))
45012 return 1;
45013 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45014 index cfc4e01..2f3fd3c 100644
45015 --- a/fs/ext4/ext4.h
45016 +++ b/fs/ext4/ext4.h
45017 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45018 unsigned long s_mb_last_start;
45019
45020 /* stats for buddy allocator */
45021 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45022 - atomic_t s_bal_success; /* we found long enough chunks */
45023 - atomic_t s_bal_allocated; /* in blocks */
45024 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45025 - atomic_t s_bal_goals; /* goal hits */
45026 - atomic_t s_bal_breaks; /* too long searches */
45027 - atomic_t s_bal_2orders; /* 2^order hits */
45028 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45029 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45030 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45031 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45032 + atomic_unchecked_t s_bal_goals; /* goal hits */
45033 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45034 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45035 spinlock_t s_bal_lock;
45036 unsigned long s_mb_buddies_generated;
45037 unsigned long long s_mb_generation_time;
45038 - atomic_t s_mb_lost_chunks;
45039 - atomic_t s_mb_preallocated;
45040 - atomic_t s_mb_discarded;
45041 + atomic_unchecked_t s_mb_lost_chunks;
45042 + atomic_unchecked_t s_mb_preallocated;
45043 + atomic_unchecked_t s_mb_discarded;
45044 atomic_t s_lock_busy;
45045
45046 /* locality groups */
45047 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45048 index 1cd6994..5799d45 100644
45049 --- a/fs/ext4/mballoc.c
45050 +++ b/fs/ext4/mballoc.c
45051 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45052 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45053
45054 if (EXT4_SB(sb)->s_mb_stats)
45055 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45056 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45057
45058 break;
45059 }
45060 @@ -2041,7 +2041,7 @@ repeat:
45061 ac->ac_status = AC_STATUS_CONTINUE;
45062 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45063 cr = 3;
45064 - atomic_inc(&sbi->s_mb_lost_chunks);
45065 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45066 goto repeat;
45067 }
45068 }
45069 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45070 if (sbi->s_mb_stats) {
45071 ext4_msg(sb, KERN_INFO,
45072 "mballoc: %u blocks %u reqs (%u success)",
45073 - atomic_read(&sbi->s_bal_allocated),
45074 - atomic_read(&sbi->s_bal_reqs),
45075 - atomic_read(&sbi->s_bal_success));
45076 + atomic_read_unchecked(&sbi->s_bal_allocated),
45077 + atomic_read_unchecked(&sbi->s_bal_reqs),
45078 + atomic_read_unchecked(&sbi->s_bal_success));
45079 ext4_msg(sb, KERN_INFO,
45080 "mballoc: %u extents scanned, %u goal hits, "
45081 "%u 2^N hits, %u breaks, %u lost",
45082 - atomic_read(&sbi->s_bal_ex_scanned),
45083 - atomic_read(&sbi->s_bal_goals),
45084 - atomic_read(&sbi->s_bal_2orders),
45085 - atomic_read(&sbi->s_bal_breaks),
45086 - atomic_read(&sbi->s_mb_lost_chunks));
45087 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45088 + atomic_read_unchecked(&sbi->s_bal_goals),
45089 + atomic_read_unchecked(&sbi->s_bal_2orders),
45090 + atomic_read_unchecked(&sbi->s_bal_breaks),
45091 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45092 ext4_msg(sb, KERN_INFO,
45093 "mballoc: %lu generated and it took %Lu",
45094 sbi->s_mb_buddies_generated,
45095 sbi->s_mb_generation_time);
45096 ext4_msg(sb, KERN_INFO,
45097 "mballoc: %u preallocated, %u discarded",
45098 - atomic_read(&sbi->s_mb_preallocated),
45099 - atomic_read(&sbi->s_mb_discarded));
45100 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45101 + atomic_read_unchecked(&sbi->s_mb_discarded));
45102 }
45103
45104 free_percpu(sbi->s_locality_groups);
45105 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45106 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45107
45108 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45109 - atomic_inc(&sbi->s_bal_reqs);
45110 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45111 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45112 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45113 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45114 - atomic_inc(&sbi->s_bal_success);
45115 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45116 + atomic_inc_unchecked(&sbi->s_bal_success);
45117 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45118 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45119 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45120 - atomic_inc(&sbi->s_bal_goals);
45121 + atomic_inc_unchecked(&sbi->s_bal_goals);
45122 if (ac->ac_found > sbi->s_mb_max_to_scan)
45123 - atomic_inc(&sbi->s_bal_breaks);
45124 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45125 }
45126
45127 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45128 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45129 trace_ext4_mb_new_inode_pa(ac, pa);
45130
45131 ext4_mb_use_inode_pa(ac, pa);
45132 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45133 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45134
45135 ei = EXT4_I(ac->ac_inode);
45136 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45137 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45138 trace_ext4_mb_new_group_pa(ac, pa);
45139
45140 ext4_mb_use_group_pa(ac, pa);
45141 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45142 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45143
45144 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45145 lg = ac->ac_lg;
45146 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45147 * from the bitmap and continue.
45148 */
45149 }
45150 - atomic_add(free, &sbi->s_mb_discarded);
45151 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45152
45153 return err;
45154 }
45155 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45156 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45157 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45158 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45159 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45160 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45161 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45162
45163 return 0;
45164 diff --git a/fs/fcntl.c b/fs/fcntl.c
45165 index 81b70e6..d9ae6cf 100644
45166 --- a/fs/fcntl.c
45167 +++ b/fs/fcntl.c
45168 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45169 if (err)
45170 return err;
45171
45172 + if (gr_handle_chroot_fowner(pid, type))
45173 + return -ENOENT;
45174 + if (gr_check_protected_task_fowner(pid, type))
45175 + return -EACCES;
45176 +
45177 f_modown(filp, pid, type, force);
45178 return 0;
45179 }
45180 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45181
45182 static int f_setown_ex(struct file *filp, unsigned long arg)
45183 {
45184 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45185 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45186 struct f_owner_ex owner;
45187 struct pid *pid;
45188 int type;
45189 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45190
45191 static int f_getown_ex(struct file *filp, unsigned long arg)
45192 {
45193 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45194 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45195 struct f_owner_ex owner;
45196 int ret = 0;
45197
45198 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45199 switch (cmd) {
45200 case F_DUPFD:
45201 case F_DUPFD_CLOEXEC:
45202 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45203 if (arg >= rlimit(RLIMIT_NOFILE))
45204 break;
45205 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45206 diff --git a/fs/fifo.c b/fs/fifo.c
45207 index cf6f434..3d7942c 100644
45208 --- a/fs/fifo.c
45209 +++ b/fs/fifo.c
45210 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45211 */
45212 filp->f_op = &read_pipefifo_fops;
45213 pipe->r_counter++;
45214 - if (pipe->readers++ == 0)
45215 + if (atomic_inc_return(&pipe->readers) == 1)
45216 wake_up_partner(inode);
45217
45218 - if (!pipe->writers) {
45219 + if (!atomic_read(&pipe->writers)) {
45220 if ((filp->f_flags & O_NONBLOCK)) {
45221 /* suppress POLLHUP until we have
45222 * seen a writer */
45223 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45224 * errno=ENXIO when there is no process reading the FIFO.
45225 */
45226 ret = -ENXIO;
45227 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45228 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45229 goto err;
45230
45231 filp->f_op = &write_pipefifo_fops;
45232 pipe->w_counter++;
45233 - if (!pipe->writers++)
45234 + if (atomic_inc_return(&pipe->writers) == 1)
45235 wake_up_partner(inode);
45236
45237 - if (!pipe->readers) {
45238 + if (!atomic_read(&pipe->readers)) {
45239 if (wait_for_partner(inode, &pipe->r_counter))
45240 goto err_wr;
45241 }
45242 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45243 */
45244 filp->f_op = &rdwr_pipefifo_fops;
45245
45246 - pipe->readers++;
45247 - pipe->writers++;
45248 + atomic_inc(&pipe->readers);
45249 + atomic_inc(&pipe->writers);
45250 pipe->r_counter++;
45251 pipe->w_counter++;
45252 - if (pipe->readers == 1 || pipe->writers == 1)
45253 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45254 wake_up_partner(inode);
45255 break;
45256
45257 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45258 return 0;
45259
45260 err_rd:
45261 - if (!--pipe->readers)
45262 + if (atomic_dec_and_test(&pipe->readers))
45263 wake_up_interruptible(&pipe->wait);
45264 ret = -ERESTARTSYS;
45265 goto err;
45266
45267 err_wr:
45268 - if (!--pipe->writers)
45269 + if (atomic_dec_and_test(&pipe->writers))
45270 wake_up_interruptible(&pipe->wait);
45271 ret = -ERESTARTSYS;
45272 goto err;
45273
45274 err:
45275 - if (!pipe->readers && !pipe->writers)
45276 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45277 free_pipe_info(inode);
45278
45279 err_nocleanup:
45280 diff --git a/fs/file.c b/fs/file.c
45281 index ba3f605..fade102 100644
45282 --- a/fs/file.c
45283 +++ b/fs/file.c
45284 @@ -15,6 +15,7 @@
45285 #include <linux/slab.h>
45286 #include <linux/vmalloc.h>
45287 #include <linux/file.h>
45288 +#include <linux/security.h>
45289 #include <linux/fdtable.h>
45290 #include <linux/bitops.h>
45291 #include <linux/interrupt.h>
45292 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45293 * N.B. For clone tasks sharing a files structure, this test
45294 * will limit the total number of files that can be opened.
45295 */
45296 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45297 if (nr >= rlimit(RLIMIT_NOFILE))
45298 return -EMFILE;
45299
45300 diff --git a/fs/filesystems.c b/fs/filesystems.c
45301 index 96f2428..f5eeb8e 100644
45302 --- a/fs/filesystems.c
45303 +++ b/fs/filesystems.c
45304 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45305 int len = dot ? dot - name : strlen(name);
45306
45307 fs = __get_fs_type(name, len);
45308 +
45309 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45310 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45311 +#else
45312 if (!fs && (request_module("%.*s", len, name) == 0))
45313 +#endif
45314 fs = __get_fs_type(name, len);
45315
45316 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45317 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45318 index e159e68..e7d2a6f 100644
45319 --- a/fs/fs_struct.c
45320 +++ b/fs/fs_struct.c
45321 @@ -4,6 +4,7 @@
45322 #include <linux/path.h>
45323 #include <linux/slab.h>
45324 #include <linux/fs_struct.h>
45325 +#include <linux/grsecurity.h>
45326 #include "internal.h"
45327
45328 static inline void path_get_longterm(struct path *path)
45329 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45330 write_seqcount_begin(&fs->seq);
45331 old_root = fs->root;
45332 fs->root = *path;
45333 + gr_set_chroot_entries(current, path);
45334 write_seqcount_end(&fs->seq);
45335 spin_unlock(&fs->lock);
45336 if (old_root.dentry)
45337 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45338 return 1;
45339 }
45340
45341 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45342 +{
45343 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45344 + return 0;
45345 + *p = *new;
45346 +
45347 + gr_set_chroot_entries(task, new);
45348 +
45349 + return 1;
45350 +}
45351 +
45352 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45353 {
45354 struct task_struct *g, *p;
45355 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45356 int hits = 0;
45357 spin_lock(&fs->lock);
45358 write_seqcount_begin(&fs->seq);
45359 - hits += replace_path(&fs->root, old_root, new_root);
45360 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45361 hits += replace_path(&fs->pwd, old_root, new_root);
45362 write_seqcount_end(&fs->seq);
45363 while (hits--) {
45364 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45365 task_lock(tsk);
45366 spin_lock(&fs->lock);
45367 tsk->fs = NULL;
45368 - kill = !--fs->users;
45369 + gr_clear_chroot_entries(tsk);
45370 + kill = !atomic_dec_return(&fs->users);
45371 spin_unlock(&fs->lock);
45372 task_unlock(tsk);
45373 if (kill)
45374 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45375 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45376 /* We don't need to lock fs - think why ;-) */
45377 if (fs) {
45378 - fs->users = 1;
45379 + atomic_set(&fs->users, 1);
45380 fs->in_exec = 0;
45381 spin_lock_init(&fs->lock);
45382 seqcount_init(&fs->seq);
45383 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45384 spin_lock(&old->lock);
45385 fs->root = old->root;
45386 path_get_longterm(&fs->root);
45387 + /* instead of calling gr_set_chroot_entries here,
45388 + we call it from every caller of this function
45389 + */
45390 fs->pwd = old->pwd;
45391 path_get_longterm(&fs->pwd);
45392 spin_unlock(&old->lock);
45393 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45394
45395 task_lock(current);
45396 spin_lock(&fs->lock);
45397 - kill = !--fs->users;
45398 + kill = !atomic_dec_return(&fs->users);
45399 current->fs = new_fs;
45400 + gr_set_chroot_entries(current, &new_fs->root);
45401 spin_unlock(&fs->lock);
45402 task_unlock(current);
45403
45404 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45405
45406 int current_umask(void)
45407 {
45408 - return current->fs->umask;
45409 + return current->fs->umask | gr_acl_umask();
45410 }
45411 EXPORT_SYMBOL(current_umask);
45412
45413 /* to be mentioned only in INIT_TASK */
45414 struct fs_struct init_fs = {
45415 - .users = 1,
45416 + .users = ATOMIC_INIT(1),
45417 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45418 .seq = SEQCNT_ZERO,
45419 .umask = 0022,
45420 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45421 task_lock(current);
45422
45423 spin_lock(&init_fs.lock);
45424 - init_fs.users++;
45425 + atomic_inc(&init_fs.users);
45426 spin_unlock(&init_fs.lock);
45427
45428 spin_lock(&fs->lock);
45429 current->fs = &init_fs;
45430 - kill = !--fs->users;
45431 + gr_set_chroot_entries(current, &current->fs->root);
45432 + kill = !atomic_dec_return(&fs->users);
45433 spin_unlock(&fs->lock);
45434
45435 task_unlock(current);
45436 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45437 index 9905350..02eaec4 100644
45438 --- a/fs/fscache/cookie.c
45439 +++ b/fs/fscache/cookie.c
45440 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45441 parent ? (char *) parent->def->name : "<no-parent>",
45442 def->name, netfs_data);
45443
45444 - fscache_stat(&fscache_n_acquires);
45445 + fscache_stat_unchecked(&fscache_n_acquires);
45446
45447 /* if there's no parent cookie, then we don't create one here either */
45448 if (!parent) {
45449 - fscache_stat(&fscache_n_acquires_null);
45450 + fscache_stat_unchecked(&fscache_n_acquires_null);
45451 _leave(" [no parent]");
45452 return NULL;
45453 }
45454 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45455 /* allocate and initialise a cookie */
45456 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45457 if (!cookie) {
45458 - fscache_stat(&fscache_n_acquires_oom);
45459 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45460 _leave(" [ENOMEM]");
45461 return NULL;
45462 }
45463 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45464
45465 switch (cookie->def->type) {
45466 case FSCACHE_COOKIE_TYPE_INDEX:
45467 - fscache_stat(&fscache_n_cookie_index);
45468 + fscache_stat_unchecked(&fscache_n_cookie_index);
45469 break;
45470 case FSCACHE_COOKIE_TYPE_DATAFILE:
45471 - fscache_stat(&fscache_n_cookie_data);
45472 + fscache_stat_unchecked(&fscache_n_cookie_data);
45473 break;
45474 default:
45475 - fscache_stat(&fscache_n_cookie_special);
45476 + fscache_stat_unchecked(&fscache_n_cookie_special);
45477 break;
45478 }
45479
45480 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45481 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45482 atomic_dec(&parent->n_children);
45483 __fscache_cookie_put(cookie);
45484 - fscache_stat(&fscache_n_acquires_nobufs);
45485 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45486 _leave(" = NULL");
45487 return NULL;
45488 }
45489 }
45490
45491 - fscache_stat(&fscache_n_acquires_ok);
45492 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45493 _leave(" = %p", cookie);
45494 return cookie;
45495 }
45496 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45497 cache = fscache_select_cache_for_object(cookie->parent);
45498 if (!cache) {
45499 up_read(&fscache_addremove_sem);
45500 - fscache_stat(&fscache_n_acquires_no_cache);
45501 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45502 _leave(" = -ENOMEDIUM [no cache]");
45503 return -ENOMEDIUM;
45504 }
45505 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45506 object = cache->ops->alloc_object(cache, cookie);
45507 fscache_stat_d(&fscache_n_cop_alloc_object);
45508 if (IS_ERR(object)) {
45509 - fscache_stat(&fscache_n_object_no_alloc);
45510 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45511 ret = PTR_ERR(object);
45512 goto error;
45513 }
45514
45515 - fscache_stat(&fscache_n_object_alloc);
45516 + fscache_stat_unchecked(&fscache_n_object_alloc);
45517
45518 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45519
45520 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45521 struct fscache_object *object;
45522 struct hlist_node *_p;
45523
45524 - fscache_stat(&fscache_n_updates);
45525 + fscache_stat_unchecked(&fscache_n_updates);
45526
45527 if (!cookie) {
45528 - fscache_stat(&fscache_n_updates_null);
45529 + fscache_stat_unchecked(&fscache_n_updates_null);
45530 _leave(" [no cookie]");
45531 return;
45532 }
45533 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45534 struct fscache_object *object;
45535 unsigned long event;
45536
45537 - fscache_stat(&fscache_n_relinquishes);
45538 + fscache_stat_unchecked(&fscache_n_relinquishes);
45539 if (retire)
45540 - fscache_stat(&fscache_n_relinquishes_retire);
45541 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45542
45543 if (!cookie) {
45544 - fscache_stat(&fscache_n_relinquishes_null);
45545 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45546 _leave(" [no cookie]");
45547 return;
45548 }
45549 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45550
45551 /* wait for the cookie to finish being instantiated (or to fail) */
45552 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45553 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45554 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45555 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45556 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45557 }
45558 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45559 index f6aad48..88dcf26 100644
45560 --- a/fs/fscache/internal.h
45561 +++ b/fs/fscache/internal.h
45562 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45563 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45564 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45565
45566 -extern atomic_t fscache_n_op_pend;
45567 -extern atomic_t fscache_n_op_run;
45568 -extern atomic_t fscache_n_op_enqueue;
45569 -extern atomic_t fscache_n_op_deferred_release;
45570 -extern atomic_t fscache_n_op_release;
45571 -extern atomic_t fscache_n_op_gc;
45572 -extern atomic_t fscache_n_op_cancelled;
45573 -extern atomic_t fscache_n_op_rejected;
45574 +extern atomic_unchecked_t fscache_n_op_pend;
45575 +extern atomic_unchecked_t fscache_n_op_run;
45576 +extern atomic_unchecked_t fscache_n_op_enqueue;
45577 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45578 +extern atomic_unchecked_t fscache_n_op_release;
45579 +extern atomic_unchecked_t fscache_n_op_gc;
45580 +extern atomic_unchecked_t fscache_n_op_cancelled;
45581 +extern atomic_unchecked_t fscache_n_op_rejected;
45582
45583 -extern atomic_t fscache_n_attr_changed;
45584 -extern atomic_t fscache_n_attr_changed_ok;
45585 -extern atomic_t fscache_n_attr_changed_nobufs;
45586 -extern atomic_t fscache_n_attr_changed_nomem;
45587 -extern atomic_t fscache_n_attr_changed_calls;
45588 +extern atomic_unchecked_t fscache_n_attr_changed;
45589 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45590 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45591 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45592 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45593
45594 -extern atomic_t fscache_n_allocs;
45595 -extern atomic_t fscache_n_allocs_ok;
45596 -extern atomic_t fscache_n_allocs_wait;
45597 -extern atomic_t fscache_n_allocs_nobufs;
45598 -extern atomic_t fscache_n_allocs_intr;
45599 -extern atomic_t fscache_n_allocs_object_dead;
45600 -extern atomic_t fscache_n_alloc_ops;
45601 -extern atomic_t fscache_n_alloc_op_waits;
45602 +extern atomic_unchecked_t fscache_n_allocs;
45603 +extern atomic_unchecked_t fscache_n_allocs_ok;
45604 +extern atomic_unchecked_t fscache_n_allocs_wait;
45605 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45606 +extern atomic_unchecked_t fscache_n_allocs_intr;
45607 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45608 +extern atomic_unchecked_t fscache_n_alloc_ops;
45609 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45610
45611 -extern atomic_t fscache_n_retrievals;
45612 -extern atomic_t fscache_n_retrievals_ok;
45613 -extern atomic_t fscache_n_retrievals_wait;
45614 -extern atomic_t fscache_n_retrievals_nodata;
45615 -extern atomic_t fscache_n_retrievals_nobufs;
45616 -extern atomic_t fscache_n_retrievals_intr;
45617 -extern atomic_t fscache_n_retrievals_nomem;
45618 -extern atomic_t fscache_n_retrievals_object_dead;
45619 -extern atomic_t fscache_n_retrieval_ops;
45620 -extern atomic_t fscache_n_retrieval_op_waits;
45621 +extern atomic_unchecked_t fscache_n_retrievals;
45622 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45623 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45624 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45625 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45626 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45627 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45628 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45629 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45630 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45631
45632 -extern atomic_t fscache_n_stores;
45633 -extern atomic_t fscache_n_stores_ok;
45634 -extern atomic_t fscache_n_stores_again;
45635 -extern atomic_t fscache_n_stores_nobufs;
45636 -extern atomic_t fscache_n_stores_oom;
45637 -extern atomic_t fscache_n_store_ops;
45638 -extern atomic_t fscache_n_store_calls;
45639 -extern atomic_t fscache_n_store_pages;
45640 -extern atomic_t fscache_n_store_radix_deletes;
45641 -extern atomic_t fscache_n_store_pages_over_limit;
45642 +extern atomic_unchecked_t fscache_n_stores;
45643 +extern atomic_unchecked_t fscache_n_stores_ok;
45644 +extern atomic_unchecked_t fscache_n_stores_again;
45645 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45646 +extern atomic_unchecked_t fscache_n_stores_oom;
45647 +extern atomic_unchecked_t fscache_n_store_ops;
45648 +extern atomic_unchecked_t fscache_n_store_calls;
45649 +extern atomic_unchecked_t fscache_n_store_pages;
45650 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45651 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45652
45653 -extern atomic_t fscache_n_store_vmscan_not_storing;
45654 -extern atomic_t fscache_n_store_vmscan_gone;
45655 -extern atomic_t fscache_n_store_vmscan_busy;
45656 -extern atomic_t fscache_n_store_vmscan_cancelled;
45657 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45658 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45659 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45660 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45661
45662 -extern atomic_t fscache_n_marks;
45663 -extern atomic_t fscache_n_uncaches;
45664 +extern atomic_unchecked_t fscache_n_marks;
45665 +extern atomic_unchecked_t fscache_n_uncaches;
45666
45667 -extern atomic_t fscache_n_acquires;
45668 -extern atomic_t fscache_n_acquires_null;
45669 -extern atomic_t fscache_n_acquires_no_cache;
45670 -extern atomic_t fscache_n_acquires_ok;
45671 -extern atomic_t fscache_n_acquires_nobufs;
45672 -extern atomic_t fscache_n_acquires_oom;
45673 +extern atomic_unchecked_t fscache_n_acquires;
45674 +extern atomic_unchecked_t fscache_n_acquires_null;
45675 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45676 +extern atomic_unchecked_t fscache_n_acquires_ok;
45677 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45678 +extern atomic_unchecked_t fscache_n_acquires_oom;
45679
45680 -extern atomic_t fscache_n_updates;
45681 -extern atomic_t fscache_n_updates_null;
45682 -extern atomic_t fscache_n_updates_run;
45683 +extern atomic_unchecked_t fscache_n_updates;
45684 +extern atomic_unchecked_t fscache_n_updates_null;
45685 +extern atomic_unchecked_t fscache_n_updates_run;
45686
45687 -extern atomic_t fscache_n_relinquishes;
45688 -extern atomic_t fscache_n_relinquishes_null;
45689 -extern atomic_t fscache_n_relinquishes_waitcrt;
45690 -extern atomic_t fscache_n_relinquishes_retire;
45691 +extern atomic_unchecked_t fscache_n_relinquishes;
45692 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45693 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45694 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45695
45696 -extern atomic_t fscache_n_cookie_index;
45697 -extern atomic_t fscache_n_cookie_data;
45698 -extern atomic_t fscache_n_cookie_special;
45699 +extern atomic_unchecked_t fscache_n_cookie_index;
45700 +extern atomic_unchecked_t fscache_n_cookie_data;
45701 +extern atomic_unchecked_t fscache_n_cookie_special;
45702
45703 -extern atomic_t fscache_n_object_alloc;
45704 -extern atomic_t fscache_n_object_no_alloc;
45705 -extern atomic_t fscache_n_object_lookups;
45706 -extern atomic_t fscache_n_object_lookups_negative;
45707 -extern atomic_t fscache_n_object_lookups_positive;
45708 -extern atomic_t fscache_n_object_lookups_timed_out;
45709 -extern atomic_t fscache_n_object_created;
45710 -extern atomic_t fscache_n_object_avail;
45711 -extern atomic_t fscache_n_object_dead;
45712 +extern atomic_unchecked_t fscache_n_object_alloc;
45713 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45714 +extern atomic_unchecked_t fscache_n_object_lookups;
45715 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45716 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45717 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45718 +extern atomic_unchecked_t fscache_n_object_created;
45719 +extern atomic_unchecked_t fscache_n_object_avail;
45720 +extern atomic_unchecked_t fscache_n_object_dead;
45721
45722 -extern atomic_t fscache_n_checkaux_none;
45723 -extern atomic_t fscache_n_checkaux_okay;
45724 -extern atomic_t fscache_n_checkaux_update;
45725 -extern atomic_t fscache_n_checkaux_obsolete;
45726 +extern atomic_unchecked_t fscache_n_checkaux_none;
45727 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45728 +extern atomic_unchecked_t fscache_n_checkaux_update;
45729 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45730
45731 extern atomic_t fscache_n_cop_alloc_object;
45732 extern atomic_t fscache_n_cop_lookup_object;
45733 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45734 atomic_inc(stat);
45735 }
45736
45737 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45738 +{
45739 + atomic_inc_unchecked(stat);
45740 +}
45741 +
45742 static inline void fscache_stat_d(atomic_t *stat)
45743 {
45744 atomic_dec(stat);
45745 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45746
45747 #define __fscache_stat(stat) (NULL)
45748 #define fscache_stat(stat) do {} while (0)
45749 +#define fscache_stat_unchecked(stat) do {} while (0)
45750 #define fscache_stat_d(stat) do {} while (0)
45751 #endif
45752
45753 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45754 index b6b897c..0ffff9c 100644
45755 --- a/fs/fscache/object.c
45756 +++ b/fs/fscache/object.c
45757 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45758 /* update the object metadata on disk */
45759 case FSCACHE_OBJECT_UPDATING:
45760 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45761 - fscache_stat(&fscache_n_updates_run);
45762 + fscache_stat_unchecked(&fscache_n_updates_run);
45763 fscache_stat(&fscache_n_cop_update_object);
45764 object->cache->ops->update_object(object);
45765 fscache_stat_d(&fscache_n_cop_update_object);
45766 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45767 spin_lock(&object->lock);
45768 object->state = FSCACHE_OBJECT_DEAD;
45769 spin_unlock(&object->lock);
45770 - fscache_stat(&fscache_n_object_dead);
45771 + fscache_stat_unchecked(&fscache_n_object_dead);
45772 goto terminal_transit;
45773
45774 /* handle the parent cache of this object being withdrawn from
45775 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45776 spin_lock(&object->lock);
45777 object->state = FSCACHE_OBJECT_DEAD;
45778 spin_unlock(&object->lock);
45779 - fscache_stat(&fscache_n_object_dead);
45780 + fscache_stat_unchecked(&fscache_n_object_dead);
45781 goto terminal_transit;
45782
45783 /* complain about the object being woken up once it is
45784 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45785 parent->cookie->def->name, cookie->def->name,
45786 object->cache->tag->name);
45787
45788 - fscache_stat(&fscache_n_object_lookups);
45789 + fscache_stat_unchecked(&fscache_n_object_lookups);
45790 fscache_stat(&fscache_n_cop_lookup_object);
45791 ret = object->cache->ops->lookup_object(object);
45792 fscache_stat_d(&fscache_n_cop_lookup_object);
45793 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45794 if (ret == -ETIMEDOUT) {
45795 /* probably stuck behind another object, so move this one to
45796 * the back of the queue */
45797 - fscache_stat(&fscache_n_object_lookups_timed_out);
45798 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45799 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45800 }
45801
45802 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45803
45804 spin_lock(&object->lock);
45805 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45806 - fscache_stat(&fscache_n_object_lookups_negative);
45807 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45808
45809 /* transit here to allow write requests to begin stacking up
45810 * and read requests to begin returning ENODATA */
45811 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45812 * result, in which case there may be data available */
45813 spin_lock(&object->lock);
45814 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45815 - fscache_stat(&fscache_n_object_lookups_positive);
45816 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45817
45818 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45819
45820 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45821 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45822 } else {
45823 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45824 - fscache_stat(&fscache_n_object_created);
45825 + fscache_stat_unchecked(&fscache_n_object_created);
45826
45827 object->state = FSCACHE_OBJECT_AVAILABLE;
45828 spin_unlock(&object->lock);
45829 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45830 fscache_enqueue_dependents(object);
45831
45832 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45833 - fscache_stat(&fscache_n_object_avail);
45834 + fscache_stat_unchecked(&fscache_n_object_avail);
45835
45836 _leave("");
45837 }
45838 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45839 enum fscache_checkaux result;
45840
45841 if (!object->cookie->def->check_aux) {
45842 - fscache_stat(&fscache_n_checkaux_none);
45843 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45844 return FSCACHE_CHECKAUX_OKAY;
45845 }
45846
45847 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45848 switch (result) {
45849 /* entry okay as is */
45850 case FSCACHE_CHECKAUX_OKAY:
45851 - fscache_stat(&fscache_n_checkaux_okay);
45852 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45853 break;
45854
45855 /* entry requires update */
45856 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45857 - fscache_stat(&fscache_n_checkaux_update);
45858 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45859 break;
45860
45861 /* entry requires deletion */
45862 case FSCACHE_CHECKAUX_OBSOLETE:
45863 - fscache_stat(&fscache_n_checkaux_obsolete);
45864 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45865 break;
45866
45867 default:
45868 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45869 index 30afdfa..2256596 100644
45870 --- a/fs/fscache/operation.c
45871 +++ b/fs/fscache/operation.c
45872 @@ -17,7 +17,7 @@
45873 #include <linux/slab.h>
45874 #include "internal.h"
45875
45876 -atomic_t fscache_op_debug_id;
45877 +atomic_unchecked_t fscache_op_debug_id;
45878 EXPORT_SYMBOL(fscache_op_debug_id);
45879
45880 /**
45881 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45882 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45883 ASSERTCMP(atomic_read(&op->usage), >, 0);
45884
45885 - fscache_stat(&fscache_n_op_enqueue);
45886 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45887 switch (op->flags & FSCACHE_OP_TYPE) {
45888 case FSCACHE_OP_ASYNC:
45889 _debug("queue async");
45890 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45891 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45892 if (op->processor)
45893 fscache_enqueue_operation(op);
45894 - fscache_stat(&fscache_n_op_run);
45895 + fscache_stat_unchecked(&fscache_n_op_run);
45896 }
45897
45898 /*
45899 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45900 if (object->n_ops > 1) {
45901 atomic_inc(&op->usage);
45902 list_add_tail(&op->pend_link, &object->pending_ops);
45903 - fscache_stat(&fscache_n_op_pend);
45904 + fscache_stat_unchecked(&fscache_n_op_pend);
45905 } else if (!list_empty(&object->pending_ops)) {
45906 atomic_inc(&op->usage);
45907 list_add_tail(&op->pend_link, &object->pending_ops);
45908 - fscache_stat(&fscache_n_op_pend);
45909 + fscache_stat_unchecked(&fscache_n_op_pend);
45910 fscache_start_operations(object);
45911 } else {
45912 ASSERTCMP(object->n_in_progress, ==, 0);
45913 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45914 object->n_exclusive++; /* reads and writes must wait */
45915 atomic_inc(&op->usage);
45916 list_add_tail(&op->pend_link, &object->pending_ops);
45917 - fscache_stat(&fscache_n_op_pend);
45918 + fscache_stat_unchecked(&fscache_n_op_pend);
45919 ret = 0;
45920 } else {
45921 /* not allowed to submit ops in any other state */
45922 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45923 if (object->n_exclusive > 0) {
45924 atomic_inc(&op->usage);
45925 list_add_tail(&op->pend_link, &object->pending_ops);
45926 - fscache_stat(&fscache_n_op_pend);
45927 + fscache_stat_unchecked(&fscache_n_op_pend);
45928 } else if (!list_empty(&object->pending_ops)) {
45929 atomic_inc(&op->usage);
45930 list_add_tail(&op->pend_link, &object->pending_ops);
45931 - fscache_stat(&fscache_n_op_pend);
45932 + fscache_stat_unchecked(&fscache_n_op_pend);
45933 fscache_start_operations(object);
45934 } else {
45935 ASSERTCMP(object->n_exclusive, ==, 0);
45936 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45937 object->n_ops++;
45938 atomic_inc(&op->usage);
45939 list_add_tail(&op->pend_link, &object->pending_ops);
45940 - fscache_stat(&fscache_n_op_pend);
45941 + fscache_stat_unchecked(&fscache_n_op_pend);
45942 ret = 0;
45943 } else if (object->state == FSCACHE_OBJECT_DYING ||
45944 object->state == FSCACHE_OBJECT_LC_DYING ||
45945 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45946 - fscache_stat(&fscache_n_op_rejected);
45947 + fscache_stat_unchecked(&fscache_n_op_rejected);
45948 ret = -ENOBUFS;
45949 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45950 fscache_report_unexpected_submission(object, op, ostate);
45951 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45952
45953 ret = -EBUSY;
45954 if (!list_empty(&op->pend_link)) {
45955 - fscache_stat(&fscache_n_op_cancelled);
45956 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45957 list_del_init(&op->pend_link);
45958 object->n_ops--;
45959 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45960 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45961 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45962 BUG();
45963
45964 - fscache_stat(&fscache_n_op_release);
45965 + fscache_stat_unchecked(&fscache_n_op_release);
45966
45967 if (op->release) {
45968 op->release(op);
45969 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45970 * lock, and defer it otherwise */
45971 if (!spin_trylock(&object->lock)) {
45972 _debug("defer put");
45973 - fscache_stat(&fscache_n_op_deferred_release);
45974 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45975
45976 cache = object->cache;
45977 spin_lock(&cache->op_gc_list_lock);
45978 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45979
45980 _debug("GC DEFERRED REL OBJ%x OP%x",
45981 object->debug_id, op->debug_id);
45982 - fscache_stat(&fscache_n_op_gc);
45983 + fscache_stat_unchecked(&fscache_n_op_gc);
45984
45985 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45986
45987 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45988 index 3f7a59b..cf196cc 100644
45989 --- a/fs/fscache/page.c
45990 +++ b/fs/fscache/page.c
45991 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45992 val = radix_tree_lookup(&cookie->stores, page->index);
45993 if (!val) {
45994 rcu_read_unlock();
45995 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45996 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45997 __fscache_uncache_page(cookie, page);
45998 return true;
45999 }
46000 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46001 spin_unlock(&cookie->stores_lock);
46002
46003 if (xpage) {
46004 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46005 - fscache_stat(&fscache_n_store_radix_deletes);
46006 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46007 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46008 ASSERTCMP(xpage, ==, page);
46009 } else {
46010 - fscache_stat(&fscache_n_store_vmscan_gone);
46011 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46012 }
46013
46014 wake_up_bit(&cookie->flags, 0);
46015 @@ -107,7 +107,7 @@ page_busy:
46016 /* we might want to wait here, but that could deadlock the allocator as
46017 * the work threads writing to the cache may all end up sleeping
46018 * on memory allocation */
46019 - fscache_stat(&fscache_n_store_vmscan_busy);
46020 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46021 return false;
46022 }
46023 EXPORT_SYMBOL(__fscache_maybe_release_page);
46024 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46025 FSCACHE_COOKIE_STORING_TAG);
46026 if (!radix_tree_tag_get(&cookie->stores, page->index,
46027 FSCACHE_COOKIE_PENDING_TAG)) {
46028 - fscache_stat(&fscache_n_store_radix_deletes);
46029 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46030 xpage = radix_tree_delete(&cookie->stores, page->index);
46031 }
46032 spin_unlock(&cookie->stores_lock);
46033 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46034
46035 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46036
46037 - fscache_stat(&fscache_n_attr_changed_calls);
46038 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46039
46040 if (fscache_object_is_active(object)) {
46041 fscache_stat(&fscache_n_cop_attr_changed);
46042 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46043
46044 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46045
46046 - fscache_stat(&fscache_n_attr_changed);
46047 + fscache_stat_unchecked(&fscache_n_attr_changed);
46048
46049 op = kzalloc(sizeof(*op), GFP_KERNEL);
46050 if (!op) {
46051 - fscache_stat(&fscache_n_attr_changed_nomem);
46052 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46053 _leave(" = -ENOMEM");
46054 return -ENOMEM;
46055 }
46056 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46057 if (fscache_submit_exclusive_op(object, op) < 0)
46058 goto nobufs;
46059 spin_unlock(&cookie->lock);
46060 - fscache_stat(&fscache_n_attr_changed_ok);
46061 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46062 fscache_put_operation(op);
46063 _leave(" = 0");
46064 return 0;
46065 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46066 nobufs:
46067 spin_unlock(&cookie->lock);
46068 kfree(op);
46069 - fscache_stat(&fscache_n_attr_changed_nobufs);
46070 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46071 _leave(" = %d", -ENOBUFS);
46072 return -ENOBUFS;
46073 }
46074 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46075 /* allocate a retrieval operation and attempt to submit it */
46076 op = kzalloc(sizeof(*op), GFP_NOIO);
46077 if (!op) {
46078 - fscache_stat(&fscache_n_retrievals_nomem);
46079 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46080 return NULL;
46081 }
46082
46083 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46084 return 0;
46085 }
46086
46087 - fscache_stat(&fscache_n_retrievals_wait);
46088 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46089
46090 jif = jiffies;
46091 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46092 fscache_wait_bit_interruptible,
46093 TASK_INTERRUPTIBLE) != 0) {
46094 - fscache_stat(&fscache_n_retrievals_intr);
46095 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46096 _leave(" = -ERESTARTSYS");
46097 return -ERESTARTSYS;
46098 }
46099 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46100 */
46101 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46102 struct fscache_retrieval *op,
46103 - atomic_t *stat_op_waits,
46104 - atomic_t *stat_object_dead)
46105 + atomic_unchecked_t *stat_op_waits,
46106 + atomic_unchecked_t *stat_object_dead)
46107 {
46108 int ret;
46109
46110 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46111 goto check_if_dead;
46112
46113 _debug(">>> WT");
46114 - fscache_stat(stat_op_waits);
46115 + fscache_stat_unchecked(stat_op_waits);
46116 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46117 fscache_wait_bit_interruptible,
46118 TASK_INTERRUPTIBLE) < 0) {
46119 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46120
46121 check_if_dead:
46122 if (unlikely(fscache_object_is_dead(object))) {
46123 - fscache_stat(stat_object_dead);
46124 + fscache_stat_unchecked(stat_object_dead);
46125 return -ENOBUFS;
46126 }
46127 return 0;
46128 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46129
46130 _enter("%p,%p,,,", cookie, page);
46131
46132 - fscache_stat(&fscache_n_retrievals);
46133 + fscache_stat_unchecked(&fscache_n_retrievals);
46134
46135 if (hlist_empty(&cookie->backing_objects))
46136 goto nobufs;
46137 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46138 goto nobufs_unlock;
46139 spin_unlock(&cookie->lock);
46140
46141 - fscache_stat(&fscache_n_retrieval_ops);
46142 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46143
46144 /* pin the netfs read context in case we need to do the actual netfs
46145 * read because we've encountered a cache read failure */
46146 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46147
46148 error:
46149 if (ret == -ENOMEM)
46150 - fscache_stat(&fscache_n_retrievals_nomem);
46151 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46152 else if (ret == -ERESTARTSYS)
46153 - fscache_stat(&fscache_n_retrievals_intr);
46154 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46155 else if (ret == -ENODATA)
46156 - fscache_stat(&fscache_n_retrievals_nodata);
46157 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46158 else if (ret < 0)
46159 - fscache_stat(&fscache_n_retrievals_nobufs);
46160 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46161 else
46162 - fscache_stat(&fscache_n_retrievals_ok);
46163 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46164
46165 fscache_put_retrieval(op);
46166 _leave(" = %d", ret);
46167 @@ -429,7 +429,7 @@ nobufs_unlock:
46168 spin_unlock(&cookie->lock);
46169 kfree(op);
46170 nobufs:
46171 - fscache_stat(&fscache_n_retrievals_nobufs);
46172 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46173 _leave(" = -ENOBUFS");
46174 return -ENOBUFS;
46175 }
46176 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46177
46178 _enter("%p,,%d,,,", cookie, *nr_pages);
46179
46180 - fscache_stat(&fscache_n_retrievals);
46181 + fscache_stat_unchecked(&fscache_n_retrievals);
46182
46183 if (hlist_empty(&cookie->backing_objects))
46184 goto nobufs;
46185 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46186 goto nobufs_unlock;
46187 spin_unlock(&cookie->lock);
46188
46189 - fscache_stat(&fscache_n_retrieval_ops);
46190 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46191
46192 /* pin the netfs read context in case we need to do the actual netfs
46193 * read because we've encountered a cache read failure */
46194 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46195
46196 error:
46197 if (ret == -ENOMEM)
46198 - fscache_stat(&fscache_n_retrievals_nomem);
46199 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46200 else if (ret == -ERESTARTSYS)
46201 - fscache_stat(&fscache_n_retrievals_intr);
46202 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46203 else if (ret == -ENODATA)
46204 - fscache_stat(&fscache_n_retrievals_nodata);
46205 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46206 else if (ret < 0)
46207 - fscache_stat(&fscache_n_retrievals_nobufs);
46208 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46209 else
46210 - fscache_stat(&fscache_n_retrievals_ok);
46211 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46212
46213 fscache_put_retrieval(op);
46214 _leave(" = %d", ret);
46215 @@ -545,7 +545,7 @@ nobufs_unlock:
46216 spin_unlock(&cookie->lock);
46217 kfree(op);
46218 nobufs:
46219 - fscache_stat(&fscache_n_retrievals_nobufs);
46220 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46221 _leave(" = -ENOBUFS");
46222 return -ENOBUFS;
46223 }
46224 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46225
46226 _enter("%p,%p,,,", cookie, page);
46227
46228 - fscache_stat(&fscache_n_allocs);
46229 + fscache_stat_unchecked(&fscache_n_allocs);
46230
46231 if (hlist_empty(&cookie->backing_objects))
46232 goto nobufs;
46233 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46234 goto nobufs_unlock;
46235 spin_unlock(&cookie->lock);
46236
46237 - fscache_stat(&fscache_n_alloc_ops);
46238 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46239
46240 ret = fscache_wait_for_retrieval_activation(
46241 object, op,
46242 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46243
46244 error:
46245 if (ret == -ERESTARTSYS)
46246 - fscache_stat(&fscache_n_allocs_intr);
46247 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46248 else if (ret < 0)
46249 - fscache_stat(&fscache_n_allocs_nobufs);
46250 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46251 else
46252 - fscache_stat(&fscache_n_allocs_ok);
46253 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46254
46255 fscache_put_retrieval(op);
46256 _leave(" = %d", ret);
46257 @@ -625,7 +625,7 @@ nobufs_unlock:
46258 spin_unlock(&cookie->lock);
46259 kfree(op);
46260 nobufs:
46261 - fscache_stat(&fscache_n_allocs_nobufs);
46262 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46263 _leave(" = -ENOBUFS");
46264 return -ENOBUFS;
46265 }
46266 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46267
46268 spin_lock(&cookie->stores_lock);
46269
46270 - fscache_stat(&fscache_n_store_calls);
46271 + fscache_stat_unchecked(&fscache_n_store_calls);
46272
46273 /* find a page to store */
46274 page = NULL;
46275 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46276 page = results[0];
46277 _debug("gang %d [%lx]", n, page->index);
46278 if (page->index > op->store_limit) {
46279 - fscache_stat(&fscache_n_store_pages_over_limit);
46280 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46281 goto superseded;
46282 }
46283
46284 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46285 spin_unlock(&cookie->stores_lock);
46286 spin_unlock(&object->lock);
46287
46288 - fscache_stat(&fscache_n_store_pages);
46289 + fscache_stat_unchecked(&fscache_n_store_pages);
46290 fscache_stat(&fscache_n_cop_write_page);
46291 ret = object->cache->ops->write_page(op, page);
46292 fscache_stat_d(&fscache_n_cop_write_page);
46293 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46294 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46295 ASSERT(PageFsCache(page));
46296
46297 - fscache_stat(&fscache_n_stores);
46298 + fscache_stat_unchecked(&fscache_n_stores);
46299
46300 op = kzalloc(sizeof(*op), GFP_NOIO);
46301 if (!op)
46302 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46303 spin_unlock(&cookie->stores_lock);
46304 spin_unlock(&object->lock);
46305
46306 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46307 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46308 op->store_limit = object->store_limit;
46309
46310 if (fscache_submit_op(object, &op->op) < 0)
46311 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46312
46313 spin_unlock(&cookie->lock);
46314 radix_tree_preload_end();
46315 - fscache_stat(&fscache_n_store_ops);
46316 - fscache_stat(&fscache_n_stores_ok);
46317 + fscache_stat_unchecked(&fscache_n_store_ops);
46318 + fscache_stat_unchecked(&fscache_n_stores_ok);
46319
46320 /* the work queue now carries its own ref on the object */
46321 fscache_put_operation(&op->op);
46322 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46323 return 0;
46324
46325 already_queued:
46326 - fscache_stat(&fscache_n_stores_again);
46327 + fscache_stat_unchecked(&fscache_n_stores_again);
46328 already_pending:
46329 spin_unlock(&cookie->stores_lock);
46330 spin_unlock(&object->lock);
46331 spin_unlock(&cookie->lock);
46332 radix_tree_preload_end();
46333 kfree(op);
46334 - fscache_stat(&fscache_n_stores_ok);
46335 + fscache_stat_unchecked(&fscache_n_stores_ok);
46336 _leave(" = 0");
46337 return 0;
46338
46339 @@ -851,14 +851,14 @@ nobufs:
46340 spin_unlock(&cookie->lock);
46341 radix_tree_preload_end();
46342 kfree(op);
46343 - fscache_stat(&fscache_n_stores_nobufs);
46344 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46345 _leave(" = -ENOBUFS");
46346 return -ENOBUFS;
46347
46348 nomem_free:
46349 kfree(op);
46350 nomem:
46351 - fscache_stat(&fscache_n_stores_oom);
46352 + fscache_stat_unchecked(&fscache_n_stores_oom);
46353 _leave(" = -ENOMEM");
46354 return -ENOMEM;
46355 }
46356 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46357 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46358 ASSERTCMP(page, !=, NULL);
46359
46360 - fscache_stat(&fscache_n_uncaches);
46361 + fscache_stat_unchecked(&fscache_n_uncaches);
46362
46363 /* cache withdrawal may beat us to it */
46364 if (!PageFsCache(page))
46365 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46366 unsigned long loop;
46367
46368 #ifdef CONFIG_FSCACHE_STATS
46369 - atomic_add(pagevec->nr, &fscache_n_marks);
46370 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46371 #endif
46372
46373 for (loop = 0; loop < pagevec->nr; loop++) {
46374 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46375 index 4765190..2a067f2 100644
46376 --- a/fs/fscache/stats.c
46377 +++ b/fs/fscache/stats.c
46378 @@ -18,95 +18,95 @@
46379 /*
46380 * operation counters
46381 */
46382 -atomic_t fscache_n_op_pend;
46383 -atomic_t fscache_n_op_run;
46384 -atomic_t fscache_n_op_enqueue;
46385 -atomic_t fscache_n_op_requeue;
46386 -atomic_t fscache_n_op_deferred_release;
46387 -atomic_t fscache_n_op_release;
46388 -atomic_t fscache_n_op_gc;
46389 -atomic_t fscache_n_op_cancelled;
46390 -atomic_t fscache_n_op_rejected;
46391 +atomic_unchecked_t fscache_n_op_pend;
46392 +atomic_unchecked_t fscache_n_op_run;
46393 +atomic_unchecked_t fscache_n_op_enqueue;
46394 +atomic_unchecked_t fscache_n_op_requeue;
46395 +atomic_unchecked_t fscache_n_op_deferred_release;
46396 +atomic_unchecked_t fscache_n_op_release;
46397 +atomic_unchecked_t fscache_n_op_gc;
46398 +atomic_unchecked_t fscache_n_op_cancelled;
46399 +atomic_unchecked_t fscache_n_op_rejected;
46400
46401 -atomic_t fscache_n_attr_changed;
46402 -atomic_t fscache_n_attr_changed_ok;
46403 -atomic_t fscache_n_attr_changed_nobufs;
46404 -atomic_t fscache_n_attr_changed_nomem;
46405 -atomic_t fscache_n_attr_changed_calls;
46406 +atomic_unchecked_t fscache_n_attr_changed;
46407 +atomic_unchecked_t fscache_n_attr_changed_ok;
46408 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46409 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46410 +atomic_unchecked_t fscache_n_attr_changed_calls;
46411
46412 -atomic_t fscache_n_allocs;
46413 -atomic_t fscache_n_allocs_ok;
46414 -atomic_t fscache_n_allocs_wait;
46415 -atomic_t fscache_n_allocs_nobufs;
46416 -atomic_t fscache_n_allocs_intr;
46417 -atomic_t fscache_n_allocs_object_dead;
46418 -atomic_t fscache_n_alloc_ops;
46419 -atomic_t fscache_n_alloc_op_waits;
46420 +atomic_unchecked_t fscache_n_allocs;
46421 +atomic_unchecked_t fscache_n_allocs_ok;
46422 +atomic_unchecked_t fscache_n_allocs_wait;
46423 +atomic_unchecked_t fscache_n_allocs_nobufs;
46424 +atomic_unchecked_t fscache_n_allocs_intr;
46425 +atomic_unchecked_t fscache_n_allocs_object_dead;
46426 +atomic_unchecked_t fscache_n_alloc_ops;
46427 +atomic_unchecked_t fscache_n_alloc_op_waits;
46428
46429 -atomic_t fscache_n_retrievals;
46430 -atomic_t fscache_n_retrievals_ok;
46431 -atomic_t fscache_n_retrievals_wait;
46432 -atomic_t fscache_n_retrievals_nodata;
46433 -atomic_t fscache_n_retrievals_nobufs;
46434 -atomic_t fscache_n_retrievals_intr;
46435 -atomic_t fscache_n_retrievals_nomem;
46436 -atomic_t fscache_n_retrievals_object_dead;
46437 -atomic_t fscache_n_retrieval_ops;
46438 -atomic_t fscache_n_retrieval_op_waits;
46439 +atomic_unchecked_t fscache_n_retrievals;
46440 +atomic_unchecked_t fscache_n_retrievals_ok;
46441 +atomic_unchecked_t fscache_n_retrievals_wait;
46442 +atomic_unchecked_t fscache_n_retrievals_nodata;
46443 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46444 +atomic_unchecked_t fscache_n_retrievals_intr;
46445 +atomic_unchecked_t fscache_n_retrievals_nomem;
46446 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46447 +atomic_unchecked_t fscache_n_retrieval_ops;
46448 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46449
46450 -atomic_t fscache_n_stores;
46451 -atomic_t fscache_n_stores_ok;
46452 -atomic_t fscache_n_stores_again;
46453 -atomic_t fscache_n_stores_nobufs;
46454 -atomic_t fscache_n_stores_oom;
46455 -atomic_t fscache_n_store_ops;
46456 -atomic_t fscache_n_store_calls;
46457 -atomic_t fscache_n_store_pages;
46458 -atomic_t fscache_n_store_radix_deletes;
46459 -atomic_t fscache_n_store_pages_over_limit;
46460 +atomic_unchecked_t fscache_n_stores;
46461 +atomic_unchecked_t fscache_n_stores_ok;
46462 +atomic_unchecked_t fscache_n_stores_again;
46463 +atomic_unchecked_t fscache_n_stores_nobufs;
46464 +atomic_unchecked_t fscache_n_stores_oom;
46465 +atomic_unchecked_t fscache_n_store_ops;
46466 +atomic_unchecked_t fscache_n_store_calls;
46467 +atomic_unchecked_t fscache_n_store_pages;
46468 +atomic_unchecked_t fscache_n_store_radix_deletes;
46469 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46470
46471 -atomic_t fscache_n_store_vmscan_not_storing;
46472 -atomic_t fscache_n_store_vmscan_gone;
46473 -atomic_t fscache_n_store_vmscan_busy;
46474 -atomic_t fscache_n_store_vmscan_cancelled;
46475 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46476 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46477 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46478 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46479
46480 -atomic_t fscache_n_marks;
46481 -atomic_t fscache_n_uncaches;
46482 +atomic_unchecked_t fscache_n_marks;
46483 +atomic_unchecked_t fscache_n_uncaches;
46484
46485 -atomic_t fscache_n_acquires;
46486 -atomic_t fscache_n_acquires_null;
46487 -atomic_t fscache_n_acquires_no_cache;
46488 -atomic_t fscache_n_acquires_ok;
46489 -atomic_t fscache_n_acquires_nobufs;
46490 -atomic_t fscache_n_acquires_oom;
46491 +atomic_unchecked_t fscache_n_acquires;
46492 +atomic_unchecked_t fscache_n_acquires_null;
46493 +atomic_unchecked_t fscache_n_acquires_no_cache;
46494 +atomic_unchecked_t fscache_n_acquires_ok;
46495 +atomic_unchecked_t fscache_n_acquires_nobufs;
46496 +atomic_unchecked_t fscache_n_acquires_oom;
46497
46498 -atomic_t fscache_n_updates;
46499 -atomic_t fscache_n_updates_null;
46500 -atomic_t fscache_n_updates_run;
46501 +atomic_unchecked_t fscache_n_updates;
46502 +atomic_unchecked_t fscache_n_updates_null;
46503 +atomic_unchecked_t fscache_n_updates_run;
46504
46505 -atomic_t fscache_n_relinquishes;
46506 -atomic_t fscache_n_relinquishes_null;
46507 -atomic_t fscache_n_relinquishes_waitcrt;
46508 -atomic_t fscache_n_relinquishes_retire;
46509 +atomic_unchecked_t fscache_n_relinquishes;
46510 +atomic_unchecked_t fscache_n_relinquishes_null;
46511 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46512 +atomic_unchecked_t fscache_n_relinquishes_retire;
46513
46514 -atomic_t fscache_n_cookie_index;
46515 -atomic_t fscache_n_cookie_data;
46516 -atomic_t fscache_n_cookie_special;
46517 +atomic_unchecked_t fscache_n_cookie_index;
46518 +atomic_unchecked_t fscache_n_cookie_data;
46519 +atomic_unchecked_t fscache_n_cookie_special;
46520
46521 -atomic_t fscache_n_object_alloc;
46522 -atomic_t fscache_n_object_no_alloc;
46523 -atomic_t fscache_n_object_lookups;
46524 -atomic_t fscache_n_object_lookups_negative;
46525 -atomic_t fscache_n_object_lookups_positive;
46526 -atomic_t fscache_n_object_lookups_timed_out;
46527 -atomic_t fscache_n_object_created;
46528 -atomic_t fscache_n_object_avail;
46529 -atomic_t fscache_n_object_dead;
46530 +atomic_unchecked_t fscache_n_object_alloc;
46531 +atomic_unchecked_t fscache_n_object_no_alloc;
46532 +atomic_unchecked_t fscache_n_object_lookups;
46533 +atomic_unchecked_t fscache_n_object_lookups_negative;
46534 +atomic_unchecked_t fscache_n_object_lookups_positive;
46535 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46536 +atomic_unchecked_t fscache_n_object_created;
46537 +atomic_unchecked_t fscache_n_object_avail;
46538 +atomic_unchecked_t fscache_n_object_dead;
46539
46540 -atomic_t fscache_n_checkaux_none;
46541 -atomic_t fscache_n_checkaux_okay;
46542 -atomic_t fscache_n_checkaux_update;
46543 -atomic_t fscache_n_checkaux_obsolete;
46544 +atomic_unchecked_t fscache_n_checkaux_none;
46545 +atomic_unchecked_t fscache_n_checkaux_okay;
46546 +atomic_unchecked_t fscache_n_checkaux_update;
46547 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46548
46549 atomic_t fscache_n_cop_alloc_object;
46550 atomic_t fscache_n_cop_lookup_object;
46551 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46552 seq_puts(m, "FS-Cache statistics\n");
46553
46554 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46555 - atomic_read(&fscache_n_cookie_index),
46556 - atomic_read(&fscache_n_cookie_data),
46557 - atomic_read(&fscache_n_cookie_special));
46558 + atomic_read_unchecked(&fscache_n_cookie_index),
46559 + atomic_read_unchecked(&fscache_n_cookie_data),
46560 + atomic_read_unchecked(&fscache_n_cookie_special));
46561
46562 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46563 - atomic_read(&fscache_n_object_alloc),
46564 - atomic_read(&fscache_n_object_no_alloc),
46565 - atomic_read(&fscache_n_object_avail),
46566 - atomic_read(&fscache_n_object_dead));
46567 + atomic_read_unchecked(&fscache_n_object_alloc),
46568 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46569 + atomic_read_unchecked(&fscache_n_object_avail),
46570 + atomic_read_unchecked(&fscache_n_object_dead));
46571 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46572 - atomic_read(&fscache_n_checkaux_none),
46573 - atomic_read(&fscache_n_checkaux_okay),
46574 - atomic_read(&fscache_n_checkaux_update),
46575 - atomic_read(&fscache_n_checkaux_obsolete));
46576 + atomic_read_unchecked(&fscache_n_checkaux_none),
46577 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46578 + atomic_read_unchecked(&fscache_n_checkaux_update),
46579 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46580
46581 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46582 - atomic_read(&fscache_n_marks),
46583 - atomic_read(&fscache_n_uncaches));
46584 + atomic_read_unchecked(&fscache_n_marks),
46585 + atomic_read_unchecked(&fscache_n_uncaches));
46586
46587 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46588 " oom=%u\n",
46589 - atomic_read(&fscache_n_acquires),
46590 - atomic_read(&fscache_n_acquires_null),
46591 - atomic_read(&fscache_n_acquires_no_cache),
46592 - atomic_read(&fscache_n_acquires_ok),
46593 - atomic_read(&fscache_n_acquires_nobufs),
46594 - atomic_read(&fscache_n_acquires_oom));
46595 + atomic_read_unchecked(&fscache_n_acquires),
46596 + atomic_read_unchecked(&fscache_n_acquires_null),
46597 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46598 + atomic_read_unchecked(&fscache_n_acquires_ok),
46599 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46600 + atomic_read_unchecked(&fscache_n_acquires_oom));
46601
46602 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46603 - atomic_read(&fscache_n_object_lookups),
46604 - atomic_read(&fscache_n_object_lookups_negative),
46605 - atomic_read(&fscache_n_object_lookups_positive),
46606 - atomic_read(&fscache_n_object_created),
46607 - atomic_read(&fscache_n_object_lookups_timed_out));
46608 + atomic_read_unchecked(&fscache_n_object_lookups),
46609 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46610 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46611 + atomic_read_unchecked(&fscache_n_object_created),
46612 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46613
46614 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46615 - atomic_read(&fscache_n_updates),
46616 - atomic_read(&fscache_n_updates_null),
46617 - atomic_read(&fscache_n_updates_run));
46618 + atomic_read_unchecked(&fscache_n_updates),
46619 + atomic_read_unchecked(&fscache_n_updates_null),
46620 + atomic_read_unchecked(&fscache_n_updates_run));
46621
46622 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46623 - atomic_read(&fscache_n_relinquishes),
46624 - atomic_read(&fscache_n_relinquishes_null),
46625 - atomic_read(&fscache_n_relinquishes_waitcrt),
46626 - atomic_read(&fscache_n_relinquishes_retire));
46627 + atomic_read_unchecked(&fscache_n_relinquishes),
46628 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46629 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46630 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46631
46632 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46633 - atomic_read(&fscache_n_attr_changed),
46634 - atomic_read(&fscache_n_attr_changed_ok),
46635 - atomic_read(&fscache_n_attr_changed_nobufs),
46636 - atomic_read(&fscache_n_attr_changed_nomem),
46637 - atomic_read(&fscache_n_attr_changed_calls));
46638 + atomic_read_unchecked(&fscache_n_attr_changed),
46639 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46640 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46641 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46642 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46643
46644 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46645 - atomic_read(&fscache_n_allocs),
46646 - atomic_read(&fscache_n_allocs_ok),
46647 - atomic_read(&fscache_n_allocs_wait),
46648 - atomic_read(&fscache_n_allocs_nobufs),
46649 - atomic_read(&fscache_n_allocs_intr));
46650 + atomic_read_unchecked(&fscache_n_allocs),
46651 + atomic_read_unchecked(&fscache_n_allocs_ok),
46652 + atomic_read_unchecked(&fscache_n_allocs_wait),
46653 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46654 + atomic_read_unchecked(&fscache_n_allocs_intr));
46655 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46656 - atomic_read(&fscache_n_alloc_ops),
46657 - atomic_read(&fscache_n_alloc_op_waits),
46658 - atomic_read(&fscache_n_allocs_object_dead));
46659 + atomic_read_unchecked(&fscache_n_alloc_ops),
46660 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46661 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46662
46663 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46664 " int=%u oom=%u\n",
46665 - atomic_read(&fscache_n_retrievals),
46666 - atomic_read(&fscache_n_retrievals_ok),
46667 - atomic_read(&fscache_n_retrievals_wait),
46668 - atomic_read(&fscache_n_retrievals_nodata),
46669 - atomic_read(&fscache_n_retrievals_nobufs),
46670 - atomic_read(&fscache_n_retrievals_intr),
46671 - atomic_read(&fscache_n_retrievals_nomem));
46672 + atomic_read_unchecked(&fscache_n_retrievals),
46673 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46674 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46675 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46676 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46677 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46678 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46679 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46680 - atomic_read(&fscache_n_retrieval_ops),
46681 - atomic_read(&fscache_n_retrieval_op_waits),
46682 - atomic_read(&fscache_n_retrievals_object_dead));
46683 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46684 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46685 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46686
46687 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46688 - atomic_read(&fscache_n_stores),
46689 - atomic_read(&fscache_n_stores_ok),
46690 - atomic_read(&fscache_n_stores_again),
46691 - atomic_read(&fscache_n_stores_nobufs),
46692 - atomic_read(&fscache_n_stores_oom));
46693 + atomic_read_unchecked(&fscache_n_stores),
46694 + atomic_read_unchecked(&fscache_n_stores_ok),
46695 + atomic_read_unchecked(&fscache_n_stores_again),
46696 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46697 + atomic_read_unchecked(&fscache_n_stores_oom));
46698 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46699 - atomic_read(&fscache_n_store_ops),
46700 - atomic_read(&fscache_n_store_calls),
46701 - atomic_read(&fscache_n_store_pages),
46702 - atomic_read(&fscache_n_store_radix_deletes),
46703 - atomic_read(&fscache_n_store_pages_over_limit));
46704 + atomic_read_unchecked(&fscache_n_store_ops),
46705 + atomic_read_unchecked(&fscache_n_store_calls),
46706 + atomic_read_unchecked(&fscache_n_store_pages),
46707 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46708 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46709
46710 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46711 - atomic_read(&fscache_n_store_vmscan_not_storing),
46712 - atomic_read(&fscache_n_store_vmscan_gone),
46713 - atomic_read(&fscache_n_store_vmscan_busy),
46714 - atomic_read(&fscache_n_store_vmscan_cancelled));
46715 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46716 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46717 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46718 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46719
46720 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46721 - atomic_read(&fscache_n_op_pend),
46722 - atomic_read(&fscache_n_op_run),
46723 - atomic_read(&fscache_n_op_enqueue),
46724 - atomic_read(&fscache_n_op_cancelled),
46725 - atomic_read(&fscache_n_op_rejected));
46726 + atomic_read_unchecked(&fscache_n_op_pend),
46727 + atomic_read_unchecked(&fscache_n_op_run),
46728 + atomic_read_unchecked(&fscache_n_op_enqueue),
46729 + atomic_read_unchecked(&fscache_n_op_cancelled),
46730 + atomic_read_unchecked(&fscache_n_op_rejected));
46731 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46732 - atomic_read(&fscache_n_op_deferred_release),
46733 - atomic_read(&fscache_n_op_release),
46734 - atomic_read(&fscache_n_op_gc));
46735 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46736 + atomic_read_unchecked(&fscache_n_op_release),
46737 + atomic_read_unchecked(&fscache_n_op_gc));
46738
46739 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46740 atomic_read(&fscache_n_cop_alloc_object),
46741 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46742 index 3426521..3b75162 100644
46743 --- a/fs/fuse/cuse.c
46744 +++ b/fs/fuse/cuse.c
46745 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46746 INIT_LIST_HEAD(&cuse_conntbl[i]);
46747
46748 /* inherit and extend fuse_dev_operations */
46749 - cuse_channel_fops = fuse_dev_operations;
46750 - cuse_channel_fops.owner = THIS_MODULE;
46751 - cuse_channel_fops.open = cuse_channel_open;
46752 - cuse_channel_fops.release = cuse_channel_release;
46753 + pax_open_kernel();
46754 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46755 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46756 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46757 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46758 + pax_close_kernel();
46759
46760 cuse_class = class_create(THIS_MODULE, "cuse");
46761 if (IS_ERR(cuse_class))
46762 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46763 index 7df2b5e..5804aa7 100644
46764 --- a/fs/fuse/dev.c
46765 +++ b/fs/fuse/dev.c
46766 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46767 ret = 0;
46768 pipe_lock(pipe);
46769
46770 - if (!pipe->readers) {
46771 + if (!atomic_read(&pipe->readers)) {
46772 send_sig(SIGPIPE, current, 0);
46773 if (!ret)
46774 ret = -EPIPE;
46775 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46776 index 334e0b1..fc571e8 100644
46777 --- a/fs/fuse/dir.c
46778 +++ b/fs/fuse/dir.c
46779 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46780 return link;
46781 }
46782
46783 -static void free_link(char *link)
46784 +static void free_link(const char *link)
46785 {
46786 if (!IS_ERR(link))
46787 free_page((unsigned long) link);
46788 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46789 index a9ba244..d9df391 100644
46790 --- a/fs/gfs2/inode.c
46791 +++ b/fs/gfs2/inode.c
46792 @@ -1496,7 +1496,7 @@ out:
46793
46794 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46795 {
46796 - char *s = nd_get_link(nd);
46797 + const char *s = nd_get_link(nd);
46798 if (!IS_ERR(s))
46799 kfree(s);
46800 }
46801 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46802 index cc9281b..58996fb 100644
46803 --- a/fs/hugetlbfs/inode.c
46804 +++ b/fs/hugetlbfs/inode.c
46805 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46806 .kill_sb = kill_litter_super,
46807 };
46808
46809 -static struct vfsmount *hugetlbfs_vfsmount;
46810 +struct vfsmount *hugetlbfs_vfsmount;
46811
46812 static int can_do_hugetlb_shm(void)
46813 {
46814 diff --git a/fs/inode.c b/fs/inode.c
46815 index c99163b..a11ad40 100644
46816 --- a/fs/inode.c
46817 +++ b/fs/inode.c
46818 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46819
46820 #ifdef CONFIG_SMP
46821 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46822 - static atomic_t shared_last_ino;
46823 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46824 + static atomic_unchecked_t shared_last_ino;
46825 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46826
46827 res = next - LAST_INO_BATCH;
46828 }
46829 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46830 index 4a6cf28..d3a29d3 100644
46831 --- a/fs/jffs2/erase.c
46832 +++ b/fs/jffs2/erase.c
46833 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46834 struct jffs2_unknown_node marker = {
46835 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46836 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46837 - .totlen = cpu_to_je32(c->cleanmarker_size)
46838 + .totlen = cpu_to_je32(c->cleanmarker_size),
46839 + .hdr_crc = cpu_to_je32(0)
46840 };
46841
46842 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46843 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46844 index 6f4529d..bf12806 100644
46845 --- a/fs/jffs2/wbuf.c
46846 +++ b/fs/jffs2/wbuf.c
46847 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46848 {
46849 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46850 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46851 - .totlen = constant_cpu_to_je32(8)
46852 + .totlen = constant_cpu_to_je32(8),
46853 + .hdr_crc = constant_cpu_to_je32(0)
46854 };
46855
46856 /*
46857 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46858 index 4a82950..bcaa0cb 100644
46859 --- a/fs/jfs/super.c
46860 +++ b/fs/jfs/super.c
46861 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46862
46863 jfs_inode_cachep =
46864 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46865 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46866 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46867 init_once);
46868 if (jfs_inode_cachep == NULL)
46869 return -ENOMEM;
46870 diff --git a/fs/libfs.c b/fs/libfs.c
46871 index f86ec27..4734776 100644
46872 --- a/fs/libfs.c
46873 +++ b/fs/libfs.c
46874 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46875
46876 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46877 struct dentry *next;
46878 + char d_name[sizeof(next->d_iname)];
46879 + const unsigned char *name;
46880 +
46881 next = list_entry(p, struct dentry, d_u.d_child);
46882 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46883 if (!simple_positive(next)) {
46884 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46885
46886 spin_unlock(&next->d_lock);
46887 spin_unlock(&dentry->d_lock);
46888 - if (filldir(dirent, next->d_name.name,
46889 + name = next->d_name.name;
46890 + if (name == next->d_iname) {
46891 + memcpy(d_name, name, next->d_name.len);
46892 + name = d_name;
46893 + }
46894 + if (filldir(dirent, name,
46895 next->d_name.len, filp->f_pos,
46896 next->d_inode->i_ino,
46897 dt_type(next->d_inode)) < 0)
46898 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46899 index 8392cb8..80d6193 100644
46900 --- a/fs/lockd/clntproc.c
46901 +++ b/fs/lockd/clntproc.c
46902 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46903 /*
46904 * Cookie counter for NLM requests
46905 */
46906 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46907 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46908
46909 void nlmclnt_next_cookie(struct nlm_cookie *c)
46910 {
46911 - u32 cookie = atomic_inc_return(&nlm_cookie);
46912 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46913
46914 memcpy(c->data, &cookie, 4);
46915 c->len=4;
46916 diff --git a/fs/locks.c b/fs/locks.c
46917 index fce6238..34e929c 100644
46918 --- a/fs/locks.c
46919 +++ b/fs/locks.c
46920 @@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
46921 return 0;
46922 }
46923
46924 -static int assign_type(struct file_lock *fl, int type)
46925 +static int assign_type(struct file_lock *fl, long type)
46926 {
46927 switch (type) {
46928 case F_RDLCK:
46929 @@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = {
46930 /*
46931 * Initialize a lease, use the default lock manager operations
46932 */
46933 -static int lease_init(struct file *filp, int type, struct file_lock *fl)
46934 +static int lease_init(struct file *filp, long type, struct file_lock *fl)
46935 {
46936 if (assign_type(fl, type) != 0)
46937 return -EINVAL;
46938 @@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
46939 }
46940
46941 /* Allocate a file_lock initialised to this type of lease */
46942 -static struct file_lock *lease_alloc(struct file *filp, int type)
46943 +static struct file_lock *lease_alloc(struct file *filp, long type)
46944 {
46945 struct file_lock *fl = locks_alloc_lock();
46946 int error = -ENOMEM;
46947 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
46948 return;
46949
46950 if (filp->f_op && filp->f_op->flock) {
46951 - struct file_lock fl = {
46952 + struct file_lock flock = {
46953 .fl_pid = current->tgid,
46954 .fl_file = filp,
46955 .fl_flags = FL_FLOCK,
46956 .fl_type = F_UNLCK,
46957 .fl_end = OFFSET_MAX,
46958 };
46959 - filp->f_op->flock(filp, F_SETLKW, &fl);
46960 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46961 - fl.fl_ops->fl_release_private(&fl);
46962 + filp->f_op->flock(filp, F_SETLKW, &flock);
46963 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46964 + flock.fl_ops->fl_release_private(&flock);
46965 }
46966
46967 lock_flocks();
46968 diff --git a/fs/namei.c b/fs/namei.c
46969 index 7d69419..1487852 100644
46970 --- a/fs/namei.c
46971 +++ b/fs/namei.c
46972 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
46973 if (ret != -EACCES)
46974 return ret;
46975
46976 +#ifdef CONFIG_GRKERNSEC
46977 + /* we'll block if we have to log due to a denied capability use */
46978 + if (mask & MAY_NOT_BLOCK)
46979 + return -ECHILD;
46980 +#endif
46981 +
46982 if (S_ISDIR(inode->i_mode)) {
46983 /* DACs are overridable for directories */
46984 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
46985 - return 0;
46986 if (!(mask & MAY_WRITE))
46987 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
46988 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
46989 + inode_capable(inode, CAP_DAC_READ_SEARCH))
46990 return 0;
46991 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
46992 + return 0;
46993 return -EACCES;
46994 }
46995 /*
46996 + * Searching includes executable on directories, else just read.
46997 + */
46998 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46999 + if (mask == MAY_READ)
47000 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47001 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47002 + return 0;
47003 +
47004 + /*
47005 * Read/write DACs are always overridable.
47006 * Executable DACs are overridable when there is
47007 * at least one exec bit set.
47008 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47009 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47010 return 0;
47011
47012 - /*
47013 - * Searching includes executable on directories, else just read.
47014 - */
47015 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47016 - if (mask == MAY_READ)
47017 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47018 - return 0;
47019 -
47020 return -EACCES;
47021 }
47022
47023 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47024 return error;
47025 }
47026
47027 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47028 + dentry->d_inode, dentry, nd->path.mnt)) {
47029 + error = -EACCES;
47030 + *p = ERR_PTR(error); /* no ->put_link(), please */
47031 + path_put(&nd->path);
47032 + return error;
47033 + }
47034 +
47035 nd->last_type = LAST_BIND;
47036 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47037 error = PTR_ERR(*p);
47038 if (!IS_ERR(*p)) {
47039 - char *s = nd_get_link(nd);
47040 + const char *s = nd_get_link(nd);
47041 error = 0;
47042 if (s)
47043 error = __vfs_follow_link(nd, s);
47044 @@ -1386,6 +1402,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47045 if (!res)
47046 res = walk_component(nd, path, &nd->last,
47047 nd->last_type, LOOKUP_FOLLOW);
47048 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
47049 + res = -EACCES;
47050 + }
47051 put_link(nd, &link, cookie);
47052 } while (res > 0);
47053
47054 @@ -1779,6 +1798,9 @@ static int path_lookupat(int dfd, const char *name,
47055 err = follow_link(&link, nd, &cookie);
47056 if (!err)
47057 err = lookup_last(nd, &path);
47058 + if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
47059 + err = -EACCES;
47060 + }
47061 put_link(nd, &link, cookie);
47062 }
47063 }
47064 @@ -1786,6 +1808,21 @@ static int path_lookupat(int dfd, const char *name,
47065 if (!err)
47066 err = complete_walk(nd);
47067
47068 + if (!(nd->flags & LOOKUP_PARENT)) {
47069 +#ifdef CONFIG_GRKERNSEC
47070 + if (flags & LOOKUP_RCU) {
47071 + if (!err)
47072 + path_put(&nd->path);
47073 + err = -ECHILD;
47074 + } else
47075 +#endif
47076 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47077 + if (!err)
47078 + path_put(&nd->path);
47079 + err = -ENOENT;
47080 + }
47081 + }
47082 +
47083 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47084 if (!nd->inode->i_op->lookup) {
47085 path_put(&nd->path);
47086 @@ -1813,6 +1850,15 @@ static int do_path_lookup(int dfd, const char *name,
47087 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47088
47089 if (likely(!retval)) {
47090 + if (*name != '/' && nd->path.dentry && nd->inode) {
47091 +#ifdef CONFIG_GRKERNSEC
47092 + if (flags & LOOKUP_RCU)
47093 + return -ECHILD;
47094 +#endif
47095 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47096 + return -ENOENT;
47097 + }
47098 +
47099 if (unlikely(!audit_dummy_context())) {
47100 if (nd->path.dentry && nd->inode)
47101 audit_inode(name, nd->path.dentry);
47102 @@ -2155,6 +2201,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47103 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47104 return -EPERM;
47105
47106 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47107 + return -EPERM;
47108 + if (gr_handle_rawio(inode))
47109 + return -EPERM;
47110 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47111 + return -EACCES;
47112 +
47113 return 0;
47114 }
47115
47116 @@ -2220,6 +2273,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47117 error = complete_walk(nd);
47118 if (error)
47119 return ERR_PTR(error);
47120 +#ifdef CONFIG_GRKERNSEC
47121 + if (nd->flags & LOOKUP_RCU) {
47122 + error = -ECHILD;
47123 + goto exit;
47124 + }
47125 +#endif
47126 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47127 + error = -ENOENT;
47128 + goto exit;
47129 + }
47130 audit_inode(pathname, nd->path.dentry);
47131 if (open_flag & O_CREAT) {
47132 error = -EISDIR;
47133 @@ -2230,6 +2293,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47134 error = complete_walk(nd);
47135 if (error)
47136 return ERR_PTR(error);
47137 +#ifdef CONFIG_GRKERNSEC
47138 + if (nd->flags & LOOKUP_RCU) {
47139 + error = -ECHILD;
47140 + goto exit;
47141 + }
47142 +#endif
47143 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47144 + error = -ENOENT;
47145 + goto exit;
47146 + }
47147 audit_inode(pathname, dir);
47148 goto ok;
47149 }
47150 @@ -2285,6 +2358,12 @@ retry_lookup:
47151 /* Negative dentry, just create the file */
47152 if (!dentry->d_inode) {
47153 umode_t mode = op->mode;
47154 +
47155 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47156 + error = -EACCES;
47157 + goto exit_mutex_unlock;
47158 + }
47159 +
47160 if (!IS_POSIXACL(dir->d_inode))
47161 mode &= ~current_umask();
47162 /*
47163 @@ -2308,6 +2387,8 @@ retry_lookup:
47164 error = vfs_create(dir->d_inode, dentry, mode, nd);
47165 if (error)
47166 goto exit_mutex_unlock;
47167 + else
47168 + gr_handle_create(path->dentry, path->mnt);
47169 mutex_unlock(&dir->d_inode->i_mutex);
47170 dput(nd->path.dentry);
47171 nd->path.dentry = dentry;
47172 @@ -2317,6 +2398,19 @@ retry_lookup:
47173 /*
47174 * It already exists.
47175 */
47176 +
47177 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47178 + error = -ENOENT;
47179 + goto exit_mutex_unlock;
47180 + }
47181 +
47182 + /* only check if O_CREAT is specified, all other checks need to go
47183 + into may_open */
47184 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47185 + error = -EACCES;
47186 + goto exit_mutex_unlock;
47187 + }
47188 +
47189 mutex_unlock(&dir->d_inode->i_mutex);
47190 audit_inode(pathname, path->dentry);
47191
47192 @@ -2367,6 +2461,16 @@ finish_lookup:
47193 path_put(&save_parent);
47194 return ERR_PTR(error);
47195 }
47196 +#ifdef CONFIG_GRKERNSEC
47197 + if (nd->flags & LOOKUP_RCU) {
47198 + error = -ECHILD;
47199 + goto exit;
47200 + }
47201 +#endif
47202 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47203 + error = -ENOENT;
47204 + goto exit;
47205 + }
47206 error = -EISDIR;
47207 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47208 goto exit;
47209 @@ -2476,8 +2580,14 @@ static struct file *path_openat(int dfd, const char *pathname,
47210 error = follow_link(&link, nd, &cookie);
47211 if (unlikely(error))
47212 filp = ERR_PTR(error);
47213 - else
47214 + else {
47215 filp = do_last(nd, &path, op, pathname);
47216 + if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
47217 + if (filp)
47218 + fput(filp);
47219 + filp = ERR_PTR(-EACCES);
47220 + }
47221 + }
47222 put_link(nd, &link, cookie);
47223 }
47224 out:
47225 @@ -2577,6 +2687,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47226 *path = nd.path;
47227 return dentry;
47228 eexist:
47229 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47230 + dput(dentry);
47231 + dentry = ERR_PTR(-ENOENT);
47232 + goto fail;
47233 + }
47234 dput(dentry);
47235 dentry = ERR_PTR(-EEXIST);
47236 fail:
47237 @@ -2599,6 +2714,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47238 }
47239 EXPORT_SYMBOL(user_path_create);
47240
47241 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47242 +{
47243 + char *tmp = getname(pathname);
47244 + struct dentry *res;
47245 + if (IS_ERR(tmp))
47246 + return ERR_CAST(tmp);
47247 + res = kern_path_create(dfd, tmp, path, is_dir);
47248 + if (IS_ERR(res))
47249 + putname(tmp);
47250 + else
47251 + *to = tmp;
47252 + return res;
47253 +}
47254 +
47255 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47256 {
47257 int error = may_create(dir, dentry);
47258 @@ -2665,6 +2794,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47259 error = mnt_want_write(path.mnt);
47260 if (error)
47261 goto out_dput;
47262 +
47263 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47264 + error = -EPERM;
47265 + goto out_drop_write;
47266 + }
47267 +
47268 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47269 + error = -EACCES;
47270 + goto out_drop_write;
47271 + }
47272 +
47273 error = security_path_mknod(&path, dentry, mode, dev);
47274 if (error)
47275 goto out_drop_write;
47276 @@ -2682,6 +2822,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47277 }
47278 out_drop_write:
47279 mnt_drop_write(path.mnt);
47280 +
47281 + if (!error)
47282 + gr_handle_create(dentry, path.mnt);
47283 out_dput:
47284 dput(dentry);
47285 mutex_unlock(&path.dentry->d_inode->i_mutex);
47286 @@ -2735,12 +2878,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47287 error = mnt_want_write(path.mnt);
47288 if (error)
47289 goto out_dput;
47290 +
47291 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47292 + error = -EACCES;
47293 + goto out_drop_write;
47294 + }
47295 +
47296 error = security_path_mkdir(&path, dentry, mode);
47297 if (error)
47298 goto out_drop_write;
47299 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47300 out_drop_write:
47301 mnt_drop_write(path.mnt);
47302 +
47303 + if (!error)
47304 + gr_handle_create(dentry, path.mnt);
47305 out_dput:
47306 dput(dentry);
47307 mutex_unlock(&path.dentry->d_inode->i_mutex);
47308 @@ -2820,6 +2972,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47309 char * name;
47310 struct dentry *dentry;
47311 struct nameidata nd;
47312 + ino_t saved_ino = 0;
47313 + dev_t saved_dev = 0;
47314
47315 error = user_path_parent(dfd, pathname, &nd, &name);
47316 if (error)
47317 @@ -2848,6 +3002,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47318 error = -ENOENT;
47319 goto exit3;
47320 }
47321 +
47322 + saved_ino = dentry->d_inode->i_ino;
47323 + saved_dev = gr_get_dev_from_dentry(dentry);
47324 +
47325 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47326 + error = -EACCES;
47327 + goto exit3;
47328 + }
47329 +
47330 error = mnt_want_write(nd.path.mnt);
47331 if (error)
47332 goto exit3;
47333 @@ -2855,6 +3018,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47334 if (error)
47335 goto exit4;
47336 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47337 + if (!error && (saved_dev || saved_ino))
47338 + gr_handle_delete(saved_ino, saved_dev);
47339 exit4:
47340 mnt_drop_write(nd.path.mnt);
47341 exit3:
47342 @@ -2917,6 +3082,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47343 struct dentry *dentry;
47344 struct nameidata nd;
47345 struct inode *inode = NULL;
47346 + ino_t saved_ino = 0;
47347 + dev_t saved_dev = 0;
47348
47349 error = user_path_parent(dfd, pathname, &nd, &name);
47350 if (error)
47351 @@ -2939,6 +3106,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47352 if (!inode)
47353 goto slashes;
47354 ihold(inode);
47355 +
47356 + if (inode->i_nlink <= 1) {
47357 + saved_ino = inode->i_ino;
47358 + saved_dev = gr_get_dev_from_dentry(dentry);
47359 + }
47360 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47361 + error = -EACCES;
47362 + goto exit2;
47363 + }
47364 +
47365 error = mnt_want_write(nd.path.mnt);
47366 if (error)
47367 goto exit2;
47368 @@ -2946,6 +3123,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47369 if (error)
47370 goto exit3;
47371 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47372 + if (!error && (saved_ino || saved_dev))
47373 + gr_handle_delete(saved_ino, saved_dev);
47374 exit3:
47375 mnt_drop_write(nd.path.mnt);
47376 exit2:
47377 @@ -3021,10 +3200,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47378 error = mnt_want_write(path.mnt);
47379 if (error)
47380 goto out_dput;
47381 +
47382 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47383 + error = -EACCES;
47384 + goto out_drop_write;
47385 + }
47386 +
47387 error = security_path_symlink(&path, dentry, from);
47388 if (error)
47389 goto out_drop_write;
47390 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47391 + if (!error)
47392 + gr_handle_create(dentry, path.mnt);
47393 out_drop_write:
47394 mnt_drop_write(path.mnt);
47395 out_dput:
47396 @@ -3099,6 +3286,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47397 {
47398 struct dentry *new_dentry;
47399 struct path old_path, new_path;
47400 + char *to = NULL;
47401 int how = 0;
47402 int error;
47403
47404 @@ -3122,7 +3310,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47405 if (error)
47406 return error;
47407
47408 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47409 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47410 error = PTR_ERR(new_dentry);
47411 if (IS_ERR(new_dentry))
47412 goto out;
47413 @@ -3133,13 +3321,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47414 error = mnt_want_write(new_path.mnt);
47415 if (error)
47416 goto out_dput;
47417 +
47418 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47419 + old_path.dentry->d_inode,
47420 + old_path.dentry->d_inode->i_mode, to)) {
47421 + error = -EACCES;
47422 + goto out_drop_write;
47423 + }
47424 +
47425 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47426 + old_path.dentry, old_path.mnt, to)) {
47427 + error = -EACCES;
47428 + goto out_drop_write;
47429 + }
47430 +
47431 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47432 if (error)
47433 goto out_drop_write;
47434 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47435 + if (!error)
47436 + gr_handle_create(new_dentry, new_path.mnt);
47437 out_drop_write:
47438 mnt_drop_write(new_path.mnt);
47439 out_dput:
47440 + putname(to);
47441 dput(new_dentry);
47442 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47443 path_put(&new_path);
47444 @@ -3373,6 +3578,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47445 if (new_dentry == trap)
47446 goto exit5;
47447
47448 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47449 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47450 + to);
47451 + if (error)
47452 + goto exit5;
47453 +
47454 error = mnt_want_write(oldnd.path.mnt);
47455 if (error)
47456 goto exit5;
47457 @@ -3382,6 +3593,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47458 goto exit6;
47459 error = vfs_rename(old_dir->d_inode, old_dentry,
47460 new_dir->d_inode, new_dentry);
47461 + if (!error)
47462 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47463 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47464 exit6:
47465 mnt_drop_write(oldnd.path.mnt);
47466 exit5:
47467 @@ -3407,6 +3621,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47468
47469 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47470 {
47471 + char tmpbuf[64];
47472 + const char *newlink;
47473 int len;
47474
47475 len = PTR_ERR(link);
47476 @@ -3416,7 +3632,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47477 len = strlen(link);
47478 if (len > (unsigned) buflen)
47479 len = buflen;
47480 - if (copy_to_user(buffer, link, len))
47481 +
47482 + if (len < sizeof(tmpbuf)) {
47483 + memcpy(tmpbuf, link, len);
47484 + newlink = tmpbuf;
47485 + } else
47486 + newlink = link;
47487 +
47488 + if (copy_to_user(buffer, newlink, len))
47489 len = -EFAULT;
47490 out:
47491 return len;
47492 diff --git a/fs/namespace.c b/fs/namespace.c
47493 index 1e4a5fe..a5ce747 100644
47494 --- a/fs/namespace.c
47495 +++ b/fs/namespace.c
47496 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47497 if (!(sb->s_flags & MS_RDONLY))
47498 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47499 up_write(&sb->s_umount);
47500 +
47501 + gr_log_remount(mnt->mnt_devname, retval);
47502 +
47503 return retval;
47504 }
47505
47506 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47507 br_write_unlock(&vfsmount_lock);
47508 up_write(&namespace_sem);
47509 release_mounts(&umount_list);
47510 +
47511 + gr_log_unmount(mnt->mnt_devname, retval);
47512 +
47513 return retval;
47514 }
47515
47516 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47517 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47518 MS_STRICTATIME);
47519
47520 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47521 + retval = -EPERM;
47522 + goto dput_out;
47523 + }
47524 +
47525 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47526 + retval = -EPERM;
47527 + goto dput_out;
47528 + }
47529 +
47530 if (flags & MS_REMOUNT)
47531 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47532 data_page);
47533 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47534 dev_name, data_page);
47535 dput_out:
47536 path_put(&path);
47537 +
47538 + gr_log_mount(dev_name, dir_name, retval);
47539 +
47540 return retval;
47541 }
47542
47543 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47544 if (error)
47545 goto out2;
47546
47547 + if (gr_handle_chroot_pivot()) {
47548 + error = -EPERM;
47549 + goto out2;
47550 + }
47551 +
47552 get_fs_root(current->fs, &root);
47553 error = lock_mount(&old);
47554 if (error)
47555 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47556 index f729698..2bac081 100644
47557 --- a/fs/nfs/inode.c
47558 +++ b/fs/nfs/inode.c
47559 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47560 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47561 nfsi->attrtimeo_timestamp = jiffies;
47562
47563 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47564 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47565 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47566 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47567 else
47568 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47569 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47570 }
47571
47572 -static atomic_long_t nfs_attr_generation_counter;
47573 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47574
47575 static unsigned long nfs_read_attr_generation_counter(void)
47576 {
47577 - return atomic_long_read(&nfs_attr_generation_counter);
47578 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47579 }
47580
47581 unsigned long nfs_inc_attr_generation_counter(void)
47582 {
47583 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47584 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47585 }
47586
47587 void nfs_fattr_init(struct nfs_fattr *fattr)
47588 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47589 index c8bd9c3..4f83416 100644
47590 --- a/fs/nfsd/vfs.c
47591 +++ b/fs/nfsd/vfs.c
47592 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47593 } else {
47594 oldfs = get_fs();
47595 set_fs(KERNEL_DS);
47596 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47597 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47598 set_fs(oldfs);
47599 }
47600
47601 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47602
47603 /* Write the data. */
47604 oldfs = get_fs(); set_fs(KERNEL_DS);
47605 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47606 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47607 set_fs(oldfs);
47608 if (host_err < 0)
47609 goto out_nfserr;
47610 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47611 */
47612
47613 oldfs = get_fs(); set_fs(KERNEL_DS);
47614 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47615 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47616 set_fs(oldfs);
47617
47618 if (host_err < 0)
47619 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47620 index 3568c8a..e0240d8 100644
47621 --- a/fs/notify/fanotify/fanotify_user.c
47622 +++ b/fs/notify/fanotify/fanotify_user.c
47623 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47624 goto out_close_fd;
47625
47626 ret = -EFAULT;
47627 - if (copy_to_user(buf, &fanotify_event_metadata,
47628 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47629 + copy_to_user(buf, &fanotify_event_metadata,
47630 fanotify_event_metadata.event_len))
47631 goto out_kill_access_response;
47632
47633 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47634 index c887b13..0fdf472 100644
47635 --- a/fs/notify/notification.c
47636 +++ b/fs/notify/notification.c
47637 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47638 * get set to 0 so it will never get 'freed'
47639 */
47640 static struct fsnotify_event *q_overflow_event;
47641 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47642 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47643
47644 /**
47645 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47646 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47647 */
47648 u32 fsnotify_get_cookie(void)
47649 {
47650 - return atomic_inc_return(&fsnotify_sync_cookie);
47651 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47652 }
47653 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47654
47655 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47656 index 99e3610..02c1068 100644
47657 --- a/fs/ntfs/dir.c
47658 +++ b/fs/ntfs/dir.c
47659 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47660 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47661 ~(s64)(ndir->itype.index.block_size - 1)));
47662 /* Bounds checks. */
47663 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47664 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47665 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47666 "inode 0x%lx or driver bug.", vdir->i_ino);
47667 goto err_out;
47668 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47669 index 7389d2d..dfd5dbe 100644
47670 --- a/fs/ntfs/file.c
47671 +++ b/fs/ntfs/file.c
47672 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47673 #endif /* NTFS_RW */
47674 };
47675
47676 -const struct file_operations ntfs_empty_file_ops = {};
47677 +const struct file_operations ntfs_empty_file_ops __read_only;
47678
47679 -const struct inode_operations ntfs_empty_inode_ops = {};
47680 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47681 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47682 index 210c352..a174f83 100644
47683 --- a/fs/ocfs2/localalloc.c
47684 +++ b/fs/ocfs2/localalloc.c
47685 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47686 goto bail;
47687 }
47688
47689 - atomic_inc(&osb->alloc_stats.moves);
47690 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47691
47692 bail:
47693 if (handle)
47694 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47695 index d355e6e..578d905 100644
47696 --- a/fs/ocfs2/ocfs2.h
47697 +++ b/fs/ocfs2/ocfs2.h
47698 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47699
47700 struct ocfs2_alloc_stats
47701 {
47702 - atomic_t moves;
47703 - atomic_t local_data;
47704 - atomic_t bitmap_data;
47705 - atomic_t bg_allocs;
47706 - atomic_t bg_extends;
47707 + atomic_unchecked_t moves;
47708 + atomic_unchecked_t local_data;
47709 + atomic_unchecked_t bitmap_data;
47710 + atomic_unchecked_t bg_allocs;
47711 + atomic_unchecked_t bg_extends;
47712 };
47713
47714 enum ocfs2_local_alloc_state
47715 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47716 index f169da4..9112253 100644
47717 --- a/fs/ocfs2/suballoc.c
47718 +++ b/fs/ocfs2/suballoc.c
47719 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47720 mlog_errno(status);
47721 goto bail;
47722 }
47723 - atomic_inc(&osb->alloc_stats.bg_extends);
47724 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47725
47726 /* You should never ask for this much metadata */
47727 BUG_ON(bits_wanted >
47728 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47729 mlog_errno(status);
47730 goto bail;
47731 }
47732 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47733 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47734
47735 *suballoc_loc = res.sr_bg_blkno;
47736 *suballoc_bit_start = res.sr_bit_offset;
47737 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47738 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47739 res->sr_bits);
47740
47741 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47742 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47743
47744 BUG_ON(res->sr_bits != 1);
47745
47746 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47747 mlog_errno(status);
47748 goto bail;
47749 }
47750 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47751 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47752
47753 BUG_ON(res.sr_bits != 1);
47754
47755 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47756 cluster_start,
47757 num_clusters);
47758 if (!status)
47759 - atomic_inc(&osb->alloc_stats.local_data);
47760 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47761 } else {
47762 if (min_clusters > (osb->bitmap_cpg - 1)) {
47763 /* The only paths asking for contiguousness
47764 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47765 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47766 res.sr_bg_blkno,
47767 res.sr_bit_offset);
47768 - atomic_inc(&osb->alloc_stats.bitmap_data);
47769 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47770 *num_clusters = res.sr_bits;
47771 }
47772 }
47773 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47774 index 68f4541..89cfe6a 100644
47775 --- a/fs/ocfs2/super.c
47776 +++ b/fs/ocfs2/super.c
47777 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47778 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47779 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47780 "Stats",
47781 - atomic_read(&osb->alloc_stats.bitmap_data),
47782 - atomic_read(&osb->alloc_stats.local_data),
47783 - atomic_read(&osb->alloc_stats.bg_allocs),
47784 - atomic_read(&osb->alloc_stats.moves),
47785 - atomic_read(&osb->alloc_stats.bg_extends));
47786 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47787 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47788 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47789 + atomic_read_unchecked(&osb->alloc_stats.moves),
47790 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47791
47792 out += snprintf(buf + out, len - out,
47793 "%10s => State: %u Descriptor: %llu Size: %u bits "
47794 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47795 spin_lock_init(&osb->osb_xattr_lock);
47796 ocfs2_init_steal_slots(osb);
47797
47798 - atomic_set(&osb->alloc_stats.moves, 0);
47799 - atomic_set(&osb->alloc_stats.local_data, 0);
47800 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47801 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47802 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47803 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47804 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47805 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47806 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47807 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47808
47809 /* Copy the blockcheck stats from the superblock probe */
47810 osb->osb_ecc_stats = *stats;
47811 diff --git a/fs/open.c b/fs/open.c
47812 index 1540632..79d7242 100644
47813 --- a/fs/open.c
47814 +++ b/fs/open.c
47815 @@ -31,6 +31,8 @@
47816 #include <linux/ima.h>
47817 #include <linux/dnotify.h>
47818
47819 +#define CREATE_TRACE_POINTS
47820 +#include <trace/events/fs.h>
47821 #include "internal.h"
47822
47823 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47824 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47825 error = locks_verify_truncate(inode, NULL, length);
47826 if (!error)
47827 error = security_path_truncate(&path);
47828 +
47829 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47830 + error = -EACCES;
47831 +
47832 if (!error)
47833 error = do_truncate(path.dentry, length, 0, NULL);
47834
47835 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47836 if (__mnt_is_readonly(path.mnt))
47837 res = -EROFS;
47838
47839 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47840 + res = -EACCES;
47841 +
47842 out_path_release:
47843 path_put(&path);
47844 out:
47845 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47846 if (error)
47847 goto dput_and_out;
47848
47849 + gr_log_chdir(path.dentry, path.mnt);
47850 +
47851 set_fs_pwd(current->fs, &path);
47852
47853 dput_and_out:
47854 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47855 goto out_putf;
47856
47857 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47858 +
47859 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47860 + error = -EPERM;
47861 +
47862 + if (!error)
47863 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47864 +
47865 if (!error)
47866 set_fs_pwd(current->fs, &file->f_path);
47867 out_putf:
47868 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47869 if (error)
47870 goto dput_and_out;
47871
47872 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47873 + goto dput_and_out;
47874 +
47875 set_fs_root(current->fs, &path);
47876 +
47877 + gr_handle_chroot_chdir(&path);
47878 +
47879 error = 0;
47880 dput_and_out:
47881 path_put(&path);
47882 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
47883 if (error)
47884 return error;
47885 mutex_lock(&inode->i_mutex);
47886 +
47887 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47888 + error = -EACCES;
47889 + goto out_unlock;
47890 + }
47891 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47892 + error = -EACCES;
47893 + goto out_unlock;
47894 + }
47895 +
47896 error = security_path_chmod(path, mode);
47897 if (error)
47898 goto out_unlock;
47899 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47900 uid = make_kuid(current_user_ns(), user);
47901 gid = make_kgid(current_user_ns(), group);
47902
47903 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47904 + return -EACCES;
47905 +
47906 newattrs.ia_valid = ATTR_CTIME;
47907 if (user != (uid_t) -1) {
47908 if (!uid_valid(uid))
47909 @@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47910 } else {
47911 fsnotify_open(f);
47912 fd_install(fd, f);
47913 + trace_do_sys_open(tmp, flags, mode);
47914 }
47915 }
47916 putname(tmp);
47917 diff --git a/fs/pipe.c b/fs/pipe.c
47918 index 49c1065..13b9e12 100644
47919 --- a/fs/pipe.c
47920 +++ b/fs/pipe.c
47921 @@ -438,9 +438,9 @@ redo:
47922 }
47923 if (bufs) /* More to do? */
47924 continue;
47925 - if (!pipe->writers)
47926 + if (!atomic_read(&pipe->writers))
47927 break;
47928 - if (!pipe->waiting_writers) {
47929 + if (!atomic_read(&pipe->waiting_writers)) {
47930 /* syscall merging: Usually we must not sleep
47931 * if O_NONBLOCK is set, or if we got some data.
47932 * But if a writer sleeps in kernel space, then
47933 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47934 mutex_lock(&inode->i_mutex);
47935 pipe = inode->i_pipe;
47936
47937 - if (!pipe->readers) {
47938 + if (!atomic_read(&pipe->readers)) {
47939 send_sig(SIGPIPE, current, 0);
47940 ret = -EPIPE;
47941 goto out;
47942 @@ -553,7 +553,7 @@ redo1:
47943 for (;;) {
47944 int bufs;
47945
47946 - if (!pipe->readers) {
47947 + if (!atomic_read(&pipe->readers)) {
47948 send_sig(SIGPIPE, current, 0);
47949 if (!ret)
47950 ret = -EPIPE;
47951 @@ -644,9 +644,9 @@ redo2:
47952 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47953 do_wakeup = 0;
47954 }
47955 - pipe->waiting_writers++;
47956 + atomic_inc(&pipe->waiting_writers);
47957 pipe_wait(pipe);
47958 - pipe->waiting_writers--;
47959 + atomic_dec(&pipe->waiting_writers);
47960 }
47961 out:
47962 mutex_unlock(&inode->i_mutex);
47963 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47964 mask = 0;
47965 if (filp->f_mode & FMODE_READ) {
47966 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47967 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47968 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47969 mask |= POLLHUP;
47970 }
47971
47972 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47973 * Most Unices do not set POLLERR for FIFOs but on Linux they
47974 * behave exactly like pipes for poll().
47975 */
47976 - if (!pipe->readers)
47977 + if (!atomic_read(&pipe->readers))
47978 mask |= POLLERR;
47979 }
47980
47981 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47982
47983 mutex_lock(&inode->i_mutex);
47984 pipe = inode->i_pipe;
47985 - pipe->readers -= decr;
47986 - pipe->writers -= decw;
47987 + atomic_sub(decr, &pipe->readers);
47988 + atomic_sub(decw, &pipe->writers);
47989
47990 - if (!pipe->readers && !pipe->writers) {
47991 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47992 free_pipe_info(inode);
47993 } else {
47994 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47995 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47996
47997 if (inode->i_pipe) {
47998 ret = 0;
47999 - inode->i_pipe->readers++;
48000 + atomic_inc(&inode->i_pipe->readers);
48001 }
48002
48003 mutex_unlock(&inode->i_mutex);
48004 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48005
48006 if (inode->i_pipe) {
48007 ret = 0;
48008 - inode->i_pipe->writers++;
48009 + atomic_inc(&inode->i_pipe->writers);
48010 }
48011
48012 mutex_unlock(&inode->i_mutex);
48013 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48014 if (inode->i_pipe) {
48015 ret = 0;
48016 if (filp->f_mode & FMODE_READ)
48017 - inode->i_pipe->readers++;
48018 + atomic_inc(&inode->i_pipe->readers);
48019 if (filp->f_mode & FMODE_WRITE)
48020 - inode->i_pipe->writers++;
48021 + atomic_inc(&inode->i_pipe->writers);
48022 }
48023
48024 mutex_unlock(&inode->i_mutex);
48025 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48026 inode->i_pipe = NULL;
48027 }
48028
48029 -static struct vfsmount *pipe_mnt __read_mostly;
48030 +struct vfsmount *pipe_mnt __read_mostly;
48031
48032 /*
48033 * pipefs_dname() is called from d_path().
48034 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48035 goto fail_iput;
48036 inode->i_pipe = pipe;
48037
48038 - pipe->readers = pipe->writers = 1;
48039 + atomic_set(&pipe->readers, 1);
48040 + atomic_set(&pipe->writers, 1);
48041 inode->i_fop = &rdwr_pipefifo_fops;
48042
48043 /*
48044 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48045 index 15af622..0e9f4467 100644
48046 --- a/fs/proc/Kconfig
48047 +++ b/fs/proc/Kconfig
48048 @@ -30,12 +30,12 @@ config PROC_FS
48049
48050 config PROC_KCORE
48051 bool "/proc/kcore support" if !ARM
48052 - depends on PROC_FS && MMU
48053 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48054
48055 config PROC_VMCORE
48056 bool "/proc/vmcore support"
48057 - depends on PROC_FS && CRASH_DUMP
48058 - default y
48059 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48060 + default n
48061 help
48062 Exports the dump image of crashed kernel in ELF format.
48063
48064 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48065 limited in memory.
48066
48067 config PROC_PAGE_MONITOR
48068 - default y
48069 - depends on PROC_FS && MMU
48070 + default n
48071 + depends on PROC_FS && MMU && !GRKERNSEC
48072 bool "Enable /proc page monitoring" if EXPERT
48073 help
48074 Various /proc files exist to monitor process memory utilization:
48075 diff --git a/fs/proc/array.c b/fs/proc/array.c
48076 index c1c207c..5179411 100644
48077 --- a/fs/proc/array.c
48078 +++ b/fs/proc/array.c
48079 @@ -60,6 +60,7 @@
48080 #include <linux/tty.h>
48081 #include <linux/string.h>
48082 #include <linux/mman.h>
48083 +#include <linux/grsecurity.h>
48084 #include <linux/proc_fs.h>
48085 #include <linux/ioport.h>
48086 #include <linux/uaccess.h>
48087 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48088 seq_putc(m, '\n');
48089 }
48090
48091 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48092 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48093 +{
48094 + if (p->mm)
48095 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48096 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48097 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48098 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48099 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48100 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48101 + else
48102 + seq_printf(m, "PaX:\t-----\n");
48103 +}
48104 +#endif
48105 +
48106 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48107 struct pid *pid, struct task_struct *task)
48108 {
48109 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48110 task_cpus_allowed(m, task);
48111 cpuset_task_status_allowed(m, task);
48112 task_context_switch_counts(m, task);
48113 +
48114 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48115 + task_pax(m, task);
48116 +#endif
48117 +
48118 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48119 + task_grsec_rbac(m, task);
48120 +#endif
48121 +
48122 return 0;
48123 }
48124
48125 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48126 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48127 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48128 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48129 +#endif
48130 +
48131 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48132 struct pid *pid, struct task_struct *task, int whole)
48133 {
48134 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48135 char tcomm[sizeof(task->comm)];
48136 unsigned long flags;
48137
48138 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48139 + if (current->exec_id != m->exec_id) {
48140 + gr_log_badprocpid("stat");
48141 + return 0;
48142 + }
48143 +#endif
48144 +
48145 state = *get_task_state(task);
48146 vsize = eip = esp = 0;
48147 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48148 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48149 gtime = task->gtime;
48150 }
48151
48152 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48153 + if (PAX_RAND_FLAGS(mm)) {
48154 + eip = 0;
48155 + esp = 0;
48156 + wchan = 0;
48157 + }
48158 +#endif
48159 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48160 + wchan = 0;
48161 + eip =0;
48162 + esp =0;
48163 +#endif
48164 +
48165 /* scale priority and nice values from timeslices to -20..20 */
48166 /* to make it look like a "normal" Unix priority/nice value */
48167 priority = task_prio(task);
48168 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48169 seq_put_decimal_ull(m, ' ', vsize);
48170 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48171 seq_put_decimal_ull(m, ' ', rsslim);
48172 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48173 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48174 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48175 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48176 +#else
48177 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48178 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48179 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48180 +#endif
48181 seq_put_decimal_ull(m, ' ', esp);
48182 seq_put_decimal_ull(m, ' ', eip);
48183 /* The signal information here is obsolete.
48184 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48185 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48186 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48187
48188 - if (mm && permitted) {
48189 + if (mm && permitted
48190 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48191 + && !PAX_RAND_FLAGS(mm)
48192 +#endif
48193 + ) {
48194 seq_put_decimal_ull(m, ' ', mm->start_data);
48195 seq_put_decimal_ull(m, ' ', mm->end_data);
48196 seq_put_decimal_ull(m, ' ', mm->start_brk);
48197 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48198 struct pid *pid, struct task_struct *task)
48199 {
48200 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48201 - struct mm_struct *mm = get_task_mm(task);
48202 + struct mm_struct *mm;
48203
48204 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48205 + if (current->exec_id != m->exec_id) {
48206 + gr_log_badprocpid("statm");
48207 + return 0;
48208 + }
48209 +#endif
48210 + mm = get_task_mm(task);
48211 if (mm) {
48212 size = task_statm(mm, &shared, &text, &data, &resident);
48213 mmput(mm);
48214 @@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48215 return 0;
48216 }
48217
48218 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48219 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48220 +{
48221 + u32 curr_ip = 0;
48222 + unsigned long flags;
48223 +
48224 + if (lock_task_sighand(task, &flags)) {
48225 + curr_ip = task->signal->curr_ip;
48226 + unlock_task_sighand(task, &flags);
48227 + }
48228 +
48229 + return sprintf(buffer, "%pI4\n", &curr_ip);
48230 +}
48231 +#endif
48232 +
48233 #ifdef CONFIG_CHECKPOINT_RESTORE
48234 static struct pid *
48235 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48236 diff --git a/fs/proc/base.c b/fs/proc/base.c
48237 index 437195f..cd2210d 100644
48238 --- a/fs/proc/base.c
48239 +++ b/fs/proc/base.c
48240 @@ -110,6 +110,14 @@ struct pid_entry {
48241 union proc_op op;
48242 };
48243
48244 +struct getdents_callback {
48245 + struct linux_dirent __user * current_dir;
48246 + struct linux_dirent __user * previous;
48247 + struct file * file;
48248 + int count;
48249 + int error;
48250 +};
48251 +
48252 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48253 .name = (NAME), \
48254 .len = sizeof(NAME) - 1, \
48255 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48256 if (!mm->arg_end)
48257 goto out_mm; /* Shh! No looking before we're done */
48258
48259 + if (gr_acl_handle_procpidmem(task))
48260 + goto out_mm;
48261 +
48262 len = mm->arg_end - mm->arg_start;
48263
48264 if (len > PAGE_SIZE)
48265 @@ -236,12 +247,28 @@ out:
48266 return res;
48267 }
48268
48269 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48270 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48271 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48272 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48273 +#endif
48274 +
48275 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48276 {
48277 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48278 int res = PTR_ERR(mm);
48279 if (mm && !IS_ERR(mm)) {
48280 unsigned int nwords = 0;
48281 +
48282 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48283 + /* allow if we're currently ptracing this task */
48284 + if (PAX_RAND_FLAGS(mm) &&
48285 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48286 + mmput(mm);
48287 + return 0;
48288 + }
48289 +#endif
48290 +
48291 do {
48292 nwords += 2;
48293 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48294 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48295 }
48296
48297
48298 -#ifdef CONFIG_KALLSYMS
48299 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48300 /*
48301 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48302 * Returns the resolved symbol. If that fails, simply return the address.
48303 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48304 mutex_unlock(&task->signal->cred_guard_mutex);
48305 }
48306
48307 -#ifdef CONFIG_STACKTRACE
48308 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48309
48310 #define MAX_STACK_TRACE_DEPTH 64
48311
48312 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48313 return count;
48314 }
48315
48316 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48317 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48318 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48319 {
48320 long nr;
48321 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48322 /************************************************************************/
48323
48324 /* permission checks */
48325 -static int proc_fd_access_allowed(struct inode *inode)
48326 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48327 {
48328 struct task_struct *task;
48329 int allowed = 0;
48330 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48331 */
48332 task = get_proc_task(inode);
48333 if (task) {
48334 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48335 + if (log)
48336 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48337 + else
48338 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48339 put_task_struct(task);
48340 }
48341 return allowed;
48342 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48343 struct task_struct *task,
48344 int hide_pid_min)
48345 {
48346 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48347 + return false;
48348 +
48349 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48350 + rcu_read_lock();
48351 + {
48352 + const struct cred *tmpcred = current_cred();
48353 + const struct cred *cred = __task_cred(task);
48354 +
48355 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48356 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48357 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48358 +#endif
48359 + ) {
48360 + rcu_read_unlock();
48361 + return true;
48362 + }
48363 + }
48364 + rcu_read_unlock();
48365 +
48366 + if (!pid->hide_pid)
48367 + return false;
48368 +#endif
48369 +
48370 if (pid->hide_pid < hide_pid_min)
48371 return true;
48372 if (in_group_p(pid->pid_gid))
48373 return true;
48374 +
48375 return ptrace_may_access(task, PTRACE_MODE_READ);
48376 }
48377
48378 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48379 put_task_struct(task);
48380
48381 if (!has_perms) {
48382 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48383 + {
48384 +#else
48385 if (pid->hide_pid == 2) {
48386 +#endif
48387 /*
48388 * Let's make getdents(), stat(), and open()
48389 * consistent with each other. If a process
48390 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48391 if (!task)
48392 return -ESRCH;
48393
48394 + if (gr_acl_handle_procpidmem(task)) {
48395 + put_task_struct(task);
48396 + return -EPERM;
48397 + }
48398 +
48399 mm = mm_access(task, mode);
48400 put_task_struct(task);
48401
48402 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48403 mmput(mm);
48404 }
48405
48406 - /* OK to pass negative loff_t, we can catch out-of-range */
48407 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
48408 file->private_data = mm;
48409
48410 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48411 + file->f_version = current->exec_id;
48412 +#endif
48413 +
48414 return 0;
48415 }
48416
48417 static int mem_open(struct inode *inode, struct file *file)
48418 {
48419 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48420 + int ret;
48421 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48422 +
48423 + /* OK to pass negative loff_t, we can catch out-of-range */
48424 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
48425 +
48426 + return ret;
48427 }
48428
48429 static ssize_t mem_rw(struct file *file, char __user *buf,
48430 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48431 ssize_t copied;
48432 char *page;
48433
48434 +#ifdef CONFIG_GRKERNSEC
48435 + if (write)
48436 + return -EPERM;
48437 +#endif
48438 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48439 + if (file->f_version != current->exec_id) {
48440 + gr_log_badprocpid("mem");
48441 + return 0;
48442 + }
48443 +#endif
48444 +
48445 if (!mm)
48446 return 0;
48447
48448 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48449 if (!mm)
48450 return 0;
48451
48452 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48453 + if (file->f_version != current->exec_id) {
48454 + gr_log_badprocpid("environ");
48455 + return 0;
48456 + }
48457 +#endif
48458 +
48459 page = (char *)__get_free_page(GFP_TEMPORARY);
48460 if (!page)
48461 return -ENOMEM;
48462 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48463 if (!atomic_inc_not_zero(&mm->mm_users))
48464 goto free;
48465 while (count > 0) {
48466 - int this_len, retval, max_len;
48467 + size_t this_len, max_len;
48468 + int retval;
48469 +
48470 + if (src >= (mm->env_end - mm->env_start))
48471 + break;
48472
48473 this_len = mm->env_end - (mm->env_start + src);
48474
48475 - if (this_len <= 0)
48476 - break;
48477
48478 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48479 - this_len = (this_len > max_len) ? max_len : this_len;
48480 + max_len = min_t(size_t, PAGE_SIZE, count);
48481 + this_len = min(max_len, this_len);
48482
48483 retval = access_remote_vm(mm, (mm->env_start + src),
48484 page, this_len, 0);
48485 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48486 path_put(&nd->path);
48487
48488 /* Are we allowed to snoop on the tasks file descriptors? */
48489 - if (!proc_fd_access_allowed(inode))
48490 + if (!proc_fd_access_allowed(inode, 0))
48491 goto out;
48492
48493 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48494 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48495 struct path path;
48496
48497 /* Are we allowed to snoop on the tasks file descriptors? */
48498 - if (!proc_fd_access_allowed(inode))
48499 - goto out;
48500 + /* logging this is needed for learning on chromium to work properly,
48501 + but we don't want to flood the logs from 'ps' which does a readlink
48502 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48503 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48504 + */
48505 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48506 + if (!proc_fd_access_allowed(inode,0))
48507 + goto out;
48508 + } else {
48509 + if (!proc_fd_access_allowed(inode,1))
48510 + goto out;
48511 + }
48512
48513 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48514 if (error)
48515 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48516 rcu_read_lock();
48517 cred = __task_cred(task);
48518 inode->i_uid = cred->euid;
48519 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48520 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48521 +#else
48522 inode->i_gid = cred->egid;
48523 +#endif
48524 rcu_read_unlock();
48525 }
48526 security_task_to_inode(task, inode);
48527 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48528 return -ENOENT;
48529 }
48530 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48531 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48532 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48533 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48534 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48535 +#endif
48536 task_dumpable(task)) {
48537 cred = __task_cred(task);
48538 stat->uid = cred->euid;
48539 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48540 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48541 +#else
48542 stat->gid = cred->egid;
48543 +#endif
48544 }
48545 }
48546 rcu_read_unlock();
48547 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48548
48549 if (task) {
48550 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48551 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48552 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48553 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48554 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48555 +#endif
48556 task_dumpable(task)) {
48557 rcu_read_lock();
48558 cred = __task_cred(task);
48559 inode->i_uid = cred->euid;
48560 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48561 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48562 +#else
48563 inode->i_gid = cred->egid;
48564 +#endif
48565 rcu_read_unlock();
48566 } else {
48567 inode->i_uid = GLOBAL_ROOT_UID;
48568 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48569 int fd = proc_fd(inode);
48570
48571 if (task) {
48572 - files = get_files_struct(task);
48573 + if (!gr_acl_handle_procpidmem(task))
48574 + files = get_files_struct(task);
48575 put_task_struct(task);
48576 }
48577 if (files) {
48578 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48579 */
48580 static int proc_fd_permission(struct inode *inode, int mask)
48581 {
48582 + struct task_struct *task;
48583 int rv = generic_permission(inode, mask);
48584 - if (rv == 0)
48585 - return 0;
48586 +
48587 if (task_pid(current) == proc_pid(inode))
48588 rv = 0;
48589 +
48590 + task = get_proc_task(inode);
48591 + if (task == NULL)
48592 + return rv;
48593 +
48594 + if (gr_acl_handle_procpidmem(task))
48595 + rv = -EACCES;
48596 +
48597 + put_task_struct(task);
48598 +
48599 return rv;
48600 }
48601
48602 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48603 if (!task)
48604 goto out_no_task;
48605
48606 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48607 + goto out;
48608 +
48609 /*
48610 * Yes, it does not scale. And it should not. Don't add
48611 * new entries into /proc/<tgid>/ without very good reasons.
48612 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48613 if (!task)
48614 goto out_no_task;
48615
48616 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48617 + goto out;
48618 +
48619 ret = 0;
48620 i = filp->f_pos;
48621 switch (i) {
48622 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48623 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48624 void *cookie)
48625 {
48626 - char *s = nd_get_link(nd);
48627 + const char *s = nd_get_link(nd);
48628 if (!IS_ERR(s))
48629 __putname(s);
48630 }
48631 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48632 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48633 #endif
48634 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48635 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48636 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48637 INF("syscall", S_IRUGO, proc_pid_syscall),
48638 #endif
48639 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48640 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48641 #ifdef CONFIG_SECURITY
48642 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48643 #endif
48644 -#ifdef CONFIG_KALLSYMS
48645 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48646 INF("wchan", S_IRUGO, proc_pid_wchan),
48647 #endif
48648 -#ifdef CONFIG_STACKTRACE
48649 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48650 ONE("stack", S_IRUGO, proc_pid_stack),
48651 #endif
48652 #ifdef CONFIG_SCHEDSTATS
48653 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48654 #ifdef CONFIG_HARDWALL
48655 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48656 #endif
48657 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48658 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48659 +#endif
48660 #ifdef CONFIG_USER_NS
48661 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48662 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48663 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48664 if (!inode)
48665 goto out;
48666
48667 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48668 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48669 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48670 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48671 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48672 +#else
48673 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48674 +#endif
48675 inode->i_op = &proc_tgid_base_inode_operations;
48676 inode->i_fop = &proc_tgid_base_operations;
48677 inode->i_flags|=S_IMMUTABLE;
48678 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48679 if (!task)
48680 goto out;
48681
48682 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48683 + goto out_put_task;
48684 +
48685 result = proc_pid_instantiate(dir, dentry, task, NULL);
48686 +out_put_task:
48687 put_task_struct(task);
48688 out:
48689 return result;
48690 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48691 static int fake_filldir(void *buf, const char *name, int namelen,
48692 loff_t offset, u64 ino, unsigned d_type)
48693 {
48694 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48695 + __buf->error = -EINVAL;
48696 return 0;
48697 }
48698
48699 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48700 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48701 #endif
48702 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48703 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48704 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48705 INF("syscall", S_IRUGO, proc_pid_syscall),
48706 #endif
48707 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48708 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48709 #ifdef CONFIG_SECURITY
48710 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48711 #endif
48712 -#ifdef CONFIG_KALLSYMS
48713 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48714 INF("wchan", S_IRUGO, proc_pid_wchan),
48715 #endif
48716 -#ifdef CONFIG_STACKTRACE
48717 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48718 ONE("stack", S_IRUGO, proc_pid_stack),
48719 #endif
48720 #ifdef CONFIG_SCHEDSTATS
48721 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48722 index 82676e3..5f8518a 100644
48723 --- a/fs/proc/cmdline.c
48724 +++ b/fs/proc/cmdline.c
48725 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48726
48727 static int __init proc_cmdline_init(void)
48728 {
48729 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48730 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48731 +#else
48732 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48733 +#endif
48734 return 0;
48735 }
48736 module_init(proc_cmdline_init);
48737 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48738 index b143471..bb105e5 100644
48739 --- a/fs/proc/devices.c
48740 +++ b/fs/proc/devices.c
48741 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48742
48743 static int __init proc_devices_init(void)
48744 {
48745 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48746 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48747 +#else
48748 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48749 +#endif
48750 return 0;
48751 }
48752 module_init(proc_devices_init);
48753 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48754 index 7ac817b..abab1a5 100644
48755 --- a/fs/proc/inode.c
48756 +++ b/fs/proc/inode.c
48757 @@ -21,11 +21,17 @@
48758 #include <linux/seq_file.h>
48759 #include <linux/slab.h>
48760 #include <linux/mount.h>
48761 +#include <linux/grsecurity.h>
48762
48763 #include <asm/uaccess.h>
48764
48765 #include "internal.h"
48766
48767 +#ifdef CONFIG_PROC_SYSCTL
48768 +extern const struct inode_operations proc_sys_inode_operations;
48769 +extern const struct inode_operations proc_sys_dir_operations;
48770 +#endif
48771 +
48772 static void proc_evict_inode(struct inode *inode)
48773 {
48774 struct proc_dir_entry *de;
48775 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48776 ns_ops = PROC_I(inode)->ns_ops;
48777 if (ns_ops && ns_ops->put)
48778 ns_ops->put(PROC_I(inode)->ns);
48779 +
48780 +#ifdef CONFIG_PROC_SYSCTL
48781 + if (inode->i_op == &proc_sys_inode_operations ||
48782 + inode->i_op == &proc_sys_dir_operations)
48783 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48784 +#endif
48785 +
48786 }
48787
48788 static struct kmem_cache * proc_inode_cachep;
48789 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48790 if (de->mode) {
48791 inode->i_mode = de->mode;
48792 inode->i_uid = de->uid;
48793 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48794 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48795 +#else
48796 inode->i_gid = de->gid;
48797 +#endif
48798 }
48799 if (de->size)
48800 inode->i_size = de->size;
48801 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48802 index eca4aca..19166b2 100644
48803 --- a/fs/proc/internal.h
48804 +++ b/fs/proc/internal.h
48805 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48806 struct pid *pid, struct task_struct *task);
48807 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48808 struct pid *pid, struct task_struct *task);
48809 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48810 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48811 +#endif
48812 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48813
48814 extern const struct file_operations proc_tid_children_operations;
48815 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48816 index 86c67ee..cdca321 100644
48817 --- a/fs/proc/kcore.c
48818 +++ b/fs/proc/kcore.c
48819 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48820 * the addresses in the elf_phdr on our list.
48821 */
48822 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48823 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48824 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48825 + if (tsz > buflen)
48826 tsz = buflen;
48827 -
48828 +
48829 while (buflen) {
48830 struct kcore_list *m;
48831
48832 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48833 kfree(elf_buf);
48834 } else {
48835 if (kern_addr_valid(start)) {
48836 - unsigned long n;
48837 + char *elf_buf;
48838 + mm_segment_t oldfs;
48839
48840 - n = copy_to_user(buffer, (char *)start, tsz);
48841 - /*
48842 - * We cannot distinguish between fault on source
48843 - * and fault on destination. When this happens
48844 - * we clear too and hope it will trigger the
48845 - * EFAULT again.
48846 - */
48847 - if (n) {
48848 - if (clear_user(buffer + tsz - n,
48849 - n))
48850 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48851 + if (!elf_buf)
48852 + return -ENOMEM;
48853 + oldfs = get_fs();
48854 + set_fs(KERNEL_DS);
48855 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48856 + set_fs(oldfs);
48857 + if (copy_to_user(buffer, elf_buf, tsz)) {
48858 + kfree(elf_buf);
48859 return -EFAULT;
48860 + }
48861 }
48862 + set_fs(oldfs);
48863 + kfree(elf_buf);
48864 } else {
48865 if (clear_user(buffer, tsz))
48866 return -EFAULT;
48867 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48868
48869 static int open_kcore(struct inode *inode, struct file *filp)
48870 {
48871 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48872 + return -EPERM;
48873 +#endif
48874 if (!capable(CAP_SYS_RAWIO))
48875 return -EPERM;
48876 if (kcore_need_update)
48877 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48878 index 80e4645..53e5fcf 100644
48879 --- a/fs/proc/meminfo.c
48880 +++ b/fs/proc/meminfo.c
48881 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48882 vmi.used >> 10,
48883 vmi.largest_chunk >> 10
48884 #ifdef CONFIG_MEMORY_FAILURE
48885 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48886 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48887 #endif
48888 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48889 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48890 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48891 index b1822dd..df622cb 100644
48892 --- a/fs/proc/nommu.c
48893 +++ b/fs/proc/nommu.c
48894 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48895 if (len < 1)
48896 len = 1;
48897 seq_printf(m, "%*c", len, ' ');
48898 - seq_path(m, &file->f_path, "");
48899 + seq_path(m, &file->f_path, "\n\\");
48900 }
48901
48902 seq_putc(m, '\n');
48903 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48904 index 06e1cc1..177cd98 100644
48905 --- a/fs/proc/proc_net.c
48906 +++ b/fs/proc/proc_net.c
48907 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48908 struct task_struct *task;
48909 struct nsproxy *ns;
48910 struct net *net = NULL;
48911 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48912 + const struct cred *cred = current_cred();
48913 +#endif
48914 +
48915 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48916 + if (cred->fsuid)
48917 + return net;
48918 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48919 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48920 + return net;
48921 +#endif
48922
48923 rcu_read_lock();
48924 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48925 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48926 index 3476bca..cb6d86a 100644
48927 --- a/fs/proc/proc_sysctl.c
48928 +++ b/fs/proc/proc_sysctl.c
48929 @@ -12,11 +12,15 @@
48930 #include <linux/module.h>
48931 #include "internal.h"
48932
48933 +extern int gr_handle_chroot_sysctl(const int op);
48934 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48935 + const int op);
48936 +
48937 static const struct dentry_operations proc_sys_dentry_operations;
48938 static const struct file_operations proc_sys_file_operations;
48939 -static const struct inode_operations proc_sys_inode_operations;
48940 +const struct inode_operations proc_sys_inode_operations;
48941 static const struct file_operations proc_sys_dir_file_operations;
48942 -static const struct inode_operations proc_sys_dir_operations;
48943 +const struct inode_operations proc_sys_dir_operations;
48944
48945 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48946 {
48947 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48948
48949 err = NULL;
48950 d_set_d_op(dentry, &proc_sys_dentry_operations);
48951 +
48952 + gr_handle_proc_create(dentry, inode);
48953 +
48954 d_add(dentry, inode);
48955
48956 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48957 + err = ERR_PTR(-ENOENT);
48958 +
48959 out:
48960 sysctl_head_finish(head);
48961 return err;
48962 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48963 struct inode *inode = filp->f_path.dentry->d_inode;
48964 struct ctl_table_header *head = grab_header(inode);
48965 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48966 + int op = write ? MAY_WRITE : MAY_READ;
48967 ssize_t error;
48968 size_t res;
48969
48970 if (IS_ERR(head))
48971 return PTR_ERR(head);
48972
48973 +
48974 /*
48975 * At this point we know that the sysctl was not unregistered
48976 * and won't be until we finish.
48977 */
48978 error = -EPERM;
48979 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48980 + if (sysctl_perm(head->root, table, op))
48981 goto out;
48982
48983 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48984 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48985 if (!table->proc_handler)
48986 goto out;
48987
48988 +#ifdef CONFIG_GRKERNSEC
48989 + error = -EPERM;
48990 + if (gr_handle_chroot_sysctl(op))
48991 + goto out;
48992 + dget(filp->f_path.dentry);
48993 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48994 + dput(filp->f_path.dentry);
48995 + goto out;
48996 + }
48997 + dput(filp->f_path.dentry);
48998 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48999 + goto out;
49000 + if (write && !capable(CAP_SYS_ADMIN))
49001 + goto out;
49002 +#endif
49003 +
49004 /* careful: calling conventions are nasty here */
49005 res = count;
49006 error = table->proc_handler(table, write, buf, &res, ppos);
49007 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49008 return -ENOMEM;
49009 } else {
49010 d_set_d_op(child, &proc_sys_dentry_operations);
49011 +
49012 + gr_handle_proc_create(child, inode);
49013 +
49014 d_add(child, inode);
49015 }
49016 } else {
49017 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49018 if ((*pos)++ < file->f_pos)
49019 return 0;
49020
49021 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49022 + return 0;
49023 +
49024 if (unlikely(S_ISLNK(table->mode)))
49025 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49026 else
49027 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49028 if (IS_ERR(head))
49029 return PTR_ERR(head);
49030
49031 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49032 + return -ENOENT;
49033 +
49034 generic_fillattr(inode, stat);
49035 if (table)
49036 stat->mode = (stat->mode & S_IFMT) | table->mode;
49037 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49038 .llseek = generic_file_llseek,
49039 };
49040
49041 -static const struct inode_operations proc_sys_inode_operations = {
49042 +const struct inode_operations proc_sys_inode_operations = {
49043 .permission = proc_sys_permission,
49044 .setattr = proc_sys_setattr,
49045 .getattr = proc_sys_getattr,
49046 };
49047
49048 -static const struct inode_operations proc_sys_dir_operations = {
49049 +const struct inode_operations proc_sys_dir_operations = {
49050 .lookup = proc_sys_lookup,
49051 .permission = proc_sys_permission,
49052 .setattr = proc_sys_setattr,
49053 diff --git a/fs/proc/root.c b/fs/proc/root.c
49054 index 7c30fce..b3d3aa2 100644
49055 --- a/fs/proc/root.c
49056 +++ b/fs/proc/root.c
49057 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49058 #ifdef CONFIG_PROC_DEVICETREE
49059 proc_device_tree_init();
49060 #endif
49061 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49062 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49063 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49064 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49065 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49066 +#endif
49067 +#else
49068 proc_mkdir("bus", NULL);
49069 +#endif
49070 proc_sys_init();
49071 }
49072
49073 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49074 index 4540b8f..1b9772f 100644
49075 --- a/fs/proc/task_mmu.c
49076 +++ b/fs/proc/task_mmu.c
49077 @@ -11,12 +11,19 @@
49078 #include <linux/rmap.h>
49079 #include <linux/swap.h>
49080 #include <linux/swapops.h>
49081 +#include <linux/grsecurity.h>
49082
49083 #include <asm/elf.h>
49084 #include <asm/uaccess.h>
49085 #include <asm/tlbflush.h>
49086 #include "internal.h"
49087
49088 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49089 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49090 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49091 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49092 +#endif
49093 +
49094 void task_mem(struct seq_file *m, struct mm_struct *mm)
49095 {
49096 unsigned long data, text, lib, swap;
49097 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49098 "VmExe:\t%8lu kB\n"
49099 "VmLib:\t%8lu kB\n"
49100 "VmPTE:\t%8lu kB\n"
49101 - "VmSwap:\t%8lu kB\n",
49102 - hiwater_vm << (PAGE_SHIFT-10),
49103 + "VmSwap:\t%8lu kB\n"
49104 +
49105 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49106 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49107 +#endif
49108 +
49109 + ,hiwater_vm << (PAGE_SHIFT-10),
49110 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49111 mm->locked_vm << (PAGE_SHIFT-10),
49112 mm->pinned_vm << (PAGE_SHIFT-10),
49113 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49114 data << (PAGE_SHIFT-10),
49115 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49116 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49117 - swap << (PAGE_SHIFT-10));
49118 + swap << (PAGE_SHIFT-10)
49119 +
49120 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49121 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49122 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49123 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49124 +#else
49125 + , mm->context.user_cs_base
49126 + , mm->context.user_cs_limit
49127 +#endif
49128 +#endif
49129 +
49130 + );
49131 }
49132
49133 unsigned long task_vsize(struct mm_struct *mm)
49134 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49135 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49136 }
49137
49138 - /* We don't show the stack guard page in /proc/maps */
49139 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49140 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49141 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49142 +#else
49143 start = vma->vm_start;
49144 - if (stack_guard_page_start(vma, start))
49145 - start += PAGE_SIZE;
49146 end = vma->vm_end;
49147 - if (stack_guard_page_end(vma, end))
49148 - end -= PAGE_SIZE;
49149 +#endif
49150
49151 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49152 start,
49153 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49154 flags & VM_WRITE ? 'w' : '-',
49155 flags & VM_EXEC ? 'x' : '-',
49156 flags & VM_MAYSHARE ? 's' : 'p',
49157 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49158 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49159 +#else
49160 pgoff,
49161 +#endif
49162 MAJOR(dev), MINOR(dev), ino, &len);
49163
49164 /*
49165 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49166 */
49167 if (file) {
49168 pad_len_spaces(m, len);
49169 - seq_path(m, &file->f_path, "\n");
49170 + seq_path(m, &file->f_path, "\n\\");
49171 goto done;
49172 }
49173
49174 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49175 * Thread stack in /proc/PID/task/TID/maps or
49176 * the main process stack.
49177 */
49178 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49179 - vma->vm_end >= mm->start_stack)) {
49180 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49181 + (vma->vm_start <= mm->start_stack &&
49182 + vma->vm_end >= mm->start_stack)) {
49183 name = "[stack]";
49184 } else {
49185 /* Thread stack in /proc/PID/maps */
49186 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49187 struct proc_maps_private *priv = m->private;
49188 struct task_struct *task = priv->task;
49189
49190 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49191 + if (current->exec_id != m->exec_id) {
49192 + gr_log_badprocpid("maps");
49193 + return 0;
49194 + }
49195 +#endif
49196 +
49197 show_map_vma(m, vma, is_pid);
49198
49199 if (m->count < m->size) /* vma is copied successfully */
49200 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49201 .private = &mss,
49202 };
49203
49204 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49205 + if (current->exec_id != m->exec_id) {
49206 + gr_log_badprocpid("smaps");
49207 + return 0;
49208 + }
49209 +#endif
49210 memset(&mss, 0, sizeof mss);
49211 - mss.vma = vma;
49212 - /* mmap_sem is held in m_start */
49213 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49214 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49215 -
49216 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49217 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49218 +#endif
49219 + mss.vma = vma;
49220 + /* mmap_sem is held in m_start */
49221 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49222 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49223 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49224 + }
49225 +#endif
49226 show_map_vma(m, vma, is_pid);
49227
49228 seq_printf(m,
49229 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49230 "KernelPageSize: %8lu kB\n"
49231 "MMUPageSize: %8lu kB\n"
49232 "Locked: %8lu kB\n",
49233 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49234 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49235 +#else
49236 (vma->vm_end - vma->vm_start) >> 10,
49237 +#endif
49238 mss.resident >> 10,
49239 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49240 mss.shared_clean >> 10,
49241 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49242 int n;
49243 char buffer[50];
49244
49245 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49246 + if (current->exec_id != m->exec_id) {
49247 + gr_log_badprocpid("numa_maps");
49248 + return 0;
49249 + }
49250 +#endif
49251 +
49252 if (!mm)
49253 return 0;
49254
49255 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49256 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49257 mpol_cond_put(pol);
49258
49259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49260 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49261 +#else
49262 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49263 +#endif
49264
49265 if (file) {
49266 seq_printf(m, " file=");
49267 - seq_path(m, &file->f_path, "\n\t= ");
49268 + seq_path(m, &file->f_path, "\n\t\\= ");
49269 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49270 seq_printf(m, " heap");
49271 } else {
49272 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49273 index 1ccfa53..0848f95 100644
49274 --- a/fs/proc/task_nommu.c
49275 +++ b/fs/proc/task_nommu.c
49276 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49277 else
49278 bytes += kobjsize(mm);
49279
49280 - if (current->fs && current->fs->users > 1)
49281 + if (current->fs && atomic_read(&current->fs->users) > 1)
49282 sbytes += kobjsize(current->fs);
49283 else
49284 bytes += kobjsize(current->fs);
49285 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49286
49287 if (file) {
49288 pad_len_spaces(m, len);
49289 - seq_path(m, &file->f_path, "");
49290 + seq_path(m, &file->f_path, "\n\\");
49291 } else if (mm) {
49292 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49293
49294 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49295 index d67908b..d13f6a6 100644
49296 --- a/fs/quota/netlink.c
49297 +++ b/fs/quota/netlink.c
49298 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49299 void quota_send_warning(short type, unsigned int id, dev_t dev,
49300 const char warntype)
49301 {
49302 - static atomic_t seq;
49303 + static atomic_unchecked_t seq;
49304 struct sk_buff *skb;
49305 void *msg_head;
49306 int ret;
49307 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49308 "VFS: Not enough memory to send quota warning.\n");
49309 return;
49310 }
49311 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49312 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49313 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49314 if (!msg_head) {
49315 printk(KERN_ERR
49316 diff --git a/fs/readdir.c b/fs/readdir.c
49317 index 39e3370..20d446d 100644
49318 --- a/fs/readdir.c
49319 +++ b/fs/readdir.c
49320 @@ -17,6 +17,7 @@
49321 #include <linux/security.h>
49322 #include <linux/syscalls.h>
49323 #include <linux/unistd.h>
49324 +#include <linux/namei.h>
49325
49326 #include <asm/uaccess.h>
49327
49328 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49329
49330 struct readdir_callback {
49331 struct old_linux_dirent __user * dirent;
49332 + struct file * file;
49333 int result;
49334 };
49335
49336 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49337 buf->result = -EOVERFLOW;
49338 return -EOVERFLOW;
49339 }
49340 +
49341 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49342 + return 0;
49343 +
49344 buf->result++;
49345 dirent = buf->dirent;
49346 if (!access_ok(VERIFY_WRITE, dirent,
49347 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49348
49349 buf.result = 0;
49350 buf.dirent = dirent;
49351 + buf.file = file;
49352
49353 error = vfs_readdir(file, fillonedir, &buf);
49354 if (buf.result)
49355 @@ -141,6 +148,7 @@ struct linux_dirent {
49356 struct getdents_callback {
49357 struct linux_dirent __user * current_dir;
49358 struct linux_dirent __user * previous;
49359 + struct file * file;
49360 int count;
49361 int error;
49362 };
49363 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49364 buf->error = -EOVERFLOW;
49365 return -EOVERFLOW;
49366 }
49367 +
49368 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49369 + return 0;
49370 +
49371 dirent = buf->previous;
49372 if (dirent) {
49373 if (__put_user(offset, &dirent->d_off))
49374 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49375 buf.previous = NULL;
49376 buf.count = count;
49377 buf.error = 0;
49378 + buf.file = file;
49379
49380 error = vfs_readdir(file, filldir, &buf);
49381 if (error >= 0)
49382 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49383 struct getdents_callback64 {
49384 struct linux_dirent64 __user * current_dir;
49385 struct linux_dirent64 __user * previous;
49386 + struct file *file;
49387 int count;
49388 int error;
49389 };
49390 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49391 buf->error = -EINVAL; /* only used if we fail.. */
49392 if (reclen > buf->count)
49393 return -EINVAL;
49394 +
49395 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49396 + return 0;
49397 +
49398 dirent = buf->previous;
49399 if (dirent) {
49400 if (__put_user(offset, &dirent->d_off))
49401 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49402
49403 buf.current_dir = dirent;
49404 buf.previous = NULL;
49405 + buf.file = file;
49406 buf.count = count;
49407 buf.error = 0;
49408
49409 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49410 error = buf.error;
49411 lastdirent = buf.previous;
49412 if (lastdirent) {
49413 - typeof(lastdirent->d_off) d_off = file->f_pos;
49414 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49415 if (__put_user(d_off, &lastdirent->d_off))
49416 error = -EFAULT;
49417 else
49418 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49419 index 2b7882b..1c5ef48 100644
49420 --- a/fs/reiserfs/do_balan.c
49421 +++ b/fs/reiserfs/do_balan.c
49422 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49423 return;
49424 }
49425
49426 - atomic_inc(&(fs_generation(tb->tb_sb)));
49427 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49428 do_balance_starts(tb);
49429
49430 /* balance leaf returns 0 except if combining L R and S into
49431 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49432 index 2c1ade6..8c59d8d 100644
49433 --- a/fs/reiserfs/procfs.c
49434 +++ b/fs/reiserfs/procfs.c
49435 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49436 "SMALL_TAILS " : "NO_TAILS ",
49437 replay_only(sb) ? "REPLAY_ONLY " : "",
49438 convert_reiserfs(sb) ? "CONV " : "",
49439 - atomic_read(&r->s_generation_counter),
49440 + atomic_read_unchecked(&r->s_generation_counter),
49441 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49442 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49443 SF(s_good_search_by_key_reada), SF(s_bmaps),
49444 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49445 index 33215f5..c5d427a 100644
49446 --- a/fs/reiserfs/reiserfs.h
49447 +++ b/fs/reiserfs/reiserfs.h
49448 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49449 /* Comment? -Hans */
49450 wait_queue_head_t s_wait;
49451 /* To be obsoleted soon by per buffer seals.. -Hans */
49452 - atomic_t s_generation_counter; // increased by one every time the
49453 + atomic_unchecked_t s_generation_counter; // increased by one every time the
49454 // tree gets re-balanced
49455 unsigned long s_properties; /* File system properties. Currently holds
49456 on-disk FS format */
49457 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49458 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49459
49460 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49461 -#define get_generation(s) atomic_read (&fs_generation(s))
49462 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49463 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49464 #define __fs_changed(gen,s) (gen != get_generation (s))
49465 #define fs_changed(gen,s) \
49466 diff --git a/fs/select.c b/fs/select.c
49467 index bae3215..06b4707 100644
49468 --- a/fs/select.c
49469 +++ b/fs/select.c
49470 @@ -20,6 +20,7 @@
49471 #include <linux/export.h>
49472 #include <linux/slab.h>
49473 #include <linux/poll.h>
49474 +#include <linux/security.h>
49475 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49476 #include <linux/file.h>
49477 #include <linux/fdtable.h>
49478 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49479 struct poll_list *walk = head;
49480 unsigned long todo = nfds;
49481
49482 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49483 if (nfds > rlimit(RLIMIT_NOFILE))
49484 return -EINVAL;
49485
49486 diff --git a/fs/seq_file.c b/fs/seq_file.c
49487 index 0cbd049..64e705c 100644
49488 --- a/fs/seq_file.c
49489 +++ b/fs/seq_file.c
49490 @@ -9,6 +9,7 @@
49491 #include <linux/export.h>
49492 #include <linux/seq_file.h>
49493 #include <linux/slab.h>
49494 +#include <linux/sched.h>
49495
49496 #include <asm/uaccess.h>
49497 #include <asm/page.h>
49498 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49499 memset(p, 0, sizeof(*p));
49500 mutex_init(&p->lock);
49501 p->op = op;
49502 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49503 + p->exec_id = current->exec_id;
49504 +#endif
49505
49506 /*
49507 * Wrappers around seq_open(e.g. swaps_open) need to be
49508 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49509 return 0;
49510 }
49511 if (!m->buf) {
49512 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49513 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49514 if (!m->buf)
49515 return -ENOMEM;
49516 }
49517 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49518 Eoverflow:
49519 m->op->stop(m, p);
49520 kfree(m->buf);
49521 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49522 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49523 return !m->buf ? -ENOMEM : -EAGAIN;
49524 }
49525
49526 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49527
49528 /* grab buffer if we didn't have one */
49529 if (!m->buf) {
49530 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49531 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49532 if (!m->buf)
49533 goto Enomem;
49534 }
49535 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49536 goto Fill;
49537 m->op->stop(m, p);
49538 kfree(m->buf);
49539 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49540 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49541 if (!m->buf)
49542 goto Enomem;
49543 m->count = 0;
49544 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49545 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49546 void *data)
49547 {
49548 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49549 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49550 int res = -ENOMEM;
49551
49552 if (op) {
49553 diff --git a/fs/splice.c b/fs/splice.c
49554 index 7bf08fa..eb35c2f 100644
49555 --- a/fs/splice.c
49556 +++ b/fs/splice.c
49557 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49558 pipe_lock(pipe);
49559
49560 for (;;) {
49561 - if (!pipe->readers) {
49562 + if (!atomic_read(&pipe->readers)) {
49563 send_sig(SIGPIPE, current, 0);
49564 if (!ret)
49565 ret = -EPIPE;
49566 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49567 do_wakeup = 0;
49568 }
49569
49570 - pipe->waiting_writers++;
49571 + atomic_inc(&pipe->waiting_writers);
49572 pipe_wait(pipe);
49573 - pipe->waiting_writers--;
49574 + atomic_dec(&pipe->waiting_writers);
49575 }
49576
49577 pipe_unlock(pipe);
49578 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49579 old_fs = get_fs();
49580 set_fs(get_ds());
49581 /* The cast to a user pointer is valid due to the set_fs() */
49582 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49583 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49584 set_fs(old_fs);
49585
49586 return res;
49587 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49588 old_fs = get_fs();
49589 set_fs(get_ds());
49590 /* The cast to a user pointer is valid due to the set_fs() */
49591 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49592 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49593 set_fs(old_fs);
49594
49595 return res;
49596 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49597 goto err;
49598
49599 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49600 - vec[i].iov_base = (void __user *) page_address(page);
49601 + vec[i].iov_base = (void __force_user *) page_address(page);
49602 vec[i].iov_len = this_len;
49603 spd.pages[i] = page;
49604 spd.nr_pages++;
49605 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49606 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49607 {
49608 while (!pipe->nrbufs) {
49609 - if (!pipe->writers)
49610 + if (!atomic_read(&pipe->writers))
49611 return 0;
49612
49613 - if (!pipe->waiting_writers && sd->num_spliced)
49614 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49615 return 0;
49616
49617 if (sd->flags & SPLICE_F_NONBLOCK)
49618 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49619 * out of the pipe right after the splice_to_pipe(). So set
49620 * PIPE_READERS appropriately.
49621 */
49622 - pipe->readers = 1;
49623 + atomic_set(&pipe->readers, 1);
49624
49625 current->splice_pipe = pipe;
49626 }
49627 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49628 ret = -ERESTARTSYS;
49629 break;
49630 }
49631 - if (!pipe->writers)
49632 + if (!atomic_read(&pipe->writers))
49633 break;
49634 - if (!pipe->waiting_writers) {
49635 + if (!atomic_read(&pipe->waiting_writers)) {
49636 if (flags & SPLICE_F_NONBLOCK) {
49637 ret = -EAGAIN;
49638 break;
49639 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49640 pipe_lock(pipe);
49641
49642 while (pipe->nrbufs >= pipe->buffers) {
49643 - if (!pipe->readers) {
49644 + if (!atomic_read(&pipe->readers)) {
49645 send_sig(SIGPIPE, current, 0);
49646 ret = -EPIPE;
49647 break;
49648 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49649 ret = -ERESTARTSYS;
49650 break;
49651 }
49652 - pipe->waiting_writers++;
49653 + atomic_inc(&pipe->waiting_writers);
49654 pipe_wait(pipe);
49655 - pipe->waiting_writers--;
49656 + atomic_dec(&pipe->waiting_writers);
49657 }
49658
49659 pipe_unlock(pipe);
49660 @@ -1825,14 +1825,14 @@ retry:
49661 pipe_double_lock(ipipe, opipe);
49662
49663 do {
49664 - if (!opipe->readers) {
49665 + if (!atomic_read(&opipe->readers)) {
49666 send_sig(SIGPIPE, current, 0);
49667 if (!ret)
49668 ret = -EPIPE;
49669 break;
49670 }
49671
49672 - if (!ipipe->nrbufs && !ipipe->writers)
49673 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49674 break;
49675
49676 /*
49677 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49678 pipe_double_lock(ipipe, opipe);
49679
49680 do {
49681 - if (!opipe->readers) {
49682 + if (!atomic_read(&opipe->readers)) {
49683 send_sig(SIGPIPE, current, 0);
49684 if (!ret)
49685 ret = -EPIPE;
49686 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49687 * return EAGAIN if we have the potential of some data in the
49688 * future, otherwise just return 0
49689 */
49690 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49691 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49692 ret = -EAGAIN;
49693
49694 pipe_unlock(ipipe);
49695 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49696 index e6bb9b2..d8e3951 100644
49697 --- a/fs/sysfs/dir.c
49698 +++ b/fs/sysfs/dir.c
49699 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49700 struct sysfs_dirent *sd;
49701 int rc;
49702
49703 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49704 + const char *parent_name = parent_sd->s_name;
49705 +
49706 + mode = S_IFDIR | S_IRWXU;
49707 +
49708 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49709 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49710 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49711 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49712 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49713 +#endif
49714 +
49715 /* allocate */
49716 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49717 if (!sd)
49718 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49719 index 00012e3..8392349 100644
49720 --- a/fs/sysfs/file.c
49721 +++ b/fs/sysfs/file.c
49722 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49723
49724 struct sysfs_open_dirent {
49725 atomic_t refcnt;
49726 - atomic_t event;
49727 + atomic_unchecked_t event;
49728 wait_queue_head_t poll;
49729 struct list_head buffers; /* goes through sysfs_buffer.list */
49730 };
49731 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49732 if (!sysfs_get_active(attr_sd))
49733 return -ENODEV;
49734
49735 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49736 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49737 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49738
49739 sysfs_put_active(attr_sd);
49740 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49741 return -ENOMEM;
49742
49743 atomic_set(&new_od->refcnt, 0);
49744 - atomic_set(&new_od->event, 1);
49745 + atomic_set_unchecked(&new_od->event, 1);
49746 init_waitqueue_head(&new_od->poll);
49747 INIT_LIST_HEAD(&new_od->buffers);
49748 goto retry;
49749 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49750
49751 sysfs_put_active(attr_sd);
49752
49753 - if (buffer->event != atomic_read(&od->event))
49754 + if (buffer->event != atomic_read_unchecked(&od->event))
49755 goto trigger;
49756
49757 return DEFAULT_POLLMASK;
49758 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49759
49760 od = sd->s_attr.open;
49761 if (od) {
49762 - atomic_inc(&od->event);
49763 + atomic_inc_unchecked(&od->event);
49764 wake_up_interruptible(&od->poll);
49765 }
49766
49767 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49768 index a7ac78f..02158e1 100644
49769 --- a/fs/sysfs/symlink.c
49770 +++ b/fs/sysfs/symlink.c
49771 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49772
49773 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49774 {
49775 - char *page = nd_get_link(nd);
49776 + const char *page = nd_get_link(nd);
49777 if (!IS_ERR(page))
49778 free_page((unsigned long)page);
49779 }
49780 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49781 index c175b4d..8f36a16 100644
49782 --- a/fs/udf/misc.c
49783 +++ b/fs/udf/misc.c
49784 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49785
49786 u8 udf_tag_checksum(const struct tag *t)
49787 {
49788 - u8 *data = (u8 *)t;
49789 + const u8 *data = (const u8 *)t;
49790 u8 checksum = 0;
49791 int i;
49792 for (i = 0; i < sizeof(struct tag); ++i)
49793 diff --git a/fs/utimes.c b/fs/utimes.c
49794 index fa4dbe4..e12d1b9 100644
49795 --- a/fs/utimes.c
49796 +++ b/fs/utimes.c
49797 @@ -1,6 +1,7 @@
49798 #include <linux/compiler.h>
49799 #include <linux/file.h>
49800 #include <linux/fs.h>
49801 +#include <linux/security.h>
49802 #include <linux/linkage.h>
49803 #include <linux/mount.h>
49804 #include <linux/namei.h>
49805 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49806 goto mnt_drop_write_and_out;
49807 }
49808 }
49809 +
49810 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49811 + error = -EACCES;
49812 + goto mnt_drop_write_and_out;
49813 + }
49814 +
49815 mutex_lock(&inode->i_mutex);
49816 error = notify_change(path->dentry, &newattrs);
49817 mutex_unlock(&inode->i_mutex);
49818 diff --git a/fs/xattr.c b/fs/xattr.c
49819 index 1d7ac37..23cb9ec 100644
49820 --- a/fs/xattr.c
49821 +++ b/fs/xattr.c
49822 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49823 * Extended attribute SET operations
49824 */
49825 static long
49826 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49827 +setxattr(struct path *path, const char __user *name, const void __user *value,
49828 size_t size, int flags)
49829 {
49830 int error;
49831 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49832 }
49833 }
49834
49835 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49836 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49837 + error = -EACCES;
49838 + goto out;
49839 + }
49840 +
49841 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49842 out:
49843 if (vvalue)
49844 vfree(vvalue);
49845 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49846 return error;
49847 error = mnt_want_write(path.mnt);
49848 if (!error) {
49849 - error = setxattr(path.dentry, name, value, size, flags);
49850 + error = setxattr(&path, name, value, size, flags);
49851 mnt_drop_write(path.mnt);
49852 }
49853 path_put(&path);
49854 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49855 return error;
49856 error = mnt_want_write(path.mnt);
49857 if (!error) {
49858 - error = setxattr(path.dentry, name, value, size, flags);
49859 + error = setxattr(&path, name, value, size, flags);
49860 mnt_drop_write(path.mnt);
49861 }
49862 path_put(&path);
49863 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49864 {
49865 int fput_needed;
49866 struct file *f;
49867 - struct dentry *dentry;
49868 int error = -EBADF;
49869
49870 f = fget_light(fd, &fput_needed);
49871 if (!f)
49872 return error;
49873 - dentry = f->f_path.dentry;
49874 - audit_inode(NULL, dentry);
49875 + audit_inode(NULL, f->f_path.dentry);
49876 error = mnt_want_write_file(f);
49877 if (!error) {
49878 - error = setxattr(dentry, name, value, size, flags);
49879 + error = setxattr(&f->f_path, name, value, size, flags);
49880 mnt_drop_write_file(f);
49881 }
49882 fput_light(f, fput_needed);
49883 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49884 index 69d06b0..c0996e5 100644
49885 --- a/fs/xattr_acl.c
49886 +++ b/fs/xattr_acl.c
49887 @@ -17,8 +17,8 @@
49888 struct posix_acl *
49889 posix_acl_from_xattr(const void *value, size_t size)
49890 {
49891 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49892 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49893 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49894 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49895 int count;
49896 struct posix_acl *acl;
49897 struct posix_acl_entry *acl_e;
49898 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49899 index 58b815e..595ddee 100644
49900 --- a/fs/xfs/xfs_bmap.c
49901 +++ b/fs/xfs/xfs_bmap.c
49902 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
49903 int nmap,
49904 int ret_nmap);
49905 #else
49906 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49907 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49908 #endif /* DEBUG */
49909
49910 STATIC int
49911 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49912 index 19bf0c5..9f26b02 100644
49913 --- a/fs/xfs/xfs_dir2_sf.c
49914 +++ b/fs/xfs/xfs_dir2_sf.c
49915 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
49916 }
49917
49918 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49919 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49920 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49921 + char name[sfep->namelen];
49922 + memcpy(name, sfep->name, sfep->namelen);
49923 + if (filldir(dirent, name, sfep->namelen,
49924 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49925 + *offset = off & 0x7fffffff;
49926 + return 0;
49927 + }
49928 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49929 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49930 *offset = off & 0x7fffffff;
49931 return 0;
49932 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49933 index 3a05a41..320bec6 100644
49934 --- a/fs/xfs/xfs_ioctl.c
49935 +++ b/fs/xfs/xfs_ioctl.c
49936 @@ -126,7 +126,7 @@ xfs_find_handle(
49937 }
49938
49939 error = -EFAULT;
49940 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49941 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49942 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49943 goto out_put;
49944
49945 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49946 index 1a25fd8..e935581 100644
49947 --- a/fs/xfs/xfs_iops.c
49948 +++ b/fs/xfs/xfs_iops.c
49949 @@ -394,7 +394,7 @@ xfs_vn_put_link(
49950 struct nameidata *nd,
49951 void *p)
49952 {
49953 - char *s = nd_get_link(nd);
49954 + const char *s = nd_get_link(nd);
49955
49956 if (!IS_ERR(s))
49957 kfree(s);
49958 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49959 new file mode 100644
49960 index 0000000..4d533f1
49961 --- /dev/null
49962 +++ b/grsecurity/Kconfig
49963 @@ -0,0 +1,941 @@
49964 +#
49965 +# grecurity configuration
49966 +#
49967 +menu "Memory Protections"
49968 +depends on GRKERNSEC
49969 +
49970 +config GRKERNSEC_KMEM
49971 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49972 + default y if GRKERNSEC_CONFIG_AUTO
49973 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49974 + help
49975 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49976 + be written to or read from to modify or leak the contents of the running
49977 + kernel. /dev/port will also not be allowed to be opened. If you have module
49978 + support disabled, enabling this will close up four ways that are
49979 + currently used to insert malicious code into the running kernel.
49980 + Even with all these features enabled, we still highly recommend that
49981 + you use the RBAC system, as it is still possible for an attacker to
49982 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49983 + If you are not using XFree86, you may be able to stop this additional
49984 + case by enabling the 'Disable privileged I/O' option. Though nothing
49985 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49986 + but only to video memory, which is the only writing we allow in this
49987 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49988 + not be allowed to mprotect it with PROT_WRITE later.
49989 + It is highly recommended that you say Y here if you meet all the
49990 + conditions above.
49991 +
49992 +config GRKERNSEC_VM86
49993 + bool "Restrict VM86 mode"
49994 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49995 + depends on X86_32
49996 +
49997 + help
49998 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49999 + make use of a special execution mode on 32bit x86 processors called
50000 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50001 + video cards and will still work with this option enabled. The purpose
50002 + of the option is to prevent exploitation of emulation errors in
50003 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50004 + Nearly all users should be able to enable this option.
50005 +
50006 +config GRKERNSEC_IO
50007 + bool "Disable privileged I/O"
50008 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50009 + depends on X86
50010 + select RTC_CLASS
50011 + select RTC_INTF_DEV
50012 + select RTC_DRV_CMOS
50013 +
50014 + help
50015 + If you say Y here, all ioperm and iopl calls will return an error.
50016 + Ioperm and iopl can be used to modify the running kernel.
50017 + Unfortunately, some programs need this access to operate properly,
50018 + the most notable of which are XFree86 and hwclock. hwclock can be
50019 + remedied by having RTC support in the kernel, so real-time
50020 + clock support is enabled if this option is enabled, to ensure
50021 + that hwclock operates correctly. XFree86 still will not
50022 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50023 + IF YOU USE XFree86. If you use XFree86 and you still want to
50024 + protect your kernel against modification, use the RBAC system.
50025 +
50026 +config GRKERNSEC_PROC_MEMMAP
50027 + bool "Harden ASLR against information leaks and entropy reduction"
50028 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50029 + depends on PAX_NOEXEC || PAX_ASLR
50030 + help
50031 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50032 + give no information about the addresses of its mappings if
50033 + PaX features that rely on random addresses are enabled on the task.
50034 + In addition to sanitizing this information and disabling other
50035 + dangerous sources of information, this option causes reads of sensitive
50036 + /proc/<pid> entries where the file descriptor was opened in a different
50037 + task than the one performing the read. Such attempts are logged.
50038 + This option also limits argv/env strings for suid/sgid binaries
50039 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50040 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50041 + binaries to prevent alternative mmap layouts from being abused.
50042 +
50043 + If you use PaX it is essential that you say Y here as it closes up
50044 + several holes that make full ASLR useless locally.
50045 +
50046 +config GRKERNSEC_BRUTE
50047 + bool "Deter exploit bruteforcing"
50048 + default y if GRKERNSEC_CONFIG_AUTO
50049 + help
50050 + If you say Y here, attempts to bruteforce exploits against forking
50051 + daemons such as apache or sshd, as well as against suid/sgid binaries
50052 + will be deterred. When a child of a forking daemon is killed by PaX
50053 + or crashes due to an illegal instruction or other suspicious signal,
50054 + the parent process will be delayed 30 seconds upon every subsequent
50055 + fork until the administrator is able to assess the situation and
50056 + restart the daemon.
50057 + In the suid/sgid case, the attempt is logged, the user has all their
50058 + processes terminated, and they are prevented from executing any further
50059 + processes for 15 minutes.
50060 + It is recommended that you also enable signal logging in the auditing
50061 + section so that logs are generated when a process triggers a suspicious
50062 + signal.
50063 + If the sysctl option is enabled, a sysctl option with name
50064 + "deter_bruteforce" is created.
50065 +
50066 +
50067 +config GRKERNSEC_MODHARDEN
50068 + bool "Harden module auto-loading"
50069 + default y if GRKERNSEC_CONFIG_AUTO
50070 + depends on MODULES
50071 + help
50072 + If you say Y here, module auto-loading in response to use of some
50073 + feature implemented by an unloaded module will be restricted to
50074 + root users. Enabling this option helps defend against attacks
50075 + by unprivileged users who abuse the auto-loading behavior to
50076 + cause a vulnerable module to load that is then exploited.
50077 +
50078 + If this option prevents a legitimate use of auto-loading for a
50079 + non-root user, the administrator can execute modprobe manually
50080 + with the exact name of the module mentioned in the alert log.
50081 + Alternatively, the administrator can add the module to the list
50082 + of modules loaded at boot by modifying init scripts.
50083 +
50084 + Modification of init scripts will most likely be needed on
50085 + Ubuntu servers with encrypted home directory support enabled,
50086 + as the first non-root user logging in will cause the ecb(aes),
50087 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50088 +
50089 +config GRKERNSEC_HIDESYM
50090 + bool "Hide kernel symbols"
50091 + default y if GRKERNSEC_CONFIG_AUTO
50092 + select PAX_USERCOPY_SLABS
50093 + help
50094 + If you say Y here, getting information on loaded modules, and
50095 + displaying all kernel symbols through a syscall will be restricted
50096 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50097 + /proc/kallsyms will be restricted to the root user. The RBAC
50098 + system can hide that entry even from root.
50099 +
50100 + This option also prevents leaking of kernel addresses through
50101 + several /proc entries.
50102 +
50103 + Note that this option is only effective provided the following
50104 + conditions are met:
50105 + 1) The kernel using grsecurity is not precompiled by some distribution
50106 + 2) You have also enabled GRKERNSEC_DMESG
50107 + 3) You are using the RBAC system and hiding other files such as your
50108 + kernel image and System.map. Alternatively, enabling this option
50109 + causes the permissions on /boot, /lib/modules, and the kernel
50110 + source directory to change at compile time to prevent
50111 + reading by non-root users.
50112 + If the above conditions are met, this option will aid in providing a
50113 + useful protection against local kernel exploitation of overflows
50114 + and arbitrary read/write vulnerabilities.
50115 +
50116 +config GRKERNSEC_KERN_LOCKOUT
50117 + bool "Active kernel exploit response"
50118 + default y if GRKERNSEC_CONFIG_AUTO
50119 + depends on X86 || ARM || PPC || SPARC
50120 + help
50121 + If you say Y here, when a PaX alert is triggered due to suspicious
50122 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50123 + or an OOPS occurs due to bad memory accesses, instead of just
50124 + terminating the offending process (and potentially allowing
50125 + a subsequent exploit from the same user), we will take one of two
50126 + actions:
50127 + If the user was root, we will panic the system
50128 + If the user was non-root, we will log the attempt, terminate
50129 + all processes owned by the user, then prevent them from creating
50130 + any new processes until the system is restarted
50131 + This deters repeated kernel exploitation/bruteforcing attempts
50132 + and is useful for later forensics.
50133 +
50134 +endmenu
50135 +menu "Role Based Access Control Options"
50136 +depends on GRKERNSEC
50137 +
50138 +config GRKERNSEC_RBAC_DEBUG
50139 + bool
50140 +
50141 +config GRKERNSEC_NO_RBAC
50142 + bool "Disable RBAC system"
50143 + help
50144 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50145 + preventing the RBAC system from being enabled. You should only say Y
50146 + here if you have no intention of using the RBAC system, so as to prevent
50147 + an attacker with root access from misusing the RBAC system to hide files
50148 + and processes when loadable module support and /dev/[k]mem have been
50149 + locked down.
50150 +
50151 +config GRKERNSEC_ACL_HIDEKERN
50152 + bool "Hide kernel processes"
50153 + help
50154 + If you say Y here, all kernel threads will be hidden to all
50155 + processes but those whose subject has the "view hidden processes"
50156 + flag.
50157 +
50158 +config GRKERNSEC_ACL_MAXTRIES
50159 + int "Maximum tries before password lockout"
50160 + default 3
50161 + help
50162 + This option enforces the maximum number of times a user can attempt
50163 + to authorize themselves with the grsecurity RBAC system before being
50164 + denied the ability to attempt authorization again for a specified time.
50165 + The lower the number, the harder it will be to brute-force a password.
50166 +
50167 +config GRKERNSEC_ACL_TIMEOUT
50168 + int "Time to wait after max password tries, in seconds"
50169 + default 30
50170 + help
50171 + This option specifies the time the user must wait after attempting to
50172 + authorize to the RBAC system with the maximum number of invalid
50173 + passwords. The higher the number, the harder it will be to brute-force
50174 + a password.
50175 +
50176 +endmenu
50177 +menu "Filesystem Protections"
50178 +depends on GRKERNSEC
50179 +
50180 +config GRKERNSEC_PROC
50181 + bool "Proc restrictions"
50182 + default y if GRKERNSEC_CONFIG_AUTO
50183 + help
50184 + If you say Y here, the permissions of the /proc filesystem
50185 + will be altered to enhance system security and privacy. You MUST
50186 + choose either a user only restriction or a user and group restriction.
50187 + Depending upon the option you choose, you can either restrict users to
50188 + see only the processes they themselves run, or choose a group that can
50189 + view all processes and files normally restricted to root if you choose
50190 + the "restrict to user only" option. NOTE: If you're running identd or
50191 + ntpd as a non-root user, you will have to run it as the group you
50192 + specify here.
50193 +
50194 +config GRKERNSEC_PROC_USER
50195 + bool "Restrict /proc to user only"
50196 + depends on GRKERNSEC_PROC
50197 + help
50198 + If you say Y here, non-root users will only be able to view their own
50199 + processes, and restricts them from viewing network-related information,
50200 + and viewing kernel symbol and module information.
50201 +
50202 +config GRKERNSEC_PROC_USERGROUP
50203 + bool "Allow special group"
50204 + default y if GRKERNSEC_CONFIG_AUTO
50205 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50206 + help
50207 + If you say Y here, you will be able to select a group that will be
50208 + able to view all processes and network-related information. If you've
50209 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50210 + remain hidden. This option is useful if you want to run identd as
50211 + a non-root user.
50212 +
50213 +config GRKERNSEC_PROC_GID
50214 + int "GID for special group"
50215 + depends on GRKERNSEC_PROC_USERGROUP
50216 + default 1001
50217 +
50218 +config GRKERNSEC_PROC_ADD
50219 + bool "Additional restrictions"
50220 + default y if GRKERNSEC_CONFIG_AUTO
50221 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50222 + help
50223 + If you say Y here, additional restrictions will be placed on
50224 + /proc that keep normal users from viewing device information and
50225 + slabinfo information that could be useful for exploits.
50226 +
50227 +config GRKERNSEC_LINK
50228 + bool "Linking restrictions"
50229 + default y if GRKERNSEC_CONFIG_AUTO
50230 + help
50231 + If you say Y here, /tmp race exploits will be prevented, since users
50232 + will no longer be able to follow symlinks owned by other users in
50233 + world-writable +t directories (e.g. /tmp), unless the owner of the
50234 + symlink is the owner of the directory. users will also not be
50235 + able to hardlink to files they do not own. If the sysctl option is
50236 + enabled, a sysctl option with name "linking_restrictions" is created.
50237 +
50238 +config GRKERNSEC_SYMLINKOWN
50239 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50240 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50241 + help
50242 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50243 + that prevents it from being used as a security feature. As Apache
50244 + verifies the symlink by performing a stat() against the target of
50245 + the symlink before it is followed, an attacker can setup a symlink
50246 + to point to a same-owned file, then replace the symlink with one
50247 + that targets another user's file just after Apache "validates" the
50248 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50249 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50250 + will be in place for the group you specify. If the sysctl option
50251 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50252 + created.
50253 +
50254 +config GRKERNSEC_SYMLINKOWN_GID
50255 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50256 + depends on GRKERNSEC_SYMLINKOWN
50257 + default 1006
50258 + help
50259 + Setting this GID determines what group kernel-enforced
50260 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50261 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50262 +
50263 +config GRKERNSEC_FIFO
50264 + bool "FIFO restrictions"
50265 + default y if GRKERNSEC_CONFIG_AUTO
50266 + help
50267 + If you say Y here, users will not be able to write to FIFOs they don't
50268 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50269 + the FIFO is the same owner of the directory it's held in. If the sysctl
50270 + option is enabled, a sysctl option with name "fifo_restrictions" is
50271 + created.
50272 +
50273 +config GRKERNSEC_SYSFS_RESTRICT
50274 + bool "Sysfs/debugfs restriction"
50275 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50276 + depends on SYSFS
50277 + help
50278 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50279 + any filesystem normally mounted under it (e.g. debugfs) will be
50280 + mostly accessible only by root. These filesystems generally provide access
50281 + to hardware and debug information that isn't appropriate for unprivileged
50282 + users of the system. Sysfs and debugfs have also become a large source
50283 + of new vulnerabilities, ranging from infoleaks to local compromise.
50284 + There has been very little oversight with an eye toward security involved
50285 + in adding new exporters of information to these filesystems, so their
50286 + use is discouraged.
50287 + For reasons of compatibility, a few directories have been whitelisted
50288 + for access by non-root users:
50289 + /sys/fs/selinux
50290 + /sys/fs/fuse
50291 + /sys/devices/system/cpu
50292 +
50293 +config GRKERNSEC_ROFS
50294 + bool "Runtime read-only mount protection"
50295 + help
50296 + If you say Y here, a sysctl option with name "romount_protect" will
50297 + be created. By setting this option to 1 at runtime, filesystems
50298 + will be protected in the following ways:
50299 + * No new writable mounts will be allowed
50300 + * Existing read-only mounts won't be able to be remounted read/write
50301 + * Write operations will be denied on all block devices
50302 + This option acts independently of grsec_lock: once it is set to 1,
50303 + it cannot be turned off. Therefore, please be mindful of the resulting
50304 + behavior if this option is enabled in an init script on a read-only
50305 + filesystem. This feature is mainly intended for secure embedded systems.
50306 +
50307 +config GRKERNSEC_CHROOT
50308 + bool "Chroot jail restrictions"
50309 + default y if GRKERNSEC_CONFIG_AUTO
50310 + help
50311 + If you say Y here, you will be able to choose several options that will
50312 + make breaking out of a chrooted jail much more difficult. If you
50313 + encounter no software incompatibilities with the following options, it
50314 + is recommended that you enable each one.
50315 +
50316 +config GRKERNSEC_CHROOT_MOUNT
50317 + bool "Deny mounts"
50318 + default y if GRKERNSEC_CONFIG_AUTO
50319 + depends on GRKERNSEC_CHROOT
50320 + help
50321 + If you say Y here, processes inside a chroot will not be able to
50322 + mount or remount filesystems. If the sysctl option is enabled, a
50323 + sysctl option with name "chroot_deny_mount" is created.
50324 +
50325 +config GRKERNSEC_CHROOT_DOUBLE
50326 + bool "Deny double-chroots"
50327 + default y if GRKERNSEC_CONFIG_AUTO
50328 + depends on GRKERNSEC_CHROOT
50329 + help
50330 + If you say Y here, processes inside a chroot will not be able to chroot
50331 + again outside the chroot. This is a widely used method of breaking
50332 + out of a chroot jail and should not be allowed. If the sysctl
50333 + option is enabled, a sysctl option with name
50334 + "chroot_deny_chroot" is created.
50335 +
50336 +config GRKERNSEC_CHROOT_PIVOT
50337 + bool "Deny pivot_root in chroot"
50338 + default y if GRKERNSEC_CONFIG_AUTO
50339 + depends on GRKERNSEC_CHROOT
50340 + help
50341 + If you say Y here, processes inside a chroot will not be able to use
50342 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50343 + works similar to chroot in that it changes the root filesystem. This
50344 + function could be misused in a chrooted process to attempt to break out
50345 + of the chroot, and therefore should not be allowed. If the sysctl
50346 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50347 + created.
50348 +
50349 +config GRKERNSEC_CHROOT_CHDIR
50350 + bool "Enforce chdir(\"/\") on all chroots"
50351 + default y if GRKERNSEC_CONFIG_AUTO
50352 + depends on GRKERNSEC_CHROOT
50353 + help
50354 + If you say Y here, the current working directory of all newly-chrooted
50355 + applications will be set to the the root directory of the chroot.
50356 + The man page on chroot(2) states:
50357 + Note that this call does not change the current working
50358 + directory, so that `.' can be outside the tree rooted at
50359 + `/'. In particular, the super-user can escape from a
50360 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50361 +
50362 + It is recommended that you say Y here, since it's not known to break
50363 + any software. If the sysctl option is enabled, a sysctl option with
50364 + name "chroot_enforce_chdir" is created.
50365 +
50366 +config GRKERNSEC_CHROOT_CHMOD
50367 + bool "Deny (f)chmod +s"
50368 + default y if GRKERNSEC_CONFIG_AUTO
50369 + depends on GRKERNSEC_CHROOT
50370 + help
50371 + If you say Y here, processes inside a chroot will not be able to chmod
50372 + or fchmod files to make them have suid or sgid bits. This protects
50373 + against another published method of breaking a chroot. If the sysctl
50374 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50375 + created.
50376 +
50377 +config GRKERNSEC_CHROOT_FCHDIR
50378 + bool "Deny fchdir out of chroot"
50379 + default y if GRKERNSEC_CONFIG_AUTO
50380 + depends on GRKERNSEC_CHROOT
50381 + help
50382 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50383 + to a file descriptor of the chrooting process that points to a directory
50384 + outside the filesystem will be stopped. If the sysctl option
50385 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50386 +
50387 +config GRKERNSEC_CHROOT_MKNOD
50388 + bool "Deny mknod"
50389 + default y if GRKERNSEC_CONFIG_AUTO
50390 + depends on GRKERNSEC_CHROOT
50391 + help
50392 + If you say Y here, processes inside a chroot will not be allowed to
50393 + mknod. The problem with using mknod inside a chroot is that it
50394 + would allow an attacker to create a device entry that is the same
50395 + as one on the physical root of your system, which could range from
50396 + anything from the console device to a device for your harddrive (which
50397 + they could then use to wipe the drive or steal data). It is recommended
50398 + that you say Y here, unless you run into software incompatibilities.
50399 + If the sysctl option is enabled, a sysctl option with name
50400 + "chroot_deny_mknod" is created.
50401 +
50402 +config GRKERNSEC_CHROOT_SHMAT
50403 + bool "Deny shmat() out of chroot"
50404 + default y if GRKERNSEC_CONFIG_AUTO
50405 + depends on GRKERNSEC_CHROOT
50406 + help
50407 + If you say Y here, processes inside a chroot will not be able to attach
50408 + to shared memory segments that were created outside of the chroot jail.
50409 + It is recommended that you say Y here. If the sysctl option is enabled,
50410 + a sysctl option with name "chroot_deny_shmat" is created.
50411 +
50412 +config GRKERNSEC_CHROOT_UNIX
50413 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50414 + default y if GRKERNSEC_CONFIG_AUTO
50415 + depends on GRKERNSEC_CHROOT
50416 + help
50417 + If you say Y here, processes inside a chroot will not be able to
50418 + connect to abstract (meaning not belonging to a filesystem) Unix
50419 + domain sockets that were bound outside of a chroot. It is recommended
50420 + that you say Y here. If the sysctl option is enabled, a sysctl option
50421 + with name "chroot_deny_unix" is created.
50422 +
50423 +config GRKERNSEC_CHROOT_FINDTASK
50424 + bool "Protect outside processes"
50425 + default y if GRKERNSEC_CONFIG_AUTO
50426 + depends on GRKERNSEC_CHROOT
50427 + help
50428 + If you say Y here, processes inside a chroot will not be able to
50429 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50430 + getsid, or view any process outside of the chroot. If the sysctl
50431 + option is enabled, a sysctl option with name "chroot_findtask" is
50432 + created.
50433 +
50434 +config GRKERNSEC_CHROOT_NICE
50435 + bool "Restrict priority changes"
50436 + default y if GRKERNSEC_CONFIG_AUTO
50437 + depends on GRKERNSEC_CHROOT
50438 + help
50439 + If you say Y here, processes inside a chroot will not be able to raise
50440 + the priority of processes in the chroot, or alter the priority of
50441 + processes outside the chroot. This provides more security than simply
50442 + removing CAP_SYS_NICE from the process' capability set. If the
50443 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50444 + is created.
50445 +
50446 +config GRKERNSEC_CHROOT_SYSCTL
50447 + bool "Deny sysctl writes"
50448 + default y if GRKERNSEC_CONFIG_AUTO
50449 + depends on GRKERNSEC_CHROOT
50450 + help
50451 + If you say Y here, an attacker in a chroot will not be able to
50452 + write to sysctl entries, either by sysctl(2) or through a /proc
50453 + interface. It is strongly recommended that you say Y here. If the
50454 + sysctl option is enabled, a sysctl option with name
50455 + "chroot_deny_sysctl" is created.
50456 +
50457 +config GRKERNSEC_CHROOT_CAPS
50458 + bool "Capability restrictions"
50459 + default y if GRKERNSEC_CONFIG_AUTO
50460 + depends on GRKERNSEC_CHROOT
50461 + help
50462 + If you say Y here, the capabilities on all processes within a
50463 + chroot jail will be lowered to stop module insertion, raw i/o,
50464 + system and net admin tasks, rebooting the system, modifying immutable
50465 + files, modifying IPC owned by another, and changing the system time.
50466 + This is left an option because it can break some apps. Disable this
50467 + if your chrooted apps are having problems performing those kinds of
50468 + tasks. If the sysctl option is enabled, a sysctl option with
50469 + name "chroot_caps" is created.
50470 +
50471 +endmenu
50472 +menu "Kernel Auditing"
50473 +depends on GRKERNSEC
50474 +
50475 +config GRKERNSEC_AUDIT_GROUP
50476 + bool "Single group for auditing"
50477 + help
50478 + If you say Y here, the exec, chdir, and (un)mount logging features
50479 + will only operate on a group you specify. This option is recommended
50480 + if you only want to watch certain users instead of having a large
50481 + amount of logs from the entire system. If the sysctl option is enabled,
50482 + a sysctl option with name "audit_group" is created.
50483 +
50484 +config GRKERNSEC_AUDIT_GID
50485 + int "GID for auditing"
50486 + depends on GRKERNSEC_AUDIT_GROUP
50487 + default 1007
50488 +
50489 +config GRKERNSEC_EXECLOG
50490 + bool "Exec logging"
50491 + help
50492 + If you say Y here, all execve() calls will be logged (since the
50493 + other exec*() calls are frontends to execve(), all execution
50494 + will be logged). Useful for shell-servers that like to keep track
50495 + of their users. If the sysctl option is enabled, a sysctl option with
50496 + name "exec_logging" is created.
50497 + WARNING: This option when enabled will produce a LOT of logs, especially
50498 + on an active system.
50499 +
50500 +config GRKERNSEC_RESLOG
50501 + bool "Resource logging"
50502 + default y if GRKERNSEC_CONFIG_AUTO
50503 + help
50504 + If you say Y here, all attempts to overstep resource limits will
50505 + be logged with the resource name, the requested size, and the current
50506 + limit. It is highly recommended that you say Y here. If the sysctl
50507 + option is enabled, a sysctl option with name "resource_logging" is
50508 + created. If the RBAC system is enabled, the sysctl value is ignored.
50509 +
50510 +config GRKERNSEC_CHROOT_EXECLOG
50511 + bool "Log execs within chroot"
50512 + help
50513 + If you say Y here, all executions inside a chroot jail will be logged
50514 + to syslog. This can cause a large amount of logs if certain
50515 + applications (eg. djb's daemontools) are installed on the system, and
50516 + is therefore left as an option. If the sysctl option is enabled, a
50517 + sysctl option with name "chroot_execlog" is created.
50518 +
50519 +config GRKERNSEC_AUDIT_PTRACE
50520 + bool "Ptrace logging"
50521 + help
50522 + If you say Y here, all attempts to attach to a process via ptrace
50523 + will be logged. If the sysctl option is enabled, a sysctl option
50524 + with name "audit_ptrace" is created.
50525 +
50526 +config GRKERNSEC_AUDIT_CHDIR
50527 + bool "Chdir logging"
50528 + help
50529 + If you say Y here, all chdir() calls will be logged. If the sysctl
50530 + option is enabled, a sysctl option with name "audit_chdir" is created.
50531 +
50532 +config GRKERNSEC_AUDIT_MOUNT
50533 + bool "(Un)Mount logging"
50534 + help
50535 + If you say Y here, all mounts and unmounts will be logged. If the
50536 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50537 + created.
50538 +
50539 +config GRKERNSEC_SIGNAL
50540 + bool "Signal logging"
50541 + default y if GRKERNSEC_CONFIG_AUTO
50542 + help
50543 + If you say Y here, certain important signals will be logged, such as
50544 + SIGSEGV, which will as a result inform you of when a error in a program
50545 + occurred, which in some cases could mean a possible exploit attempt.
50546 + If the sysctl option is enabled, a sysctl option with name
50547 + "signal_logging" is created.
50548 +
50549 +config GRKERNSEC_FORKFAIL
50550 + bool "Fork failure logging"
50551 + help
50552 + If you say Y here, all failed fork() attempts will be logged.
50553 + This could suggest a fork bomb, or someone attempting to overstep
50554 + their process limit. If the sysctl option is enabled, a sysctl option
50555 + with name "forkfail_logging" is created.
50556 +
50557 +config GRKERNSEC_TIME
50558 + bool "Time change logging"
50559 + default y if GRKERNSEC_CONFIG_AUTO
50560 + help
50561 + If you say Y here, any changes of the system clock will be logged.
50562 + If the sysctl option is enabled, a sysctl option with name
50563 + "timechange_logging" is created.
50564 +
50565 +config GRKERNSEC_PROC_IPADDR
50566 + bool "/proc/<pid>/ipaddr support"
50567 + default y if GRKERNSEC_CONFIG_AUTO
50568 + help
50569 + If you say Y here, a new entry will be added to each /proc/<pid>
50570 + directory that contains the IP address of the person using the task.
50571 + The IP is carried across local TCP and AF_UNIX stream sockets.
50572 + This information can be useful for IDS/IPSes to perform remote response
50573 + to a local attack. The entry is readable by only the owner of the
50574 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50575 + the RBAC system), and thus does not create privacy concerns.
50576 +
50577 +config GRKERNSEC_RWXMAP_LOG
50578 + bool 'Denied RWX mmap/mprotect logging'
50579 + default y if GRKERNSEC_CONFIG_AUTO
50580 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50581 + help
50582 + If you say Y here, calls to mmap() and mprotect() with explicit
50583 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50584 + denied by the PAX_MPROTECT feature. If the sysctl option is
50585 + enabled, a sysctl option with name "rwxmap_logging" is created.
50586 +
50587 +config GRKERNSEC_AUDIT_TEXTREL
50588 + bool 'ELF text relocations logging (READ HELP)'
50589 + depends on PAX_MPROTECT
50590 + help
50591 + If you say Y here, text relocations will be logged with the filename
50592 + of the offending library or binary. The purpose of the feature is
50593 + to help Linux distribution developers get rid of libraries and
50594 + binaries that need text relocations which hinder the future progress
50595 + of PaX. Only Linux distribution developers should say Y here, and
50596 + never on a production machine, as this option creates an information
50597 + leak that could aid an attacker in defeating the randomization of
50598 + a single memory region. If the sysctl option is enabled, a sysctl
50599 + option with name "audit_textrel" is created.
50600 +
50601 +endmenu
50602 +
50603 +menu "Executable Protections"
50604 +depends on GRKERNSEC
50605 +
50606 +config GRKERNSEC_DMESG
50607 + bool "Dmesg(8) restriction"
50608 + default y if GRKERNSEC_CONFIG_AUTO
50609 + help
50610 + If you say Y here, non-root users will not be able to use dmesg(8)
50611 + to view up to the last 4kb of messages in the kernel's log buffer.
50612 + The kernel's log buffer often contains kernel addresses and other
50613 + identifying information useful to an attacker in fingerprinting a
50614 + system for a targeted exploit.
50615 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50616 + created.
50617 +
50618 +config GRKERNSEC_HARDEN_PTRACE
50619 + bool "Deter ptrace-based process snooping"
50620 + default y if GRKERNSEC_CONFIG_AUTO
50621 + help
50622 + If you say Y here, TTY sniffers and other malicious monitoring
50623 + programs implemented through ptrace will be defeated. If you
50624 + have been using the RBAC system, this option has already been
50625 + enabled for several years for all users, with the ability to make
50626 + fine-grained exceptions.
50627 +
50628 + This option only affects the ability of non-root users to ptrace
50629 + processes that are not a descendent of the ptracing process.
50630 + This means that strace ./binary and gdb ./binary will still work,
50631 + but attaching to arbitrary processes will not. If the sysctl
50632 + option is enabled, a sysctl option with name "harden_ptrace" is
50633 + created.
50634 +
50635 +config GRKERNSEC_PTRACE_READEXEC
50636 + bool "Require read access to ptrace sensitive binaries"
50637 + default y if GRKERNSEC_CONFIG_AUTO
50638 + help
50639 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50640 + binaries. This option is useful in environments that
50641 + remove the read bits (e.g. file mode 4711) from suid binaries to
50642 + prevent infoleaking of their contents. This option adds
50643 + consistency to the use of that file mode, as the binary could normally
50644 + be read out when run without privileges while ptracing.
50645 +
50646 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50647 + is created.
50648 +
50649 +config GRKERNSEC_SETXID
50650 + bool "Enforce consistent multithreaded privileges"
50651 + default y if GRKERNSEC_CONFIG_AUTO
50652 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50653 + help
50654 + If you say Y here, a change from a root uid to a non-root uid
50655 + in a multithreaded application will cause the resulting uids,
50656 + gids, supplementary groups, and capabilities in that thread
50657 + to be propagated to the other threads of the process. In most
50658 + cases this is unnecessary, as glibc will emulate this behavior
50659 + on behalf of the application. Other libcs do not act in the
50660 + same way, allowing the other threads of the process to continue
50661 + running with root privileges. If the sysctl option is enabled,
50662 + a sysctl option with name "consistent_setxid" is created.
50663 +
50664 +config GRKERNSEC_TPE
50665 + bool "Trusted Path Execution (TPE)"
50666 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50667 + help
50668 + If you say Y here, you will be able to choose a gid to add to the
50669 + supplementary groups of users you want to mark as "untrusted."
50670 + These users will not be able to execute any files that are not in
50671 + root-owned directories writable only by root. If the sysctl option
50672 + is enabled, a sysctl option with name "tpe" is created.
50673 +
50674 +config GRKERNSEC_TPE_ALL
50675 + bool "Partially restrict all non-root users"
50676 + depends on GRKERNSEC_TPE
50677 + help
50678 + If you say Y here, all non-root users will be covered under
50679 + a weaker TPE restriction. This is separate from, and in addition to,
50680 + the main TPE options that you have selected elsewhere. Thus, if a
50681 + "trusted" GID is chosen, this restriction applies to even that GID.
50682 + Under this restriction, all non-root users will only be allowed to
50683 + execute files in directories they own that are not group or
50684 + world-writable, or in directories owned by root and writable only by
50685 + root. If the sysctl option is enabled, a sysctl option with name
50686 + "tpe_restrict_all" is created.
50687 +
50688 +config GRKERNSEC_TPE_INVERT
50689 + bool "Invert GID option"
50690 + depends on GRKERNSEC_TPE
50691 + help
50692 + If you say Y here, the group you specify in the TPE configuration will
50693 + decide what group TPE restrictions will be *disabled* for. This
50694 + option is useful if you want TPE restrictions to be applied to most
50695 + users on the system. If the sysctl option is enabled, a sysctl option
50696 + with name "tpe_invert" is created. Unlike other sysctl options, this
50697 + entry will default to on for backward-compatibility.
50698 +
50699 +config GRKERNSEC_TPE_GID
50700 + int "GID for untrusted users"
50701 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50702 + default 1005
50703 + help
50704 + Setting this GID determines what group TPE restrictions will be
50705 + *enabled* for. If the sysctl option is enabled, a sysctl option
50706 + with name "tpe_gid" is created.
50707 +
50708 +config GRKERNSEC_TPE_GID
50709 + int "GID for trusted users"
50710 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50711 + default 1005
50712 + help
50713 + Setting this GID determines what group TPE restrictions will be
50714 + *disabled* for. If the sysctl option is enabled, a sysctl option
50715 + with name "tpe_gid" is created.
50716 +
50717 +endmenu
50718 +menu "Network Protections"
50719 +depends on GRKERNSEC
50720 +
50721 +config GRKERNSEC_RANDNET
50722 + bool "Larger entropy pools"
50723 + default y if GRKERNSEC_CONFIG_AUTO
50724 + help
50725 + If you say Y here, the entropy pools used for many features of Linux
50726 + and grsecurity will be doubled in size. Since several grsecurity
50727 + features use additional randomness, it is recommended that you say Y
50728 + here. Saying Y here has a similar effect as modifying
50729 + /proc/sys/kernel/random/poolsize.
50730 +
50731 +config GRKERNSEC_BLACKHOLE
50732 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50733 + default y if GRKERNSEC_CONFIG_AUTO
50734 + depends on NET
50735 + help
50736 + If you say Y here, neither TCP resets nor ICMP
50737 + destination-unreachable packets will be sent in response to packets
50738 + sent to ports for which no associated listening process exists.
50739 + This feature supports both IPV4 and IPV6 and exempts the
50740 + loopback interface from blackholing. Enabling this feature
50741 + makes a host more resilient to DoS attacks and reduces network
50742 + visibility against scanners.
50743 +
50744 + The blackhole feature as-implemented is equivalent to the FreeBSD
50745 + blackhole feature, as it prevents RST responses to all packets, not
50746 + just SYNs. Under most application behavior this causes no
50747 + problems, but applications (like haproxy) may not close certain
50748 + connections in a way that cleanly terminates them on the remote
50749 + end, leaving the remote host in LAST_ACK state. Because of this
50750 + side-effect and to prevent intentional LAST_ACK DoSes, this
50751 + feature also adds automatic mitigation against such attacks.
50752 + The mitigation drastically reduces the amount of time a socket
50753 + can spend in LAST_ACK state. If you're using haproxy and not
50754 + all servers it connects to have this option enabled, consider
50755 + disabling this feature on the haproxy host.
50756 +
50757 + If the sysctl option is enabled, two sysctl options with names
50758 + "ip_blackhole" and "lastack_retries" will be created.
50759 + While "ip_blackhole" takes the standard zero/non-zero on/off
50760 + toggle, "lastack_retries" uses the same kinds of values as
50761 + "tcp_retries1" and "tcp_retries2". The default value of 4
50762 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50763 + state.
50764 +
50765 +config GRKERNSEC_SOCKET
50766 + bool "Socket restrictions"
50767 + depends on NET
50768 + help
50769 + If you say Y here, you will be able to choose from several options.
50770 + If you assign a GID on your system and add it to the supplementary
50771 + groups of users you want to restrict socket access to, this patch
50772 + will perform up to three things, based on the option(s) you choose.
50773 +
50774 +config GRKERNSEC_SOCKET_ALL
50775 + bool "Deny any sockets to group"
50776 + depends on GRKERNSEC_SOCKET
50777 + help
50778 + If you say Y here, you will be able to choose a GID of whose users will
50779 + be unable to connect to other hosts from your machine or run server
50780 + applications from your machine. If the sysctl option is enabled, a
50781 + sysctl option with name "socket_all" is created.
50782 +
50783 +config GRKERNSEC_SOCKET_ALL_GID
50784 + int "GID to deny all sockets for"
50785 + depends on GRKERNSEC_SOCKET_ALL
50786 + default 1004
50787 + help
50788 + Here you can choose the GID to disable socket access for. Remember to
50789 + add the users you want socket access disabled for to the GID
50790 + specified here. If the sysctl option is enabled, a sysctl option
50791 + with name "socket_all_gid" is created.
50792 +
50793 +config GRKERNSEC_SOCKET_CLIENT
50794 + bool "Deny client sockets to group"
50795 + depends on GRKERNSEC_SOCKET
50796 + help
50797 + If you say Y here, you will be able to choose a GID of whose users will
50798 + be unable to connect to other hosts from your machine, but will be
50799 + able to run servers. If this option is enabled, all users in the group
50800 + you specify will have to use passive mode when initiating ftp transfers
50801 + from the shell on your machine. If the sysctl option is enabled, a
50802 + sysctl option with name "socket_client" is created.
50803 +
50804 +config GRKERNSEC_SOCKET_CLIENT_GID
50805 + int "GID to deny client sockets for"
50806 + depends on GRKERNSEC_SOCKET_CLIENT
50807 + default 1003
50808 + help
50809 + Here you can choose the GID to disable client socket access for.
50810 + Remember to add the users you want client socket access disabled for to
50811 + the GID specified here. If the sysctl option is enabled, a sysctl
50812 + option with name "socket_client_gid" is created.
50813 +
50814 +config GRKERNSEC_SOCKET_SERVER
50815 + bool "Deny server sockets to group"
50816 + depends on GRKERNSEC_SOCKET
50817 + help
50818 + If you say Y here, you will be able to choose a GID of whose users will
50819 + be unable to run server applications from your machine. If the sysctl
50820 + option is enabled, a sysctl option with name "socket_server" is created.
50821 +
50822 +config GRKERNSEC_SOCKET_SERVER_GID
50823 + int "GID to deny server sockets for"
50824 + depends on GRKERNSEC_SOCKET_SERVER
50825 + default 1002
50826 + help
50827 + Here you can choose the GID to disable server socket access for.
50828 + Remember to add the users you want server socket access disabled for to
50829 + the GID specified here. If the sysctl option is enabled, a sysctl
50830 + option with name "socket_server_gid" is created.
50831 +
50832 +endmenu
50833 +menu "Sysctl Support"
50834 +depends on GRKERNSEC && SYSCTL
50835 +
50836 +config GRKERNSEC_SYSCTL
50837 + bool "Sysctl support"
50838 + default y if GRKERNSEC_CONFIG_AUTO
50839 + help
50840 + If you say Y here, you will be able to change the options that
50841 + grsecurity runs with at bootup, without having to recompile your
50842 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50843 + to enable (1) or disable (0) various features. All the sysctl entries
50844 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50845 + All features enabled in the kernel configuration are disabled at boot
50846 + if you do not say Y to the "Turn on features by default" option.
50847 + All options should be set at startup, and the grsec_lock entry should
50848 + be set to a non-zero value after all the options are set.
50849 + *THIS IS EXTREMELY IMPORTANT*
50850 +
50851 +config GRKERNSEC_SYSCTL_DISTRO
50852 + bool "Extra sysctl support for distro makers (READ HELP)"
50853 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50854 + help
50855 + If you say Y here, additional sysctl options will be created
50856 + for features that affect processes running as root. Therefore,
50857 + it is critical when using this option that the grsec_lock entry be
50858 + enabled after boot. Only distros with prebuilt kernel packages
50859 + with this option enabled that can ensure grsec_lock is enabled
50860 + after boot should use this option.
50861 + *Failure to set grsec_lock after boot makes all grsec features
50862 + this option covers useless*
50863 +
50864 + Currently this option creates the following sysctl entries:
50865 + "Disable Privileged I/O": "disable_priv_io"
50866 +
50867 +config GRKERNSEC_SYSCTL_ON
50868 + bool "Turn on features by default"
50869 + default y if GRKERNSEC_CONFIG_AUTO
50870 + depends on GRKERNSEC_SYSCTL
50871 + help
50872 + If you say Y here, instead of having all features enabled in the
50873 + kernel configuration disabled at boot time, the features will be
50874 + enabled at boot time. It is recommended you say Y here unless
50875 + there is some reason you would want all sysctl-tunable features to
50876 + be disabled by default. As mentioned elsewhere, it is important
50877 + to enable the grsec_lock entry once you have finished modifying
50878 + the sysctl entries.
50879 +
50880 +endmenu
50881 +menu "Logging Options"
50882 +depends on GRKERNSEC
50883 +
50884 +config GRKERNSEC_FLOODTIME
50885 + int "Seconds in between log messages (minimum)"
50886 + default 10
50887 + help
50888 + This option allows you to enforce the number of seconds between
50889 + grsecurity log messages. The default should be suitable for most
50890 + people, however, if you choose to change it, choose a value small enough
50891 + to allow informative logs to be produced, but large enough to
50892 + prevent flooding.
50893 +
50894 +config GRKERNSEC_FLOODBURST
50895 + int "Number of messages in a burst (maximum)"
50896 + default 6
50897 + help
50898 + This option allows you to choose the maximum number of messages allowed
50899 + within the flood time interval you chose in a separate option. The
50900 + default should be suitable for most people, however if you find that
50901 + many of your logs are being interpreted as flooding, you may want to
50902 + raise this value.
50903 +
50904 +endmenu
50905 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50906 new file mode 100644
50907 index 0000000..1b9afa9
50908 --- /dev/null
50909 +++ b/grsecurity/Makefile
50910 @@ -0,0 +1,38 @@
50911 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50912 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50913 +# into an RBAC system
50914 +#
50915 +# All code in this directory and various hooks inserted throughout the kernel
50916 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50917 +# under the GPL v2 or higher
50918 +
50919 +KBUILD_CFLAGS += -Werror
50920 +
50921 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50922 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50923 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50924 +
50925 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50926 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50927 + gracl_learn.o grsec_log.o
50928 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50929 +
50930 +ifdef CONFIG_NET
50931 +obj-y += grsec_sock.o
50932 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50933 +endif
50934 +
50935 +ifndef CONFIG_GRKERNSEC
50936 +obj-y += grsec_disabled.o
50937 +endif
50938 +
50939 +ifdef CONFIG_GRKERNSEC_HIDESYM
50940 +extra-y := grsec_hidesym.o
50941 +$(obj)/grsec_hidesym.o:
50942 + @-chmod -f 500 /boot
50943 + @-chmod -f 500 /lib/modules
50944 + @-chmod -f 500 /lib64/modules
50945 + @-chmod -f 500 /lib32/modules
50946 + @-chmod -f 700 .
50947 + @echo ' grsec: protected kernel image paths'
50948 +endif
50949 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50950 new file mode 100644
50951 index 0000000..4480ed8
50952 --- /dev/null
50953 +++ b/grsecurity/gracl.c
50954 @@ -0,0 +1,4017 @@
50955 +#include <linux/kernel.h>
50956 +#include <linux/module.h>
50957 +#include <linux/sched.h>
50958 +#include <linux/mm.h>
50959 +#include <linux/file.h>
50960 +#include <linux/fs.h>
50961 +#include <linux/namei.h>
50962 +#include <linux/mount.h>
50963 +#include <linux/tty.h>
50964 +#include <linux/proc_fs.h>
50965 +#include <linux/lglock.h>
50966 +#include <linux/slab.h>
50967 +#include <linux/vmalloc.h>
50968 +#include <linux/types.h>
50969 +#include <linux/sysctl.h>
50970 +#include <linux/netdevice.h>
50971 +#include <linux/ptrace.h>
50972 +#include <linux/gracl.h>
50973 +#include <linux/gralloc.h>
50974 +#include <linux/security.h>
50975 +#include <linux/grinternal.h>
50976 +#include <linux/pid_namespace.h>
50977 +#include <linux/stop_machine.h>
50978 +#include <linux/fdtable.h>
50979 +#include <linux/percpu.h>
50980 +#include <linux/lglock.h>
50981 +#include "../fs/mount.h"
50982 +
50983 +#include <asm/uaccess.h>
50984 +#include <asm/errno.h>
50985 +#include <asm/mman.h>
50986 +
50987 +extern struct lglock vfsmount_lock;
50988 +
50989 +static struct acl_role_db acl_role_set;
50990 +static struct name_db name_set;
50991 +static struct inodev_db inodev_set;
50992 +
50993 +/* for keeping track of userspace pointers used for subjects, so we
50994 + can share references in the kernel as well
50995 +*/
50996 +
50997 +static struct path real_root;
50998 +
50999 +static struct acl_subj_map_db subj_map_set;
51000 +
51001 +static struct acl_role_label *default_role;
51002 +
51003 +static struct acl_role_label *role_list;
51004 +
51005 +static u16 acl_sp_role_value;
51006 +
51007 +extern char *gr_shared_page[4];
51008 +static DEFINE_MUTEX(gr_dev_mutex);
51009 +DEFINE_RWLOCK(gr_inode_lock);
51010 +
51011 +struct gr_arg *gr_usermode;
51012 +
51013 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51014 +
51015 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51016 +extern void gr_clear_learn_entries(void);
51017 +
51018 +#ifdef CONFIG_GRKERNSEC_RESLOG
51019 +extern void gr_log_resource(const struct task_struct *task,
51020 + const int res, const unsigned long wanted, const int gt);
51021 +#endif
51022 +
51023 +unsigned char *gr_system_salt;
51024 +unsigned char *gr_system_sum;
51025 +
51026 +static struct sprole_pw **acl_special_roles = NULL;
51027 +static __u16 num_sprole_pws = 0;
51028 +
51029 +static struct acl_role_label *kernel_role = NULL;
51030 +
51031 +static unsigned int gr_auth_attempts = 0;
51032 +static unsigned long gr_auth_expires = 0UL;
51033 +
51034 +#ifdef CONFIG_NET
51035 +extern struct vfsmount *sock_mnt;
51036 +#endif
51037 +
51038 +extern struct vfsmount *pipe_mnt;
51039 +extern struct vfsmount *shm_mnt;
51040 +#ifdef CONFIG_HUGETLBFS
51041 +extern struct vfsmount *hugetlbfs_vfsmount;
51042 +#endif
51043 +
51044 +static struct acl_object_label *fakefs_obj_rw;
51045 +static struct acl_object_label *fakefs_obj_rwx;
51046 +
51047 +extern int gr_init_uidset(void);
51048 +extern void gr_free_uidset(void);
51049 +extern void gr_remove_uid(uid_t uid);
51050 +extern int gr_find_uid(uid_t uid);
51051 +
51052 +__inline__ int
51053 +gr_acl_is_enabled(void)
51054 +{
51055 + return (gr_status & GR_READY);
51056 +}
51057 +
51058 +#ifdef CONFIG_BTRFS_FS
51059 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51060 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51061 +#endif
51062 +
51063 +static inline dev_t __get_dev(const struct dentry *dentry)
51064 +{
51065 +#ifdef CONFIG_BTRFS_FS
51066 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51067 + return get_btrfs_dev_from_inode(dentry->d_inode);
51068 + else
51069 +#endif
51070 + return dentry->d_inode->i_sb->s_dev;
51071 +}
51072 +
51073 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51074 +{
51075 + return __get_dev(dentry);
51076 +}
51077 +
51078 +static char gr_task_roletype_to_char(struct task_struct *task)
51079 +{
51080 + switch (task->role->roletype &
51081 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51082 + GR_ROLE_SPECIAL)) {
51083 + case GR_ROLE_DEFAULT:
51084 + return 'D';
51085 + case GR_ROLE_USER:
51086 + return 'U';
51087 + case GR_ROLE_GROUP:
51088 + return 'G';
51089 + case GR_ROLE_SPECIAL:
51090 + return 'S';
51091 + }
51092 +
51093 + return 'X';
51094 +}
51095 +
51096 +char gr_roletype_to_char(void)
51097 +{
51098 + return gr_task_roletype_to_char(current);
51099 +}
51100 +
51101 +__inline__ int
51102 +gr_acl_tpe_check(void)
51103 +{
51104 + if (unlikely(!(gr_status & GR_READY)))
51105 + return 0;
51106 + if (current->role->roletype & GR_ROLE_TPE)
51107 + return 1;
51108 + else
51109 + return 0;
51110 +}
51111 +
51112 +int
51113 +gr_handle_rawio(const struct inode *inode)
51114 +{
51115 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51116 + if (inode && S_ISBLK(inode->i_mode) &&
51117 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51118 + !capable(CAP_SYS_RAWIO))
51119 + return 1;
51120 +#endif
51121 + return 0;
51122 +}
51123 +
51124 +static int
51125 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51126 +{
51127 + if (likely(lena != lenb))
51128 + return 0;
51129 +
51130 + return !memcmp(a, b, lena);
51131 +}
51132 +
51133 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51134 +{
51135 + *buflen -= namelen;
51136 + if (*buflen < 0)
51137 + return -ENAMETOOLONG;
51138 + *buffer -= namelen;
51139 + memcpy(*buffer, str, namelen);
51140 + return 0;
51141 +}
51142 +
51143 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51144 +{
51145 + return prepend(buffer, buflen, name->name, name->len);
51146 +}
51147 +
51148 +static int prepend_path(const struct path *path, struct path *root,
51149 + char **buffer, int *buflen)
51150 +{
51151 + struct dentry *dentry = path->dentry;
51152 + struct vfsmount *vfsmnt = path->mnt;
51153 + struct mount *mnt = real_mount(vfsmnt);
51154 + bool slash = false;
51155 + int error = 0;
51156 +
51157 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51158 + struct dentry * parent;
51159 +
51160 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51161 + /* Global root? */
51162 + if (!mnt_has_parent(mnt)) {
51163 + goto out;
51164 + }
51165 + dentry = mnt->mnt_mountpoint;
51166 + mnt = mnt->mnt_parent;
51167 + vfsmnt = &mnt->mnt;
51168 + continue;
51169 + }
51170 + parent = dentry->d_parent;
51171 + prefetch(parent);
51172 + spin_lock(&dentry->d_lock);
51173 + error = prepend_name(buffer, buflen, &dentry->d_name);
51174 + spin_unlock(&dentry->d_lock);
51175 + if (!error)
51176 + error = prepend(buffer, buflen, "/", 1);
51177 + if (error)
51178 + break;
51179 +
51180 + slash = true;
51181 + dentry = parent;
51182 + }
51183 +
51184 +out:
51185 + if (!error && !slash)
51186 + error = prepend(buffer, buflen, "/", 1);
51187 +
51188 + return error;
51189 +}
51190 +
51191 +/* this must be called with vfsmount_lock and rename_lock held */
51192 +
51193 +static char *__our_d_path(const struct path *path, struct path *root,
51194 + char *buf, int buflen)
51195 +{
51196 + char *res = buf + buflen;
51197 + int error;
51198 +
51199 + prepend(&res, &buflen, "\0", 1);
51200 + error = prepend_path(path, root, &res, &buflen);
51201 + if (error)
51202 + return ERR_PTR(error);
51203 +
51204 + return res;
51205 +}
51206 +
51207 +static char *
51208 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51209 +{
51210 + char *retval;
51211 +
51212 + retval = __our_d_path(path, root, buf, buflen);
51213 + if (unlikely(IS_ERR(retval)))
51214 + retval = strcpy(buf, "<path too long>");
51215 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51216 + retval[1] = '\0';
51217 +
51218 + return retval;
51219 +}
51220 +
51221 +static char *
51222 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51223 + char *buf, int buflen)
51224 +{
51225 + struct path path;
51226 + char *res;
51227 +
51228 + path.dentry = (struct dentry *)dentry;
51229 + path.mnt = (struct vfsmount *)vfsmnt;
51230 +
51231 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51232 + by the RBAC system */
51233 + res = gen_full_path(&path, &real_root, buf, buflen);
51234 +
51235 + return res;
51236 +}
51237 +
51238 +static char *
51239 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51240 + char *buf, int buflen)
51241 +{
51242 + char *res;
51243 + struct path path;
51244 + struct path root;
51245 + struct task_struct *reaper = init_pid_ns.child_reaper;
51246 +
51247 + path.dentry = (struct dentry *)dentry;
51248 + path.mnt = (struct vfsmount *)vfsmnt;
51249 +
51250 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51251 + get_fs_root(reaper->fs, &root);
51252 +
51253 + write_seqlock(&rename_lock);
51254 + br_read_lock(&vfsmount_lock);
51255 + res = gen_full_path(&path, &root, buf, buflen);
51256 + br_read_unlock(&vfsmount_lock);
51257 + write_sequnlock(&rename_lock);
51258 +
51259 + path_put(&root);
51260 + return res;
51261 +}
51262 +
51263 +static char *
51264 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51265 +{
51266 + char *ret;
51267 + write_seqlock(&rename_lock);
51268 + br_read_lock(&vfsmount_lock);
51269 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51270 + PAGE_SIZE);
51271 + br_read_unlock(&vfsmount_lock);
51272 + write_sequnlock(&rename_lock);
51273 + return ret;
51274 +}
51275 +
51276 +static char *
51277 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51278 +{
51279 + char *ret;
51280 + char *buf;
51281 + int buflen;
51282 +
51283 + write_seqlock(&rename_lock);
51284 + br_read_lock(&vfsmount_lock);
51285 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51286 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51287 + buflen = (int)(ret - buf);
51288 + if (buflen >= 5)
51289 + prepend(&ret, &buflen, "/proc", 5);
51290 + else
51291 + ret = strcpy(buf, "<path too long>");
51292 + br_read_unlock(&vfsmount_lock);
51293 + write_sequnlock(&rename_lock);
51294 + return ret;
51295 +}
51296 +
51297 +char *
51298 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51299 +{
51300 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51301 + PAGE_SIZE);
51302 +}
51303 +
51304 +char *
51305 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51306 +{
51307 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51308 + PAGE_SIZE);
51309 +}
51310 +
51311 +char *
51312 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51313 +{
51314 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51315 + PAGE_SIZE);
51316 +}
51317 +
51318 +char *
51319 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51320 +{
51321 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51322 + PAGE_SIZE);
51323 +}
51324 +
51325 +char *
51326 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51327 +{
51328 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51329 + PAGE_SIZE);
51330 +}
51331 +
51332 +__inline__ __u32
51333 +to_gr_audit(const __u32 reqmode)
51334 +{
51335 + /* masks off auditable permission flags, then shifts them to create
51336 + auditing flags, and adds the special case of append auditing if
51337 + we're requesting write */
51338 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51339 +}
51340 +
51341 +struct acl_subject_label *
51342 +lookup_subject_map(const struct acl_subject_label *userp)
51343 +{
51344 + unsigned int index = shash(userp, subj_map_set.s_size);
51345 + struct subject_map *match;
51346 +
51347 + match = subj_map_set.s_hash[index];
51348 +
51349 + while (match && match->user != userp)
51350 + match = match->next;
51351 +
51352 + if (match != NULL)
51353 + return match->kernel;
51354 + else
51355 + return NULL;
51356 +}
51357 +
51358 +static void
51359 +insert_subj_map_entry(struct subject_map *subjmap)
51360 +{
51361 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51362 + struct subject_map **curr;
51363 +
51364 + subjmap->prev = NULL;
51365 +
51366 + curr = &subj_map_set.s_hash[index];
51367 + if (*curr != NULL)
51368 + (*curr)->prev = subjmap;
51369 +
51370 + subjmap->next = *curr;
51371 + *curr = subjmap;
51372 +
51373 + return;
51374 +}
51375 +
51376 +static struct acl_role_label *
51377 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51378 + const gid_t gid)
51379 +{
51380 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51381 + struct acl_role_label *match;
51382 + struct role_allowed_ip *ipp;
51383 + unsigned int x;
51384 + u32 curr_ip = task->signal->curr_ip;
51385 +
51386 + task->signal->saved_ip = curr_ip;
51387 +
51388 + match = acl_role_set.r_hash[index];
51389 +
51390 + while (match) {
51391 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51392 + for (x = 0; x < match->domain_child_num; x++) {
51393 + if (match->domain_children[x] == uid)
51394 + goto found;
51395 + }
51396 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51397 + break;
51398 + match = match->next;
51399 + }
51400 +found:
51401 + if (match == NULL) {
51402 + try_group:
51403 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51404 + match = acl_role_set.r_hash[index];
51405 +
51406 + while (match) {
51407 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51408 + for (x = 0; x < match->domain_child_num; x++) {
51409 + if (match->domain_children[x] == gid)
51410 + goto found2;
51411 + }
51412 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51413 + break;
51414 + match = match->next;
51415 + }
51416 +found2:
51417 + if (match == NULL)
51418 + match = default_role;
51419 + if (match->allowed_ips == NULL)
51420 + return match;
51421 + else {
51422 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51423 + if (likely
51424 + ((ntohl(curr_ip) & ipp->netmask) ==
51425 + (ntohl(ipp->addr) & ipp->netmask)))
51426 + return match;
51427 + }
51428 + match = default_role;
51429 + }
51430 + } else if (match->allowed_ips == NULL) {
51431 + return match;
51432 + } else {
51433 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51434 + if (likely
51435 + ((ntohl(curr_ip) & ipp->netmask) ==
51436 + (ntohl(ipp->addr) & ipp->netmask)))
51437 + return match;
51438 + }
51439 + goto try_group;
51440 + }
51441 +
51442 + return match;
51443 +}
51444 +
51445 +struct acl_subject_label *
51446 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51447 + const struct acl_role_label *role)
51448 +{
51449 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51450 + struct acl_subject_label *match;
51451 +
51452 + match = role->subj_hash[index];
51453 +
51454 + while (match && (match->inode != ino || match->device != dev ||
51455 + (match->mode & GR_DELETED))) {
51456 + match = match->next;
51457 + }
51458 +
51459 + if (match && !(match->mode & GR_DELETED))
51460 + return match;
51461 + else
51462 + return NULL;
51463 +}
51464 +
51465 +struct acl_subject_label *
51466 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51467 + const struct acl_role_label *role)
51468 +{
51469 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51470 + struct acl_subject_label *match;
51471 +
51472 + match = role->subj_hash[index];
51473 +
51474 + while (match && (match->inode != ino || match->device != dev ||
51475 + !(match->mode & GR_DELETED))) {
51476 + match = match->next;
51477 + }
51478 +
51479 + if (match && (match->mode & GR_DELETED))
51480 + return match;
51481 + else
51482 + return NULL;
51483 +}
51484 +
51485 +static struct acl_object_label *
51486 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51487 + const struct acl_subject_label *subj)
51488 +{
51489 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51490 + struct acl_object_label *match;
51491 +
51492 + match = subj->obj_hash[index];
51493 +
51494 + while (match && (match->inode != ino || match->device != dev ||
51495 + (match->mode & GR_DELETED))) {
51496 + match = match->next;
51497 + }
51498 +
51499 + if (match && !(match->mode & GR_DELETED))
51500 + return match;
51501 + else
51502 + return NULL;
51503 +}
51504 +
51505 +static struct acl_object_label *
51506 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51507 + const struct acl_subject_label *subj)
51508 +{
51509 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51510 + struct acl_object_label *match;
51511 +
51512 + match = subj->obj_hash[index];
51513 +
51514 + while (match && (match->inode != ino || match->device != dev ||
51515 + !(match->mode & GR_DELETED))) {
51516 + match = match->next;
51517 + }
51518 +
51519 + if (match && (match->mode & GR_DELETED))
51520 + return match;
51521 +
51522 + match = subj->obj_hash[index];
51523 +
51524 + while (match && (match->inode != ino || match->device != dev ||
51525 + (match->mode & GR_DELETED))) {
51526 + match = match->next;
51527 + }
51528 +
51529 + if (match && !(match->mode & GR_DELETED))
51530 + return match;
51531 + else
51532 + return NULL;
51533 +}
51534 +
51535 +static struct name_entry *
51536 +lookup_name_entry(const char *name)
51537 +{
51538 + unsigned int len = strlen(name);
51539 + unsigned int key = full_name_hash(name, len);
51540 + unsigned int index = key % name_set.n_size;
51541 + struct name_entry *match;
51542 +
51543 + match = name_set.n_hash[index];
51544 +
51545 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51546 + match = match->next;
51547 +
51548 + return match;
51549 +}
51550 +
51551 +static struct name_entry *
51552 +lookup_name_entry_create(const char *name)
51553 +{
51554 + unsigned int len = strlen(name);
51555 + unsigned int key = full_name_hash(name, len);
51556 + unsigned int index = key % name_set.n_size;
51557 + struct name_entry *match;
51558 +
51559 + match = name_set.n_hash[index];
51560 +
51561 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51562 + !match->deleted))
51563 + match = match->next;
51564 +
51565 + if (match && match->deleted)
51566 + return match;
51567 +
51568 + match = name_set.n_hash[index];
51569 +
51570 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51571 + match->deleted))
51572 + match = match->next;
51573 +
51574 + if (match && !match->deleted)
51575 + return match;
51576 + else
51577 + return NULL;
51578 +}
51579 +
51580 +static struct inodev_entry *
51581 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51582 +{
51583 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51584 + struct inodev_entry *match;
51585 +
51586 + match = inodev_set.i_hash[index];
51587 +
51588 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51589 + match = match->next;
51590 +
51591 + return match;
51592 +}
51593 +
51594 +static void
51595 +insert_inodev_entry(struct inodev_entry *entry)
51596 +{
51597 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51598 + inodev_set.i_size);
51599 + struct inodev_entry **curr;
51600 +
51601 + entry->prev = NULL;
51602 +
51603 + curr = &inodev_set.i_hash[index];
51604 + if (*curr != NULL)
51605 + (*curr)->prev = entry;
51606 +
51607 + entry->next = *curr;
51608 + *curr = entry;
51609 +
51610 + return;
51611 +}
51612 +
51613 +static void
51614 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51615 +{
51616 + unsigned int index =
51617 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51618 + struct acl_role_label **curr;
51619 + struct acl_role_label *tmp, *tmp2;
51620 +
51621 + curr = &acl_role_set.r_hash[index];
51622 +
51623 + /* simple case, slot is empty, just set it to our role */
51624 + if (*curr == NULL) {
51625 + *curr = role;
51626 + } else {
51627 + /* example:
51628 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51629 + 2 -> 3
51630 + */
51631 + /* first check to see if we can already be reached via this slot */
51632 + tmp = *curr;
51633 + while (tmp && tmp != role)
51634 + tmp = tmp->next;
51635 + if (tmp == role) {
51636 + /* we don't need to add ourselves to this slot's chain */
51637 + return;
51638 + }
51639 + /* we need to add ourselves to this chain, two cases */
51640 + if (role->next == NULL) {
51641 + /* simple case, append the current chain to our role */
51642 + role->next = *curr;
51643 + *curr = role;
51644 + } else {
51645 + /* 1 -> 2 -> 3 -> 4
51646 + 2 -> 3 -> 4
51647 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51648 + */
51649 + /* trickier case: walk our role's chain until we find
51650 + the role for the start of the current slot's chain */
51651 + tmp = role;
51652 + tmp2 = *curr;
51653 + while (tmp->next && tmp->next != tmp2)
51654 + tmp = tmp->next;
51655 + if (tmp->next == tmp2) {
51656 + /* from example above, we found 3, so just
51657 + replace this slot's chain with ours */
51658 + *curr = role;
51659 + } else {
51660 + /* we didn't find a subset of our role's chain
51661 + in the current slot's chain, so append their
51662 + chain to ours, and set us as the first role in
51663 + the slot's chain
51664 +
51665 + we could fold this case with the case above,
51666 + but making it explicit for clarity
51667 + */
51668 + tmp->next = tmp2;
51669 + *curr = role;
51670 + }
51671 + }
51672 + }
51673 +
51674 + return;
51675 +}
51676 +
51677 +static void
51678 +insert_acl_role_label(struct acl_role_label *role)
51679 +{
51680 + int i;
51681 +
51682 + if (role_list == NULL) {
51683 + role_list = role;
51684 + role->prev = NULL;
51685 + } else {
51686 + role->prev = role_list;
51687 + role_list = role;
51688 + }
51689 +
51690 + /* used for hash chains */
51691 + role->next = NULL;
51692 +
51693 + if (role->roletype & GR_ROLE_DOMAIN) {
51694 + for (i = 0; i < role->domain_child_num; i++)
51695 + __insert_acl_role_label(role, role->domain_children[i]);
51696 + } else
51697 + __insert_acl_role_label(role, role->uidgid);
51698 +}
51699 +
51700 +static int
51701 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51702 +{
51703 + struct name_entry **curr, *nentry;
51704 + struct inodev_entry *ientry;
51705 + unsigned int len = strlen(name);
51706 + unsigned int key = full_name_hash(name, len);
51707 + unsigned int index = key % name_set.n_size;
51708 +
51709 + curr = &name_set.n_hash[index];
51710 +
51711 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51712 + curr = &((*curr)->next);
51713 +
51714 + if (*curr != NULL)
51715 + return 1;
51716 +
51717 + nentry = acl_alloc(sizeof (struct name_entry));
51718 + if (nentry == NULL)
51719 + return 0;
51720 + ientry = acl_alloc(sizeof (struct inodev_entry));
51721 + if (ientry == NULL)
51722 + return 0;
51723 + ientry->nentry = nentry;
51724 +
51725 + nentry->key = key;
51726 + nentry->name = name;
51727 + nentry->inode = inode;
51728 + nentry->device = device;
51729 + nentry->len = len;
51730 + nentry->deleted = deleted;
51731 +
51732 + nentry->prev = NULL;
51733 + curr = &name_set.n_hash[index];
51734 + if (*curr != NULL)
51735 + (*curr)->prev = nentry;
51736 + nentry->next = *curr;
51737 + *curr = nentry;
51738 +
51739 + /* insert us into the table searchable by inode/dev */
51740 + insert_inodev_entry(ientry);
51741 +
51742 + return 1;
51743 +}
51744 +
51745 +static void
51746 +insert_acl_obj_label(struct acl_object_label *obj,
51747 + struct acl_subject_label *subj)
51748 +{
51749 + unsigned int index =
51750 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51751 + struct acl_object_label **curr;
51752 +
51753 +
51754 + obj->prev = NULL;
51755 +
51756 + curr = &subj->obj_hash[index];
51757 + if (*curr != NULL)
51758 + (*curr)->prev = obj;
51759 +
51760 + obj->next = *curr;
51761 + *curr = obj;
51762 +
51763 + return;
51764 +}
51765 +
51766 +static void
51767 +insert_acl_subj_label(struct acl_subject_label *obj,
51768 + struct acl_role_label *role)
51769 +{
51770 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51771 + struct acl_subject_label **curr;
51772 +
51773 + obj->prev = NULL;
51774 +
51775 + curr = &role->subj_hash[index];
51776 + if (*curr != NULL)
51777 + (*curr)->prev = obj;
51778 +
51779 + obj->next = *curr;
51780 + *curr = obj;
51781 +
51782 + return;
51783 +}
51784 +
51785 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51786 +
51787 +static void *
51788 +create_table(__u32 * len, int elementsize)
51789 +{
51790 + unsigned int table_sizes[] = {
51791 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51792 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51793 + 4194301, 8388593, 16777213, 33554393, 67108859
51794 + };
51795 + void *newtable = NULL;
51796 + unsigned int pwr = 0;
51797 +
51798 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51799 + table_sizes[pwr] <= *len)
51800 + pwr++;
51801 +
51802 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51803 + return newtable;
51804 +
51805 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51806 + newtable =
51807 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51808 + else
51809 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51810 +
51811 + *len = table_sizes[pwr];
51812 +
51813 + return newtable;
51814 +}
51815 +
51816 +static int
51817 +init_variables(const struct gr_arg *arg)
51818 +{
51819 + struct task_struct *reaper = init_pid_ns.child_reaper;
51820 + unsigned int stacksize;
51821 +
51822 + subj_map_set.s_size = arg->role_db.num_subjects;
51823 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51824 + name_set.n_size = arg->role_db.num_objects;
51825 + inodev_set.i_size = arg->role_db.num_objects;
51826 +
51827 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51828 + !name_set.n_size || !inodev_set.i_size)
51829 + return 1;
51830 +
51831 + if (!gr_init_uidset())
51832 + return 1;
51833 +
51834 + /* set up the stack that holds allocation info */
51835 +
51836 + stacksize = arg->role_db.num_pointers + 5;
51837 +
51838 + if (!acl_alloc_stack_init(stacksize))
51839 + return 1;
51840 +
51841 + /* grab reference for the real root dentry and vfsmount */
51842 + get_fs_root(reaper->fs, &real_root);
51843 +
51844 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51845 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51846 +#endif
51847 +
51848 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51849 + if (fakefs_obj_rw == NULL)
51850 + return 1;
51851 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51852 +
51853 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51854 + if (fakefs_obj_rwx == NULL)
51855 + return 1;
51856 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51857 +
51858 + subj_map_set.s_hash =
51859 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51860 + acl_role_set.r_hash =
51861 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51862 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51863 + inodev_set.i_hash =
51864 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51865 +
51866 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51867 + !name_set.n_hash || !inodev_set.i_hash)
51868 + return 1;
51869 +
51870 + memset(subj_map_set.s_hash, 0,
51871 + sizeof(struct subject_map *) * subj_map_set.s_size);
51872 + memset(acl_role_set.r_hash, 0,
51873 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51874 + memset(name_set.n_hash, 0,
51875 + sizeof (struct name_entry *) * name_set.n_size);
51876 + memset(inodev_set.i_hash, 0,
51877 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51878 +
51879 + return 0;
51880 +}
51881 +
51882 +/* free information not needed after startup
51883 + currently contains user->kernel pointer mappings for subjects
51884 +*/
51885 +
51886 +static void
51887 +free_init_variables(void)
51888 +{
51889 + __u32 i;
51890 +
51891 + if (subj_map_set.s_hash) {
51892 + for (i = 0; i < subj_map_set.s_size; i++) {
51893 + if (subj_map_set.s_hash[i]) {
51894 + kfree(subj_map_set.s_hash[i]);
51895 + subj_map_set.s_hash[i] = NULL;
51896 + }
51897 + }
51898 +
51899 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51900 + PAGE_SIZE)
51901 + kfree(subj_map_set.s_hash);
51902 + else
51903 + vfree(subj_map_set.s_hash);
51904 + }
51905 +
51906 + return;
51907 +}
51908 +
51909 +static void
51910 +free_variables(void)
51911 +{
51912 + struct acl_subject_label *s;
51913 + struct acl_role_label *r;
51914 + struct task_struct *task, *task2;
51915 + unsigned int x;
51916 +
51917 + gr_clear_learn_entries();
51918 +
51919 + read_lock(&tasklist_lock);
51920 + do_each_thread(task2, task) {
51921 + task->acl_sp_role = 0;
51922 + task->acl_role_id = 0;
51923 + task->acl = NULL;
51924 + task->role = NULL;
51925 + } while_each_thread(task2, task);
51926 + read_unlock(&tasklist_lock);
51927 +
51928 + /* release the reference to the real root dentry and vfsmount */
51929 + path_put(&real_root);
51930 + memset(&real_root, 0, sizeof(real_root));
51931 +
51932 + /* free all object hash tables */
51933 +
51934 + FOR_EACH_ROLE_START(r)
51935 + if (r->subj_hash == NULL)
51936 + goto next_role;
51937 + FOR_EACH_SUBJECT_START(r, s, x)
51938 + if (s->obj_hash == NULL)
51939 + break;
51940 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51941 + kfree(s->obj_hash);
51942 + else
51943 + vfree(s->obj_hash);
51944 + FOR_EACH_SUBJECT_END(s, x)
51945 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51946 + if (s->obj_hash == NULL)
51947 + break;
51948 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51949 + kfree(s->obj_hash);
51950 + else
51951 + vfree(s->obj_hash);
51952 + FOR_EACH_NESTED_SUBJECT_END(s)
51953 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51954 + kfree(r->subj_hash);
51955 + else
51956 + vfree(r->subj_hash);
51957 + r->subj_hash = NULL;
51958 +next_role:
51959 + FOR_EACH_ROLE_END(r)
51960 +
51961 + acl_free_all();
51962 +
51963 + if (acl_role_set.r_hash) {
51964 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51965 + PAGE_SIZE)
51966 + kfree(acl_role_set.r_hash);
51967 + else
51968 + vfree(acl_role_set.r_hash);
51969 + }
51970 + if (name_set.n_hash) {
51971 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51972 + PAGE_SIZE)
51973 + kfree(name_set.n_hash);
51974 + else
51975 + vfree(name_set.n_hash);
51976 + }
51977 +
51978 + if (inodev_set.i_hash) {
51979 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51980 + PAGE_SIZE)
51981 + kfree(inodev_set.i_hash);
51982 + else
51983 + vfree(inodev_set.i_hash);
51984 + }
51985 +
51986 + gr_free_uidset();
51987 +
51988 + memset(&name_set, 0, sizeof (struct name_db));
51989 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51990 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51991 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51992 +
51993 + default_role = NULL;
51994 + kernel_role = NULL;
51995 + role_list = NULL;
51996 +
51997 + return;
51998 +}
51999 +
52000 +static __u32
52001 +count_user_objs(struct acl_object_label *userp)
52002 +{
52003 + struct acl_object_label o_tmp;
52004 + __u32 num = 0;
52005 +
52006 + while (userp) {
52007 + if (copy_from_user(&o_tmp, userp,
52008 + sizeof (struct acl_object_label)))
52009 + break;
52010 +
52011 + userp = o_tmp.prev;
52012 + num++;
52013 + }
52014 +
52015 + return num;
52016 +}
52017 +
52018 +static struct acl_subject_label *
52019 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52020 +
52021 +static int
52022 +copy_user_glob(struct acl_object_label *obj)
52023 +{
52024 + struct acl_object_label *g_tmp, **guser;
52025 + unsigned int len;
52026 + char *tmp;
52027 +
52028 + if (obj->globbed == NULL)
52029 + return 0;
52030 +
52031 + guser = &obj->globbed;
52032 + while (*guser) {
52033 + g_tmp = (struct acl_object_label *)
52034 + acl_alloc(sizeof (struct acl_object_label));
52035 + if (g_tmp == NULL)
52036 + return -ENOMEM;
52037 +
52038 + if (copy_from_user(g_tmp, *guser,
52039 + sizeof (struct acl_object_label)))
52040 + return -EFAULT;
52041 +
52042 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52043 +
52044 + if (!len || len >= PATH_MAX)
52045 + return -EINVAL;
52046 +
52047 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52048 + return -ENOMEM;
52049 +
52050 + if (copy_from_user(tmp, g_tmp->filename, len))
52051 + return -EFAULT;
52052 + tmp[len-1] = '\0';
52053 + g_tmp->filename = tmp;
52054 +
52055 + *guser = g_tmp;
52056 + guser = &(g_tmp->next);
52057 + }
52058 +
52059 + return 0;
52060 +}
52061 +
52062 +static int
52063 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52064 + struct acl_role_label *role)
52065 +{
52066 + struct acl_object_label *o_tmp;
52067 + unsigned int len;
52068 + int ret;
52069 + char *tmp;
52070 +
52071 + while (userp) {
52072 + if ((o_tmp = (struct acl_object_label *)
52073 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52074 + return -ENOMEM;
52075 +
52076 + if (copy_from_user(o_tmp, userp,
52077 + sizeof (struct acl_object_label)))
52078 + return -EFAULT;
52079 +
52080 + userp = o_tmp->prev;
52081 +
52082 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52083 +
52084 + if (!len || len >= PATH_MAX)
52085 + return -EINVAL;
52086 +
52087 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52088 + return -ENOMEM;
52089 +
52090 + if (copy_from_user(tmp, o_tmp->filename, len))
52091 + return -EFAULT;
52092 + tmp[len-1] = '\0';
52093 + o_tmp->filename = tmp;
52094 +
52095 + insert_acl_obj_label(o_tmp, subj);
52096 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52097 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52098 + return -ENOMEM;
52099 +
52100 + ret = copy_user_glob(o_tmp);
52101 + if (ret)
52102 + return ret;
52103 +
52104 + if (o_tmp->nested) {
52105 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52106 + if (IS_ERR(o_tmp->nested))
52107 + return PTR_ERR(o_tmp->nested);
52108 +
52109 + /* insert into nested subject list */
52110 + o_tmp->nested->next = role->hash->first;
52111 + role->hash->first = o_tmp->nested;
52112 + }
52113 + }
52114 +
52115 + return 0;
52116 +}
52117 +
52118 +static __u32
52119 +count_user_subjs(struct acl_subject_label *userp)
52120 +{
52121 + struct acl_subject_label s_tmp;
52122 + __u32 num = 0;
52123 +
52124 + while (userp) {
52125 + if (copy_from_user(&s_tmp, userp,
52126 + sizeof (struct acl_subject_label)))
52127 + break;
52128 +
52129 + userp = s_tmp.prev;
52130 + /* do not count nested subjects against this count, since
52131 + they are not included in the hash table, but are
52132 + attached to objects. We have already counted
52133 + the subjects in userspace for the allocation
52134 + stack
52135 + */
52136 + if (!(s_tmp.mode & GR_NESTED))
52137 + num++;
52138 + }
52139 +
52140 + return num;
52141 +}
52142 +
52143 +static int
52144 +copy_user_allowedips(struct acl_role_label *rolep)
52145 +{
52146 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52147 +
52148 + ruserip = rolep->allowed_ips;
52149 +
52150 + while (ruserip) {
52151 + rlast = rtmp;
52152 +
52153 + if ((rtmp = (struct role_allowed_ip *)
52154 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52155 + return -ENOMEM;
52156 +
52157 + if (copy_from_user(rtmp, ruserip,
52158 + sizeof (struct role_allowed_ip)))
52159 + return -EFAULT;
52160 +
52161 + ruserip = rtmp->prev;
52162 +
52163 + if (!rlast) {
52164 + rtmp->prev = NULL;
52165 + rolep->allowed_ips = rtmp;
52166 + } else {
52167 + rlast->next = rtmp;
52168 + rtmp->prev = rlast;
52169 + }
52170 +
52171 + if (!ruserip)
52172 + rtmp->next = NULL;
52173 + }
52174 +
52175 + return 0;
52176 +}
52177 +
52178 +static int
52179 +copy_user_transitions(struct acl_role_label *rolep)
52180 +{
52181 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52182 +
52183 + unsigned int len;
52184 + char *tmp;
52185 +
52186 + rusertp = rolep->transitions;
52187 +
52188 + while (rusertp) {
52189 + rlast = rtmp;
52190 +
52191 + if ((rtmp = (struct role_transition *)
52192 + acl_alloc(sizeof (struct role_transition))) == NULL)
52193 + return -ENOMEM;
52194 +
52195 + if (copy_from_user(rtmp, rusertp,
52196 + sizeof (struct role_transition)))
52197 + return -EFAULT;
52198 +
52199 + rusertp = rtmp->prev;
52200 +
52201 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52202 +
52203 + if (!len || len >= GR_SPROLE_LEN)
52204 + return -EINVAL;
52205 +
52206 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52207 + return -ENOMEM;
52208 +
52209 + if (copy_from_user(tmp, rtmp->rolename, len))
52210 + return -EFAULT;
52211 + tmp[len-1] = '\0';
52212 + rtmp->rolename = tmp;
52213 +
52214 + if (!rlast) {
52215 + rtmp->prev = NULL;
52216 + rolep->transitions = rtmp;
52217 + } else {
52218 + rlast->next = rtmp;
52219 + rtmp->prev = rlast;
52220 + }
52221 +
52222 + if (!rusertp)
52223 + rtmp->next = NULL;
52224 + }
52225 +
52226 + return 0;
52227 +}
52228 +
52229 +static struct acl_subject_label *
52230 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52231 +{
52232 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52233 + unsigned int len;
52234 + char *tmp;
52235 + __u32 num_objs;
52236 + struct acl_ip_label **i_tmp, *i_utmp2;
52237 + struct gr_hash_struct ghash;
52238 + struct subject_map *subjmap;
52239 + unsigned int i_num;
52240 + int err;
52241 +
52242 + s_tmp = lookup_subject_map(userp);
52243 +
52244 + /* we've already copied this subject into the kernel, just return
52245 + the reference to it, and don't copy it over again
52246 + */
52247 + if (s_tmp)
52248 + return(s_tmp);
52249 +
52250 + if ((s_tmp = (struct acl_subject_label *)
52251 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52252 + return ERR_PTR(-ENOMEM);
52253 +
52254 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52255 + if (subjmap == NULL)
52256 + return ERR_PTR(-ENOMEM);
52257 +
52258 + subjmap->user = userp;
52259 + subjmap->kernel = s_tmp;
52260 + insert_subj_map_entry(subjmap);
52261 +
52262 + if (copy_from_user(s_tmp, userp,
52263 + sizeof (struct acl_subject_label)))
52264 + return ERR_PTR(-EFAULT);
52265 +
52266 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52267 +
52268 + if (!len || len >= PATH_MAX)
52269 + return ERR_PTR(-EINVAL);
52270 +
52271 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52272 + return ERR_PTR(-ENOMEM);
52273 +
52274 + if (copy_from_user(tmp, s_tmp->filename, len))
52275 + return ERR_PTR(-EFAULT);
52276 + tmp[len-1] = '\0';
52277 + s_tmp->filename = tmp;
52278 +
52279 + if (!strcmp(s_tmp->filename, "/"))
52280 + role->root_label = s_tmp;
52281 +
52282 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52283 + return ERR_PTR(-EFAULT);
52284 +
52285 + /* copy user and group transition tables */
52286 +
52287 + if (s_tmp->user_trans_num) {
52288 + uid_t *uidlist;
52289 +
52290 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52291 + if (uidlist == NULL)
52292 + return ERR_PTR(-ENOMEM);
52293 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52294 + return ERR_PTR(-EFAULT);
52295 +
52296 + s_tmp->user_transitions = uidlist;
52297 + }
52298 +
52299 + if (s_tmp->group_trans_num) {
52300 + gid_t *gidlist;
52301 +
52302 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52303 + if (gidlist == NULL)
52304 + return ERR_PTR(-ENOMEM);
52305 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52306 + return ERR_PTR(-EFAULT);
52307 +
52308 + s_tmp->group_transitions = gidlist;
52309 + }
52310 +
52311 + /* set up object hash table */
52312 + num_objs = count_user_objs(ghash.first);
52313 +
52314 + s_tmp->obj_hash_size = num_objs;
52315 + s_tmp->obj_hash =
52316 + (struct acl_object_label **)
52317 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52318 +
52319 + if (!s_tmp->obj_hash)
52320 + return ERR_PTR(-ENOMEM);
52321 +
52322 + memset(s_tmp->obj_hash, 0,
52323 + s_tmp->obj_hash_size *
52324 + sizeof (struct acl_object_label *));
52325 +
52326 + /* add in objects */
52327 + err = copy_user_objs(ghash.first, s_tmp, role);
52328 +
52329 + if (err)
52330 + return ERR_PTR(err);
52331 +
52332 + /* set pointer for parent subject */
52333 + if (s_tmp->parent_subject) {
52334 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52335 +
52336 + if (IS_ERR(s_tmp2))
52337 + return s_tmp2;
52338 +
52339 + s_tmp->parent_subject = s_tmp2;
52340 + }
52341 +
52342 + /* add in ip acls */
52343 +
52344 + if (!s_tmp->ip_num) {
52345 + s_tmp->ips = NULL;
52346 + goto insert;
52347 + }
52348 +
52349 + i_tmp =
52350 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52351 + sizeof (struct acl_ip_label *));
52352 +
52353 + if (!i_tmp)
52354 + return ERR_PTR(-ENOMEM);
52355 +
52356 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52357 + *(i_tmp + i_num) =
52358 + (struct acl_ip_label *)
52359 + acl_alloc(sizeof (struct acl_ip_label));
52360 + if (!*(i_tmp + i_num))
52361 + return ERR_PTR(-ENOMEM);
52362 +
52363 + if (copy_from_user
52364 + (&i_utmp2, s_tmp->ips + i_num,
52365 + sizeof (struct acl_ip_label *)))
52366 + return ERR_PTR(-EFAULT);
52367 +
52368 + if (copy_from_user
52369 + (*(i_tmp + i_num), i_utmp2,
52370 + sizeof (struct acl_ip_label)))
52371 + return ERR_PTR(-EFAULT);
52372 +
52373 + if ((*(i_tmp + i_num))->iface == NULL)
52374 + continue;
52375 +
52376 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52377 + if (!len || len >= IFNAMSIZ)
52378 + return ERR_PTR(-EINVAL);
52379 + tmp = acl_alloc(len);
52380 + if (tmp == NULL)
52381 + return ERR_PTR(-ENOMEM);
52382 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52383 + return ERR_PTR(-EFAULT);
52384 + (*(i_tmp + i_num))->iface = tmp;
52385 + }
52386 +
52387 + s_tmp->ips = i_tmp;
52388 +
52389 +insert:
52390 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52391 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52392 + return ERR_PTR(-ENOMEM);
52393 +
52394 + return s_tmp;
52395 +}
52396 +
52397 +static int
52398 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52399 +{
52400 + struct acl_subject_label s_pre;
52401 + struct acl_subject_label * ret;
52402 + int err;
52403 +
52404 + while (userp) {
52405 + if (copy_from_user(&s_pre, userp,
52406 + sizeof (struct acl_subject_label)))
52407 + return -EFAULT;
52408 +
52409 + /* do not add nested subjects here, add
52410 + while parsing objects
52411 + */
52412 +
52413 + if (s_pre.mode & GR_NESTED) {
52414 + userp = s_pre.prev;
52415 + continue;
52416 + }
52417 +
52418 + ret = do_copy_user_subj(userp, role);
52419 +
52420 + err = PTR_ERR(ret);
52421 + if (IS_ERR(ret))
52422 + return err;
52423 +
52424 + insert_acl_subj_label(ret, role);
52425 +
52426 + userp = s_pre.prev;
52427 + }
52428 +
52429 + return 0;
52430 +}
52431 +
52432 +static int
52433 +copy_user_acl(struct gr_arg *arg)
52434 +{
52435 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52436 + struct sprole_pw *sptmp;
52437 + struct gr_hash_struct *ghash;
52438 + uid_t *domainlist;
52439 + unsigned int r_num;
52440 + unsigned int len;
52441 + char *tmp;
52442 + int err = 0;
52443 + __u16 i;
52444 + __u32 num_subjs;
52445 +
52446 + /* we need a default and kernel role */
52447 + if (arg->role_db.num_roles < 2)
52448 + return -EINVAL;
52449 +
52450 + /* copy special role authentication info from userspace */
52451 +
52452 + num_sprole_pws = arg->num_sprole_pws;
52453 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52454 +
52455 + if (!acl_special_roles && num_sprole_pws)
52456 + return -ENOMEM;
52457 +
52458 + for (i = 0; i < num_sprole_pws; i++) {
52459 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52460 + if (!sptmp)
52461 + return -ENOMEM;
52462 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52463 + sizeof (struct sprole_pw)))
52464 + return -EFAULT;
52465 +
52466 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52467 +
52468 + if (!len || len >= GR_SPROLE_LEN)
52469 + return -EINVAL;
52470 +
52471 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52472 + return -ENOMEM;
52473 +
52474 + if (copy_from_user(tmp, sptmp->rolename, len))
52475 + return -EFAULT;
52476 +
52477 + tmp[len-1] = '\0';
52478 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52479 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52480 +#endif
52481 + sptmp->rolename = tmp;
52482 + acl_special_roles[i] = sptmp;
52483 + }
52484 +
52485 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52486 +
52487 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52488 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52489 +
52490 + if (!r_tmp)
52491 + return -ENOMEM;
52492 +
52493 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52494 + sizeof (struct acl_role_label *)))
52495 + return -EFAULT;
52496 +
52497 + if (copy_from_user(r_tmp, r_utmp2,
52498 + sizeof (struct acl_role_label)))
52499 + return -EFAULT;
52500 +
52501 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52502 +
52503 + if (!len || len >= PATH_MAX)
52504 + return -EINVAL;
52505 +
52506 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52507 + return -ENOMEM;
52508 +
52509 + if (copy_from_user(tmp, r_tmp->rolename, len))
52510 + return -EFAULT;
52511 +
52512 + tmp[len-1] = '\0';
52513 + r_tmp->rolename = tmp;
52514 +
52515 + if (!strcmp(r_tmp->rolename, "default")
52516 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52517 + default_role = r_tmp;
52518 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52519 + kernel_role = r_tmp;
52520 + }
52521 +
52522 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52523 + return -ENOMEM;
52524 +
52525 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52526 + return -EFAULT;
52527 +
52528 + r_tmp->hash = ghash;
52529 +
52530 + num_subjs = count_user_subjs(r_tmp->hash->first);
52531 +
52532 + r_tmp->subj_hash_size = num_subjs;
52533 + r_tmp->subj_hash =
52534 + (struct acl_subject_label **)
52535 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52536 +
52537 + if (!r_tmp->subj_hash)
52538 + return -ENOMEM;
52539 +
52540 + err = copy_user_allowedips(r_tmp);
52541 + if (err)
52542 + return err;
52543 +
52544 + /* copy domain info */
52545 + if (r_tmp->domain_children != NULL) {
52546 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52547 + if (domainlist == NULL)
52548 + return -ENOMEM;
52549 +
52550 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52551 + return -EFAULT;
52552 +
52553 + r_tmp->domain_children = domainlist;
52554 + }
52555 +
52556 + err = copy_user_transitions(r_tmp);
52557 + if (err)
52558 + return err;
52559 +
52560 + memset(r_tmp->subj_hash, 0,
52561 + r_tmp->subj_hash_size *
52562 + sizeof (struct acl_subject_label *));
52563 +
52564 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52565 +
52566 + if (err)
52567 + return err;
52568 +
52569 + /* set nested subject list to null */
52570 + r_tmp->hash->first = NULL;
52571 +
52572 + insert_acl_role_label(r_tmp);
52573 + }
52574 +
52575 + if (default_role == NULL || kernel_role == NULL)
52576 + return -EINVAL;
52577 +
52578 + return err;
52579 +}
52580 +
52581 +static int
52582 +gracl_init(struct gr_arg *args)
52583 +{
52584 + int error = 0;
52585 +
52586 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52587 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52588 +
52589 + if (init_variables(args)) {
52590 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52591 + error = -ENOMEM;
52592 + free_variables();
52593 + goto out;
52594 + }
52595 +
52596 + error = copy_user_acl(args);
52597 + free_init_variables();
52598 + if (error) {
52599 + free_variables();
52600 + goto out;
52601 + }
52602 +
52603 + if ((error = gr_set_acls(0))) {
52604 + free_variables();
52605 + goto out;
52606 + }
52607 +
52608 + pax_open_kernel();
52609 + gr_status |= GR_READY;
52610 + pax_close_kernel();
52611 +
52612 + out:
52613 + return error;
52614 +}
52615 +
52616 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52617 +
52618 +static int
52619 +glob_match(const char *p, const char *n)
52620 +{
52621 + char c;
52622 +
52623 + while ((c = *p++) != '\0') {
52624 + switch (c) {
52625 + case '?':
52626 + if (*n == '\0')
52627 + return 1;
52628 + else if (*n == '/')
52629 + return 1;
52630 + break;
52631 + case '\\':
52632 + if (*n != c)
52633 + return 1;
52634 + break;
52635 + case '*':
52636 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52637 + if (*n == '/')
52638 + return 1;
52639 + else if (c == '?') {
52640 + if (*n == '\0')
52641 + return 1;
52642 + else
52643 + ++n;
52644 + }
52645 + }
52646 + if (c == '\0') {
52647 + return 0;
52648 + } else {
52649 + const char *endp;
52650 +
52651 + if ((endp = strchr(n, '/')) == NULL)
52652 + endp = n + strlen(n);
52653 +
52654 + if (c == '[') {
52655 + for (--p; n < endp; ++n)
52656 + if (!glob_match(p, n))
52657 + return 0;
52658 + } else if (c == '/') {
52659 + while (*n != '\0' && *n != '/')
52660 + ++n;
52661 + if (*n == '/' && !glob_match(p, n + 1))
52662 + return 0;
52663 + } else {
52664 + for (--p; n < endp; ++n)
52665 + if (*n == c && !glob_match(p, n))
52666 + return 0;
52667 + }
52668 +
52669 + return 1;
52670 + }
52671 + case '[':
52672 + {
52673 + int not;
52674 + char cold;
52675 +
52676 + if (*n == '\0' || *n == '/')
52677 + return 1;
52678 +
52679 + not = (*p == '!' || *p == '^');
52680 + if (not)
52681 + ++p;
52682 +
52683 + c = *p++;
52684 + for (;;) {
52685 + unsigned char fn = (unsigned char)*n;
52686 +
52687 + if (c == '\0')
52688 + return 1;
52689 + else {
52690 + if (c == fn)
52691 + goto matched;
52692 + cold = c;
52693 + c = *p++;
52694 +
52695 + if (c == '-' && *p != ']') {
52696 + unsigned char cend = *p++;
52697 +
52698 + if (cend == '\0')
52699 + return 1;
52700 +
52701 + if (cold <= fn && fn <= cend)
52702 + goto matched;
52703 +
52704 + c = *p++;
52705 + }
52706 + }
52707 +
52708 + if (c == ']')
52709 + break;
52710 + }
52711 + if (!not)
52712 + return 1;
52713 + break;
52714 + matched:
52715 + while (c != ']') {
52716 + if (c == '\0')
52717 + return 1;
52718 +
52719 + c = *p++;
52720 + }
52721 + if (not)
52722 + return 1;
52723 + }
52724 + break;
52725 + default:
52726 + if (c != *n)
52727 + return 1;
52728 + }
52729 +
52730 + ++n;
52731 + }
52732 +
52733 + if (*n == '\0')
52734 + return 0;
52735 +
52736 + if (*n == '/')
52737 + return 0;
52738 +
52739 + return 1;
52740 +}
52741 +
52742 +static struct acl_object_label *
52743 +chk_glob_label(struct acl_object_label *globbed,
52744 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52745 +{
52746 + struct acl_object_label *tmp;
52747 +
52748 + if (*path == NULL)
52749 + *path = gr_to_filename_nolock(dentry, mnt);
52750 +
52751 + tmp = globbed;
52752 +
52753 + while (tmp) {
52754 + if (!glob_match(tmp->filename, *path))
52755 + return tmp;
52756 + tmp = tmp->next;
52757 + }
52758 +
52759 + return NULL;
52760 +}
52761 +
52762 +static struct acl_object_label *
52763 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52764 + const ino_t curr_ino, const dev_t curr_dev,
52765 + const struct acl_subject_label *subj, char **path, const int checkglob)
52766 +{
52767 + struct acl_subject_label *tmpsubj;
52768 + struct acl_object_label *retval;
52769 + struct acl_object_label *retval2;
52770 +
52771 + tmpsubj = (struct acl_subject_label *) subj;
52772 + read_lock(&gr_inode_lock);
52773 + do {
52774 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52775 + if (retval) {
52776 + if (checkglob && retval->globbed) {
52777 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52778 + if (retval2)
52779 + retval = retval2;
52780 + }
52781 + break;
52782 + }
52783 + } while ((tmpsubj = tmpsubj->parent_subject));
52784 + read_unlock(&gr_inode_lock);
52785 +
52786 + return retval;
52787 +}
52788 +
52789 +static __inline__ struct acl_object_label *
52790 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52791 + struct dentry *curr_dentry,
52792 + const struct acl_subject_label *subj, char **path, const int checkglob)
52793 +{
52794 + int newglob = checkglob;
52795 + ino_t inode;
52796 + dev_t device;
52797 +
52798 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52799 + as we don't want a / * rule to match instead of the / object
52800 + don't do this for create lookups that call this function though, since they're looking up
52801 + on the parent and thus need globbing checks on all paths
52802 + */
52803 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52804 + newglob = GR_NO_GLOB;
52805 +
52806 + spin_lock(&curr_dentry->d_lock);
52807 + inode = curr_dentry->d_inode->i_ino;
52808 + device = __get_dev(curr_dentry);
52809 + spin_unlock(&curr_dentry->d_lock);
52810 +
52811 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52812 +}
52813 +
52814 +static struct acl_object_label *
52815 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52816 + const struct acl_subject_label *subj, char *path, const int checkglob)
52817 +{
52818 + struct dentry *dentry = (struct dentry *) l_dentry;
52819 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52820 + struct mount *real_mnt = real_mount(mnt);
52821 + struct acl_object_label *retval;
52822 + struct dentry *parent;
52823 +
52824 + write_seqlock(&rename_lock);
52825 + br_read_lock(&vfsmount_lock);
52826 +
52827 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52828 +#ifdef CONFIG_NET
52829 + mnt == sock_mnt ||
52830 +#endif
52831 +#ifdef CONFIG_HUGETLBFS
52832 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52833 +#endif
52834 + /* ignore Eric Biederman */
52835 + IS_PRIVATE(l_dentry->d_inode))) {
52836 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52837 + goto out;
52838 + }
52839 +
52840 + for (;;) {
52841 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52842 + break;
52843 +
52844 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52845 + if (!mnt_has_parent(real_mnt))
52846 + break;
52847 +
52848 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52849 + if (retval != NULL)
52850 + goto out;
52851 +
52852 + dentry = real_mnt->mnt_mountpoint;
52853 + real_mnt = real_mnt->mnt_parent;
52854 + mnt = &real_mnt->mnt;
52855 + continue;
52856 + }
52857 +
52858 + parent = dentry->d_parent;
52859 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52860 + if (retval != NULL)
52861 + goto out;
52862 +
52863 + dentry = parent;
52864 + }
52865 +
52866 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52867 +
52868 + /* real_root is pinned so we don't have to hold a reference */
52869 + if (retval == NULL)
52870 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52871 +out:
52872 + br_read_unlock(&vfsmount_lock);
52873 + write_sequnlock(&rename_lock);
52874 +
52875 + BUG_ON(retval == NULL);
52876 +
52877 + return retval;
52878 +}
52879 +
52880 +static __inline__ struct acl_object_label *
52881 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52882 + const struct acl_subject_label *subj)
52883 +{
52884 + char *path = NULL;
52885 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52886 +}
52887 +
52888 +static __inline__ struct acl_object_label *
52889 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52890 + const struct acl_subject_label *subj)
52891 +{
52892 + char *path = NULL;
52893 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52894 +}
52895 +
52896 +static __inline__ struct acl_object_label *
52897 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52898 + const struct acl_subject_label *subj, char *path)
52899 +{
52900 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52901 +}
52902 +
52903 +static struct acl_subject_label *
52904 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52905 + const struct acl_role_label *role)
52906 +{
52907 + struct dentry *dentry = (struct dentry *) l_dentry;
52908 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52909 + struct mount *real_mnt = real_mount(mnt);
52910 + struct acl_subject_label *retval;
52911 + struct dentry *parent;
52912 +
52913 + write_seqlock(&rename_lock);
52914 + br_read_lock(&vfsmount_lock);
52915 +
52916 + for (;;) {
52917 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52918 + break;
52919 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52920 + if (!mnt_has_parent(real_mnt))
52921 + break;
52922 +
52923 + spin_lock(&dentry->d_lock);
52924 + read_lock(&gr_inode_lock);
52925 + retval =
52926 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52927 + __get_dev(dentry), role);
52928 + read_unlock(&gr_inode_lock);
52929 + spin_unlock(&dentry->d_lock);
52930 + if (retval != NULL)
52931 + goto out;
52932 +
52933 + dentry = real_mnt->mnt_mountpoint;
52934 + real_mnt = real_mnt->mnt_parent;
52935 + mnt = &real_mnt->mnt;
52936 + continue;
52937 + }
52938 +
52939 + spin_lock(&dentry->d_lock);
52940 + read_lock(&gr_inode_lock);
52941 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52942 + __get_dev(dentry), role);
52943 + read_unlock(&gr_inode_lock);
52944 + parent = dentry->d_parent;
52945 + spin_unlock(&dentry->d_lock);
52946 +
52947 + if (retval != NULL)
52948 + goto out;
52949 +
52950 + dentry = parent;
52951 + }
52952 +
52953 + spin_lock(&dentry->d_lock);
52954 + read_lock(&gr_inode_lock);
52955 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52956 + __get_dev(dentry), role);
52957 + read_unlock(&gr_inode_lock);
52958 + spin_unlock(&dentry->d_lock);
52959 +
52960 + if (unlikely(retval == NULL)) {
52961 + /* real_root is pinned, we don't need to hold a reference */
52962 + read_lock(&gr_inode_lock);
52963 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52964 + __get_dev(real_root.dentry), role);
52965 + read_unlock(&gr_inode_lock);
52966 + }
52967 +out:
52968 + br_read_unlock(&vfsmount_lock);
52969 + write_sequnlock(&rename_lock);
52970 +
52971 + BUG_ON(retval == NULL);
52972 +
52973 + return retval;
52974 +}
52975 +
52976 +static void
52977 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52978 +{
52979 + struct task_struct *task = current;
52980 + const struct cred *cred = current_cred();
52981 +
52982 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52983 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52984 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52985 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52986 +
52987 + return;
52988 +}
52989 +
52990 +static void
52991 +gr_log_learn_id_change(const char type, const unsigned int real,
52992 + const unsigned int effective, const unsigned int fs)
52993 +{
52994 + struct task_struct *task = current;
52995 + const struct cred *cred = current_cred();
52996 +
52997 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52998 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52999 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53000 + type, real, effective, fs, &task->signal->saved_ip);
53001 +
53002 + return;
53003 +}
53004 +
53005 +__u32
53006 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53007 + const struct vfsmount * mnt)
53008 +{
53009 + __u32 retval = mode;
53010 + struct acl_subject_label *curracl;
53011 + struct acl_object_label *currobj;
53012 +
53013 + if (unlikely(!(gr_status & GR_READY)))
53014 + return (mode & ~GR_AUDITS);
53015 +
53016 + curracl = current->acl;
53017 +
53018 + currobj = chk_obj_label(dentry, mnt, curracl);
53019 + retval = currobj->mode & mode;
53020 +
53021 + /* if we're opening a specified transfer file for writing
53022 + (e.g. /dev/initctl), then transfer our role to init
53023 + */
53024 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53025 + current->role->roletype & GR_ROLE_PERSIST)) {
53026 + struct task_struct *task = init_pid_ns.child_reaper;
53027 +
53028 + if (task->role != current->role) {
53029 + task->acl_sp_role = 0;
53030 + task->acl_role_id = current->acl_role_id;
53031 + task->role = current->role;
53032 + rcu_read_lock();
53033 + read_lock(&grsec_exec_file_lock);
53034 + gr_apply_subject_to_task(task);
53035 + read_unlock(&grsec_exec_file_lock);
53036 + rcu_read_unlock();
53037 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53038 + }
53039 + }
53040 +
53041 + if (unlikely
53042 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53043 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53044 + __u32 new_mode = mode;
53045 +
53046 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53047 +
53048 + retval = new_mode;
53049 +
53050 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53051 + new_mode |= GR_INHERIT;
53052 +
53053 + if (!(mode & GR_NOLEARN))
53054 + gr_log_learn(dentry, mnt, new_mode);
53055 + }
53056 +
53057 + return retval;
53058 +}
53059 +
53060 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53061 + const struct dentry *parent,
53062 + const struct vfsmount *mnt)
53063 +{
53064 + struct name_entry *match;
53065 + struct acl_object_label *matchpo;
53066 + struct acl_subject_label *curracl;
53067 + char *path;
53068 +
53069 + if (unlikely(!(gr_status & GR_READY)))
53070 + return NULL;
53071 +
53072 + preempt_disable();
53073 + path = gr_to_filename_rbac(new_dentry, mnt);
53074 + match = lookup_name_entry_create(path);
53075 +
53076 + curracl = current->acl;
53077 +
53078 + if (match) {
53079 + read_lock(&gr_inode_lock);
53080 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53081 + read_unlock(&gr_inode_lock);
53082 +
53083 + if (matchpo) {
53084 + preempt_enable();
53085 + return matchpo;
53086 + }
53087 + }
53088 +
53089 + // lookup parent
53090 +
53091 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53092 +
53093 + preempt_enable();
53094 + return matchpo;
53095 +}
53096 +
53097 +__u32
53098 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53099 + const struct vfsmount * mnt, const __u32 mode)
53100 +{
53101 + struct acl_object_label *matchpo;
53102 + __u32 retval;
53103 +
53104 + if (unlikely(!(gr_status & GR_READY)))
53105 + return (mode & ~GR_AUDITS);
53106 +
53107 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53108 +
53109 + retval = matchpo->mode & mode;
53110 +
53111 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53112 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53113 + __u32 new_mode = mode;
53114 +
53115 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53116 +
53117 + gr_log_learn(new_dentry, mnt, new_mode);
53118 + return new_mode;
53119 + }
53120 +
53121 + return retval;
53122 +}
53123 +
53124 +__u32
53125 +gr_check_link(const struct dentry * new_dentry,
53126 + const struct dentry * parent_dentry,
53127 + const struct vfsmount * parent_mnt,
53128 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53129 +{
53130 + struct acl_object_label *obj;
53131 + __u32 oldmode, newmode;
53132 + __u32 needmode;
53133 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53134 + GR_DELETE | GR_INHERIT;
53135 +
53136 + if (unlikely(!(gr_status & GR_READY)))
53137 + return (GR_CREATE | GR_LINK);
53138 +
53139 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53140 + oldmode = obj->mode;
53141 +
53142 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53143 + newmode = obj->mode;
53144 +
53145 + needmode = newmode & checkmodes;
53146 +
53147 + // old name for hardlink must have at least the permissions of the new name
53148 + if ((oldmode & needmode) != needmode)
53149 + goto bad;
53150 +
53151 + // if old name had restrictions/auditing, make sure the new name does as well
53152 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53153 +
53154 + // don't allow hardlinking of suid/sgid files without permission
53155 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53156 + needmode |= GR_SETID;
53157 +
53158 + if ((newmode & needmode) != needmode)
53159 + goto bad;
53160 +
53161 + // enforce minimum permissions
53162 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53163 + return newmode;
53164 +bad:
53165 + needmode = oldmode;
53166 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53167 + needmode |= GR_SETID;
53168 +
53169 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53170 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53171 + return (GR_CREATE | GR_LINK);
53172 + } else if (newmode & GR_SUPPRESS)
53173 + return GR_SUPPRESS;
53174 + else
53175 + return 0;
53176 +}
53177 +
53178 +int
53179 +gr_check_hidden_task(const struct task_struct *task)
53180 +{
53181 + if (unlikely(!(gr_status & GR_READY)))
53182 + return 0;
53183 +
53184 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53185 + return 1;
53186 +
53187 + return 0;
53188 +}
53189 +
53190 +int
53191 +gr_check_protected_task(const struct task_struct *task)
53192 +{
53193 + if (unlikely(!(gr_status & GR_READY) || !task))
53194 + return 0;
53195 +
53196 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53197 + task->acl != current->acl)
53198 + return 1;
53199 +
53200 + return 0;
53201 +}
53202 +
53203 +int
53204 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53205 +{
53206 + struct task_struct *p;
53207 + int ret = 0;
53208 +
53209 + if (unlikely(!(gr_status & GR_READY) || !pid))
53210 + return ret;
53211 +
53212 + read_lock(&tasklist_lock);
53213 + do_each_pid_task(pid, type, p) {
53214 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53215 + p->acl != current->acl) {
53216 + ret = 1;
53217 + goto out;
53218 + }
53219 + } while_each_pid_task(pid, type, p);
53220 +out:
53221 + read_unlock(&tasklist_lock);
53222 +
53223 + return ret;
53224 +}
53225 +
53226 +void
53227 +gr_copy_label(struct task_struct *tsk)
53228 +{
53229 + tsk->signal->used_accept = 0;
53230 + tsk->acl_sp_role = 0;
53231 + tsk->acl_role_id = current->acl_role_id;
53232 + tsk->acl = current->acl;
53233 + tsk->role = current->role;
53234 + tsk->signal->curr_ip = current->signal->curr_ip;
53235 + tsk->signal->saved_ip = current->signal->saved_ip;
53236 + if (current->exec_file)
53237 + get_file(current->exec_file);
53238 + tsk->exec_file = current->exec_file;
53239 + tsk->is_writable = current->is_writable;
53240 + if (unlikely(current->signal->used_accept)) {
53241 + current->signal->curr_ip = 0;
53242 + current->signal->saved_ip = 0;
53243 + }
53244 +
53245 + return;
53246 +}
53247 +
53248 +static void
53249 +gr_set_proc_res(struct task_struct *task)
53250 +{
53251 + struct acl_subject_label *proc;
53252 + unsigned short i;
53253 +
53254 + proc = task->acl;
53255 +
53256 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53257 + return;
53258 +
53259 + for (i = 0; i < RLIM_NLIMITS; i++) {
53260 + if (!(proc->resmask & (1 << i)))
53261 + continue;
53262 +
53263 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53264 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53265 + }
53266 +
53267 + return;
53268 +}
53269 +
53270 +extern int __gr_process_user_ban(struct user_struct *user);
53271 +
53272 +int
53273 +gr_check_user_change(int real, int effective, int fs)
53274 +{
53275 + unsigned int i;
53276 + __u16 num;
53277 + uid_t *uidlist;
53278 + int curuid;
53279 + int realok = 0;
53280 + int effectiveok = 0;
53281 + int fsok = 0;
53282 +
53283 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53284 + struct user_struct *user;
53285 +
53286 + if (real == -1)
53287 + goto skipit;
53288 +
53289 + user = find_user(real);
53290 + if (user == NULL)
53291 + goto skipit;
53292 +
53293 + if (__gr_process_user_ban(user)) {
53294 + /* for find_user */
53295 + free_uid(user);
53296 + return 1;
53297 + }
53298 +
53299 + /* for find_user */
53300 + free_uid(user);
53301 +
53302 +skipit:
53303 +#endif
53304 +
53305 + if (unlikely(!(gr_status & GR_READY)))
53306 + return 0;
53307 +
53308 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53309 + gr_log_learn_id_change('u', real, effective, fs);
53310 +
53311 + num = current->acl->user_trans_num;
53312 + uidlist = current->acl->user_transitions;
53313 +
53314 + if (uidlist == NULL)
53315 + return 0;
53316 +
53317 + if (real == -1)
53318 + realok = 1;
53319 + if (effective == -1)
53320 + effectiveok = 1;
53321 + if (fs == -1)
53322 + fsok = 1;
53323 +
53324 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53325 + for (i = 0; i < num; i++) {
53326 + curuid = (int)uidlist[i];
53327 + if (real == curuid)
53328 + realok = 1;
53329 + if (effective == curuid)
53330 + effectiveok = 1;
53331 + if (fs == curuid)
53332 + fsok = 1;
53333 + }
53334 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53335 + for (i = 0; i < num; i++) {
53336 + curuid = (int)uidlist[i];
53337 + if (real == curuid)
53338 + break;
53339 + if (effective == curuid)
53340 + break;
53341 + if (fs == curuid)
53342 + break;
53343 + }
53344 + /* not in deny list */
53345 + if (i == num) {
53346 + realok = 1;
53347 + effectiveok = 1;
53348 + fsok = 1;
53349 + }
53350 + }
53351 +
53352 + if (realok && effectiveok && fsok)
53353 + return 0;
53354 + else {
53355 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53356 + return 1;
53357 + }
53358 +}
53359 +
53360 +int
53361 +gr_check_group_change(int real, int effective, int fs)
53362 +{
53363 + unsigned int i;
53364 + __u16 num;
53365 + gid_t *gidlist;
53366 + int curgid;
53367 + int realok = 0;
53368 + int effectiveok = 0;
53369 + int fsok = 0;
53370 +
53371 + if (unlikely(!(gr_status & GR_READY)))
53372 + return 0;
53373 +
53374 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53375 + gr_log_learn_id_change('g', real, effective, fs);
53376 +
53377 + num = current->acl->group_trans_num;
53378 + gidlist = current->acl->group_transitions;
53379 +
53380 + if (gidlist == NULL)
53381 + return 0;
53382 +
53383 + if (real == -1)
53384 + realok = 1;
53385 + if (effective == -1)
53386 + effectiveok = 1;
53387 + if (fs == -1)
53388 + fsok = 1;
53389 +
53390 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53391 + for (i = 0; i < num; i++) {
53392 + curgid = (int)gidlist[i];
53393 + if (real == curgid)
53394 + realok = 1;
53395 + if (effective == curgid)
53396 + effectiveok = 1;
53397 + if (fs == curgid)
53398 + fsok = 1;
53399 + }
53400 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53401 + for (i = 0; i < num; i++) {
53402 + curgid = (int)gidlist[i];
53403 + if (real == curgid)
53404 + break;
53405 + if (effective == curgid)
53406 + break;
53407 + if (fs == curgid)
53408 + break;
53409 + }
53410 + /* not in deny list */
53411 + if (i == num) {
53412 + realok = 1;
53413 + effectiveok = 1;
53414 + fsok = 1;
53415 + }
53416 + }
53417 +
53418 + if (realok && effectiveok && fsok)
53419 + return 0;
53420 + else {
53421 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53422 + return 1;
53423 + }
53424 +}
53425 +
53426 +extern int gr_acl_is_capable(const int cap);
53427 +
53428 +void
53429 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53430 +{
53431 + struct acl_role_label *role = task->role;
53432 + struct acl_subject_label *subj = NULL;
53433 + struct acl_object_label *obj;
53434 + struct file *filp;
53435 +
53436 + if (unlikely(!(gr_status & GR_READY)))
53437 + return;
53438 +
53439 + filp = task->exec_file;
53440 +
53441 + /* kernel process, we'll give them the kernel role */
53442 + if (unlikely(!filp)) {
53443 + task->role = kernel_role;
53444 + task->acl = kernel_role->root_label;
53445 + return;
53446 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53447 + role = lookup_acl_role_label(task, uid, gid);
53448 +
53449 + /* don't change the role if we're not a privileged process */
53450 + if (role && task->role != role &&
53451 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53452 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53453 + return;
53454 +
53455 + /* perform subject lookup in possibly new role
53456 + we can use this result below in the case where role == task->role
53457 + */
53458 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53459 +
53460 + /* if we changed uid/gid, but result in the same role
53461 + and are using inheritance, don't lose the inherited subject
53462 + if current subject is other than what normal lookup
53463 + would result in, we arrived via inheritance, don't
53464 + lose subject
53465 + */
53466 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53467 + (subj == task->acl)))
53468 + task->acl = subj;
53469 +
53470 + task->role = role;
53471 +
53472 + task->is_writable = 0;
53473 +
53474 + /* ignore additional mmap checks for processes that are writable
53475 + by the default ACL */
53476 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53477 + if (unlikely(obj->mode & GR_WRITE))
53478 + task->is_writable = 1;
53479 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53480 + if (unlikely(obj->mode & GR_WRITE))
53481 + task->is_writable = 1;
53482 +
53483 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53484 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53485 +#endif
53486 +
53487 + gr_set_proc_res(task);
53488 +
53489 + return;
53490 +}
53491 +
53492 +int
53493 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53494 + const int unsafe_flags)
53495 +{
53496 + struct task_struct *task = current;
53497 + struct acl_subject_label *newacl;
53498 + struct acl_object_label *obj;
53499 + __u32 retmode;
53500 +
53501 + if (unlikely(!(gr_status & GR_READY)))
53502 + return 0;
53503 +
53504 + newacl = chk_subj_label(dentry, mnt, task->role);
53505 +
53506 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53507 + did an exec
53508 + */
53509 + rcu_read_lock();
53510 + read_lock(&tasklist_lock);
53511 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53512 + (task->parent->acl->mode & GR_POVERRIDE))) {
53513 + read_unlock(&tasklist_lock);
53514 + rcu_read_unlock();
53515 + goto skip_check;
53516 + }
53517 + read_unlock(&tasklist_lock);
53518 + rcu_read_unlock();
53519 +
53520 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53521 + !(task->role->roletype & GR_ROLE_GOD) &&
53522 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53523 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53524 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53525 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53526 + else
53527 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53528 + return -EACCES;
53529 + }
53530 +
53531 +skip_check:
53532 +
53533 + obj = chk_obj_label(dentry, mnt, task->acl);
53534 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53535 +
53536 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53537 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53538 + if (obj->nested)
53539 + task->acl = obj->nested;
53540 + else
53541 + task->acl = newacl;
53542 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53543 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53544 +
53545 + task->is_writable = 0;
53546 +
53547 + /* ignore additional mmap checks for processes that are writable
53548 + by the default ACL */
53549 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53550 + if (unlikely(obj->mode & GR_WRITE))
53551 + task->is_writable = 1;
53552 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53553 + if (unlikely(obj->mode & GR_WRITE))
53554 + task->is_writable = 1;
53555 +
53556 + gr_set_proc_res(task);
53557 +
53558 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53559 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53560 +#endif
53561 + return 0;
53562 +}
53563 +
53564 +/* always called with valid inodev ptr */
53565 +static void
53566 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53567 +{
53568 + struct acl_object_label *matchpo;
53569 + struct acl_subject_label *matchps;
53570 + struct acl_subject_label *subj;
53571 + struct acl_role_label *role;
53572 + unsigned int x;
53573 +
53574 + FOR_EACH_ROLE_START(role)
53575 + FOR_EACH_SUBJECT_START(role, subj, x)
53576 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53577 + matchpo->mode |= GR_DELETED;
53578 + FOR_EACH_SUBJECT_END(subj,x)
53579 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53580 + if (subj->inode == ino && subj->device == dev)
53581 + subj->mode |= GR_DELETED;
53582 + FOR_EACH_NESTED_SUBJECT_END(subj)
53583 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53584 + matchps->mode |= GR_DELETED;
53585 + FOR_EACH_ROLE_END(role)
53586 +
53587 + inodev->nentry->deleted = 1;
53588 +
53589 + return;
53590 +}
53591 +
53592 +void
53593 +gr_handle_delete(const ino_t ino, const dev_t dev)
53594 +{
53595 + struct inodev_entry *inodev;
53596 +
53597 + if (unlikely(!(gr_status & GR_READY)))
53598 + return;
53599 +
53600 + write_lock(&gr_inode_lock);
53601 + inodev = lookup_inodev_entry(ino, dev);
53602 + if (inodev != NULL)
53603 + do_handle_delete(inodev, ino, dev);
53604 + write_unlock(&gr_inode_lock);
53605 +
53606 + return;
53607 +}
53608 +
53609 +static void
53610 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53611 + const ino_t newinode, const dev_t newdevice,
53612 + struct acl_subject_label *subj)
53613 +{
53614 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53615 + struct acl_object_label *match;
53616 +
53617 + match = subj->obj_hash[index];
53618 +
53619 + while (match && (match->inode != oldinode ||
53620 + match->device != olddevice ||
53621 + !(match->mode & GR_DELETED)))
53622 + match = match->next;
53623 +
53624 + if (match && (match->inode == oldinode)
53625 + && (match->device == olddevice)
53626 + && (match->mode & GR_DELETED)) {
53627 + if (match->prev == NULL) {
53628 + subj->obj_hash[index] = match->next;
53629 + if (match->next != NULL)
53630 + match->next->prev = NULL;
53631 + } else {
53632 + match->prev->next = match->next;
53633 + if (match->next != NULL)
53634 + match->next->prev = match->prev;
53635 + }
53636 + match->prev = NULL;
53637 + match->next = NULL;
53638 + match->inode = newinode;
53639 + match->device = newdevice;
53640 + match->mode &= ~GR_DELETED;
53641 +
53642 + insert_acl_obj_label(match, subj);
53643 + }
53644 +
53645 + return;
53646 +}
53647 +
53648 +static void
53649 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53650 + const ino_t newinode, const dev_t newdevice,
53651 + struct acl_role_label *role)
53652 +{
53653 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53654 + struct acl_subject_label *match;
53655 +
53656 + match = role->subj_hash[index];
53657 +
53658 + while (match && (match->inode != oldinode ||
53659 + match->device != olddevice ||
53660 + !(match->mode & GR_DELETED)))
53661 + match = match->next;
53662 +
53663 + if (match && (match->inode == oldinode)
53664 + && (match->device == olddevice)
53665 + && (match->mode & GR_DELETED)) {
53666 + if (match->prev == NULL) {
53667 + role->subj_hash[index] = match->next;
53668 + if (match->next != NULL)
53669 + match->next->prev = NULL;
53670 + } else {
53671 + match->prev->next = match->next;
53672 + if (match->next != NULL)
53673 + match->next->prev = match->prev;
53674 + }
53675 + match->prev = NULL;
53676 + match->next = NULL;
53677 + match->inode = newinode;
53678 + match->device = newdevice;
53679 + match->mode &= ~GR_DELETED;
53680 +
53681 + insert_acl_subj_label(match, role);
53682 + }
53683 +
53684 + return;
53685 +}
53686 +
53687 +static void
53688 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53689 + const ino_t newinode, const dev_t newdevice)
53690 +{
53691 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53692 + struct inodev_entry *match;
53693 +
53694 + match = inodev_set.i_hash[index];
53695 +
53696 + while (match && (match->nentry->inode != oldinode ||
53697 + match->nentry->device != olddevice || !match->nentry->deleted))
53698 + match = match->next;
53699 +
53700 + if (match && (match->nentry->inode == oldinode)
53701 + && (match->nentry->device == olddevice) &&
53702 + match->nentry->deleted) {
53703 + if (match->prev == NULL) {
53704 + inodev_set.i_hash[index] = match->next;
53705 + if (match->next != NULL)
53706 + match->next->prev = NULL;
53707 + } else {
53708 + match->prev->next = match->next;
53709 + if (match->next != NULL)
53710 + match->next->prev = match->prev;
53711 + }
53712 + match->prev = NULL;
53713 + match->next = NULL;
53714 + match->nentry->inode = newinode;
53715 + match->nentry->device = newdevice;
53716 + match->nentry->deleted = 0;
53717 +
53718 + insert_inodev_entry(match);
53719 + }
53720 +
53721 + return;
53722 +}
53723 +
53724 +static void
53725 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53726 +{
53727 + struct acl_subject_label *subj;
53728 + struct acl_role_label *role;
53729 + unsigned int x;
53730 +
53731 + FOR_EACH_ROLE_START(role)
53732 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53733 +
53734 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53735 + if ((subj->inode == ino) && (subj->device == dev)) {
53736 + subj->inode = ino;
53737 + subj->device = dev;
53738 + }
53739 + FOR_EACH_NESTED_SUBJECT_END(subj)
53740 + FOR_EACH_SUBJECT_START(role, subj, x)
53741 + update_acl_obj_label(matchn->inode, matchn->device,
53742 + ino, dev, subj);
53743 + FOR_EACH_SUBJECT_END(subj,x)
53744 + FOR_EACH_ROLE_END(role)
53745 +
53746 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53747 +
53748 + return;
53749 +}
53750 +
53751 +static void
53752 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53753 + const struct vfsmount *mnt)
53754 +{
53755 + ino_t ino = dentry->d_inode->i_ino;
53756 + dev_t dev = __get_dev(dentry);
53757 +
53758 + __do_handle_create(matchn, ino, dev);
53759 +
53760 + return;
53761 +}
53762 +
53763 +void
53764 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53765 +{
53766 + struct name_entry *matchn;
53767 +
53768 + if (unlikely(!(gr_status & GR_READY)))
53769 + return;
53770 +
53771 + preempt_disable();
53772 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53773 +
53774 + if (unlikely((unsigned long)matchn)) {
53775 + write_lock(&gr_inode_lock);
53776 + do_handle_create(matchn, dentry, mnt);
53777 + write_unlock(&gr_inode_lock);
53778 + }
53779 + preempt_enable();
53780 +
53781 + return;
53782 +}
53783 +
53784 +void
53785 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53786 +{
53787 + struct name_entry *matchn;
53788 +
53789 + if (unlikely(!(gr_status & GR_READY)))
53790 + return;
53791 +
53792 + preempt_disable();
53793 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53794 +
53795 + if (unlikely((unsigned long)matchn)) {
53796 + write_lock(&gr_inode_lock);
53797 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53798 + write_unlock(&gr_inode_lock);
53799 + }
53800 + preempt_enable();
53801 +
53802 + return;
53803 +}
53804 +
53805 +void
53806 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53807 + struct dentry *old_dentry,
53808 + struct dentry *new_dentry,
53809 + struct vfsmount *mnt, const __u8 replace)
53810 +{
53811 + struct name_entry *matchn;
53812 + struct inodev_entry *inodev;
53813 + struct inode *inode = new_dentry->d_inode;
53814 + ino_t old_ino = old_dentry->d_inode->i_ino;
53815 + dev_t old_dev = __get_dev(old_dentry);
53816 +
53817 + /* vfs_rename swaps the name and parent link for old_dentry and
53818 + new_dentry
53819 + at this point, old_dentry has the new name, parent link, and inode
53820 + for the renamed file
53821 + if a file is being replaced by a rename, new_dentry has the inode
53822 + and name for the replaced file
53823 + */
53824 +
53825 + if (unlikely(!(gr_status & GR_READY)))
53826 + return;
53827 +
53828 + preempt_disable();
53829 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53830 +
53831 + /* we wouldn't have to check d_inode if it weren't for
53832 + NFS silly-renaming
53833 + */
53834 +
53835 + write_lock(&gr_inode_lock);
53836 + if (unlikely(replace && inode)) {
53837 + ino_t new_ino = inode->i_ino;
53838 + dev_t new_dev = __get_dev(new_dentry);
53839 +
53840 + inodev = lookup_inodev_entry(new_ino, new_dev);
53841 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53842 + do_handle_delete(inodev, new_ino, new_dev);
53843 + }
53844 +
53845 + inodev = lookup_inodev_entry(old_ino, old_dev);
53846 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53847 + do_handle_delete(inodev, old_ino, old_dev);
53848 +
53849 + if (unlikely((unsigned long)matchn))
53850 + do_handle_create(matchn, old_dentry, mnt);
53851 +
53852 + write_unlock(&gr_inode_lock);
53853 + preempt_enable();
53854 +
53855 + return;
53856 +}
53857 +
53858 +static int
53859 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53860 + unsigned char **sum)
53861 +{
53862 + struct acl_role_label *r;
53863 + struct role_allowed_ip *ipp;
53864 + struct role_transition *trans;
53865 + unsigned int i;
53866 + int found = 0;
53867 + u32 curr_ip = current->signal->curr_ip;
53868 +
53869 + current->signal->saved_ip = curr_ip;
53870 +
53871 + /* check transition table */
53872 +
53873 + for (trans = current->role->transitions; trans; trans = trans->next) {
53874 + if (!strcmp(rolename, trans->rolename)) {
53875 + found = 1;
53876 + break;
53877 + }
53878 + }
53879 +
53880 + if (!found)
53881 + return 0;
53882 +
53883 + /* handle special roles that do not require authentication
53884 + and check ip */
53885 +
53886 + FOR_EACH_ROLE_START(r)
53887 + if (!strcmp(rolename, r->rolename) &&
53888 + (r->roletype & GR_ROLE_SPECIAL)) {
53889 + found = 0;
53890 + if (r->allowed_ips != NULL) {
53891 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53892 + if ((ntohl(curr_ip) & ipp->netmask) ==
53893 + (ntohl(ipp->addr) & ipp->netmask))
53894 + found = 1;
53895 + }
53896 + } else
53897 + found = 2;
53898 + if (!found)
53899 + return 0;
53900 +
53901 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53902 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53903 + *salt = NULL;
53904 + *sum = NULL;
53905 + return 1;
53906 + }
53907 + }
53908 + FOR_EACH_ROLE_END(r)
53909 +
53910 + for (i = 0; i < num_sprole_pws; i++) {
53911 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53912 + *salt = acl_special_roles[i]->salt;
53913 + *sum = acl_special_roles[i]->sum;
53914 + return 1;
53915 + }
53916 + }
53917 +
53918 + return 0;
53919 +}
53920 +
53921 +static void
53922 +assign_special_role(char *rolename)
53923 +{
53924 + struct acl_object_label *obj;
53925 + struct acl_role_label *r;
53926 + struct acl_role_label *assigned = NULL;
53927 + struct task_struct *tsk;
53928 + struct file *filp;
53929 +
53930 + FOR_EACH_ROLE_START(r)
53931 + if (!strcmp(rolename, r->rolename) &&
53932 + (r->roletype & GR_ROLE_SPECIAL)) {
53933 + assigned = r;
53934 + break;
53935 + }
53936 + FOR_EACH_ROLE_END(r)
53937 +
53938 + if (!assigned)
53939 + return;
53940 +
53941 + read_lock(&tasklist_lock);
53942 + read_lock(&grsec_exec_file_lock);
53943 +
53944 + tsk = current->real_parent;
53945 + if (tsk == NULL)
53946 + goto out_unlock;
53947 +
53948 + filp = tsk->exec_file;
53949 + if (filp == NULL)
53950 + goto out_unlock;
53951 +
53952 + tsk->is_writable = 0;
53953 +
53954 + tsk->acl_sp_role = 1;
53955 + tsk->acl_role_id = ++acl_sp_role_value;
53956 + tsk->role = assigned;
53957 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53958 +
53959 + /* ignore additional mmap checks for processes that are writable
53960 + by the default ACL */
53961 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53962 + if (unlikely(obj->mode & GR_WRITE))
53963 + tsk->is_writable = 1;
53964 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53965 + if (unlikely(obj->mode & GR_WRITE))
53966 + tsk->is_writable = 1;
53967 +
53968 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53969 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53970 +#endif
53971 +
53972 +out_unlock:
53973 + read_unlock(&grsec_exec_file_lock);
53974 + read_unlock(&tasklist_lock);
53975 + return;
53976 +}
53977 +
53978 +int gr_check_secure_terminal(struct task_struct *task)
53979 +{
53980 + struct task_struct *p, *p2, *p3;
53981 + struct files_struct *files;
53982 + struct fdtable *fdt;
53983 + struct file *our_file = NULL, *file;
53984 + int i;
53985 +
53986 + if (task->signal->tty == NULL)
53987 + return 1;
53988 +
53989 + files = get_files_struct(task);
53990 + if (files != NULL) {
53991 + rcu_read_lock();
53992 + fdt = files_fdtable(files);
53993 + for (i=0; i < fdt->max_fds; i++) {
53994 + file = fcheck_files(files, i);
53995 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53996 + get_file(file);
53997 + our_file = file;
53998 + }
53999 + }
54000 + rcu_read_unlock();
54001 + put_files_struct(files);
54002 + }
54003 +
54004 + if (our_file == NULL)
54005 + return 1;
54006 +
54007 + read_lock(&tasklist_lock);
54008 + do_each_thread(p2, p) {
54009 + files = get_files_struct(p);
54010 + if (files == NULL ||
54011 + (p->signal && p->signal->tty == task->signal->tty)) {
54012 + if (files != NULL)
54013 + put_files_struct(files);
54014 + continue;
54015 + }
54016 + rcu_read_lock();
54017 + fdt = files_fdtable(files);
54018 + for (i=0; i < fdt->max_fds; i++) {
54019 + file = fcheck_files(files, i);
54020 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54021 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54022 + p3 = task;
54023 + while (p3->pid > 0) {
54024 + if (p3 == p)
54025 + break;
54026 + p3 = p3->real_parent;
54027 + }
54028 + if (p3 == p)
54029 + break;
54030 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54031 + gr_handle_alertkill(p);
54032 + rcu_read_unlock();
54033 + put_files_struct(files);
54034 + read_unlock(&tasklist_lock);
54035 + fput(our_file);
54036 + return 0;
54037 + }
54038 + }
54039 + rcu_read_unlock();
54040 + put_files_struct(files);
54041 + } while_each_thread(p2, p);
54042 + read_unlock(&tasklist_lock);
54043 +
54044 + fput(our_file);
54045 + return 1;
54046 +}
54047 +
54048 +static int gr_rbac_disable(void *unused)
54049 +{
54050 + pax_open_kernel();
54051 + gr_status &= ~GR_READY;
54052 + pax_close_kernel();
54053 +
54054 + return 0;
54055 +}
54056 +
54057 +ssize_t
54058 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54059 +{
54060 + struct gr_arg_wrapper uwrap;
54061 + unsigned char *sprole_salt = NULL;
54062 + unsigned char *sprole_sum = NULL;
54063 + int error = sizeof (struct gr_arg_wrapper);
54064 + int error2 = 0;
54065 +
54066 + mutex_lock(&gr_dev_mutex);
54067 +
54068 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54069 + error = -EPERM;
54070 + goto out;
54071 + }
54072 +
54073 + if (count != sizeof (struct gr_arg_wrapper)) {
54074 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54075 + error = -EINVAL;
54076 + goto out;
54077 + }
54078 +
54079 +
54080 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54081 + gr_auth_expires = 0;
54082 + gr_auth_attempts = 0;
54083 + }
54084 +
54085 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54086 + error = -EFAULT;
54087 + goto out;
54088 + }
54089 +
54090 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54091 + error = -EINVAL;
54092 + goto out;
54093 + }
54094 +
54095 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54096 + error = -EFAULT;
54097 + goto out;
54098 + }
54099 +
54100 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54101 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54102 + time_after(gr_auth_expires, get_seconds())) {
54103 + error = -EBUSY;
54104 + goto out;
54105 + }
54106 +
54107 + /* if non-root trying to do anything other than use a special role,
54108 + do not attempt authentication, do not count towards authentication
54109 + locking
54110 + */
54111 +
54112 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54113 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54114 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54115 + error = -EPERM;
54116 + goto out;
54117 + }
54118 +
54119 + /* ensure pw and special role name are null terminated */
54120 +
54121 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54122 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54123 +
54124 + /* Okay.
54125 + * We have our enough of the argument structure..(we have yet
54126 + * to copy_from_user the tables themselves) . Copy the tables
54127 + * only if we need them, i.e. for loading operations. */
54128 +
54129 + switch (gr_usermode->mode) {
54130 + case GR_STATUS:
54131 + if (gr_status & GR_READY) {
54132 + error = 1;
54133 + if (!gr_check_secure_terminal(current))
54134 + error = 3;
54135 + } else
54136 + error = 2;
54137 + goto out;
54138 + case GR_SHUTDOWN:
54139 + if ((gr_status & GR_READY)
54140 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54141 + stop_machine(gr_rbac_disable, NULL, NULL);
54142 + free_variables();
54143 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54144 + memset(gr_system_salt, 0, GR_SALT_LEN);
54145 + memset(gr_system_sum, 0, GR_SHA_LEN);
54146 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54147 + } else if (gr_status & GR_READY) {
54148 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54149 + error = -EPERM;
54150 + } else {
54151 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54152 + error = -EAGAIN;
54153 + }
54154 + break;
54155 + case GR_ENABLE:
54156 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54157 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54158 + else {
54159 + if (gr_status & GR_READY)
54160 + error = -EAGAIN;
54161 + else
54162 + error = error2;
54163 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54164 + }
54165 + break;
54166 + case GR_RELOAD:
54167 + if (!(gr_status & GR_READY)) {
54168 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54169 + error = -EAGAIN;
54170 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54171 + stop_machine(gr_rbac_disable, NULL, NULL);
54172 + free_variables();
54173 + error2 = gracl_init(gr_usermode);
54174 + if (!error2)
54175 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54176 + else {
54177 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54178 + error = error2;
54179 + }
54180 + } else {
54181 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54182 + error = -EPERM;
54183 + }
54184 + break;
54185 + case GR_SEGVMOD:
54186 + if (unlikely(!(gr_status & GR_READY))) {
54187 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54188 + error = -EAGAIN;
54189 + break;
54190 + }
54191 +
54192 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54193 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54194 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54195 + struct acl_subject_label *segvacl;
54196 + segvacl =
54197 + lookup_acl_subj_label(gr_usermode->segv_inode,
54198 + gr_usermode->segv_device,
54199 + current->role);
54200 + if (segvacl) {
54201 + segvacl->crashes = 0;
54202 + segvacl->expires = 0;
54203 + }
54204 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54205 + gr_remove_uid(gr_usermode->segv_uid);
54206 + }
54207 + } else {
54208 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54209 + error = -EPERM;
54210 + }
54211 + break;
54212 + case GR_SPROLE:
54213 + case GR_SPROLEPAM:
54214 + if (unlikely(!(gr_status & GR_READY))) {
54215 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54216 + error = -EAGAIN;
54217 + break;
54218 + }
54219 +
54220 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54221 + current->role->expires = 0;
54222 + current->role->auth_attempts = 0;
54223 + }
54224 +
54225 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54226 + time_after(current->role->expires, get_seconds())) {
54227 + error = -EBUSY;
54228 + goto out;
54229 + }
54230 +
54231 + if (lookup_special_role_auth
54232 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54233 + && ((!sprole_salt && !sprole_sum)
54234 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54235 + char *p = "";
54236 + assign_special_role(gr_usermode->sp_role);
54237 + read_lock(&tasklist_lock);
54238 + if (current->real_parent)
54239 + p = current->real_parent->role->rolename;
54240 + read_unlock(&tasklist_lock);
54241 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54242 + p, acl_sp_role_value);
54243 + } else {
54244 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54245 + error = -EPERM;
54246 + if(!(current->role->auth_attempts++))
54247 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54248 +
54249 + goto out;
54250 + }
54251 + break;
54252 + case GR_UNSPROLE:
54253 + if (unlikely(!(gr_status & GR_READY))) {
54254 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54255 + error = -EAGAIN;
54256 + break;
54257 + }
54258 +
54259 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54260 + char *p = "";
54261 + int i = 0;
54262 +
54263 + read_lock(&tasklist_lock);
54264 + if (current->real_parent) {
54265 + p = current->real_parent->role->rolename;
54266 + i = current->real_parent->acl_role_id;
54267 + }
54268 + read_unlock(&tasklist_lock);
54269 +
54270 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54271 + gr_set_acls(1);
54272 + } else {
54273 + error = -EPERM;
54274 + goto out;
54275 + }
54276 + break;
54277 + default:
54278 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54279 + error = -EINVAL;
54280 + break;
54281 + }
54282 +
54283 + if (error != -EPERM)
54284 + goto out;
54285 +
54286 + if(!(gr_auth_attempts++))
54287 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54288 +
54289 + out:
54290 + mutex_unlock(&gr_dev_mutex);
54291 + return error;
54292 +}
54293 +
54294 +/* must be called with
54295 + rcu_read_lock();
54296 + read_lock(&tasklist_lock);
54297 + read_lock(&grsec_exec_file_lock);
54298 +*/
54299 +int gr_apply_subject_to_task(struct task_struct *task)
54300 +{
54301 + struct acl_object_label *obj;
54302 + char *tmpname;
54303 + struct acl_subject_label *tmpsubj;
54304 + struct file *filp;
54305 + struct name_entry *nmatch;
54306 +
54307 + filp = task->exec_file;
54308 + if (filp == NULL)
54309 + return 0;
54310 +
54311 + /* the following is to apply the correct subject
54312 + on binaries running when the RBAC system
54313 + is enabled, when the binaries have been
54314 + replaced or deleted since their execution
54315 + -----
54316 + when the RBAC system starts, the inode/dev
54317 + from exec_file will be one the RBAC system
54318 + is unaware of. It only knows the inode/dev
54319 + of the present file on disk, or the absence
54320 + of it.
54321 + */
54322 + preempt_disable();
54323 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54324 +
54325 + nmatch = lookup_name_entry(tmpname);
54326 + preempt_enable();
54327 + tmpsubj = NULL;
54328 + if (nmatch) {
54329 + if (nmatch->deleted)
54330 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54331 + else
54332 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54333 + if (tmpsubj != NULL)
54334 + task->acl = tmpsubj;
54335 + }
54336 + if (tmpsubj == NULL)
54337 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54338 + task->role);
54339 + if (task->acl) {
54340 + task->is_writable = 0;
54341 + /* ignore additional mmap checks for processes that are writable
54342 + by the default ACL */
54343 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54344 + if (unlikely(obj->mode & GR_WRITE))
54345 + task->is_writable = 1;
54346 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54347 + if (unlikely(obj->mode & GR_WRITE))
54348 + task->is_writable = 1;
54349 +
54350 + gr_set_proc_res(task);
54351 +
54352 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54353 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54354 +#endif
54355 + } else {
54356 + return 1;
54357 + }
54358 +
54359 + return 0;
54360 +}
54361 +
54362 +int
54363 +gr_set_acls(const int type)
54364 +{
54365 + struct task_struct *task, *task2;
54366 + struct acl_role_label *role = current->role;
54367 + __u16 acl_role_id = current->acl_role_id;
54368 + const struct cred *cred;
54369 + int ret;
54370 +
54371 + rcu_read_lock();
54372 + read_lock(&tasklist_lock);
54373 + read_lock(&grsec_exec_file_lock);
54374 + do_each_thread(task2, task) {
54375 + /* check to see if we're called from the exit handler,
54376 + if so, only replace ACLs that have inherited the admin
54377 + ACL */
54378 +
54379 + if (type && (task->role != role ||
54380 + task->acl_role_id != acl_role_id))
54381 + continue;
54382 +
54383 + task->acl_role_id = 0;
54384 + task->acl_sp_role = 0;
54385 +
54386 + if (task->exec_file) {
54387 + cred = __task_cred(task);
54388 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54389 + ret = gr_apply_subject_to_task(task);
54390 + if (ret) {
54391 + read_unlock(&grsec_exec_file_lock);
54392 + read_unlock(&tasklist_lock);
54393 + rcu_read_unlock();
54394 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54395 + return ret;
54396 + }
54397 + } else {
54398 + // it's a kernel process
54399 + task->role = kernel_role;
54400 + task->acl = kernel_role->root_label;
54401 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54402 + task->acl->mode &= ~GR_PROCFIND;
54403 +#endif
54404 + }
54405 + } while_each_thread(task2, task);
54406 + read_unlock(&grsec_exec_file_lock);
54407 + read_unlock(&tasklist_lock);
54408 + rcu_read_unlock();
54409 +
54410 + return 0;
54411 +}
54412 +
54413 +void
54414 +gr_learn_resource(const struct task_struct *task,
54415 + const int res, const unsigned long wanted, const int gt)
54416 +{
54417 + struct acl_subject_label *acl;
54418 + const struct cred *cred;
54419 +
54420 + if (unlikely((gr_status & GR_READY) &&
54421 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54422 + goto skip_reslog;
54423 +
54424 +#ifdef CONFIG_GRKERNSEC_RESLOG
54425 + gr_log_resource(task, res, wanted, gt);
54426 +#endif
54427 + skip_reslog:
54428 +
54429 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54430 + return;
54431 +
54432 + acl = task->acl;
54433 +
54434 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54435 + !(acl->resmask & (1 << (unsigned short) res))))
54436 + return;
54437 +
54438 + if (wanted >= acl->res[res].rlim_cur) {
54439 + unsigned long res_add;
54440 +
54441 + res_add = wanted;
54442 + switch (res) {
54443 + case RLIMIT_CPU:
54444 + res_add += GR_RLIM_CPU_BUMP;
54445 + break;
54446 + case RLIMIT_FSIZE:
54447 + res_add += GR_RLIM_FSIZE_BUMP;
54448 + break;
54449 + case RLIMIT_DATA:
54450 + res_add += GR_RLIM_DATA_BUMP;
54451 + break;
54452 + case RLIMIT_STACK:
54453 + res_add += GR_RLIM_STACK_BUMP;
54454 + break;
54455 + case RLIMIT_CORE:
54456 + res_add += GR_RLIM_CORE_BUMP;
54457 + break;
54458 + case RLIMIT_RSS:
54459 + res_add += GR_RLIM_RSS_BUMP;
54460 + break;
54461 + case RLIMIT_NPROC:
54462 + res_add += GR_RLIM_NPROC_BUMP;
54463 + break;
54464 + case RLIMIT_NOFILE:
54465 + res_add += GR_RLIM_NOFILE_BUMP;
54466 + break;
54467 + case RLIMIT_MEMLOCK:
54468 + res_add += GR_RLIM_MEMLOCK_BUMP;
54469 + break;
54470 + case RLIMIT_AS:
54471 + res_add += GR_RLIM_AS_BUMP;
54472 + break;
54473 + case RLIMIT_LOCKS:
54474 + res_add += GR_RLIM_LOCKS_BUMP;
54475 + break;
54476 + case RLIMIT_SIGPENDING:
54477 + res_add += GR_RLIM_SIGPENDING_BUMP;
54478 + break;
54479 + case RLIMIT_MSGQUEUE:
54480 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54481 + break;
54482 + case RLIMIT_NICE:
54483 + res_add += GR_RLIM_NICE_BUMP;
54484 + break;
54485 + case RLIMIT_RTPRIO:
54486 + res_add += GR_RLIM_RTPRIO_BUMP;
54487 + break;
54488 + case RLIMIT_RTTIME:
54489 + res_add += GR_RLIM_RTTIME_BUMP;
54490 + break;
54491 + }
54492 +
54493 + acl->res[res].rlim_cur = res_add;
54494 +
54495 + if (wanted > acl->res[res].rlim_max)
54496 + acl->res[res].rlim_max = res_add;
54497 +
54498 + /* only log the subject filename, since resource logging is supported for
54499 + single-subject learning only */
54500 + rcu_read_lock();
54501 + cred = __task_cred(task);
54502 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54503 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54504 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54505 + "", (unsigned long) res, &task->signal->saved_ip);
54506 + rcu_read_unlock();
54507 + }
54508 +
54509 + return;
54510 +}
54511 +
54512 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54513 +void
54514 +pax_set_initial_flags(struct linux_binprm *bprm)
54515 +{
54516 + struct task_struct *task = current;
54517 + struct acl_subject_label *proc;
54518 + unsigned long flags;
54519 +
54520 + if (unlikely(!(gr_status & GR_READY)))
54521 + return;
54522 +
54523 + flags = pax_get_flags(task);
54524 +
54525 + proc = task->acl;
54526 +
54527 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54528 + flags &= ~MF_PAX_PAGEEXEC;
54529 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54530 + flags &= ~MF_PAX_SEGMEXEC;
54531 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54532 + flags &= ~MF_PAX_RANDMMAP;
54533 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54534 + flags &= ~MF_PAX_EMUTRAMP;
54535 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54536 + flags &= ~MF_PAX_MPROTECT;
54537 +
54538 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54539 + flags |= MF_PAX_PAGEEXEC;
54540 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54541 + flags |= MF_PAX_SEGMEXEC;
54542 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54543 + flags |= MF_PAX_RANDMMAP;
54544 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54545 + flags |= MF_PAX_EMUTRAMP;
54546 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54547 + flags |= MF_PAX_MPROTECT;
54548 +
54549 + pax_set_flags(task, flags);
54550 +
54551 + return;
54552 +}
54553 +#endif
54554 +
54555 +int
54556 +gr_handle_proc_ptrace(struct task_struct *task)
54557 +{
54558 + struct file *filp;
54559 + struct task_struct *tmp = task;
54560 + struct task_struct *curtemp = current;
54561 + __u32 retmode;
54562 +
54563 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54564 + if (unlikely(!(gr_status & GR_READY)))
54565 + return 0;
54566 +#endif
54567 +
54568 + read_lock(&tasklist_lock);
54569 + read_lock(&grsec_exec_file_lock);
54570 + filp = task->exec_file;
54571 +
54572 + while (tmp->pid > 0) {
54573 + if (tmp == curtemp)
54574 + break;
54575 + tmp = tmp->real_parent;
54576 + }
54577 +
54578 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54579 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54580 + read_unlock(&grsec_exec_file_lock);
54581 + read_unlock(&tasklist_lock);
54582 + return 1;
54583 + }
54584 +
54585 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54586 + if (!(gr_status & GR_READY)) {
54587 + read_unlock(&grsec_exec_file_lock);
54588 + read_unlock(&tasklist_lock);
54589 + return 0;
54590 + }
54591 +#endif
54592 +
54593 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54594 + read_unlock(&grsec_exec_file_lock);
54595 + read_unlock(&tasklist_lock);
54596 +
54597 + if (retmode & GR_NOPTRACE)
54598 + return 1;
54599 +
54600 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54601 + && (current->acl != task->acl || (current->acl != current->role->root_label
54602 + && current->pid != task->pid)))
54603 + return 1;
54604 +
54605 + return 0;
54606 +}
54607 +
54608 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54609 +{
54610 + if (unlikely(!(gr_status & GR_READY)))
54611 + return;
54612 +
54613 + if (!(current->role->roletype & GR_ROLE_GOD))
54614 + return;
54615 +
54616 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54617 + p->role->rolename, gr_task_roletype_to_char(p),
54618 + p->acl->filename);
54619 +}
54620 +
54621 +int
54622 +gr_handle_ptrace(struct task_struct *task, const long request)
54623 +{
54624 + struct task_struct *tmp = task;
54625 + struct task_struct *curtemp = current;
54626 + __u32 retmode;
54627 +
54628 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54629 + if (unlikely(!(gr_status & GR_READY)))
54630 + return 0;
54631 +#endif
54632 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54633 + read_lock(&tasklist_lock);
54634 + while (tmp->pid > 0) {
54635 + if (tmp == curtemp)
54636 + break;
54637 + tmp = tmp->real_parent;
54638 + }
54639 +
54640 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54641 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54642 + read_unlock(&tasklist_lock);
54643 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54644 + return 1;
54645 + }
54646 + read_unlock(&tasklist_lock);
54647 + }
54648 +
54649 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54650 + if (!(gr_status & GR_READY))
54651 + return 0;
54652 +#endif
54653 +
54654 + read_lock(&grsec_exec_file_lock);
54655 + if (unlikely(!task->exec_file)) {
54656 + read_unlock(&grsec_exec_file_lock);
54657 + return 0;
54658 + }
54659 +
54660 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54661 + read_unlock(&grsec_exec_file_lock);
54662 +
54663 + if (retmode & GR_NOPTRACE) {
54664 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54665 + return 1;
54666 + }
54667 +
54668 + if (retmode & GR_PTRACERD) {
54669 + switch (request) {
54670 + case PTRACE_SEIZE:
54671 + case PTRACE_POKETEXT:
54672 + case PTRACE_POKEDATA:
54673 + case PTRACE_POKEUSR:
54674 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54675 + case PTRACE_SETREGS:
54676 + case PTRACE_SETFPREGS:
54677 +#endif
54678 +#ifdef CONFIG_X86
54679 + case PTRACE_SETFPXREGS:
54680 +#endif
54681 +#ifdef CONFIG_ALTIVEC
54682 + case PTRACE_SETVRREGS:
54683 +#endif
54684 + return 1;
54685 + default:
54686 + return 0;
54687 + }
54688 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54689 + !(current->role->roletype & GR_ROLE_GOD) &&
54690 + (current->acl != task->acl)) {
54691 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54692 + return 1;
54693 + }
54694 +
54695 + return 0;
54696 +}
54697 +
54698 +static int is_writable_mmap(const struct file *filp)
54699 +{
54700 + struct task_struct *task = current;
54701 + struct acl_object_label *obj, *obj2;
54702 +
54703 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54704 + !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))) {
54705 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54706 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54707 + task->role->root_label);
54708 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54709 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54710 + return 1;
54711 + }
54712 + }
54713 + return 0;
54714 +}
54715 +
54716 +int
54717 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54718 +{
54719 + __u32 mode;
54720 +
54721 + if (unlikely(!file || !(prot & PROT_EXEC)))
54722 + return 1;
54723 +
54724 + if (is_writable_mmap(file))
54725 + return 0;
54726 +
54727 + mode =
54728 + gr_search_file(file->f_path.dentry,
54729 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54730 + file->f_path.mnt);
54731 +
54732 + if (!gr_tpe_allow(file))
54733 + return 0;
54734 +
54735 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54736 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54737 + return 0;
54738 + } else if (unlikely(!(mode & GR_EXEC))) {
54739 + return 0;
54740 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54741 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54742 + return 1;
54743 + }
54744 +
54745 + return 1;
54746 +}
54747 +
54748 +int
54749 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54750 +{
54751 + __u32 mode;
54752 +
54753 + if (unlikely(!file || !(prot & PROT_EXEC)))
54754 + return 1;
54755 +
54756 + if (is_writable_mmap(file))
54757 + return 0;
54758 +
54759 + mode =
54760 + gr_search_file(file->f_path.dentry,
54761 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54762 + file->f_path.mnt);
54763 +
54764 + if (!gr_tpe_allow(file))
54765 + return 0;
54766 +
54767 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54768 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54769 + return 0;
54770 + } else if (unlikely(!(mode & GR_EXEC))) {
54771 + return 0;
54772 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54773 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54774 + return 1;
54775 + }
54776 +
54777 + return 1;
54778 +}
54779 +
54780 +void
54781 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54782 +{
54783 + unsigned long runtime;
54784 + unsigned long cputime;
54785 + unsigned int wday, cday;
54786 + __u8 whr, chr;
54787 + __u8 wmin, cmin;
54788 + __u8 wsec, csec;
54789 + struct timespec timeval;
54790 +
54791 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54792 + !(task->acl->mode & GR_PROCACCT)))
54793 + return;
54794 +
54795 + do_posix_clock_monotonic_gettime(&timeval);
54796 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54797 + wday = runtime / (3600 * 24);
54798 + runtime -= wday * (3600 * 24);
54799 + whr = runtime / 3600;
54800 + runtime -= whr * 3600;
54801 + wmin = runtime / 60;
54802 + runtime -= wmin * 60;
54803 + wsec = runtime;
54804 +
54805 + cputime = (task->utime + task->stime) / HZ;
54806 + cday = cputime / (3600 * 24);
54807 + cputime -= cday * (3600 * 24);
54808 + chr = cputime / 3600;
54809 + cputime -= chr * 3600;
54810 + cmin = cputime / 60;
54811 + cputime -= cmin * 60;
54812 + csec = cputime;
54813 +
54814 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54815 +
54816 + return;
54817 +}
54818 +
54819 +void gr_set_kernel_label(struct task_struct *task)
54820 +{
54821 + if (gr_status & GR_READY) {
54822 + task->role = kernel_role;
54823 + task->acl = kernel_role->root_label;
54824 + }
54825 + return;
54826 +}
54827 +
54828 +#ifdef CONFIG_TASKSTATS
54829 +int gr_is_taskstats_denied(int pid)
54830 +{
54831 + struct task_struct *task;
54832 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54833 + const struct cred *cred;
54834 +#endif
54835 + int ret = 0;
54836 +
54837 + /* restrict taskstats viewing to un-chrooted root users
54838 + who have the 'view' subject flag if the RBAC system is enabled
54839 + */
54840 +
54841 + rcu_read_lock();
54842 + read_lock(&tasklist_lock);
54843 + task = find_task_by_vpid(pid);
54844 + if (task) {
54845 +#ifdef CONFIG_GRKERNSEC_CHROOT
54846 + if (proc_is_chrooted(task))
54847 + ret = -EACCES;
54848 +#endif
54849 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54850 + cred = __task_cred(task);
54851 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54852 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54853 + ret = -EACCES;
54854 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54855 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID)) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54856 + ret = -EACCES;
54857 +#endif
54858 +#endif
54859 + if (gr_status & GR_READY) {
54860 + if (!(task->acl->mode & GR_VIEW))
54861 + ret = -EACCES;
54862 + }
54863 + } else
54864 + ret = -ENOENT;
54865 +
54866 + read_unlock(&tasklist_lock);
54867 + rcu_read_unlock();
54868 +
54869 + return ret;
54870 +}
54871 +#endif
54872 +
54873 +/* AUXV entries are filled via a descendant of search_binary_handler
54874 + after we've already applied the subject for the target
54875 +*/
54876 +int gr_acl_enable_at_secure(void)
54877 +{
54878 + if (unlikely(!(gr_status & GR_READY)))
54879 + return 0;
54880 +
54881 + if (current->acl->mode & GR_ATSECURE)
54882 + return 1;
54883 +
54884 + return 0;
54885 +}
54886 +
54887 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54888 +{
54889 + struct task_struct *task = current;
54890 + struct dentry *dentry = file->f_path.dentry;
54891 + struct vfsmount *mnt = file->f_path.mnt;
54892 + struct acl_object_label *obj, *tmp;
54893 + struct acl_subject_label *subj;
54894 + unsigned int bufsize;
54895 + int is_not_root;
54896 + char *path;
54897 + dev_t dev = __get_dev(dentry);
54898 +
54899 + if (unlikely(!(gr_status & GR_READY)))
54900 + return 1;
54901 +
54902 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54903 + return 1;
54904 +
54905 + /* ignore Eric Biederman */
54906 + if (IS_PRIVATE(dentry->d_inode))
54907 + return 1;
54908 +
54909 + subj = task->acl;
54910 + read_lock(&gr_inode_lock);
54911 + do {
54912 + obj = lookup_acl_obj_label(ino, dev, subj);
54913 + if (obj != NULL) {
54914 + read_unlock(&gr_inode_lock);
54915 + return (obj->mode & GR_FIND) ? 1 : 0;
54916 + }
54917 + } while ((subj = subj->parent_subject));
54918 + read_unlock(&gr_inode_lock);
54919 +
54920 + /* this is purely an optimization since we're looking for an object
54921 + for the directory we're doing a readdir on
54922 + if it's possible for any globbed object to match the entry we're
54923 + filling into the directory, then the object we find here will be
54924 + an anchor point with attached globbed objects
54925 + */
54926 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54927 + if (obj->globbed == NULL)
54928 + return (obj->mode & GR_FIND) ? 1 : 0;
54929 +
54930 + is_not_root = ((obj->filename[0] == '/') &&
54931 + (obj->filename[1] == '\0')) ? 0 : 1;
54932 + bufsize = PAGE_SIZE - namelen - is_not_root;
54933 +
54934 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54935 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54936 + return 1;
54937 +
54938 + preempt_disable();
54939 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54940 + bufsize);
54941 +
54942 + bufsize = strlen(path);
54943 +
54944 + /* if base is "/", don't append an additional slash */
54945 + if (is_not_root)
54946 + *(path + bufsize) = '/';
54947 + memcpy(path + bufsize + is_not_root, name, namelen);
54948 + *(path + bufsize + namelen + is_not_root) = '\0';
54949 +
54950 + tmp = obj->globbed;
54951 + while (tmp) {
54952 + if (!glob_match(tmp->filename, path)) {
54953 + preempt_enable();
54954 + return (tmp->mode & GR_FIND) ? 1 : 0;
54955 + }
54956 + tmp = tmp->next;
54957 + }
54958 + preempt_enable();
54959 + return (obj->mode & GR_FIND) ? 1 : 0;
54960 +}
54961 +
54962 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54963 +EXPORT_SYMBOL(gr_acl_is_enabled);
54964 +#endif
54965 +EXPORT_SYMBOL(gr_learn_resource);
54966 +EXPORT_SYMBOL(gr_set_kernel_label);
54967 +#ifdef CONFIG_SECURITY
54968 +EXPORT_SYMBOL(gr_check_user_change);
54969 +EXPORT_SYMBOL(gr_check_group_change);
54970 +#endif
54971 +
54972 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54973 new file mode 100644
54974 index 0000000..34fefda
54975 --- /dev/null
54976 +++ b/grsecurity/gracl_alloc.c
54977 @@ -0,0 +1,105 @@
54978 +#include <linux/kernel.h>
54979 +#include <linux/mm.h>
54980 +#include <linux/slab.h>
54981 +#include <linux/vmalloc.h>
54982 +#include <linux/gracl.h>
54983 +#include <linux/grsecurity.h>
54984 +
54985 +static unsigned long alloc_stack_next = 1;
54986 +static unsigned long alloc_stack_size = 1;
54987 +static void **alloc_stack;
54988 +
54989 +static __inline__ int
54990 +alloc_pop(void)
54991 +{
54992 + if (alloc_stack_next == 1)
54993 + return 0;
54994 +
54995 + kfree(alloc_stack[alloc_stack_next - 2]);
54996 +
54997 + alloc_stack_next--;
54998 +
54999 + return 1;
55000 +}
55001 +
55002 +static __inline__ int
55003 +alloc_push(void *buf)
55004 +{
55005 + if (alloc_stack_next >= alloc_stack_size)
55006 + return 1;
55007 +
55008 + alloc_stack[alloc_stack_next - 1] = buf;
55009 +
55010 + alloc_stack_next++;
55011 +
55012 + return 0;
55013 +}
55014 +
55015 +void *
55016 +acl_alloc(unsigned long len)
55017 +{
55018 + void *ret = NULL;
55019 +
55020 + if (!len || len > PAGE_SIZE)
55021 + goto out;
55022 +
55023 + ret = kmalloc(len, GFP_KERNEL);
55024 +
55025 + if (ret) {
55026 + if (alloc_push(ret)) {
55027 + kfree(ret);
55028 + ret = NULL;
55029 + }
55030 + }
55031 +
55032 +out:
55033 + return ret;
55034 +}
55035 +
55036 +void *
55037 +acl_alloc_num(unsigned long num, unsigned long len)
55038 +{
55039 + if (!len || (num > (PAGE_SIZE / len)))
55040 + return NULL;
55041 +
55042 + return acl_alloc(num * len);
55043 +}
55044 +
55045 +void
55046 +acl_free_all(void)
55047 +{
55048 + if (gr_acl_is_enabled() || !alloc_stack)
55049 + return;
55050 +
55051 + while (alloc_pop()) ;
55052 +
55053 + if (alloc_stack) {
55054 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55055 + kfree(alloc_stack);
55056 + else
55057 + vfree(alloc_stack);
55058 + }
55059 +
55060 + alloc_stack = NULL;
55061 + alloc_stack_size = 1;
55062 + alloc_stack_next = 1;
55063 +
55064 + return;
55065 +}
55066 +
55067 +int
55068 +acl_alloc_stack_init(unsigned long size)
55069 +{
55070 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55071 + alloc_stack =
55072 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55073 + else
55074 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55075 +
55076 + alloc_stack_size = size;
55077 +
55078 + if (!alloc_stack)
55079 + return 0;
55080 + else
55081 + return 1;
55082 +}
55083 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55084 new file mode 100644
55085 index 0000000..6d21049
55086 --- /dev/null
55087 +++ b/grsecurity/gracl_cap.c
55088 @@ -0,0 +1,110 @@
55089 +#include <linux/kernel.h>
55090 +#include <linux/module.h>
55091 +#include <linux/sched.h>
55092 +#include <linux/gracl.h>
55093 +#include <linux/grsecurity.h>
55094 +#include <linux/grinternal.h>
55095 +
55096 +extern const char *captab_log[];
55097 +extern int captab_log_entries;
55098 +
55099 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55100 +{
55101 + struct acl_subject_label *curracl;
55102 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55103 + kernel_cap_t cap_audit = __cap_empty_set;
55104 +
55105 + if (!gr_acl_is_enabled())
55106 + return 1;
55107 +
55108 + curracl = task->acl;
55109 +
55110 + cap_drop = curracl->cap_lower;
55111 + cap_mask = curracl->cap_mask;
55112 + cap_audit = curracl->cap_invert_audit;
55113 +
55114 + while ((curracl = curracl->parent_subject)) {
55115 + /* if the cap isn't specified in the current computed mask but is specified in the
55116 + current level subject, and is lowered in the current level subject, then add
55117 + it to the set of dropped capabilities
55118 + otherwise, add the current level subject's mask to the current computed mask
55119 + */
55120 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55121 + cap_raise(cap_mask, cap);
55122 + if (cap_raised(curracl->cap_lower, cap))
55123 + cap_raise(cap_drop, cap);
55124 + if (cap_raised(curracl->cap_invert_audit, cap))
55125 + cap_raise(cap_audit, cap);
55126 + }
55127 + }
55128 +
55129 + if (!cap_raised(cap_drop, cap)) {
55130 + if (cap_raised(cap_audit, cap))
55131 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55132 + return 1;
55133 + }
55134 +
55135 + curracl = task->acl;
55136 +
55137 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55138 + && cap_raised(cred->cap_effective, cap)) {
55139 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55140 + task->role->roletype, cred->uid,
55141 + cred->gid, task->exec_file ?
55142 + gr_to_filename(task->exec_file->f_path.dentry,
55143 + task->exec_file->f_path.mnt) : curracl->filename,
55144 + curracl->filename, 0UL,
55145 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55146 + return 1;
55147 + }
55148 +
55149 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55150 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55151 +
55152 + return 0;
55153 +}
55154 +
55155 +int
55156 +gr_acl_is_capable(const int cap)
55157 +{
55158 + return gr_task_acl_is_capable(current, current_cred(), cap);
55159 +}
55160 +
55161 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55162 +{
55163 + struct acl_subject_label *curracl;
55164 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55165 +
55166 + if (!gr_acl_is_enabled())
55167 + return 1;
55168 +
55169 + curracl = task->acl;
55170 +
55171 + cap_drop = curracl->cap_lower;
55172 + cap_mask = curracl->cap_mask;
55173 +
55174 + while ((curracl = curracl->parent_subject)) {
55175 + /* if the cap isn't specified in the current computed mask but is specified in the
55176 + current level subject, and is lowered in the current level subject, then add
55177 + it to the set of dropped capabilities
55178 + otherwise, add the current level subject's mask to the current computed mask
55179 + */
55180 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55181 + cap_raise(cap_mask, cap);
55182 + if (cap_raised(curracl->cap_lower, cap))
55183 + cap_raise(cap_drop, cap);
55184 + }
55185 + }
55186 +
55187 + if (!cap_raised(cap_drop, cap))
55188 + return 1;
55189 +
55190 + return 0;
55191 +}
55192 +
55193 +int
55194 +gr_acl_is_capable_nolog(const int cap)
55195 +{
55196 + return gr_task_acl_is_capable_nolog(current, cap);
55197 +}
55198 +
55199 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55200 new file mode 100644
55201 index 0000000..88d0e87
55202 --- /dev/null
55203 +++ b/grsecurity/gracl_fs.c
55204 @@ -0,0 +1,435 @@
55205 +#include <linux/kernel.h>
55206 +#include <linux/sched.h>
55207 +#include <linux/types.h>
55208 +#include <linux/fs.h>
55209 +#include <linux/file.h>
55210 +#include <linux/stat.h>
55211 +#include <linux/grsecurity.h>
55212 +#include <linux/grinternal.h>
55213 +#include <linux/gracl.h>
55214 +
55215 +umode_t
55216 +gr_acl_umask(void)
55217 +{
55218 + if (unlikely(!gr_acl_is_enabled()))
55219 + return 0;
55220 +
55221 + return current->role->umask;
55222 +}
55223 +
55224 +__u32
55225 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55226 + const struct vfsmount * mnt)
55227 +{
55228 + __u32 mode;
55229 +
55230 + if (unlikely(!dentry->d_inode))
55231 + return GR_FIND;
55232 +
55233 + mode =
55234 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55235 +
55236 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55237 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55238 + return mode;
55239 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55240 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55241 + return 0;
55242 + } else if (unlikely(!(mode & GR_FIND)))
55243 + return 0;
55244 +
55245 + return GR_FIND;
55246 +}
55247 +
55248 +__u32
55249 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55250 + int acc_mode)
55251 +{
55252 + __u32 reqmode = GR_FIND;
55253 + __u32 mode;
55254 +
55255 + if (unlikely(!dentry->d_inode))
55256 + return reqmode;
55257 +
55258 + if (acc_mode & MAY_APPEND)
55259 + reqmode |= GR_APPEND;
55260 + else if (acc_mode & MAY_WRITE)
55261 + reqmode |= GR_WRITE;
55262 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55263 + reqmode |= GR_READ;
55264 +
55265 + mode =
55266 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55267 + mnt);
55268 +
55269 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55270 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55271 + reqmode & GR_READ ? " reading" : "",
55272 + reqmode & GR_WRITE ? " writing" : reqmode &
55273 + GR_APPEND ? " appending" : "");
55274 + return reqmode;
55275 + } else
55276 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55277 + {
55278 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55279 + reqmode & GR_READ ? " reading" : "",
55280 + reqmode & GR_WRITE ? " writing" : reqmode &
55281 + GR_APPEND ? " appending" : "");
55282 + return 0;
55283 + } else if (unlikely((mode & reqmode) != reqmode))
55284 + return 0;
55285 +
55286 + return reqmode;
55287 +}
55288 +
55289 +__u32
55290 +gr_acl_handle_creat(const struct dentry * dentry,
55291 + const struct dentry * p_dentry,
55292 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55293 + const int imode)
55294 +{
55295 + __u32 reqmode = GR_WRITE | GR_CREATE;
55296 + __u32 mode;
55297 +
55298 + if (acc_mode & MAY_APPEND)
55299 + reqmode |= GR_APPEND;
55300 + // if a directory was required or the directory already exists, then
55301 + // don't count this open as a read
55302 + if ((acc_mode & MAY_READ) &&
55303 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55304 + reqmode |= GR_READ;
55305 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55306 + reqmode |= GR_SETID;
55307 +
55308 + mode =
55309 + gr_check_create(dentry, p_dentry, p_mnt,
55310 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55311 +
55312 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55313 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55314 + reqmode & GR_READ ? " reading" : "",
55315 + reqmode & GR_WRITE ? " writing" : reqmode &
55316 + GR_APPEND ? " appending" : "");
55317 + return reqmode;
55318 + } else
55319 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55320 + {
55321 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55322 + reqmode & GR_READ ? " reading" : "",
55323 + reqmode & GR_WRITE ? " writing" : reqmode &
55324 + GR_APPEND ? " appending" : "");
55325 + return 0;
55326 + } else if (unlikely((mode & reqmode) != reqmode))
55327 + return 0;
55328 +
55329 + return reqmode;
55330 +}
55331 +
55332 +__u32
55333 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55334 + const int fmode)
55335 +{
55336 + __u32 mode, reqmode = GR_FIND;
55337 +
55338 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55339 + reqmode |= GR_EXEC;
55340 + if (fmode & S_IWOTH)
55341 + reqmode |= GR_WRITE;
55342 + if (fmode & S_IROTH)
55343 + reqmode |= GR_READ;
55344 +
55345 + mode =
55346 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55347 + mnt);
55348 +
55349 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55350 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55351 + reqmode & GR_READ ? " reading" : "",
55352 + reqmode & GR_WRITE ? " writing" : "",
55353 + reqmode & GR_EXEC ? " executing" : "");
55354 + return reqmode;
55355 + } else
55356 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55357 + {
55358 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55359 + reqmode & GR_READ ? " reading" : "",
55360 + reqmode & GR_WRITE ? " writing" : "",
55361 + reqmode & GR_EXEC ? " executing" : "");
55362 + return 0;
55363 + } else if (unlikely((mode & reqmode) != reqmode))
55364 + return 0;
55365 +
55366 + return reqmode;
55367 +}
55368 +
55369 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55370 +{
55371 + __u32 mode;
55372 +
55373 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55374 +
55375 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55376 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55377 + return mode;
55378 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55379 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55380 + return 0;
55381 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55382 + return 0;
55383 +
55384 + return (reqmode);
55385 +}
55386 +
55387 +__u32
55388 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55389 +{
55390 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55391 +}
55392 +
55393 +__u32
55394 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55395 +{
55396 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55397 +}
55398 +
55399 +__u32
55400 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55401 +{
55402 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55403 +}
55404 +
55405 +__u32
55406 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55407 +{
55408 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55409 +}
55410 +
55411 +__u32
55412 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55413 + umode_t *modeptr)
55414 +{
55415 + umode_t mode;
55416 +
55417 + *modeptr &= ~gr_acl_umask();
55418 + mode = *modeptr;
55419 +
55420 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55421 + return 1;
55422 +
55423 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55424 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55425 + GR_CHMOD_ACL_MSG);
55426 + } else {
55427 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55428 + }
55429 +}
55430 +
55431 +__u32
55432 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55433 +{
55434 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55435 +}
55436 +
55437 +__u32
55438 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55439 +{
55440 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55441 +}
55442 +
55443 +__u32
55444 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55445 +{
55446 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55447 +}
55448 +
55449 +__u32
55450 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55451 +{
55452 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55453 + GR_UNIXCONNECT_ACL_MSG);
55454 +}
55455 +
55456 +/* hardlinks require at minimum create and link permission,
55457 + any additional privilege required is based on the
55458 + privilege of the file being linked to
55459 +*/
55460 +__u32
55461 +gr_acl_handle_link(const struct dentry * new_dentry,
55462 + const struct dentry * parent_dentry,
55463 + const struct vfsmount * parent_mnt,
55464 + const struct dentry * old_dentry,
55465 + const struct vfsmount * old_mnt, const char *to)
55466 +{
55467 + __u32 mode;
55468 + __u32 needmode = GR_CREATE | GR_LINK;
55469 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55470 +
55471 + mode =
55472 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55473 + old_mnt);
55474 +
55475 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55476 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55477 + return mode;
55478 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55479 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55480 + return 0;
55481 + } else if (unlikely((mode & needmode) != needmode))
55482 + return 0;
55483 +
55484 + return 1;
55485 +}
55486 +
55487 +__u32
55488 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55489 + const struct dentry * parent_dentry,
55490 + const struct vfsmount * parent_mnt, const char *from)
55491 +{
55492 + __u32 needmode = GR_WRITE | GR_CREATE;
55493 + __u32 mode;
55494 +
55495 + mode =
55496 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55497 + GR_CREATE | GR_AUDIT_CREATE |
55498 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55499 +
55500 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55501 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55502 + return mode;
55503 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55504 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55505 + return 0;
55506 + } else if (unlikely((mode & needmode) != needmode))
55507 + return 0;
55508 +
55509 + return (GR_WRITE | GR_CREATE);
55510 +}
55511 +
55512 +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)
55513 +{
55514 + __u32 mode;
55515 +
55516 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55517 +
55518 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55519 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55520 + return mode;
55521 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55522 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55523 + return 0;
55524 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55525 + return 0;
55526 +
55527 + return (reqmode);
55528 +}
55529 +
55530 +__u32
55531 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55532 + const struct dentry * parent_dentry,
55533 + const struct vfsmount * parent_mnt,
55534 + const int mode)
55535 +{
55536 + __u32 reqmode = GR_WRITE | GR_CREATE;
55537 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55538 + reqmode |= GR_SETID;
55539 +
55540 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55541 + reqmode, GR_MKNOD_ACL_MSG);
55542 +}
55543 +
55544 +__u32
55545 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55546 + const struct dentry *parent_dentry,
55547 + const struct vfsmount *parent_mnt)
55548 +{
55549 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55550 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55551 +}
55552 +
55553 +#define RENAME_CHECK_SUCCESS(old, new) \
55554 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55555 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55556 +
55557 +int
55558 +gr_acl_handle_rename(struct dentry *new_dentry,
55559 + struct dentry *parent_dentry,
55560 + const struct vfsmount *parent_mnt,
55561 + struct dentry *old_dentry,
55562 + struct inode *old_parent_inode,
55563 + struct vfsmount *old_mnt, const char *newname)
55564 +{
55565 + __u32 comp1, comp2;
55566 + int error = 0;
55567 +
55568 + if (unlikely(!gr_acl_is_enabled()))
55569 + return 0;
55570 +
55571 + if (!new_dentry->d_inode) {
55572 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55573 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55574 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55575 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55576 + GR_DELETE | GR_AUDIT_DELETE |
55577 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55578 + GR_SUPPRESS, old_mnt);
55579 + } else {
55580 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55581 + GR_CREATE | GR_DELETE |
55582 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55583 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55584 + GR_SUPPRESS, parent_mnt);
55585 + comp2 =
55586 + gr_search_file(old_dentry,
55587 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55588 + GR_DELETE | GR_AUDIT_DELETE |
55589 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55590 + }
55591 +
55592 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55593 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55594 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55595 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55596 + && !(comp2 & GR_SUPPRESS)) {
55597 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55598 + error = -EACCES;
55599 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55600 + error = -EACCES;
55601 +
55602 + return error;
55603 +}
55604 +
55605 +void
55606 +gr_acl_handle_exit(void)
55607 +{
55608 + u16 id;
55609 + char *rolename;
55610 + struct file *exec_file;
55611 +
55612 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55613 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55614 + id = current->acl_role_id;
55615 + rolename = current->role->rolename;
55616 + gr_set_acls(1);
55617 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55618 + }
55619 +
55620 + write_lock(&grsec_exec_file_lock);
55621 + exec_file = current->exec_file;
55622 + current->exec_file = NULL;
55623 + write_unlock(&grsec_exec_file_lock);
55624 +
55625 + if (exec_file)
55626 + fput(exec_file);
55627 +}
55628 +
55629 +int
55630 +gr_acl_handle_procpidmem(const struct task_struct *task)
55631 +{
55632 + if (unlikely(!gr_acl_is_enabled()))
55633 + return 0;
55634 +
55635 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55636 + return -EACCES;
55637 +
55638 + return 0;
55639 +}
55640 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55641 new file mode 100644
55642 index 0000000..58800a7
55643 --- /dev/null
55644 +++ b/grsecurity/gracl_ip.c
55645 @@ -0,0 +1,384 @@
55646 +#include <linux/kernel.h>
55647 +#include <asm/uaccess.h>
55648 +#include <asm/errno.h>
55649 +#include <net/sock.h>
55650 +#include <linux/file.h>
55651 +#include <linux/fs.h>
55652 +#include <linux/net.h>
55653 +#include <linux/in.h>
55654 +#include <linux/skbuff.h>
55655 +#include <linux/ip.h>
55656 +#include <linux/udp.h>
55657 +#include <linux/types.h>
55658 +#include <linux/sched.h>
55659 +#include <linux/netdevice.h>
55660 +#include <linux/inetdevice.h>
55661 +#include <linux/gracl.h>
55662 +#include <linux/grsecurity.h>
55663 +#include <linux/grinternal.h>
55664 +
55665 +#define GR_BIND 0x01
55666 +#define GR_CONNECT 0x02
55667 +#define GR_INVERT 0x04
55668 +#define GR_BINDOVERRIDE 0x08
55669 +#define GR_CONNECTOVERRIDE 0x10
55670 +#define GR_SOCK_FAMILY 0x20
55671 +
55672 +static const char * gr_protocols[IPPROTO_MAX] = {
55673 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55674 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55675 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55676 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55677 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55678 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55679 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55680 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55681 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55682 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55683 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55684 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55685 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55686 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55687 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55688 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55689 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55690 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55691 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55692 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55693 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55694 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55695 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55696 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55697 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55698 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55699 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55700 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55701 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55702 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55703 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55704 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55705 + };
55706 +
55707 +static const char * gr_socktypes[SOCK_MAX] = {
55708 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55709 + "unknown:7", "unknown:8", "unknown:9", "packet"
55710 + };
55711 +
55712 +static const char * gr_sockfamilies[AF_MAX+1] = {
55713 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55714 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55715 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55716 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55717 + };
55718 +
55719 +const char *
55720 +gr_proto_to_name(unsigned char proto)
55721 +{
55722 + return gr_protocols[proto];
55723 +}
55724 +
55725 +const char *
55726 +gr_socktype_to_name(unsigned char type)
55727 +{
55728 + return gr_socktypes[type];
55729 +}
55730 +
55731 +const char *
55732 +gr_sockfamily_to_name(unsigned char family)
55733 +{
55734 + return gr_sockfamilies[family];
55735 +}
55736 +
55737 +int
55738 +gr_search_socket(const int domain, const int type, const int protocol)
55739 +{
55740 + struct acl_subject_label *curr;
55741 + const struct cred *cred = current_cred();
55742 +
55743 + if (unlikely(!gr_acl_is_enabled()))
55744 + goto exit;
55745 +
55746 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55747 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55748 + goto exit; // let the kernel handle it
55749 +
55750 + curr = current->acl;
55751 +
55752 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55753 + /* the family is allowed, if this is PF_INET allow it only if
55754 + the extra sock type/protocol checks pass */
55755 + if (domain == PF_INET)
55756 + goto inet_check;
55757 + goto exit;
55758 + } else {
55759 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55760 + __u32 fakeip = 0;
55761 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55762 + current->role->roletype, cred->uid,
55763 + cred->gid, current->exec_file ?
55764 + gr_to_filename(current->exec_file->f_path.dentry,
55765 + current->exec_file->f_path.mnt) :
55766 + curr->filename, curr->filename,
55767 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55768 + &current->signal->saved_ip);
55769 + goto exit;
55770 + }
55771 + goto exit_fail;
55772 + }
55773 +
55774 +inet_check:
55775 + /* the rest of this checking is for IPv4 only */
55776 + if (!curr->ips)
55777 + goto exit;
55778 +
55779 + if ((curr->ip_type & (1 << type)) &&
55780 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55781 + goto exit;
55782 +
55783 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55784 + /* we don't place acls on raw sockets , and sometimes
55785 + dgram/ip sockets are opened for ioctl and not
55786 + bind/connect, so we'll fake a bind learn log */
55787 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55788 + __u32 fakeip = 0;
55789 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55790 + current->role->roletype, cred->uid,
55791 + cred->gid, current->exec_file ?
55792 + gr_to_filename(current->exec_file->f_path.dentry,
55793 + current->exec_file->f_path.mnt) :
55794 + curr->filename, curr->filename,
55795 + &fakeip, 0, type,
55796 + protocol, GR_CONNECT, &current->signal->saved_ip);
55797 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55798 + __u32 fakeip = 0;
55799 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55800 + current->role->roletype, cred->uid,
55801 + cred->gid, current->exec_file ?
55802 + gr_to_filename(current->exec_file->f_path.dentry,
55803 + current->exec_file->f_path.mnt) :
55804 + curr->filename, curr->filename,
55805 + &fakeip, 0, type,
55806 + protocol, GR_BIND, &current->signal->saved_ip);
55807 + }
55808 + /* we'll log when they use connect or bind */
55809 + goto exit;
55810 + }
55811 +
55812 +exit_fail:
55813 + if (domain == PF_INET)
55814 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55815 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55816 + else
55817 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55818 + gr_socktype_to_name(type), protocol);
55819 +
55820 + return 0;
55821 +exit:
55822 + return 1;
55823 +}
55824 +
55825 +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)
55826 +{
55827 + if ((ip->mode & mode) &&
55828 + (ip_port >= ip->low) &&
55829 + (ip_port <= ip->high) &&
55830 + ((ntohl(ip_addr) & our_netmask) ==
55831 + (ntohl(our_addr) & our_netmask))
55832 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55833 + && (ip->type & (1 << type))) {
55834 + if (ip->mode & GR_INVERT)
55835 + return 2; // specifically denied
55836 + else
55837 + return 1; // allowed
55838 + }
55839 +
55840 + return 0; // not specifically allowed, may continue parsing
55841 +}
55842 +
55843 +static int
55844 +gr_search_connectbind(const int full_mode, struct sock *sk,
55845 + struct sockaddr_in *addr, const int type)
55846 +{
55847 + char iface[IFNAMSIZ] = {0};
55848 + struct acl_subject_label *curr;
55849 + struct acl_ip_label *ip;
55850 + struct inet_sock *isk;
55851 + struct net_device *dev;
55852 + struct in_device *idev;
55853 + unsigned long i;
55854 + int ret;
55855 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55856 + __u32 ip_addr = 0;
55857 + __u32 our_addr;
55858 + __u32 our_netmask;
55859 + char *p;
55860 + __u16 ip_port = 0;
55861 + const struct cred *cred = current_cred();
55862 +
55863 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55864 + return 0;
55865 +
55866 + curr = current->acl;
55867 + isk = inet_sk(sk);
55868 +
55869 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55870 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55871 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55872 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55873 + struct sockaddr_in saddr;
55874 + int err;
55875 +
55876 + saddr.sin_family = AF_INET;
55877 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55878 + saddr.sin_port = isk->inet_sport;
55879 +
55880 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55881 + if (err)
55882 + return err;
55883 +
55884 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55885 + if (err)
55886 + return err;
55887 + }
55888 +
55889 + if (!curr->ips)
55890 + return 0;
55891 +
55892 + ip_addr = addr->sin_addr.s_addr;
55893 + ip_port = ntohs(addr->sin_port);
55894 +
55895 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55896 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55897 + current->role->roletype, cred->uid,
55898 + cred->gid, current->exec_file ?
55899 + gr_to_filename(current->exec_file->f_path.dentry,
55900 + current->exec_file->f_path.mnt) :
55901 + curr->filename, curr->filename,
55902 + &ip_addr, ip_port, type,
55903 + sk->sk_protocol, mode, &current->signal->saved_ip);
55904 + return 0;
55905 + }
55906 +
55907 + for (i = 0; i < curr->ip_num; i++) {
55908 + ip = *(curr->ips + i);
55909 + if (ip->iface != NULL) {
55910 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55911 + p = strchr(iface, ':');
55912 + if (p != NULL)
55913 + *p = '\0';
55914 + dev = dev_get_by_name(sock_net(sk), iface);
55915 + if (dev == NULL)
55916 + continue;
55917 + idev = in_dev_get(dev);
55918 + if (idev == NULL) {
55919 + dev_put(dev);
55920 + continue;
55921 + }
55922 + rcu_read_lock();
55923 + for_ifa(idev) {
55924 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55925 + our_addr = ifa->ifa_address;
55926 + our_netmask = 0xffffffff;
55927 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55928 + if (ret == 1) {
55929 + rcu_read_unlock();
55930 + in_dev_put(idev);
55931 + dev_put(dev);
55932 + return 0;
55933 + } else if (ret == 2) {
55934 + rcu_read_unlock();
55935 + in_dev_put(idev);
55936 + dev_put(dev);
55937 + goto denied;
55938 + }
55939 + }
55940 + } endfor_ifa(idev);
55941 + rcu_read_unlock();
55942 + in_dev_put(idev);
55943 + dev_put(dev);
55944 + } else {
55945 + our_addr = ip->addr;
55946 + our_netmask = ip->netmask;
55947 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55948 + if (ret == 1)
55949 + return 0;
55950 + else if (ret == 2)
55951 + goto denied;
55952 + }
55953 + }
55954 +
55955 +denied:
55956 + if (mode == GR_BIND)
55957 + 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));
55958 + else if (mode == GR_CONNECT)
55959 + 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));
55960 +
55961 + return -EACCES;
55962 +}
55963 +
55964 +int
55965 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55966 +{
55967 + /* always allow disconnection of dgram sockets with connect */
55968 + if (addr->sin_family == AF_UNSPEC)
55969 + return 0;
55970 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55971 +}
55972 +
55973 +int
55974 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55975 +{
55976 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55977 +}
55978 +
55979 +int gr_search_listen(struct socket *sock)
55980 +{
55981 + struct sock *sk = sock->sk;
55982 + struct sockaddr_in addr;
55983 +
55984 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55985 + addr.sin_port = inet_sk(sk)->inet_sport;
55986 +
55987 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55988 +}
55989 +
55990 +int gr_search_accept(struct socket *sock)
55991 +{
55992 + struct sock *sk = sock->sk;
55993 + struct sockaddr_in addr;
55994 +
55995 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55996 + addr.sin_port = inet_sk(sk)->inet_sport;
55997 +
55998 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55999 +}
56000 +
56001 +int
56002 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56003 +{
56004 + if (addr)
56005 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56006 + else {
56007 + struct sockaddr_in sin;
56008 + const struct inet_sock *inet = inet_sk(sk);
56009 +
56010 + sin.sin_addr.s_addr = inet->inet_daddr;
56011 + sin.sin_port = inet->inet_dport;
56012 +
56013 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56014 + }
56015 +}
56016 +
56017 +int
56018 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56019 +{
56020 + struct sockaddr_in sin;
56021 +
56022 + if (unlikely(skb->len < sizeof (struct udphdr)))
56023 + return 0; // skip this packet
56024 +
56025 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56026 + sin.sin_port = udp_hdr(skb)->source;
56027 +
56028 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56029 +}
56030 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56031 new file mode 100644
56032 index 0000000..25f54ef
56033 --- /dev/null
56034 +++ b/grsecurity/gracl_learn.c
56035 @@ -0,0 +1,207 @@
56036 +#include <linux/kernel.h>
56037 +#include <linux/mm.h>
56038 +#include <linux/sched.h>
56039 +#include <linux/poll.h>
56040 +#include <linux/string.h>
56041 +#include <linux/file.h>
56042 +#include <linux/types.h>
56043 +#include <linux/vmalloc.h>
56044 +#include <linux/grinternal.h>
56045 +
56046 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56047 + size_t count, loff_t *ppos);
56048 +extern int gr_acl_is_enabled(void);
56049 +
56050 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56051 +static int gr_learn_attached;
56052 +
56053 +/* use a 512k buffer */
56054 +#define LEARN_BUFFER_SIZE (512 * 1024)
56055 +
56056 +static DEFINE_SPINLOCK(gr_learn_lock);
56057 +static DEFINE_MUTEX(gr_learn_user_mutex);
56058 +
56059 +/* we need to maintain two buffers, so that the kernel context of grlearn
56060 + uses a semaphore around the userspace copying, and the other kernel contexts
56061 + use a spinlock when copying into the buffer, since they cannot sleep
56062 +*/
56063 +static char *learn_buffer;
56064 +static char *learn_buffer_user;
56065 +static int learn_buffer_len;
56066 +static int learn_buffer_user_len;
56067 +
56068 +static ssize_t
56069 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56070 +{
56071 + DECLARE_WAITQUEUE(wait, current);
56072 + ssize_t retval = 0;
56073 +
56074 + add_wait_queue(&learn_wait, &wait);
56075 + set_current_state(TASK_INTERRUPTIBLE);
56076 + do {
56077 + mutex_lock(&gr_learn_user_mutex);
56078 + spin_lock(&gr_learn_lock);
56079 + if (learn_buffer_len)
56080 + break;
56081 + spin_unlock(&gr_learn_lock);
56082 + mutex_unlock(&gr_learn_user_mutex);
56083 + if (file->f_flags & O_NONBLOCK) {
56084 + retval = -EAGAIN;
56085 + goto out;
56086 + }
56087 + if (signal_pending(current)) {
56088 + retval = -ERESTARTSYS;
56089 + goto out;
56090 + }
56091 +
56092 + schedule();
56093 + } while (1);
56094 +
56095 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56096 + learn_buffer_user_len = learn_buffer_len;
56097 + retval = learn_buffer_len;
56098 + learn_buffer_len = 0;
56099 +
56100 + spin_unlock(&gr_learn_lock);
56101 +
56102 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56103 + retval = -EFAULT;
56104 +
56105 + mutex_unlock(&gr_learn_user_mutex);
56106 +out:
56107 + set_current_state(TASK_RUNNING);
56108 + remove_wait_queue(&learn_wait, &wait);
56109 + return retval;
56110 +}
56111 +
56112 +static unsigned int
56113 +poll_learn(struct file * file, poll_table * wait)
56114 +{
56115 + poll_wait(file, &learn_wait, wait);
56116 +
56117 + if (learn_buffer_len)
56118 + return (POLLIN | POLLRDNORM);
56119 +
56120 + return 0;
56121 +}
56122 +
56123 +void
56124 +gr_clear_learn_entries(void)
56125 +{
56126 + char *tmp;
56127 +
56128 + mutex_lock(&gr_learn_user_mutex);
56129 + spin_lock(&gr_learn_lock);
56130 + tmp = learn_buffer;
56131 + learn_buffer = NULL;
56132 + spin_unlock(&gr_learn_lock);
56133 + if (tmp)
56134 + vfree(tmp);
56135 + if (learn_buffer_user != NULL) {
56136 + vfree(learn_buffer_user);
56137 + learn_buffer_user = NULL;
56138 + }
56139 + learn_buffer_len = 0;
56140 + mutex_unlock(&gr_learn_user_mutex);
56141 +
56142 + return;
56143 +}
56144 +
56145 +void
56146 +gr_add_learn_entry(const char *fmt, ...)
56147 +{
56148 + va_list args;
56149 + unsigned int len;
56150 +
56151 + if (!gr_learn_attached)
56152 + return;
56153 +
56154 + spin_lock(&gr_learn_lock);
56155 +
56156 + /* leave a gap at the end so we know when it's "full" but don't have to
56157 + compute the exact length of the string we're trying to append
56158 + */
56159 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56160 + spin_unlock(&gr_learn_lock);
56161 + wake_up_interruptible(&learn_wait);
56162 + return;
56163 + }
56164 + if (learn_buffer == NULL) {
56165 + spin_unlock(&gr_learn_lock);
56166 + return;
56167 + }
56168 +
56169 + va_start(args, fmt);
56170 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56171 + va_end(args);
56172 +
56173 + learn_buffer_len += len + 1;
56174 +
56175 + spin_unlock(&gr_learn_lock);
56176 + wake_up_interruptible(&learn_wait);
56177 +
56178 + return;
56179 +}
56180 +
56181 +static int
56182 +open_learn(struct inode *inode, struct file *file)
56183 +{
56184 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56185 + return -EBUSY;
56186 + if (file->f_mode & FMODE_READ) {
56187 + int retval = 0;
56188 + mutex_lock(&gr_learn_user_mutex);
56189 + if (learn_buffer == NULL)
56190 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56191 + if (learn_buffer_user == NULL)
56192 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56193 + if (learn_buffer == NULL) {
56194 + retval = -ENOMEM;
56195 + goto out_error;
56196 + }
56197 + if (learn_buffer_user == NULL) {
56198 + retval = -ENOMEM;
56199 + goto out_error;
56200 + }
56201 + learn_buffer_len = 0;
56202 + learn_buffer_user_len = 0;
56203 + gr_learn_attached = 1;
56204 +out_error:
56205 + mutex_unlock(&gr_learn_user_mutex);
56206 + return retval;
56207 + }
56208 + return 0;
56209 +}
56210 +
56211 +static int
56212 +close_learn(struct inode *inode, struct file *file)
56213 +{
56214 + if (file->f_mode & FMODE_READ) {
56215 + char *tmp = NULL;
56216 + mutex_lock(&gr_learn_user_mutex);
56217 + spin_lock(&gr_learn_lock);
56218 + tmp = learn_buffer;
56219 + learn_buffer = NULL;
56220 + spin_unlock(&gr_learn_lock);
56221 + if (tmp)
56222 + vfree(tmp);
56223 + if (learn_buffer_user != NULL) {
56224 + vfree(learn_buffer_user);
56225 + learn_buffer_user = NULL;
56226 + }
56227 + learn_buffer_len = 0;
56228 + learn_buffer_user_len = 0;
56229 + gr_learn_attached = 0;
56230 + mutex_unlock(&gr_learn_user_mutex);
56231 + }
56232 +
56233 + return 0;
56234 +}
56235 +
56236 +const struct file_operations grsec_fops = {
56237 + .read = read_learn,
56238 + .write = write_grsec_handler,
56239 + .open = open_learn,
56240 + .release = close_learn,
56241 + .poll = poll_learn,
56242 +};
56243 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56244 new file mode 100644
56245 index 0000000..39645c9
56246 --- /dev/null
56247 +++ b/grsecurity/gracl_res.c
56248 @@ -0,0 +1,68 @@
56249 +#include <linux/kernel.h>
56250 +#include <linux/sched.h>
56251 +#include <linux/gracl.h>
56252 +#include <linux/grinternal.h>
56253 +
56254 +static const char *restab_log[] = {
56255 + [RLIMIT_CPU] = "RLIMIT_CPU",
56256 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56257 + [RLIMIT_DATA] = "RLIMIT_DATA",
56258 + [RLIMIT_STACK] = "RLIMIT_STACK",
56259 + [RLIMIT_CORE] = "RLIMIT_CORE",
56260 + [RLIMIT_RSS] = "RLIMIT_RSS",
56261 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56262 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56263 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56264 + [RLIMIT_AS] = "RLIMIT_AS",
56265 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56266 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56267 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56268 + [RLIMIT_NICE] = "RLIMIT_NICE",
56269 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56270 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56271 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56272 +};
56273 +
56274 +void
56275 +gr_log_resource(const struct task_struct *task,
56276 + const int res, const unsigned long wanted, const int gt)
56277 +{
56278 + const struct cred *cred;
56279 + unsigned long rlim;
56280 +
56281 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56282 + return;
56283 +
56284 + // not yet supported resource
56285 + if (unlikely(!restab_log[res]))
56286 + return;
56287 +
56288 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56289 + rlim = task_rlimit_max(task, res);
56290 + else
56291 + rlim = task_rlimit(task, res);
56292 +
56293 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56294 + return;
56295 +
56296 + rcu_read_lock();
56297 + cred = __task_cred(task);
56298 +
56299 + if (res == RLIMIT_NPROC &&
56300 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56301 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56302 + goto out_rcu_unlock;
56303 + else if (res == RLIMIT_MEMLOCK &&
56304 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56305 + goto out_rcu_unlock;
56306 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56307 + goto out_rcu_unlock;
56308 + rcu_read_unlock();
56309 +
56310 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56311 +
56312 + return;
56313 +out_rcu_unlock:
56314 + rcu_read_unlock();
56315 + return;
56316 +}
56317 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56318 new file mode 100644
56319 index 0000000..25197e9
56320 --- /dev/null
56321 +++ b/grsecurity/gracl_segv.c
56322 @@ -0,0 +1,299 @@
56323 +#include <linux/kernel.h>
56324 +#include <linux/mm.h>
56325 +#include <asm/uaccess.h>
56326 +#include <asm/errno.h>
56327 +#include <asm/mman.h>
56328 +#include <net/sock.h>
56329 +#include <linux/file.h>
56330 +#include <linux/fs.h>
56331 +#include <linux/net.h>
56332 +#include <linux/in.h>
56333 +#include <linux/slab.h>
56334 +#include <linux/types.h>
56335 +#include <linux/sched.h>
56336 +#include <linux/timer.h>
56337 +#include <linux/gracl.h>
56338 +#include <linux/grsecurity.h>
56339 +#include <linux/grinternal.h>
56340 +
56341 +static struct crash_uid *uid_set;
56342 +static unsigned short uid_used;
56343 +static DEFINE_SPINLOCK(gr_uid_lock);
56344 +extern rwlock_t gr_inode_lock;
56345 +extern struct acl_subject_label *
56346 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56347 + struct acl_role_label *role);
56348 +
56349 +#ifdef CONFIG_BTRFS_FS
56350 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56351 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56352 +#endif
56353 +
56354 +static inline dev_t __get_dev(const struct dentry *dentry)
56355 +{
56356 +#ifdef CONFIG_BTRFS_FS
56357 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56358 + return get_btrfs_dev_from_inode(dentry->d_inode);
56359 + else
56360 +#endif
56361 + return dentry->d_inode->i_sb->s_dev;
56362 +}
56363 +
56364 +int
56365 +gr_init_uidset(void)
56366 +{
56367 + uid_set =
56368 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56369 + uid_used = 0;
56370 +
56371 + return uid_set ? 1 : 0;
56372 +}
56373 +
56374 +void
56375 +gr_free_uidset(void)
56376 +{
56377 + if (uid_set)
56378 + kfree(uid_set);
56379 +
56380 + return;
56381 +}
56382 +
56383 +int
56384 +gr_find_uid(const uid_t uid)
56385 +{
56386 + struct crash_uid *tmp = uid_set;
56387 + uid_t buid;
56388 + int low = 0, high = uid_used - 1, mid;
56389 +
56390 + while (high >= low) {
56391 + mid = (low + high) >> 1;
56392 + buid = tmp[mid].uid;
56393 + if (buid == uid)
56394 + return mid;
56395 + if (buid > uid)
56396 + high = mid - 1;
56397 + if (buid < uid)
56398 + low = mid + 1;
56399 + }
56400 +
56401 + return -1;
56402 +}
56403 +
56404 +static __inline__ void
56405 +gr_insertsort(void)
56406 +{
56407 + unsigned short i, j;
56408 + struct crash_uid index;
56409 +
56410 + for (i = 1; i < uid_used; i++) {
56411 + index = uid_set[i];
56412 + j = i;
56413 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56414 + uid_set[j] = uid_set[j - 1];
56415 + j--;
56416 + }
56417 + uid_set[j] = index;
56418 + }
56419 +
56420 + return;
56421 +}
56422 +
56423 +static __inline__ void
56424 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56425 +{
56426 + int loc;
56427 +
56428 + if (uid_used == GR_UIDTABLE_MAX)
56429 + return;
56430 +
56431 + loc = gr_find_uid(uid);
56432 +
56433 + if (loc >= 0) {
56434 + uid_set[loc].expires = expires;
56435 + return;
56436 + }
56437 +
56438 + uid_set[uid_used].uid = uid;
56439 + uid_set[uid_used].expires = expires;
56440 + uid_used++;
56441 +
56442 + gr_insertsort();
56443 +
56444 + return;
56445 +}
56446 +
56447 +void
56448 +gr_remove_uid(const unsigned short loc)
56449 +{
56450 + unsigned short i;
56451 +
56452 + for (i = loc + 1; i < uid_used; i++)
56453 + uid_set[i - 1] = uid_set[i];
56454 +
56455 + uid_used--;
56456 +
56457 + return;
56458 +}
56459 +
56460 +int
56461 +gr_check_crash_uid(const uid_t uid)
56462 +{
56463 + int loc;
56464 + int ret = 0;
56465 +
56466 + if (unlikely(!gr_acl_is_enabled()))
56467 + return 0;
56468 +
56469 + spin_lock(&gr_uid_lock);
56470 + loc = gr_find_uid(uid);
56471 +
56472 + if (loc < 0)
56473 + goto out_unlock;
56474 +
56475 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56476 + gr_remove_uid(loc);
56477 + else
56478 + ret = 1;
56479 +
56480 +out_unlock:
56481 + spin_unlock(&gr_uid_lock);
56482 + return ret;
56483 +}
56484 +
56485 +static __inline__ int
56486 +proc_is_setxid(const struct cred *cred)
56487 +{
56488 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56489 + !uid_eq(cred->uid, cred->fsuid))
56490 + return 1;
56491 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56492 + !uid_eq(cred->gid, cred->fsgid))
56493 + return 1;
56494 +
56495 + return 0;
56496 +}
56497 +
56498 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56499 +
56500 +void
56501 +gr_handle_crash(struct task_struct *task, const int sig)
56502 +{
56503 + struct acl_subject_label *curr;
56504 + struct task_struct *tsk, *tsk2;
56505 + const struct cred *cred;
56506 + const struct cred *cred2;
56507 +
56508 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56509 + return;
56510 +
56511 + if (unlikely(!gr_acl_is_enabled()))
56512 + return;
56513 +
56514 + curr = task->acl;
56515 +
56516 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56517 + return;
56518 +
56519 + if (time_before_eq(curr->expires, get_seconds())) {
56520 + curr->expires = 0;
56521 + curr->crashes = 0;
56522 + }
56523 +
56524 + curr->crashes++;
56525 +
56526 + if (!curr->expires)
56527 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56528 +
56529 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56530 + time_after(curr->expires, get_seconds())) {
56531 + rcu_read_lock();
56532 + cred = __task_cred(task);
56533 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56534 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56535 + spin_lock(&gr_uid_lock);
56536 + gr_insert_uid(cred->uid, curr->expires);
56537 + spin_unlock(&gr_uid_lock);
56538 + curr->expires = 0;
56539 + curr->crashes = 0;
56540 + read_lock(&tasklist_lock);
56541 + do_each_thread(tsk2, tsk) {
56542 + cred2 = __task_cred(tsk);
56543 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
56544 + gr_fake_force_sig(SIGKILL, tsk);
56545 + } while_each_thread(tsk2, tsk);
56546 + read_unlock(&tasklist_lock);
56547 + } else {
56548 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56549 + read_lock(&tasklist_lock);
56550 + read_lock(&grsec_exec_file_lock);
56551 + do_each_thread(tsk2, tsk) {
56552 + if (likely(tsk != task)) {
56553 + // if this thread has the same subject as the one that triggered
56554 + // RES_CRASH and it's the same binary, kill it
56555 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56556 + gr_fake_force_sig(SIGKILL, tsk);
56557 + }
56558 + } while_each_thread(tsk2, tsk);
56559 + read_unlock(&grsec_exec_file_lock);
56560 + read_unlock(&tasklist_lock);
56561 + }
56562 + rcu_read_unlock();
56563 + }
56564 +
56565 + return;
56566 +}
56567 +
56568 +int
56569 +gr_check_crash_exec(const struct file *filp)
56570 +{
56571 + struct acl_subject_label *curr;
56572 +
56573 + if (unlikely(!gr_acl_is_enabled()))
56574 + return 0;
56575 +
56576 + read_lock(&gr_inode_lock);
56577 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56578 + __get_dev(filp->f_path.dentry),
56579 + current->role);
56580 + read_unlock(&gr_inode_lock);
56581 +
56582 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56583 + (!curr->crashes && !curr->expires))
56584 + return 0;
56585 +
56586 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56587 + time_after(curr->expires, get_seconds()))
56588 + return 1;
56589 + else if (time_before_eq(curr->expires, get_seconds())) {
56590 + curr->crashes = 0;
56591 + curr->expires = 0;
56592 + }
56593 +
56594 + return 0;
56595 +}
56596 +
56597 +void
56598 +gr_handle_alertkill(struct task_struct *task)
56599 +{
56600 + struct acl_subject_label *curracl;
56601 + __u32 curr_ip;
56602 + struct task_struct *p, *p2;
56603 +
56604 + if (unlikely(!gr_acl_is_enabled()))
56605 + return;
56606 +
56607 + curracl = task->acl;
56608 + curr_ip = task->signal->curr_ip;
56609 +
56610 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56611 + read_lock(&tasklist_lock);
56612 + do_each_thread(p2, p) {
56613 + if (p->signal->curr_ip == curr_ip)
56614 + gr_fake_force_sig(SIGKILL, p);
56615 + } while_each_thread(p2, p);
56616 + read_unlock(&tasklist_lock);
56617 + } else if (curracl->mode & GR_KILLPROC)
56618 + gr_fake_force_sig(SIGKILL, task);
56619 +
56620 + return;
56621 +}
56622 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56623 new file mode 100644
56624 index 0000000..9d83a69
56625 --- /dev/null
56626 +++ b/grsecurity/gracl_shm.c
56627 @@ -0,0 +1,40 @@
56628 +#include <linux/kernel.h>
56629 +#include <linux/mm.h>
56630 +#include <linux/sched.h>
56631 +#include <linux/file.h>
56632 +#include <linux/ipc.h>
56633 +#include <linux/gracl.h>
56634 +#include <linux/grsecurity.h>
56635 +#include <linux/grinternal.h>
56636 +
56637 +int
56638 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56639 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56640 +{
56641 + struct task_struct *task;
56642 +
56643 + if (!gr_acl_is_enabled())
56644 + return 1;
56645 +
56646 + rcu_read_lock();
56647 + read_lock(&tasklist_lock);
56648 +
56649 + task = find_task_by_vpid(shm_cprid);
56650 +
56651 + if (unlikely(!task))
56652 + task = find_task_by_vpid(shm_lapid);
56653 +
56654 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56655 + (task->pid == shm_lapid)) &&
56656 + (task->acl->mode & GR_PROTSHM) &&
56657 + (task->acl != current->acl))) {
56658 + read_unlock(&tasklist_lock);
56659 + rcu_read_unlock();
56660 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56661 + return 0;
56662 + }
56663 + read_unlock(&tasklist_lock);
56664 + rcu_read_unlock();
56665 +
56666 + return 1;
56667 +}
56668 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56669 new file mode 100644
56670 index 0000000..bc0be01
56671 --- /dev/null
56672 +++ b/grsecurity/grsec_chdir.c
56673 @@ -0,0 +1,19 @@
56674 +#include <linux/kernel.h>
56675 +#include <linux/sched.h>
56676 +#include <linux/fs.h>
56677 +#include <linux/file.h>
56678 +#include <linux/grsecurity.h>
56679 +#include <linux/grinternal.h>
56680 +
56681 +void
56682 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56683 +{
56684 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56685 + if ((grsec_enable_chdir && grsec_enable_group &&
56686 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56687 + !grsec_enable_group)) {
56688 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56689 + }
56690 +#endif
56691 + return;
56692 +}
56693 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56694 new file mode 100644
56695 index 0000000..9807ee2
56696 --- /dev/null
56697 +++ b/grsecurity/grsec_chroot.c
56698 @@ -0,0 +1,368 @@
56699 +#include <linux/kernel.h>
56700 +#include <linux/module.h>
56701 +#include <linux/sched.h>
56702 +#include <linux/file.h>
56703 +#include <linux/fs.h>
56704 +#include <linux/mount.h>
56705 +#include <linux/types.h>
56706 +#include "../fs/mount.h"
56707 +#include <linux/grsecurity.h>
56708 +#include <linux/grinternal.h>
56709 +
56710 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56711 +{
56712 +#ifdef CONFIG_GRKERNSEC
56713 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56714 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56715 + task->gr_is_chrooted = 1;
56716 + else
56717 + task->gr_is_chrooted = 0;
56718 +
56719 + task->gr_chroot_dentry = path->dentry;
56720 +#endif
56721 + return;
56722 +}
56723 +
56724 +void gr_clear_chroot_entries(struct task_struct *task)
56725 +{
56726 +#ifdef CONFIG_GRKERNSEC
56727 + task->gr_is_chrooted = 0;
56728 + task->gr_chroot_dentry = NULL;
56729 +#endif
56730 + return;
56731 +}
56732 +
56733 +int
56734 +gr_handle_chroot_unix(const pid_t pid)
56735 +{
56736 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56737 + struct task_struct *p;
56738 +
56739 + if (unlikely(!grsec_enable_chroot_unix))
56740 + return 1;
56741 +
56742 + if (likely(!proc_is_chrooted(current)))
56743 + return 1;
56744 +
56745 + rcu_read_lock();
56746 + read_lock(&tasklist_lock);
56747 + p = find_task_by_vpid_unrestricted(pid);
56748 + if (unlikely(p && !have_same_root(current, p))) {
56749 + read_unlock(&tasklist_lock);
56750 + rcu_read_unlock();
56751 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56752 + return 0;
56753 + }
56754 + read_unlock(&tasklist_lock);
56755 + rcu_read_unlock();
56756 +#endif
56757 + return 1;
56758 +}
56759 +
56760 +int
56761 +gr_handle_chroot_nice(void)
56762 +{
56763 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56764 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56765 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56766 + return -EPERM;
56767 + }
56768 +#endif
56769 + return 0;
56770 +}
56771 +
56772 +int
56773 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56774 +{
56775 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56776 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56777 + && proc_is_chrooted(current)) {
56778 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56779 + return -EACCES;
56780 + }
56781 +#endif
56782 + return 0;
56783 +}
56784 +
56785 +int
56786 +gr_handle_chroot_rawio(const struct inode *inode)
56787 +{
56788 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56789 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56790 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56791 + return 1;
56792 +#endif
56793 + return 0;
56794 +}
56795 +
56796 +int
56797 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56798 +{
56799 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56800 + struct task_struct *p;
56801 + int ret = 0;
56802 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56803 + return ret;
56804 +
56805 + read_lock(&tasklist_lock);
56806 + do_each_pid_task(pid, type, p) {
56807 + if (!have_same_root(current, p)) {
56808 + ret = 1;
56809 + goto out;
56810 + }
56811 + } while_each_pid_task(pid, type, p);
56812 +out:
56813 + read_unlock(&tasklist_lock);
56814 + return ret;
56815 +#endif
56816 + return 0;
56817 +}
56818 +
56819 +int
56820 +gr_pid_is_chrooted(struct task_struct *p)
56821 +{
56822 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56823 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56824 + return 0;
56825 +
56826 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56827 + !have_same_root(current, p)) {
56828 + return 1;
56829 + }
56830 +#endif
56831 + return 0;
56832 +}
56833 +
56834 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56835 +
56836 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56837 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56838 +{
56839 + struct path path, currentroot;
56840 + int ret = 0;
56841 +
56842 + path.dentry = (struct dentry *)u_dentry;
56843 + path.mnt = (struct vfsmount *)u_mnt;
56844 + get_fs_root(current->fs, &currentroot);
56845 + if (path_is_under(&path, &currentroot))
56846 + ret = 1;
56847 + path_put(&currentroot);
56848 +
56849 + return ret;
56850 +}
56851 +#endif
56852 +
56853 +int
56854 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56855 +{
56856 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56857 + if (!grsec_enable_chroot_fchdir)
56858 + return 1;
56859 +
56860 + if (!proc_is_chrooted(current))
56861 + return 1;
56862 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56863 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56864 + return 0;
56865 + }
56866 +#endif
56867 + return 1;
56868 +}
56869 +
56870 +int
56871 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56872 + const time_t shm_createtime)
56873 +{
56874 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56875 + struct task_struct *p;
56876 + time_t starttime;
56877 +
56878 + if (unlikely(!grsec_enable_chroot_shmat))
56879 + return 1;
56880 +
56881 + if (likely(!proc_is_chrooted(current)))
56882 + return 1;
56883 +
56884 + rcu_read_lock();
56885 + read_lock(&tasklist_lock);
56886 +
56887 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56888 + starttime = p->start_time.tv_sec;
56889 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56890 + if (have_same_root(current, p)) {
56891 + goto allow;
56892 + } else {
56893 + read_unlock(&tasklist_lock);
56894 + rcu_read_unlock();
56895 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56896 + return 0;
56897 + }
56898 + }
56899 + /* creator exited, pid reuse, fall through to next check */
56900 + }
56901 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56902 + if (unlikely(!have_same_root(current, p))) {
56903 + read_unlock(&tasklist_lock);
56904 + rcu_read_unlock();
56905 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56906 + return 0;
56907 + }
56908 + }
56909 +
56910 +allow:
56911 + read_unlock(&tasklist_lock);
56912 + rcu_read_unlock();
56913 +#endif
56914 + return 1;
56915 +}
56916 +
56917 +void
56918 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56919 +{
56920 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56921 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56922 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56923 +#endif
56924 + return;
56925 +}
56926 +
56927 +int
56928 +gr_handle_chroot_mknod(const struct dentry *dentry,
56929 + const struct vfsmount *mnt, const int mode)
56930 +{
56931 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56932 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56933 + proc_is_chrooted(current)) {
56934 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56935 + return -EPERM;
56936 + }
56937 +#endif
56938 + return 0;
56939 +}
56940 +
56941 +int
56942 +gr_handle_chroot_mount(const struct dentry *dentry,
56943 + const struct vfsmount *mnt, const char *dev_name)
56944 +{
56945 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56946 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56947 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56948 + return -EPERM;
56949 + }
56950 +#endif
56951 + return 0;
56952 +}
56953 +
56954 +int
56955 +gr_handle_chroot_pivot(void)
56956 +{
56957 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56958 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56959 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56960 + return -EPERM;
56961 + }
56962 +#endif
56963 + return 0;
56964 +}
56965 +
56966 +int
56967 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56968 +{
56969 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56970 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56971 + !gr_is_outside_chroot(dentry, mnt)) {
56972 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56973 + return -EPERM;
56974 + }
56975 +#endif
56976 + return 0;
56977 +}
56978 +
56979 +extern const char *captab_log[];
56980 +extern int captab_log_entries;
56981 +
56982 +int
56983 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56984 +{
56985 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56986 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56987 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56988 + if (cap_raised(chroot_caps, cap)) {
56989 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56990 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56991 + }
56992 + return 0;
56993 + }
56994 + }
56995 +#endif
56996 + return 1;
56997 +}
56998 +
56999 +int
57000 +gr_chroot_is_capable(const int cap)
57001 +{
57002 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57003 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57004 +#endif
57005 + return 1;
57006 +}
57007 +
57008 +int
57009 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57010 +{
57011 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57012 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57013 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57014 + if (cap_raised(chroot_caps, cap)) {
57015 + return 0;
57016 + }
57017 + }
57018 +#endif
57019 + return 1;
57020 +}
57021 +
57022 +int
57023 +gr_chroot_is_capable_nolog(const int cap)
57024 +{
57025 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57026 + return gr_task_chroot_is_capable_nolog(current, cap);
57027 +#endif
57028 + return 1;
57029 +}
57030 +
57031 +int
57032 +gr_handle_chroot_sysctl(const int op)
57033 +{
57034 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57035 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57036 + proc_is_chrooted(current))
57037 + return -EACCES;
57038 +#endif
57039 + return 0;
57040 +}
57041 +
57042 +void
57043 +gr_handle_chroot_chdir(struct path *path)
57044 +{
57045 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57046 + if (grsec_enable_chroot_chdir)
57047 + set_fs_pwd(current->fs, path);
57048 +#endif
57049 + return;
57050 +}
57051 +
57052 +int
57053 +gr_handle_chroot_chmod(const struct dentry *dentry,
57054 + const struct vfsmount *mnt, const int mode)
57055 +{
57056 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57057 + /* allow chmod +s on directories, but not files */
57058 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57059 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57060 + proc_is_chrooted(current)) {
57061 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57062 + return -EPERM;
57063 + }
57064 +#endif
57065 + return 0;
57066 +}
57067 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57068 new file mode 100644
57069 index 0000000..213ad8b
57070 --- /dev/null
57071 +++ b/grsecurity/grsec_disabled.c
57072 @@ -0,0 +1,437 @@
57073 +#include <linux/kernel.h>
57074 +#include <linux/module.h>
57075 +#include <linux/sched.h>
57076 +#include <linux/file.h>
57077 +#include <linux/fs.h>
57078 +#include <linux/kdev_t.h>
57079 +#include <linux/net.h>
57080 +#include <linux/in.h>
57081 +#include <linux/ip.h>
57082 +#include <linux/skbuff.h>
57083 +#include <linux/sysctl.h>
57084 +
57085 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57086 +void
57087 +pax_set_initial_flags(struct linux_binprm *bprm)
57088 +{
57089 + return;
57090 +}
57091 +#endif
57092 +
57093 +#ifdef CONFIG_SYSCTL
57094 +__u32
57095 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57096 +{
57097 + return 0;
57098 +}
57099 +#endif
57100 +
57101 +#ifdef CONFIG_TASKSTATS
57102 +int gr_is_taskstats_denied(int pid)
57103 +{
57104 + return 0;
57105 +}
57106 +#endif
57107 +
57108 +int
57109 +gr_acl_is_enabled(void)
57110 +{
57111 + return 0;
57112 +}
57113 +
57114 +void
57115 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57116 +{
57117 + return;
57118 +}
57119 +
57120 +int
57121 +gr_handle_rawio(const struct inode *inode)
57122 +{
57123 + return 0;
57124 +}
57125 +
57126 +void
57127 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57128 +{
57129 + return;
57130 +}
57131 +
57132 +int
57133 +gr_handle_ptrace(struct task_struct *task, const long request)
57134 +{
57135 + return 0;
57136 +}
57137 +
57138 +int
57139 +gr_handle_proc_ptrace(struct task_struct *task)
57140 +{
57141 + return 0;
57142 +}
57143 +
57144 +void
57145 +gr_learn_resource(const struct task_struct *task,
57146 + const int res, const unsigned long wanted, const int gt)
57147 +{
57148 + return;
57149 +}
57150 +
57151 +int
57152 +gr_set_acls(const int type)
57153 +{
57154 + return 0;
57155 +}
57156 +
57157 +int
57158 +gr_check_hidden_task(const struct task_struct *tsk)
57159 +{
57160 + return 0;
57161 +}
57162 +
57163 +int
57164 +gr_check_protected_task(const struct task_struct *task)
57165 +{
57166 + return 0;
57167 +}
57168 +
57169 +int
57170 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57171 +{
57172 + return 0;
57173 +}
57174 +
57175 +void
57176 +gr_copy_label(struct task_struct *tsk)
57177 +{
57178 + return;
57179 +}
57180 +
57181 +void
57182 +gr_set_pax_flags(struct task_struct *task)
57183 +{
57184 + return;
57185 +}
57186 +
57187 +int
57188 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57189 + const int unsafe_share)
57190 +{
57191 + return 0;
57192 +}
57193 +
57194 +void
57195 +gr_handle_delete(const ino_t ino, const dev_t dev)
57196 +{
57197 + return;
57198 +}
57199 +
57200 +void
57201 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57202 +{
57203 + return;
57204 +}
57205 +
57206 +void
57207 +gr_handle_crash(struct task_struct *task, const int sig)
57208 +{
57209 + return;
57210 +}
57211 +
57212 +int
57213 +gr_check_crash_exec(const struct file *filp)
57214 +{
57215 + return 0;
57216 +}
57217 +
57218 +int
57219 +gr_check_crash_uid(const uid_t uid)
57220 +{
57221 + return 0;
57222 +}
57223 +
57224 +void
57225 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57226 + struct dentry *old_dentry,
57227 + struct dentry *new_dentry,
57228 + struct vfsmount *mnt, const __u8 replace)
57229 +{
57230 + return;
57231 +}
57232 +
57233 +int
57234 +gr_search_socket(const int family, const int type, const int protocol)
57235 +{
57236 + return 1;
57237 +}
57238 +
57239 +int
57240 +gr_search_connectbind(const int mode, const struct socket *sock,
57241 + const struct sockaddr_in *addr)
57242 +{
57243 + return 0;
57244 +}
57245 +
57246 +void
57247 +gr_handle_alertkill(struct task_struct *task)
57248 +{
57249 + return;
57250 +}
57251 +
57252 +__u32
57253 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57254 +{
57255 + return 1;
57256 +}
57257 +
57258 +__u32
57259 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57260 + const struct vfsmount * mnt)
57261 +{
57262 + return 1;
57263 +}
57264 +
57265 +__u32
57266 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57267 + int acc_mode)
57268 +{
57269 + return 1;
57270 +}
57271 +
57272 +__u32
57273 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57274 +{
57275 + return 1;
57276 +}
57277 +
57278 +__u32
57279 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57280 +{
57281 + return 1;
57282 +}
57283 +
57284 +int
57285 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57286 + unsigned int *vm_flags)
57287 +{
57288 + return 1;
57289 +}
57290 +
57291 +__u32
57292 +gr_acl_handle_truncate(const struct dentry * dentry,
57293 + const struct vfsmount * mnt)
57294 +{
57295 + return 1;
57296 +}
57297 +
57298 +__u32
57299 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57300 +{
57301 + return 1;
57302 +}
57303 +
57304 +__u32
57305 +gr_acl_handle_access(const struct dentry * dentry,
57306 + const struct vfsmount * mnt, const int fmode)
57307 +{
57308 + return 1;
57309 +}
57310 +
57311 +__u32
57312 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57313 + umode_t *mode)
57314 +{
57315 + return 1;
57316 +}
57317 +
57318 +__u32
57319 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57320 +{
57321 + return 1;
57322 +}
57323 +
57324 +__u32
57325 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57326 +{
57327 + return 1;
57328 +}
57329 +
57330 +void
57331 +grsecurity_init(void)
57332 +{
57333 + return;
57334 +}
57335 +
57336 +umode_t gr_acl_umask(void)
57337 +{
57338 + return 0;
57339 +}
57340 +
57341 +__u32
57342 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57343 + const struct dentry * parent_dentry,
57344 + const struct vfsmount * parent_mnt,
57345 + const int mode)
57346 +{
57347 + return 1;
57348 +}
57349 +
57350 +__u32
57351 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57352 + const struct dentry * parent_dentry,
57353 + const struct vfsmount * parent_mnt)
57354 +{
57355 + return 1;
57356 +}
57357 +
57358 +__u32
57359 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57360 + const struct dentry * parent_dentry,
57361 + const struct vfsmount * parent_mnt, const char *from)
57362 +{
57363 + return 1;
57364 +}
57365 +
57366 +__u32
57367 +gr_acl_handle_link(const struct dentry * new_dentry,
57368 + const struct dentry * parent_dentry,
57369 + const struct vfsmount * parent_mnt,
57370 + const struct dentry * old_dentry,
57371 + const struct vfsmount * old_mnt, const char *to)
57372 +{
57373 + return 1;
57374 +}
57375 +
57376 +int
57377 +gr_acl_handle_rename(const struct dentry *new_dentry,
57378 + const struct dentry *parent_dentry,
57379 + const struct vfsmount *parent_mnt,
57380 + const struct dentry *old_dentry,
57381 + const struct inode *old_parent_inode,
57382 + const struct vfsmount *old_mnt, const char *newname)
57383 +{
57384 + return 0;
57385 +}
57386 +
57387 +int
57388 +gr_acl_handle_filldir(const struct file *file, const char *name,
57389 + const int namelen, const ino_t ino)
57390 +{
57391 + return 1;
57392 +}
57393 +
57394 +int
57395 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57396 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57397 +{
57398 + return 1;
57399 +}
57400 +
57401 +int
57402 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57403 +{
57404 + return 0;
57405 +}
57406 +
57407 +int
57408 +gr_search_accept(const struct socket *sock)
57409 +{
57410 + return 0;
57411 +}
57412 +
57413 +int
57414 +gr_search_listen(const struct socket *sock)
57415 +{
57416 + return 0;
57417 +}
57418 +
57419 +int
57420 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57421 +{
57422 + return 0;
57423 +}
57424 +
57425 +__u32
57426 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57427 +{
57428 + return 1;
57429 +}
57430 +
57431 +__u32
57432 +gr_acl_handle_creat(const struct dentry * dentry,
57433 + const struct dentry * p_dentry,
57434 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57435 + const int imode)
57436 +{
57437 + return 1;
57438 +}
57439 +
57440 +void
57441 +gr_acl_handle_exit(void)
57442 +{
57443 + return;
57444 +}
57445 +
57446 +int
57447 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57448 +{
57449 + return 1;
57450 +}
57451 +
57452 +void
57453 +gr_set_role_label(const uid_t uid, const gid_t gid)
57454 +{
57455 + return;
57456 +}
57457 +
57458 +int
57459 +gr_acl_handle_procpidmem(const struct task_struct *task)
57460 +{
57461 + return 0;
57462 +}
57463 +
57464 +int
57465 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57466 +{
57467 + return 0;
57468 +}
57469 +
57470 +int
57471 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57472 +{
57473 + return 0;
57474 +}
57475 +
57476 +void
57477 +gr_set_kernel_label(struct task_struct *task)
57478 +{
57479 + return;
57480 +}
57481 +
57482 +int
57483 +gr_check_user_change(int real, int effective, int fs)
57484 +{
57485 + return 0;
57486 +}
57487 +
57488 +int
57489 +gr_check_group_change(int real, int effective, int fs)
57490 +{
57491 + return 0;
57492 +}
57493 +
57494 +int gr_acl_enable_at_secure(void)
57495 +{
57496 + return 0;
57497 +}
57498 +
57499 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57500 +{
57501 + return dentry->d_inode->i_sb->s_dev;
57502 +}
57503 +
57504 +EXPORT_SYMBOL(gr_learn_resource);
57505 +EXPORT_SYMBOL(gr_set_kernel_label);
57506 +#ifdef CONFIG_SECURITY
57507 +EXPORT_SYMBOL(gr_check_user_change);
57508 +EXPORT_SYMBOL(gr_check_group_change);
57509 +#endif
57510 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57511 new file mode 100644
57512 index 0000000..abfa971
57513 --- /dev/null
57514 +++ b/grsecurity/grsec_exec.c
57515 @@ -0,0 +1,174 @@
57516 +#include <linux/kernel.h>
57517 +#include <linux/sched.h>
57518 +#include <linux/file.h>
57519 +#include <linux/binfmts.h>
57520 +#include <linux/fs.h>
57521 +#include <linux/types.h>
57522 +#include <linux/grdefs.h>
57523 +#include <linux/grsecurity.h>
57524 +#include <linux/grinternal.h>
57525 +#include <linux/capability.h>
57526 +#include <linux/module.h>
57527 +
57528 +#include <asm/uaccess.h>
57529 +
57530 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57531 +static char gr_exec_arg_buf[132];
57532 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57533 +#endif
57534 +
57535 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57536 +
57537 +void
57538 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57539 +{
57540 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57541 + char *grarg = gr_exec_arg_buf;
57542 + unsigned int i, x, execlen = 0;
57543 + char c;
57544 +
57545 + if (!((grsec_enable_execlog && grsec_enable_group &&
57546 + in_group_p(grsec_audit_gid))
57547 + || (grsec_enable_execlog && !grsec_enable_group)))
57548 + return;
57549 +
57550 + mutex_lock(&gr_exec_arg_mutex);
57551 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57552 +
57553 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57554 + const char __user *p;
57555 + unsigned int len;
57556 +
57557 + p = get_user_arg_ptr(argv, i);
57558 + if (IS_ERR(p))
57559 + goto log;
57560 +
57561 + len = strnlen_user(p, 128 - execlen);
57562 + if (len > 128 - execlen)
57563 + len = 128 - execlen;
57564 + else if (len > 0)
57565 + len--;
57566 + if (copy_from_user(grarg + execlen, p, len))
57567 + goto log;
57568 +
57569 + /* rewrite unprintable characters */
57570 + for (x = 0; x < len; x++) {
57571 + c = *(grarg + execlen + x);
57572 + if (c < 32 || c > 126)
57573 + *(grarg + execlen + x) = ' ';
57574 + }
57575 +
57576 + execlen += len;
57577 + *(grarg + execlen) = ' ';
57578 + *(grarg + execlen + 1) = '\0';
57579 + execlen++;
57580 + }
57581 +
57582 + log:
57583 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57584 + bprm->file->f_path.mnt, grarg);
57585 + mutex_unlock(&gr_exec_arg_mutex);
57586 +#endif
57587 + return;
57588 +}
57589 +
57590 +#ifdef CONFIG_GRKERNSEC
57591 +extern int gr_acl_is_capable(const int cap);
57592 +extern int gr_acl_is_capable_nolog(const int cap);
57593 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57594 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57595 +extern int gr_chroot_is_capable(const int cap);
57596 +extern int gr_chroot_is_capable_nolog(const int cap);
57597 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57598 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57599 +#endif
57600 +
57601 +const char *captab_log[] = {
57602 + "CAP_CHOWN",
57603 + "CAP_DAC_OVERRIDE",
57604 + "CAP_DAC_READ_SEARCH",
57605 + "CAP_FOWNER",
57606 + "CAP_FSETID",
57607 + "CAP_KILL",
57608 + "CAP_SETGID",
57609 + "CAP_SETUID",
57610 + "CAP_SETPCAP",
57611 + "CAP_LINUX_IMMUTABLE",
57612 + "CAP_NET_BIND_SERVICE",
57613 + "CAP_NET_BROADCAST",
57614 + "CAP_NET_ADMIN",
57615 + "CAP_NET_RAW",
57616 + "CAP_IPC_LOCK",
57617 + "CAP_IPC_OWNER",
57618 + "CAP_SYS_MODULE",
57619 + "CAP_SYS_RAWIO",
57620 + "CAP_SYS_CHROOT",
57621 + "CAP_SYS_PTRACE",
57622 + "CAP_SYS_PACCT",
57623 + "CAP_SYS_ADMIN",
57624 + "CAP_SYS_BOOT",
57625 + "CAP_SYS_NICE",
57626 + "CAP_SYS_RESOURCE",
57627 + "CAP_SYS_TIME",
57628 + "CAP_SYS_TTY_CONFIG",
57629 + "CAP_MKNOD",
57630 + "CAP_LEASE",
57631 + "CAP_AUDIT_WRITE",
57632 + "CAP_AUDIT_CONTROL",
57633 + "CAP_SETFCAP",
57634 + "CAP_MAC_OVERRIDE",
57635 + "CAP_MAC_ADMIN",
57636 + "CAP_SYSLOG",
57637 + "CAP_WAKE_ALARM"
57638 +};
57639 +
57640 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57641 +
57642 +int gr_is_capable(const int cap)
57643 +{
57644 +#ifdef CONFIG_GRKERNSEC
57645 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57646 + return 1;
57647 + return 0;
57648 +#else
57649 + return 1;
57650 +#endif
57651 +}
57652 +
57653 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57654 +{
57655 +#ifdef CONFIG_GRKERNSEC
57656 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57657 + return 1;
57658 + return 0;
57659 +#else
57660 + return 1;
57661 +#endif
57662 +}
57663 +
57664 +int gr_is_capable_nolog(const int cap)
57665 +{
57666 +#ifdef CONFIG_GRKERNSEC
57667 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57668 + return 1;
57669 + return 0;
57670 +#else
57671 + return 1;
57672 +#endif
57673 +}
57674 +
57675 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57676 +{
57677 +#ifdef CONFIG_GRKERNSEC
57678 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57679 + return 1;
57680 + return 0;
57681 +#else
57682 + return 1;
57683 +#endif
57684 +}
57685 +
57686 +EXPORT_SYMBOL(gr_is_capable);
57687 +EXPORT_SYMBOL(gr_is_capable_nolog);
57688 +EXPORT_SYMBOL(gr_task_is_capable);
57689 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57690 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57691 new file mode 100644
57692 index 0000000..d3ee748
57693 --- /dev/null
57694 +++ b/grsecurity/grsec_fifo.c
57695 @@ -0,0 +1,24 @@
57696 +#include <linux/kernel.h>
57697 +#include <linux/sched.h>
57698 +#include <linux/fs.h>
57699 +#include <linux/file.h>
57700 +#include <linux/grinternal.h>
57701 +
57702 +int
57703 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57704 + const struct dentry *dir, const int flag, const int acc_mode)
57705 +{
57706 +#ifdef CONFIG_GRKERNSEC_FIFO
57707 + const struct cred *cred = current_cred();
57708 +
57709 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57710 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57711 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57712 + (cred->fsuid != dentry->d_inode->i_uid)) {
57713 + if (!inode_permission(dentry->d_inode, acc_mode))
57714 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57715 + return -EACCES;
57716 + }
57717 +#endif
57718 + return 0;
57719 +}
57720 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57721 new file mode 100644
57722 index 0000000..8ca18bf
57723 --- /dev/null
57724 +++ b/grsecurity/grsec_fork.c
57725 @@ -0,0 +1,23 @@
57726 +#include <linux/kernel.h>
57727 +#include <linux/sched.h>
57728 +#include <linux/grsecurity.h>
57729 +#include <linux/grinternal.h>
57730 +#include <linux/errno.h>
57731 +
57732 +void
57733 +gr_log_forkfail(const int retval)
57734 +{
57735 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57736 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57737 + switch (retval) {
57738 + case -EAGAIN:
57739 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57740 + break;
57741 + case -ENOMEM:
57742 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57743 + break;
57744 + }
57745 + }
57746 +#endif
57747 + return;
57748 +}
57749 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57750 new file mode 100644
57751 index 0000000..05a6015
57752 --- /dev/null
57753 +++ b/grsecurity/grsec_init.c
57754 @@ -0,0 +1,283 @@
57755 +#include <linux/kernel.h>
57756 +#include <linux/sched.h>
57757 +#include <linux/mm.h>
57758 +#include <linux/gracl.h>
57759 +#include <linux/slab.h>
57760 +#include <linux/vmalloc.h>
57761 +#include <linux/percpu.h>
57762 +#include <linux/module.h>
57763 +
57764 +int grsec_enable_ptrace_readexec;
57765 +int grsec_enable_setxid;
57766 +int grsec_enable_symlinkown;
57767 +int grsec_symlinkown_gid;
57768 +int grsec_enable_brute;
57769 +int grsec_enable_link;
57770 +int grsec_enable_dmesg;
57771 +int grsec_enable_harden_ptrace;
57772 +int grsec_enable_fifo;
57773 +int grsec_enable_execlog;
57774 +int grsec_enable_signal;
57775 +int grsec_enable_forkfail;
57776 +int grsec_enable_audit_ptrace;
57777 +int grsec_enable_time;
57778 +int grsec_enable_audit_textrel;
57779 +int grsec_enable_group;
57780 +int grsec_audit_gid;
57781 +int grsec_enable_chdir;
57782 +int grsec_enable_mount;
57783 +int grsec_enable_rofs;
57784 +int grsec_enable_chroot_findtask;
57785 +int grsec_enable_chroot_mount;
57786 +int grsec_enable_chroot_shmat;
57787 +int grsec_enable_chroot_fchdir;
57788 +int grsec_enable_chroot_double;
57789 +int grsec_enable_chroot_pivot;
57790 +int grsec_enable_chroot_chdir;
57791 +int grsec_enable_chroot_chmod;
57792 +int grsec_enable_chroot_mknod;
57793 +int grsec_enable_chroot_nice;
57794 +int grsec_enable_chroot_execlog;
57795 +int grsec_enable_chroot_caps;
57796 +int grsec_enable_chroot_sysctl;
57797 +int grsec_enable_chroot_unix;
57798 +int grsec_enable_tpe;
57799 +int grsec_tpe_gid;
57800 +int grsec_enable_blackhole;
57801 +#ifdef CONFIG_IPV6_MODULE
57802 +EXPORT_SYMBOL(grsec_enable_blackhole);
57803 +#endif
57804 +int grsec_lastack_retries;
57805 +int grsec_enable_tpe_all;
57806 +int grsec_enable_tpe_invert;
57807 +int grsec_enable_socket_all;
57808 +int grsec_socket_all_gid;
57809 +int grsec_enable_socket_client;
57810 +int grsec_socket_client_gid;
57811 +int grsec_enable_socket_server;
57812 +int grsec_socket_server_gid;
57813 +int grsec_resource_logging;
57814 +int grsec_disable_privio;
57815 +int grsec_enable_log_rwxmaps;
57816 +int grsec_lock;
57817 +
57818 +DEFINE_SPINLOCK(grsec_alert_lock);
57819 +unsigned long grsec_alert_wtime = 0;
57820 +unsigned long grsec_alert_fyet = 0;
57821 +
57822 +DEFINE_SPINLOCK(grsec_audit_lock);
57823 +
57824 +DEFINE_RWLOCK(grsec_exec_file_lock);
57825 +
57826 +char *gr_shared_page[4];
57827 +
57828 +char *gr_alert_log_fmt;
57829 +char *gr_audit_log_fmt;
57830 +char *gr_alert_log_buf;
57831 +char *gr_audit_log_buf;
57832 +
57833 +extern struct gr_arg *gr_usermode;
57834 +extern unsigned char *gr_system_salt;
57835 +extern unsigned char *gr_system_sum;
57836 +
57837 +void __init
57838 +grsecurity_init(void)
57839 +{
57840 + int j;
57841 + /* create the per-cpu shared pages */
57842 +
57843 +#ifdef CONFIG_X86
57844 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57845 +#endif
57846 +
57847 + for (j = 0; j < 4; j++) {
57848 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57849 + if (gr_shared_page[j] == NULL) {
57850 + panic("Unable to allocate grsecurity shared page");
57851 + return;
57852 + }
57853 + }
57854 +
57855 + /* allocate log buffers */
57856 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57857 + if (!gr_alert_log_fmt) {
57858 + panic("Unable to allocate grsecurity alert log format buffer");
57859 + return;
57860 + }
57861 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57862 + if (!gr_audit_log_fmt) {
57863 + panic("Unable to allocate grsecurity audit log format buffer");
57864 + return;
57865 + }
57866 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57867 + if (!gr_alert_log_buf) {
57868 + panic("Unable to allocate grsecurity alert log buffer");
57869 + return;
57870 + }
57871 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57872 + if (!gr_audit_log_buf) {
57873 + panic("Unable to allocate grsecurity audit log buffer");
57874 + return;
57875 + }
57876 +
57877 + /* allocate memory for authentication structure */
57878 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57879 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57880 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57881 +
57882 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57883 + panic("Unable to allocate grsecurity authentication structure");
57884 + return;
57885 + }
57886 +
57887 +
57888 +#ifdef CONFIG_GRKERNSEC_IO
57889 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57890 + grsec_disable_privio = 1;
57891 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57892 + grsec_disable_privio = 1;
57893 +#else
57894 + grsec_disable_privio = 0;
57895 +#endif
57896 +#endif
57897 +
57898 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57899 + /* for backward compatibility, tpe_invert always defaults to on if
57900 + enabled in the kernel
57901 + */
57902 + grsec_enable_tpe_invert = 1;
57903 +#endif
57904 +
57905 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57906 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57907 + grsec_lock = 1;
57908 +#endif
57909 +
57910 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57911 + grsec_enable_audit_textrel = 1;
57912 +#endif
57913 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57914 + grsec_enable_log_rwxmaps = 1;
57915 +#endif
57916 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57917 + grsec_enable_group = 1;
57918 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57919 +#endif
57920 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57921 + grsec_enable_ptrace_readexec = 1;
57922 +#endif
57923 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57924 + grsec_enable_chdir = 1;
57925 +#endif
57926 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57927 + grsec_enable_harden_ptrace = 1;
57928 +#endif
57929 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57930 + grsec_enable_mount = 1;
57931 +#endif
57932 +#ifdef CONFIG_GRKERNSEC_LINK
57933 + grsec_enable_link = 1;
57934 +#endif
57935 +#ifdef CONFIG_GRKERNSEC_BRUTE
57936 + grsec_enable_brute = 1;
57937 +#endif
57938 +#ifdef CONFIG_GRKERNSEC_DMESG
57939 + grsec_enable_dmesg = 1;
57940 +#endif
57941 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57942 + grsec_enable_blackhole = 1;
57943 + grsec_lastack_retries = 4;
57944 +#endif
57945 +#ifdef CONFIG_GRKERNSEC_FIFO
57946 + grsec_enable_fifo = 1;
57947 +#endif
57948 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57949 + grsec_enable_execlog = 1;
57950 +#endif
57951 +#ifdef CONFIG_GRKERNSEC_SETXID
57952 + grsec_enable_setxid = 1;
57953 +#endif
57954 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57955 + grsec_enable_signal = 1;
57956 +#endif
57957 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57958 + grsec_enable_forkfail = 1;
57959 +#endif
57960 +#ifdef CONFIG_GRKERNSEC_TIME
57961 + grsec_enable_time = 1;
57962 +#endif
57963 +#ifdef CONFIG_GRKERNSEC_RESLOG
57964 + grsec_resource_logging = 1;
57965 +#endif
57966 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57967 + grsec_enable_chroot_findtask = 1;
57968 +#endif
57969 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57970 + grsec_enable_chroot_unix = 1;
57971 +#endif
57972 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57973 + grsec_enable_chroot_mount = 1;
57974 +#endif
57975 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57976 + grsec_enable_chroot_fchdir = 1;
57977 +#endif
57978 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57979 + grsec_enable_chroot_shmat = 1;
57980 +#endif
57981 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57982 + grsec_enable_audit_ptrace = 1;
57983 +#endif
57984 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57985 + grsec_enable_chroot_double = 1;
57986 +#endif
57987 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57988 + grsec_enable_chroot_pivot = 1;
57989 +#endif
57990 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57991 + grsec_enable_chroot_chdir = 1;
57992 +#endif
57993 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57994 + grsec_enable_chroot_chmod = 1;
57995 +#endif
57996 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57997 + grsec_enable_chroot_mknod = 1;
57998 +#endif
57999 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58000 + grsec_enable_chroot_nice = 1;
58001 +#endif
58002 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58003 + grsec_enable_chroot_execlog = 1;
58004 +#endif
58005 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58006 + grsec_enable_chroot_caps = 1;
58007 +#endif
58008 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58009 + grsec_enable_chroot_sysctl = 1;
58010 +#endif
58011 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58012 + grsec_enable_symlinkown = 1;
58013 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58014 +#endif
58015 +#ifdef CONFIG_GRKERNSEC_TPE
58016 + grsec_enable_tpe = 1;
58017 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58018 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58019 + grsec_enable_tpe_all = 1;
58020 +#endif
58021 +#endif
58022 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58023 + grsec_enable_socket_all = 1;
58024 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58025 +#endif
58026 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58027 + grsec_enable_socket_client = 1;
58028 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58029 +#endif
58030 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58031 + grsec_enable_socket_server = 1;
58032 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58033 +#endif
58034 +#endif
58035 +
58036 + return;
58037 +}
58038 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58039 new file mode 100644
58040 index 0000000..551a2e7
58041 --- /dev/null
58042 +++ b/grsecurity/grsec_link.c
58043 @@ -0,0 +1,59 @@
58044 +#include <linux/kernel.h>
58045 +#include <linux/sched.h>
58046 +#include <linux/fs.h>
58047 +#include <linux/file.h>
58048 +#include <linux/grinternal.h>
58049 +
58050 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58051 +{
58052 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58053 + const struct inode *link_inode = link->dentry->d_inode;
58054 +
58055 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58056 + /* ignore root-owned links, e.g. /proc/self */
58057 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) &&
58058 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58059 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58060 + return 1;
58061 + }
58062 +#endif
58063 + return 0;
58064 +}
58065 +
58066 +int
58067 +gr_handle_follow_link(const struct inode *parent,
58068 + const struct inode *inode,
58069 + const struct dentry *dentry, const struct vfsmount *mnt)
58070 +{
58071 +#ifdef CONFIG_GRKERNSEC_LINK
58072 + const struct cred *cred = current_cred();
58073 +
58074 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58075 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58076 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58077 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58078 + return -EACCES;
58079 + }
58080 +#endif
58081 + return 0;
58082 +}
58083 +
58084 +int
58085 +gr_handle_hardlink(const struct dentry *dentry,
58086 + const struct vfsmount *mnt,
58087 + struct inode *inode, const int mode, const char *to)
58088 +{
58089 +#ifdef CONFIG_GRKERNSEC_LINK
58090 + const struct cred *cred = current_cred();
58091 +
58092 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58093 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58094 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58095 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58096 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58097 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58098 + return -EPERM;
58099 + }
58100 +#endif
58101 + return 0;
58102 +}
58103 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58104 new file mode 100644
58105 index 0000000..a45d2e9
58106 --- /dev/null
58107 +++ b/grsecurity/grsec_log.c
58108 @@ -0,0 +1,322 @@
58109 +#include <linux/kernel.h>
58110 +#include <linux/sched.h>
58111 +#include <linux/file.h>
58112 +#include <linux/tty.h>
58113 +#include <linux/fs.h>
58114 +#include <linux/grinternal.h>
58115 +
58116 +#ifdef CONFIG_TREE_PREEMPT_RCU
58117 +#define DISABLE_PREEMPT() preempt_disable()
58118 +#define ENABLE_PREEMPT() preempt_enable()
58119 +#else
58120 +#define DISABLE_PREEMPT()
58121 +#define ENABLE_PREEMPT()
58122 +#endif
58123 +
58124 +#define BEGIN_LOCKS(x) \
58125 + DISABLE_PREEMPT(); \
58126 + rcu_read_lock(); \
58127 + read_lock(&tasklist_lock); \
58128 + read_lock(&grsec_exec_file_lock); \
58129 + if (x != GR_DO_AUDIT) \
58130 + spin_lock(&grsec_alert_lock); \
58131 + else \
58132 + spin_lock(&grsec_audit_lock)
58133 +
58134 +#define END_LOCKS(x) \
58135 + if (x != GR_DO_AUDIT) \
58136 + spin_unlock(&grsec_alert_lock); \
58137 + else \
58138 + spin_unlock(&grsec_audit_lock); \
58139 + read_unlock(&grsec_exec_file_lock); \
58140 + read_unlock(&tasklist_lock); \
58141 + rcu_read_unlock(); \
58142 + ENABLE_PREEMPT(); \
58143 + if (x == GR_DONT_AUDIT) \
58144 + gr_handle_alertkill(current)
58145 +
58146 +enum {
58147 + FLOODING,
58148 + NO_FLOODING
58149 +};
58150 +
58151 +extern char *gr_alert_log_fmt;
58152 +extern char *gr_audit_log_fmt;
58153 +extern char *gr_alert_log_buf;
58154 +extern char *gr_audit_log_buf;
58155 +
58156 +static int gr_log_start(int audit)
58157 +{
58158 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58159 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58160 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58161 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58162 + unsigned long curr_secs = get_seconds();
58163 +
58164 + if (audit == GR_DO_AUDIT)
58165 + goto set_fmt;
58166 +
58167 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58168 + grsec_alert_wtime = curr_secs;
58169 + grsec_alert_fyet = 0;
58170 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58171 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58172 + grsec_alert_fyet++;
58173 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58174 + grsec_alert_wtime = curr_secs;
58175 + grsec_alert_fyet++;
58176 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58177 + return FLOODING;
58178 + }
58179 + else return FLOODING;
58180 +
58181 +set_fmt:
58182 +#endif
58183 + memset(buf, 0, PAGE_SIZE);
58184 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58185 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58186 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58187 + } else if (current->signal->curr_ip) {
58188 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58189 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58190 + } else if (gr_acl_is_enabled()) {
58191 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58192 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58193 + } else {
58194 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58195 + strcpy(buf, fmt);
58196 + }
58197 +
58198 + return NO_FLOODING;
58199 +}
58200 +
58201 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58202 + __attribute__ ((format (printf, 2, 0)));
58203 +
58204 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58205 +{
58206 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58207 + unsigned int len = strlen(buf);
58208 +
58209 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58210 +
58211 + return;
58212 +}
58213 +
58214 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58215 + __attribute__ ((format (printf, 2, 3)));
58216 +
58217 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58218 +{
58219 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58220 + unsigned int len = strlen(buf);
58221 + va_list ap;
58222 +
58223 + va_start(ap, msg);
58224 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58225 + va_end(ap);
58226 +
58227 + return;
58228 +}
58229 +
58230 +static void gr_log_end(int audit, int append_default)
58231 +{
58232 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58233 +
58234 + if (append_default) {
58235 + unsigned int len = strlen(buf);
58236 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58237 + }
58238 +
58239 + printk("%s\n", buf);
58240 +
58241 + return;
58242 +}
58243 +
58244 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58245 +{
58246 + int logtype;
58247 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58248 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58249 + void *voidptr = NULL;
58250 + int num1 = 0, num2 = 0;
58251 + unsigned long ulong1 = 0, ulong2 = 0;
58252 + struct dentry *dentry = NULL;
58253 + struct vfsmount *mnt = NULL;
58254 + struct file *file = NULL;
58255 + struct task_struct *task = NULL;
58256 + const struct cred *cred, *pcred;
58257 + va_list ap;
58258 +
58259 + BEGIN_LOCKS(audit);
58260 + logtype = gr_log_start(audit);
58261 + if (logtype == FLOODING) {
58262 + END_LOCKS(audit);
58263 + return;
58264 + }
58265 + va_start(ap, argtypes);
58266 + switch (argtypes) {
58267 + case GR_TTYSNIFF:
58268 + task = va_arg(ap, struct task_struct *);
58269 + 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);
58270 + break;
58271 + case GR_SYSCTL_HIDDEN:
58272 + str1 = va_arg(ap, char *);
58273 + gr_log_middle_varargs(audit, msg, result, str1);
58274 + break;
58275 + case GR_RBAC:
58276 + dentry = va_arg(ap, struct dentry *);
58277 + mnt = va_arg(ap, struct vfsmount *);
58278 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58279 + break;
58280 + case GR_RBAC_STR:
58281 + dentry = va_arg(ap, struct dentry *);
58282 + mnt = va_arg(ap, struct vfsmount *);
58283 + str1 = va_arg(ap, char *);
58284 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58285 + break;
58286 + case GR_STR_RBAC:
58287 + str1 = va_arg(ap, char *);
58288 + dentry = va_arg(ap, struct dentry *);
58289 + mnt = va_arg(ap, struct vfsmount *);
58290 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58291 + break;
58292 + case GR_RBAC_MODE2:
58293 + dentry = va_arg(ap, struct dentry *);
58294 + mnt = va_arg(ap, struct vfsmount *);
58295 + str1 = va_arg(ap, char *);
58296 + str2 = va_arg(ap, char *);
58297 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58298 + break;
58299 + case GR_RBAC_MODE3:
58300 + dentry = va_arg(ap, struct dentry *);
58301 + mnt = va_arg(ap, struct vfsmount *);
58302 + str1 = va_arg(ap, char *);
58303 + str2 = va_arg(ap, char *);
58304 + str3 = va_arg(ap, char *);
58305 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58306 + break;
58307 + case GR_FILENAME:
58308 + dentry = va_arg(ap, struct dentry *);
58309 + mnt = va_arg(ap, struct vfsmount *);
58310 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58311 + break;
58312 + case GR_STR_FILENAME:
58313 + str1 = va_arg(ap, char *);
58314 + dentry = va_arg(ap, struct dentry *);
58315 + mnt = va_arg(ap, struct vfsmount *);
58316 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58317 + break;
58318 + case GR_FILENAME_STR:
58319 + dentry = va_arg(ap, struct dentry *);
58320 + mnt = va_arg(ap, struct vfsmount *);
58321 + str1 = va_arg(ap, char *);
58322 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58323 + break;
58324 + case GR_FILENAME_TWO_INT:
58325 + dentry = va_arg(ap, struct dentry *);
58326 + mnt = va_arg(ap, struct vfsmount *);
58327 + num1 = va_arg(ap, int);
58328 + num2 = va_arg(ap, int);
58329 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58330 + break;
58331 + case GR_FILENAME_TWO_INT_STR:
58332 + dentry = va_arg(ap, struct dentry *);
58333 + mnt = va_arg(ap, struct vfsmount *);
58334 + num1 = va_arg(ap, int);
58335 + num2 = va_arg(ap, int);
58336 + str1 = va_arg(ap, char *);
58337 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58338 + break;
58339 + case GR_TEXTREL:
58340 + file = va_arg(ap, struct file *);
58341 + ulong1 = va_arg(ap, unsigned long);
58342 + ulong2 = va_arg(ap, unsigned long);
58343 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58344 + break;
58345 + case GR_PTRACE:
58346 + task = va_arg(ap, struct task_struct *);
58347 + 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);
58348 + break;
58349 + case GR_RESOURCE:
58350 + task = va_arg(ap, struct task_struct *);
58351 + cred = __task_cred(task);
58352 + pcred = __task_cred(task->real_parent);
58353 + ulong1 = va_arg(ap, unsigned long);
58354 + str1 = va_arg(ap, char *);
58355 + ulong2 = va_arg(ap, unsigned long);
58356 + 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);
58357 + break;
58358 + case GR_CAP:
58359 + task = va_arg(ap, struct task_struct *);
58360 + cred = __task_cred(task);
58361 + pcred = __task_cred(task->real_parent);
58362 + str1 = va_arg(ap, char *);
58363 + 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);
58364 + break;
58365 + case GR_SIG:
58366 + str1 = va_arg(ap, char *);
58367 + voidptr = va_arg(ap, void *);
58368 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58369 + break;
58370 + case GR_SIG2:
58371 + task = va_arg(ap, struct task_struct *);
58372 + cred = __task_cred(task);
58373 + pcred = __task_cred(task->real_parent);
58374 + num1 = va_arg(ap, int);
58375 + 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);
58376 + break;
58377 + case GR_CRASH1:
58378 + task = va_arg(ap, struct task_struct *);
58379 + cred = __task_cred(task);
58380 + pcred = __task_cred(task->real_parent);
58381 + ulong1 = va_arg(ap, unsigned long);
58382 + 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);
58383 + break;
58384 + case GR_CRASH2:
58385 + task = va_arg(ap, struct task_struct *);
58386 + cred = __task_cred(task);
58387 + pcred = __task_cred(task->real_parent);
58388 + ulong1 = va_arg(ap, unsigned long);
58389 + 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);
58390 + break;
58391 + case GR_RWXMAP:
58392 + file = va_arg(ap, struct file *);
58393 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58394 + break;
58395 + case GR_PSACCT:
58396 + {
58397 + unsigned int wday, cday;
58398 + __u8 whr, chr;
58399 + __u8 wmin, cmin;
58400 + __u8 wsec, csec;
58401 + char cur_tty[64] = { 0 };
58402 + char parent_tty[64] = { 0 };
58403 +
58404 + task = va_arg(ap, struct task_struct *);
58405 + wday = va_arg(ap, unsigned int);
58406 + cday = va_arg(ap, unsigned int);
58407 + whr = va_arg(ap, int);
58408 + chr = va_arg(ap, int);
58409 + wmin = va_arg(ap, int);
58410 + cmin = va_arg(ap, int);
58411 + wsec = va_arg(ap, int);
58412 + csec = va_arg(ap, int);
58413 + ulong1 = va_arg(ap, unsigned long);
58414 + cred = __task_cred(task);
58415 + pcred = __task_cred(task->real_parent);
58416 +
58417 + 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);
58418 + }
58419 + break;
58420 + default:
58421 + gr_log_middle(audit, msg, ap);
58422 + }
58423 + va_end(ap);
58424 + // these don't need DEFAULTSECARGS printed on the end
58425 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58426 + gr_log_end(audit, 0);
58427 + else
58428 + gr_log_end(audit, 1);
58429 + END_LOCKS(audit);
58430 +}
58431 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58432 new file mode 100644
58433 index 0000000..f536303
58434 --- /dev/null
58435 +++ b/grsecurity/grsec_mem.c
58436 @@ -0,0 +1,40 @@
58437 +#include <linux/kernel.h>
58438 +#include <linux/sched.h>
58439 +#include <linux/mm.h>
58440 +#include <linux/mman.h>
58441 +#include <linux/grinternal.h>
58442 +
58443 +void
58444 +gr_handle_ioperm(void)
58445 +{
58446 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58447 + return;
58448 +}
58449 +
58450 +void
58451 +gr_handle_iopl(void)
58452 +{
58453 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58454 + return;
58455 +}
58456 +
58457 +void
58458 +gr_handle_mem_readwrite(u64 from, u64 to)
58459 +{
58460 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58461 + return;
58462 +}
58463 +
58464 +void
58465 +gr_handle_vm86(void)
58466 +{
58467 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58468 + return;
58469 +}
58470 +
58471 +void
58472 +gr_log_badprocpid(const char *entry)
58473 +{
58474 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58475 + return;
58476 +}
58477 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58478 new file mode 100644
58479 index 0000000..2131422
58480 --- /dev/null
58481 +++ b/grsecurity/grsec_mount.c
58482 @@ -0,0 +1,62 @@
58483 +#include <linux/kernel.h>
58484 +#include <linux/sched.h>
58485 +#include <linux/mount.h>
58486 +#include <linux/grsecurity.h>
58487 +#include <linux/grinternal.h>
58488 +
58489 +void
58490 +gr_log_remount(const char *devname, const int retval)
58491 +{
58492 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58493 + if (grsec_enable_mount && (retval >= 0))
58494 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58495 +#endif
58496 + return;
58497 +}
58498 +
58499 +void
58500 +gr_log_unmount(const char *devname, const int retval)
58501 +{
58502 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58503 + if (grsec_enable_mount && (retval >= 0))
58504 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58505 +#endif
58506 + return;
58507 +}
58508 +
58509 +void
58510 +gr_log_mount(const char *from, const char *to, const int retval)
58511 +{
58512 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58513 + if (grsec_enable_mount && (retval >= 0))
58514 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58515 +#endif
58516 + return;
58517 +}
58518 +
58519 +int
58520 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58521 +{
58522 +#ifdef CONFIG_GRKERNSEC_ROFS
58523 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58524 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58525 + return -EPERM;
58526 + } else
58527 + return 0;
58528 +#endif
58529 + return 0;
58530 +}
58531 +
58532 +int
58533 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58534 +{
58535 +#ifdef CONFIG_GRKERNSEC_ROFS
58536 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58537 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58538 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58539 + return -EPERM;
58540 + } else
58541 + return 0;
58542 +#endif
58543 + return 0;
58544 +}
58545 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58546 new file mode 100644
58547 index 0000000..a3b12a0
58548 --- /dev/null
58549 +++ b/grsecurity/grsec_pax.c
58550 @@ -0,0 +1,36 @@
58551 +#include <linux/kernel.h>
58552 +#include <linux/sched.h>
58553 +#include <linux/mm.h>
58554 +#include <linux/file.h>
58555 +#include <linux/grinternal.h>
58556 +#include <linux/grsecurity.h>
58557 +
58558 +void
58559 +gr_log_textrel(struct vm_area_struct * vma)
58560 +{
58561 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58562 + if (grsec_enable_audit_textrel)
58563 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58564 +#endif
58565 + return;
58566 +}
58567 +
58568 +void
58569 +gr_log_rwxmmap(struct file *file)
58570 +{
58571 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58572 + if (grsec_enable_log_rwxmaps)
58573 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58574 +#endif
58575 + return;
58576 +}
58577 +
58578 +void
58579 +gr_log_rwxmprotect(struct file *file)
58580 +{
58581 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58582 + if (grsec_enable_log_rwxmaps)
58583 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58584 +#endif
58585 + return;
58586 +}
58587 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58588 new file mode 100644
58589 index 0000000..f7f29aa
58590 --- /dev/null
58591 +++ b/grsecurity/grsec_ptrace.c
58592 @@ -0,0 +1,30 @@
58593 +#include <linux/kernel.h>
58594 +#include <linux/sched.h>
58595 +#include <linux/grinternal.h>
58596 +#include <linux/security.h>
58597 +
58598 +void
58599 +gr_audit_ptrace(struct task_struct *task)
58600 +{
58601 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58602 + if (grsec_enable_audit_ptrace)
58603 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58604 +#endif
58605 + return;
58606 +}
58607 +
58608 +int
58609 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58610 +{
58611 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58612 + const struct dentry *dentry = file->f_path.dentry;
58613 + const struct vfsmount *mnt = file->f_path.mnt;
58614 +
58615 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58616 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58617 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58618 + return -EACCES;
58619 + }
58620 +#endif
58621 + return 0;
58622 +}
58623 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58624 new file mode 100644
58625 index 0000000..b4ac94c
58626 --- /dev/null
58627 +++ b/grsecurity/grsec_sig.c
58628 @@ -0,0 +1,209 @@
58629 +#include <linux/kernel.h>
58630 +#include <linux/sched.h>
58631 +#include <linux/delay.h>
58632 +#include <linux/grsecurity.h>
58633 +#include <linux/grinternal.h>
58634 +#include <linux/hardirq.h>
58635 +
58636 +char *signames[] = {
58637 + [SIGSEGV] = "Segmentation fault",
58638 + [SIGILL] = "Illegal instruction",
58639 + [SIGABRT] = "Abort",
58640 + [SIGBUS] = "Invalid alignment/Bus error"
58641 +};
58642 +
58643 +void
58644 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58645 +{
58646 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58647 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58648 + (sig == SIGABRT) || (sig == SIGBUS))) {
58649 + if (t->pid == current->pid) {
58650 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58651 + } else {
58652 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58653 + }
58654 + }
58655 +#endif
58656 + return;
58657 +}
58658 +
58659 +int
58660 +gr_handle_signal(const struct task_struct *p, const int sig)
58661 +{
58662 +#ifdef CONFIG_GRKERNSEC
58663 + /* ignore the 0 signal for protected task checks */
58664 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58665 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58666 + return -EPERM;
58667 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58668 + return -EPERM;
58669 + }
58670 +#endif
58671 + return 0;
58672 +}
58673 +
58674 +#ifdef CONFIG_GRKERNSEC
58675 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58676 +
58677 +int gr_fake_force_sig(int sig, struct task_struct *t)
58678 +{
58679 + unsigned long int flags;
58680 + int ret, blocked, ignored;
58681 + struct k_sigaction *action;
58682 +
58683 + spin_lock_irqsave(&t->sighand->siglock, flags);
58684 + action = &t->sighand->action[sig-1];
58685 + ignored = action->sa.sa_handler == SIG_IGN;
58686 + blocked = sigismember(&t->blocked, sig);
58687 + if (blocked || ignored) {
58688 + action->sa.sa_handler = SIG_DFL;
58689 + if (blocked) {
58690 + sigdelset(&t->blocked, sig);
58691 + recalc_sigpending_and_wake(t);
58692 + }
58693 + }
58694 + if (action->sa.sa_handler == SIG_DFL)
58695 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58696 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58697 +
58698 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58699 +
58700 + return ret;
58701 +}
58702 +#endif
58703 +
58704 +#ifdef CONFIG_GRKERNSEC_BRUTE
58705 +#define GR_USER_BAN_TIME (15 * 60)
58706 +
58707 +static int __get_dumpable(unsigned long mm_flags)
58708 +{
58709 + int ret;
58710 +
58711 + ret = mm_flags & MMF_DUMPABLE_MASK;
58712 + return (ret >= 2) ? 2 : ret;
58713 +}
58714 +#endif
58715 +
58716 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58717 +{
58718 +#ifdef CONFIG_GRKERNSEC_BRUTE
58719 + kuid_t uid = GLOBAL_ROOT_UID;
58720 +
58721 + if (!grsec_enable_brute)
58722 + return;
58723 +
58724 + rcu_read_lock();
58725 + read_lock(&tasklist_lock);
58726 + read_lock(&grsec_exec_file_lock);
58727 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58728 + p->real_parent->brute = 1;
58729 + else {
58730 + const struct cred *cred = __task_cred(p), *cred2;
58731 + struct task_struct *tsk, *tsk2;
58732 +
58733 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58734 + struct user_struct *user;
58735 +
58736 + uid = cred->uid;
58737 +
58738 + /* this is put upon execution past expiration */
58739 + user = find_user(uid);
58740 + if (user == NULL)
58741 + goto unlock;
58742 + user->banned = 1;
58743 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58744 + if (user->ban_expires == ~0UL)
58745 + user->ban_expires--;
58746 +
58747 + do_each_thread(tsk2, tsk) {
58748 + cred2 = __task_cred(tsk);
58749 + if (tsk != p && uid_eq(cred2->uid, uid))
58750 + gr_fake_force_sig(SIGKILL, tsk);
58751 + } while_each_thread(tsk2, tsk);
58752 + }
58753 + }
58754 +unlock:
58755 + read_unlock(&grsec_exec_file_lock);
58756 + read_unlock(&tasklist_lock);
58757 + rcu_read_unlock();
58758 +
58759 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
58760 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58761 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58762 +
58763 +#endif
58764 + return;
58765 +}
58766 +
58767 +void gr_handle_brute_check(void)
58768 +{
58769 +#ifdef CONFIG_GRKERNSEC_BRUTE
58770 + if (current->brute)
58771 + msleep(30 * 1000);
58772 +#endif
58773 + return;
58774 +}
58775 +
58776 +void gr_handle_kernel_exploit(void)
58777 +{
58778 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58779 + const struct cred *cred;
58780 + struct task_struct *tsk, *tsk2;
58781 + struct user_struct *user;
58782 + kuid_t uid;
58783 +
58784 + if (in_irq() || in_serving_softirq() || in_nmi())
58785 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58786 +
58787 + uid = current_uid();
58788 +
58789 + if (uid_eq(uid, GLOBAL_ROOT_UID))
58790 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58791 + else {
58792 + /* kill all the processes of this user, hold a reference
58793 + to their creds struct, and prevent them from creating
58794 + another process until system reset
58795 + */
58796 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58797 + from_kuid_munged(&init_user_ns, uid));
58798 + /* we intentionally leak this ref */
58799 + user = get_uid(current->cred->user);
58800 + if (user) {
58801 + user->banned = 1;
58802 + user->ban_expires = ~0UL;
58803 + }
58804 +
58805 + read_lock(&tasklist_lock);
58806 + do_each_thread(tsk2, tsk) {
58807 + cred = __task_cred(tsk);
58808 + if (uid_eq(cred->uid, uid))
58809 + gr_fake_force_sig(SIGKILL, tsk);
58810 + } while_each_thread(tsk2, tsk);
58811 + read_unlock(&tasklist_lock);
58812 + }
58813 +#endif
58814 +}
58815 +
58816 +int __gr_process_user_ban(struct user_struct *user)
58817 +{
58818 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58819 + if (unlikely(user->banned)) {
58820 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58821 + user->banned = 0;
58822 + user->ban_expires = 0;
58823 + free_uid(user);
58824 + } else
58825 + return -EPERM;
58826 + }
58827 +#endif
58828 + return 0;
58829 +}
58830 +
58831 +int gr_process_user_ban(void)
58832 +{
58833 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58834 + return __gr_process_user_ban(current->cred->user);
58835 +#endif
58836 + return 0;
58837 +}
58838 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58839 new file mode 100644
58840 index 0000000..4030d57
58841 --- /dev/null
58842 +++ b/grsecurity/grsec_sock.c
58843 @@ -0,0 +1,244 @@
58844 +#include <linux/kernel.h>
58845 +#include <linux/module.h>
58846 +#include <linux/sched.h>
58847 +#include <linux/file.h>
58848 +#include <linux/net.h>
58849 +#include <linux/in.h>
58850 +#include <linux/ip.h>
58851 +#include <net/sock.h>
58852 +#include <net/inet_sock.h>
58853 +#include <linux/grsecurity.h>
58854 +#include <linux/grinternal.h>
58855 +#include <linux/gracl.h>
58856 +
58857 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58858 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58859 +
58860 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58861 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58862 +
58863 +#ifdef CONFIG_UNIX_MODULE
58864 +EXPORT_SYMBOL(gr_acl_handle_unix);
58865 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58866 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58867 +EXPORT_SYMBOL(gr_handle_create);
58868 +#endif
58869 +
58870 +#ifdef CONFIG_GRKERNSEC
58871 +#define gr_conn_table_size 32749
58872 +struct conn_table_entry {
58873 + struct conn_table_entry *next;
58874 + struct signal_struct *sig;
58875 +};
58876 +
58877 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58878 +DEFINE_SPINLOCK(gr_conn_table_lock);
58879 +
58880 +extern const char * gr_socktype_to_name(unsigned char type);
58881 +extern const char * gr_proto_to_name(unsigned char proto);
58882 +extern const char * gr_sockfamily_to_name(unsigned char family);
58883 +
58884 +static __inline__ int
58885 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58886 +{
58887 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58888 +}
58889 +
58890 +static __inline__ int
58891 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58892 + __u16 sport, __u16 dport)
58893 +{
58894 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58895 + sig->gr_sport == sport && sig->gr_dport == dport))
58896 + return 1;
58897 + else
58898 + return 0;
58899 +}
58900 +
58901 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58902 +{
58903 + struct conn_table_entry **match;
58904 + unsigned int index;
58905 +
58906 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58907 + sig->gr_sport, sig->gr_dport,
58908 + gr_conn_table_size);
58909 +
58910 + newent->sig = sig;
58911 +
58912 + match = &gr_conn_table[index];
58913 + newent->next = *match;
58914 + *match = newent;
58915 +
58916 + return;
58917 +}
58918 +
58919 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58920 +{
58921 + struct conn_table_entry *match, *last = NULL;
58922 + unsigned int index;
58923 +
58924 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58925 + sig->gr_sport, sig->gr_dport,
58926 + gr_conn_table_size);
58927 +
58928 + match = gr_conn_table[index];
58929 + while (match && !conn_match(match->sig,
58930 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58931 + sig->gr_dport)) {
58932 + last = match;
58933 + match = match->next;
58934 + }
58935 +
58936 + if (match) {
58937 + if (last)
58938 + last->next = match->next;
58939 + else
58940 + gr_conn_table[index] = NULL;
58941 + kfree(match);
58942 + }
58943 +
58944 + return;
58945 +}
58946 +
58947 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58948 + __u16 sport, __u16 dport)
58949 +{
58950 + struct conn_table_entry *match;
58951 + unsigned int index;
58952 +
58953 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58954 +
58955 + match = gr_conn_table[index];
58956 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58957 + match = match->next;
58958 +
58959 + if (match)
58960 + return match->sig;
58961 + else
58962 + return NULL;
58963 +}
58964 +
58965 +#endif
58966 +
58967 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58968 +{
58969 +#ifdef CONFIG_GRKERNSEC
58970 + struct signal_struct *sig = task->signal;
58971 + struct conn_table_entry *newent;
58972 +
58973 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58974 + if (newent == NULL)
58975 + return;
58976 + /* no bh lock needed since we are called with bh disabled */
58977 + spin_lock(&gr_conn_table_lock);
58978 + gr_del_task_from_ip_table_nolock(sig);
58979 + sig->gr_saddr = inet->inet_rcv_saddr;
58980 + sig->gr_daddr = inet->inet_daddr;
58981 + sig->gr_sport = inet->inet_sport;
58982 + sig->gr_dport = inet->inet_dport;
58983 + gr_add_to_task_ip_table_nolock(sig, newent);
58984 + spin_unlock(&gr_conn_table_lock);
58985 +#endif
58986 + return;
58987 +}
58988 +
58989 +void gr_del_task_from_ip_table(struct task_struct *task)
58990 +{
58991 +#ifdef CONFIG_GRKERNSEC
58992 + spin_lock_bh(&gr_conn_table_lock);
58993 + gr_del_task_from_ip_table_nolock(task->signal);
58994 + spin_unlock_bh(&gr_conn_table_lock);
58995 +#endif
58996 + return;
58997 +}
58998 +
58999 +void
59000 +gr_attach_curr_ip(const struct sock *sk)
59001 +{
59002 +#ifdef CONFIG_GRKERNSEC
59003 + struct signal_struct *p, *set;
59004 + const struct inet_sock *inet = inet_sk(sk);
59005 +
59006 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59007 + return;
59008 +
59009 + set = current->signal;
59010 +
59011 + spin_lock_bh(&gr_conn_table_lock);
59012 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59013 + inet->inet_dport, inet->inet_sport);
59014 + if (unlikely(p != NULL)) {
59015 + set->curr_ip = p->curr_ip;
59016 + set->used_accept = 1;
59017 + gr_del_task_from_ip_table_nolock(p);
59018 + spin_unlock_bh(&gr_conn_table_lock);
59019 + return;
59020 + }
59021 + spin_unlock_bh(&gr_conn_table_lock);
59022 +
59023 + set->curr_ip = inet->inet_daddr;
59024 + set->used_accept = 1;
59025 +#endif
59026 + return;
59027 +}
59028 +
59029 +int
59030 +gr_handle_sock_all(const int family, const int type, const int protocol)
59031 +{
59032 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59033 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59034 + (family != AF_UNIX)) {
59035 + if (family == AF_INET)
59036 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59037 + else
59038 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59039 + return -EACCES;
59040 + }
59041 +#endif
59042 + return 0;
59043 +}
59044 +
59045 +int
59046 +gr_handle_sock_server(const struct sockaddr *sck)
59047 +{
59048 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59049 + if (grsec_enable_socket_server &&
59050 + in_group_p(grsec_socket_server_gid) &&
59051 + sck && (sck->sa_family != AF_UNIX) &&
59052 + (sck->sa_family != AF_LOCAL)) {
59053 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59054 + return -EACCES;
59055 + }
59056 +#endif
59057 + return 0;
59058 +}
59059 +
59060 +int
59061 +gr_handle_sock_server_other(const struct sock *sck)
59062 +{
59063 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59064 + if (grsec_enable_socket_server &&
59065 + in_group_p(grsec_socket_server_gid) &&
59066 + sck && (sck->sk_family != AF_UNIX) &&
59067 + (sck->sk_family != AF_LOCAL)) {
59068 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59069 + return -EACCES;
59070 + }
59071 +#endif
59072 + return 0;
59073 +}
59074 +
59075 +int
59076 +gr_handle_sock_client(const struct sockaddr *sck)
59077 +{
59078 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59079 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59080 + sck && (sck->sa_family != AF_UNIX) &&
59081 + (sck->sa_family != AF_LOCAL)) {
59082 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59083 + return -EACCES;
59084 + }
59085 +#endif
59086 + return 0;
59087 +}
59088 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59089 new file mode 100644
59090 index 0000000..f55ef0f
59091 --- /dev/null
59092 +++ b/grsecurity/grsec_sysctl.c
59093 @@ -0,0 +1,469 @@
59094 +#include <linux/kernel.h>
59095 +#include <linux/sched.h>
59096 +#include <linux/sysctl.h>
59097 +#include <linux/grsecurity.h>
59098 +#include <linux/grinternal.h>
59099 +
59100 +int
59101 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59102 +{
59103 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59104 + if (dirname == NULL || name == NULL)
59105 + return 0;
59106 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59107 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59108 + return -EACCES;
59109 + }
59110 +#endif
59111 + return 0;
59112 +}
59113 +
59114 +#ifdef CONFIG_GRKERNSEC_ROFS
59115 +static int __maybe_unused one = 1;
59116 +#endif
59117 +
59118 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59119 +struct ctl_table grsecurity_table[] = {
59120 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59121 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59122 +#ifdef CONFIG_GRKERNSEC_IO
59123 + {
59124 + .procname = "disable_priv_io",
59125 + .data = &grsec_disable_privio,
59126 + .maxlen = sizeof(int),
59127 + .mode = 0600,
59128 + .proc_handler = &proc_dointvec,
59129 + },
59130 +#endif
59131 +#endif
59132 +#ifdef CONFIG_GRKERNSEC_LINK
59133 + {
59134 + .procname = "linking_restrictions",
59135 + .data = &grsec_enable_link,
59136 + .maxlen = sizeof(int),
59137 + .mode = 0600,
59138 + .proc_handler = &proc_dointvec,
59139 + },
59140 +#endif
59141 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59142 + {
59143 + .procname = "enforce_symlinksifowner",
59144 + .data = &grsec_enable_symlinkown,
59145 + .maxlen = sizeof(int),
59146 + .mode = 0600,
59147 + .proc_handler = &proc_dointvec,
59148 + },
59149 + {
59150 + .procname = "symlinkown_gid",
59151 + .data = &grsec_symlinkown_gid,
59152 + .maxlen = sizeof(int),
59153 + .mode = 0600,
59154 + .proc_handler = &proc_dointvec,
59155 + },
59156 +#endif
59157 +#ifdef CONFIG_GRKERNSEC_BRUTE
59158 + {
59159 + .procname = "deter_bruteforce",
59160 + .data = &grsec_enable_brute,
59161 + .maxlen = sizeof(int),
59162 + .mode = 0600,
59163 + .proc_handler = &proc_dointvec,
59164 + },
59165 +#endif
59166 +#ifdef CONFIG_GRKERNSEC_FIFO
59167 + {
59168 + .procname = "fifo_restrictions",
59169 + .data = &grsec_enable_fifo,
59170 + .maxlen = sizeof(int),
59171 + .mode = 0600,
59172 + .proc_handler = &proc_dointvec,
59173 + },
59174 +#endif
59175 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59176 + {
59177 + .procname = "ptrace_readexec",
59178 + .data = &grsec_enable_ptrace_readexec,
59179 + .maxlen = sizeof(int),
59180 + .mode = 0600,
59181 + .proc_handler = &proc_dointvec,
59182 + },
59183 +#endif
59184 +#ifdef CONFIG_GRKERNSEC_SETXID
59185 + {
59186 + .procname = "consistent_setxid",
59187 + .data = &grsec_enable_setxid,
59188 + .maxlen = sizeof(int),
59189 + .mode = 0600,
59190 + .proc_handler = &proc_dointvec,
59191 + },
59192 +#endif
59193 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59194 + {
59195 + .procname = "ip_blackhole",
59196 + .data = &grsec_enable_blackhole,
59197 + .maxlen = sizeof(int),
59198 + .mode = 0600,
59199 + .proc_handler = &proc_dointvec,
59200 + },
59201 + {
59202 + .procname = "lastack_retries",
59203 + .data = &grsec_lastack_retries,
59204 + .maxlen = sizeof(int),
59205 + .mode = 0600,
59206 + .proc_handler = &proc_dointvec,
59207 + },
59208 +#endif
59209 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59210 + {
59211 + .procname = "exec_logging",
59212 + .data = &grsec_enable_execlog,
59213 + .maxlen = sizeof(int),
59214 + .mode = 0600,
59215 + .proc_handler = &proc_dointvec,
59216 + },
59217 +#endif
59218 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59219 + {
59220 + .procname = "rwxmap_logging",
59221 + .data = &grsec_enable_log_rwxmaps,
59222 + .maxlen = sizeof(int),
59223 + .mode = 0600,
59224 + .proc_handler = &proc_dointvec,
59225 + },
59226 +#endif
59227 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59228 + {
59229 + .procname = "signal_logging",
59230 + .data = &grsec_enable_signal,
59231 + .maxlen = sizeof(int),
59232 + .mode = 0600,
59233 + .proc_handler = &proc_dointvec,
59234 + },
59235 +#endif
59236 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59237 + {
59238 + .procname = "forkfail_logging",
59239 + .data = &grsec_enable_forkfail,
59240 + .maxlen = sizeof(int),
59241 + .mode = 0600,
59242 + .proc_handler = &proc_dointvec,
59243 + },
59244 +#endif
59245 +#ifdef CONFIG_GRKERNSEC_TIME
59246 + {
59247 + .procname = "timechange_logging",
59248 + .data = &grsec_enable_time,
59249 + .maxlen = sizeof(int),
59250 + .mode = 0600,
59251 + .proc_handler = &proc_dointvec,
59252 + },
59253 +#endif
59254 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59255 + {
59256 + .procname = "chroot_deny_shmat",
59257 + .data = &grsec_enable_chroot_shmat,
59258 + .maxlen = sizeof(int),
59259 + .mode = 0600,
59260 + .proc_handler = &proc_dointvec,
59261 + },
59262 +#endif
59263 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59264 + {
59265 + .procname = "chroot_deny_unix",
59266 + .data = &grsec_enable_chroot_unix,
59267 + .maxlen = sizeof(int),
59268 + .mode = 0600,
59269 + .proc_handler = &proc_dointvec,
59270 + },
59271 +#endif
59272 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59273 + {
59274 + .procname = "chroot_deny_mount",
59275 + .data = &grsec_enable_chroot_mount,
59276 + .maxlen = sizeof(int),
59277 + .mode = 0600,
59278 + .proc_handler = &proc_dointvec,
59279 + },
59280 +#endif
59281 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59282 + {
59283 + .procname = "chroot_deny_fchdir",
59284 + .data = &grsec_enable_chroot_fchdir,
59285 + .maxlen = sizeof(int),
59286 + .mode = 0600,
59287 + .proc_handler = &proc_dointvec,
59288 + },
59289 +#endif
59290 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59291 + {
59292 + .procname = "chroot_deny_chroot",
59293 + .data = &grsec_enable_chroot_double,
59294 + .maxlen = sizeof(int),
59295 + .mode = 0600,
59296 + .proc_handler = &proc_dointvec,
59297 + },
59298 +#endif
59299 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59300 + {
59301 + .procname = "chroot_deny_pivot",
59302 + .data = &grsec_enable_chroot_pivot,
59303 + .maxlen = sizeof(int),
59304 + .mode = 0600,
59305 + .proc_handler = &proc_dointvec,
59306 + },
59307 +#endif
59308 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59309 + {
59310 + .procname = "chroot_enforce_chdir",
59311 + .data = &grsec_enable_chroot_chdir,
59312 + .maxlen = sizeof(int),
59313 + .mode = 0600,
59314 + .proc_handler = &proc_dointvec,
59315 + },
59316 +#endif
59317 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59318 + {
59319 + .procname = "chroot_deny_chmod",
59320 + .data = &grsec_enable_chroot_chmod,
59321 + .maxlen = sizeof(int),
59322 + .mode = 0600,
59323 + .proc_handler = &proc_dointvec,
59324 + },
59325 +#endif
59326 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59327 + {
59328 + .procname = "chroot_deny_mknod",
59329 + .data = &grsec_enable_chroot_mknod,
59330 + .maxlen = sizeof(int),
59331 + .mode = 0600,
59332 + .proc_handler = &proc_dointvec,
59333 + },
59334 +#endif
59335 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59336 + {
59337 + .procname = "chroot_restrict_nice",
59338 + .data = &grsec_enable_chroot_nice,
59339 + .maxlen = sizeof(int),
59340 + .mode = 0600,
59341 + .proc_handler = &proc_dointvec,
59342 + },
59343 +#endif
59344 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59345 + {
59346 + .procname = "chroot_execlog",
59347 + .data = &grsec_enable_chroot_execlog,
59348 + .maxlen = sizeof(int),
59349 + .mode = 0600,
59350 + .proc_handler = &proc_dointvec,
59351 + },
59352 +#endif
59353 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59354 + {
59355 + .procname = "chroot_caps",
59356 + .data = &grsec_enable_chroot_caps,
59357 + .maxlen = sizeof(int),
59358 + .mode = 0600,
59359 + .proc_handler = &proc_dointvec,
59360 + },
59361 +#endif
59362 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59363 + {
59364 + .procname = "chroot_deny_sysctl",
59365 + .data = &grsec_enable_chroot_sysctl,
59366 + .maxlen = sizeof(int),
59367 + .mode = 0600,
59368 + .proc_handler = &proc_dointvec,
59369 + },
59370 +#endif
59371 +#ifdef CONFIG_GRKERNSEC_TPE
59372 + {
59373 + .procname = "tpe",
59374 + .data = &grsec_enable_tpe,
59375 + .maxlen = sizeof(int),
59376 + .mode = 0600,
59377 + .proc_handler = &proc_dointvec,
59378 + },
59379 + {
59380 + .procname = "tpe_gid",
59381 + .data = &grsec_tpe_gid,
59382 + .maxlen = sizeof(int),
59383 + .mode = 0600,
59384 + .proc_handler = &proc_dointvec,
59385 + },
59386 +#endif
59387 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59388 + {
59389 + .procname = "tpe_invert",
59390 + .data = &grsec_enable_tpe_invert,
59391 + .maxlen = sizeof(int),
59392 + .mode = 0600,
59393 + .proc_handler = &proc_dointvec,
59394 + },
59395 +#endif
59396 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59397 + {
59398 + .procname = "tpe_restrict_all",
59399 + .data = &grsec_enable_tpe_all,
59400 + .maxlen = sizeof(int),
59401 + .mode = 0600,
59402 + .proc_handler = &proc_dointvec,
59403 + },
59404 +#endif
59405 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59406 + {
59407 + .procname = "socket_all",
59408 + .data = &grsec_enable_socket_all,
59409 + .maxlen = sizeof(int),
59410 + .mode = 0600,
59411 + .proc_handler = &proc_dointvec,
59412 + },
59413 + {
59414 + .procname = "socket_all_gid",
59415 + .data = &grsec_socket_all_gid,
59416 + .maxlen = sizeof(int),
59417 + .mode = 0600,
59418 + .proc_handler = &proc_dointvec,
59419 + },
59420 +#endif
59421 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59422 + {
59423 + .procname = "socket_client",
59424 + .data = &grsec_enable_socket_client,
59425 + .maxlen = sizeof(int),
59426 + .mode = 0600,
59427 + .proc_handler = &proc_dointvec,
59428 + },
59429 + {
59430 + .procname = "socket_client_gid",
59431 + .data = &grsec_socket_client_gid,
59432 + .maxlen = sizeof(int),
59433 + .mode = 0600,
59434 + .proc_handler = &proc_dointvec,
59435 + },
59436 +#endif
59437 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59438 + {
59439 + .procname = "socket_server",
59440 + .data = &grsec_enable_socket_server,
59441 + .maxlen = sizeof(int),
59442 + .mode = 0600,
59443 + .proc_handler = &proc_dointvec,
59444 + },
59445 + {
59446 + .procname = "socket_server_gid",
59447 + .data = &grsec_socket_server_gid,
59448 + .maxlen = sizeof(int),
59449 + .mode = 0600,
59450 + .proc_handler = &proc_dointvec,
59451 + },
59452 +#endif
59453 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59454 + {
59455 + .procname = "audit_group",
59456 + .data = &grsec_enable_group,
59457 + .maxlen = sizeof(int),
59458 + .mode = 0600,
59459 + .proc_handler = &proc_dointvec,
59460 + },
59461 + {
59462 + .procname = "audit_gid",
59463 + .data = &grsec_audit_gid,
59464 + .maxlen = sizeof(int),
59465 + .mode = 0600,
59466 + .proc_handler = &proc_dointvec,
59467 + },
59468 +#endif
59469 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59470 + {
59471 + .procname = "audit_chdir",
59472 + .data = &grsec_enable_chdir,
59473 + .maxlen = sizeof(int),
59474 + .mode = 0600,
59475 + .proc_handler = &proc_dointvec,
59476 + },
59477 +#endif
59478 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59479 + {
59480 + .procname = "audit_mount",
59481 + .data = &grsec_enable_mount,
59482 + .maxlen = sizeof(int),
59483 + .mode = 0600,
59484 + .proc_handler = &proc_dointvec,
59485 + },
59486 +#endif
59487 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59488 + {
59489 + .procname = "audit_textrel",
59490 + .data = &grsec_enable_audit_textrel,
59491 + .maxlen = sizeof(int),
59492 + .mode = 0600,
59493 + .proc_handler = &proc_dointvec,
59494 + },
59495 +#endif
59496 +#ifdef CONFIG_GRKERNSEC_DMESG
59497 + {
59498 + .procname = "dmesg",
59499 + .data = &grsec_enable_dmesg,
59500 + .maxlen = sizeof(int),
59501 + .mode = 0600,
59502 + .proc_handler = &proc_dointvec,
59503 + },
59504 +#endif
59505 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59506 + {
59507 + .procname = "chroot_findtask",
59508 + .data = &grsec_enable_chroot_findtask,
59509 + .maxlen = sizeof(int),
59510 + .mode = 0600,
59511 + .proc_handler = &proc_dointvec,
59512 + },
59513 +#endif
59514 +#ifdef CONFIG_GRKERNSEC_RESLOG
59515 + {
59516 + .procname = "resource_logging",
59517 + .data = &grsec_resource_logging,
59518 + .maxlen = sizeof(int),
59519 + .mode = 0600,
59520 + .proc_handler = &proc_dointvec,
59521 + },
59522 +#endif
59523 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59524 + {
59525 + .procname = "audit_ptrace",
59526 + .data = &grsec_enable_audit_ptrace,
59527 + .maxlen = sizeof(int),
59528 + .mode = 0600,
59529 + .proc_handler = &proc_dointvec,
59530 + },
59531 +#endif
59532 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59533 + {
59534 + .procname = "harden_ptrace",
59535 + .data = &grsec_enable_harden_ptrace,
59536 + .maxlen = sizeof(int),
59537 + .mode = 0600,
59538 + .proc_handler = &proc_dointvec,
59539 + },
59540 +#endif
59541 + {
59542 + .procname = "grsec_lock",
59543 + .data = &grsec_lock,
59544 + .maxlen = sizeof(int),
59545 + .mode = 0600,
59546 + .proc_handler = &proc_dointvec,
59547 + },
59548 +#endif
59549 +#ifdef CONFIG_GRKERNSEC_ROFS
59550 + {
59551 + .procname = "romount_protect",
59552 + .data = &grsec_enable_rofs,
59553 + .maxlen = sizeof(int),
59554 + .mode = 0600,
59555 + .proc_handler = &proc_dointvec_minmax,
59556 + .extra1 = &one,
59557 + .extra2 = &one,
59558 + },
59559 +#endif
59560 + { }
59561 +};
59562 +#endif
59563 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59564 new file mode 100644
59565 index 0000000..0dc13c3
59566 --- /dev/null
59567 +++ b/grsecurity/grsec_time.c
59568 @@ -0,0 +1,16 @@
59569 +#include <linux/kernel.h>
59570 +#include <linux/sched.h>
59571 +#include <linux/grinternal.h>
59572 +#include <linux/module.h>
59573 +
59574 +void
59575 +gr_log_timechange(void)
59576 +{
59577 +#ifdef CONFIG_GRKERNSEC_TIME
59578 + if (grsec_enable_time)
59579 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59580 +#endif
59581 + return;
59582 +}
59583 +
59584 +EXPORT_SYMBOL(gr_log_timechange);
59585 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59586 new file mode 100644
59587 index 0000000..07e0dc0
59588 --- /dev/null
59589 +++ b/grsecurity/grsec_tpe.c
59590 @@ -0,0 +1,73 @@
59591 +#include <linux/kernel.h>
59592 +#include <linux/sched.h>
59593 +#include <linux/file.h>
59594 +#include <linux/fs.h>
59595 +#include <linux/grinternal.h>
59596 +
59597 +extern int gr_acl_tpe_check(void);
59598 +
59599 +int
59600 +gr_tpe_allow(const struct file *file)
59601 +{
59602 +#ifdef CONFIG_GRKERNSEC
59603 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59604 + const struct cred *cred = current_cred();
59605 + char *msg = NULL;
59606 + char *msg2 = NULL;
59607 +
59608 + // never restrict root
59609 + if (!cred->uid)
59610 + return 1;
59611 +
59612 + if (grsec_enable_tpe) {
59613 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59614 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59615 + msg = "not being in trusted group";
59616 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59617 + msg = "being in untrusted group";
59618 +#else
59619 + if (in_group_p(grsec_tpe_gid))
59620 + msg = "being in untrusted group";
59621 +#endif
59622 + }
59623 + if (!msg && gr_acl_tpe_check())
59624 + msg = "being in untrusted role";
59625 +
59626 + // not in any affected group/role
59627 + if (!msg)
59628 + goto next_check;
59629 +
59630 + if (inode->i_uid)
59631 + msg2 = "file in non-root-owned directory";
59632 + else if (inode->i_mode & S_IWOTH)
59633 + msg2 = "file in world-writable directory";
59634 + else if (inode->i_mode & S_IWGRP)
59635 + msg2 = "file in group-writable directory";
59636 +
59637 + if (msg && msg2) {
59638 + char fullmsg[70] = {0};
59639 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59640 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59641 + return 0;
59642 + }
59643 + msg = NULL;
59644 +next_check:
59645 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59646 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59647 + return 1;
59648 +
59649 + if (inode->i_uid && (inode->i_uid != cred->uid))
59650 + msg = "directory not owned by user";
59651 + else if (inode->i_mode & S_IWOTH)
59652 + msg = "file in world-writable directory";
59653 + else if (inode->i_mode & S_IWGRP)
59654 + msg = "file in group-writable directory";
59655 +
59656 + if (msg) {
59657 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59658 + return 0;
59659 + }
59660 +#endif
59661 +#endif
59662 + return 1;
59663 +}
59664 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59665 new file mode 100644
59666 index 0000000..9f7b1ac
59667 --- /dev/null
59668 +++ b/grsecurity/grsum.c
59669 @@ -0,0 +1,61 @@
59670 +#include <linux/err.h>
59671 +#include <linux/kernel.h>
59672 +#include <linux/sched.h>
59673 +#include <linux/mm.h>
59674 +#include <linux/scatterlist.h>
59675 +#include <linux/crypto.h>
59676 +#include <linux/gracl.h>
59677 +
59678 +
59679 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59680 +#error "crypto and sha256 must be built into the kernel"
59681 +#endif
59682 +
59683 +int
59684 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59685 +{
59686 + char *p;
59687 + struct crypto_hash *tfm;
59688 + struct hash_desc desc;
59689 + struct scatterlist sg;
59690 + unsigned char temp_sum[GR_SHA_LEN];
59691 + volatile int retval = 0;
59692 + volatile int dummy = 0;
59693 + unsigned int i;
59694 +
59695 + sg_init_table(&sg, 1);
59696 +
59697 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59698 + if (IS_ERR(tfm)) {
59699 + /* should never happen, since sha256 should be built in */
59700 + return 1;
59701 + }
59702 +
59703 + desc.tfm = tfm;
59704 + desc.flags = 0;
59705 +
59706 + crypto_hash_init(&desc);
59707 +
59708 + p = salt;
59709 + sg_set_buf(&sg, p, GR_SALT_LEN);
59710 + crypto_hash_update(&desc, &sg, sg.length);
59711 +
59712 + p = entry->pw;
59713 + sg_set_buf(&sg, p, strlen(p));
59714 +
59715 + crypto_hash_update(&desc, &sg, sg.length);
59716 +
59717 + crypto_hash_final(&desc, temp_sum);
59718 +
59719 + memset(entry->pw, 0, GR_PW_LEN);
59720 +
59721 + for (i = 0; i < GR_SHA_LEN; i++)
59722 + if (sum[i] != temp_sum[i])
59723 + retval = 1;
59724 + else
59725 + dummy = 1; // waste a cycle
59726 +
59727 + crypto_free_hash(tfm);
59728 +
59729 + return retval;
59730 +}
59731 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59732 index 9e6e1c6..d47b906 100644
59733 --- a/include/acpi/acpi_bus.h
59734 +++ b/include/acpi/acpi_bus.h
59735 @@ -138,7 +138,7 @@ struct acpi_device_ops {
59736 acpi_op_bind bind;
59737 acpi_op_unbind unbind;
59738 acpi_op_notify notify;
59739 -};
59740 +} __no_const;
59741
59742 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59743
59744 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59745 index b7babf0..3ba8aee 100644
59746 --- a/include/asm-generic/atomic-long.h
59747 +++ b/include/asm-generic/atomic-long.h
59748 @@ -22,6 +22,12 @@
59749
59750 typedef atomic64_t atomic_long_t;
59751
59752 +#ifdef CONFIG_PAX_REFCOUNT
59753 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59754 +#else
59755 +typedef atomic64_t atomic_long_unchecked_t;
59756 +#endif
59757 +
59758 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59759
59760 static inline long atomic_long_read(atomic_long_t *l)
59761 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59762 return (long)atomic64_read(v);
59763 }
59764
59765 +#ifdef CONFIG_PAX_REFCOUNT
59766 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59767 +{
59768 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59769 +
59770 + return (long)atomic64_read_unchecked(v);
59771 +}
59772 +#endif
59773 +
59774 static inline void atomic_long_set(atomic_long_t *l, long i)
59775 {
59776 atomic64_t *v = (atomic64_t *)l;
59777 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59778 atomic64_set(v, i);
59779 }
59780
59781 +#ifdef CONFIG_PAX_REFCOUNT
59782 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59783 +{
59784 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59785 +
59786 + atomic64_set_unchecked(v, i);
59787 +}
59788 +#endif
59789 +
59790 static inline void atomic_long_inc(atomic_long_t *l)
59791 {
59792 atomic64_t *v = (atomic64_t *)l;
59793 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59794 atomic64_inc(v);
59795 }
59796
59797 +#ifdef CONFIG_PAX_REFCOUNT
59798 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59799 +{
59800 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59801 +
59802 + atomic64_inc_unchecked(v);
59803 +}
59804 +#endif
59805 +
59806 static inline void atomic_long_dec(atomic_long_t *l)
59807 {
59808 atomic64_t *v = (atomic64_t *)l;
59809 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59810 atomic64_dec(v);
59811 }
59812
59813 +#ifdef CONFIG_PAX_REFCOUNT
59814 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59815 +{
59816 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59817 +
59818 + atomic64_dec_unchecked(v);
59819 +}
59820 +#endif
59821 +
59822 static inline void atomic_long_add(long i, atomic_long_t *l)
59823 {
59824 atomic64_t *v = (atomic64_t *)l;
59825 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59826 atomic64_add(i, v);
59827 }
59828
59829 +#ifdef CONFIG_PAX_REFCOUNT
59830 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59831 +{
59832 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59833 +
59834 + atomic64_add_unchecked(i, v);
59835 +}
59836 +#endif
59837 +
59838 static inline void atomic_long_sub(long i, atomic_long_t *l)
59839 {
59840 atomic64_t *v = (atomic64_t *)l;
59841 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59842 atomic64_sub(i, v);
59843 }
59844
59845 +#ifdef CONFIG_PAX_REFCOUNT
59846 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59847 +{
59848 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59849 +
59850 + atomic64_sub_unchecked(i, v);
59851 +}
59852 +#endif
59853 +
59854 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59855 {
59856 atomic64_t *v = (atomic64_t *)l;
59857 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59858 return (long)atomic64_inc_return(v);
59859 }
59860
59861 +#ifdef CONFIG_PAX_REFCOUNT
59862 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59863 +{
59864 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59865 +
59866 + return (long)atomic64_inc_return_unchecked(v);
59867 +}
59868 +#endif
59869 +
59870 static inline long atomic_long_dec_return(atomic_long_t *l)
59871 {
59872 atomic64_t *v = (atomic64_t *)l;
59873 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59874
59875 typedef atomic_t atomic_long_t;
59876
59877 +#ifdef CONFIG_PAX_REFCOUNT
59878 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59879 +#else
59880 +typedef atomic_t atomic_long_unchecked_t;
59881 +#endif
59882 +
59883 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59884 static inline long atomic_long_read(atomic_long_t *l)
59885 {
59886 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59887 return (long)atomic_read(v);
59888 }
59889
59890 +#ifdef CONFIG_PAX_REFCOUNT
59891 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59892 +{
59893 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59894 +
59895 + return (long)atomic_read_unchecked(v);
59896 +}
59897 +#endif
59898 +
59899 static inline void atomic_long_set(atomic_long_t *l, long i)
59900 {
59901 atomic_t *v = (atomic_t *)l;
59902 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59903 atomic_set(v, i);
59904 }
59905
59906 +#ifdef CONFIG_PAX_REFCOUNT
59907 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59908 +{
59909 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59910 +
59911 + atomic_set_unchecked(v, i);
59912 +}
59913 +#endif
59914 +
59915 static inline void atomic_long_inc(atomic_long_t *l)
59916 {
59917 atomic_t *v = (atomic_t *)l;
59918 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59919 atomic_inc(v);
59920 }
59921
59922 +#ifdef CONFIG_PAX_REFCOUNT
59923 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59924 +{
59925 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59926 +
59927 + atomic_inc_unchecked(v);
59928 +}
59929 +#endif
59930 +
59931 static inline void atomic_long_dec(atomic_long_t *l)
59932 {
59933 atomic_t *v = (atomic_t *)l;
59934 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59935 atomic_dec(v);
59936 }
59937
59938 +#ifdef CONFIG_PAX_REFCOUNT
59939 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59940 +{
59941 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59942 +
59943 + atomic_dec_unchecked(v);
59944 +}
59945 +#endif
59946 +
59947 static inline void atomic_long_add(long i, atomic_long_t *l)
59948 {
59949 atomic_t *v = (atomic_t *)l;
59950 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59951 atomic_add(i, v);
59952 }
59953
59954 +#ifdef CONFIG_PAX_REFCOUNT
59955 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59956 +{
59957 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59958 +
59959 + atomic_add_unchecked(i, v);
59960 +}
59961 +#endif
59962 +
59963 static inline void atomic_long_sub(long i, atomic_long_t *l)
59964 {
59965 atomic_t *v = (atomic_t *)l;
59966 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59967 atomic_sub(i, v);
59968 }
59969
59970 +#ifdef CONFIG_PAX_REFCOUNT
59971 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59972 +{
59973 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59974 +
59975 + atomic_sub_unchecked(i, v);
59976 +}
59977 +#endif
59978 +
59979 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59980 {
59981 atomic_t *v = (atomic_t *)l;
59982 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59983 return (long)atomic_inc_return(v);
59984 }
59985
59986 +#ifdef CONFIG_PAX_REFCOUNT
59987 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59988 +{
59989 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59990 +
59991 + return (long)atomic_inc_return_unchecked(v);
59992 +}
59993 +#endif
59994 +
59995 static inline long atomic_long_dec_return(atomic_long_t *l)
59996 {
59997 atomic_t *v = (atomic_t *)l;
59998 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59999
60000 #endif /* BITS_PER_LONG == 64 */
60001
60002 +#ifdef CONFIG_PAX_REFCOUNT
60003 +static inline void pax_refcount_needs_these_functions(void)
60004 +{
60005 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60006 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60007 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60008 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60009 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60010 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60011 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60012 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60013 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60014 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60015 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60016 +#ifdef CONFIG_X86
60017 + atomic_clear_mask_unchecked(0, NULL);
60018 + atomic_set_mask_unchecked(0, NULL);
60019 +#endif
60020 +
60021 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60022 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60023 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60024 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60025 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60026 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60027 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60028 +}
60029 +#else
60030 +#define atomic_read_unchecked(v) atomic_read(v)
60031 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60032 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60033 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60034 +#define atomic_inc_unchecked(v) atomic_inc(v)
60035 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60036 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60037 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60038 +#define atomic_dec_unchecked(v) atomic_dec(v)
60039 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60040 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60041 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60042 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60043 +
60044 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60045 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60046 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60047 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60048 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60049 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60050 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60051 +#endif
60052 +
60053 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60054 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60055 index 1ced641..c896ee8 100644
60056 --- a/include/asm-generic/atomic.h
60057 +++ b/include/asm-generic/atomic.h
60058 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60059 * Atomically clears the bits set in @mask from @v
60060 */
60061 #ifndef atomic_clear_mask
60062 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60063 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60064 {
60065 unsigned long flags;
60066
60067 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60068 index b18ce4f..2ee2843 100644
60069 --- a/include/asm-generic/atomic64.h
60070 +++ b/include/asm-generic/atomic64.h
60071 @@ -16,6 +16,8 @@ typedef struct {
60072 long long counter;
60073 } atomic64_t;
60074
60075 +typedef atomic64_t atomic64_unchecked_t;
60076 +
60077 #define ATOMIC64_INIT(i) { (i) }
60078
60079 extern long long atomic64_read(const atomic64_t *v);
60080 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60081 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60082 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60083
60084 +#define atomic64_read_unchecked(v) atomic64_read(v)
60085 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60086 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60087 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60088 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60089 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60090 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60091 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60092 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60093 +
60094 #endif /* _ASM_GENERIC_ATOMIC64_H */
60095 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60096 index 1bfcfe5..e04c5c9 100644
60097 --- a/include/asm-generic/cache.h
60098 +++ b/include/asm-generic/cache.h
60099 @@ -6,7 +6,7 @@
60100 * cache lines need to provide their own cache.h.
60101 */
60102
60103 -#define L1_CACHE_SHIFT 5
60104 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60105 +#define L1_CACHE_SHIFT 5UL
60106 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60107
60108 #endif /* __ASM_GENERIC_CACHE_H */
60109 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60110 index 0d68a1e..b74a761 100644
60111 --- a/include/asm-generic/emergency-restart.h
60112 +++ b/include/asm-generic/emergency-restart.h
60113 @@ -1,7 +1,7 @@
60114 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60115 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60116
60117 -static inline void machine_emergency_restart(void)
60118 +static inline __noreturn void machine_emergency_restart(void)
60119 {
60120 machine_restart(NULL);
60121 }
60122 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60123 index 0232ccb..13d9165 100644
60124 --- a/include/asm-generic/kmap_types.h
60125 +++ b/include/asm-generic/kmap_types.h
60126 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60127 KMAP_D(17) KM_NMI,
60128 KMAP_D(18) KM_NMI_PTE,
60129 KMAP_D(19) KM_KDB,
60130 +KMAP_D(20) KM_CLEARPAGE,
60131 /*
60132 * Remember to update debug_kmap_atomic() when adding new kmap types!
60133 */
60134 -KMAP_D(20) KM_TYPE_NR
60135 +KMAP_D(21) KM_TYPE_NR
60136 };
60137
60138 #undef KMAP_D
60139 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60140 index 9ceb03b..2efbcbd 100644
60141 --- a/include/asm-generic/local.h
60142 +++ b/include/asm-generic/local.h
60143 @@ -39,6 +39,7 @@ typedef struct
60144 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60145 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60146 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60147 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60148
60149 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60150 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60151 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60152 index 725612b..9cc513a 100644
60153 --- a/include/asm-generic/pgtable-nopmd.h
60154 +++ b/include/asm-generic/pgtable-nopmd.h
60155 @@ -1,14 +1,19 @@
60156 #ifndef _PGTABLE_NOPMD_H
60157 #define _PGTABLE_NOPMD_H
60158
60159 -#ifndef __ASSEMBLY__
60160 -
60161 #include <asm-generic/pgtable-nopud.h>
60162
60163 -struct mm_struct;
60164 -
60165 #define __PAGETABLE_PMD_FOLDED
60166
60167 +#define PMD_SHIFT PUD_SHIFT
60168 +#define PTRS_PER_PMD 1
60169 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60170 +#define PMD_MASK (~(PMD_SIZE-1))
60171 +
60172 +#ifndef __ASSEMBLY__
60173 +
60174 +struct mm_struct;
60175 +
60176 /*
60177 * Having the pmd type consist of a pud gets the size right, and allows
60178 * us to conceptually access the pud entry that this pmd is folded into
60179 @@ -16,11 +21,6 @@ struct mm_struct;
60180 */
60181 typedef struct { pud_t pud; } pmd_t;
60182
60183 -#define PMD_SHIFT PUD_SHIFT
60184 -#define PTRS_PER_PMD 1
60185 -#define PMD_SIZE (1UL << PMD_SHIFT)
60186 -#define PMD_MASK (~(PMD_SIZE-1))
60187 -
60188 /*
60189 * The "pud_xxx()" functions here are trivial for a folded two-level
60190 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60191 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60192 index 810431d..0ec4804f 100644
60193 --- a/include/asm-generic/pgtable-nopud.h
60194 +++ b/include/asm-generic/pgtable-nopud.h
60195 @@ -1,10 +1,15 @@
60196 #ifndef _PGTABLE_NOPUD_H
60197 #define _PGTABLE_NOPUD_H
60198
60199 -#ifndef __ASSEMBLY__
60200 -
60201 #define __PAGETABLE_PUD_FOLDED
60202
60203 +#define PUD_SHIFT PGDIR_SHIFT
60204 +#define PTRS_PER_PUD 1
60205 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60206 +#define PUD_MASK (~(PUD_SIZE-1))
60207 +
60208 +#ifndef __ASSEMBLY__
60209 +
60210 /*
60211 * Having the pud type consist of a pgd gets the size right, and allows
60212 * us to conceptually access the pgd entry that this pud is folded into
60213 @@ -12,11 +17,6 @@
60214 */
60215 typedef struct { pgd_t pgd; } pud_t;
60216
60217 -#define PUD_SHIFT PGDIR_SHIFT
60218 -#define PTRS_PER_PUD 1
60219 -#define PUD_SIZE (1UL << PUD_SHIFT)
60220 -#define PUD_MASK (~(PUD_SIZE-1))
60221 -
60222 /*
60223 * The "pgd_xxx()" functions here are trivial for a folded two-level
60224 * setup: the pud is never bad, and a pud always exists (as it's folded
60225 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60226 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60227
60228 #define pgd_populate(mm, pgd, pud) do { } while (0)
60229 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60230 /*
60231 * (puds are folded into pgds so this doesn't get actually called,
60232 * but the define is needed for a generic inline function.)
60233 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60234 index ff4947b..f48183f 100644
60235 --- a/include/asm-generic/pgtable.h
60236 +++ b/include/asm-generic/pgtable.h
60237 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60238 #endif
60239 }
60240
60241 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60242 +static inline unsigned long pax_open_kernel(void) { return 0; }
60243 +#endif
60244 +
60245 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60246 +static inline unsigned long pax_close_kernel(void) { return 0; }
60247 +#endif
60248 +
60249 #endif /* CONFIG_MMU */
60250
60251 #endif /* !__ASSEMBLY__ */
60252 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60253 index 4e2e1cc..12c266b 100644
60254 --- a/include/asm-generic/vmlinux.lds.h
60255 +++ b/include/asm-generic/vmlinux.lds.h
60256 @@ -218,6 +218,7 @@
60257 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60258 VMLINUX_SYMBOL(__start_rodata) = .; \
60259 *(.rodata) *(.rodata.*) \
60260 + *(.data..read_only) \
60261 *(__vermagic) /* Kernel version magic */ \
60262 . = ALIGN(8); \
60263 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60264 @@ -716,17 +717,18 @@
60265 * section in the linker script will go there too. @phdr should have
60266 * a leading colon.
60267 *
60268 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60269 + * Note that this macros defines per_cpu_load as an absolute symbol.
60270 * If there is no need to put the percpu section at a predetermined
60271 * address, use PERCPU_SECTION.
60272 */
60273 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60274 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60275 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60276 + per_cpu_load = .; \
60277 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60278 - LOAD_OFFSET) { \
60279 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60280 PERCPU_INPUT(cacheline) \
60281 } phdr \
60282 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60283 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60284
60285 /**
60286 * PERCPU_SECTION - define output section for percpu area, simple version
60287 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60288 index 31ad880..4e79884 100644
60289 --- a/include/drm/drmP.h
60290 +++ b/include/drm/drmP.h
60291 @@ -72,6 +72,7 @@
60292 #include <linux/workqueue.h>
60293 #include <linux/poll.h>
60294 #include <asm/pgalloc.h>
60295 +#include <asm/local.h>
60296 #include "drm.h"
60297
60298 #include <linux/idr.h>
60299 @@ -1074,7 +1075,7 @@ struct drm_device {
60300
60301 /** \name Usage Counters */
60302 /*@{ */
60303 - int open_count; /**< Outstanding files open */
60304 + local_t open_count; /**< Outstanding files open */
60305 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60306 atomic_t vma_count; /**< Outstanding vma areas open */
60307 int buf_use; /**< Buffers in use -- cannot alloc */
60308 @@ -1085,7 +1086,7 @@ struct drm_device {
60309 /*@{ */
60310 unsigned long counters;
60311 enum drm_stat_type types[15];
60312 - atomic_t counts[15];
60313 + atomic_unchecked_t counts[15];
60314 /*@} */
60315
60316 struct list_head filelist;
60317 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60318 index 7988e55..ec974c9 100644
60319 --- a/include/drm/drm_crtc_helper.h
60320 +++ b/include/drm/drm_crtc_helper.h
60321 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60322
60323 /* disable crtc when not in use - more explicit than dpms off */
60324 void (*disable)(struct drm_crtc *crtc);
60325 -};
60326 +} __no_const;
60327
60328 /**
60329 * drm_encoder_helper_funcs - helper operations for encoders
60330 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60331 struct drm_connector *connector);
60332 /* disable encoder when not in use - more explicit than dpms off */
60333 void (*disable)(struct drm_encoder *encoder);
60334 -};
60335 +} __no_const;
60336
60337 /**
60338 * drm_connector_helper_funcs - helper operations for connectors
60339 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60340 index d6d1da4..fdd1ac5 100644
60341 --- a/include/drm/ttm/ttm_memory.h
60342 +++ b/include/drm/ttm/ttm_memory.h
60343 @@ -48,7 +48,7 @@
60344
60345 struct ttm_mem_shrink {
60346 int (*do_shrink) (struct ttm_mem_shrink *);
60347 -};
60348 +} __no_const;
60349
60350 /**
60351 * struct ttm_mem_global - Global memory accounting structure.
60352 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60353 index e86dfca..40cc55f 100644
60354 --- a/include/linux/a.out.h
60355 +++ b/include/linux/a.out.h
60356 @@ -39,6 +39,14 @@ enum machine_type {
60357 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60358 };
60359
60360 +/* Constants for the N_FLAGS field */
60361 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60362 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60363 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60364 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60365 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60366 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60367 +
60368 #if !defined (N_MAGIC)
60369 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60370 #endif
60371 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60372 index 06fd4bb..1caec0d 100644
60373 --- a/include/linux/atmdev.h
60374 +++ b/include/linux/atmdev.h
60375 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60376 #endif
60377
60378 struct k_atm_aal_stats {
60379 -#define __HANDLE_ITEM(i) atomic_t i
60380 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60381 __AAL_STAT_ITEMS
60382 #undef __HANDLE_ITEM
60383 };
60384 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60385 index 366422b..1fa7f84 100644
60386 --- a/include/linux/binfmts.h
60387 +++ b/include/linux/binfmts.h
60388 @@ -89,6 +89,7 @@ struct linux_binfmt {
60389 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60390 int (*load_shlib)(struct file *);
60391 int (*core_dump)(struct coredump_params *cprm);
60392 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60393 unsigned long min_coredump; /* minimal dump size */
60394 };
60395
60396 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60397 index 07954b0..cb2ae71 100644
60398 --- a/include/linux/blkdev.h
60399 +++ b/include/linux/blkdev.h
60400 @@ -1393,7 +1393,7 @@ struct block_device_operations {
60401 /* this callback is with swap_lock and sometimes page table lock held */
60402 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60403 struct module *owner;
60404 -};
60405 +} __do_const;
60406
60407 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60408 unsigned long);
60409 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60410 index 4d1a074..88f929a 100644
60411 --- a/include/linux/blktrace_api.h
60412 +++ b/include/linux/blktrace_api.h
60413 @@ -162,7 +162,7 @@ struct blk_trace {
60414 struct dentry *dir;
60415 struct dentry *dropped_file;
60416 struct dentry *msg_file;
60417 - atomic_t dropped;
60418 + atomic_unchecked_t dropped;
60419 };
60420
60421 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60422 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60423 index 83195fb..0b0f77d 100644
60424 --- a/include/linux/byteorder/little_endian.h
60425 +++ b/include/linux/byteorder/little_endian.h
60426 @@ -42,51 +42,51 @@
60427
60428 static inline __le64 __cpu_to_le64p(const __u64 *p)
60429 {
60430 - return (__force __le64)*p;
60431 + return (__force const __le64)*p;
60432 }
60433 static inline __u64 __le64_to_cpup(const __le64 *p)
60434 {
60435 - return (__force __u64)*p;
60436 + return (__force const __u64)*p;
60437 }
60438 static inline __le32 __cpu_to_le32p(const __u32 *p)
60439 {
60440 - return (__force __le32)*p;
60441 + return (__force const __le32)*p;
60442 }
60443 static inline __u32 __le32_to_cpup(const __le32 *p)
60444 {
60445 - return (__force __u32)*p;
60446 + return (__force const __u32)*p;
60447 }
60448 static inline __le16 __cpu_to_le16p(const __u16 *p)
60449 {
60450 - return (__force __le16)*p;
60451 + return (__force const __le16)*p;
60452 }
60453 static inline __u16 __le16_to_cpup(const __le16 *p)
60454 {
60455 - return (__force __u16)*p;
60456 + return (__force const __u16)*p;
60457 }
60458 static inline __be64 __cpu_to_be64p(const __u64 *p)
60459 {
60460 - return (__force __be64)__swab64p(p);
60461 + return (__force const __be64)__swab64p(p);
60462 }
60463 static inline __u64 __be64_to_cpup(const __be64 *p)
60464 {
60465 - return __swab64p((__u64 *)p);
60466 + return __swab64p((const __u64 *)p);
60467 }
60468 static inline __be32 __cpu_to_be32p(const __u32 *p)
60469 {
60470 - return (__force __be32)__swab32p(p);
60471 + return (__force const __be32)__swab32p(p);
60472 }
60473 static inline __u32 __be32_to_cpup(const __be32 *p)
60474 {
60475 - return __swab32p((__u32 *)p);
60476 + return __swab32p((const __u32 *)p);
60477 }
60478 static inline __be16 __cpu_to_be16p(const __u16 *p)
60479 {
60480 - return (__force __be16)__swab16p(p);
60481 + return (__force const __be16)__swab16p(p);
60482 }
60483 static inline __u16 __be16_to_cpup(const __be16 *p)
60484 {
60485 - return __swab16p((__u16 *)p);
60486 + return __swab16p((const __u16 *)p);
60487 }
60488 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60489 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60490 diff --git a/include/linux/cache.h b/include/linux/cache.h
60491 index 4c57065..4307975 100644
60492 --- a/include/linux/cache.h
60493 +++ b/include/linux/cache.h
60494 @@ -16,6 +16,10 @@
60495 #define __read_mostly
60496 #endif
60497
60498 +#ifndef __read_only
60499 +#define __read_only __read_mostly
60500 +#endif
60501 +
60502 #ifndef ____cacheline_aligned
60503 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60504 #endif
60505 diff --git a/include/linux/capability.h b/include/linux/capability.h
60506 index d10b7ed..11390a1 100644
60507 --- a/include/linux/capability.h
60508 +++ b/include/linux/capability.h
60509 @@ -553,6 +553,9 @@ extern bool capable(int cap);
60510 extern bool ns_capable(struct user_namespace *ns, int cap);
60511 extern bool nsown_capable(int cap);
60512 extern bool inode_capable(const struct inode *inode, int cap);
60513 +extern bool capable_nolog(int cap);
60514 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60515 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
60516
60517 /* audit system wants to get cap info from files as well */
60518 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60519 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60520 index 42e55de..1cd0e66 100644
60521 --- a/include/linux/cleancache.h
60522 +++ b/include/linux/cleancache.h
60523 @@ -31,7 +31,7 @@ struct cleancache_ops {
60524 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60525 void (*invalidate_inode)(int, struct cleancache_filekey);
60526 void (*invalidate_fs)(int);
60527 -};
60528 +} __no_const;
60529
60530 extern struct cleancache_ops
60531 cleancache_register_ops(struct cleancache_ops *ops);
60532 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60533 index 2f40791..9c9e13c 100644
60534 --- a/include/linux/compiler-gcc4.h
60535 +++ b/include/linux/compiler-gcc4.h
60536 @@ -32,6 +32,20 @@
60537 #define __linktime_error(message) __attribute__((__error__(message)))
60538
60539 #if __GNUC_MINOR__ >= 5
60540 +
60541 +#ifdef CONSTIFY_PLUGIN
60542 +#define __no_const __attribute__((no_const))
60543 +#define __do_const __attribute__((do_const))
60544 +#endif
60545 +
60546 +#ifdef SIZE_OVERFLOW_PLUGIN
60547 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60548 +#endif
60549 +
60550 +#ifdef LATENT_ENTROPY_PLUGIN
60551 +#define __latent_entropy __attribute__((latent_entropy))
60552 +#endif
60553 +
60554 /*
60555 * Mark a position in code as unreachable. This can be used to
60556 * suppress control flow warnings after asm blocks that transfer
60557 @@ -47,6 +61,11 @@
60558 #define __noclone __attribute__((__noclone__))
60559
60560 #endif
60561 +
60562 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60563 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60564 +#define __bos0(ptr) __bos((ptr), 0)
60565 +#define __bos1(ptr) __bos((ptr), 1)
60566 #endif
60567
60568 #if __GNUC_MINOR__ > 0
60569 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60570 index 923d093..1fef491 100644
60571 --- a/include/linux/compiler.h
60572 +++ b/include/linux/compiler.h
60573 @@ -5,31 +5,62 @@
60574
60575 #ifdef __CHECKER__
60576 # define __user __attribute__((noderef, address_space(1)))
60577 +# define __force_user __force __user
60578 # define __kernel __attribute__((address_space(0)))
60579 +# define __force_kernel __force __kernel
60580 # define __safe __attribute__((safe))
60581 # define __force __attribute__((force))
60582 # define __nocast __attribute__((nocast))
60583 # define __iomem __attribute__((noderef, address_space(2)))
60584 +# define __force_iomem __force __iomem
60585 # define __acquires(x) __attribute__((context(x,0,1)))
60586 # define __releases(x) __attribute__((context(x,1,0)))
60587 # define __acquire(x) __context__(x,1)
60588 # define __release(x) __context__(x,-1)
60589 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60590 # define __percpu __attribute__((noderef, address_space(3)))
60591 +# define __force_percpu __force __percpu
60592 #ifdef CONFIG_SPARSE_RCU_POINTER
60593 # define __rcu __attribute__((noderef, address_space(4)))
60594 +# define __force_rcu __force __rcu
60595 #else
60596 # define __rcu
60597 +# define __force_rcu
60598 #endif
60599 extern void __chk_user_ptr(const volatile void __user *);
60600 extern void __chk_io_ptr(const volatile void __iomem *);
60601 +#elif defined(CHECKER_PLUGIN)
60602 +//# define __user
60603 +//# define __force_user
60604 +//# define __kernel
60605 +//# define __force_kernel
60606 +# define __safe
60607 +# define __force
60608 +# define __nocast
60609 +# define __iomem
60610 +# define __force_iomem
60611 +# define __chk_user_ptr(x) (void)0
60612 +# define __chk_io_ptr(x) (void)0
60613 +# define __builtin_warning(x, y...) (1)
60614 +# define __acquires(x)
60615 +# define __releases(x)
60616 +# define __acquire(x) (void)0
60617 +# define __release(x) (void)0
60618 +# define __cond_lock(x,c) (c)
60619 +# define __percpu
60620 +# define __force_percpu
60621 +# define __rcu
60622 +# define __force_rcu
60623 #else
60624 # define __user
60625 +# define __force_user
60626 # define __kernel
60627 +# define __force_kernel
60628 # define __safe
60629 # define __force
60630 # define __nocast
60631 # define __iomem
60632 +# define __force_iomem
60633 # define __chk_user_ptr(x) (void)0
60634 # define __chk_io_ptr(x) (void)0
60635 # define __builtin_warning(x, y...) (1)
60636 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60637 # define __release(x) (void)0
60638 # define __cond_lock(x,c) (c)
60639 # define __percpu
60640 +# define __force_percpu
60641 # define __rcu
60642 +# define __force_rcu
60643 #endif
60644
60645 #ifdef __KERNEL__
60646 @@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60647 # define __attribute_const__ /* unimplemented */
60648 #endif
60649
60650 +#ifndef __no_const
60651 +# define __no_const
60652 +#endif
60653 +
60654 +#ifndef __do_const
60655 +# define __do_const
60656 +#endif
60657 +
60658 +#ifndef __size_overflow
60659 +# define __size_overflow(...)
60660 +#endif
60661 +
60662 +#ifndef __latent_entropy
60663 +# define __latent_entropy
60664 +#endif
60665 +
60666 /*
60667 * Tell gcc if a function is cold. The compiler will assume any path
60668 * directly leading to the call is unlikely.
60669 @@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60670 #define __cold
60671 #endif
60672
60673 +#ifndef __alloc_size
60674 +#define __alloc_size(...)
60675 +#endif
60676 +
60677 +#ifndef __bos
60678 +#define __bos(ptr, arg)
60679 +#endif
60680 +
60681 +#ifndef __bos0
60682 +#define __bos0(ptr)
60683 +#endif
60684 +
60685 +#ifndef __bos1
60686 +#define __bos1(ptr)
60687 +#endif
60688 +
60689 /* Simple shorthand for a section definition */
60690 #ifndef __section
60691 # define __section(S) __attribute__ ((__section__(#S)))
60692 @@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60693 * use is to mediate communication between process-level code and irq/NMI
60694 * handlers, all running on the same CPU.
60695 */
60696 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60697 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60698 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60699
60700 #endif /* __LINUX_COMPILER_H */
60701 diff --git a/include/linux/cred.h b/include/linux/cred.h
60702 index ebbed2c..908cc2c 100644
60703 --- a/include/linux/cred.h
60704 +++ b/include/linux/cred.h
60705 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60706 static inline void validate_process_creds(void)
60707 {
60708 }
60709 +static inline void validate_task_creds(struct task_struct *task)
60710 +{
60711 +}
60712 #endif
60713
60714 /**
60715 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60716 index b92eadf..b4ecdc1 100644
60717 --- a/include/linux/crypto.h
60718 +++ b/include/linux/crypto.h
60719 @@ -373,7 +373,7 @@ struct cipher_tfm {
60720 const u8 *key, unsigned int keylen);
60721 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60722 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60723 -};
60724 +} __no_const;
60725
60726 struct hash_tfm {
60727 int (*init)(struct hash_desc *desc);
60728 @@ -394,13 +394,13 @@ struct compress_tfm {
60729 int (*cot_decompress)(struct crypto_tfm *tfm,
60730 const u8 *src, unsigned int slen,
60731 u8 *dst, unsigned int *dlen);
60732 -};
60733 +} __no_const;
60734
60735 struct rng_tfm {
60736 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60737 unsigned int dlen);
60738 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60739 -};
60740 +} __no_const;
60741
60742 #define crt_ablkcipher crt_u.ablkcipher
60743 #define crt_aead crt_u.aead
60744 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60745 index 7925bf0..d5143d2 100644
60746 --- a/include/linux/decompress/mm.h
60747 +++ b/include/linux/decompress/mm.h
60748 @@ -77,7 +77,7 @@ static void free(void *where)
60749 * warnings when not needed (indeed large_malloc / large_free are not
60750 * needed by inflate */
60751
60752 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60753 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60754 #define free(a) kfree(a)
60755
60756 #define large_malloc(a) vmalloc(a)
60757 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60758 index dfc099e..e583e66 100644
60759 --- a/include/linux/dma-mapping.h
60760 +++ b/include/linux/dma-mapping.h
60761 @@ -51,7 +51,7 @@ struct dma_map_ops {
60762 u64 (*get_required_mask)(struct device *dev);
60763 #endif
60764 int is_phys;
60765 -};
60766 +} __do_const;
60767
60768 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60769
60770 diff --git a/include/linux/efi.h b/include/linux/efi.h
60771 index ec45ccd..9923c32 100644
60772 --- a/include/linux/efi.h
60773 +++ b/include/linux/efi.h
60774 @@ -635,7 +635,7 @@ struct efivar_operations {
60775 efi_get_variable_t *get_variable;
60776 efi_get_next_variable_t *get_next_variable;
60777 efi_set_variable_t *set_variable;
60778 -};
60779 +} __no_const;
60780
60781 struct efivars {
60782 /*
60783 diff --git a/include/linux/elf.h b/include/linux/elf.h
60784 index 999b4f5..57753b4 100644
60785 --- a/include/linux/elf.h
60786 +++ b/include/linux/elf.h
60787 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60788 #define PT_GNU_EH_FRAME 0x6474e550
60789
60790 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60791 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60792 +
60793 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60794 +
60795 +/* Constants for the e_flags field */
60796 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60797 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60798 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60799 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60800 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60801 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60802
60803 /*
60804 * Extended Numbering
60805 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60806 #define DT_DEBUG 21
60807 #define DT_TEXTREL 22
60808 #define DT_JMPREL 23
60809 +#define DT_FLAGS 30
60810 + #define DF_TEXTREL 0x00000004
60811 #define DT_ENCODING 32
60812 #define OLD_DT_LOOS 0x60000000
60813 #define DT_LOOS 0x6000000d
60814 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60815 #define PF_W 0x2
60816 #define PF_X 0x1
60817
60818 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60819 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60820 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60821 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60822 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60823 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60824 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60825 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60826 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60827 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60828 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60829 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60830 +
60831 typedef struct elf32_phdr{
60832 Elf32_Word p_type;
60833 Elf32_Off p_offset;
60834 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60835 #define EI_OSABI 7
60836 #define EI_PAD 8
60837
60838 +#define EI_PAX 14
60839 +
60840 #define ELFMAG0 0x7f /* EI_MAG */
60841 #define ELFMAG1 'E'
60842 #define ELFMAG2 'L'
60843 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60844 #define elf_note elf32_note
60845 #define elf_addr_t Elf32_Off
60846 #define Elf_Half Elf32_Half
60847 +#define elf_dyn Elf32_Dyn
60848
60849 #else
60850
60851 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60852 #define elf_note elf64_note
60853 #define elf_addr_t Elf64_Off
60854 #define Elf_Half Elf64_Half
60855 +#define elf_dyn Elf64_Dyn
60856
60857 #endif
60858
60859 diff --git a/include/linux/filter.h b/include/linux/filter.h
60860 index 82b0135..917914d 100644
60861 --- a/include/linux/filter.h
60862 +++ b/include/linux/filter.h
60863 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
60864
60865 struct sk_buff;
60866 struct sock;
60867 +struct bpf_jit_work;
60868
60869 struct sk_filter
60870 {
60871 @@ -153,6 +154,9 @@ struct sk_filter
60872 unsigned int len; /* Number of filter blocks */
60873 unsigned int (*bpf_func)(const struct sk_buff *skb,
60874 const struct sock_filter *filter);
60875 +#ifdef CONFIG_BPF_JIT
60876 + struct bpf_jit_work *work;
60877 +#endif
60878 struct rcu_head rcu;
60879 struct sock_filter insns[0];
60880 };
60881 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60882 index 7edcf10..714d5e8 100644
60883 --- a/include/linux/firewire.h
60884 +++ b/include/linux/firewire.h
60885 @@ -430,7 +430,7 @@ struct fw_iso_context {
60886 union {
60887 fw_iso_callback_t sc;
60888 fw_iso_mc_callback_t mc;
60889 - } callback;
60890 + } __no_const callback;
60891 void *callback_data;
60892 };
60893
60894 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
60895 index 0e4e2ee..4ff4312 100644
60896 --- a/include/linux/frontswap.h
60897 +++ b/include/linux/frontswap.h
60898 @@ -11,7 +11,7 @@ struct frontswap_ops {
60899 int (*load)(unsigned, pgoff_t, struct page *);
60900 void (*invalidate_page)(unsigned, pgoff_t);
60901 void (*invalidate_area)(unsigned);
60902 -};
60903 +} __no_const;
60904
60905 extern bool frontswap_enabled;
60906 extern struct frontswap_ops
60907 diff --git a/include/linux/fs.h b/include/linux/fs.h
60908 index 17fd887..8eebca0 100644
60909 --- a/include/linux/fs.h
60910 +++ b/include/linux/fs.h
60911 @@ -1663,7 +1663,8 @@ struct file_operations {
60912 int (*setlease)(struct file *, long, struct file_lock **);
60913 long (*fallocate)(struct file *file, int mode, loff_t offset,
60914 loff_t len);
60915 -};
60916 +} __do_const;
60917 +typedef struct file_operations __no_const file_operations_no_const;
60918
60919 struct inode_operations {
60920 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60921 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60922 index 003dc0f..3c4ea97 100644
60923 --- a/include/linux/fs_struct.h
60924 +++ b/include/linux/fs_struct.h
60925 @@ -6,7 +6,7 @@
60926 #include <linux/seqlock.h>
60927
60928 struct fs_struct {
60929 - int users;
60930 + atomic_t users;
60931 spinlock_t lock;
60932 seqcount_t seq;
60933 int umask;
60934 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60935 index ce31408..b1ad003 100644
60936 --- a/include/linux/fscache-cache.h
60937 +++ b/include/linux/fscache-cache.h
60938 @@ -102,7 +102,7 @@ struct fscache_operation {
60939 fscache_operation_release_t release;
60940 };
60941
60942 -extern atomic_t fscache_op_debug_id;
60943 +extern atomic_unchecked_t fscache_op_debug_id;
60944 extern void fscache_op_work_func(struct work_struct *work);
60945
60946 extern void fscache_enqueue_operation(struct fscache_operation *);
60947 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60948 {
60949 INIT_WORK(&op->work, fscache_op_work_func);
60950 atomic_set(&op->usage, 1);
60951 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60952 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60953 op->processor = processor;
60954 op->release = release;
60955 INIT_LIST_HEAD(&op->pend_link);
60956 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60957 index a6dfe69..569586df 100644
60958 --- a/include/linux/fsnotify.h
60959 +++ b/include/linux/fsnotify.h
60960 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60961 */
60962 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60963 {
60964 - return kstrdup(name, GFP_KERNEL);
60965 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60966 }
60967
60968 /*
60969 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60970 index 63d966d..cdcb717 100644
60971 --- a/include/linux/fsnotify_backend.h
60972 +++ b/include/linux/fsnotify_backend.h
60973 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60974 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60975 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60976 };
60977 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60978
60979 /*
60980 * A group is a "thing" that wants to receive notification about filesystem
60981 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60982 index 176a939..1462211 100644
60983 --- a/include/linux/ftrace_event.h
60984 +++ b/include/linux/ftrace_event.h
60985 @@ -97,7 +97,7 @@ struct trace_event_functions {
60986 trace_print_func raw;
60987 trace_print_func hex;
60988 trace_print_func binary;
60989 -};
60990 +} __no_const;
60991
60992 struct trace_event {
60993 struct hlist_node node;
60994 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60995 extern int trace_add_event_call(struct ftrace_event_call *call);
60996 extern void trace_remove_event_call(struct ftrace_event_call *call);
60997
60998 -#define is_signed_type(type) (((type)(-1)) < 0)
60999 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61000
61001 int trace_set_clr_event(const char *system, const char *event, int set);
61002
61003 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61004 index 017a7fb..33a8507 100644
61005 --- a/include/linux/genhd.h
61006 +++ b/include/linux/genhd.h
61007 @@ -185,7 +185,7 @@ struct gendisk {
61008 struct kobject *slave_dir;
61009
61010 struct timer_rand_state *random;
61011 - atomic_t sync_io; /* RAID */
61012 + atomic_unchecked_t sync_io; /* RAID */
61013 struct disk_events *ev;
61014 #ifdef CONFIG_BLK_DEV_INTEGRITY
61015 struct blk_integrity *integrity;
61016 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61017 index 1e49be4..b8a9305 100644
61018 --- a/include/linux/gfp.h
61019 +++ b/include/linux/gfp.h
61020 @@ -38,6 +38,12 @@ struct vm_area_struct;
61021 #define ___GFP_OTHER_NODE 0x800000u
61022 #define ___GFP_WRITE 0x1000000u
61023
61024 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61025 +#define ___GFP_USERCOPY 0x2000000u
61026 +#else
61027 +#define ___GFP_USERCOPY 0
61028 +#endif
61029 +
61030 /*
61031 * GFP bitmasks..
61032 *
61033 @@ -87,6 +93,7 @@ struct vm_area_struct;
61034 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61035 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61036 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61037 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61038
61039 /*
61040 * This may seem redundant, but it's a way of annotating false positives vs.
61041 @@ -94,7 +101,7 @@ struct vm_area_struct;
61042 */
61043 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61044
61045 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61046 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61047 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61048
61049 /* This equals 0, but use constants in case they ever change */
61050 @@ -148,6 +155,8 @@ struct vm_area_struct;
61051 /* 4GB DMA on some platforms */
61052 #define GFP_DMA32 __GFP_DMA32
61053
61054 +#define GFP_USERCOPY __GFP_USERCOPY
61055 +
61056 /* Convert GFP flags to their corresponding migrate type */
61057 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61058 {
61059 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61060 new file mode 100644
61061 index 0000000..c938b1f
61062 --- /dev/null
61063 +++ b/include/linux/gracl.h
61064 @@ -0,0 +1,319 @@
61065 +#ifndef GR_ACL_H
61066 +#define GR_ACL_H
61067 +
61068 +#include <linux/grdefs.h>
61069 +#include <linux/resource.h>
61070 +#include <linux/capability.h>
61071 +#include <linux/dcache.h>
61072 +#include <asm/resource.h>
61073 +
61074 +/* Major status information */
61075 +
61076 +#define GR_VERSION "grsecurity 2.9.1"
61077 +#define GRSECURITY_VERSION 0x2901
61078 +
61079 +enum {
61080 + GR_SHUTDOWN = 0,
61081 + GR_ENABLE = 1,
61082 + GR_SPROLE = 2,
61083 + GR_RELOAD = 3,
61084 + GR_SEGVMOD = 4,
61085 + GR_STATUS = 5,
61086 + GR_UNSPROLE = 6,
61087 + GR_PASSSET = 7,
61088 + GR_SPROLEPAM = 8,
61089 +};
61090 +
61091 +/* Password setup definitions
61092 + * kernel/grhash.c */
61093 +enum {
61094 + GR_PW_LEN = 128,
61095 + GR_SALT_LEN = 16,
61096 + GR_SHA_LEN = 32,
61097 +};
61098 +
61099 +enum {
61100 + GR_SPROLE_LEN = 64,
61101 +};
61102 +
61103 +enum {
61104 + GR_NO_GLOB = 0,
61105 + GR_REG_GLOB,
61106 + GR_CREATE_GLOB
61107 +};
61108 +
61109 +#define GR_NLIMITS 32
61110 +
61111 +/* Begin Data Structures */
61112 +
61113 +struct sprole_pw {
61114 + unsigned char *rolename;
61115 + unsigned char salt[GR_SALT_LEN];
61116 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61117 +};
61118 +
61119 +struct name_entry {
61120 + __u32 key;
61121 + ino_t inode;
61122 + dev_t device;
61123 + char *name;
61124 + __u16 len;
61125 + __u8 deleted;
61126 + struct name_entry *prev;
61127 + struct name_entry *next;
61128 +};
61129 +
61130 +struct inodev_entry {
61131 + struct name_entry *nentry;
61132 + struct inodev_entry *prev;
61133 + struct inodev_entry *next;
61134 +};
61135 +
61136 +struct acl_role_db {
61137 + struct acl_role_label **r_hash;
61138 + __u32 r_size;
61139 +};
61140 +
61141 +struct inodev_db {
61142 + struct inodev_entry **i_hash;
61143 + __u32 i_size;
61144 +};
61145 +
61146 +struct name_db {
61147 + struct name_entry **n_hash;
61148 + __u32 n_size;
61149 +};
61150 +
61151 +struct crash_uid {
61152 + uid_t uid;
61153 + unsigned long expires;
61154 +};
61155 +
61156 +struct gr_hash_struct {
61157 + void **table;
61158 + void **nametable;
61159 + void *first;
61160 + __u32 table_size;
61161 + __u32 used_size;
61162 + int type;
61163 +};
61164 +
61165 +/* Userspace Grsecurity ACL data structures */
61166 +
61167 +struct acl_subject_label {
61168 + char *filename;
61169 + ino_t inode;
61170 + dev_t device;
61171 + __u32 mode;
61172 + kernel_cap_t cap_mask;
61173 + kernel_cap_t cap_lower;
61174 + kernel_cap_t cap_invert_audit;
61175 +
61176 + struct rlimit res[GR_NLIMITS];
61177 + __u32 resmask;
61178 +
61179 + __u8 user_trans_type;
61180 + __u8 group_trans_type;
61181 + uid_t *user_transitions;
61182 + gid_t *group_transitions;
61183 + __u16 user_trans_num;
61184 + __u16 group_trans_num;
61185 +
61186 + __u32 sock_families[2];
61187 + __u32 ip_proto[8];
61188 + __u32 ip_type;
61189 + struct acl_ip_label **ips;
61190 + __u32 ip_num;
61191 + __u32 inaddr_any_override;
61192 +
61193 + __u32 crashes;
61194 + unsigned long expires;
61195 +
61196 + struct acl_subject_label *parent_subject;
61197 + struct gr_hash_struct *hash;
61198 + struct acl_subject_label *prev;
61199 + struct acl_subject_label *next;
61200 +
61201 + struct acl_object_label **obj_hash;
61202 + __u32 obj_hash_size;
61203 + __u16 pax_flags;
61204 +};
61205 +
61206 +struct role_allowed_ip {
61207 + __u32 addr;
61208 + __u32 netmask;
61209 +
61210 + struct role_allowed_ip *prev;
61211 + struct role_allowed_ip *next;
61212 +};
61213 +
61214 +struct role_transition {
61215 + char *rolename;
61216 +
61217 + struct role_transition *prev;
61218 + struct role_transition *next;
61219 +};
61220 +
61221 +struct acl_role_label {
61222 + char *rolename;
61223 + uid_t uidgid;
61224 + __u16 roletype;
61225 +
61226 + __u16 auth_attempts;
61227 + unsigned long expires;
61228 +
61229 + struct acl_subject_label *root_label;
61230 + struct gr_hash_struct *hash;
61231 +
61232 + struct acl_role_label *prev;
61233 + struct acl_role_label *next;
61234 +
61235 + struct role_transition *transitions;
61236 + struct role_allowed_ip *allowed_ips;
61237 + uid_t *domain_children;
61238 + __u16 domain_child_num;
61239 +
61240 + umode_t umask;
61241 +
61242 + struct acl_subject_label **subj_hash;
61243 + __u32 subj_hash_size;
61244 +};
61245 +
61246 +struct user_acl_role_db {
61247 + struct acl_role_label **r_table;
61248 + __u32 num_pointers; /* Number of allocations to track */
61249 + __u32 num_roles; /* Number of roles */
61250 + __u32 num_domain_children; /* Number of domain children */
61251 + __u32 num_subjects; /* Number of subjects */
61252 + __u32 num_objects; /* Number of objects */
61253 +};
61254 +
61255 +struct acl_object_label {
61256 + char *filename;
61257 + ino_t inode;
61258 + dev_t device;
61259 + __u32 mode;
61260 +
61261 + struct acl_subject_label *nested;
61262 + struct acl_object_label *globbed;
61263 +
61264 + /* next two structures not used */
61265 +
61266 + struct acl_object_label *prev;
61267 + struct acl_object_label *next;
61268 +};
61269 +
61270 +struct acl_ip_label {
61271 + char *iface;
61272 + __u32 addr;
61273 + __u32 netmask;
61274 + __u16 low, high;
61275 + __u8 mode;
61276 + __u32 type;
61277 + __u32 proto[8];
61278 +
61279 + /* next two structures not used */
61280 +
61281 + struct acl_ip_label *prev;
61282 + struct acl_ip_label *next;
61283 +};
61284 +
61285 +struct gr_arg {
61286 + struct user_acl_role_db role_db;
61287 + unsigned char pw[GR_PW_LEN];
61288 + unsigned char salt[GR_SALT_LEN];
61289 + unsigned char sum[GR_SHA_LEN];
61290 + unsigned char sp_role[GR_SPROLE_LEN];
61291 + struct sprole_pw *sprole_pws;
61292 + dev_t segv_device;
61293 + ino_t segv_inode;
61294 + uid_t segv_uid;
61295 + __u16 num_sprole_pws;
61296 + __u16 mode;
61297 +};
61298 +
61299 +struct gr_arg_wrapper {
61300 + struct gr_arg *arg;
61301 + __u32 version;
61302 + __u32 size;
61303 +};
61304 +
61305 +struct subject_map {
61306 + struct acl_subject_label *user;
61307 + struct acl_subject_label *kernel;
61308 + struct subject_map *prev;
61309 + struct subject_map *next;
61310 +};
61311 +
61312 +struct acl_subj_map_db {
61313 + struct subject_map **s_hash;
61314 + __u32 s_size;
61315 +};
61316 +
61317 +/* End Data Structures Section */
61318 +
61319 +/* Hash functions generated by empirical testing by Brad Spengler
61320 + Makes good use of the low bits of the inode. Generally 0-1 times
61321 + in loop for successful match. 0-3 for unsuccessful match.
61322 + Shift/add algorithm with modulus of table size and an XOR*/
61323 +
61324 +static __inline__ unsigned int
61325 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61326 +{
61327 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61328 +}
61329 +
61330 + static __inline__ unsigned int
61331 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61332 +{
61333 + return ((const unsigned long)userp % sz);
61334 +}
61335 +
61336 +static __inline__ unsigned int
61337 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61338 +{
61339 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61340 +}
61341 +
61342 +static __inline__ unsigned int
61343 +nhash(const char *name, const __u16 len, const unsigned int sz)
61344 +{
61345 + return full_name_hash((const unsigned char *)name, len) % sz;
61346 +}
61347 +
61348 +#define FOR_EACH_ROLE_START(role) \
61349 + role = role_list; \
61350 + while (role) {
61351 +
61352 +#define FOR_EACH_ROLE_END(role) \
61353 + role = role->prev; \
61354 + }
61355 +
61356 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61357 + subj = NULL; \
61358 + iter = 0; \
61359 + while (iter < role->subj_hash_size) { \
61360 + if (subj == NULL) \
61361 + subj = role->subj_hash[iter]; \
61362 + if (subj == NULL) { \
61363 + iter++; \
61364 + continue; \
61365 + }
61366 +
61367 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61368 + subj = subj->next; \
61369 + if (subj == NULL) \
61370 + iter++; \
61371 + }
61372 +
61373 +
61374 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61375 + subj = role->hash->first; \
61376 + while (subj != NULL) {
61377 +
61378 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61379 + subj = subj->next; \
61380 + }
61381 +
61382 +#endif
61383 +
61384 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61385 new file mode 100644
61386 index 0000000..323ecf2
61387 --- /dev/null
61388 +++ b/include/linux/gralloc.h
61389 @@ -0,0 +1,9 @@
61390 +#ifndef __GRALLOC_H
61391 +#define __GRALLOC_H
61392 +
61393 +void acl_free_all(void);
61394 +int acl_alloc_stack_init(unsigned long size);
61395 +void *acl_alloc(unsigned long len);
61396 +void *acl_alloc_num(unsigned long num, unsigned long len);
61397 +
61398 +#endif
61399 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61400 new file mode 100644
61401 index 0000000..b30e9bc
61402 --- /dev/null
61403 +++ b/include/linux/grdefs.h
61404 @@ -0,0 +1,140 @@
61405 +#ifndef GRDEFS_H
61406 +#define GRDEFS_H
61407 +
61408 +/* Begin grsecurity status declarations */
61409 +
61410 +enum {
61411 + GR_READY = 0x01,
61412 + GR_STATUS_INIT = 0x00 // disabled state
61413 +};
61414 +
61415 +/* Begin ACL declarations */
61416 +
61417 +/* Role flags */
61418 +
61419 +enum {
61420 + GR_ROLE_USER = 0x0001,
61421 + GR_ROLE_GROUP = 0x0002,
61422 + GR_ROLE_DEFAULT = 0x0004,
61423 + GR_ROLE_SPECIAL = 0x0008,
61424 + GR_ROLE_AUTH = 0x0010,
61425 + GR_ROLE_NOPW = 0x0020,
61426 + GR_ROLE_GOD = 0x0040,
61427 + GR_ROLE_LEARN = 0x0080,
61428 + GR_ROLE_TPE = 0x0100,
61429 + GR_ROLE_DOMAIN = 0x0200,
61430 + GR_ROLE_PAM = 0x0400,
61431 + GR_ROLE_PERSIST = 0x0800
61432 +};
61433 +
61434 +/* ACL Subject and Object mode flags */
61435 +enum {
61436 + GR_DELETED = 0x80000000
61437 +};
61438 +
61439 +/* ACL Object-only mode flags */
61440 +enum {
61441 + GR_READ = 0x00000001,
61442 + GR_APPEND = 0x00000002,
61443 + GR_WRITE = 0x00000004,
61444 + GR_EXEC = 0x00000008,
61445 + GR_FIND = 0x00000010,
61446 + GR_INHERIT = 0x00000020,
61447 + GR_SETID = 0x00000040,
61448 + GR_CREATE = 0x00000080,
61449 + GR_DELETE = 0x00000100,
61450 + GR_LINK = 0x00000200,
61451 + GR_AUDIT_READ = 0x00000400,
61452 + GR_AUDIT_APPEND = 0x00000800,
61453 + GR_AUDIT_WRITE = 0x00001000,
61454 + GR_AUDIT_EXEC = 0x00002000,
61455 + GR_AUDIT_FIND = 0x00004000,
61456 + GR_AUDIT_INHERIT= 0x00008000,
61457 + GR_AUDIT_SETID = 0x00010000,
61458 + GR_AUDIT_CREATE = 0x00020000,
61459 + GR_AUDIT_DELETE = 0x00040000,
61460 + GR_AUDIT_LINK = 0x00080000,
61461 + GR_PTRACERD = 0x00100000,
61462 + GR_NOPTRACE = 0x00200000,
61463 + GR_SUPPRESS = 0x00400000,
61464 + GR_NOLEARN = 0x00800000,
61465 + GR_INIT_TRANSFER= 0x01000000
61466 +};
61467 +
61468 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61469 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61470 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61471 +
61472 +/* ACL subject-only mode flags */
61473 +enum {
61474 + GR_KILL = 0x00000001,
61475 + GR_VIEW = 0x00000002,
61476 + GR_PROTECTED = 0x00000004,
61477 + GR_LEARN = 0x00000008,
61478 + GR_OVERRIDE = 0x00000010,
61479 + /* just a placeholder, this mode is only used in userspace */
61480 + GR_DUMMY = 0x00000020,
61481 + GR_PROTSHM = 0x00000040,
61482 + GR_KILLPROC = 0x00000080,
61483 + GR_KILLIPPROC = 0x00000100,
61484 + /* just a placeholder, this mode is only used in userspace */
61485 + GR_NOTROJAN = 0x00000200,
61486 + GR_PROTPROCFD = 0x00000400,
61487 + GR_PROCACCT = 0x00000800,
61488 + GR_RELAXPTRACE = 0x00001000,
61489 + GR_NESTED = 0x00002000,
61490 + GR_INHERITLEARN = 0x00004000,
61491 + GR_PROCFIND = 0x00008000,
61492 + GR_POVERRIDE = 0x00010000,
61493 + GR_KERNELAUTH = 0x00020000,
61494 + GR_ATSECURE = 0x00040000,
61495 + GR_SHMEXEC = 0x00080000
61496 +};
61497 +
61498 +enum {
61499 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61500 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61501 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61502 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61503 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61504 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61505 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61506 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61507 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61508 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61509 +};
61510 +
61511 +enum {
61512 + GR_ID_USER = 0x01,
61513 + GR_ID_GROUP = 0x02,
61514 +};
61515 +
61516 +enum {
61517 + GR_ID_ALLOW = 0x01,
61518 + GR_ID_DENY = 0x02,
61519 +};
61520 +
61521 +#define GR_CRASH_RES 31
61522 +#define GR_UIDTABLE_MAX 500
61523 +
61524 +/* begin resource learning section */
61525 +enum {
61526 + GR_RLIM_CPU_BUMP = 60,
61527 + GR_RLIM_FSIZE_BUMP = 50000,
61528 + GR_RLIM_DATA_BUMP = 10000,
61529 + GR_RLIM_STACK_BUMP = 1000,
61530 + GR_RLIM_CORE_BUMP = 10000,
61531 + GR_RLIM_RSS_BUMP = 500000,
61532 + GR_RLIM_NPROC_BUMP = 1,
61533 + GR_RLIM_NOFILE_BUMP = 5,
61534 + GR_RLIM_MEMLOCK_BUMP = 50000,
61535 + GR_RLIM_AS_BUMP = 500000,
61536 + GR_RLIM_LOCKS_BUMP = 2,
61537 + GR_RLIM_SIGPENDING_BUMP = 5,
61538 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61539 + GR_RLIM_NICE_BUMP = 1,
61540 + GR_RLIM_RTPRIO_BUMP = 1,
61541 + GR_RLIM_RTTIME_BUMP = 1000000
61542 +};
61543 +
61544 +#endif
61545 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61546 new file mode 100644
61547 index 0000000..c9292f7
61548 --- /dev/null
61549 +++ b/include/linux/grinternal.h
61550 @@ -0,0 +1,223 @@
61551 +#ifndef __GRINTERNAL_H
61552 +#define __GRINTERNAL_H
61553 +
61554 +#ifdef CONFIG_GRKERNSEC
61555 +
61556 +#include <linux/fs.h>
61557 +#include <linux/mnt_namespace.h>
61558 +#include <linux/nsproxy.h>
61559 +#include <linux/gracl.h>
61560 +#include <linux/grdefs.h>
61561 +#include <linux/grmsg.h>
61562 +
61563 +void gr_add_learn_entry(const char *fmt, ...)
61564 + __attribute__ ((format (printf, 1, 2)));
61565 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61566 + const struct vfsmount *mnt);
61567 +__u32 gr_check_create(const struct dentry *new_dentry,
61568 + const struct dentry *parent,
61569 + const struct vfsmount *mnt, const __u32 mode);
61570 +int gr_check_protected_task(const struct task_struct *task);
61571 +__u32 to_gr_audit(const __u32 reqmode);
61572 +int gr_set_acls(const int type);
61573 +int gr_apply_subject_to_task(struct task_struct *task);
61574 +int gr_acl_is_enabled(void);
61575 +char gr_roletype_to_char(void);
61576 +
61577 +void gr_handle_alertkill(struct task_struct *task);
61578 +char *gr_to_filename(const struct dentry *dentry,
61579 + const struct vfsmount *mnt);
61580 +char *gr_to_filename1(const struct dentry *dentry,
61581 + const struct vfsmount *mnt);
61582 +char *gr_to_filename2(const struct dentry *dentry,
61583 + const struct vfsmount *mnt);
61584 +char *gr_to_filename3(const struct dentry *dentry,
61585 + const struct vfsmount *mnt);
61586 +
61587 +extern int grsec_enable_ptrace_readexec;
61588 +extern int grsec_enable_harden_ptrace;
61589 +extern int grsec_enable_link;
61590 +extern int grsec_enable_fifo;
61591 +extern int grsec_enable_execve;
61592 +extern int grsec_enable_shm;
61593 +extern int grsec_enable_execlog;
61594 +extern int grsec_enable_signal;
61595 +extern int grsec_enable_audit_ptrace;
61596 +extern int grsec_enable_forkfail;
61597 +extern int grsec_enable_time;
61598 +extern int grsec_enable_rofs;
61599 +extern int grsec_enable_chroot_shmat;
61600 +extern int grsec_enable_chroot_mount;
61601 +extern int grsec_enable_chroot_double;
61602 +extern int grsec_enable_chroot_pivot;
61603 +extern int grsec_enable_chroot_chdir;
61604 +extern int grsec_enable_chroot_chmod;
61605 +extern int grsec_enable_chroot_mknod;
61606 +extern int grsec_enable_chroot_fchdir;
61607 +extern int grsec_enable_chroot_nice;
61608 +extern int grsec_enable_chroot_execlog;
61609 +extern int grsec_enable_chroot_caps;
61610 +extern int grsec_enable_chroot_sysctl;
61611 +extern int grsec_enable_chroot_unix;
61612 +extern int grsec_enable_symlinkown;
61613 +extern int grsec_symlinkown_gid;
61614 +extern int grsec_enable_tpe;
61615 +extern int grsec_tpe_gid;
61616 +extern int grsec_enable_tpe_all;
61617 +extern int grsec_enable_tpe_invert;
61618 +extern int grsec_enable_socket_all;
61619 +extern int grsec_socket_all_gid;
61620 +extern int grsec_enable_socket_client;
61621 +extern int grsec_socket_client_gid;
61622 +extern int grsec_enable_socket_server;
61623 +extern int grsec_socket_server_gid;
61624 +extern int grsec_audit_gid;
61625 +extern int grsec_enable_group;
61626 +extern int grsec_enable_audit_textrel;
61627 +extern int grsec_enable_log_rwxmaps;
61628 +extern int grsec_enable_mount;
61629 +extern int grsec_enable_chdir;
61630 +extern int grsec_resource_logging;
61631 +extern int grsec_enable_blackhole;
61632 +extern int grsec_lastack_retries;
61633 +extern int grsec_enable_brute;
61634 +extern int grsec_lock;
61635 +
61636 +extern spinlock_t grsec_alert_lock;
61637 +extern unsigned long grsec_alert_wtime;
61638 +extern unsigned long grsec_alert_fyet;
61639 +
61640 +extern spinlock_t grsec_audit_lock;
61641 +
61642 +extern rwlock_t grsec_exec_file_lock;
61643 +
61644 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61645 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61646 + (tsk)->exec_file->f_vfsmnt) : "/")
61647 +
61648 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61649 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61650 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61651 +
61652 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61653 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61654 + (tsk)->exec_file->f_vfsmnt) : "/")
61655 +
61656 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61657 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61658 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61659 +
61660 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61661 +
61662 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61663 +
61664 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61665 + (task)->pid, (cred)->uid, \
61666 + (cred)->euid, (cred)->gid, (cred)->egid, \
61667 + gr_parent_task_fullpath(task), \
61668 + (task)->real_parent->comm, (task)->real_parent->pid, \
61669 + (pcred)->uid, (pcred)->euid, \
61670 + (pcred)->gid, (pcred)->egid
61671 +
61672 +#define GR_CHROOT_CAPS {{ \
61673 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61674 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61675 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61676 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61677 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61678 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61679 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61680 +
61681 +#define security_learn(normal_msg,args...) \
61682 +({ \
61683 + read_lock(&grsec_exec_file_lock); \
61684 + gr_add_learn_entry(normal_msg "\n", ## args); \
61685 + read_unlock(&grsec_exec_file_lock); \
61686 +})
61687 +
61688 +enum {
61689 + GR_DO_AUDIT,
61690 + GR_DONT_AUDIT,
61691 + /* used for non-audit messages that we shouldn't kill the task on */
61692 + GR_DONT_AUDIT_GOOD
61693 +};
61694 +
61695 +enum {
61696 + GR_TTYSNIFF,
61697 + GR_RBAC,
61698 + GR_RBAC_STR,
61699 + GR_STR_RBAC,
61700 + GR_RBAC_MODE2,
61701 + GR_RBAC_MODE3,
61702 + GR_FILENAME,
61703 + GR_SYSCTL_HIDDEN,
61704 + GR_NOARGS,
61705 + GR_ONE_INT,
61706 + GR_ONE_INT_TWO_STR,
61707 + GR_ONE_STR,
61708 + GR_STR_INT,
61709 + GR_TWO_STR_INT,
61710 + GR_TWO_INT,
61711 + GR_TWO_U64,
61712 + GR_THREE_INT,
61713 + GR_FIVE_INT_TWO_STR,
61714 + GR_TWO_STR,
61715 + GR_THREE_STR,
61716 + GR_FOUR_STR,
61717 + GR_STR_FILENAME,
61718 + GR_FILENAME_STR,
61719 + GR_FILENAME_TWO_INT,
61720 + GR_FILENAME_TWO_INT_STR,
61721 + GR_TEXTREL,
61722 + GR_PTRACE,
61723 + GR_RESOURCE,
61724 + GR_CAP,
61725 + GR_SIG,
61726 + GR_SIG2,
61727 + GR_CRASH1,
61728 + GR_CRASH2,
61729 + GR_PSACCT,
61730 + GR_RWXMAP
61731 +};
61732 +
61733 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61734 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61735 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61736 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61737 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61738 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61739 +#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)
61740 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61741 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61742 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61743 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61744 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61745 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61746 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61747 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61748 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61749 +#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)
61750 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61751 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61752 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61753 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61754 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61755 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61756 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61757 +#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)
61758 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61759 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61760 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61761 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61762 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61763 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61764 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61765 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61766 +#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)
61767 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61768 +
61769 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61770 +
61771 +#endif
61772 +
61773 +#endif
61774 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61775 new file mode 100644
61776 index 0000000..54f4e85
61777 --- /dev/null
61778 +++ b/include/linux/grmsg.h
61779 @@ -0,0 +1,110 @@
61780 +#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"
61781 +#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"
61782 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61783 +#define GR_STOPMOD_MSG "denied modification of module state by "
61784 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61785 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61786 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61787 +#define GR_IOPL_MSG "denied use of iopl() by "
61788 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61789 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61790 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61791 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61792 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61793 +#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"
61794 +#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"
61795 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61796 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61797 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61798 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61799 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61800 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61801 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61802 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61803 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61804 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61805 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61806 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61807 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61808 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61809 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61810 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61811 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61812 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61813 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61814 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61815 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61816 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61817 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61818 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61819 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61820 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61821 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61822 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61823 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61824 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61825 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61826 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61827 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61828 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61829 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61830 +#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"
61831 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61832 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61833 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61834 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61835 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61836 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61837 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61838 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61839 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61840 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61841 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61842 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61843 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61844 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61845 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61846 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61847 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61848 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61849 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61850 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61851 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61852 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61853 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61854 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61855 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61856 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61857 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61858 +#define GR_TIME_MSG "time set by "
61859 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61860 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61861 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61862 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61863 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61864 +#define GR_BIND_MSG "denied bind() by "
61865 +#define GR_CONNECT_MSG "denied connect() by "
61866 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61867 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61868 +#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"
61869 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61870 +#define GR_CAP_ACL_MSG "use of %s denied for "
61871 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61872 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61873 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61874 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61875 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61876 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61877 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61878 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61879 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61880 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61881 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61882 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61883 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61884 +#define GR_VM86_MSG "denied use of vm86 by "
61885 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61886 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61887 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61888 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61889 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61890 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61891 new file mode 100644
61892 index 0000000..38bfb04
61893 --- /dev/null
61894 +++ b/include/linux/grsecurity.h
61895 @@ -0,0 +1,233 @@
61896 +#ifndef GR_SECURITY_H
61897 +#define GR_SECURITY_H
61898 +#include <linux/fs.h>
61899 +#include <linux/fs_struct.h>
61900 +#include <linux/binfmts.h>
61901 +#include <linux/gracl.h>
61902 +
61903 +/* notify of brain-dead configs */
61904 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61905 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61906 +#endif
61907 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61908 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61909 +#endif
61910 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61911 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61912 +#endif
61913 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61914 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61915 +#endif
61916 +
61917 +#include <linux/compat.h>
61918 +
61919 +struct user_arg_ptr {
61920 +#ifdef CONFIG_COMPAT
61921 + bool is_compat;
61922 +#endif
61923 + union {
61924 + const char __user *const __user *native;
61925 +#ifdef CONFIG_COMPAT
61926 + compat_uptr_t __user *compat;
61927 +#endif
61928 + } ptr;
61929 +};
61930 +
61931 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61932 +void gr_handle_brute_check(void);
61933 +void gr_handle_kernel_exploit(void);
61934 +int gr_process_user_ban(void);
61935 +
61936 +char gr_roletype_to_char(void);
61937 +
61938 +int gr_acl_enable_at_secure(void);
61939 +
61940 +int gr_check_user_change(int real, int effective, int fs);
61941 +int gr_check_group_change(int real, int effective, int fs);
61942 +
61943 +void gr_del_task_from_ip_table(struct task_struct *p);
61944 +
61945 +int gr_pid_is_chrooted(struct task_struct *p);
61946 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61947 +int gr_handle_chroot_nice(void);
61948 +int gr_handle_chroot_sysctl(const int op);
61949 +int gr_handle_chroot_setpriority(struct task_struct *p,
61950 + const int niceval);
61951 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61952 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61953 + const struct vfsmount *mnt);
61954 +void gr_handle_chroot_chdir(struct path *path);
61955 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61956 + const struct vfsmount *mnt, const int mode);
61957 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61958 + const struct vfsmount *mnt, const int mode);
61959 +int gr_handle_chroot_mount(const struct dentry *dentry,
61960 + const struct vfsmount *mnt,
61961 + const char *dev_name);
61962 +int gr_handle_chroot_pivot(void);
61963 +int gr_handle_chroot_unix(const pid_t pid);
61964 +
61965 +int gr_handle_rawio(const struct inode *inode);
61966 +
61967 +void gr_handle_ioperm(void);
61968 +void gr_handle_iopl(void);
61969 +
61970 +umode_t gr_acl_umask(void);
61971 +
61972 +int gr_tpe_allow(const struct file *file);
61973 +
61974 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61975 +void gr_clear_chroot_entries(struct task_struct *task);
61976 +
61977 +void gr_log_forkfail(const int retval);
61978 +void gr_log_timechange(void);
61979 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61980 +void gr_log_chdir(const struct dentry *dentry,
61981 + const struct vfsmount *mnt);
61982 +void gr_log_chroot_exec(const struct dentry *dentry,
61983 + const struct vfsmount *mnt);
61984 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61985 +void gr_log_remount(const char *devname, const int retval);
61986 +void gr_log_unmount(const char *devname, const int retval);
61987 +void gr_log_mount(const char *from, const char *to, const int retval);
61988 +void gr_log_textrel(struct vm_area_struct *vma);
61989 +void gr_log_rwxmmap(struct file *file);
61990 +void gr_log_rwxmprotect(struct file *file);
61991 +
61992 +int gr_handle_follow_link(const struct inode *parent,
61993 + const struct inode *inode,
61994 + const struct dentry *dentry,
61995 + const struct vfsmount *mnt);
61996 +int gr_handle_fifo(const struct dentry *dentry,
61997 + const struct vfsmount *mnt,
61998 + const struct dentry *dir, const int flag,
61999 + const int acc_mode);
62000 +int gr_handle_hardlink(const struct dentry *dentry,
62001 + const struct vfsmount *mnt,
62002 + struct inode *inode,
62003 + const int mode, const char *to);
62004 +
62005 +int gr_is_capable(const int cap);
62006 +int gr_is_capable_nolog(const int cap);
62007 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62008 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62009 +
62010 +void gr_learn_resource(const struct task_struct *task, const int limit,
62011 + const unsigned long wanted, const int gt);
62012 +void gr_copy_label(struct task_struct *tsk);
62013 +void gr_handle_crash(struct task_struct *task, const int sig);
62014 +int gr_handle_signal(const struct task_struct *p, const int sig);
62015 +int gr_check_crash_uid(const uid_t uid);
62016 +int gr_check_protected_task(const struct task_struct *task);
62017 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62018 +int gr_acl_handle_mmap(const struct file *file,
62019 + const unsigned long prot);
62020 +int gr_acl_handle_mprotect(const struct file *file,
62021 + const unsigned long prot);
62022 +int gr_check_hidden_task(const struct task_struct *tsk);
62023 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62024 + const struct vfsmount *mnt);
62025 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62026 + const struct vfsmount *mnt);
62027 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62028 + const struct vfsmount *mnt, const int fmode);
62029 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62030 + const struct vfsmount *mnt, umode_t *mode);
62031 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62032 + const struct vfsmount *mnt);
62033 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62034 + const struct vfsmount *mnt);
62035 +int gr_handle_ptrace(struct task_struct *task, const long request);
62036 +int gr_handle_proc_ptrace(struct task_struct *task);
62037 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62038 + const struct vfsmount *mnt);
62039 +int gr_check_crash_exec(const struct file *filp);
62040 +int gr_acl_is_enabled(void);
62041 +void gr_set_kernel_label(struct task_struct *task);
62042 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62043 + const gid_t gid);
62044 +int gr_set_proc_label(const struct dentry *dentry,
62045 + const struct vfsmount *mnt,
62046 + const int unsafe_flags);
62047 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62048 + const struct vfsmount *mnt);
62049 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62050 + const struct vfsmount *mnt, int acc_mode);
62051 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62052 + const struct dentry *p_dentry,
62053 + const struct vfsmount *p_mnt,
62054 + int open_flags, int acc_mode, const int imode);
62055 +void gr_handle_create(const struct dentry *dentry,
62056 + const struct vfsmount *mnt);
62057 +void gr_handle_proc_create(const struct dentry *dentry,
62058 + const struct inode *inode);
62059 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62060 + const struct dentry *parent_dentry,
62061 + const struct vfsmount *parent_mnt,
62062 + const int mode);
62063 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62064 + const struct dentry *parent_dentry,
62065 + const struct vfsmount *parent_mnt);
62066 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62067 + const struct vfsmount *mnt);
62068 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62069 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62070 + const struct vfsmount *mnt);
62071 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62072 + const struct dentry *parent_dentry,
62073 + const struct vfsmount *parent_mnt,
62074 + const char *from);
62075 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62076 + const struct dentry *parent_dentry,
62077 + const struct vfsmount *parent_mnt,
62078 + const struct dentry *old_dentry,
62079 + const struct vfsmount *old_mnt, const char *to);
62080 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62081 +int gr_acl_handle_rename(struct dentry *new_dentry,
62082 + struct dentry *parent_dentry,
62083 + const struct vfsmount *parent_mnt,
62084 + struct dentry *old_dentry,
62085 + struct inode *old_parent_inode,
62086 + struct vfsmount *old_mnt, const char *newname);
62087 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62088 + struct dentry *old_dentry,
62089 + struct dentry *new_dentry,
62090 + struct vfsmount *mnt, const __u8 replace);
62091 +__u32 gr_check_link(const struct dentry *new_dentry,
62092 + const struct dentry *parent_dentry,
62093 + const struct vfsmount *parent_mnt,
62094 + const struct dentry *old_dentry,
62095 + const struct vfsmount *old_mnt);
62096 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62097 + const unsigned int namelen, const ino_t ino);
62098 +
62099 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62100 + const struct vfsmount *mnt);
62101 +void gr_acl_handle_exit(void);
62102 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62103 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62104 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62105 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62106 +void gr_audit_ptrace(struct task_struct *task);
62107 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62108 +
62109 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62110 +
62111 +#ifdef CONFIG_GRKERNSEC
62112 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62113 +void gr_handle_vm86(void);
62114 +void gr_handle_mem_readwrite(u64 from, u64 to);
62115 +
62116 +void gr_log_badprocpid(const char *entry);
62117 +
62118 +extern int grsec_enable_dmesg;
62119 +extern int grsec_disable_privio;
62120 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62121 +extern int grsec_enable_chroot_findtask;
62122 +#endif
62123 +#ifdef CONFIG_GRKERNSEC_SETXID
62124 +extern int grsec_enable_setxid;
62125 +#endif
62126 +#endif
62127 +
62128 +#endif
62129 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62130 new file mode 100644
62131 index 0000000..e7ffaaf
62132 --- /dev/null
62133 +++ b/include/linux/grsock.h
62134 @@ -0,0 +1,19 @@
62135 +#ifndef __GRSOCK_H
62136 +#define __GRSOCK_H
62137 +
62138 +extern void gr_attach_curr_ip(const struct sock *sk);
62139 +extern int gr_handle_sock_all(const int family, const int type,
62140 + const int protocol);
62141 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62142 +extern int gr_handle_sock_server_other(const struct sock *sck);
62143 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62144 +extern int gr_search_connect(struct socket * sock,
62145 + struct sockaddr_in * addr);
62146 +extern int gr_search_bind(struct socket * sock,
62147 + struct sockaddr_in * addr);
62148 +extern int gr_search_listen(struct socket * sock);
62149 +extern int gr_search_accept(struct socket * sock);
62150 +extern int gr_search_socket(const int domain, const int type,
62151 + const int protocol);
62152 +
62153 +#endif
62154 diff --git a/include/linux/hid.h b/include/linux/hid.h
62155 index 449fa38..b37c8cc 100644
62156 --- a/include/linux/hid.h
62157 +++ b/include/linux/hid.h
62158 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62159 unsigned int code, int value);
62160
62161 int (*parse)(struct hid_device *hdev);
62162 -};
62163 +} __no_const;
62164
62165 #define PM_HINT_FULLON 1<<5
62166 #define PM_HINT_NORMAL 1<<1
62167 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62168 index d3999b4..1304cb4 100644
62169 --- a/include/linux/highmem.h
62170 +++ b/include/linux/highmem.h
62171 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62172 kunmap_atomic(kaddr);
62173 }
62174
62175 +static inline void sanitize_highpage(struct page *page)
62176 +{
62177 + void *kaddr;
62178 + unsigned long flags;
62179 +
62180 + local_irq_save(flags);
62181 + kaddr = kmap_atomic(page);
62182 + clear_page(kaddr);
62183 + kunmap_atomic(kaddr);
62184 + local_irq_restore(flags);
62185 +}
62186 +
62187 static inline void zero_user_segments(struct page *page,
62188 unsigned start1, unsigned end1,
62189 unsigned start2, unsigned end2)
62190 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62191 index ddfa041..a44cfff 100644
62192 --- a/include/linux/i2c.h
62193 +++ b/include/linux/i2c.h
62194 @@ -366,6 +366,7 @@ struct i2c_algorithm {
62195 /* To determine what the adapter supports */
62196 u32 (*functionality) (struct i2c_adapter *);
62197 };
62198 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62199
62200 /*
62201 * i2c_adapter is the structure used to identify a physical i2c bus along
62202 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62203 index d23c3c2..eb63c81 100644
62204 --- a/include/linux/i2o.h
62205 +++ b/include/linux/i2o.h
62206 @@ -565,7 +565,7 @@ struct i2o_controller {
62207 struct i2o_device *exec; /* Executive */
62208 #if BITS_PER_LONG == 64
62209 spinlock_t context_list_lock; /* lock for context_list */
62210 - atomic_t context_list_counter; /* needed for unique contexts */
62211 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62212 struct list_head context_list; /* list of context id's
62213 and pointers */
62214 #endif
62215 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62216 index 8185f57..7b2d222 100644
62217 --- a/include/linux/if_team.h
62218 +++ b/include/linux/if_team.h
62219 @@ -74,6 +74,7 @@ struct team_mode_ops {
62220 void (*port_leave)(struct team *team, struct team_port *port);
62221 void (*port_change_mac)(struct team *team, struct team_port *port);
62222 };
62223 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62224
62225 enum team_option_type {
62226 TEAM_OPTION_TYPE_U32,
62227 @@ -136,7 +137,7 @@ struct team {
62228 struct list_head option_inst_list; /* list of option instances */
62229
62230 const struct team_mode *mode;
62231 - struct team_mode_ops ops;
62232 + team_mode_ops_no_const ops;
62233 long mode_priv[TEAM_MODE_PRIV_LONGS];
62234 };
62235
62236 diff --git a/include/linux/init.h b/include/linux/init.h
62237 index 6b95109..bcbdd68 100644
62238 --- a/include/linux/init.h
62239 +++ b/include/linux/init.h
62240 @@ -39,9 +39,15 @@
62241 * Also note, that this data cannot be "const".
62242 */
62243
62244 +#ifdef MODULE
62245 +#define add_latent_entropy
62246 +#else
62247 +#define add_latent_entropy __latent_entropy
62248 +#endif
62249 +
62250 /* These are for everybody (although not all archs will actually
62251 discard it in modules) */
62252 -#define __init __section(.init.text) __cold notrace
62253 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62254 #define __initdata __section(.init.data)
62255 #define __initconst __section(.init.rodata)
62256 #define __exitdata __section(.exit.data)
62257 @@ -83,7 +89,7 @@
62258 #define __exit __section(.exit.text) __exitused __cold notrace
62259
62260 /* Used for HOTPLUG */
62261 -#define __devinit __section(.devinit.text) __cold notrace
62262 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62263 #define __devinitdata __section(.devinit.data)
62264 #define __devinitconst __section(.devinit.rodata)
62265 #define __devexit __section(.devexit.text) __exitused __cold notrace
62266 @@ -91,7 +97,7 @@
62267 #define __devexitconst __section(.devexit.rodata)
62268
62269 /* Used for HOTPLUG_CPU */
62270 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62271 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62272 #define __cpuinitdata __section(.cpuinit.data)
62273 #define __cpuinitconst __section(.cpuinit.rodata)
62274 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62275 @@ -99,7 +105,7 @@
62276 #define __cpuexitconst __section(.cpuexit.rodata)
62277
62278 /* Used for MEMORY_HOTPLUG */
62279 -#define __meminit __section(.meminit.text) __cold notrace
62280 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62281 #define __meminitdata __section(.meminit.data)
62282 #define __meminitconst __section(.meminit.rodata)
62283 #define __memexit __section(.memexit.text) __exitused __cold notrace
62284 @@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62285
62286 /* Each module must use one module_init(). */
62287 #define module_init(initfn) \
62288 - static inline initcall_t __inittest(void) \
62289 + static inline __used initcall_t __inittest(void) \
62290 { return initfn; } \
62291 int init_module(void) __attribute__((alias(#initfn)));
62292
62293 /* This is only required if you want to be unloadable. */
62294 #define module_exit(exitfn) \
62295 - static inline exitcall_t __exittest(void) \
62296 + static inline __used exitcall_t __exittest(void) \
62297 { return exitfn; } \
62298 void cleanup_module(void) __attribute__((alias(#exitfn)));
62299
62300 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62301 index 9e65eff..b131e8b 100644
62302 --- a/include/linux/init_task.h
62303 +++ b/include/linux/init_task.h
62304 @@ -134,6 +134,12 @@ extern struct cred init_cred;
62305
62306 #define INIT_TASK_COMM "swapper"
62307
62308 +#ifdef CONFIG_X86
62309 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62310 +#else
62311 +#define INIT_TASK_THREAD_INFO
62312 +#endif
62313 +
62314 /*
62315 * INIT_TASK is used to set up the first task table, touch at
62316 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62317 @@ -172,6 +178,7 @@ extern struct cred init_cred;
62318 RCU_INIT_POINTER(.cred, &init_cred), \
62319 .comm = INIT_TASK_COMM, \
62320 .thread = INIT_THREAD, \
62321 + INIT_TASK_THREAD_INFO \
62322 .fs = &init_fs, \
62323 .files = &init_files, \
62324 .signal = &init_signals, \
62325 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62326 index e6ca56d..8583707 100644
62327 --- a/include/linux/intel-iommu.h
62328 +++ b/include/linux/intel-iommu.h
62329 @@ -296,7 +296,7 @@ struct iommu_flush {
62330 u8 fm, u64 type);
62331 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62332 unsigned int size_order, u64 type);
62333 -};
62334 +} __no_const;
62335
62336 enum {
62337 SR_DMAR_FECTL_REG,
62338 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62339 index e68a8e5..811b9af 100644
62340 --- a/include/linux/interrupt.h
62341 +++ b/include/linux/interrupt.h
62342 @@ -435,7 +435,7 @@ enum
62343 /* map softirq index to softirq name. update 'softirq_to_name' in
62344 * kernel/softirq.c when adding a new softirq.
62345 */
62346 -extern char *softirq_to_name[NR_SOFTIRQS];
62347 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62348
62349 /* softirq mask and active fields moved to irq_cpustat_t in
62350 * asm/hardirq.h to get better cache usage. KAO
62351 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62352
62353 struct softirq_action
62354 {
62355 - void (*action)(struct softirq_action *);
62356 + void (*action)(void);
62357 };
62358
62359 asmlinkage void do_softirq(void);
62360 asmlinkage void __do_softirq(void);
62361 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62362 +extern void open_softirq(int nr, void (*action)(void));
62363 extern void softirq_init(void);
62364 extern void __raise_softirq_irqoff(unsigned int nr);
62365
62366 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62367 index 6883e19..06992b1 100644
62368 --- a/include/linux/kallsyms.h
62369 +++ b/include/linux/kallsyms.h
62370 @@ -15,7 +15,8 @@
62371
62372 struct module;
62373
62374 -#ifdef CONFIG_KALLSYMS
62375 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62376 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62377 /* Lookup the address for a symbol. Returns 0 if not found. */
62378 unsigned long kallsyms_lookup_name(const char *name);
62379
62380 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62381 /* Stupid that this does nothing, but I didn't create this mess. */
62382 #define __print_symbol(fmt, addr)
62383 #endif /*CONFIG_KALLSYMS*/
62384 +#else /* when included by kallsyms.c, vsnprintf.c, or
62385 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62386 +extern void __print_symbol(const char *fmt, unsigned long address);
62387 +extern int sprint_backtrace(char *buffer, unsigned long address);
62388 +extern int sprint_symbol(char *buffer, unsigned long address);
62389 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62390 +const char *kallsyms_lookup(unsigned long addr,
62391 + unsigned long *symbolsize,
62392 + unsigned long *offset,
62393 + char **modname, char *namebuf);
62394 +#endif
62395
62396 /* This macro allows us to keep printk typechecking */
62397 static __printf(1, 2)
62398 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62399 index c4d2fc1..5df9c19 100644
62400 --- a/include/linux/kgdb.h
62401 +++ b/include/linux/kgdb.h
62402 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62403 extern int kgdb_io_module_registered;
62404
62405 extern atomic_t kgdb_setting_breakpoint;
62406 -extern atomic_t kgdb_cpu_doing_single_step;
62407 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62408
62409 extern struct task_struct *kgdb_usethread;
62410 extern struct task_struct *kgdb_contthread;
62411 @@ -252,7 +252,7 @@ struct kgdb_arch {
62412 void (*disable_hw_break)(struct pt_regs *regs);
62413 void (*remove_all_hw_break)(void);
62414 void (*correct_hw_break)(void);
62415 -};
62416 +} __do_const;
62417
62418 /**
62419 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62420 @@ -277,7 +277,7 @@ struct kgdb_io {
62421 void (*pre_exception) (void);
62422 void (*post_exception) (void);
62423 int is_console;
62424 -};
62425 +} __do_const;
62426
62427 extern struct kgdb_arch arch_kgdb_ops;
62428
62429 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62430 index 5398d58..5883a34 100644
62431 --- a/include/linux/kmod.h
62432 +++ b/include/linux/kmod.h
62433 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62434 * usually useless though. */
62435 extern __printf(2, 3)
62436 int __request_module(bool wait, const char *name, ...);
62437 +extern __printf(3, 4)
62438 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62439 #define request_module(mod...) __request_module(true, mod)
62440 #define request_module_nowait(mod...) __request_module(false, mod)
62441 #define try_then_request_module(x, mod...) \
62442 diff --git a/include/linux/kref.h b/include/linux/kref.h
62443 index 9c07dce..a92fa71 100644
62444 --- a/include/linux/kref.h
62445 +++ b/include/linux/kref.h
62446 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62447 static inline int kref_sub(struct kref *kref, unsigned int count,
62448 void (*release)(struct kref *kref))
62449 {
62450 - WARN_ON(release == NULL);
62451 + BUG_ON(release == NULL);
62452
62453 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62454 release(kref);
62455 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62456 index 96c158a..1864db5 100644
62457 --- a/include/linux/kvm_host.h
62458 +++ b/include/linux/kvm_host.h
62459 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62460 void vcpu_load(struct kvm_vcpu *vcpu);
62461 void vcpu_put(struct kvm_vcpu *vcpu);
62462
62463 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62464 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62465 struct module *module);
62466 void kvm_exit(void);
62467
62468 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62469 struct kvm_guest_debug *dbg);
62470 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62471
62472 -int kvm_arch_init(void *opaque);
62473 +int kvm_arch_init(const void *opaque);
62474 void kvm_arch_exit(void);
62475
62476 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62477 diff --git a/include/linux/libata.h b/include/linux/libata.h
62478 index 6e887c7..4539601 100644
62479 --- a/include/linux/libata.h
62480 +++ b/include/linux/libata.h
62481 @@ -910,7 +910,7 @@ struct ata_port_operations {
62482 * fields must be pointers.
62483 */
62484 const struct ata_port_operations *inherits;
62485 -};
62486 +} __do_const;
62487
62488 struct ata_port_info {
62489 unsigned long flags;
62490 diff --git a/include/linux/memory.h b/include/linux/memory.h
62491 index 1ac7f6e..a5794d0 100644
62492 --- a/include/linux/memory.h
62493 +++ b/include/linux/memory.h
62494 @@ -143,7 +143,7 @@ struct memory_accessor {
62495 size_t count);
62496 ssize_t (*write)(struct memory_accessor *, const char *buf,
62497 off_t offset, size_t count);
62498 -};
62499 +} __no_const;
62500
62501 /*
62502 * Kernel text modification mutex, used for code patching. Users of this lock
62503 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62504 index 1318ca6..7521340 100644
62505 --- a/include/linux/mfd/abx500.h
62506 +++ b/include/linux/mfd/abx500.h
62507 @@ -452,6 +452,7 @@ struct abx500_ops {
62508 int (*event_registers_startup_state_get) (struct device *, u8 *);
62509 int (*startup_irq_enabled) (struct device *, unsigned int);
62510 };
62511 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62512
62513 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62514 void abx500_remove_ops(struct device *dev);
62515 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62516 index 9b07725..3d55001 100644
62517 --- a/include/linux/mfd/abx500/ux500_chargalg.h
62518 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
62519 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
62520 int (*enable) (struct ux500_charger *, int, int, int);
62521 int (*kick_wd) (struct ux500_charger *);
62522 int (*update_curr) (struct ux500_charger *, int);
62523 -};
62524 +} __no_const;
62525
62526 /**
62527 * struct ux500_charger - power supply ux500 charger sub class
62528 diff --git a/include/linux/mm.h b/include/linux/mm.h
62529 index b36d08c..410ee7c 100644
62530 --- a/include/linux/mm.h
62531 +++ b/include/linux/mm.h
62532 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62533
62534 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62535 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62536 +
62537 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62538 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62539 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62540 +#else
62541 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62542 +#endif
62543 +
62544 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62545 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62546
62547 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62548 int set_page_dirty_lock(struct page *page);
62549 int clear_page_dirty_for_io(struct page *page);
62550
62551 -/* Is the vma a continuation of the stack vma above it? */
62552 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62553 -{
62554 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62555 -}
62556 -
62557 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62558 - unsigned long addr)
62559 -{
62560 - return (vma->vm_flags & VM_GROWSDOWN) &&
62561 - (vma->vm_start == addr) &&
62562 - !vma_growsdown(vma->vm_prev, addr);
62563 -}
62564 -
62565 -/* Is the vma a continuation of the stack vma below it? */
62566 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62567 -{
62568 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62569 -}
62570 -
62571 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62572 - unsigned long addr)
62573 -{
62574 - return (vma->vm_flags & VM_GROWSUP) &&
62575 - (vma->vm_end == addr) &&
62576 - !vma_growsup(vma->vm_next, addr);
62577 -}
62578 -
62579 extern pid_t
62580 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62581
62582 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62583 }
62584 #endif
62585
62586 +#ifdef CONFIG_MMU
62587 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62588 +#else
62589 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62590 +{
62591 + return __pgprot(0);
62592 +}
62593 +#endif
62594 +
62595 int vma_wants_writenotify(struct vm_area_struct *vma);
62596
62597 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62598 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62599 {
62600 return 0;
62601 }
62602 +
62603 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62604 + unsigned long address)
62605 +{
62606 + return 0;
62607 +}
62608 #else
62609 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62610 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62611 #endif
62612
62613 #ifdef __PAGETABLE_PMD_FOLDED
62614 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62615 {
62616 return 0;
62617 }
62618 +
62619 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62620 + unsigned long address)
62621 +{
62622 + return 0;
62623 +}
62624 #else
62625 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62626 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62627 #endif
62628
62629 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62630 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62631 NULL: pud_offset(pgd, address);
62632 }
62633
62634 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62635 +{
62636 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62637 + NULL: pud_offset(pgd, address);
62638 +}
62639 +
62640 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62641 {
62642 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62643 NULL: pmd_offset(pud, address);
62644 }
62645 +
62646 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62647 +{
62648 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62649 + NULL: pmd_offset(pud, address);
62650 +}
62651 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62652
62653 #if USE_SPLIT_PTLOCKS
62654 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62655 unsigned long, unsigned long,
62656 unsigned long, unsigned long);
62657 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62658 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62659
62660 /* These take the mm semaphore themselves */
62661 extern unsigned long vm_brk(unsigned long, unsigned long);
62662 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62663 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62664 struct vm_area_struct **pprev);
62665
62666 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62667 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62668 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62669 +
62670 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62671 NULL if none. Assume start_addr < end_addr. */
62672 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62673 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62674 return vma;
62675 }
62676
62677 -#ifdef CONFIG_MMU
62678 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62679 -#else
62680 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62681 -{
62682 - return __pgprot(0);
62683 -}
62684 -#endif
62685 -
62686 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62687 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62688 unsigned long pfn, unsigned long size, pgprot_t);
62689 @@ -1598,7 +1608,7 @@ extern int unpoison_memory(unsigned long pfn);
62690 extern int sysctl_memory_failure_early_kill;
62691 extern int sysctl_memory_failure_recovery;
62692 extern void shake_page(struct page *p, int access);
62693 -extern atomic_long_t mce_bad_pages;
62694 +extern atomic_long_unchecked_t mce_bad_pages;
62695 extern int soft_offline_page(struct page *page, int flags);
62696
62697 extern void dump_page(struct page *page);
62698 @@ -1629,5 +1639,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62699 static inline bool page_is_guard(struct page *page) { return false; }
62700 #endif /* CONFIG_DEBUG_PAGEALLOC */
62701
62702 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62703 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62704 +#else
62705 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62706 +#endif
62707 +
62708 #endif /* __KERNEL__ */
62709 #endif /* _LINUX_MM_H */
62710 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62711 index 704a626..56c7d46 100644
62712 --- a/include/linux/mm_types.h
62713 +++ b/include/linux/mm_types.h
62714 @@ -263,6 +263,8 @@ struct vm_area_struct {
62715 #ifdef CONFIG_NUMA
62716 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62717 #endif
62718 +
62719 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62720 };
62721
62722 struct core_thread {
62723 @@ -337,7 +339,7 @@ struct mm_struct {
62724 unsigned long def_flags;
62725 unsigned long nr_ptes; /* Page table pages */
62726 unsigned long start_code, end_code, start_data, end_data;
62727 - unsigned long start_brk, brk, start_stack;
62728 + unsigned long brk_gap, start_brk, brk, start_stack;
62729 unsigned long arg_start, arg_end, env_start, env_end;
62730
62731 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62732 @@ -389,6 +391,24 @@ struct mm_struct {
62733 struct cpumask cpumask_allocation;
62734 #endif
62735 struct uprobes_state uprobes_state;
62736 +
62737 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62738 + unsigned long pax_flags;
62739 +#endif
62740 +
62741 +#ifdef CONFIG_PAX_DLRESOLVE
62742 + unsigned long call_dl_resolve;
62743 +#endif
62744 +
62745 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62746 + unsigned long call_syscall;
62747 +#endif
62748 +
62749 +#ifdef CONFIG_PAX_ASLR
62750 + unsigned long delta_mmap; /* randomized offset */
62751 + unsigned long delta_stack; /* randomized offset */
62752 +#endif
62753 +
62754 };
62755
62756 static inline void mm_init_cpumask(struct mm_struct *mm)
62757 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62758 index 1d1b1e1..2a13c78 100644
62759 --- a/include/linux/mmu_notifier.h
62760 +++ b/include/linux/mmu_notifier.h
62761 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62762 */
62763 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62764 ({ \
62765 - pte_t __pte; \
62766 + pte_t ___pte; \
62767 struct vm_area_struct *___vma = __vma; \
62768 unsigned long ___address = __address; \
62769 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62770 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62771 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62772 - __pte; \
62773 + ___pte; \
62774 })
62775
62776 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62777 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62778 index 68c569f..5f43753 100644
62779 --- a/include/linux/mmzone.h
62780 +++ b/include/linux/mmzone.h
62781 @@ -411,7 +411,7 @@ struct zone {
62782 unsigned long flags; /* zone flags, see below */
62783
62784 /* Zone statistics */
62785 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62786 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62787
62788 /*
62789 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62790 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62791 index 5db9382..50e801d 100644
62792 --- a/include/linux/mod_devicetable.h
62793 +++ b/include/linux/mod_devicetable.h
62794 @@ -12,7 +12,7 @@
62795 typedef unsigned long kernel_ulong_t;
62796 #endif
62797
62798 -#define PCI_ANY_ID (~0)
62799 +#define PCI_ANY_ID ((__u16)~0)
62800
62801 struct pci_device_id {
62802 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62803 @@ -131,7 +131,7 @@ struct usb_device_id {
62804 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62805 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62806
62807 -#define HID_ANY_ID (~0)
62808 +#define HID_ANY_ID (~0U)
62809 #define HID_BUS_ANY 0xffff
62810 #define HID_GROUP_ANY 0x0000
62811
62812 diff --git a/include/linux/module.h b/include/linux/module.h
62813 index fbcafe2..e5d9587 100644
62814 --- a/include/linux/module.h
62815 +++ b/include/linux/module.h
62816 @@ -17,6 +17,7 @@
62817 #include <linux/moduleparam.h>
62818 #include <linux/tracepoint.h>
62819 #include <linux/export.h>
62820 +#include <linux/fs.h>
62821
62822 #include <linux/percpu.h>
62823 #include <asm/module.h>
62824 @@ -273,19 +274,16 @@ struct module
62825 int (*init)(void);
62826
62827 /* If this is non-NULL, vfree after init() returns */
62828 - void *module_init;
62829 + void *module_init_rx, *module_init_rw;
62830
62831 /* Here is the actual code + data, vfree'd on unload. */
62832 - void *module_core;
62833 + void *module_core_rx, *module_core_rw;
62834
62835 /* Here are the sizes of the init and core sections */
62836 - unsigned int init_size, core_size;
62837 + unsigned int init_size_rw, core_size_rw;
62838
62839 /* The size of the executable code in each section. */
62840 - unsigned int init_text_size, core_text_size;
62841 -
62842 - /* Size of RO sections of the module (text+rodata) */
62843 - unsigned int init_ro_size, core_ro_size;
62844 + unsigned int init_size_rx, core_size_rx;
62845
62846 /* Arch-specific module values */
62847 struct mod_arch_specific arch;
62848 @@ -341,6 +339,10 @@ struct module
62849 #ifdef CONFIG_EVENT_TRACING
62850 struct ftrace_event_call **trace_events;
62851 unsigned int num_trace_events;
62852 + struct file_operations trace_id;
62853 + struct file_operations trace_enable;
62854 + struct file_operations trace_format;
62855 + struct file_operations trace_filter;
62856 #endif
62857 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62858 unsigned int num_ftrace_callsites;
62859 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62860 bool is_module_percpu_address(unsigned long addr);
62861 bool is_module_text_address(unsigned long addr);
62862
62863 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62864 +{
62865 +
62866 +#ifdef CONFIG_PAX_KERNEXEC
62867 + if (ktla_ktva(addr) >= (unsigned long)start &&
62868 + ktla_ktva(addr) < (unsigned long)start + size)
62869 + return 1;
62870 +#endif
62871 +
62872 + return ((void *)addr >= start && (void *)addr < start + size);
62873 +}
62874 +
62875 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62876 +{
62877 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62878 +}
62879 +
62880 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62881 +{
62882 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62883 +}
62884 +
62885 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62886 +{
62887 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62888 +}
62889 +
62890 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62891 +{
62892 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62893 +}
62894 +
62895 static inline int within_module_core(unsigned long addr, struct module *mod)
62896 {
62897 - return (unsigned long)mod->module_core <= addr &&
62898 - addr < (unsigned long)mod->module_core + mod->core_size;
62899 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62900 }
62901
62902 static inline int within_module_init(unsigned long addr, struct module *mod)
62903 {
62904 - return (unsigned long)mod->module_init <= addr &&
62905 - addr < (unsigned long)mod->module_init + mod->init_size;
62906 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62907 }
62908
62909 /* Search for module by name: must hold module_mutex. */
62910 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62911 index b2be02e..72d2f78 100644
62912 --- a/include/linux/moduleloader.h
62913 +++ b/include/linux/moduleloader.h
62914 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62915
62916 /* Allocator used for allocating struct module, core sections and init
62917 sections. Returns NULL on failure. */
62918 -void *module_alloc(unsigned long size);
62919 +void *module_alloc(unsigned long size) __size_overflow(1);
62920 +
62921 +#ifdef CONFIG_PAX_KERNEXEC
62922 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62923 +#else
62924 +#define module_alloc_exec(x) module_alloc(x)
62925 +#endif
62926
62927 /* Free memory returned from module_alloc. */
62928 void module_free(struct module *mod, void *module_region);
62929
62930 +#ifdef CONFIG_PAX_KERNEXEC
62931 +void module_free_exec(struct module *mod, void *module_region);
62932 +#else
62933 +#define module_free_exec(x, y) module_free((x), (y))
62934 +#endif
62935 +
62936 /* Apply the given relocation to the (simplified) ELF. Return -error
62937 or 0. */
62938 int apply_relocate(Elf_Shdr *sechdrs,
62939 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62940 index d6a5806..7c13347 100644
62941 --- a/include/linux/moduleparam.h
62942 +++ b/include/linux/moduleparam.h
62943 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62944 * @len is usually just sizeof(string).
62945 */
62946 #define module_param_string(name, string, len, perm) \
62947 - static const struct kparam_string __param_string_##name \
62948 + static const struct kparam_string __param_string_##name __used \
62949 = { len, string }; \
62950 __module_param_call(MODULE_PARAM_PREFIX, name, \
62951 &param_ops_string, \
62952 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62953 */
62954 #define module_param_array_named(name, array, type, nump, perm) \
62955 param_check_##type(name, &(array)[0]); \
62956 - static const struct kparam_array __param_arr_##name \
62957 + static const struct kparam_array __param_arr_##name __used \
62958 = { .max = ARRAY_SIZE(array), .num = nump, \
62959 .ops = &param_ops_##type, \
62960 .elemsize = sizeof(array[0]), .elem = array }; \
62961 diff --git a/include/linux/namei.h b/include/linux/namei.h
62962 index ffc0213..2c1f2cb 100644
62963 --- a/include/linux/namei.h
62964 +++ b/include/linux/namei.h
62965 @@ -24,7 +24,7 @@ struct nameidata {
62966 unsigned seq;
62967 int last_type;
62968 unsigned depth;
62969 - char *saved_names[MAX_NESTED_LINKS + 1];
62970 + const char *saved_names[MAX_NESTED_LINKS + 1];
62971
62972 /* Intent data */
62973 union {
62974 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62975 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62976 extern void unlock_rename(struct dentry *, struct dentry *);
62977
62978 -static inline void nd_set_link(struct nameidata *nd, char *path)
62979 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62980 {
62981 nd->saved_names[nd->depth] = path;
62982 }
62983
62984 -static inline char *nd_get_link(struct nameidata *nd)
62985 +static inline const char *nd_get_link(const struct nameidata *nd)
62986 {
62987 return nd->saved_names[nd->depth];
62988 }
62989 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62990 index d94cb14..e64c951 100644
62991 --- a/include/linux/netdevice.h
62992 +++ b/include/linux/netdevice.h
62993 @@ -1026,6 +1026,7 @@ struct net_device_ops {
62994 struct net_device *dev,
62995 int idx);
62996 };
62997 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62998
62999 /*
63000 * The DEVICE structure.
63001 @@ -1087,7 +1088,7 @@ struct net_device {
63002 int iflink;
63003
63004 struct net_device_stats stats;
63005 - atomic_long_t rx_dropped; /* dropped packets by core network
63006 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63007 * Do not use this in drivers.
63008 */
63009
63010 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63011 new file mode 100644
63012 index 0000000..33f4af8
63013 --- /dev/null
63014 +++ b/include/linux/netfilter/xt_gradm.h
63015 @@ -0,0 +1,9 @@
63016 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63017 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63018 +
63019 +struct xt_gradm_mtinfo {
63020 + __u16 flags;
63021 + __u16 invflags;
63022 +};
63023 +
63024 +#endif
63025 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63026 index c65a18a..0c05f3a 100644
63027 --- a/include/linux/of_pdt.h
63028 +++ b/include/linux/of_pdt.h
63029 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63030
63031 /* return 0 on success; fill in 'len' with number of bytes in path */
63032 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63033 -};
63034 +} __no_const;
63035
63036 extern void *prom_early_alloc(unsigned long size);
63037
63038 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63039 index a4c5624..79d6d88 100644
63040 --- a/include/linux/oprofile.h
63041 +++ b/include/linux/oprofile.h
63042 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63043 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63044 char const * name, ulong * val);
63045
63046 -/** Create a file for read-only access to an atomic_t. */
63047 +/** Create a file for read-only access to an atomic_unchecked_t. */
63048 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63049 - char const * name, atomic_t * val);
63050 + char const * name, atomic_unchecked_t * val);
63051
63052 /** create a directory */
63053 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63054 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63055 index 45db49f..386788e 100644
63056 --- a/include/linux/perf_event.h
63057 +++ b/include/linux/perf_event.h
63058 @@ -879,8 +879,8 @@ struct perf_event {
63059
63060 enum perf_event_active_state state;
63061 unsigned int attach_state;
63062 - local64_t count;
63063 - atomic64_t child_count;
63064 + local64_t count; /* PaX: fix it one day */
63065 + atomic64_unchecked_t child_count;
63066
63067 /*
63068 * These are the total time in nanoseconds that the event
63069 @@ -931,8 +931,8 @@ struct perf_event {
63070 * These accumulate total time (in nanoseconds) that children
63071 * events have been enabled and running, respectively.
63072 */
63073 - atomic64_t child_total_time_enabled;
63074 - atomic64_t child_total_time_running;
63075 + atomic64_unchecked_t child_total_time_enabled;
63076 + atomic64_unchecked_t child_total_time_running;
63077
63078 /*
63079 * Protect attach/detach and child_list:
63080 diff --git a/include/linux/personality.h b/include/linux/personality.h
63081 index 8fc7dd1a..c19d89e 100644
63082 --- a/include/linux/personality.h
63083 +++ b/include/linux/personality.h
63084 @@ -44,6 +44,7 @@ enum {
63085 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63086 ADDR_NO_RANDOMIZE | \
63087 ADDR_COMPAT_LAYOUT | \
63088 + ADDR_LIMIT_3GB | \
63089 MMAP_PAGE_ZERO)
63090
63091 /*
63092 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63093 index e1ac1ce..0675fed 100644
63094 --- a/include/linux/pipe_fs_i.h
63095 +++ b/include/linux/pipe_fs_i.h
63096 @@ -45,9 +45,9 @@ struct pipe_buffer {
63097 struct pipe_inode_info {
63098 wait_queue_head_t wait;
63099 unsigned int nrbufs, curbuf, buffers;
63100 - unsigned int readers;
63101 - unsigned int writers;
63102 - unsigned int waiting_writers;
63103 + atomic_t readers;
63104 + atomic_t writers;
63105 + atomic_t waiting_writers;
63106 unsigned int r_counter;
63107 unsigned int w_counter;
63108 struct page *tmp_page;
63109 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63110 index f271860..6b3bec5 100644
63111 --- a/include/linux/pm_runtime.h
63112 +++ b/include/linux/pm_runtime.h
63113 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63114
63115 static inline void pm_runtime_mark_last_busy(struct device *dev)
63116 {
63117 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63118 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63119 }
63120
63121 #else /* !CONFIG_PM_RUNTIME */
63122 diff --git a/include/linux/poison.h b/include/linux/poison.h
63123 index 2110a81..13a11bb 100644
63124 --- a/include/linux/poison.h
63125 +++ b/include/linux/poison.h
63126 @@ -19,8 +19,8 @@
63127 * under normal circumstances, used to verify that nobody uses
63128 * non-initialized list entries.
63129 */
63130 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63131 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63132 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63133 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63134
63135 /********** include/linux/timer.h **********/
63136 /*
63137 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63138 index 5a710b9..0b0dab9 100644
63139 --- a/include/linux/preempt.h
63140 +++ b/include/linux/preempt.h
63141 @@ -126,7 +126,7 @@ struct preempt_ops {
63142 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63143 void (*sched_out)(struct preempt_notifier *notifier,
63144 struct task_struct *next);
63145 -};
63146 +} __no_const;
63147
63148 /**
63149 * preempt_notifier - key for installing preemption notifiers
63150 diff --git a/include/linux/printk.h b/include/linux/printk.h
63151 index 1bec2f7..b66e833 100644
63152 --- a/include/linux/printk.h
63153 +++ b/include/linux/printk.h
63154 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63155 extern int printk_needs_cpu(int cpu);
63156 extern void printk_tick(void);
63157
63158 +extern int kptr_restrict;
63159 +
63160 #ifdef CONFIG_PRINTK
63161 asmlinkage __printf(5, 0)
63162 int vprintk_emit(int facility, int level,
63163 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63164
63165 extern int printk_delay_msec;
63166 extern int dmesg_restrict;
63167 -extern int kptr_restrict;
63168
63169 void log_buf_kexec_setup(void);
63170 void __init setup_log_buf(int early);
63171 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63172 index 3fd2e87..d93a721 100644
63173 --- a/include/linux/proc_fs.h
63174 +++ b/include/linux/proc_fs.h
63175 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63176 return proc_create_data(name, mode, parent, proc_fops, NULL);
63177 }
63178
63179 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63180 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63181 +{
63182 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63183 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63184 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63185 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63186 +#else
63187 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63188 +#endif
63189 +}
63190 +
63191 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63192 umode_t mode, struct proc_dir_entry *base,
63193 read_proc_t *read_proc, void * data)
63194 @@ -258,7 +270,7 @@ union proc_op {
63195 int (*proc_show)(struct seq_file *m,
63196 struct pid_namespace *ns, struct pid *pid,
63197 struct task_struct *task);
63198 -};
63199 +} __no_const;
63200
63201 struct ctl_table_header;
63202 struct ctl_table;
63203 diff --git a/include/linux/random.h b/include/linux/random.h
63204 index 8f74538..de61694 100644
63205 --- a/include/linux/random.h
63206 +++ b/include/linux/random.h
63207 @@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63208 unsigned int value);
63209 extern void add_interrupt_randomness(int irq);
63210
63211 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63212 +extern void transfer_latent_entropy(void);
63213 +#endif
63214 +
63215 extern void get_random_bytes(void *buf, int nbytes);
63216 void generate_random_uuid(unsigned char uuid_out[16]);
63217
63218 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63219
63220 u32 prandom32(struct rnd_state *);
63221
63222 +static inline unsigned long pax_get_random_long(void)
63223 +{
63224 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63225 +}
63226 +
63227 /*
63228 * Handle minimum values for seeds
63229 */
63230 static inline u32 __seed(u32 x, u32 m)
63231 {
63232 - return (x < m) ? x + m : x;
63233 + return (x <= m) ? x + m + 1 : x;
63234 }
63235
63236 /**
63237 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63238 index e0879a7..a12f962 100644
63239 --- a/include/linux/reboot.h
63240 +++ b/include/linux/reboot.h
63241 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63242 * Architecture-specific implementations of sys_reboot commands.
63243 */
63244
63245 -extern void machine_restart(char *cmd);
63246 -extern void machine_halt(void);
63247 -extern void machine_power_off(void);
63248 +extern void machine_restart(char *cmd) __noreturn;
63249 +extern void machine_halt(void) __noreturn;
63250 +extern void machine_power_off(void) __noreturn;
63251
63252 extern void machine_shutdown(void);
63253 struct pt_regs;
63254 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63255 */
63256
63257 extern void kernel_restart_prepare(char *cmd);
63258 -extern void kernel_restart(char *cmd);
63259 -extern void kernel_halt(void);
63260 -extern void kernel_power_off(void);
63261 +extern void kernel_restart(char *cmd) __noreturn;
63262 +extern void kernel_halt(void) __noreturn;
63263 +extern void kernel_power_off(void) __noreturn;
63264
63265 extern int C_A_D; /* for sysctl */
63266 void ctrl_alt_del(void);
63267 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63268 * Emergency restart, callable from an interrupt handler.
63269 */
63270
63271 -extern void emergency_restart(void);
63272 +extern void emergency_restart(void) __noreturn;
63273 #include <asm/emergency-restart.h>
63274
63275 #endif
63276 diff --git a/include/linux/relay.h b/include/linux/relay.h
63277 index 91cacc3..b55ff74 100644
63278 --- a/include/linux/relay.h
63279 +++ b/include/linux/relay.h
63280 @@ -160,7 +160,7 @@ struct rchan_callbacks
63281 * The callback should return 0 if successful, negative if not.
63282 */
63283 int (*remove_buf_file)(struct dentry *dentry);
63284 -};
63285 +} __no_const;
63286
63287 /*
63288 * CONFIG_RELAY kernel API, kernel/relay.c
63289 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63290 index 6fdf027..ff72610 100644
63291 --- a/include/linux/rfkill.h
63292 +++ b/include/linux/rfkill.h
63293 @@ -147,6 +147,7 @@ struct rfkill_ops {
63294 void (*query)(struct rfkill *rfkill, void *data);
63295 int (*set_block)(void *data, bool blocked);
63296 };
63297 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63298
63299 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63300 /**
63301 diff --git a/include/linux/rio.h b/include/linux/rio.h
63302 index a90ebad..fd87b5d 100644
63303 --- a/include/linux/rio.h
63304 +++ b/include/linux/rio.h
63305 @@ -321,7 +321,7 @@ struct rio_ops {
63306 int mbox, void *buffer, size_t len);
63307 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63308 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63309 -};
63310 +} __no_const;
63311
63312 #define RIO_RESOURCE_MEM 0x00000100
63313 #define RIO_RESOURCE_DOORBELL 0x00000200
63314 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63315 index 3fce545..b4fed6e 100644
63316 --- a/include/linux/rmap.h
63317 +++ b/include/linux/rmap.h
63318 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63319 void anon_vma_init(void); /* create anon_vma_cachep */
63320 int anon_vma_prepare(struct vm_area_struct *);
63321 void unlink_anon_vmas(struct vm_area_struct *);
63322 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63323 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63324 void anon_vma_moveto_tail(struct vm_area_struct *);
63325 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63326 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63327
63328 static inline void anon_vma_merge(struct vm_area_struct *vma,
63329 struct vm_area_struct *next)
63330 diff --git a/include/linux/sched.h b/include/linux/sched.h
63331 index 4a1f493..5812aeb 100644
63332 --- a/include/linux/sched.h
63333 +++ b/include/linux/sched.h
63334 @@ -101,6 +101,7 @@ struct bio_list;
63335 struct fs_struct;
63336 struct perf_event_context;
63337 struct blk_plug;
63338 +struct linux_binprm;
63339
63340 /*
63341 * List of flags we want to share for kernel threads,
63342 @@ -384,10 +385,13 @@ struct user_namespace;
63343 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63344
63345 extern int sysctl_max_map_count;
63346 +extern unsigned long sysctl_heap_stack_gap;
63347
63348 #include <linux/aio.h>
63349
63350 #ifdef CONFIG_MMU
63351 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63352 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63353 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63354 extern unsigned long
63355 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63356 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63357 extern void set_dumpable(struct mm_struct *mm, int value);
63358 extern int get_dumpable(struct mm_struct *mm);
63359
63360 +/* get/set_dumpable() values */
63361 +#define SUID_DUMPABLE_DISABLED 0
63362 +#define SUID_DUMPABLE_ENABLED 1
63363 +#define SUID_DUMPABLE_SAFE 2
63364 +
63365 /* mm flags */
63366 /* dumpable bits */
63367 #define MMF_DUMPABLE 0 /* core dump is permitted */
63368 @@ -646,6 +655,17 @@ struct signal_struct {
63369 #ifdef CONFIG_TASKSTATS
63370 struct taskstats *stats;
63371 #endif
63372 +
63373 +#ifdef CONFIG_GRKERNSEC
63374 + u32 curr_ip;
63375 + u32 saved_ip;
63376 + u32 gr_saddr;
63377 + u32 gr_daddr;
63378 + u16 gr_sport;
63379 + u16 gr_dport;
63380 + u8 used_accept:1;
63381 +#endif
63382 +
63383 #ifdef CONFIG_AUDIT
63384 unsigned audit_tty;
63385 struct tty_audit_buf *tty_audit_buf;
63386 @@ -729,6 +749,11 @@ struct user_struct {
63387 struct key *session_keyring; /* UID's default session keyring */
63388 #endif
63389
63390 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63391 + unsigned int banned;
63392 + unsigned long ban_expires;
63393 +#endif
63394 +
63395 /* Hash table maintenance information */
63396 struct hlist_node uidhash_node;
63397 kuid_t uid;
63398 @@ -1348,8 +1373,8 @@ struct task_struct {
63399 struct list_head thread_group;
63400
63401 struct completion *vfork_done; /* for vfork() */
63402 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63403 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63404 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63405 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63406
63407 cputime_t utime, stime, utimescaled, stimescaled;
63408 cputime_t gtime;
63409 @@ -1365,11 +1390,6 @@ struct task_struct {
63410 struct task_cputime cputime_expires;
63411 struct list_head cpu_timers[3];
63412
63413 -/* process credentials */
63414 - const struct cred __rcu *real_cred; /* objective and real subjective task
63415 - * credentials (COW) */
63416 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63417 - * credentials (COW) */
63418 char comm[TASK_COMM_LEN]; /* executable name excluding path
63419 - access with [gs]et_task_comm (which lock
63420 it with task_lock())
63421 @@ -1386,8 +1406,16 @@ struct task_struct {
63422 #endif
63423 /* CPU-specific state of this task */
63424 struct thread_struct thread;
63425 +/* thread_info moved to task_struct */
63426 +#ifdef CONFIG_X86
63427 + struct thread_info tinfo;
63428 +#endif
63429 /* filesystem information */
63430 struct fs_struct *fs;
63431 +
63432 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63433 + * credentials (COW) */
63434 +
63435 /* open file information */
63436 struct files_struct *files;
63437 /* namespaces */
63438 @@ -1431,6 +1459,11 @@ struct task_struct {
63439 struct rt_mutex_waiter *pi_blocked_on;
63440 #endif
63441
63442 +/* process credentials */
63443 + const struct cred __rcu *real_cred; /* objective and real subjective task
63444 + * credentials (COW) */
63445 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63446 +
63447 #ifdef CONFIG_DEBUG_MUTEXES
63448 /* mutex deadlock detection */
63449 struct mutex_waiter *blocked_on;
63450 @@ -1547,6 +1580,27 @@ struct task_struct {
63451 unsigned long default_timer_slack_ns;
63452
63453 struct list_head *scm_work_list;
63454 +
63455 +#ifdef CONFIG_GRKERNSEC
63456 + /* grsecurity */
63457 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63458 + u64 exec_id;
63459 +#endif
63460 +#ifdef CONFIG_GRKERNSEC_SETXID
63461 + const struct cred *delayed_cred;
63462 +#endif
63463 + struct dentry *gr_chroot_dentry;
63464 + struct acl_subject_label *acl;
63465 + struct acl_role_label *role;
63466 + struct file *exec_file;
63467 + u16 acl_role_id;
63468 + /* is this the task that authenticated to the special role */
63469 + u8 acl_sp_role;
63470 + u8 is_writable;
63471 + u8 brute;
63472 + u8 gr_is_chrooted;
63473 +#endif
63474 +
63475 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63476 /* Index of current stored address in ret_stack */
63477 int curr_ret_stack;
63478 @@ -1585,6 +1639,51 @@ struct task_struct {
63479 #endif
63480 };
63481
63482 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63483 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63484 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63485 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63486 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63487 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63488 +
63489 +#ifdef CONFIG_PAX_SOFTMODE
63490 +extern int pax_softmode;
63491 +#endif
63492 +
63493 +extern int pax_check_flags(unsigned long *);
63494 +
63495 +/* if tsk != current then task_lock must be held on it */
63496 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63497 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63498 +{
63499 + if (likely(tsk->mm))
63500 + return tsk->mm->pax_flags;
63501 + else
63502 + return 0UL;
63503 +}
63504 +
63505 +/* if tsk != current then task_lock must be held on it */
63506 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63507 +{
63508 + if (likely(tsk->mm)) {
63509 + tsk->mm->pax_flags = flags;
63510 + return 0;
63511 + }
63512 + return -EINVAL;
63513 +}
63514 +#endif
63515 +
63516 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63517 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63518 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63519 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63520 +#endif
63521 +
63522 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63523 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63524 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63525 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
63526 +
63527 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63528 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63529
63530 @@ -2112,7 +2211,9 @@ void yield(void);
63531 extern struct exec_domain default_exec_domain;
63532
63533 union thread_union {
63534 +#ifndef CONFIG_X86
63535 struct thread_info thread_info;
63536 +#endif
63537 unsigned long stack[THREAD_SIZE/sizeof(long)];
63538 };
63539
63540 @@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63541 */
63542
63543 extern struct task_struct *find_task_by_vpid(pid_t nr);
63544 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63545 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63546 struct pid_namespace *ns);
63547
63548 @@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63549 extern void exit_itimers(struct signal_struct *);
63550 extern void flush_itimer_signals(void);
63551
63552 -extern void do_group_exit(int);
63553 +extern __noreturn void do_group_exit(int);
63554
63555 extern void daemonize(const char *, ...);
63556 extern int allow_signal(int);
63557 @@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63558
63559 #endif
63560
63561 -static inline int object_is_on_stack(void *obj)
63562 +static inline int object_starts_on_stack(void *obj)
63563 {
63564 - void *stack = task_stack_page(current);
63565 + const void *stack = task_stack_page(current);
63566
63567 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63568 }
63569 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63570 index 899fbb4..1cb4138 100644
63571 --- a/include/linux/screen_info.h
63572 +++ b/include/linux/screen_info.h
63573 @@ -43,7 +43,8 @@ struct screen_info {
63574 __u16 pages; /* 0x32 */
63575 __u16 vesa_attributes; /* 0x34 */
63576 __u32 capabilities; /* 0x36 */
63577 - __u8 _reserved[6]; /* 0x3a */
63578 + __u16 vesapm_size; /* 0x3a */
63579 + __u8 _reserved[4]; /* 0x3c */
63580 } __attribute__((packed));
63581
63582 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63583 diff --git a/include/linux/security.h b/include/linux/security.h
63584 index 4e5a73c..a5784a1 100644
63585 --- a/include/linux/security.h
63586 +++ b/include/linux/security.h
63587 @@ -26,6 +26,7 @@
63588 #include <linux/capability.h>
63589 #include <linux/slab.h>
63590 #include <linux/err.h>
63591 +#include <linux/grsecurity.h>
63592
63593 struct linux_binprm;
63594 struct cred;
63595 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63596 index fc61854..d7c490b 100644
63597 --- a/include/linux/seq_file.h
63598 +++ b/include/linux/seq_file.h
63599 @@ -25,6 +25,9 @@ struct seq_file {
63600 struct mutex lock;
63601 const struct seq_operations *op;
63602 int poll_event;
63603 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63604 + u64 exec_id;
63605 +#endif
63606 void *private;
63607 };
63608
63609 @@ -34,6 +37,7 @@ struct seq_operations {
63610 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63611 int (*show) (struct seq_file *m, void *v);
63612 };
63613 +typedef struct seq_operations __no_const seq_operations_no_const;
63614
63615 #define SEQ_SKIP 1
63616
63617 diff --git a/include/linux/shm.h b/include/linux/shm.h
63618 index 92808b8..c28cac4 100644
63619 --- a/include/linux/shm.h
63620 +++ b/include/linux/shm.h
63621 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63622
63623 /* The task created the shm object. NULL if the task is dead. */
63624 struct task_struct *shm_creator;
63625 +#ifdef CONFIG_GRKERNSEC
63626 + time_t shm_createtime;
63627 + pid_t shm_lapid;
63628 +#endif
63629 };
63630
63631 /* shm_mode upper byte flags */
63632 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63633 index 642cb73..7ff7f9f 100644
63634 --- a/include/linux/skbuff.h
63635 +++ b/include/linux/skbuff.h
63636 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63637 */
63638 static inline int skb_queue_empty(const struct sk_buff_head *list)
63639 {
63640 - return list->next == (struct sk_buff *)list;
63641 + return list->next == (const struct sk_buff *)list;
63642 }
63643
63644 /**
63645 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63646 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63647 const struct sk_buff *skb)
63648 {
63649 - return skb->next == (struct sk_buff *)list;
63650 + return skb->next == (const struct sk_buff *)list;
63651 }
63652
63653 /**
63654 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63655 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63656 const struct sk_buff *skb)
63657 {
63658 - return skb->prev == (struct sk_buff *)list;
63659 + return skb->prev == (const struct sk_buff *)list;
63660 }
63661
63662 /**
63663 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63664 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63665 */
63666 #ifndef NET_SKB_PAD
63667 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63668 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63669 #endif
63670
63671 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63672 diff --git a/include/linux/slab.h b/include/linux/slab.h
63673 index 67d5d94..371d9a7 100644
63674 --- a/include/linux/slab.h
63675 +++ b/include/linux/slab.h
63676 @@ -11,12 +11,20 @@
63677
63678 #include <linux/gfp.h>
63679 #include <linux/types.h>
63680 +#include <linux/err.h>
63681
63682 /*
63683 * Flags to pass to kmem_cache_create().
63684 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63685 */
63686 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63687 +
63688 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63689 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63690 +#else
63691 +#define SLAB_USERCOPY 0x00000000UL
63692 +#endif
63693 +
63694 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63695 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63696 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63697 @@ -87,10 +95,13 @@
63698 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63699 * Both make kfree a no-op.
63700 */
63701 -#define ZERO_SIZE_PTR ((void *)16)
63702 +#define ZERO_SIZE_PTR \
63703 +({ \
63704 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63705 + (void *)(-MAX_ERRNO-1L); \
63706 +})
63707
63708 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63709 - (unsigned long)ZERO_SIZE_PTR)
63710 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63711
63712 /*
63713 * struct kmem_cache related prototypes
63714 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63715 void kfree(const void *);
63716 void kzfree(const void *);
63717 size_t ksize(const void *);
63718 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63719 +bool is_usercopy_object(const void *ptr);
63720
63721 /*
63722 * Allocator specific definitions. These are mainly used to establish optimized
63723 @@ -240,6 +253,7 @@ size_t ksize(const void *);
63724 * for general use, and so are not documented here. For a full list of
63725 * potential flags, always refer to linux/gfp.h.
63726 */
63727 +static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
63728 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
63729 {
63730 if (size != 0 && n > SIZE_MAX / size)
63731 @@ -298,7 +312,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63732 */
63733 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63734 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63735 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63736 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63737 #define kmalloc_track_caller(size, flags) \
63738 __kmalloc_track_caller(size, flags, _RET_IP_)
63739 #else
63740 @@ -317,7 +331,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63741 */
63742 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63743 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63744 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63745 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63746 #define kmalloc_node_track_caller(size, flags, node) \
63747 __kmalloc_node_track_caller(size, flags, node, \
63748 _RET_IP_)
63749 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63750 index fbd1117..0a3d314 100644
63751 --- a/include/linux/slab_def.h
63752 +++ b/include/linux/slab_def.h
63753 @@ -66,10 +66,10 @@ struct kmem_cache {
63754 unsigned long node_allocs;
63755 unsigned long node_frees;
63756 unsigned long node_overflow;
63757 - atomic_t allochit;
63758 - atomic_t allocmiss;
63759 - atomic_t freehit;
63760 - atomic_t freemiss;
63761 + atomic_unchecked_t allochit;
63762 + atomic_unchecked_t allocmiss;
63763 + atomic_unchecked_t freehit;
63764 + atomic_unchecked_t freemiss;
63765
63766 /*
63767 * If debugging is enabled, then the allocator can add additional
63768 @@ -103,11 +103,16 @@ struct cache_sizes {
63769 #ifdef CONFIG_ZONE_DMA
63770 struct kmem_cache *cs_dmacachep;
63771 #endif
63772 +
63773 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63774 + struct kmem_cache *cs_usercopycachep;
63775 +#endif
63776 +
63777 };
63778 extern struct cache_sizes malloc_sizes[];
63779
63780 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63781 -void *__kmalloc(size_t size, gfp_t flags);
63782 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63783
63784 #ifdef CONFIG_TRACING
63785 extern void *kmem_cache_alloc_trace(size_t size,
63786 @@ -150,6 +155,13 @@ found:
63787 cachep = malloc_sizes[i].cs_dmacachep;
63788 else
63789 #endif
63790 +
63791 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63792 + if (flags & GFP_USERCOPY)
63793 + cachep = malloc_sizes[i].cs_usercopycachep;
63794 + else
63795 +#endif
63796 +
63797 cachep = malloc_sizes[i].cs_cachep;
63798
63799 ret = kmem_cache_alloc_trace(size, cachep, flags);
63800 @@ -160,7 +172,7 @@ found:
63801 }
63802
63803 #ifdef CONFIG_NUMA
63804 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63805 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63806 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63807
63808 #ifdef CONFIG_TRACING
63809 @@ -203,6 +215,13 @@ found:
63810 cachep = malloc_sizes[i].cs_dmacachep;
63811 else
63812 #endif
63813 +
63814 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63815 + if (flags & GFP_USERCOPY)
63816 + cachep = malloc_sizes[i].cs_usercopycachep;
63817 + else
63818 +#endif
63819 +
63820 cachep = malloc_sizes[i].cs_cachep;
63821
63822 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63823 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63824 index 0ec00b3..39cb7fc 100644
63825 --- a/include/linux/slob_def.h
63826 +++ b/include/linux/slob_def.h
63827 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63828 return kmem_cache_alloc_node(cachep, flags, -1);
63829 }
63830
63831 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63832 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63833
63834 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63835 {
63836 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63837 return __kmalloc_node(size, flags, -1);
63838 }
63839
63840 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63841 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63842 {
63843 return kmalloc(size, flags);
63844 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63845 index c2f8c8b..be9e036 100644
63846 --- a/include/linux/slub_def.h
63847 +++ b/include/linux/slub_def.h
63848 @@ -92,7 +92,7 @@ struct kmem_cache {
63849 struct kmem_cache_order_objects max;
63850 struct kmem_cache_order_objects min;
63851 gfp_t allocflags; /* gfp flags to use on each alloc */
63852 - int refcount; /* Refcount for slab cache destroy */
63853 + atomic_t refcount; /* Refcount for slab cache destroy */
63854 void (*ctor)(void *);
63855 int inuse; /* Offset to metadata */
63856 int align; /* Alignment */
63857 @@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63858 * Sorry that the following has to be that ugly but some versions of GCC
63859 * have trouble with constant propagation and loops.
63860 */
63861 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63862 static __always_inline int kmalloc_index(size_t size)
63863 {
63864 if (!size)
63865 @@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63866 }
63867
63868 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63869 -void *__kmalloc(size_t size, gfp_t flags);
63870 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63871
63872 static __always_inline void *
63873 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63874 @@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63875 }
63876 #endif
63877
63878 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63879 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63880 {
63881 unsigned int order = get_order(size);
63882 @@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63883 }
63884
63885 #ifdef CONFIG_NUMA
63886 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63887 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63888 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63889
63890 #ifdef CONFIG_TRACING
63891 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63892 index de8832d..0147b46 100644
63893 --- a/include/linux/sonet.h
63894 +++ b/include/linux/sonet.h
63895 @@ -61,7 +61,7 @@ struct sonet_stats {
63896 #include <linux/atomic.h>
63897
63898 struct k_sonet_stats {
63899 -#define __HANDLE_ITEM(i) atomic_t i
63900 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63901 __SONET_ITEMS
63902 #undef __HANDLE_ITEM
63903 };
63904 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63905 index 523547e..2cb7140 100644
63906 --- a/include/linux/sunrpc/clnt.h
63907 +++ b/include/linux/sunrpc/clnt.h
63908 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63909 {
63910 switch (sap->sa_family) {
63911 case AF_INET:
63912 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63913 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63914 case AF_INET6:
63915 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63916 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63917 }
63918 return 0;
63919 }
63920 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63921 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63922 const struct sockaddr *src)
63923 {
63924 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63925 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63926 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63927
63928 dsin->sin_family = ssin->sin_family;
63929 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63930 if (sa->sa_family != AF_INET6)
63931 return 0;
63932
63933 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63934 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63935 }
63936
63937 #endif /* __KERNEL__ */
63938 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63939 index dc0c3cc..8503fb6 100644
63940 --- a/include/linux/sunrpc/sched.h
63941 +++ b/include/linux/sunrpc/sched.h
63942 @@ -106,6 +106,7 @@ struct rpc_call_ops {
63943 void (*rpc_count_stats)(struct rpc_task *, void *);
63944 void (*rpc_release)(void *);
63945 };
63946 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63947
63948 struct rpc_task_setup {
63949 struct rpc_task *task;
63950 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63951 index 0b8e3e6..33e0a01 100644
63952 --- a/include/linux/sunrpc/svc_rdma.h
63953 +++ b/include/linux/sunrpc/svc_rdma.h
63954 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63955 extern unsigned int svcrdma_max_requests;
63956 extern unsigned int svcrdma_max_req_size;
63957
63958 -extern atomic_t rdma_stat_recv;
63959 -extern atomic_t rdma_stat_read;
63960 -extern atomic_t rdma_stat_write;
63961 -extern atomic_t rdma_stat_sq_starve;
63962 -extern atomic_t rdma_stat_rq_starve;
63963 -extern atomic_t rdma_stat_rq_poll;
63964 -extern atomic_t rdma_stat_rq_prod;
63965 -extern atomic_t rdma_stat_sq_poll;
63966 -extern atomic_t rdma_stat_sq_prod;
63967 +extern atomic_unchecked_t rdma_stat_recv;
63968 +extern atomic_unchecked_t rdma_stat_read;
63969 +extern atomic_unchecked_t rdma_stat_write;
63970 +extern atomic_unchecked_t rdma_stat_sq_starve;
63971 +extern atomic_unchecked_t rdma_stat_rq_starve;
63972 +extern atomic_unchecked_t rdma_stat_rq_poll;
63973 +extern atomic_unchecked_t rdma_stat_rq_prod;
63974 +extern atomic_unchecked_t rdma_stat_sq_poll;
63975 +extern atomic_unchecked_t rdma_stat_sq_prod;
63976
63977 #define RPCRDMA_VERSION 1
63978
63979 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63980 index c34b4c8..a65b67d 100644
63981 --- a/include/linux/sysctl.h
63982 +++ b/include/linux/sysctl.h
63983 @@ -155,7 +155,11 @@ enum
63984 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63985 };
63986
63987 -
63988 +#ifdef CONFIG_PAX_SOFTMODE
63989 +enum {
63990 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63991 +};
63992 +#endif
63993
63994 /* CTL_VM names: */
63995 enum
63996 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63997
63998 extern int proc_dostring(struct ctl_table *, int,
63999 void __user *, size_t *, loff_t *);
64000 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64001 + void __user *, size_t *, loff_t *);
64002 extern int proc_dointvec(struct ctl_table *, int,
64003 void __user *, size_t *, loff_t *);
64004 extern int proc_dointvec_minmax(struct ctl_table *, int,
64005 diff --git a/include/linux/tty.h b/include/linux/tty.h
64006 index 9f47ab5..73da944 100644
64007 --- a/include/linux/tty.h
64008 +++ b/include/linux/tty.h
64009 @@ -225,7 +225,7 @@ struct tty_port {
64010 const struct tty_port_operations *ops; /* Port operations */
64011 spinlock_t lock; /* Lock protecting tty field */
64012 int blocked_open; /* Waiting to open */
64013 - int count; /* Usage count */
64014 + atomic_t count; /* Usage count */
64015 wait_queue_head_t open_wait; /* Open waiters */
64016 wait_queue_head_t close_wait; /* Close waiters */
64017 wait_queue_head_t delta_msr_wait; /* Modem status change */
64018 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64019 struct tty_struct *tty, struct file *filp);
64020 static inline int tty_port_users(struct tty_port *port)
64021 {
64022 - return port->count + port->blocked_open;
64023 + return atomic_read(&port->count) + port->blocked_open;
64024 }
64025
64026 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64027 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64028 index fb79dd8d..07d4773 100644
64029 --- a/include/linux/tty_ldisc.h
64030 +++ b/include/linux/tty_ldisc.h
64031 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64032
64033 struct module *owner;
64034
64035 - int refcount;
64036 + atomic_t refcount;
64037 };
64038
64039 struct tty_ldisc {
64040 diff --git a/include/linux/types.h b/include/linux/types.h
64041 index 9c1bd53..c2370f6 100644
64042 --- a/include/linux/types.h
64043 +++ b/include/linux/types.h
64044 @@ -220,10 +220,26 @@ typedef struct {
64045 int counter;
64046 } atomic_t;
64047
64048 +#ifdef CONFIG_PAX_REFCOUNT
64049 +typedef struct {
64050 + int counter;
64051 +} atomic_unchecked_t;
64052 +#else
64053 +typedef atomic_t atomic_unchecked_t;
64054 +#endif
64055 +
64056 #ifdef CONFIG_64BIT
64057 typedef struct {
64058 long counter;
64059 } atomic64_t;
64060 +
64061 +#ifdef CONFIG_PAX_REFCOUNT
64062 +typedef struct {
64063 + long counter;
64064 +} atomic64_unchecked_t;
64065 +#else
64066 +typedef atomic64_t atomic64_unchecked_t;
64067 +#endif
64068 #endif
64069
64070 struct list_head {
64071 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64072 index 5ca0951..ab496a5 100644
64073 --- a/include/linux/uaccess.h
64074 +++ b/include/linux/uaccess.h
64075 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64076 long ret; \
64077 mm_segment_t old_fs = get_fs(); \
64078 \
64079 - set_fs(KERNEL_DS); \
64080 pagefault_disable(); \
64081 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64082 - pagefault_enable(); \
64083 + set_fs(KERNEL_DS); \
64084 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64085 set_fs(old_fs); \
64086 + pagefault_enable(); \
64087 ret; \
64088 })
64089
64090 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64091 index 99c1b4d..bb94261 100644
64092 --- a/include/linux/unaligned/access_ok.h
64093 +++ b/include/linux/unaligned/access_ok.h
64094 @@ -6,32 +6,32 @@
64095
64096 static inline u16 get_unaligned_le16(const void *p)
64097 {
64098 - return le16_to_cpup((__le16 *)p);
64099 + return le16_to_cpup((const __le16 *)p);
64100 }
64101
64102 static inline u32 get_unaligned_le32(const void *p)
64103 {
64104 - return le32_to_cpup((__le32 *)p);
64105 + return le32_to_cpup((const __le32 *)p);
64106 }
64107
64108 static inline u64 get_unaligned_le64(const void *p)
64109 {
64110 - return le64_to_cpup((__le64 *)p);
64111 + return le64_to_cpup((const __le64 *)p);
64112 }
64113
64114 static inline u16 get_unaligned_be16(const void *p)
64115 {
64116 - return be16_to_cpup((__be16 *)p);
64117 + return be16_to_cpup((const __be16 *)p);
64118 }
64119
64120 static inline u32 get_unaligned_be32(const void *p)
64121 {
64122 - return be32_to_cpup((__be32 *)p);
64123 + return be32_to_cpup((const __be32 *)p);
64124 }
64125
64126 static inline u64 get_unaligned_be64(const void *p)
64127 {
64128 - return be64_to_cpup((__be64 *)p);
64129 + return be64_to_cpup((const __be64 *)p);
64130 }
64131
64132 static inline void put_unaligned_le16(u16 val, void *p)
64133 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64134 index 547e59c..db6ad19 100644
64135 --- a/include/linux/usb/renesas_usbhs.h
64136 +++ b/include/linux/usb/renesas_usbhs.h
64137 @@ -39,7 +39,7 @@ enum {
64138 */
64139 struct renesas_usbhs_driver_callback {
64140 int (*notify_hotplug)(struct platform_device *pdev);
64141 -};
64142 +} __no_const;
64143
64144 /*
64145 * callback functions for platform
64146 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64147 * VBUS control is needed for Host
64148 */
64149 int (*set_vbus)(struct platform_device *pdev, int enable);
64150 -};
64151 +} __no_const;
64152
64153 /*
64154 * parameters for renesas usbhs
64155 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64156 index 6f8fbcf..8259001 100644
64157 --- a/include/linux/vermagic.h
64158 +++ b/include/linux/vermagic.h
64159 @@ -25,9 +25,35 @@
64160 #define MODULE_ARCH_VERMAGIC ""
64161 #endif
64162
64163 +#ifdef CONFIG_PAX_REFCOUNT
64164 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64165 +#else
64166 +#define MODULE_PAX_REFCOUNT ""
64167 +#endif
64168 +
64169 +#ifdef CONSTIFY_PLUGIN
64170 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64171 +#else
64172 +#define MODULE_CONSTIFY_PLUGIN ""
64173 +#endif
64174 +
64175 +#ifdef STACKLEAK_PLUGIN
64176 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64177 +#else
64178 +#define MODULE_STACKLEAK_PLUGIN ""
64179 +#endif
64180 +
64181 +#ifdef CONFIG_GRKERNSEC
64182 +#define MODULE_GRSEC "GRSEC "
64183 +#else
64184 +#define MODULE_GRSEC ""
64185 +#endif
64186 +
64187 #define VERMAGIC_STRING \
64188 UTS_RELEASE " " \
64189 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64190 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64191 - MODULE_ARCH_VERMAGIC
64192 + MODULE_ARCH_VERMAGIC \
64193 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64194 + MODULE_GRSEC
64195
64196 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64197 index dcdfc2b..ec79ab5 100644
64198 --- a/include/linux/vmalloc.h
64199 +++ b/include/linux/vmalloc.h
64200 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64201 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64202 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64203 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64204 +
64205 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64206 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64207 +#endif
64208 +
64209 /* bits [20..32] reserved for arch specific ioremap internals */
64210
64211 /*
64212 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64213 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64214 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64215 unsigned long start, unsigned long end, gfp_t gfp_mask,
64216 - pgprot_t prot, int node, void *caller);
64217 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64218 extern void vfree(const void *addr);
64219
64220 extern void *vmap(struct page **pages, unsigned int count,
64221 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64222 extern void free_vm_area(struct vm_struct *area);
64223
64224 /* for /dev/kmem */
64225 -extern long vread(char *buf, char *addr, unsigned long count);
64226 -extern long vwrite(char *buf, char *addr, unsigned long count);
64227 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64228 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64229
64230 /*
64231 * Internals. Dont't use..
64232 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64233 index 65efb92..137adbb 100644
64234 --- a/include/linux/vmstat.h
64235 +++ b/include/linux/vmstat.h
64236 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64237 /*
64238 * Zone based page accounting with per cpu differentials.
64239 */
64240 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64241 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64242
64243 static inline void zone_page_state_add(long x, struct zone *zone,
64244 enum zone_stat_item item)
64245 {
64246 - atomic_long_add(x, &zone->vm_stat[item]);
64247 - atomic_long_add(x, &vm_stat[item]);
64248 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64249 + atomic_long_add_unchecked(x, &vm_stat[item]);
64250 }
64251
64252 static inline unsigned long global_page_state(enum zone_stat_item item)
64253 {
64254 - long x = atomic_long_read(&vm_stat[item]);
64255 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64256 #ifdef CONFIG_SMP
64257 if (x < 0)
64258 x = 0;
64259 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64260 static inline unsigned long zone_page_state(struct zone *zone,
64261 enum zone_stat_item item)
64262 {
64263 - long x = atomic_long_read(&zone->vm_stat[item]);
64264 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64265 #ifdef CONFIG_SMP
64266 if (x < 0)
64267 x = 0;
64268 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64269 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64270 enum zone_stat_item item)
64271 {
64272 - long x = atomic_long_read(&zone->vm_stat[item]);
64273 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64274
64275 #ifdef CONFIG_SMP
64276 int cpu;
64277 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64278
64279 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64280 {
64281 - atomic_long_inc(&zone->vm_stat[item]);
64282 - atomic_long_inc(&vm_stat[item]);
64283 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64284 + atomic_long_inc_unchecked(&vm_stat[item]);
64285 }
64286
64287 static inline void __inc_zone_page_state(struct page *page,
64288 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64289
64290 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64291 {
64292 - atomic_long_dec(&zone->vm_stat[item]);
64293 - atomic_long_dec(&vm_stat[item]);
64294 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64295 + atomic_long_dec_unchecked(&vm_stat[item]);
64296 }
64297
64298 static inline void __dec_zone_page_state(struct page *page,
64299 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64300 index e5d1220..ef6e406 100644
64301 --- a/include/linux/xattr.h
64302 +++ b/include/linux/xattr.h
64303 @@ -57,6 +57,11 @@
64304 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64305 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64306
64307 +/* User namespace */
64308 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64309 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64310 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64311 +
64312 #ifdef __KERNEL__
64313
64314 #include <linux/types.h>
64315 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64316 index 944ecdf..a3994fc 100644
64317 --- a/include/media/saa7146_vv.h
64318 +++ b/include/media/saa7146_vv.h
64319 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64320 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64321
64322 /* the extension can override this */
64323 - struct v4l2_ioctl_ops vid_ops;
64324 - struct v4l2_ioctl_ops vbi_ops;
64325 + v4l2_ioctl_ops_no_const vid_ops;
64326 + v4l2_ioctl_ops_no_const vbi_ops;
64327 /* pointer to the saa7146 core ops */
64328 const struct v4l2_ioctl_ops *core_ops;
64329
64330 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64331 index a056e6e..31023a5 100644
64332 --- a/include/media/v4l2-dev.h
64333 +++ b/include/media/v4l2-dev.h
64334 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64335 int (*mmap) (struct file *, struct vm_area_struct *);
64336 int (*open) (struct file *);
64337 int (*release) (struct file *);
64338 -};
64339 +} __do_const;
64340 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64341
64342 /*
64343 * Newer version of video_device, handled by videodev2.c
64344 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64345 index d8b76f7..7d5aa18 100644
64346 --- a/include/media/v4l2-ioctl.h
64347 +++ b/include/media/v4l2-ioctl.h
64348 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64349 long (*vidioc_default) (struct file *file, void *fh,
64350 bool valid_prio, int cmd, void *arg);
64351 };
64352 -
64353 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64354
64355 /* v4l debugging and diagnostics */
64356
64357 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64358 index 439dadc..1c67e3f 100644
64359 --- a/include/net/caif/caif_hsi.h
64360 +++ b/include/net/caif/caif_hsi.h
64361 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64362 void (*rx_done_cb) (struct cfhsi_drv *drv);
64363 void (*wake_up_cb) (struct cfhsi_drv *drv);
64364 void (*wake_down_cb) (struct cfhsi_drv *drv);
64365 -};
64366 +} __no_const;
64367
64368 /* Structure implemented by HSI device. */
64369 struct cfhsi_dev {
64370 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64371 index 9e5425b..8136ffc 100644
64372 --- a/include/net/caif/cfctrl.h
64373 +++ b/include/net/caif/cfctrl.h
64374 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64375 void (*radioset_rsp)(void);
64376 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64377 struct cflayer *client_layer);
64378 -};
64379 +} __no_const;
64380
64381 /* Link Setup Parameters for CAIF-Links. */
64382 struct cfctrl_link_param {
64383 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64384 struct cfctrl {
64385 struct cfsrvl serv;
64386 struct cfctrl_rsp res;
64387 - atomic_t req_seq_no;
64388 - atomic_t rsp_seq_no;
64389 + atomic_unchecked_t req_seq_no;
64390 + atomic_unchecked_t rsp_seq_no;
64391 struct list_head list;
64392 /* Protects from simultaneous access to first_req list */
64393 spinlock_t info_list_lock;
64394 diff --git a/include/net/flow.h b/include/net/flow.h
64395 index 6c469db..7743b8e 100644
64396 --- a/include/net/flow.h
64397 +++ b/include/net/flow.h
64398 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64399
64400 extern void flow_cache_flush(void);
64401 extern void flow_cache_flush_deferred(void);
64402 -extern atomic_t flow_cache_genid;
64403 +extern atomic_unchecked_t flow_cache_genid;
64404
64405 #endif
64406 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64407 index 2040bff..f4c0733 100644
64408 --- a/include/net/inetpeer.h
64409 +++ b/include/net/inetpeer.h
64410 @@ -51,8 +51,8 @@ struct inet_peer {
64411 */
64412 union {
64413 struct {
64414 - atomic_t rid; /* Frag reception counter */
64415 - atomic_t ip_id_count; /* IP ID for the next packet */
64416 + atomic_unchecked_t rid; /* Frag reception counter */
64417 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64418 __u32 tcp_ts;
64419 __u32 tcp_ts_stamp;
64420 };
64421 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64422 more++;
64423 inet_peer_refcheck(p);
64424 do {
64425 - old = atomic_read(&p->ip_id_count);
64426 + old = atomic_read_unchecked(&p->ip_id_count);
64427 new = old + more;
64428 if (!new)
64429 new = 1;
64430 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64431 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64432 return new;
64433 }
64434
64435 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64436 index 78df0866..00e5c9b 100644
64437 --- a/include/net/ip_fib.h
64438 +++ b/include/net/ip_fib.h
64439 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64440
64441 #define FIB_RES_SADDR(net, res) \
64442 ((FIB_RES_NH(res).nh_saddr_genid == \
64443 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64444 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64445 FIB_RES_NH(res).nh_saddr : \
64446 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64447 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64448 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64449 index 95374d1..2300e36 100644
64450 --- a/include/net/ip_vs.h
64451 +++ b/include/net/ip_vs.h
64452 @@ -510,7 +510,7 @@ struct ip_vs_conn {
64453 struct ip_vs_conn *control; /* Master control connection */
64454 atomic_t n_control; /* Number of controlled ones */
64455 struct ip_vs_dest *dest; /* real server */
64456 - atomic_t in_pkts; /* incoming packet counter */
64457 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64458
64459 /* packet transmitter for different forwarding methods. If it
64460 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64461 @@ -648,7 +648,7 @@ struct ip_vs_dest {
64462 __be16 port; /* port number of the server */
64463 union nf_inet_addr addr; /* IP address of the server */
64464 volatile unsigned int flags; /* dest status flags */
64465 - atomic_t conn_flags; /* flags to copy to conn */
64466 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64467 atomic_t weight; /* server weight */
64468
64469 atomic_t refcnt; /* reference counter */
64470 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64471 index 69b610a..fe3962c 100644
64472 --- a/include/net/irda/ircomm_core.h
64473 +++ b/include/net/irda/ircomm_core.h
64474 @@ -51,7 +51,7 @@ typedef struct {
64475 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64476 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64477 struct ircomm_info *);
64478 -} call_t;
64479 +} __no_const call_t;
64480
64481 struct ircomm_cb {
64482 irda_queue_t queue;
64483 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64484 index 59ba38bc..d515662 100644
64485 --- a/include/net/irda/ircomm_tty.h
64486 +++ b/include/net/irda/ircomm_tty.h
64487 @@ -35,6 +35,7 @@
64488 #include <linux/termios.h>
64489 #include <linux/timer.h>
64490 #include <linux/tty.h> /* struct tty_struct */
64491 +#include <asm/local.h>
64492
64493 #include <net/irda/irias_object.h>
64494 #include <net/irda/ircomm_core.h>
64495 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64496 unsigned short close_delay;
64497 unsigned short closing_wait; /* time to wait before closing */
64498
64499 - int open_count;
64500 - int blocked_open; /* # of blocked opens */
64501 + local_t open_count;
64502 + local_t blocked_open; /* # of blocked opens */
64503
64504 /* Protect concurent access to :
64505 * o self->open_count
64506 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64507 index cc7c197..9f2da2a 100644
64508 --- a/include/net/iucv/af_iucv.h
64509 +++ b/include/net/iucv/af_iucv.h
64510 @@ -141,7 +141,7 @@ struct iucv_sock {
64511 struct iucv_sock_list {
64512 struct hlist_head head;
64513 rwlock_t lock;
64514 - atomic_t autobind_name;
64515 + atomic_unchecked_t autobind_name;
64516 };
64517
64518 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64519 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64520 index 6cdfeed..55a0256 100644
64521 --- a/include/net/neighbour.h
64522 +++ b/include/net/neighbour.h
64523 @@ -123,7 +123,7 @@ struct neigh_ops {
64524 void (*error_report)(struct neighbour *, struct sk_buff *);
64525 int (*output)(struct neighbour *, struct sk_buff *);
64526 int (*connected_output)(struct neighbour *, struct sk_buff *);
64527 -};
64528 +} __do_const;
64529
64530 struct pneigh_entry {
64531 struct pneigh_entry *next;
64532 diff --git a/include/net/netlink.h b/include/net/netlink.h
64533 index 785f37a..c81dc0c 100644
64534 --- a/include/net/netlink.h
64535 +++ b/include/net/netlink.h
64536 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64537 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64538 {
64539 if (mark)
64540 - skb_trim(skb, (unsigned char *) mark - skb->data);
64541 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64542 }
64543
64544 /**
64545 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64546 index bbd023a..97c6d0d 100644
64547 --- a/include/net/netns/ipv4.h
64548 +++ b/include/net/netns/ipv4.h
64549 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64550 unsigned int sysctl_ping_group_range[2];
64551 long sysctl_tcp_mem[3];
64552
64553 - atomic_t rt_genid;
64554 - atomic_t dev_addr_genid;
64555 + atomic_unchecked_t rt_genid;
64556 + atomic_unchecked_t dev_addr_genid;
64557
64558 #ifdef CONFIG_IP_MROUTE
64559 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64560 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64561 index a2ef814..31a8e3f 100644
64562 --- a/include/net/sctp/sctp.h
64563 +++ b/include/net/sctp/sctp.h
64564 @@ -318,9 +318,9 @@ do { \
64565
64566 #else /* SCTP_DEBUG */
64567
64568 -#define SCTP_DEBUG_PRINTK(whatever...)
64569 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64570 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64571 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64572 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64573 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64574 #define SCTP_ENABLE_DEBUG
64575 #define SCTP_DISABLE_DEBUG
64576 #define SCTP_ASSERT(expr, str, func)
64577 diff --git a/include/net/sock.h b/include/net/sock.h
64578 index 4a45216..7af2578 100644
64579 --- a/include/net/sock.h
64580 +++ b/include/net/sock.h
64581 @@ -303,7 +303,7 @@ struct sock {
64582 #ifdef CONFIG_RPS
64583 __u32 sk_rxhash;
64584 #endif
64585 - atomic_t sk_drops;
64586 + atomic_unchecked_t sk_drops;
64587 int sk_rcvbuf;
64588
64589 struct sk_filter __rcu *sk_filter;
64590 @@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64591 }
64592
64593 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64594 - char __user *from, char *to,
64595 + char __user *from, unsigned char *to,
64596 int copy, int offset)
64597 {
64598 if (skb->ip_summed == CHECKSUM_NONE) {
64599 diff --git a/include/net/tcp.h b/include/net/tcp.h
64600 index e79aa48..9929421 100644
64601 --- a/include/net/tcp.h
64602 +++ b/include/net/tcp.h
64603 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64604 char *name;
64605 sa_family_t family;
64606 const struct file_operations *seq_fops;
64607 - struct seq_operations seq_ops;
64608 + seq_operations_no_const seq_ops;
64609 };
64610
64611 struct tcp_iter_state {
64612 diff --git a/include/net/udp.h b/include/net/udp.h
64613 index 065f379..b661b40 100644
64614 --- a/include/net/udp.h
64615 +++ b/include/net/udp.h
64616 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64617 sa_family_t family;
64618 struct udp_table *udp_table;
64619 const struct file_operations *seq_fops;
64620 - struct seq_operations seq_ops;
64621 + seq_operations_no_const seq_ops;
64622 };
64623
64624 struct udp_iter_state {
64625 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64626 index e0a55df..5890bca07 100644
64627 --- a/include/net/xfrm.h
64628 +++ b/include/net/xfrm.h
64629 @@ -505,7 +505,7 @@ struct xfrm_policy {
64630 struct timer_list timer;
64631
64632 struct flow_cache_object flo;
64633 - atomic_t genid;
64634 + atomic_unchecked_t genid;
64635 u32 priority;
64636 u32 index;
64637 struct xfrm_mark mark;
64638 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64639 index 1a046b1..ee0bef0 100644
64640 --- a/include/rdma/iw_cm.h
64641 +++ b/include/rdma/iw_cm.h
64642 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64643 int backlog);
64644
64645 int (*destroy_listen)(struct iw_cm_id *cm_id);
64646 -};
64647 +} __no_const;
64648
64649 /**
64650 * iw_create_cm_id - Create an IW CM identifier.
64651 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64652 index 8f9dfba..610ab6c 100644
64653 --- a/include/scsi/libfc.h
64654 +++ b/include/scsi/libfc.h
64655 @@ -756,6 +756,7 @@ struct libfc_function_template {
64656 */
64657 void (*disc_stop_final) (struct fc_lport *);
64658 };
64659 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64660
64661 /**
64662 * struct fc_disc - Discovery context
64663 @@ -861,7 +862,7 @@ struct fc_lport {
64664 struct fc_vport *vport;
64665
64666 /* Operational Information */
64667 - struct libfc_function_template tt;
64668 + libfc_function_template_no_const tt;
64669 u8 link_up;
64670 u8 qfull;
64671 enum fc_lport_state state;
64672 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64673 index ba96988..ecf2eb9 100644
64674 --- a/include/scsi/scsi_device.h
64675 +++ b/include/scsi/scsi_device.h
64676 @@ -163,9 +163,9 @@ struct scsi_device {
64677 unsigned int max_device_blocked; /* what device_blocked counts down from */
64678 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64679
64680 - atomic_t iorequest_cnt;
64681 - atomic_t iodone_cnt;
64682 - atomic_t ioerr_cnt;
64683 + atomic_unchecked_t iorequest_cnt;
64684 + atomic_unchecked_t iodone_cnt;
64685 + atomic_unchecked_t ioerr_cnt;
64686
64687 struct device sdev_gendev,
64688 sdev_dev;
64689 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64690 index 719faf1..07b6728 100644
64691 --- a/include/scsi/scsi_transport_fc.h
64692 +++ b/include/scsi/scsi_transport_fc.h
64693 @@ -739,7 +739,8 @@ struct fc_function_template {
64694 unsigned long show_host_system_hostname:1;
64695
64696 unsigned long disable_target_scan:1;
64697 -};
64698 +} __do_const;
64699 +typedef struct fc_function_template __no_const fc_function_template_no_const;
64700
64701
64702 /**
64703 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64704 index 030b87c..98a6954 100644
64705 --- a/include/sound/ak4xxx-adda.h
64706 +++ b/include/sound/ak4xxx-adda.h
64707 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64708 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64709 unsigned char val);
64710 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64711 -};
64712 +} __no_const;
64713
64714 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64715
64716 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64717 index 8c05e47..2b5df97 100644
64718 --- a/include/sound/hwdep.h
64719 +++ b/include/sound/hwdep.h
64720 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64721 struct snd_hwdep_dsp_status *status);
64722 int (*dsp_load)(struct snd_hwdep *hw,
64723 struct snd_hwdep_dsp_image *image);
64724 -};
64725 +} __no_const;
64726
64727 struct snd_hwdep {
64728 struct snd_card *card;
64729 diff --git a/include/sound/info.h b/include/sound/info.h
64730 index 9ca1a49..aba1728 100644
64731 --- a/include/sound/info.h
64732 +++ b/include/sound/info.h
64733 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64734 struct snd_info_buffer *buffer);
64735 void (*write)(struct snd_info_entry *entry,
64736 struct snd_info_buffer *buffer);
64737 -};
64738 +} __no_const;
64739
64740 struct snd_info_entry_ops {
64741 int (*open)(struct snd_info_entry *entry,
64742 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64743 index 0d11128..814178e 100644
64744 --- a/include/sound/pcm.h
64745 +++ b/include/sound/pcm.h
64746 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64747 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64748 int (*ack)(struct snd_pcm_substream *substream);
64749 };
64750 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64751
64752 /*
64753 *
64754 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64755 index af1b49e..a5d55a5 100644
64756 --- a/include/sound/sb16_csp.h
64757 +++ b/include/sound/sb16_csp.h
64758 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64759 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64760 int (*csp_stop) (struct snd_sb_csp * p);
64761 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64762 -};
64763 +} __no_const;
64764
64765 /*
64766 * CSP private data
64767 diff --git a/include/sound/soc.h b/include/sound/soc.h
64768 index c703871..f7fbbbd 100644
64769 --- a/include/sound/soc.h
64770 +++ b/include/sound/soc.h
64771 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64772 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64773 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64774 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64775 -};
64776 +} __do_const;
64777
64778 struct snd_soc_platform {
64779 const char *name;
64780 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64781 struct snd_soc_dai_link *dai_link;
64782 struct mutex pcm_mutex;
64783 enum snd_soc_pcm_subclass pcm_subclass;
64784 - struct snd_pcm_ops ops;
64785 + snd_pcm_ops_no_const ops;
64786
64787 unsigned int dev_registered:1;
64788
64789 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64790 index 0c3c2fb..d9d9990 100644
64791 --- a/include/sound/tea575x-tuner.h
64792 +++ b/include/sound/tea575x-tuner.h
64793 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64794
64795 struct snd_tea575x {
64796 struct v4l2_device *v4l2_dev;
64797 - struct v4l2_file_operations fops;
64798 + v4l2_file_operations_no_const fops;
64799 struct video_device vd; /* video device */
64800 int radio_nr; /* radio_nr */
64801 bool tea5759; /* 5759 chip is present */
64802 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64803 index 4119966..1a4671c 100644
64804 --- a/include/sound/ymfpci.h
64805 +++ b/include/sound/ymfpci.h
64806 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64807 spinlock_t reg_lock;
64808 spinlock_t voice_lock;
64809 wait_queue_head_t interrupt_sleep;
64810 - atomic_t interrupt_sleep_count;
64811 + atomic_unchecked_t interrupt_sleep_count;
64812 struct snd_info_entry *proc_entry;
64813 const struct firmware *dsp_microcode;
64814 const struct firmware *controller_microcode;
64815 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64816 index dc35d86..4725f45 100644
64817 --- a/include/target/target_core_base.h
64818 +++ b/include/target/target_core_base.h
64819 @@ -440,7 +440,7 @@ struct t10_reservation_ops {
64820 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64821 int (*t10_pr_register)(struct se_cmd *);
64822 int (*t10_pr_clear)(struct se_cmd *);
64823 -};
64824 +} __no_const;
64825
64826 struct t10_reservation {
64827 /* Reservation effects all target ports */
64828 @@ -779,7 +779,7 @@ struct se_device {
64829 spinlock_t stats_lock;
64830 /* Active commands on this virtual SE device */
64831 atomic_t simple_cmds;
64832 - atomic_t dev_ordered_id;
64833 + atomic_unchecked_t dev_ordered_id;
64834 atomic_t execute_tasks;
64835 atomic_t dev_ordered_sync;
64836 atomic_t dev_qf_count;
64837 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64838 new file mode 100644
64839 index 0000000..2efe49d
64840 --- /dev/null
64841 +++ b/include/trace/events/fs.h
64842 @@ -0,0 +1,53 @@
64843 +#undef TRACE_SYSTEM
64844 +#define TRACE_SYSTEM fs
64845 +
64846 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64847 +#define _TRACE_FS_H
64848 +
64849 +#include <linux/fs.h>
64850 +#include <linux/tracepoint.h>
64851 +
64852 +TRACE_EVENT(do_sys_open,
64853 +
64854 + TP_PROTO(char *filename, int flags, int mode),
64855 +
64856 + TP_ARGS(filename, flags, mode),
64857 +
64858 + TP_STRUCT__entry(
64859 + __string( filename, filename )
64860 + __field( int, flags )
64861 + __field( int, mode )
64862 + ),
64863 +
64864 + TP_fast_assign(
64865 + __assign_str(filename, filename);
64866 + __entry->flags = flags;
64867 + __entry->mode = mode;
64868 + ),
64869 +
64870 + TP_printk("\"%s\" %x %o",
64871 + __get_str(filename), __entry->flags, __entry->mode)
64872 +);
64873 +
64874 +TRACE_EVENT(open_exec,
64875 +
64876 + TP_PROTO(const char *filename),
64877 +
64878 + TP_ARGS(filename),
64879 +
64880 + TP_STRUCT__entry(
64881 + __string( filename, filename )
64882 + ),
64883 +
64884 + TP_fast_assign(
64885 + __assign_str(filename, filename);
64886 + ),
64887 +
64888 + TP_printk("\"%s\"",
64889 + __get_str(filename))
64890 +);
64891 +
64892 +#endif /* _TRACE_FS_H */
64893 +
64894 +/* This part must be outside protection */
64895 +#include <trace/define_trace.h>
64896 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64897 index 1c09820..7f5ec79 100644
64898 --- a/include/trace/events/irq.h
64899 +++ b/include/trace/events/irq.h
64900 @@ -36,7 +36,7 @@ struct softirq_action;
64901 */
64902 TRACE_EVENT(irq_handler_entry,
64903
64904 - TP_PROTO(int irq, struct irqaction *action),
64905 + TP_PROTO(int irq, const struct irqaction *action),
64906
64907 TP_ARGS(irq, action),
64908
64909 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64910 */
64911 TRACE_EVENT(irq_handler_exit,
64912
64913 - TP_PROTO(int irq, struct irqaction *action, int ret),
64914 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64915
64916 TP_ARGS(irq, action, ret),
64917
64918 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64919 index f9466fa..f4e2b81 100644
64920 --- a/include/video/udlfb.h
64921 +++ b/include/video/udlfb.h
64922 @@ -53,10 +53,10 @@ struct dlfb_data {
64923 u32 pseudo_palette[256];
64924 int blank_mode; /*one of FB_BLANK_ */
64925 /* blit-only rendering path metrics, exposed through sysfs */
64926 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64927 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64928 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64929 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64930 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64931 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64932 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64933 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64934 };
64935
64936 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64937 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64938 index 0993a22..32ba2fe 100644
64939 --- a/include/video/uvesafb.h
64940 +++ b/include/video/uvesafb.h
64941 @@ -177,6 +177,7 @@ struct uvesafb_par {
64942 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64943 u8 pmi_setpal; /* PMI for palette changes */
64944 u16 *pmi_base; /* protected mode interface location */
64945 + u8 *pmi_code; /* protected mode code location */
64946 void *pmi_start;
64947 void *pmi_pal;
64948 u8 *vbe_state_orig; /*
64949 diff --git a/init/Kconfig b/init/Kconfig
64950 index d07dcf9..fa47d0e 100644
64951 --- a/init/Kconfig
64952 +++ b/init/Kconfig
64953 @@ -835,6 +835,7 @@ endif # CGROUPS
64954
64955 config CHECKPOINT_RESTORE
64956 bool "Checkpoint/restore support" if EXPERT
64957 + depends on !GRKERNSEC
64958 default n
64959 help
64960 Enables additional kernel features in a sake of checkpoint/restore.
64961 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
64962 # Security modules
64963 depends on SECURITY_TOMOYO = n
64964 depends on SECURITY_APPARMOR = n
64965 + depends on GRKERNSEC = n
64966
64967 config UIDGID_STRICT_TYPE_CHECKS
64968 bool "Require conversions between uid/gids and their internal representation"
64969 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
64970
64971 config COMPAT_BRK
64972 bool "Disable heap randomization"
64973 - default y
64974 + default n
64975 help
64976 Randomizing heap placement makes heap exploits harder, but it
64977 also breaks ancient binaries (including anything libc5 based).
64978 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
64979 config STOP_MACHINE
64980 bool
64981 default y
64982 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
64983 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
64984 help
64985 Need stop_machine() primitive.
64986
64987 diff --git a/init/do_mounts.c b/init/do_mounts.c
64988 index d3f0aee..c9322f5 100644
64989 --- a/init/do_mounts.c
64990 +++ b/init/do_mounts.c
64991 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
64992 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64993 {
64994 struct super_block *s;
64995 - int err = sys_mount(name, "/root", fs, flags, data);
64996 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64997 if (err)
64998 return err;
64999
65000 - sys_chdir("/root");
65001 + sys_chdir((const char __force_user *)"/root");
65002 s = current->fs->pwd.dentry->d_sb;
65003 ROOT_DEV = s->s_dev;
65004 printk(KERN_INFO
65005 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65006 va_start(args, fmt);
65007 vsprintf(buf, fmt, args);
65008 va_end(args);
65009 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65010 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65011 if (fd >= 0) {
65012 sys_ioctl(fd, FDEJECT, 0);
65013 sys_close(fd);
65014 }
65015 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65016 - fd = sys_open("/dev/console", O_RDWR, 0);
65017 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65018 if (fd >= 0) {
65019 sys_ioctl(fd, TCGETS, (long)&termios);
65020 termios.c_lflag &= ~ICANON;
65021 sys_ioctl(fd, TCSETSF, (long)&termios);
65022 - sys_read(fd, &c, 1);
65023 + sys_read(fd, (char __user *)&c, 1);
65024 termios.c_lflag |= ICANON;
65025 sys_ioctl(fd, TCSETSF, (long)&termios);
65026 sys_close(fd);
65027 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65028 mount_root();
65029 out:
65030 devtmpfs_mount("dev");
65031 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65032 - sys_chroot(".");
65033 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65034 + sys_chroot((const char __force_user *)".");
65035 }
65036 diff --git a/init/do_mounts.h b/init/do_mounts.h
65037 index f5b978a..69dbfe8 100644
65038 --- a/init/do_mounts.h
65039 +++ b/init/do_mounts.h
65040 @@ -15,15 +15,15 @@ extern int root_mountflags;
65041
65042 static inline int create_dev(char *name, dev_t dev)
65043 {
65044 - sys_unlink(name);
65045 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65046 + sys_unlink((char __force_user *)name);
65047 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65048 }
65049
65050 #if BITS_PER_LONG == 32
65051 static inline u32 bstat(char *name)
65052 {
65053 struct stat64 stat;
65054 - if (sys_stat64(name, &stat) != 0)
65055 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65056 return 0;
65057 if (!S_ISBLK(stat.st_mode))
65058 return 0;
65059 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65060 static inline u32 bstat(char *name)
65061 {
65062 struct stat stat;
65063 - if (sys_newstat(name, &stat) != 0)
65064 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65065 return 0;
65066 if (!S_ISBLK(stat.st_mode))
65067 return 0;
65068 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65069 index 135959a2..28a3f43 100644
65070 --- a/init/do_mounts_initrd.c
65071 +++ b/init/do_mounts_initrd.c
65072 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65073 create_dev("/dev/root.old", Root_RAM0);
65074 /* mount initrd on rootfs' /root */
65075 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65076 - sys_mkdir("/old", 0700);
65077 - root_fd = sys_open("/", 0, 0);
65078 - old_fd = sys_open("/old", 0, 0);
65079 + sys_mkdir((const char __force_user *)"/old", 0700);
65080 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65081 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65082 /* move initrd over / and chdir/chroot in initrd root */
65083 - sys_chdir("/root");
65084 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65085 - sys_chroot(".");
65086 + sys_chdir((const char __force_user *)"/root");
65087 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65088 + sys_chroot((const char __force_user *)".");
65089
65090 /*
65091 * In case that a resume from disk is carried out by linuxrc or one of
65092 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65093
65094 /* move initrd to rootfs' /old */
65095 sys_fchdir(old_fd);
65096 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65097 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65098 /* switch root and cwd back to / of rootfs */
65099 sys_fchdir(root_fd);
65100 - sys_chroot(".");
65101 + sys_chroot((const char __force_user *)".");
65102 sys_close(old_fd);
65103 sys_close(root_fd);
65104
65105 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65106 - sys_chdir("/old");
65107 + sys_chdir((const char __force_user *)"/old");
65108 return;
65109 }
65110
65111 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65112 mount_root();
65113
65114 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65115 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65116 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65117 if (!error)
65118 printk("okay\n");
65119 else {
65120 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65121 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65122 if (error == -ENOENT)
65123 printk("/initrd does not exist. Ignored.\n");
65124 else
65125 printk("failed\n");
65126 printk(KERN_NOTICE "Unmounting old root\n");
65127 - sys_umount("/old", MNT_DETACH);
65128 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65129 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65130 if (fd < 0) {
65131 error = fd;
65132 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65133 * mounted in the normal path.
65134 */
65135 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65136 - sys_unlink("/initrd.image");
65137 + sys_unlink((const char __force_user *)"/initrd.image");
65138 handle_initrd();
65139 return 1;
65140 }
65141 }
65142 - sys_unlink("/initrd.image");
65143 + sys_unlink((const char __force_user *)"/initrd.image");
65144 return 0;
65145 }
65146 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65147 index 8cb6db5..d729f50 100644
65148 --- a/init/do_mounts_md.c
65149 +++ b/init/do_mounts_md.c
65150 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65151 partitioned ? "_d" : "", minor,
65152 md_setup_args[ent].device_names);
65153
65154 - fd = sys_open(name, 0, 0);
65155 + fd = sys_open((char __force_user *)name, 0, 0);
65156 if (fd < 0) {
65157 printk(KERN_ERR "md: open failed - cannot start "
65158 "array %s\n", name);
65159 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65160 * array without it
65161 */
65162 sys_close(fd);
65163 - fd = sys_open(name, 0, 0);
65164 + fd = sys_open((char __force_user *)name, 0, 0);
65165 sys_ioctl(fd, BLKRRPART, 0);
65166 }
65167 sys_close(fd);
65168 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65169
65170 wait_for_device_probe();
65171
65172 - fd = sys_open("/dev/md0", 0, 0);
65173 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65174 if (fd >= 0) {
65175 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65176 sys_close(fd);
65177 diff --git a/init/init_task.c b/init/init_task.c
65178 index 8b2f399..f0797c9 100644
65179 --- a/init/init_task.c
65180 +++ b/init/init_task.c
65181 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65182 * Initial thread structure. Alignment of this is handled by a special
65183 * linker map entry.
65184 */
65185 +#ifdef CONFIG_X86
65186 +union thread_union init_thread_union __init_task_data;
65187 +#else
65188 union thread_union init_thread_union __init_task_data =
65189 { INIT_THREAD_INFO(init_task) };
65190 +#endif
65191 diff --git a/init/initramfs.c b/init/initramfs.c
65192 index 84c6bf1..8899338 100644
65193 --- a/init/initramfs.c
65194 +++ b/init/initramfs.c
65195 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65196 }
65197 }
65198
65199 -static long __init do_utime(char *filename, time_t mtime)
65200 +static long __init do_utime(char __force_user *filename, time_t mtime)
65201 {
65202 struct timespec t[2];
65203
65204 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65205 struct dir_entry *de, *tmp;
65206 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65207 list_del(&de->list);
65208 - do_utime(de->name, de->mtime);
65209 + do_utime((char __force_user *)de->name, de->mtime);
65210 kfree(de->name);
65211 kfree(de);
65212 }
65213 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65214 if (nlink >= 2) {
65215 char *old = find_link(major, minor, ino, mode, collected);
65216 if (old)
65217 - return (sys_link(old, collected) < 0) ? -1 : 1;
65218 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65219 }
65220 return 0;
65221 }
65222 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65223 {
65224 struct stat st;
65225
65226 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65227 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65228 if (S_ISDIR(st.st_mode))
65229 - sys_rmdir(path);
65230 + sys_rmdir((char __force_user *)path);
65231 else
65232 - sys_unlink(path);
65233 + sys_unlink((char __force_user *)path);
65234 }
65235 }
65236
65237 @@ -315,7 +315,7 @@ static int __init do_name(void)
65238 int openflags = O_WRONLY|O_CREAT;
65239 if (ml != 1)
65240 openflags |= O_TRUNC;
65241 - wfd = sys_open(collected, openflags, mode);
65242 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65243
65244 if (wfd >= 0) {
65245 sys_fchown(wfd, uid, gid);
65246 @@ -327,17 +327,17 @@ static int __init do_name(void)
65247 }
65248 }
65249 } else if (S_ISDIR(mode)) {
65250 - sys_mkdir(collected, mode);
65251 - sys_chown(collected, uid, gid);
65252 - sys_chmod(collected, mode);
65253 + sys_mkdir((char __force_user *)collected, mode);
65254 + sys_chown((char __force_user *)collected, uid, gid);
65255 + sys_chmod((char __force_user *)collected, mode);
65256 dir_add(collected, mtime);
65257 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65258 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65259 if (maybe_link() == 0) {
65260 - sys_mknod(collected, mode, rdev);
65261 - sys_chown(collected, uid, gid);
65262 - sys_chmod(collected, mode);
65263 - do_utime(collected, mtime);
65264 + sys_mknod((char __force_user *)collected, mode, rdev);
65265 + sys_chown((char __force_user *)collected, uid, gid);
65266 + sys_chmod((char __force_user *)collected, mode);
65267 + do_utime((char __force_user *)collected, mtime);
65268 }
65269 }
65270 return 0;
65271 @@ -346,15 +346,15 @@ static int __init do_name(void)
65272 static int __init do_copy(void)
65273 {
65274 if (count >= body_len) {
65275 - sys_write(wfd, victim, body_len);
65276 + sys_write(wfd, (char __force_user *)victim, body_len);
65277 sys_close(wfd);
65278 - do_utime(vcollected, mtime);
65279 + do_utime((char __force_user *)vcollected, mtime);
65280 kfree(vcollected);
65281 eat(body_len);
65282 state = SkipIt;
65283 return 0;
65284 } else {
65285 - sys_write(wfd, victim, count);
65286 + sys_write(wfd, (char __force_user *)victim, count);
65287 body_len -= count;
65288 eat(count);
65289 return 1;
65290 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
65291 {
65292 collected[N_ALIGN(name_len) + body_len] = '\0';
65293 clean_path(collected, 0);
65294 - sys_symlink(collected + N_ALIGN(name_len), collected);
65295 - sys_lchown(collected, uid, gid);
65296 - do_utime(collected, mtime);
65297 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65298 + sys_lchown((char __force_user *)collected, uid, gid);
65299 + do_utime((char __force_user *)collected, mtime);
65300 state = SkipIt;
65301 next_state = Reset;
65302 return 0;
65303 diff --git a/init/main.c b/init/main.c
65304 index b5cc0a7..5605c91 100644
65305 --- a/init/main.c
65306 +++ b/init/main.c
65307 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65308 extern void tc_init(void);
65309 #endif
65310
65311 +extern void grsecurity_init(void);
65312 +
65313 /*
65314 * Debug helper: via this flag we know that we are in 'early bootup code'
65315 * where only the boot processor is running with IRQ disabled. This means
65316 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65317
65318 __setup("reset_devices", set_reset_devices);
65319
65320 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65321 +extern char pax_enter_kernel_user[];
65322 +extern char pax_exit_kernel_user[];
65323 +extern pgdval_t clone_pgd_mask;
65324 +#endif
65325 +
65326 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65327 +static int __init setup_pax_nouderef(char *str)
65328 +{
65329 +#ifdef CONFIG_X86_32
65330 + unsigned int cpu;
65331 + struct desc_struct *gdt;
65332 +
65333 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65334 + gdt = get_cpu_gdt_table(cpu);
65335 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65336 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65337 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65338 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65339 + }
65340 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65341 +#else
65342 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65343 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65344 + clone_pgd_mask = ~(pgdval_t)0UL;
65345 +#endif
65346 +
65347 + return 0;
65348 +}
65349 +early_param("pax_nouderef", setup_pax_nouderef);
65350 +#endif
65351 +
65352 +#ifdef CONFIG_PAX_SOFTMODE
65353 +int pax_softmode;
65354 +
65355 +static int __init setup_pax_softmode(char *str)
65356 +{
65357 + get_option(&str, &pax_softmode);
65358 + return 1;
65359 +}
65360 +__setup("pax_softmode=", setup_pax_softmode);
65361 +#endif
65362 +
65363 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65364 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65365 static const char *panic_later, *panic_param;
65366 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65367 {
65368 int count = preempt_count();
65369 int ret;
65370 + const char *msg1 = "", *msg2 = "";
65371
65372 if (initcall_debug)
65373 ret = do_one_initcall_debug(fn);
65374 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65375 sprintf(msgbuf, "error code %d ", ret);
65376
65377 if (preempt_count() != count) {
65378 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65379 + msg1 = " preemption imbalance";
65380 preempt_count() = count;
65381 }
65382 if (irqs_disabled()) {
65383 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65384 + msg2 = " disabled interrupts";
65385 local_irq_enable();
65386 }
65387 - if (msgbuf[0]) {
65388 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65389 + if (msgbuf[0] || *msg1 || *msg2) {
65390 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65391 }
65392
65393 return ret;
65394 @@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65395 level, level,
65396 &repair_env_string);
65397
65398 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65399 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65400 do_one_initcall(*fn);
65401 +
65402 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65403 + transfer_latent_entropy();
65404 +#endif
65405 +
65406 + }
65407 }
65408
65409 static void __init do_initcalls(void)
65410 @@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65411 {
65412 initcall_t *fn;
65413
65414 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
65415 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65416 do_one_initcall(*fn);
65417 +
65418 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65419 + transfer_latent_entropy();
65420 +#endif
65421 +
65422 + }
65423 }
65424
65425 static void run_init_process(const char *init_filename)
65426 @@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65427 do_basic_setup();
65428
65429 /* Open the /dev/console on the rootfs, this should never fail */
65430 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65431 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65432 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65433
65434 (void) sys_dup(0);
65435 @@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65436 if (!ramdisk_execute_command)
65437 ramdisk_execute_command = "/init";
65438
65439 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65440 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65441 ramdisk_execute_command = NULL;
65442 prepare_namespace();
65443 }
65444
65445 + grsecurity_init();
65446 +
65447 /*
65448 * Ok, we have completed the initial bootup, and
65449 * we're essentially up and running. Get rid of the
65450 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65451 index 8ce5769..4666884 100644
65452 --- a/ipc/mqueue.c
65453 +++ b/ipc/mqueue.c
65454 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65455 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65456 info->attr.mq_msgsize);
65457
65458 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65459 spin_lock(&mq_lock);
65460 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65461 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65462 diff --git a/ipc/msg.c b/ipc/msg.c
65463 index 7385de2..a8180e08 100644
65464 --- a/ipc/msg.c
65465 +++ b/ipc/msg.c
65466 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65467 return security_msg_queue_associate(msq, msgflg);
65468 }
65469
65470 +static struct ipc_ops msg_ops = {
65471 + .getnew = newque,
65472 + .associate = msg_security,
65473 + .more_checks = NULL
65474 +};
65475 +
65476 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65477 {
65478 struct ipc_namespace *ns;
65479 - struct ipc_ops msg_ops;
65480 struct ipc_params msg_params;
65481
65482 ns = current->nsproxy->ipc_ns;
65483
65484 - msg_ops.getnew = newque;
65485 - msg_ops.associate = msg_security;
65486 - msg_ops.more_checks = NULL;
65487 -
65488 msg_params.key = key;
65489 msg_params.flg = msgflg;
65490
65491 diff --git a/ipc/sem.c b/ipc/sem.c
65492 index 5215a81..cfc0cac 100644
65493 --- a/ipc/sem.c
65494 +++ b/ipc/sem.c
65495 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65496 return 0;
65497 }
65498
65499 +static struct ipc_ops sem_ops = {
65500 + .getnew = newary,
65501 + .associate = sem_security,
65502 + .more_checks = sem_more_checks
65503 +};
65504 +
65505 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65506 {
65507 struct ipc_namespace *ns;
65508 - struct ipc_ops sem_ops;
65509 struct ipc_params sem_params;
65510
65511 ns = current->nsproxy->ipc_ns;
65512 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65513 if (nsems < 0 || nsems > ns->sc_semmsl)
65514 return -EINVAL;
65515
65516 - sem_ops.getnew = newary;
65517 - sem_ops.associate = sem_security;
65518 - sem_ops.more_checks = sem_more_checks;
65519 -
65520 sem_params.key = key;
65521 sem_params.flg = semflg;
65522 sem_params.u.nsems = nsems;
65523 diff --git a/ipc/shm.c b/ipc/shm.c
65524 index 41c1285..cf6404c 100644
65525 --- a/ipc/shm.c
65526 +++ b/ipc/shm.c
65527 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65528 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65529 #endif
65530
65531 +#ifdef CONFIG_GRKERNSEC
65532 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65533 + const time_t shm_createtime, const uid_t cuid,
65534 + const int shmid);
65535 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65536 + const time_t shm_createtime);
65537 +#endif
65538 +
65539 void shm_init_ns(struct ipc_namespace *ns)
65540 {
65541 ns->shm_ctlmax = SHMMAX;
65542 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65543 shp->shm_lprid = 0;
65544 shp->shm_atim = shp->shm_dtim = 0;
65545 shp->shm_ctim = get_seconds();
65546 +#ifdef CONFIG_GRKERNSEC
65547 + {
65548 + struct timespec timeval;
65549 + do_posix_clock_monotonic_gettime(&timeval);
65550 +
65551 + shp->shm_createtime = timeval.tv_sec;
65552 + }
65553 +#endif
65554 shp->shm_segsz = size;
65555 shp->shm_nattch = 0;
65556 shp->shm_file = file;
65557 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65558 return 0;
65559 }
65560
65561 +static struct ipc_ops shm_ops = {
65562 + .getnew = newseg,
65563 + .associate = shm_security,
65564 + .more_checks = shm_more_checks
65565 +};
65566 +
65567 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65568 {
65569 struct ipc_namespace *ns;
65570 - struct ipc_ops shm_ops;
65571 struct ipc_params shm_params;
65572
65573 ns = current->nsproxy->ipc_ns;
65574
65575 - shm_ops.getnew = newseg;
65576 - shm_ops.associate = shm_security;
65577 - shm_ops.more_checks = shm_more_checks;
65578 -
65579 shm_params.key = key;
65580 shm_params.flg = shmflg;
65581 shm_params.u.size = size;
65582 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65583 f_mode = FMODE_READ | FMODE_WRITE;
65584 }
65585 if (shmflg & SHM_EXEC) {
65586 +
65587 +#ifdef CONFIG_PAX_MPROTECT
65588 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65589 + goto out;
65590 +#endif
65591 +
65592 prot |= PROT_EXEC;
65593 acc_mode |= S_IXUGO;
65594 }
65595 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65596 if (err)
65597 goto out_unlock;
65598
65599 +#ifdef CONFIG_GRKERNSEC
65600 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65601 + shp->shm_perm.cuid, shmid) ||
65602 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65603 + err = -EACCES;
65604 + goto out_unlock;
65605 + }
65606 +#endif
65607 +
65608 path = shp->shm_file->f_path;
65609 path_get(&path);
65610 shp->shm_nattch++;
65611 +#ifdef CONFIG_GRKERNSEC
65612 + shp->shm_lapid = current->pid;
65613 +#endif
65614 size = i_size_read(path.dentry->d_inode);
65615 shm_unlock(shp);
65616
65617 diff --git a/kernel/acct.c b/kernel/acct.c
65618 index 02e6167..54824f7 100644
65619 --- a/kernel/acct.c
65620 +++ b/kernel/acct.c
65621 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65622 */
65623 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65624 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65625 - file->f_op->write(file, (char *)&ac,
65626 + file->f_op->write(file, (char __force_user *)&ac,
65627 sizeof(acct_t), &file->f_pos);
65628 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65629 set_fs(fs);
65630 diff --git a/kernel/audit.c b/kernel/audit.c
65631 index 1c7f2c6..9ba5359 100644
65632 --- a/kernel/audit.c
65633 +++ b/kernel/audit.c
65634 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65635 3) suppressed due to audit_rate_limit
65636 4) suppressed due to audit_backlog_limit
65637 */
65638 -static atomic_t audit_lost = ATOMIC_INIT(0);
65639 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65640
65641 /* The netlink socket. */
65642 static struct sock *audit_sock;
65643 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65644 unsigned long now;
65645 int print;
65646
65647 - atomic_inc(&audit_lost);
65648 + atomic_inc_unchecked(&audit_lost);
65649
65650 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65651
65652 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65653 printk(KERN_WARNING
65654 "audit: audit_lost=%d audit_rate_limit=%d "
65655 "audit_backlog_limit=%d\n",
65656 - atomic_read(&audit_lost),
65657 + atomic_read_unchecked(&audit_lost),
65658 audit_rate_limit,
65659 audit_backlog_limit);
65660 audit_panic(message);
65661 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65662 status_set.pid = audit_pid;
65663 status_set.rate_limit = audit_rate_limit;
65664 status_set.backlog_limit = audit_backlog_limit;
65665 - status_set.lost = atomic_read(&audit_lost);
65666 + status_set.lost = atomic_read_unchecked(&audit_lost);
65667 status_set.backlog = skb_queue_len(&audit_skb_queue);
65668 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65669 &status_set, sizeof(status_set));
65670 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65671 index 4b96415..d8c16ee 100644
65672 --- a/kernel/auditsc.c
65673 +++ b/kernel/auditsc.c
65674 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65675 }
65676
65677 /* global counter which is incremented every time something logs in */
65678 -static atomic_t session_id = ATOMIC_INIT(0);
65679 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65680
65681 /**
65682 * audit_set_loginuid - set current task's audit_context loginuid
65683 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65684 return -EPERM;
65685 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65686
65687 - sessionid = atomic_inc_return(&session_id);
65688 + sessionid = atomic_inc_return_unchecked(&session_id);
65689 if (context && context->in_syscall) {
65690 struct audit_buffer *ab;
65691
65692 diff --git a/kernel/capability.c b/kernel/capability.c
65693 index 493d972..ea17248 100644
65694 --- a/kernel/capability.c
65695 +++ b/kernel/capability.c
65696 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65697 * before modification is attempted and the application
65698 * fails.
65699 */
65700 + if (tocopy > ARRAY_SIZE(kdata))
65701 + return -EFAULT;
65702 +
65703 if (copy_to_user(dataptr, kdata, tocopy
65704 * sizeof(struct __user_cap_data_struct))) {
65705 return -EFAULT;
65706 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65707 int ret;
65708
65709 rcu_read_lock();
65710 - ret = security_capable(__task_cred(t), ns, cap);
65711 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65712 + gr_task_is_capable(t, __task_cred(t), cap);
65713 rcu_read_unlock();
65714
65715 - return (ret == 0);
65716 + return ret;
65717 }
65718
65719 /**
65720 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65721 int ret;
65722
65723 rcu_read_lock();
65724 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65725 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65726 rcu_read_unlock();
65727
65728 - return (ret == 0);
65729 + return ret;
65730 }
65731
65732 /**
65733 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65734 BUG();
65735 }
65736
65737 - if (security_capable(current_cred(), ns, cap) == 0) {
65738 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65739 current->flags |= PF_SUPERPRIV;
65740 return true;
65741 }
65742 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65743 }
65744 EXPORT_SYMBOL(ns_capable);
65745
65746 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65747 +{
65748 + if (unlikely(!cap_valid(cap))) {
65749 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65750 + BUG();
65751 + }
65752 +
65753 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65754 + current->flags |= PF_SUPERPRIV;
65755 + return true;
65756 + }
65757 + return false;
65758 +}
65759 +EXPORT_SYMBOL(ns_capable_nolog);
65760 +
65761 /**
65762 * capable - Determine if the current task has a superior capability in effect
65763 * @cap: The capability to be tested for
65764 @@ -408,6 +427,12 @@ bool capable(int cap)
65765 }
65766 EXPORT_SYMBOL(capable);
65767
65768 +bool capable_nolog(int cap)
65769 +{
65770 + return ns_capable_nolog(&init_user_ns, cap);
65771 +}
65772 +EXPORT_SYMBOL(capable_nolog);
65773 +
65774 /**
65775 * nsown_capable - Check superior capability to one's own user_ns
65776 * @cap: The capability in question
65777 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65778
65779 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65780 }
65781 +
65782 +bool inode_capable_nolog(const struct inode *inode, int cap)
65783 +{
65784 + struct user_namespace *ns = current_user_ns();
65785 +
65786 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65787 +}
65788 diff --git a/kernel/compat.c b/kernel/compat.c
65789 index c28a306..b4d0cf3 100644
65790 --- a/kernel/compat.c
65791 +++ b/kernel/compat.c
65792 @@ -13,6 +13,7 @@
65793
65794 #include <linux/linkage.h>
65795 #include <linux/compat.h>
65796 +#include <linux/module.h>
65797 #include <linux/errno.h>
65798 #include <linux/time.h>
65799 #include <linux/signal.h>
65800 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65801 mm_segment_t oldfs;
65802 long ret;
65803
65804 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65805 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65806 oldfs = get_fs();
65807 set_fs(KERNEL_DS);
65808 ret = hrtimer_nanosleep_restart(restart);
65809 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65810 oldfs = get_fs();
65811 set_fs(KERNEL_DS);
65812 ret = hrtimer_nanosleep(&tu,
65813 - rmtp ? (struct timespec __user *)&rmt : NULL,
65814 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65815 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65816 set_fs(oldfs);
65817
65818 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65819 mm_segment_t old_fs = get_fs();
65820
65821 set_fs(KERNEL_DS);
65822 - ret = sys_sigpending((old_sigset_t __user *) &s);
65823 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65824 set_fs(old_fs);
65825 if (ret == 0)
65826 ret = put_user(s, set);
65827 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65828 mm_segment_t old_fs = get_fs();
65829
65830 set_fs(KERNEL_DS);
65831 - ret = sys_old_getrlimit(resource, &r);
65832 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65833 set_fs(old_fs);
65834
65835 if (!ret) {
65836 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65837 mm_segment_t old_fs = get_fs();
65838
65839 set_fs(KERNEL_DS);
65840 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65841 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65842 set_fs(old_fs);
65843
65844 if (ret)
65845 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65846 set_fs (KERNEL_DS);
65847 ret = sys_wait4(pid,
65848 (stat_addr ?
65849 - (unsigned int __user *) &status : NULL),
65850 - options, (struct rusage __user *) &r);
65851 + (unsigned int __force_user *) &status : NULL),
65852 + options, (struct rusage __force_user *) &r);
65853 set_fs (old_fs);
65854
65855 if (ret > 0) {
65856 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65857 memset(&info, 0, sizeof(info));
65858
65859 set_fs(KERNEL_DS);
65860 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65861 - uru ? (struct rusage __user *)&ru : NULL);
65862 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65863 + uru ? (struct rusage __force_user *)&ru : NULL);
65864 set_fs(old_fs);
65865
65866 if ((ret < 0) || (info.si_signo == 0))
65867 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65868 oldfs = get_fs();
65869 set_fs(KERNEL_DS);
65870 err = sys_timer_settime(timer_id, flags,
65871 - (struct itimerspec __user *) &newts,
65872 - (struct itimerspec __user *) &oldts);
65873 + (struct itimerspec __force_user *) &newts,
65874 + (struct itimerspec __force_user *) &oldts);
65875 set_fs(oldfs);
65876 if (!err && old && put_compat_itimerspec(old, &oldts))
65877 return -EFAULT;
65878 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65879 oldfs = get_fs();
65880 set_fs(KERNEL_DS);
65881 err = sys_timer_gettime(timer_id,
65882 - (struct itimerspec __user *) &ts);
65883 + (struct itimerspec __force_user *) &ts);
65884 set_fs(oldfs);
65885 if (!err && put_compat_itimerspec(setting, &ts))
65886 return -EFAULT;
65887 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65888 oldfs = get_fs();
65889 set_fs(KERNEL_DS);
65890 err = sys_clock_settime(which_clock,
65891 - (struct timespec __user *) &ts);
65892 + (struct timespec __force_user *) &ts);
65893 set_fs(oldfs);
65894 return err;
65895 }
65896 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65897 oldfs = get_fs();
65898 set_fs(KERNEL_DS);
65899 err = sys_clock_gettime(which_clock,
65900 - (struct timespec __user *) &ts);
65901 + (struct timespec __force_user *) &ts);
65902 set_fs(oldfs);
65903 if (!err && put_compat_timespec(&ts, tp))
65904 return -EFAULT;
65905 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65906
65907 oldfs = get_fs();
65908 set_fs(KERNEL_DS);
65909 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65910 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65911 set_fs(oldfs);
65912
65913 err = compat_put_timex(utp, &txc);
65914 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65915 oldfs = get_fs();
65916 set_fs(KERNEL_DS);
65917 err = sys_clock_getres(which_clock,
65918 - (struct timespec __user *) &ts);
65919 + (struct timespec __force_user *) &ts);
65920 set_fs(oldfs);
65921 if (!err && tp && put_compat_timespec(&ts, tp))
65922 return -EFAULT;
65923 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65924 long err;
65925 mm_segment_t oldfs;
65926 struct timespec tu;
65927 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65928 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65929
65930 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65931 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65932 oldfs = get_fs();
65933 set_fs(KERNEL_DS);
65934 err = clock_nanosleep_restart(restart);
65935 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65936 oldfs = get_fs();
65937 set_fs(KERNEL_DS);
65938 err = sys_clock_nanosleep(which_clock, flags,
65939 - (struct timespec __user *) &in,
65940 - (struct timespec __user *) &out);
65941 + (struct timespec __force_user *) &in,
65942 + (struct timespec __force_user *) &out);
65943 set_fs(oldfs);
65944
65945 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65946 diff --git a/kernel/configs.c b/kernel/configs.c
65947 index 42e8fa0..9e7406b 100644
65948 --- a/kernel/configs.c
65949 +++ b/kernel/configs.c
65950 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65951 struct proc_dir_entry *entry;
65952
65953 /* create the current config file */
65954 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65955 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65956 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65957 + &ikconfig_file_ops);
65958 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65959 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65960 + &ikconfig_file_ops);
65961 +#endif
65962 +#else
65963 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65964 &ikconfig_file_ops);
65965 +#endif
65966 +
65967 if (!entry)
65968 return -ENOMEM;
65969
65970 diff --git a/kernel/cred.c b/kernel/cred.c
65971 index de728ac..e3c267c 100644
65972 --- a/kernel/cred.c
65973 +++ b/kernel/cred.c
65974 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
65975 validate_creds(cred);
65976 alter_cred_subscribers(cred, -1);
65977 put_cred(cred);
65978 +
65979 +#ifdef CONFIG_GRKERNSEC_SETXID
65980 + cred = (struct cred *) tsk->delayed_cred;
65981 + if (cred != NULL) {
65982 + tsk->delayed_cred = NULL;
65983 + validate_creds(cred);
65984 + alter_cred_subscribers(cred, -1);
65985 + put_cred(cred);
65986 + }
65987 +#endif
65988 }
65989
65990 /**
65991 @@ -469,7 +479,7 @@ error_put:
65992 * Always returns 0 thus allowing this function to be tail-called at the end
65993 * of, say, sys_setgid().
65994 */
65995 -int commit_creds(struct cred *new)
65996 +static int __commit_creds(struct cred *new)
65997 {
65998 struct task_struct *task = current;
65999 const struct cred *old = task->real_cred;
66000 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66001
66002 get_cred(new); /* we will require a ref for the subj creds too */
66003
66004 + gr_set_role_label(task, new->uid, new->gid);
66005 +
66006 /* dumpability changes */
66007 if (!uid_eq(old->euid, new->euid) ||
66008 !gid_eq(old->egid, new->egid) ||
66009 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66010 put_cred(old);
66011 return 0;
66012 }
66013 +#ifdef CONFIG_GRKERNSEC_SETXID
66014 +extern int set_user(struct cred *new);
66015 +
66016 +void gr_delayed_cred_worker(void)
66017 +{
66018 + const struct cred *new = current->delayed_cred;
66019 + struct cred *ncred;
66020 +
66021 + current->delayed_cred = NULL;
66022 +
66023 + if (current_uid() && new != NULL) {
66024 + // from doing get_cred on it when queueing this
66025 + put_cred(new);
66026 + return;
66027 + } else if (new == NULL)
66028 + return;
66029 +
66030 + ncred = prepare_creds();
66031 + if (!ncred)
66032 + goto die;
66033 + // uids
66034 + ncred->uid = new->uid;
66035 + ncred->euid = new->euid;
66036 + ncred->suid = new->suid;
66037 + ncred->fsuid = new->fsuid;
66038 + // gids
66039 + ncred->gid = new->gid;
66040 + ncred->egid = new->egid;
66041 + ncred->sgid = new->sgid;
66042 + ncred->fsgid = new->fsgid;
66043 + // groups
66044 + if (set_groups(ncred, new->group_info) < 0) {
66045 + abort_creds(ncred);
66046 + goto die;
66047 + }
66048 + // caps
66049 + ncred->securebits = new->securebits;
66050 + ncred->cap_inheritable = new->cap_inheritable;
66051 + ncred->cap_permitted = new->cap_permitted;
66052 + ncred->cap_effective = new->cap_effective;
66053 + ncred->cap_bset = new->cap_bset;
66054 +
66055 + if (set_user(ncred)) {
66056 + abort_creds(ncred);
66057 + goto die;
66058 + }
66059 +
66060 + // from doing get_cred on it when queueing this
66061 + put_cred(new);
66062 +
66063 + __commit_creds(ncred);
66064 + return;
66065 +die:
66066 + // from doing get_cred on it when queueing this
66067 + put_cred(new);
66068 + do_group_exit(SIGKILL);
66069 +}
66070 +#endif
66071 +
66072 +int commit_creds(struct cred *new)
66073 +{
66074 +#ifdef CONFIG_GRKERNSEC_SETXID
66075 + int ret;
66076 + int schedule_it = 0;
66077 + struct task_struct *t;
66078 +
66079 + /* we won't get called with tasklist_lock held for writing
66080 + and interrupts disabled as the cred struct in that case is
66081 + init_cred
66082 + */
66083 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66084 + !current_uid() && new->uid) {
66085 + schedule_it = 1;
66086 + }
66087 + ret = __commit_creds(new);
66088 + if (schedule_it) {
66089 + rcu_read_lock();
66090 + read_lock(&tasklist_lock);
66091 + for (t = next_thread(current); t != current;
66092 + t = next_thread(t)) {
66093 + if (t->delayed_cred == NULL) {
66094 + t->delayed_cred = get_cred(new);
66095 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66096 + set_tsk_need_resched(t);
66097 + }
66098 + }
66099 + read_unlock(&tasklist_lock);
66100 + rcu_read_unlock();
66101 + }
66102 + return ret;
66103 +#else
66104 + return __commit_creds(new);
66105 +#endif
66106 +}
66107 +
66108 EXPORT_SYMBOL(commit_creds);
66109
66110 /**
66111 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66112 index 0557f24..1a00d9a 100644
66113 --- a/kernel/debug/debug_core.c
66114 +++ b/kernel/debug/debug_core.c
66115 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66116 */
66117 static atomic_t masters_in_kgdb;
66118 static atomic_t slaves_in_kgdb;
66119 -static atomic_t kgdb_break_tasklet_var;
66120 +static atomic_unchecked_t kgdb_break_tasklet_var;
66121 atomic_t kgdb_setting_breakpoint;
66122
66123 struct task_struct *kgdb_usethread;
66124 @@ -132,7 +132,7 @@ int kgdb_single_step;
66125 static pid_t kgdb_sstep_pid;
66126
66127 /* to keep track of the CPU which is doing the single stepping*/
66128 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66129 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66130
66131 /*
66132 * If you are debugging a problem where roundup (the collection of
66133 @@ -540,7 +540,7 @@ return_normal:
66134 * kernel will only try for the value of sstep_tries before
66135 * giving up and continuing on.
66136 */
66137 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66138 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66139 (kgdb_info[cpu].task &&
66140 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66141 atomic_set(&kgdb_active, -1);
66142 @@ -634,8 +634,8 @@ cpu_master_loop:
66143 }
66144
66145 kgdb_restore:
66146 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66147 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66148 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66149 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66150 if (kgdb_info[sstep_cpu].task)
66151 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66152 else
66153 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66154 static void kgdb_tasklet_bpt(unsigned long ing)
66155 {
66156 kgdb_breakpoint();
66157 - atomic_set(&kgdb_break_tasklet_var, 0);
66158 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66159 }
66160
66161 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66162
66163 void kgdb_schedule_breakpoint(void)
66164 {
66165 - if (atomic_read(&kgdb_break_tasklet_var) ||
66166 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66167 atomic_read(&kgdb_active) != -1 ||
66168 atomic_read(&kgdb_setting_breakpoint))
66169 return;
66170 - atomic_inc(&kgdb_break_tasklet_var);
66171 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66172 tasklet_schedule(&kgdb_tasklet_breakpoint);
66173 }
66174 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66175 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66176 index 1f91413..362a0a1 100644
66177 --- a/kernel/debug/kdb/kdb_main.c
66178 +++ b/kernel/debug/kdb/kdb_main.c
66179 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66180 list_for_each_entry(mod, kdb_modules, list) {
66181
66182 kdb_printf("%-20s%8u 0x%p ", mod->name,
66183 - mod->core_size, (void *)mod);
66184 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66185 #ifdef CONFIG_MODULE_UNLOAD
66186 kdb_printf("%4ld ", module_refcount(mod));
66187 #endif
66188 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66189 kdb_printf(" (Loading)");
66190 else
66191 kdb_printf(" (Live)");
66192 - kdb_printf(" 0x%p", mod->module_core);
66193 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66194
66195 #ifdef CONFIG_MODULE_UNLOAD
66196 {
66197 diff --git a/kernel/events/core.c b/kernel/events/core.c
66198 index d7d71d6..f54b76f 100644
66199 --- a/kernel/events/core.c
66200 +++ b/kernel/events/core.c
66201 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66202 return 0;
66203 }
66204
66205 -static atomic64_t perf_event_id;
66206 +static atomic64_unchecked_t perf_event_id;
66207
66208 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66209 enum event_type_t event_type);
66210 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66211
66212 static inline u64 perf_event_count(struct perf_event *event)
66213 {
66214 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66215 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66216 }
66217
66218 static u64 perf_event_read(struct perf_event *event)
66219 @@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66220 mutex_lock(&event->child_mutex);
66221 total += perf_event_read(event);
66222 *enabled += event->total_time_enabled +
66223 - atomic64_read(&event->child_total_time_enabled);
66224 + atomic64_read_unchecked(&event->child_total_time_enabled);
66225 *running += event->total_time_running +
66226 - atomic64_read(&event->child_total_time_running);
66227 + atomic64_read_unchecked(&event->child_total_time_running);
66228
66229 list_for_each_entry(child, &event->child_list, child_list) {
66230 total += perf_event_read(child);
66231 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66232 userpg->offset -= local64_read(&event->hw.prev_count);
66233
66234 userpg->time_enabled = enabled +
66235 - atomic64_read(&event->child_total_time_enabled);
66236 + atomic64_read_unchecked(&event->child_total_time_enabled);
66237
66238 userpg->time_running = running +
66239 - atomic64_read(&event->child_total_time_running);
66240 + atomic64_read_unchecked(&event->child_total_time_running);
66241
66242 arch_perf_update_userpage(userpg, now);
66243
66244 @@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66245 values[n++] = perf_event_count(event);
66246 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66247 values[n++] = enabled +
66248 - atomic64_read(&event->child_total_time_enabled);
66249 + atomic64_read_unchecked(&event->child_total_time_enabled);
66250 }
66251 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66252 values[n++] = running +
66253 - atomic64_read(&event->child_total_time_running);
66254 + atomic64_read_unchecked(&event->child_total_time_running);
66255 }
66256 if (read_format & PERF_FORMAT_ID)
66257 values[n++] = primary_event_id(event);
66258 @@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66259 * need to add enough zero bytes after the string to handle
66260 * the 64bit alignment we do later.
66261 */
66262 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66263 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66264 if (!buf) {
66265 name = strncpy(tmp, "//enomem", sizeof(tmp));
66266 goto got_name;
66267 }
66268 - name = d_path(&file->f_path, buf, PATH_MAX);
66269 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66270 if (IS_ERR(name)) {
66271 name = strncpy(tmp, "//toolong", sizeof(tmp));
66272 goto got_name;
66273 @@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66274 event->parent = parent_event;
66275
66276 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66277 - event->id = atomic64_inc_return(&perf_event_id);
66278 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66279
66280 event->state = PERF_EVENT_STATE_INACTIVE;
66281
66282 @@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66283 /*
66284 * Add back the child's count to the parent's count:
66285 */
66286 - atomic64_add(child_val, &parent_event->child_count);
66287 - atomic64_add(child_event->total_time_enabled,
66288 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66289 + atomic64_add_unchecked(child_event->total_time_enabled,
66290 &parent_event->child_total_time_enabled);
66291 - atomic64_add(child_event->total_time_running,
66292 + atomic64_add_unchecked(child_event->total_time_running,
66293 &parent_event->child_total_time_running);
66294
66295 /*
66296 diff --git a/kernel/exit.c b/kernel/exit.c
66297 index 2f59cc3..ce5b167 100644
66298 --- a/kernel/exit.c
66299 +++ b/kernel/exit.c
66300 @@ -59,6 +59,10 @@
66301 #include <asm/pgtable.h>
66302 #include <asm/mmu_context.h>
66303
66304 +#ifdef CONFIG_GRKERNSEC
66305 +extern rwlock_t grsec_exec_file_lock;
66306 +#endif
66307 +
66308 static void exit_mm(struct task_struct * tsk);
66309
66310 static void __unhash_process(struct task_struct *p, bool group_dead)
66311 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66312 struct task_struct *leader;
66313 int zap_leader;
66314 repeat:
66315 +#ifdef CONFIG_NET
66316 + gr_del_task_from_ip_table(p);
66317 +#endif
66318 +
66319 /* don't need to get the RCU readlock here - the process is dead and
66320 * can't be modifying its own credentials. But shut RCU-lockdep up */
66321 rcu_read_lock();
66322 @@ -394,7 +402,7 @@ int allow_signal(int sig)
66323 * know it'll be handled, so that they don't get converted to
66324 * SIGKILL or just silently dropped.
66325 */
66326 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66327 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66328 recalc_sigpending();
66329 spin_unlock_irq(&current->sighand->siglock);
66330 return 0;
66331 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66332 vsnprintf(current->comm, sizeof(current->comm), name, args);
66333 va_end(args);
66334
66335 +#ifdef CONFIG_GRKERNSEC
66336 + write_lock(&grsec_exec_file_lock);
66337 + if (current->exec_file) {
66338 + fput(current->exec_file);
66339 + current->exec_file = NULL;
66340 + }
66341 + write_unlock(&grsec_exec_file_lock);
66342 +#endif
66343 +
66344 + gr_set_kernel_label(current);
66345 +
66346 /*
66347 * If we were started as result of loading a module, close all of the
66348 * user space pages. We don't need them, and if we didn't close them
66349 @@ -907,6 +926,8 @@ void do_exit(long code)
66350 struct task_struct *tsk = current;
66351 int group_dead;
66352
66353 + set_fs(USER_DS);
66354 +
66355 profile_task_exit(tsk);
66356
66357 WARN_ON(blk_needs_flush_plug(tsk));
66358 @@ -923,7 +944,6 @@ void do_exit(long code)
66359 * mm_release()->clear_child_tid() from writing to a user-controlled
66360 * kernel address.
66361 */
66362 - set_fs(USER_DS);
66363
66364 ptrace_event(PTRACE_EVENT_EXIT, code);
66365
66366 @@ -985,6 +1005,9 @@ void do_exit(long code)
66367 tsk->exit_code = code;
66368 taskstats_exit(tsk, group_dead);
66369
66370 + gr_acl_handle_psacct(tsk, code);
66371 + gr_acl_handle_exit();
66372 +
66373 exit_mm(tsk);
66374
66375 if (group_dead)
66376 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66377 * Take down every thread in the group. This is called by fatal signals
66378 * as well as by sys_exit_group (below).
66379 */
66380 -void
66381 +__noreturn void
66382 do_group_exit(int exit_code)
66383 {
66384 struct signal_struct *sig = current->signal;
66385 diff --git a/kernel/fork.c b/kernel/fork.c
66386 index f00e319..c212fbc 100644
66387 --- a/kernel/fork.c
66388 +++ b/kernel/fork.c
66389 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66390 *stackend = STACK_END_MAGIC; /* for overflow detection */
66391
66392 #ifdef CONFIG_CC_STACKPROTECTOR
66393 - tsk->stack_canary = get_random_int();
66394 + tsk->stack_canary = pax_get_random_long();
66395 #endif
66396
66397 /*
66398 @@ -345,13 +345,78 @@ out:
66399 }
66400
66401 #ifdef CONFIG_MMU
66402 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66403 +{
66404 + struct vm_area_struct *tmp;
66405 + unsigned long charge;
66406 + struct mempolicy *pol;
66407 + struct file *file;
66408 +
66409 + charge = 0;
66410 + if (mpnt->vm_flags & VM_ACCOUNT) {
66411 + unsigned long len;
66412 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66413 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66414 + goto fail_nomem;
66415 + charge = len;
66416 + }
66417 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66418 + if (!tmp)
66419 + goto fail_nomem;
66420 + *tmp = *mpnt;
66421 + tmp->vm_mm = mm;
66422 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66423 + pol = mpol_dup(vma_policy(mpnt));
66424 + if (IS_ERR(pol))
66425 + goto fail_nomem_policy;
66426 + vma_set_policy(tmp, pol);
66427 + if (anon_vma_fork(tmp, mpnt))
66428 + goto fail_nomem_anon_vma_fork;
66429 + tmp->vm_flags &= ~VM_LOCKED;
66430 + tmp->vm_next = tmp->vm_prev = NULL;
66431 + tmp->vm_mirror = NULL;
66432 + file = tmp->vm_file;
66433 + if (file) {
66434 + struct inode *inode = file->f_path.dentry->d_inode;
66435 + struct address_space *mapping = file->f_mapping;
66436 +
66437 + get_file(file);
66438 + if (tmp->vm_flags & VM_DENYWRITE)
66439 + atomic_dec(&inode->i_writecount);
66440 + mutex_lock(&mapping->i_mmap_mutex);
66441 + if (tmp->vm_flags & VM_SHARED)
66442 + mapping->i_mmap_writable++;
66443 + flush_dcache_mmap_lock(mapping);
66444 + /* insert tmp into the share list, just after mpnt */
66445 + vma_prio_tree_add(tmp, mpnt);
66446 + flush_dcache_mmap_unlock(mapping);
66447 + mutex_unlock(&mapping->i_mmap_mutex);
66448 + }
66449 +
66450 + /*
66451 + * Clear hugetlb-related page reserves for children. This only
66452 + * affects MAP_PRIVATE mappings. Faults generated by the child
66453 + * are not guaranteed to succeed, even if read-only
66454 + */
66455 + if (is_vm_hugetlb_page(tmp))
66456 + reset_vma_resv_huge_pages(tmp);
66457 +
66458 + return tmp;
66459 +
66460 +fail_nomem_anon_vma_fork:
66461 + mpol_put(pol);
66462 +fail_nomem_policy:
66463 + kmem_cache_free(vm_area_cachep, tmp);
66464 +fail_nomem:
66465 + vm_unacct_memory(charge);
66466 + return NULL;
66467 +}
66468 +
66469 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66470 {
66471 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66472 struct rb_node **rb_link, *rb_parent;
66473 int retval;
66474 - unsigned long charge;
66475 - struct mempolicy *pol;
66476
66477 down_write(&oldmm->mmap_sem);
66478 flush_cache_dup_mm(oldmm);
66479 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66480 mm->locked_vm = 0;
66481 mm->mmap = NULL;
66482 mm->mmap_cache = NULL;
66483 - mm->free_area_cache = oldmm->mmap_base;
66484 - mm->cached_hole_size = ~0UL;
66485 + mm->free_area_cache = oldmm->free_area_cache;
66486 + mm->cached_hole_size = oldmm->cached_hole_size;
66487 mm->map_count = 0;
66488 cpumask_clear(mm_cpumask(mm));
66489 mm->mm_rb = RB_ROOT;
66490 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66491
66492 prev = NULL;
66493 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66494 - struct file *file;
66495 -
66496 if (mpnt->vm_flags & VM_DONTCOPY) {
66497 long pages = vma_pages(mpnt);
66498 mm->total_vm -= pages;
66499 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66500 -pages);
66501 continue;
66502 }
66503 - charge = 0;
66504 - if (mpnt->vm_flags & VM_ACCOUNT) {
66505 - unsigned long len;
66506 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66507 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66508 - goto fail_nomem;
66509 - charge = len;
66510 + tmp = dup_vma(mm, oldmm, mpnt);
66511 + if (!tmp) {
66512 + retval = -ENOMEM;
66513 + goto out;
66514 }
66515 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66516 - if (!tmp)
66517 - goto fail_nomem;
66518 - *tmp = *mpnt;
66519 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66520 - pol = mpol_dup(vma_policy(mpnt));
66521 - retval = PTR_ERR(pol);
66522 - if (IS_ERR(pol))
66523 - goto fail_nomem_policy;
66524 - vma_set_policy(tmp, pol);
66525 - tmp->vm_mm = mm;
66526 - if (anon_vma_fork(tmp, mpnt))
66527 - goto fail_nomem_anon_vma_fork;
66528 - tmp->vm_flags &= ~VM_LOCKED;
66529 - tmp->vm_next = tmp->vm_prev = NULL;
66530 - file = tmp->vm_file;
66531 - if (file) {
66532 - struct inode *inode = file->f_path.dentry->d_inode;
66533 - struct address_space *mapping = file->f_mapping;
66534 -
66535 - get_file(file);
66536 - if (tmp->vm_flags & VM_DENYWRITE)
66537 - atomic_dec(&inode->i_writecount);
66538 - mutex_lock(&mapping->i_mmap_mutex);
66539 - if (tmp->vm_flags & VM_SHARED)
66540 - mapping->i_mmap_writable++;
66541 - flush_dcache_mmap_lock(mapping);
66542 - /* insert tmp into the share list, just after mpnt */
66543 - vma_prio_tree_add(tmp, mpnt);
66544 - flush_dcache_mmap_unlock(mapping);
66545 - mutex_unlock(&mapping->i_mmap_mutex);
66546 - }
66547 -
66548 - /*
66549 - * Clear hugetlb-related page reserves for children. This only
66550 - * affects MAP_PRIVATE mappings. Faults generated by the child
66551 - * are not guaranteed to succeed, even if read-only
66552 - */
66553 - if (is_vm_hugetlb_page(tmp))
66554 - reset_vma_resv_huge_pages(tmp);
66555
66556 /*
66557 * Link in the new vma and copy the page table entries.
66558 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66559 if (retval)
66560 goto out;
66561
66562 - if (file && uprobe_mmap(tmp))
66563 + if (tmp->vm_file && uprobe_mmap(tmp))
66564 goto out;
66565 }
66566 +
66567 +#ifdef CONFIG_PAX_SEGMEXEC
66568 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66569 + struct vm_area_struct *mpnt_m;
66570 +
66571 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66572 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66573 +
66574 + if (!mpnt->vm_mirror)
66575 + continue;
66576 +
66577 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66578 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66579 + mpnt->vm_mirror = mpnt_m;
66580 + } else {
66581 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66582 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66583 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66584 + mpnt->vm_mirror->vm_mirror = mpnt;
66585 + }
66586 + }
66587 + BUG_ON(mpnt_m);
66588 + }
66589 +#endif
66590 +
66591 /* a new mm has just been created */
66592 arch_dup_mmap(oldmm, mm);
66593 retval = 0;
66594 @@ -470,14 +515,6 @@ out:
66595 flush_tlb_mm(oldmm);
66596 up_write(&oldmm->mmap_sem);
66597 return retval;
66598 -fail_nomem_anon_vma_fork:
66599 - mpol_put(pol);
66600 -fail_nomem_policy:
66601 - kmem_cache_free(vm_area_cachep, tmp);
66602 -fail_nomem:
66603 - retval = -ENOMEM;
66604 - vm_unacct_memory(charge);
66605 - goto out;
66606 }
66607
66608 static inline int mm_alloc_pgd(struct mm_struct *mm)
66609 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66610 return ERR_PTR(err);
66611
66612 mm = get_task_mm(task);
66613 - if (mm && mm != current->mm &&
66614 - !ptrace_may_access(task, mode)) {
66615 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66616 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66617 mmput(mm);
66618 mm = ERR_PTR(-EACCES);
66619 }
66620 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66621 spin_unlock(&fs->lock);
66622 return -EAGAIN;
66623 }
66624 - fs->users++;
66625 + atomic_inc(&fs->users);
66626 spin_unlock(&fs->lock);
66627 return 0;
66628 }
66629 tsk->fs = copy_fs_struct(fs);
66630 if (!tsk->fs)
66631 return -ENOMEM;
66632 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66633 return 0;
66634 }
66635
66636 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66637 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66638 #endif
66639 retval = -EAGAIN;
66640 +
66641 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66642 +
66643 if (atomic_read(&p->real_cred->user->processes) >=
66644 task_rlimit(p, RLIMIT_NPROC)) {
66645 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66646 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66647 /* Need tasklist lock for parent etc handling! */
66648 write_lock_irq(&tasklist_lock);
66649
66650 + /* synchronizes with gr_set_acls() */
66651 + gr_copy_label(p);
66652 +
66653 /* CLONE_PARENT re-uses the old parent */
66654 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66655 p->real_parent = current->real_parent;
66656 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66657 bad_fork_free:
66658 free_task(p);
66659 fork_out:
66660 + gr_log_forkfail(retval);
66661 +
66662 return ERR_PTR(retval);
66663 }
66664
66665 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66666 if (clone_flags & CLONE_PARENT_SETTID)
66667 put_user(nr, parent_tidptr);
66668
66669 + gr_handle_brute_check();
66670 +
66671 if (clone_flags & CLONE_VFORK) {
66672 p->vfork_done = &vfork;
66673 init_completion(&vfork);
66674 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66675 return 0;
66676
66677 /* don't need lock here; in the worst case we'll do useless copy */
66678 - if (fs->users == 1)
66679 + if (atomic_read(&fs->users) == 1)
66680 return 0;
66681
66682 *new_fsp = copy_fs_struct(fs);
66683 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66684 fs = current->fs;
66685 spin_lock(&fs->lock);
66686 current->fs = new_fs;
66687 - if (--fs->users)
66688 + gr_set_chroot_entries(current, &current->fs->root);
66689 + if (atomic_dec_return(&fs->users))
66690 new_fs = NULL;
66691 else
66692 new_fs = fs;
66693 diff --git a/kernel/futex.c b/kernel/futex.c
66694 index e2b0fb9..ced552c 100644
66695 --- a/kernel/futex.c
66696 +++ b/kernel/futex.c
66697 @@ -54,6 +54,7 @@
66698 #include <linux/mount.h>
66699 #include <linux/pagemap.h>
66700 #include <linux/syscalls.h>
66701 +#include <linux/ptrace.h>
66702 #include <linux/signal.h>
66703 #include <linux/export.h>
66704 #include <linux/magic.h>
66705 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66706 struct page *page, *page_head;
66707 int err, ro = 0;
66708
66709 +#ifdef CONFIG_PAX_SEGMEXEC
66710 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66711 + return -EFAULT;
66712 +#endif
66713 +
66714 /*
66715 * The futex address must be "naturally" aligned.
66716 */
66717 @@ -2231,11 +2237,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
66718 * @uaddr2: the pi futex we will take prior to returning to user-space
66719 *
66720 * The caller will wait on uaddr and will be requeued by futex_requeue() to
66721 - * uaddr2 which must be PI aware. Normal wakeup will wake on uaddr2 and
66722 - * complete the acquisition of the rt_mutex prior to returning to userspace.
66723 - * This ensures the rt_mutex maintains an owner when it has waiters; without
66724 - * one, the pi logic wouldn't know which task to boost/deboost, if there was a
66725 - * need to.
66726 + * uaddr2 which must be PI aware and unique from uaddr. Normal wakeup will wake
66727 + * on uaddr2 and complete the acquisition of the rt_mutex prior to returning to
66728 + * userspace. This ensures the rt_mutex maintains an owner when it has waiters;
66729 + * without one, the pi logic would not know which task to boost/deboost, if
66730 + * there was a need to.
66731 *
66732 * We call schedule in futex_wait_queue_me() when we enqueue and return there
66733 * via the following:
66734 @@ -2272,6 +2278,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66735 struct futex_q q = futex_q_init;
66736 int res, ret;
66737
66738 + if (uaddr == uaddr2)
66739 + return -EINVAL;
66740 +
66741 if (!bitset)
66742 return -EINVAL;
66743
66744 @@ -2370,7 +2379,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66745 * fault, unlock the rt_mutex and return the fault to userspace.
66746 */
66747 if (ret == -EFAULT) {
66748 - if (rt_mutex_owner(pi_mutex) == current)
66749 + if (pi_mutex && rt_mutex_owner(pi_mutex) == current)
66750 rt_mutex_unlock(pi_mutex);
66751 } else if (ret == -EINTR) {
66752 /*
66753 @@ -2711,6 +2720,7 @@ static int __init futex_init(void)
66754 {
66755 u32 curval;
66756 int i;
66757 + mm_segment_t oldfs;
66758
66759 /*
66760 * This will fail and we want it. Some arch implementations do
66761 @@ -2722,8 +2732,11 @@ static int __init futex_init(void)
66762 * implementation, the non-functional ones will return
66763 * -ENOSYS.
66764 */
66765 + oldfs = get_fs();
66766 + set_fs(USER_DS);
66767 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66768 futex_cmpxchg_enabled = 1;
66769 + set_fs(oldfs);
66770
66771 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66772 plist_head_init(&futex_queues[i].chain);
66773 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66774 index 9b22d03..6295b62 100644
66775 --- a/kernel/gcov/base.c
66776 +++ b/kernel/gcov/base.c
66777 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66778 }
66779
66780 #ifdef CONFIG_MODULES
66781 -static inline int within(void *addr, void *start, unsigned long size)
66782 -{
66783 - return ((addr >= start) && (addr < start + size));
66784 -}
66785 -
66786 /* Update list and generate events when modules are unloaded. */
66787 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66788 void *data)
66789 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66790 prev = NULL;
66791 /* Remove entries located in module from linked list. */
66792 for (info = gcov_info_head; info; info = info->next) {
66793 - if (within(info, mod->module_core, mod->core_size)) {
66794 + if (within_module_core_rw((unsigned long)info, mod)) {
66795 if (prev)
66796 prev->next = info->next;
66797 else
66798 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66799 index 6db7a5e..25b6648 100644
66800 --- a/kernel/hrtimer.c
66801 +++ b/kernel/hrtimer.c
66802 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66803 local_irq_restore(flags);
66804 }
66805
66806 -static void run_hrtimer_softirq(struct softirq_action *h)
66807 +static void run_hrtimer_softirq(void)
66808 {
66809 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66810
66811 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66812 index 4304919..408c4c0 100644
66813 --- a/kernel/jump_label.c
66814 +++ b/kernel/jump_label.c
66815 @@ -13,6 +13,7 @@
66816 #include <linux/sort.h>
66817 #include <linux/err.h>
66818 #include <linux/static_key.h>
66819 +#include <linux/mm.h>
66820
66821 #ifdef HAVE_JUMP_LABEL
66822
66823 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66824
66825 size = (((unsigned long)stop - (unsigned long)start)
66826 / sizeof(struct jump_entry));
66827 + pax_open_kernel();
66828 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66829 + pax_close_kernel();
66830 }
66831
66832 static void jump_label_update(struct static_key *key, int enable);
66833 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66834 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66835 struct jump_entry *iter;
66836
66837 + pax_open_kernel();
66838 for (iter = iter_start; iter < iter_stop; iter++) {
66839 if (within_module_init(iter->code, mod))
66840 iter->code = 0;
66841 }
66842 + pax_close_kernel();
66843 }
66844
66845 static int
66846 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66847 index 2169fee..45c017a 100644
66848 --- a/kernel/kallsyms.c
66849 +++ b/kernel/kallsyms.c
66850 @@ -11,6 +11,9 @@
66851 * Changed the compression method from stem compression to "table lookup"
66852 * compression (see scripts/kallsyms.c for a more complete description)
66853 */
66854 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66855 +#define __INCLUDED_BY_HIDESYM 1
66856 +#endif
66857 #include <linux/kallsyms.h>
66858 #include <linux/module.h>
66859 #include <linux/init.h>
66860 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66861
66862 static inline int is_kernel_inittext(unsigned long addr)
66863 {
66864 + if (system_state != SYSTEM_BOOTING)
66865 + return 0;
66866 +
66867 if (addr >= (unsigned long)_sinittext
66868 && addr <= (unsigned long)_einittext)
66869 return 1;
66870 return 0;
66871 }
66872
66873 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66874 +#ifdef CONFIG_MODULES
66875 +static inline int is_module_text(unsigned long addr)
66876 +{
66877 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66878 + return 1;
66879 +
66880 + addr = ktla_ktva(addr);
66881 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66882 +}
66883 +#else
66884 +static inline int is_module_text(unsigned long addr)
66885 +{
66886 + return 0;
66887 +}
66888 +#endif
66889 +#endif
66890 +
66891 static inline int is_kernel_text(unsigned long addr)
66892 {
66893 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66894 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66895
66896 static inline int is_kernel(unsigned long addr)
66897 {
66898 +
66899 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66900 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66901 + return 1;
66902 +
66903 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66904 +#else
66905 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66906 +#endif
66907 +
66908 return 1;
66909 return in_gate_area_no_mm(addr);
66910 }
66911
66912 static int is_ksym_addr(unsigned long addr)
66913 {
66914 +
66915 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66916 + if (is_module_text(addr))
66917 + return 0;
66918 +#endif
66919 +
66920 if (all_var)
66921 return is_kernel(addr);
66922
66923 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66924
66925 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66926 {
66927 - iter->name[0] = '\0';
66928 iter->nameoff = get_symbol_offset(new_pos);
66929 iter->pos = new_pos;
66930 }
66931 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
66932 {
66933 struct kallsym_iter *iter = m->private;
66934
66935 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66936 + if (current_uid())
66937 + return 0;
66938 +#endif
66939 +
66940 /* Some debugging symbols have no name. Ignore them. */
66941 if (!iter->name[0])
66942 return 0;
66943 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
66944 */
66945 type = iter->exported ? toupper(iter->type) :
66946 tolower(iter->type);
66947 +
66948 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
66949 type, iter->name, iter->module_name);
66950 } else
66951 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66952 struct kallsym_iter *iter;
66953 int ret;
66954
66955 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66956 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66957 if (!iter)
66958 return -ENOMEM;
66959 reset_iter(iter, 0);
66960 diff --git a/kernel/kexec.c b/kernel/kexec.c
66961 index 4e2e472..cd0c7ae 100644
66962 --- a/kernel/kexec.c
66963 +++ b/kernel/kexec.c
66964 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66965 unsigned long flags)
66966 {
66967 struct compat_kexec_segment in;
66968 - struct kexec_segment out, __user *ksegments;
66969 + struct kexec_segment out;
66970 + struct kexec_segment __user *ksegments;
66971 unsigned long i, result;
66972
66973 /* Don't allow clients that don't understand the native
66974 diff --git a/kernel/kmod.c b/kernel/kmod.c
66975 index ff2c7cb..085d7af 100644
66976 --- a/kernel/kmod.c
66977 +++ b/kernel/kmod.c
66978 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
66979 kfree(info->argv);
66980 }
66981
66982 -static int call_modprobe(char *module_name, int wait)
66983 +static int call_modprobe(char *module_name, char *module_param, int wait)
66984 {
66985 static char *envp[] = {
66986 "HOME=/",
66987 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
66988 NULL
66989 };
66990
66991 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
66992 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
66993 if (!argv)
66994 goto out;
66995
66996 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
66997 argv[1] = "-q";
66998 argv[2] = "--";
66999 argv[3] = module_name; /* check free_modprobe_argv() */
67000 - argv[4] = NULL;
67001 + argv[4] = module_param;
67002 + argv[5] = NULL;
67003
67004 return call_usermodehelper_fns(modprobe_path, argv, envp,
67005 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67006 @@ -112,9 +113,8 @@ out:
67007 * If module auto-loading support is disabled then this function
67008 * becomes a no-operation.
67009 */
67010 -int __request_module(bool wait, const char *fmt, ...)
67011 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67012 {
67013 - va_list args;
67014 char module_name[MODULE_NAME_LEN];
67015 unsigned int max_modprobes;
67016 int ret;
67017 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67018 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67019 static int kmod_loop_msg;
67020
67021 - va_start(args, fmt);
67022 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67023 - va_end(args);
67024 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67025 if (ret >= MODULE_NAME_LEN)
67026 return -ENAMETOOLONG;
67027
67028 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67029 if (ret)
67030 return ret;
67031
67032 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67033 + if (!current_uid()) {
67034 + /* hack to workaround consolekit/udisks stupidity */
67035 + read_lock(&tasklist_lock);
67036 + if (!strcmp(current->comm, "mount") &&
67037 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67038 + read_unlock(&tasklist_lock);
67039 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67040 + return -EPERM;
67041 + }
67042 + read_unlock(&tasklist_lock);
67043 + }
67044 +#endif
67045 +
67046 /* If modprobe needs a service that is in a module, we get a recursive
67047 * loop. Limit the number of running kmod threads to max_threads/2 or
67048 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67049 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67050
67051 trace_module_request(module_name, wait, _RET_IP_);
67052
67053 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67054 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67055
67056 atomic_dec(&kmod_concurrent);
67057 return ret;
67058 }
67059 +
67060 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67061 +{
67062 + va_list args;
67063 + int ret;
67064 +
67065 + va_start(args, fmt);
67066 + ret = ____request_module(wait, module_param, fmt, args);
67067 + va_end(args);
67068 +
67069 + return ret;
67070 +}
67071 +
67072 +int __request_module(bool wait, const char *fmt, ...)
67073 +{
67074 + va_list args;
67075 + int ret;
67076 +
67077 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67078 + if (current_uid()) {
67079 + char module_param[MODULE_NAME_LEN];
67080 +
67081 + memset(module_param, 0, sizeof(module_param));
67082 +
67083 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67084 +
67085 + va_start(args, fmt);
67086 + ret = ____request_module(wait, module_param, fmt, args);
67087 + va_end(args);
67088 +
67089 + return ret;
67090 + }
67091 +#endif
67092 +
67093 + va_start(args, fmt);
67094 + ret = ____request_module(wait, NULL, fmt, args);
67095 + va_end(args);
67096 +
67097 + return ret;
67098 +}
67099 +
67100 EXPORT_SYMBOL(__request_module);
67101 #endif /* CONFIG_MODULES */
67102
67103 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67104 *
67105 * Thus the __user pointer cast is valid here.
67106 */
67107 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67108 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67109
67110 /*
67111 * If ret is 0, either ____call_usermodehelper failed and the
67112 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67113 index c62b854..cb67968 100644
67114 --- a/kernel/kprobes.c
67115 +++ b/kernel/kprobes.c
67116 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67117 * kernel image and loaded module images reside. This is required
67118 * so x86_64 can correctly handle the %rip-relative fixups.
67119 */
67120 - kip->insns = module_alloc(PAGE_SIZE);
67121 + kip->insns = module_alloc_exec(PAGE_SIZE);
67122 if (!kip->insns) {
67123 kfree(kip);
67124 return NULL;
67125 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67126 */
67127 if (!list_is_singular(&kip->list)) {
67128 list_del(&kip->list);
67129 - module_free(NULL, kip->insns);
67130 + module_free_exec(NULL, kip->insns);
67131 kfree(kip);
67132 }
67133 return 1;
67134 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67135 {
67136 int i, err = 0;
67137 unsigned long offset = 0, size = 0;
67138 - char *modname, namebuf[128];
67139 + char *modname, namebuf[KSYM_NAME_LEN];
67140 const char *symbol_name;
67141 void *addr;
67142 struct kprobe_blackpoint *kb;
67143 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67144 const char *sym = NULL;
67145 unsigned int i = *(loff_t *) v;
67146 unsigned long offset = 0;
67147 - char *modname, namebuf[128];
67148 + char *modname, namebuf[KSYM_NAME_LEN];
67149
67150 head = &kprobe_table[i];
67151 preempt_disable();
67152 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67153 index 4e316e1..5501eef 100644
67154 --- a/kernel/ksysfs.c
67155 +++ b/kernel/ksysfs.c
67156 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67157 {
67158 if (count+1 > UEVENT_HELPER_PATH_LEN)
67159 return -ENOENT;
67160 + if (!capable(CAP_SYS_ADMIN))
67161 + return -EPERM;
67162 memcpy(uevent_helper, buf, count);
67163 uevent_helper[count] = '\0';
67164 if (count && uevent_helper[count-1] == '\n')
67165 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67166 index ea9ee45..67ebc8f 100644
67167 --- a/kernel/lockdep.c
67168 +++ b/kernel/lockdep.c
67169 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67170 end = (unsigned long) &_end,
67171 addr = (unsigned long) obj;
67172
67173 +#ifdef CONFIG_PAX_KERNEXEC
67174 + start = ktla_ktva(start);
67175 +#endif
67176 +
67177 /*
67178 * static variable?
67179 */
67180 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67181 if (!static_obj(lock->key)) {
67182 debug_locks_off();
67183 printk("INFO: trying to register non-static key.\n");
67184 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67185 printk("the code is fine but needs lockdep annotation.\n");
67186 printk("turning off the locking correctness validator.\n");
67187 dump_stack();
67188 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67189 if (!class)
67190 return 0;
67191 }
67192 - atomic_inc((atomic_t *)&class->ops);
67193 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67194 if (very_verbose(class)) {
67195 printk("\nacquire class [%p] %s", class->key, class->name);
67196 if (class->name_version > 1)
67197 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67198 index 91c32a0..b2c71c5 100644
67199 --- a/kernel/lockdep_proc.c
67200 +++ b/kernel/lockdep_proc.c
67201 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67202
67203 static void print_name(struct seq_file *m, struct lock_class *class)
67204 {
67205 - char str[128];
67206 + char str[KSYM_NAME_LEN];
67207 const char *name = class->name;
67208
67209 if (!name) {
67210 diff --git a/kernel/module.c b/kernel/module.c
67211 index 4edbd9c..165e780 100644
67212 --- a/kernel/module.c
67213 +++ b/kernel/module.c
67214 @@ -58,6 +58,7 @@
67215 #include <linux/jump_label.h>
67216 #include <linux/pfn.h>
67217 #include <linux/bsearch.h>
67218 +#include <linux/grsecurity.h>
67219
67220 #define CREATE_TRACE_POINTS
67221 #include <trace/events/module.h>
67222 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67223
67224 /* Bounds of module allocation, for speeding __module_address.
67225 * Protected by module_mutex. */
67226 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67227 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67228 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67229
67230 int register_module_notifier(struct notifier_block * nb)
67231 {
67232 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67233 return true;
67234
67235 list_for_each_entry_rcu(mod, &modules, list) {
67236 - struct symsearch arr[] = {
67237 + struct symsearch modarr[] = {
67238 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67239 NOT_GPL_ONLY, false },
67240 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67241 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67242 #endif
67243 };
67244
67245 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67246 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67247 return true;
67248 }
67249 return false;
67250 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67251 static int percpu_modalloc(struct module *mod,
67252 unsigned long size, unsigned long align)
67253 {
67254 - if (align > PAGE_SIZE) {
67255 + if (align-1 >= PAGE_SIZE) {
67256 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67257 mod->name, align, PAGE_SIZE);
67258 align = PAGE_SIZE;
67259 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67260 static ssize_t show_coresize(struct module_attribute *mattr,
67261 struct module_kobject *mk, char *buffer)
67262 {
67263 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67264 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67265 }
67266
67267 static struct module_attribute modinfo_coresize =
67268 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67269 static ssize_t show_initsize(struct module_attribute *mattr,
67270 struct module_kobject *mk, char *buffer)
67271 {
67272 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67273 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67274 }
67275
67276 static struct module_attribute modinfo_initsize =
67277 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67278 */
67279 #ifdef CONFIG_SYSFS
67280
67281 -#ifdef CONFIG_KALLSYMS
67282 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67283 static inline bool sect_empty(const Elf_Shdr *sect)
67284 {
67285 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67286 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67287
67288 static void unset_module_core_ro_nx(struct module *mod)
67289 {
67290 - set_page_attributes(mod->module_core + mod->core_text_size,
67291 - mod->module_core + mod->core_size,
67292 + set_page_attributes(mod->module_core_rw,
67293 + mod->module_core_rw + mod->core_size_rw,
67294 set_memory_x);
67295 - set_page_attributes(mod->module_core,
67296 - mod->module_core + mod->core_ro_size,
67297 + set_page_attributes(mod->module_core_rx,
67298 + mod->module_core_rx + mod->core_size_rx,
67299 set_memory_rw);
67300 }
67301
67302 static void unset_module_init_ro_nx(struct module *mod)
67303 {
67304 - set_page_attributes(mod->module_init + mod->init_text_size,
67305 - mod->module_init + mod->init_size,
67306 + set_page_attributes(mod->module_init_rw,
67307 + mod->module_init_rw + mod->init_size_rw,
67308 set_memory_x);
67309 - set_page_attributes(mod->module_init,
67310 - mod->module_init + mod->init_ro_size,
67311 + set_page_attributes(mod->module_init_rx,
67312 + mod->module_init_rx + mod->init_size_rx,
67313 set_memory_rw);
67314 }
67315
67316 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67317
67318 mutex_lock(&module_mutex);
67319 list_for_each_entry_rcu(mod, &modules, list) {
67320 - if ((mod->module_core) && (mod->core_text_size)) {
67321 - set_page_attributes(mod->module_core,
67322 - mod->module_core + mod->core_text_size,
67323 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67324 + set_page_attributes(mod->module_core_rx,
67325 + mod->module_core_rx + mod->core_size_rx,
67326 set_memory_rw);
67327 }
67328 - if ((mod->module_init) && (mod->init_text_size)) {
67329 - set_page_attributes(mod->module_init,
67330 - mod->module_init + mod->init_text_size,
67331 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67332 + set_page_attributes(mod->module_init_rx,
67333 + mod->module_init_rx + mod->init_size_rx,
67334 set_memory_rw);
67335 }
67336 }
67337 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67338
67339 mutex_lock(&module_mutex);
67340 list_for_each_entry_rcu(mod, &modules, list) {
67341 - if ((mod->module_core) && (mod->core_text_size)) {
67342 - set_page_attributes(mod->module_core,
67343 - mod->module_core + mod->core_text_size,
67344 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67345 + set_page_attributes(mod->module_core_rx,
67346 + mod->module_core_rx + mod->core_size_rx,
67347 set_memory_ro);
67348 }
67349 - if ((mod->module_init) && (mod->init_text_size)) {
67350 - set_page_attributes(mod->module_init,
67351 - mod->module_init + mod->init_text_size,
67352 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67353 + set_page_attributes(mod->module_init_rx,
67354 + mod->module_init_rx + mod->init_size_rx,
67355 set_memory_ro);
67356 }
67357 }
67358 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67359
67360 /* This may be NULL, but that's OK */
67361 unset_module_init_ro_nx(mod);
67362 - module_free(mod, mod->module_init);
67363 + module_free(mod, mod->module_init_rw);
67364 + module_free_exec(mod, mod->module_init_rx);
67365 kfree(mod->args);
67366 percpu_modfree(mod);
67367
67368 /* Free lock-classes: */
67369 - lockdep_free_key_range(mod->module_core, mod->core_size);
67370 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67371 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67372
67373 /* Finally, free the core (containing the module structure) */
67374 unset_module_core_ro_nx(mod);
67375 - module_free(mod, mod->module_core);
67376 + module_free_exec(mod, mod->module_core_rx);
67377 + module_free(mod, mod->module_core_rw);
67378
67379 #ifdef CONFIG_MPU
67380 update_protections(current->mm);
67381 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67382 int ret = 0;
67383 const struct kernel_symbol *ksym;
67384
67385 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67386 + int is_fs_load = 0;
67387 + int register_filesystem_found = 0;
67388 + char *p;
67389 +
67390 + p = strstr(mod->args, "grsec_modharden_fs");
67391 + if (p) {
67392 + char *endptr = p + strlen("grsec_modharden_fs");
67393 + /* copy \0 as well */
67394 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67395 + is_fs_load = 1;
67396 + }
67397 +#endif
67398 +
67399 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67400 const char *name = info->strtab + sym[i].st_name;
67401
67402 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67403 + /* it's a real shame this will never get ripped and copied
67404 + upstream! ;(
67405 + */
67406 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67407 + register_filesystem_found = 1;
67408 +#endif
67409 +
67410 switch (sym[i].st_shndx) {
67411 case SHN_COMMON:
67412 /* We compiled with -fno-common. These are not
67413 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67414 ksym = resolve_symbol_wait(mod, info, name);
67415 /* Ok if resolved. */
67416 if (ksym && !IS_ERR(ksym)) {
67417 + pax_open_kernel();
67418 sym[i].st_value = ksym->value;
67419 + pax_close_kernel();
67420 break;
67421 }
67422
67423 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67424 secbase = (unsigned long)mod_percpu(mod);
67425 else
67426 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67427 + pax_open_kernel();
67428 sym[i].st_value += secbase;
67429 + pax_close_kernel();
67430 break;
67431 }
67432 }
67433
67434 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67435 + if (is_fs_load && !register_filesystem_found) {
67436 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67437 + ret = -EPERM;
67438 + }
67439 +#endif
67440 +
67441 return ret;
67442 }
67443
67444 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67445 || s->sh_entsize != ~0UL
67446 || strstarts(sname, ".init"))
67447 continue;
67448 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67449 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67450 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67451 + else
67452 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67453 pr_debug("\t%s\n", sname);
67454 }
67455 - switch (m) {
67456 - case 0: /* executable */
67457 - mod->core_size = debug_align(mod->core_size);
67458 - mod->core_text_size = mod->core_size;
67459 - break;
67460 - case 1: /* RO: text and ro-data */
67461 - mod->core_size = debug_align(mod->core_size);
67462 - mod->core_ro_size = mod->core_size;
67463 - break;
67464 - case 3: /* whole core */
67465 - mod->core_size = debug_align(mod->core_size);
67466 - break;
67467 - }
67468 }
67469
67470 pr_debug("Init section allocation order:\n");
67471 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67472 || s->sh_entsize != ~0UL
67473 || !strstarts(sname, ".init"))
67474 continue;
67475 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67476 - | INIT_OFFSET_MASK);
67477 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67478 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67479 + else
67480 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67481 + s->sh_entsize |= INIT_OFFSET_MASK;
67482 pr_debug("\t%s\n", sname);
67483 }
67484 - switch (m) {
67485 - case 0: /* executable */
67486 - mod->init_size = debug_align(mod->init_size);
67487 - mod->init_text_size = mod->init_size;
67488 - break;
67489 - case 1: /* RO: text and ro-data */
67490 - mod->init_size = debug_align(mod->init_size);
67491 - mod->init_ro_size = mod->init_size;
67492 - break;
67493 - case 3: /* whole init */
67494 - mod->init_size = debug_align(mod->init_size);
67495 - break;
67496 - }
67497 }
67498 }
67499
67500 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67501
67502 /* Put symbol section at end of init part of module. */
67503 symsect->sh_flags |= SHF_ALLOC;
67504 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67505 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67506 info->index.sym) | INIT_OFFSET_MASK;
67507 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67508
67509 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67510 }
67511
67512 /* Append room for core symbols at end of core part. */
67513 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67514 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67515 - mod->core_size += strtab_size;
67516 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67517 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67518 + mod->core_size_rx += strtab_size;
67519
67520 /* Put string table section at end of init part of module. */
67521 strsect->sh_flags |= SHF_ALLOC;
67522 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67523 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67524 info->index.str) | INIT_OFFSET_MASK;
67525 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67526 }
67527 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67528 /* Make sure we get permanent strtab: don't use info->strtab. */
67529 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67530
67531 + pax_open_kernel();
67532 +
67533 /* Set types up while we still have access to sections. */
67534 for (i = 0; i < mod->num_symtab; i++)
67535 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67536
67537 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67538 - mod->core_strtab = s = mod->module_core + info->stroffs;
67539 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67540 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67541 src = mod->symtab;
67542 *dst = *src;
67543 *s++ = 0;
67544 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67545 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67546 }
67547 mod->core_num_syms = ndst;
67548 +
67549 + pax_close_kernel();
67550 }
67551 #else
67552 static inline void layout_symtab(struct module *mod, struct load_info *info)
67553 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67554 return size == 0 ? NULL : vmalloc_exec(size);
67555 }
67556
67557 -static void *module_alloc_update_bounds(unsigned long size)
67558 +static void *module_alloc_update_bounds_rw(unsigned long size)
67559 {
67560 void *ret = module_alloc(size);
67561
67562 if (ret) {
67563 mutex_lock(&module_mutex);
67564 /* Update module bounds. */
67565 - if ((unsigned long)ret < module_addr_min)
67566 - module_addr_min = (unsigned long)ret;
67567 - if ((unsigned long)ret + size > module_addr_max)
67568 - module_addr_max = (unsigned long)ret + size;
67569 + if ((unsigned long)ret < module_addr_min_rw)
67570 + module_addr_min_rw = (unsigned long)ret;
67571 + if ((unsigned long)ret + size > module_addr_max_rw)
67572 + module_addr_max_rw = (unsigned long)ret + size;
67573 + mutex_unlock(&module_mutex);
67574 + }
67575 + return ret;
67576 +}
67577 +
67578 +static void *module_alloc_update_bounds_rx(unsigned long size)
67579 +{
67580 + void *ret = module_alloc_exec(size);
67581 +
67582 + if (ret) {
67583 + mutex_lock(&module_mutex);
67584 + /* Update module bounds. */
67585 + if ((unsigned long)ret < module_addr_min_rx)
67586 + module_addr_min_rx = (unsigned long)ret;
67587 + if ((unsigned long)ret + size > module_addr_max_rx)
67588 + module_addr_max_rx = (unsigned long)ret + size;
67589 mutex_unlock(&module_mutex);
67590 }
67591 return ret;
67592 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67593 static int check_modinfo(struct module *mod, struct load_info *info)
67594 {
67595 const char *modmagic = get_modinfo(info, "vermagic");
67596 + const char *license = get_modinfo(info, "license");
67597 int err;
67598
67599 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67600 + if (!license || !license_is_gpl_compatible(license))
67601 + return -ENOEXEC;
67602 +#endif
67603 +
67604 /* This is allowed: modprobe --force will invalidate it. */
67605 if (!modmagic) {
67606 err = try_to_force_load(mod, "bad vermagic");
67607 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67608 }
67609
67610 /* Set up license info based on the info section */
67611 - set_license(mod, get_modinfo(info, "license"));
67612 + set_license(mod, license);
67613
67614 return 0;
67615 }
67616 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67617 void *ptr;
67618
67619 /* Do the allocs. */
67620 - ptr = module_alloc_update_bounds(mod->core_size);
67621 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67622 /*
67623 * The pointer to this block is stored in the module structure
67624 * which is inside the block. Just mark it as not being a
67625 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67626 if (!ptr)
67627 return -ENOMEM;
67628
67629 - memset(ptr, 0, mod->core_size);
67630 - mod->module_core = ptr;
67631 + memset(ptr, 0, mod->core_size_rw);
67632 + mod->module_core_rw = ptr;
67633
67634 - ptr = module_alloc_update_bounds(mod->init_size);
67635 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67636 /*
67637 * The pointer to this block is stored in the module structure
67638 * which is inside the block. This block doesn't need to be
67639 * scanned as it contains data and code that will be freed
67640 * after the module is initialized.
67641 */
67642 - kmemleak_ignore(ptr);
67643 - if (!ptr && mod->init_size) {
67644 - module_free(mod, mod->module_core);
67645 + kmemleak_not_leak(ptr);
67646 + if (!ptr && mod->init_size_rw) {
67647 + module_free(mod, mod->module_core_rw);
67648 return -ENOMEM;
67649 }
67650 - memset(ptr, 0, mod->init_size);
67651 - mod->module_init = ptr;
67652 + memset(ptr, 0, mod->init_size_rw);
67653 + mod->module_init_rw = ptr;
67654 +
67655 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67656 + kmemleak_not_leak(ptr);
67657 + if (!ptr) {
67658 + module_free(mod, mod->module_init_rw);
67659 + module_free(mod, mod->module_core_rw);
67660 + return -ENOMEM;
67661 + }
67662 +
67663 + pax_open_kernel();
67664 + memset(ptr, 0, mod->core_size_rx);
67665 + pax_close_kernel();
67666 + mod->module_core_rx = ptr;
67667 +
67668 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67669 + kmemleak_not_leak(ptr);
67670 + if (!ptr && mod->init_size_rx) {
67671 + module_free_exec(mod, mod->module_core_rx);
67672 + module_free(mod, mod->module_init_rw);
67673 + module_free(mod, mod->module_core_rw);
67674 + return -ENOMEM;
67675 + }
67676 +
67677 + pax_open_kernel();
67678 + memset(ptr, 0, mod->init_size_rx);
67679 + pax_close_kernel();
67680 + mod->module_init_rx = ptr;
67681
67682 /* Transfer each section which specifies SHF_ALLOC */
67683 pr_debug("final section addresses:\n");
67684 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67685 if (!(shdr->sh_flags & SHF_ALLOC))
67686 continue;
67687
67688 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67689 - dest = mod->module_init
67690 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67691 - else
67692 - dest = mod->module_core + shdr->sh_entsize;
67693 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67694 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67695 + dest = mod->module_init_rw
67696 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67697 + else
67698 + dest = mod->module_init_rx
67699 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67700 + } else {
67701 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67702 + dest = mod->module_core_rw + shdr->sh_entsize;
67703 + else
67704 + dest = mod->module_core_rx + shdr->sh_entsize;
67705 + }
67706 +
67707 + if (shdr->sh_type != SHT_NOBITS) {
67708 +
67709 +#ifdef CONFIG_PAX_KERNEXEC
67710 +#ifdef CONFIG_X86_64
67711 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67712 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67713 +#endif
67714 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67715 + pax_open_kernel();
67716 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67717 + pax_close_kernel();
67718 + } else
67719 +#endif
67720
67721 - if (shdr->sh_type != SHT_NOBITS)
67722 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67723 + }
67724 /* Update sh_addr to point to copy in image. */
67725 - shdr->sh_addr = (unsigned long)dest;
67726 +
67727 +#ifdef CONFIG_PAX_KERNEXEC
67728 + if (shdr->sh_flags & SHF_EXECINSTR)
67729 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67730 + else
67731 +#endif
67732 +
67733 + shdr->sh_addr = (unsigned long)dest;
67734 pr_debug("\t0x%lx %s\n",
67735 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67736 }
67737 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67738 * Do it before processing of module parameters, so the module
67739 * can provide parameter accessor functions of its own.
67740 */
67741 - if (mod->module_init)
67742 - flush_icache_range((unsigned long)mod->module_init,
67743 - (unsigned long)mod->module_init
67744 - + mod->init_size);
67745 - flush_icache_range((unsigned long)mod->module_core,
67746 - (unsigned long)mod->module_core + mod->core_size);
67747 + if (mod->module_init_rx)
67748 + flush_icache_range((unsigned long)mod->module_init_rx,
67749 + (unsigned long)mod->module_init_rx
67750 + + mod->init_size_rx);
67751 + flush_icache_range((unsigned long)mod->module_core_rx,
67752 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67753
67754 set_fs(old_fs);
67755 }
67756 @@ -2834,8 +2934,10 @@ out:
67757 static void module_deallocate(struct module *mod, struct load_info *info)
67758 {
67759 percpu_modfree(mod);
67760 - module_free(mod, mod->module_init);
67761 - module_free(mod, mod->module_core);
67762 + module_free_exec(mod, mod->module_init_rx);
67763 + module_free_exec(mod, mod->module_core_rx);
67764 + module_free(mod, mod->module_init_rw);
67765 + module_free(mod, mod->module_core_rw);
67766 }
67767
67768 int __weak module_finalize(const Elf_Ehdr *hdr,
67769 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67770 static int post_relocation(struct module *mod, const struct load_info *info)
67771 {
67772 /* Sort exception table now relocations are done. */
67773 + pax_open_kernel();
67774 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67775 + pax_close_kernel();
67776
67777 /* Copy relocated percpu area over. */
67778 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67779 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67780 if (err)
67781 goto free_unload;
67782
67783 + /* Now copy in args */
67784 + mod->args = strndup_user(uargs, ~0UL >> 1);
67785 + if (IS_ERR(mod->args)) {
67786 + err = PTR_ERR(mod->args);
67787 + goto free_unload;
67788 + }
67789 +
67790 /* Set up MODINFO_ATTR fields */
67791 setup_modinfo(mod, &info);
67792
67793 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67794 + {
67795 + char *p, *p2;
67796 +
67797 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67798 + 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);
67799 + err = -EPERM;
67800 + goto free_modinfo;
67801 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67802 + p += strlen("grsec_modharden_normal");
67803 + p2 = strstr(p, "_");
67804 + if (p2) {
67805 + *p2 = '\0';
67806 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67807 + *p2 = '_';
67808 + }
67809 + err = -EPERM;
67810 + goto free_modinfo;
67811 + }
67812 + }
67813 +#endif
67814 +
67815 /* Fix up syms, so that st_value is a pointer to location. */
67816 err = simplify_symbols(mod, &info);
67817 if (err < 0)
67818 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67819
67820 flush_module_icache(mod);
67821
67822 - /* Now copy in args */
67823 - mod->args = strndup_user(uargs, ~0UL >> 1);
67824 - if (IS_ERR(mod->args)) {
67825 - err = PTR_ERR(mod->args);
67826 - goto free_arch_cleanup;
67827 - }
67828 -
67829 /* Mark state as coming so strong_try_module_get() ignores us. */
67830 mod->state = MODULE_STATE_COMING;
67831
67832 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67833 unlock:
67834 mutex_unlock(&module_mutex);
67835 synchronize_sched();
67836 - kfree(mod->args);
67837 - free_arch_cleanup:
67838 module_arch_cleanup(mod);
67839 free_modinfo:
67840 free_modinfo(mod);
67841 + kfree(mod->args);
67842 free_unload:
67843 module_unload_free(mod);
67844 free_module:
67845 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67846 MODULE_STATE_COMING, mod);
67847
67848 /* Set RO and NX regions for core */
67849 - set_section_ro_nx(mod->module_core,
67850 - mod->core_text_size,
67851 - mod->core_ro_size,
67852 - mod->core_size);
67853 + set_section_ro_nx(mod->module_core_rx,
67854 + mod->core_size_rx,
67855 + mod->core_size_rx,
67856 + mod->core_size_rx);
67857
67858 /* Set RO and NX regions for init */
67859 - set_section_ro_nx(mod->module_init,
67860 - mod->init_text_size,
67861 - mod->init_ro_size,
67862 - mod->init_size);
67863 + set_section_ro_nx(mod->module_init_rx,
67864 + mod->init_size_rx,
67865 + mod->init_size_rx,
67866 + mod->init_size_rx);
67867
67868 do_mod_ctors(mod);
67869 /* Start the module */
67870 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67871 mod->strtab = mod->core_strtab;
67872 #endif
67873 unset_module_init_ro_nx(mod);
67874 - module_free(mod, mod->module_init);
67875 - mod->module_init = NULL;
67876 - mod->init_size = 0;
67877 - mod->init_ro_size = 0;
67878 - mod->init_text_size = 0;
67879 + module_free(mod, mod->module_init_rw);
67880 + module_free_exec(mod, mod->module_init_rx);
67881 + mod->module_init_rw = NULL;
67882 + mod->module_init_rx = NULL;
67883 + mod->init_size_rw = 0;
67884 + mod->init_size_rx = 0;
67885 mutex_unlock(&module_mutex);
67886
67887 return 0;
67888 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
67889 unsigned long nextval;
67890
67891 /* At worse, next value is at end of module */
67892 - if (within_module_init(addr, mod))
67893 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67894 + if (within_module_init_rx(addr, mod))
67895 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67896 + else if (within_module_init_rw(addr, mod))
67897 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67898 + else if (within_module_core_rx(addr, mod))
67899 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67900 + else if (within_module_core_rw(addr, mod))
67901 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67902 else
67903 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67904 + return NULL;
67905
67906 /* Scan for closest preceding symbol, and next symbol. (ELF
67907 starts real symbols at 1). */
67908 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
67909 char buf[8];
67910
67911 seq_printf(m, "%s %u",
67912 - mod->name, mod->init_size + mod->core_size);
67913 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67914 print_unload_info(m, mod);
67915
67916 /* Informative for users. */
67917 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
67918 mod->state == MODULE_STATE_COMING ? "Loading":
67919 "Live");
67920 /* Used by oprofile and other similar tools. */
67921 - seq_printf(m, " 0x%pK", mod->module_core);
67922 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67923
67924 /* Taints info */
67925 if (mod->taints)
67926 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
67927
67928 static int __init proc_modules_init(void)
67929 {
67930 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67931 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67932 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67933 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67934 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67935 +#else
67936 proc_create("modules", 0, NULL, &proc_modules_operations);
67937 +#endif
67938 +#else
67939 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67940 +#endif
67941 return 0;
67942 }
67943 module_init(proc_modules_init);
67944 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
67945 {
67946 struct module *mod;
67947
67948 - if (addr < module_addr_min || addr > module_addr_max)
67949 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67950 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67951 return NULL;
67952
67953 list_for_each_entry_rcu(mod, &modules, list)
67954 - if (within_module_core(addr, mod)
67955 - || within_module_init(addr, mod))
67956 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67957 return mod;
67958 return NULL;
67959 }
67960 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
67961 */
67962 struct module *__module_text_address(unsigned long addr)
67963 {
67964 - struct module *mod = __module_address(addr);
67965 + struct module *mod;
67966 +
67967 +#ifdef CONFIG_X86_32
67968 + addr = ktla_ktva(addr);
67969 +#endif
67970 +
67971 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67972 + return NULL;
67973 +
67974 + mod = __module_address(addr);
67975 +
67976 if (mod) {
67977 /* Make sure it's within the text section. */
67978 - if (!within(addr, mod->module_init, mod->init_text_size)
67979 - && !within(addr, mod->module_core, mod->core_text_size))
67980 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67981 mod = NULL;
67982 }
67983 return mod;
67984 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67985 index 7e3443f..b2a1e6b 100644
67986 --- a/kernel/mutex-debug.c
67987 +++ b/kernel/mutex-debug.c
67988 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67989 }
67990
67991 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67992 - struct thread_info *ti)
67993 + struct task_struct *task)
67994 {
67995 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67996
67997 /* Mark the current thread as blocked on the lock: */
67998 - ti->task->blocked_on = waiter;
67999 + task->blocked_on = waiter;
68000 }
68001
68002 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68003 - struct thread_info *ti)
68004 + struct task_struct *task)
68005 {
68006 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68007 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68008 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68009 - ti->task->blocked_on = NULL;
68010 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68011 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68012 + task->blocked_on = NULL;
68013
68014 list_del_init(&waiter->list);
68015 waiter->task = NULL;
68016 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68017 index 0799fd3..d06ae3b 100644
68018 --- a/kernel/mutex-debug.h
68019 +++ b/kernel/mutex-debug.h
68020 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68021 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68022 extern void debug_mutex_add_waiter(struct mutex *lock,
68023 struct mutex_waiter *waiter,
68024 - struct thread_info *ti);
68025 + struct task_struct *task);
68026 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68027 - struct thread_info *ti);
68028 + struct task_struct *task);
68029 extern void debug_mutex_unlock(struct mutex *lock);
68030 extern void debug_mutex_init(struct mutex *lock, const char *name,
68031 struct lock_class_key *key);
68032 diff --git a/kernel/mutex.c b/kernel/mutex.c
68033 index a307cc9..27fd2e9 100644
68034 --- a/kernel/mutex.c
68035 +++ b/kernel/mutex.c
68036 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68037 spin_lock_mutex(&lock->wait_lock, flags);
68038
68039 debug_mutex_lock_common(lock, &waiter);
68040 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68041 + debug_mutex_add_waiter(lock, &waiter, task);
68042
68043 /* add waiting tasks to the end of the waitqueue (FIFO): */
68044 list_add_tail(&waiter.list, &lock->wait_list);
68045 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68046 * TASK_UNINTERRUPTIBLE case.)
68047 */
68048 if (unlikely(signal_pending_state(state, task))) {
68049 - mutex_remove_waiter(lock, &waiter,
68050 - task_thread_info(task));
68051 + mutex_remove_waiter(lock, &waiter, task);
68052 mutex_release(&lock->dep_map, 1, ip);
68053 spin_unlock_mutex(&lock->wait_lock, flags);
68054
68055 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68056 done:
68057 lock_acquired(&lock->dep_map, ip);
68058 /* got the lock - rejoice! */
68059 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68060 + mutex_remove_waiter(lock, &waiter, task);
68061 mutex_set_owner(lock);
68062
68063 /* set it to 0 if there are no waiters left: */
68064 diff --git a/kernel/panic.c b/kernel/panic.c
68065 index d2a5f4e..5edc1d9 100644
68066 --- a/kernel/panic.c
68067 +++ b/kernel/panic.c
68068 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68069 int state = 0;
68070
68071 /*
68072 + * Disable local interrupts. This will prevent panic_smp_self_stop
68073 + * from deadlocking the first cpu that invokes the panic, since
68074 + * there is nothing to prevent an interrupt handler (that runs
68075 + * after the panic_lock is acquired) from invoking panic again.
68076 + */
68077 + local_irq_disable();
68078 +
68079 + /*
68080 * It's possible to come here directly from a panic-assertion and
68081 * not have preempt disabled. Some functions called from here want
68082 * preempt to be disabled. No point enabling it later though...
68083 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68084 const char *board;
68085
68086 printk(KERN_WARNING "------------[ cut here ]------------\n");
68087 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68088 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68089 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68090 if (board)
68091 printk(KERN_WARNING "Hardware name: %s\n", board);
68092 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68093 */
68094 void __stack_chk_fail(void)
68095 {
68096 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68097 + dump_stack();
68098 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68099 __builtin_return_address(0));
68100 }
68101 EXPORT_SYMBOL(__stack_chk_fail);
68102 diff --git a/kernel/pid.c b/kernel/pid.c
68103 index e86b291a..e8b0fb5 100644
68104 --- a/kernel/pid.c
68105 +++ b/kernel/pid.c
68106 @@ -33,6 +33,7 @@
68107 #include <linux/rculist.h>
68108 #include <linux/bootmem.h>
68109 #include <linux/hash.h>
68110 +#include <linux/security.h>
68111 #include <linux/pid_namespace.h>
68112 #include <linux/init_task.h>
68113 #include <linux/syscalls.h>
68114 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68115
68116 int pid_max = PID_MAX_DEFAULT;
68117
68118 -#define RESERVED_PIDS 300
68119 +#define RESERVED_PIDS 500
68120
68121 int pid_max_min = RESERVED_PIDS + 1;
68122 int pid_max_max = PID_MAX_LIMIT;
68123 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68124 */
68125 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68126 {
68127 + struct task_struct *task;
68128 +
68129 rcu_lockdep_assert(rcu_read_lock_held(),
68130 "find_task_by_pid_ns() needs rcu_read_lock()"
68131 " protection");
68132 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68133 +
68134 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68135 +
68136 + if (gr_pid_is_chrooted(task))
68137 + return NULL;
68138 +
68139 + return task;
68140 }
68141
68142 struct task_struct *find_task_by_vpid(pid_t vnr)
68143 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68144 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68145 }
68146
68147 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68148 +{
68149 + rcu_lockdep_assert(rcu_read_lock_held(),
68150 + "find_task_by_pid_ns() needs rcu_read_lock()"
68151 + " protection");
68152 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68153 +}
68154 +
68155 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68156 {
68157 struct pid *pid;
68158 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68159 index 125cb67..a4d1c30 100644
68160 --- a/kernel/posix-cpu-timers.c
68161 +++ b/kernel/posix-cpu-timers.c
68162 @@ -6,6 +6,7 @@
68163 #include <linux/posix-timers.h>
68164 #include <linux/errno.h>
68165 #include <linux/math64.h>
68166 +#include <linux/security.h>
68167 #include <asm/uaccess.h>
68168 #include <linux/kernel_stat.h>
68169 #include <trace/events/timer.h>
68170 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68171
68172 static __init int init_posix_cpu_timers(void)
68173 {
68174 - struct k_clock process = {
68175 + static struct k_clock process = {
68176 .clock_getres = process_cpu_clock_getres,
68177 .clock_get = process_cpu_clock_get,
68178 .timer_create = process_cpu_timer_create,
68179 .nsleep = process_cpu_nsleep,
68180 .nsleep_restart = process_cpu_nsleep_restart,
68181 };
68182 - struct k_clock thread = {
68183 + static struct k_clock thread = {
68184 .clock_getres = thread_cpu_clock_getres,
68185 .clock_get = thread_cpu_clock_get,
68186 .timer_create = thread_cpu_timer_create,
68187 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68188 index 69185ae..cc2847a 100644
68189 --- a/kernel/posix-timers.c
68190 +++ b/kernel/posix-timers.c
68191 @@ -43,6 +43,7 @@
68192 #include <linux/idr.h>
68193 #include <linux/posix-clock.h>
68194 #include <linux/posix-timers.h>
68195 +#include <linux/grsecurity.h>
68196 #include <linux/syscalls.h>
68197 #include <linux/wait.h>
68198 #include <linux/workqueue.h>
68199 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68200 * which we beg off on and pass to do_sys_settimeofday().
68201 */
68202
68203 -static struct k_clock posix_clocks[MAX_CLOCKS];
68204 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68205
68206 /*
68207 * These ones are defined below.
68208 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68209 */
68210 static __init int init_posix_timers(void)
68211 {
68212 - struct k_clock clock_realtime = {
68213 + static struct k_clock clock_realtime = {
68214 .clock_getres = hrtimer_get_res,
68215 .clock_get = posix_clock_realtime_get,
68216 .clock_set = posix_clock_realtime_set,
68217 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68218 .timer_get = common_timer_get,
68219 .timer_del = common_timer_del,
68220 };
68221 - struct k_clock clock_monotonic = {
68222 + static struct k_clock clock_monotonic = {
68223 .clock_getres = hrtimer_get_res,
68224 .clock_get = posix_ktime_get_ts,
68225 .nsleep = common_nsleep,
68226 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68227 .timer_get = common_timer_get,
68228 .timer_del = common_timer_del,
68229 };
68230 - struct k_clock clock_monotonic_raw = {
68231 + static struct k_clock clock_monotonic_raw = {
68232 .clock_getres = hrtimer_get_res,
68233 .clock_get = posix_get_monotonic_raw,
68234 };
68235 - struct k_clock clock_realtime_coarse = {
68236 + static struct k_clock clock_realtime_coarse = {
68237 .clock_getres = posix_get_coarse_res,
68238 .clock_get = posix_get_realtime_coarse,
68239 };
68240 - struct k_clock clock_monotonic_coarse = {
68241 + static struct k_clock clock_monotonic_coarse = {
68242 .clock_getres = posix_get_coarse_res,
68243 .clock_get = posix_get_monotonic_coarse,
68244 };
68245 - struct k_clock clock_boottime = {
68246 + static struct k_clock clock_boottime = {
68247 .clock_getres = hrtimer_get_res,
68248 .clock_get = posix_get_boottime,
68249 .nsleep = common_nsleep,
68250 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68251 return;
68252 }
68253
68254 - posix_clocks[clock_id] = *new_clock;
68255 + posix_clocks[clock_id] = new_clock;
68256 }
68257 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68258
68259 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68260 return (id & CLOCKFD_MASK) == CLOCKFD ?
68261 &clock_posix_dynamic : &clock_posix_cpu;
68262
68263 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68264 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68265 return NULL;
68266 - return &posix_clocks[id];
68267 + return posix_clocks[id];
68268 }
68269
68270 static int common_timer_create(struct k_itimer *new_timer)
68271 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68272 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68273 return -EFAULT;
68274
68275 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68276 + have their clock_set fptr set to a nosettime dummy function
68277 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68278 + call common_clock_set, which calls do_sys_settimeofday, which
68279 + we hook
68280 + */
68281 +
68282 return kc->clock_set(which_clock, &new_tp);
68283 }
68284
68285 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68286 index d523593..68197a4 100644
68287 --- a/kernel/power/poweroff.c
68288 +++ b/kernel/power/poweroff.c
68289 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68290 .enable_mask = SYSRQ_ENABLE_BOOT,
68291 };
68292
68293 -static int pm_sysrq_init(void)
68294 +static int __init pm_sysrq_init(void)
68295 {
68296 register_sysrq_key('o', &sysrq_poweroff_op);
68297 return 0;
68298 diff --git a/kernel/power/process.c b/kernel/power/process.c
68299 index 19db29f..33b52b6 100644
68300 --- a/kernel/power/process.c
68301 +++ b/kernel/power/process.c
68302 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68303 u64 elapsed_csecs64;
68304 unsigned int elapsed_csecs;
68305 bool wakeup = false;
68306 + bool timedout = false;
68307
68308 do_gettimeofday(&start);
68309
68310 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68311
68312 while (true) {
68313 todo = 0;
68314 + if (time_after(jiffies, end_time))
68315 + timedout = true;
68316 read_lock(&tasklist_lock);
68317 do_each_thread(g, p) {
68318 if (p == current || !freeze_task(p))
68319 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68320 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68321 * transition can't race with task state testing here.
68322 */
68323 - if (!task_is_stopped_or_traced(p) &&
68324 - !freezer_should_skip(p))
68325 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68326 todo++;
68327 + if (timedout) {
68328 + printk(KERN_ERR "Task refusing to freeze:\n");
68329 + sched_show_task(p);
68330 + }
68331 + }
68332 } while_each_thread(g, p);
68333 read_unlock(&tasklist_lock);
68334
68335 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68336 todo += wq_busy;
68337 }
68338
68339 - if (!todo || time_after(jiffies, end_time))
68340 + if (!todo || timedout)
68341 break;
68342
68343 if (pm_wakeup_pending()) {
68344 diff --git a/kernel/printk.c b/kernel/printk.c
68345 index ac4bc9e..1d2db99 100644
68346 --- a/kernel/printk.c
68347 +++ b/kernel/printk.c
68348 @@ -781,6 +781,11 @@ static int check_syslog_permissions(int type, bool from_file)
68349 if (from_file && type != SYSLOG_ACTION_OPEN)
68350 return 0;
68351
68352 +#ifdef CONFIG_GRKERNSEC_DMESG
68353 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68354 + return -EPERM;
68355 +#endif
68356 +
68357 if (syslog_action_restricted(type)) {
68358 if (capable(CAP_SYSLOG))
68359 return 0;
68360 diff --git a/kernel/profile.c b/kernel/profile.c
68361 index 76b8e77..a2930e8 100644
68362 --- a/kernel/profile.c
68363 +++ b/kernel/profile.c
68364 @@ -39,7 +39,7 @@ struct profile_hit {
68365 /* Oprofile timer tick hook */
68366 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68367
68368 -static atomic_t *prof_buffer;
68369 +static atomic_unchecked_t *prof_buffer;
68370 static unsigned long prof_len, prof_shift;
68371
68372 int prof_on __read_mostly;
68373 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68374 hits[i].pc = 0;
68375 continue;
68376 }
68377 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68378 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68379 hits[i].hits = hits[i].pc = 0;
68380 }
68381 }
68382 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68383 * Add the current hit(s) and flush the write-queue out
68384 * to the global buffer:
68385 */
68386 - atomic_add(nr_hits, &prof_buffer[pc]);
68387 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68388 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68389 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68390 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68391 hits[i].pc = hits[i].hits = 0;
68392 }
68393 out:
68394 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68395 {
68396 unsigned long pc;
68397 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68398 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68399 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68400 }
68401 #endif /* !CONFIG_SMP */
68402
68403 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68404 return -EFAULT;
68405 buf++; p++; count--; read++;
68406 }
68407 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68408 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68409 if (copy_to_user(buf, (void *)pnt, count))
68410 return -EFAULT;
68411 read += count;
68412 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68413 }
68414 #endif
68415 profile_discard_flip_buffers();
68416 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68417 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68418 return count;
68419 }
68420
68421 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68422 index a232bb5..2a65ef9 100644
68423 --- a/kernel/ptrace.c
68424 +++ b/kernel/ptrace.c
68425 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68426
68427 if (seize)
68428 flags |= PT_SEIZED;
68429 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68430 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68431 flags |= PT_PTRACE_CAP;
68432 task->ptrace = flags;
68433
68434 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68435 break;
68436 return -EIO;
68437 }
68438 - if (copy_to_user(dst, buf, retval))
68439 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68440 return -EFAULT;
68441 copied += retval;
68442 src += retval;
68443 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68444 bool seized = child->ptrace & PT_SEIZED;
68445 int ret = -EIO;
68446 siginfo_t siginfo, *si;
68447 - void __user *datavp = (void __user *) data;
68448 + void __user *datavp = (__force void __user *) data;
68449 unsigned long __user *datalp = datavp;
68450 unsigned long flags;
68451
68452 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68453 goto out;
68454 }
68455
68456 + if (gr_handle_ptrace(child, request)) {
68457 + ret = -EPERM;
68458 + goto out_put_task_struct;
68459 + }
68460 +
68461 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68462 ret = ptrace_attach(child, request, addr, data);
68463 /*
68464 * Some architectures need to do book-keeping after
68465 * a ptrace attach.
68466 */
68467 - if (!ret)
68468 + if (!ret) {
68469 arch_ptrace_attach(child);
68470 + gr_audit_ptrace(child);
68471 + }
68472 goto out_put_task_struct;
68473 }
68474
68475 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68476 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68477 if (copied != sizeof(tmp))
68478 return -EIO;
68479 - return put_user(tmp, (unsigned long __user *)data);
68480 + return put_user(tmp, (__force unsigned long __user *)data);
68481 }
68482
68483 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68484 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68485 goto out;
68486 }
68487
68488 + if (gr_handle_ptrace(child, request)) {
68489 + ret = -EPERM;
68490 + goto out_put_task_struct;
68491 + }
68492 +
68493 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68494 ret = ptrace_attach(child, request, addr, data);
68495 /*
68496 * Some architectures need to do book-keeping after
68497 * a ptrace attach.
68498 */
68499 - if (!ret)
68500 + if (!ret) {
68501 arch_ptrace_attach(child);
68502 + gr_audit_ptrace(child);
68503 + }
68504 goto out_put_task_struct;
68505 }
68506
68507 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68508 index 37a5444..eec170a 100644
68509 --- a/kernel/rcutiny.c
68510 +++ b/kernel/rcutiny.c
68511 @@ -46,7 +46,7 @@
68512 struct rcu_ctrlblk;
68513 static void invoke_rcu_callbacks(void);
68514 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68515 -static void rcu_process_callbacks(struct softirq_action *unused);
68516 +static void rcu_process_callbacks(void);
68517 static void __call_rcu(struct rcu_head *head,
68518 void (*func)(struct rcu_head *rcu),
68519 struct rcu_ctrlblk *rcp);
68520 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68521 rcu_is_callbacks_kthread()));
68522 }
68523
68524 -static void rcu_process_callbacks(struct softirq_action *unused)
68525 +static void rcu_process_callbacks(void)
68526 {
68527 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68528 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68529 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68530 index fc31a2d..be2ec04 100644
68531 --- a/kernel/rcutiny_plugin.h
68532 +++ b/kernel/rcutiny_plugin.h
68533 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68534 have_rcu_kthread_work = morework;
68535 local_irq_restore(flags);
68536 if (work)
68537 - rcu_process_callbacks(NULL);
68538 + rcu_process_callbacks();
68539 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68540 }
68541
68542 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68543 index e66b34a..4b8b626 100644
68544 --- a/kernel/rcutorture.c
68545 +++ b/kernel/rcutorture.c
68546 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68547 { 0 };
68548 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68549 { 0 };
68550 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68551 -static atomic_t n_rcu_torture_alloc;
68552 -static atomic_t n_rcu_torture_alloc_fail;
68553 -static atomic_t n_rcu_torture_free;
68554 -static atomic_t n_rcu_torture_mberror;
68555 -static atomic_t n_rcu_torture_error;
68556 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68557 +static atomic_unchecked_t n_rcu_torture_alloc;
68558 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68559 +static atomic_unchecked_t n_rcu_torture_free;
68560 +static atomic_unchecked_t n_rcu_torture_mberror;
68561 +static atomic_unchecked_t n_rcu_torture_error;
68562 static long n_rcu_torture_barrier_error;
68563 static long n_rcu_torture_boost_ktrerror;
68564 static long n_rcu_torture_boost_rterror;
68565 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68566
68567 spin_lock_bh(&rcu_torture_lock);
68568 if (list_empty(&rcu_torture_freelist)) {
68569 - atomic_inc(&n_rcu_torture_alloc_fail);
68570 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68571 spin_unlock_bh(&rcu_torture_lock);
68572 return NULL;
68573 }
68574 - atomic_inc(&n_rcu_torture_alloc);
68575 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68576 p = rcu_torture_freelist.next;
68577 list_del_init(p);
68578 spin_unlock_bh(&rcu_torture_lock);
68579 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68580 static void
68581 rcu_torture_free(struct rcu_torture *p)
68582 {
68583 - atomic_inc(&n_rcu_torture_free);
68584 + atomic_inc_unchecked(&n_rcu_torture_free);
68585 spin_lock_bh(&rcu_torture_lock);
68586 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68587 spin_unlock_bh(&rcu_torture_lock);
68588 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68589 i = rp->rtort_pipe_count;
68590 if (i > RCU_TORTURE_PIPE_LEN)
68591 i = RCU_TORTURE_PIPE_LEN;
68592 - atomic_inc(&rcu_torture_wcount[i]);
68593 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68594 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68595 rp->rtort_mbtest = 0;
68596 rcu_torture_free(rp);
68597 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68598 i = rp->rtort_pipe_count;
68599 if (i > RCU_TORTURE_PIPE_LEN)
68600 i = RCU_TORTURE_PIPE_LEN;
68601 - atomic_inc(&rcu_torture_wcount[i]);
68602 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68603 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68604 rp->rtort_mbtest = 0;
68605 list_del(&rp->rtort_free);
68606 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68607 i = old_rp->rtort_pipe_count;
68608 if (i > RCU_TORTURE_PIPE_LEN)
68609 i = RCU_TORTURE_PIPE_LEN;
68610 - atomic_inc(&rcu_torture_wcount[i]);
68611 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68612 old_rp->rtort_pipe_count++;
68613 cur_ops->deferred_free(old_rp);
68614 }
68615 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68616 }
68617 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68618 if (p->rtort_mbtest == 0)
68619 - atomic_inc(&n_rcu_torture_mberror);
68620 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68621 spin_lock(&rand_lock);
68622 cur_ops->read_delay(&rand);
68623 n_rcu_torture_timers++;
68624 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68625 }
68626 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68627 if (p->rtort_mbtest == 0)
68628 - atomic_inc(&n_rcu_torture_mberror);
68629 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68630 cur_ops->read_delay(&rand);
68631 preempt_disable();
68632 pipe_count = p->rtort_pipe_count;
68633 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68634 rcu_torture_current,
68635 rcu_torture_current_version,
68636 list_empty(&rcu_torture_freelist),
68637 - atomic_read(&n_rcu_torture_alloc),
68638 - atomic_read(&n_rcu_torture_alloc_fail),
68639 - atomic_read(&n_rcu_torture_free),
68640 - atomic_read(&n_rcu_torture_mberror),
68641 + atomic_read_unchecked(&n_rcu_torture_alloc),
68642 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68643 + atomic_read_unchecked(&n_rcu_torture_free),
68644 + atomic_read_unchecked(&n_rcu_torture_mberror),
68645 n_rcu_torture_boost_ktrerror,
68646 n_rcu_torture_boost_rterror,
68647 n_rcu_torture_boost_failure,
68648 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68649 n_barrier_attempts,
68650 n_rcu_torture_barrier_error);
68651 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68652 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68653 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68654 n_rcu_torture_barrier_error != 0 ||
68655 n_rcu_torture_boost_ktrerror != 0 ||
68656 n_rcu_torture_boost_rterror != 0 ||
68657 n_rcu_torture_boost_failure != 0 ||
68658 i > 1) {
68659 cnt += sprintf(&page[cnt], "!!! ");
68660 - atomic_inc(&n_rcu_torture_error);
68661 + atomic_inc_unchecked(&n_rcu_torture_error);
68662 WARN_ON_ONCE(1);
68663 }
68664 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68665 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68666 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68667 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68668 cnt += sprintf(&page[cnt], " %d",
68669 - atomic_read(&rcu_torture_wcount[i]));
68670 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68671 }
68672 cnt += sprintf(&page[cnt], "\n");
68673 if (cur_ops->stats)
68674 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68675
68676 if (cur_ops->cleanup)
68677 cur_ops->cleanup();
68678 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68679 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68680 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68681 else if (n_online_successes != n_online_attempts ||
68682 n_offline_successes != n_offline_attempts)
68683 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68684
68685 rcu_torture_current = NULL;
68686 rcu_torture_current_version = 0;
68687 - atomic_set(&n_rcu_torture_alloc, 0);
68688 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68689 - atomic_set(&n_rcu_torture_free, 0);
68690 - atomic_set(&n_rcu_torture_mberror, 0);
68691 - atomic_set(&n_rcu_torture_error, 0);
68692 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68693 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68694 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68695 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68696 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68697 n_rcu_torture_barrier_error = 0;
68698 n_rcu_torture_boost_ktrerror = 0;
68699 n_rcu_torture_boost_rterror = 0;
68700 n_rcu_torture_boost_failure = 0;
68701 n_rcu_torture_boosts = 0;
68702 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68703 - atomic_set(&rcu_torture_wcount[i], 0);
68704 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68705 for_each_possible_cpu(cpu) {
68706 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68707 per_cpu(rcu_torture_count, cpu)[i] = 0;
68708 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68709 index 4b97bba..b92c9d2 100644
68710 --- a/kernel/rcutree.c
68711 +++ b/kernel/rcutree.c
68712 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68713 rcu_prepare_for_idle(smp_processor_id());
68714 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68715 smp_mb__before_atomic_inc(); /* See above. */
68716 - atomic_inc(&rdtp->dynticks);
68717 + atomic_inc_unchecked(&rdtp->dynticks);
68718 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68719 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68720 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68721
68722 /*
68723 * The idle task is not permitted to enter the idle loop while
68724 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68725 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68726 {
68727 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68728 - atomic_inc(&rdtp->dynticks);
68729 + atomic_inc_unchecked(&rdtp->dynticks);
68730 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68731 smp_mb__after_atomic_inc(); /* See above. */
68732 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68733 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68734 rcu_cleanup_after_idle(smp_processor_id());
68735 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68736 if (!is_idle_task(current)) {
68737 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68738 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68739
68740 if (rdtp->dynticks_nmi_nesting == 0 &&
68741 - (atomic_read(&rdtp->dynticks) & 0x1))
68742 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68743 return;
68744 rdtp->dynticks_nmi_nesting++;
68745 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68746 - atomic_inc(&rdtp->dynticks);
68747 + atomic_inc_unchecked(&rdtp->dynticks);
68748 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68749 smp_mb__after_atomic_inc(); /* See above. */
68750 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68751 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68752 }
68753
68754 /**
68755 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68756 return;
68757 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68758 smp_mb__before_atomic_inc(); /* See above. */
68759 - atomic_inc(&rdtp->dynticks);
68760 + atomic_inc_unchecked(&rdtp->dynticks);
68761 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68762 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68763 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68764 }
68765
68766 #ifdef CONFIG_PROVE_RCU
68767 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68768 int ret;
68769
68770 preempt_disable();
68771 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68772 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68773 preempt_enable();
68774 return ret;
68775 }
68776 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68777 */
68778 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68779 {
68780 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68781 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68782 return (rdp->dynticks_snap & 0x1) == 0;
68783 }
68784
68785 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68786 unsigned int curr;
68787 unsigned int snap;
68788
68789 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68790 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68791 snap = (unsigned int)rdp->dynticks_snap;
68792
68793 /*
68794 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68795 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68796 */
68797 if (till_stall_check < 3) {
68798 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68799 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68800 till_stall_check = 3;
68801 } else if (till_stall_check > 300) {
68802 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68803 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68804 till_stall_check = 300;
68805 }
68806 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68807 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68808 /*
68809 * Do RCU core processing for the current CPU.
68810 */
68811 -static void rcu_process_callbacks(struct softirq_action *unused)
68812 +static void rcu_process_callbacks(void)
68813 {
68814 trace_rcu_utilization("Start RCU core");
68815 __rcu_process_callbacks(&rcu_sched_state,
68816 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68817 }
68818 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68819
68820 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68821 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68822 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68823 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68824
68825 static int synchronize_sched_expedited_cpu_stop(void *data)
68826 {
68827 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68828 int firstsnap, s, snap, trycount = 0;
68829
68830 /* Note that atomic_inc_return() implies full memory barrier. */
68831 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68832 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68833 get_online_cpus();
68834 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68835
68836 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68837 }
68838
68839 /* Check to see if someone else did our work for us. */
68840 - s = atomic_read(&sync_sched_expedited_done);
68841 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68842 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68843 smp_mb(); /* ensure test happens before caller kfree */
68844 return;
68845 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68846 * grace period works for us.
68847 */
68848 get_online_cpus();
68849 - snap = atomic_read(&sync_sched_expedited_started);
68850 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68851 smp_mb(); /* ensure read is before try_stop_cpus(). */
68852 }
68853
68854 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68855 * than we did beat us to the punch.
68856 */
68857 do {
68858 - s = atomic_read(&sync_sched_expedited_done);
68859 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68860 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68861 smp_mb(); /* ensure test happens before caller kfree */
68862 break;
68863 }
68864 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68865 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68866
68867 put_online_cpus();
68868 }
68869 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68870 rdp->qlen = 0;
68871 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68872 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68873 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68874 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68875 rdp->cpu = cpu;
68876 rdp->rsp = rsp;
68877 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68878 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68879 rdp->n_force_qs_snap = rsp->n_force_qs;
68880 rdp->blimit = blimit;
68881 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68882 - atomic_set(&rdp->dynticks->dynticks,
68883 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68884 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68885 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68886 rcu_prepare_for_idle_init(cpu);
68887 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68888
68889 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68890 index 19b61ac..5c60a94 100644
68891 --- a/kernel/rcutree.h
68892 +++ b/kernel/rcutree.h
68893 @@ -83,7 +83,7 @@ struct rcu_dynticks {
68894 long long dynticks_nesting; /* Track irq/process nesting level. */
68895 /* Process level is worth LLONG_MAX/2. */
68896 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68897 - atomic_t dynticks; /* Even value for idle, else odd. */
68898 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68899 #ifdef CONFIG_RCU_FAST_NO_HZ
68900 int dyntick_drain; /* Prepare-for-idle state variable. */
68901 unsigned long dyntick_holdoff;
68902 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68903 index 3e48994..d94f03a 100644
68904 --- a/kernel/rcutree_plugin.h
68905 +++ b/kernel/rcutree_plugin.h
68906 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68907
68908 /* Clean up and exit. */
68909 smp_mb(); /* ensure expedited GP seen before counter increment. */
68910 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68911 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68912 unlock_mb_ret:
68913 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68914 mb_ret:
68915 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68916 index d4bc16d..c234a5c 100644
68917 --- a/kernel/rcutree_trace.c
68918 +++ b/kernel/rcutree_trace.c
68919 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68920 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68921 rdp->qs_pending);
68922 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68923 - atomic_read(&rdp->dynticks->dynticks),
68924 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68925 rdp->dynticks->dynticks_nesting,
68926 rdp->dynticks->dynticks_nmi_nesting,
68927 rdp->dynticks_fqs);
68928 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68929 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68930 rdp->qs_pending);
68931 seq_printf(m, ",%d,%llx,%d,%lu",
68932 - atomic_read(&rdp->dynticks->dynticks),
68933 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68934 rdp->dynticks->dynticks_nesting,
68935 rdp->dynticks->dynticks_nmi_nesting,
68936 rdp->dynticks_fqs);
68937 diff --git a/kernel/resource.c b/kernel/resource.c
68938 index e1d2b8e..24820bb 100644
68939 --- a/kernel/resource.c
68940 +++ b/kernel/resource.c
68941 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68942
68943 static int __init ioresources_init(void)
68944 {
68945 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68946 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68947 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68948 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68949 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68950 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68951 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68952 +#endif
68953 +#else
68954 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68955 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68956 +#endif
68957 return 0;
68958 }
68959 __initcall(ioresources_init);
68960 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68961 index 98ec494..4241d6d 100644
68962 --- a/kernel/rtmutex-tester.c
68963 +++ b/kernel/rtmutex-tester.c
68964 @@ -20,7 +20,7 @@
68965 #define MAX_RT_TEST_MUTEXES 8
68966
68967 static spinlock_t rttest_lock;
68968 -static atomic_t rttest_event;
68969 +static atomic_unchecked_t rttest_event;
68970
68971 struct test_thread_data {
68972 int opcode;
68973 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68974
68975 case RTTEST_LOCKCONT:
68976 td->mutexes[td->opdata] = 1;
68977 - td->event = atomic_add_return(1, &rttest_event);
68978 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68979 return 0;
68980
68981 case RTTEST_RESET:
68982 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68983 return 0;
68984
68985 case RTTEST_RESETEVENT:
68986 - atomic_set(&rttest_event, 0);
68987 + atomic_set_unchecked(&rttest_event, 0);
68988 return 0;
68989
68990 default:
68991 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68992 return ret;
68993
68994 td->mutexes[id] = 1;
68995 - td->event = atomic_add_return(1, &rttest_event);
68996 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68997 rt_mutex_lock(&mutexes[id]);
68998 - td->event = atomic_add_return(1, &rttest_event);
68999 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69000 td->mutexes[id] = 4;
69001 return 0;
69002
69003 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69004 return ret;
69005
69006 td->mutexes[id] = 1;
69007 - td->event = atomic_add_return(1, &rttest_event);
69008 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69009 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69010 - td->event = atomic_add_return(1, &rttest_event);
69011 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69012 td->mutexes[id] = ret ? 0 : 4;
69013 return ret ? -EINTR : 0;
69014
69015 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69016 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69017 return ret;
69018
69019 - td->event = atomic_add_return(1, &rttest_event);
69020 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69021 rt_mutex_unlock(&mutexes[id]);
69022 - td->event = atomic_add_return(1, &rttest_event);
69023 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69024 td->mutexes[id] = 0;
69025 return 0;
69026
69027 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69028 break;
69029
69030 td->mutexes[dat] = 2;
69031 - td->event = atomic_add_return(1, &rttest_event);
69032 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69033 break;
69034
69035 default:
69036 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69037 return;
69038
69039 td->mutexes[dat] = 3;
69040 - td->event = atomic_add_return(1, &rttest_event);
69041 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69042 break;
69043
69044 case RTTEST_LOCKNOWAIT:
69045 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69046 return;
69047
69048 td->mutexes[dat] = 1;
69049 - td->event = atomic_add_return(1, &rttest_event);
69050 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69051 return;
69052
69053 default:
69054 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69055 index 0984a21..939f183 100644
69056 --- a/kernel/sched/auto_group.c
69057 +++ b/kernel/sched/auto_group.c
69058 @@ -11,7 +11,7 @@
69059
69060 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69061 static struct autogroup autogroup_default;
69062 -static atomic_t autogroup_seq_nr;
69063 +static atomic_unchecked_t autogroup_seq_nr;
69064
69065 void __init autogroup_init(struct task_struct *init_task)
69066 {
69067 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69068
69069 kref_init(&ag->kref);
69070 init_rwsem(&ag->lock);
69071 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69072 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69073 ag->tg = tg;
69074 #ifdef CONFIG_RT_GROUP_SCHED
69075 /*
69076 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69077 index 468bdd4..b941572 100644
69078 --- a/kernel/sched/core.c
69079 +++ b/kernel/sched/core.c
69080 @@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69081 /* convert nice value [19,-20] to rlimit style value [1,40] */
69082 int nice_rlim = 20 - nice;
69083
69084 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69085 +
69086 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69087 capable(CAP_SYS_NICE));
69088 }
69089 @@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69090 if (nice > 19)
69091 nice = 19;
69092
69093 - if (increment < 0 && !can_nice(current, nice))
69094 + if (increment < 0 && (!can_nice(current, nice) ||
69095 + gr_handle_chroot_nice()))
69096 return -EPERM;
69097
69098 retval = security_task_setnice(current, nice);
69099 @@ -4284,6 +4287,7 @@ recheck:
69100 unsigned long rlim_rtprio =
69101 task_rlimit(p, RLIMIT_RTPRIO);
69102
69103 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69104 /* can't set/change the rt policy */
69105 if (policy != p->policy && !rlim_rtprio)
69106 return -EPERM;
69107 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69108 index c099cc6..06aec4f 100644
69109 --- a/kernel/sched/fair.c
69110 +++ b/kernel/sched/fair.c
69111 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69112 * run_rebalance_domains is triggered when needed from the scheduler tick.
69113 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69114 */
69115 -static void run_rebalance_domains(struct softirq_action *h)
69116 +static void run_rebalance_domains(void)
69117 {
69118 int this_cpu = smp_processor_id();
69119 struct rq *this_rq = cpu_rq(this_cpu);
69120 diff --git a/kernel/signal.c b/kernel/signal.c
69121 index 6771027..763e51e 100644
69122 --- a/kernel/signal.c
69123 +++ b/kernel/signal.c
69124 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69125
69126 int print_fatal_signals __read_mostly;
69127
69128 -static void __user *sig_handler(struct task_struct *t, int sig)
69129 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69130 {
69131 return t->sighand->action[sig - 1].sa.sa_handler;
69132 }
69133
69134 -static int sig_handler_ignored(void __user *handler, int sig)
69135 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69136 {
69137 /* Is it explicitly or implicitly ignored? */
69138 return handler == SIG_IGN ||
69139 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69140
69141 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69142 {
69143 - void __user *handler;
69144 + __sighandler_t handler;
69145
69146 handler = sig_handler(t, sig);
69147
69148 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69149 atomic_inc(&user->sigpending);
69150 rcu_read_unlock();
69151
69152 + if (!override_rlimit)
69153 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69154 +
69155 if (override_rlimit ||
69156 atomic_read(&user->sigpending) <=
69157 task_rlimit(t, RLIMIT_SIGPENDING)) {
69158 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69159
69160 int unhandled_signal(struct task_struct *tsk, int sig)
69161 {
69162 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69163 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69164 if (is_global_init(tsk))
69165 return 1;
69166 if (handler != SIG_IGN && handler != SIG_DFL)
69167 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69168 }
69169 }
69170
69171 + /* allow glibc communication via tgkill to other threads in our
69172 + thread group */
69173 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69174 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69175 + && gr_handle_signal(t, sig))
69176 + return -EPERM;
69177 +
69178 return security_task_kill(t, info, sig, 0);
69179 }
69180
69181 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69182 return send_signal(sig, info, p, 1);
69183 }
69184
69185 -static int
69186 +int
69187 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69188 {
69189 return send_signal(sig, info, t, 0);
69190 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69191 unsigned long int flags;
69192 int ret, blocked, ignored;
69193 struct k_sigaction *action;
69194 + int is_unhandled = 0;
69195
69196 spin_lock_irqsave(&t->sighand->siglock, flags);
69197 action = &t->sighand->action[sig-1];
69198 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69199 }
69200 if (action->sa.sa_handler == SIG_DFL)
69201 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69202 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69203 + is_unhandled = 1;
69204 ret = specific_send_sig_info(sig, info, t);
69205 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69206
69207 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69208 + normal operation */
69209 + if (is_unhandled) {
69210 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69211 + gr_handle_crash(t, sig);
69212 + }
69213 +
69214 return ret;
69215 }
69216
69217 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69218 ret = check_kill_permission(sig, info, p);
69219 rcu_read_unlock();
69220
69221 - if (!ret && sig)
69222 + if (!ret && sig) {
69223 ret = do_send_sig_info(sig, info, p, true);
69224 + if (!ret)
69225 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69226 + }
69227
69228 return ret;
69229 }
69230 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69231 int error = -ESRCH;
69232
69233 rcu_read_lock();
69234 - p = find_task_by_vpid(pid);
69235 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69236 + /* allow glibc communication via tgkill to other threads in our
69237 + thread group */
69238 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69239 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69240 + p = find_task_by_vpid_unrestricted(pid);
69241 + else
69242 +#endif
69243 + p = find_task_by_vpid(pid);
69244 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69245 error = check_kill_permission(sig, info, p);
69246 /*
69247 diff --git a/kernel/smp.c b/kernel/smp.c
69248 index d0ae5b2..b87c5a8 100644
69249 --- a/kernel/smp.c
69250 +++ b/kernel/smp.c
69251 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69252 }
69253 EXPORT_SYMBOL(smp_call_function);
69254
69255 -void ipi_call_lock(void)
69256 +void ipi_call_lock(void) __acquires(call_function.lock)
69257 {
69258 raw_spin_lock(&call_function.lock);
69259 }
69260
69261 -void ipi_call_unlock(void)
69262 +void ipi_call_unlock(void) __releases(call_function.lock)
69263 {
69264 raw_spin_unlock(&call_function.lock);
69265 }
69266
69267 -void ipi_call_lock_irq(void)
69268 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69269 {
69270 raw_spin_lock_irq(&call_function.lock);
69271 }
69272
69273 -void ipi_call_unlock_irq(void)
69274 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69275 {
69276 raw_spin_unlock_irq(&call_function.lock);
69277 }
69278 diff --git a/kernel/softirq.c b/kernel/softirq.c
69279 index 671f959..91c51cb 100644
69280 --- a/kernel/softirq.c
69281 +++ b/kernel/softirq.c
69282 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69283
69284 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69285
69286 -char *softirq_to_name[NR_SOFTIRQS] = {
69287 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69288 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69289 "TASKLET", "SCHED", "HRTIMER", "RCU"
69290 };
69291 @@ -235,7 +235,7 @@ restart:
69292 kstat_incr_softirqs_this_cpu(vec_nr);
69293
69294 trace_softirq_entry(vec_nr);
69295 - h->action(h);
69296 + h->action();
69297 trace_softirq_exit(vec_nr);
69298 if (unlikely(prev_count != preempt_count())) {
69299 printk(KERN_ERR "huh, entered softirq %u %s %p"
69300 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69301 or_softirq_pending(1UL << nr);
69302 }
69303
69304 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69305 +void open_softirq(int nr, void (*action)(void))
69306 {
69307 - softirq_vec[nr].action = action;
69308 + pax_open_kernel();
69309 + *(void **)&softirq_vec[nr].action = action;
69310 + pax_close_kernel();
69311 }
69312
69313 /*
69314 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69315
69316 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69317
69318 -static void tasklet_action(struct softirq_action *a)
69319 +static void tasklet_action(void)
69320 {
69321 struct tasklet_struct *list;
69322
69323 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69324 }
69325 }
69326
69327 -static void tasklet_hi_action(struct softirq_action *a)
69328 +static void tasklet_hi_action(void)
69329 {
69330 struct tasklet_struct *list;
69331
69332 diff --git a/kernel/srcu.c b/kernel/srcu.c
69333 index 2095be3..9a5b89d 100644
69334 --- a/kernel/srcu.c
69335 +++ b/kernel/srcu.c
69336 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69337 preempt_disable();
69338 idx = rcu_dereference_index_check(sp->completed,
69339 rcu_read_lock_sched_held()) & 0x1;
69340 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69341 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69342 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69343 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69344 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69345 preempt_enable();
69346 return idx;
69347 }
69348 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69349 {
69350 preempt_disable();
69351 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69352 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69353 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69354 preempt_enable();
69355 }
69356 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69357 diff --git a/kernel/sys.c b/kernel/sys.c
69358 index 2d39a84..f778b49 100644
69359 --- a/kernel/sys.c
69360 +++ b/kernel/sys.c
69361 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69362 error = -EACCES;
69363 goto out;
69364 }
69365 +
69366 + if (gr_handle_chroot_setpriority(p, niceval)) {
69367 + error = -EACCES;
69368 + goto out;
69369 + }
69370 +
69371 no_nice = security_task_setnice(p, niceval);
69372 if (no_nice) {
69373 error = no_nice;
69374 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69375 goto error;
69376 }
69377
69378 + if (gr_check_group_change(new->gid, new->egid, -1))
69379 + goto error;
69380 +
69381 if (rgid != (gid_t) -1 ||
69382 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69383 new->sgid = new->egid;
69384 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69385 old = current_cred();
69386
69387 retval = -EPERM;
69388 +
69389 + if (gr_check_group_change(kgid, kgid, kgid))
69390 + goto error;
69391 +
69392 if (nsown_capable(CAP_SETGID))
69393 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69394 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69395 @@ -646,7 +659,7 @@ error:
69396 /*
69397 * change the user struct in a credentials set to match the new UID
69398 */
69399 -static int set_user(struct cred *new)
69400 +int set_user(struct cred *new)
69401 {
69402 struct user_struct *new_user;
69403
69404 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69405 goto error;
69406 }
69407
69408 + if (gr_check_user_change(new->uid, new->euid, -1))
69409 + goto error;
69410 +
69411 if (!uid_eq(new->uid, old->uid)) {
69412 retval = set_user(new);
69413 if (retval < 0)
69414 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69415 old = current_cred();
69416
69417 retval = -EPERM;
69418 +
69419 + if (gr_check_crash_uid(kuid))
69420 + goto error;
69421 + if (gr_check_user_change(kuid, kuid, kuid))
69422 + goto error;
69423 +
69424 if (nsown_capable(CAP_SETUID)) {
69425 new->suid = new->uid = kuid;
69426 if (!uid_eq(kuid, old->uid)) {
69427 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69428 goto error;
69429 }
69430
69431 + if (gr_check_user_change(kruid, keuid, -1))
69432 + goto error;
69433 +
69434 if (ruid != (uid_t) -1) {
69435 new->uid = kruid;
69436 if (!uid_eq(kruid, old->uid)) {
69437 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69438 goto error;
69439 }
69440
69441 + if (gr_check_group_change(krgid, kegid, -1))
69442 + goto error;
69443 +
69444 if (rgid != (gid_t) -1)
69445 new->gid = krgid;
69446 if (egid != (gid_t) -1)
69447 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69448 if (!uid_valid(kuid))
69449 return old_fsuid;
69450
69451 + if (gr_check_user_change(-1, -1, kuid))
69452 + goto error;
69453 +
69454 new = prepare_creds();
69455 if (!new)
69456 return old_fsuid;
69457 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69458 }
69459 }
69460
69461 +error:
69462 abort_creds(new);
69463 return old_fsuid;
69464
69465 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69466 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69467 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69468 nsown_capable(CAP_SETGID)) {
69469 + if (gr_check_group_change(-1, -1, kgid))
69470 + goto error;
69471 +
69472 if (!gid_eq(kgid, old->fsgid)) {
69473 new->fsgid = kgid;
69474 goto change_okay;
69475 }
69476 }
69477
69478 +error:
69479 abort_creds(new);
69480 return old_fsgid;
69481
69482 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69483 }
69484 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69485 snprintf(buf, len, "2.6.%u%s", v, rest);
69486 - ret = copy_to_user(release, buf, len);
69487 + if (len > sizeof(buf))
69488 + ret = -EFAULT;
69489 + else
69490 + ret = copy_to_user(release, buf, len);
69491 }
69492 return ret;
69493 }
69494 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69495 return -EFAULT;
69496
69497 down_read(&uts_sem);
69498 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69499 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69500 __OLD_UTS_LEN);
69501 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69502 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69503 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69504 __OLD_UTS_LEN);
69505 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69506 - error |= __copy_to_user(&name->release, &utsname()->release,
69507 + error |= __copy_to_user(name->release, &utsname()->release,
69508 __OLD_UTS_LEN);
69509 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69510 - error |= __copy_to_user(&name->version, &utsname()->version,
69511 + error |= __copy_to_user(name->version, &utsname()->version,
69512 __OLD_UTS_LEN);
69513 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69514 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69515 + error |= __copy_to_user(name->machine, &utsname()->machine,
69516 __OLD_UTS_LEN);
69517 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69518 up_read(&uts_sem);
69519 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69520 error = get_dumpable(me->mm);
69521 break;
69522 case PR_SET_DUMPABLE:
69523 - if (arg2 < 0 || arg2 > 1) {
69524 + if (arg2 > 1) {
69525 error = -EINVAL;
69526 break;
69527 }
69528 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69529 index 4ab1187..33f4f2b 100644
69530 --- a/kernel/sysctl.c
69531 +++ b/kernel/sysctl.c
69532 @@ -91,7 +91,6 @@
69533
69534
69535 #if defined(CONFIG_SYSCTL)
69536 -
69537 /* External variables not in a header file. */
69538 extern int sysctl_overcommit_memory;
69539 extern int sysctl_overcommit_ratio;
69540 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69541 void __user *buffer, size_t *lenp, loff_t *ppos);
69542 #endif
69543
69544 -#ifdef CONFIG_PRINTK
69545 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69546 void __user *buffer, size_t *lenp, loff_t *ppos);
69547 -#endif
69548 +
69549 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69550 + void __user *buffer, size_t *lenp, loff_t *ppos);
69551 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69552 + void __user *buffer, size_t *lenp, loff_t *ppos);
69553
69554 #ifdef CONFIG_MAGIC_SYSRQ
69555 /* Note: sysrq code uses it's own private copy */
69556 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69557
69558 #endif
69559
69560 +extern struct ctl_table grsecurity_table[];
69561 +
69562 static struct ctl_table kern_table[];
69563 static struct ctl_table vm_table[];
69564 static struct ctl_table fs_table[];
69565 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69566 int sysctl_legacy_va_layout;
69567 #endif
69568
69569 +#ifdef CONFIG_PAX_SOFTMODE
69570 +static ctl_table pax_table[] = {
69571 + {
69572 + .procname = "softmode",
69573 + .data = &pax_softmode,
69574 + .maxlen = sizeof(unsigned int),
69575 + .mode = 0600,
69576 + .proc_handler = &proc_dointvec,
69577 + },
69578 +
69579 + { }
69580 +};
69581 +#endif
69582 +
69583 /* The default sysctl tables: */
69584
69585 static struct ctl_table sysctl_base_table[] = {
69586 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69587 #endif
69588
69589 static struct ctl_table kern_table[] = {
69590 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69591 + {
69592 + .procname = "grsecurity",
69593 + .mode = 0500,
69594 + .child = grsecurity_table,
69595 + },
69596 +#endif
69597 +
69598 +#ifdef CONFIG_PAX_SOFTMODE
69599 + {
69600 + .procname = "pax",
69601 + .mode = 0500,
69602 + .child = pax_table,
69603 + },
69604 +#endif
69605 +
69606 {
69607 .procname = "sched_child_runs_first",
69608 .data = &sysctl_sched_child_runs_first,
69609 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69610 .data = core_pattern,
69611 .maxlen = CORENAME_MAX_SIZE,
69612 .mode = 0644,
69613 - .proc_handler = proc_dostring,
69614 + .proc_handler = proc_dostring_coredump,
69615 },
69616 {
69617 .procname = "core_pipe_limit",
69618 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69619 .data = &modprobe_path,
69620 .maxlen = KMOD_PATH_LEN,
69621 .mode = 0644,
69622 - .proc_handler = proc_dostring,
69623 + .proc_handler = proc_dostring_modpriv,
69624 },
69625 {
69626 .procname = "modules_disabled",
69627 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69628 .extra1 = &zero,
69629 .extra2 = &one,
69630 },
69631 +#endif
69632 {
69633 .procname = "kptr_restrict",
69634 .data = &kptr_restrict,
69635 .maxlen = sizeof(int),
69636 .mode = 0644,
69637 .proc_handler = proc_dointvec_minmax_sysadmin,
69638 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69639 + .extra1 = &two,
69640 +#else
69641 .extra1 = &zero,
69642 +#endif
69643 .extra2 = &two,
69644 },
69645 -#endif
69646 {
69647 .procname = "ngroups_max",
69648 .data = &ngroups_max,
69649 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69650 .proc_handler = proc_dointvec_minmax,
69651 .extra1 = &zero,
69652 },
69653 + {
69654 + .procname = "heap_stack_gap",
69655 + .data = &sysctl_heap_stack_gap,
69656 + .maxlen = sizeof(sysctl_heap_stack_gap),
69657 + .mode = 0644,
69658 + .proc_handler = proc_doulongvec_minmax,
69659 + },
69660 #else
69661 {
69662 .procname = "nr_trim_pages",
69663 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69664 .data = &suid_dumpable,
69665 .maxlen = sizeof(int),
69666 .mode = 0644,
69667 - .proc_handler = proc_dointvec_minmax,
69668 + .proc_handler = proc_dointvec_minmax_coredump,
69669 .extra1 = &zero,
69670 .extra2 = &two,
69671 },
69672 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69673 buffer, lenp, ppos);
69674 }
69675
69676 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69677 + void __user *buffer, size_t *lenp, loff_t *ppos)
69678 +{
69679 + if (write && !capable(CAP_SYS_MODULE))
69680 + return -EPERM;
69681 +
69682 + return _proc_do_string(table->data, table->maxlen, write,
69683 + buffer, lenp, ppos);
69684 +}
69685 +
69686 static size_t proc_skip_spaces(char **buf)
69687 {
69688 size_t ret;
69689 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69690 len = strlen(tmp);
69691 if (len > *size)
69692 len = *size;
69693 + if (len > sizeof(tmp))
69694 + len = sizeof(tmp);
69695 if (copy_to_user(*buf, tmp, len))
69696 return -EFAULT;
69697 *size -= len;
69698 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69699 return err;
69700 }
69701
69702 -#ifdef CONFIG_PRINTK
69703 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69704 void __user *buffer, size_t *lenp, loff_t *ppos)
69705 {
69706 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69707
69708 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69709 }
69710 -#endif
69711
69712 struct do_proc_dointvec_minmax_conv_param {
69713 int *min;
69714 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69715 do_proc_dointvec_minmax_conv, &param);
69716 }
69717
69718 +static void validate_coredump_safety(void)
69719 +{
69720 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69721 + core_pattern[0] != '/' && core_pattern[0] != '|') {
69722 + printk(KERN_WARNING "Unsafe core_pattern used with "\
69723 + "suid_dumpable=2. Pipe handler or fully qualified "\
69724 + "core dump path required.\n");
69725 + }
69726 +}
69727 +
69728 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69729 + void __user *buffer, size_t *lenp, loff_t *ppos)
69730 +{
69731 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69732 + if (!error)
69733 + validate_coredump_safety();
69734 + return error;
69735 +}
69736 +
69737 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69738 + void __user *buffer, size_t *lenp, loff_t *ppos)
69739 +{
69740 + int error = proc_dostring(table, write, buffer, lenp, ppos);
69741 + if (!error)
69742 + validate_coredump_safety();
69743 + return error;
69744 +}
69745 +
69746 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69747 void __user *buffer,
69748 size_t *lenp, loff_t *ppos,
69749 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69750 *i = val;
69751 } else {
69752 val = convdiv * (*i) / convmul;
69753 - if (!first)
69754 + if (!first) {
69755 err = proc_put_char(&buffer, &left, '\t');
69756 + if (err)
69757 + break;
69758 + }
69759 err = proc_put_long(&buffer, &left, val, false);
69760 if (err)
69761 break;
69762 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69763 return -ENOSYS;
69764 }
69765
69766 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69767 + void __user *buffer, size_t *lenp, loff_t *ppos)
69768 +{
69769 + return -ENOSYS;
69770 +}
69771 +
69772 int proc_dointvec(struct ctl_table *table, int write,
69773 void __user *buffer, size_t *lenp, loff_t *ppos)
69774 {
69775 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69776 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69777 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69778 EXPORT_SYMBOL(proc_dostring);
69779 +EXPORT_SYMBOL(proc_dostring_modpriv);
69780 EXPORT_SYMBOL(proc_doulongvec_minmax);
69781 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69782 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69783 index a650694..aaeeb20 100644
69784 --- a/kernel/sysctl_binary.c
69785 +++ b/kernel/sysctl_binary.c
69786 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69787 int i;
69788
69789 set_fs(KERNEL_DS);
69790 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69791 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69792 set_fs(old_fs);
69793 if (result < 0)
69794 goto out_kfree;
69795 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69796 }
69797
69798 set_fs(KERNEL_DS);
69799 - result = vfs_write(file, buffer, str - buffer, &pos);
69800 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69801 set_fs(old_fs);
69802 if (result < 0)
69803 goto out_kfree;
69804 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69805 int i;
69806
69807 set_fs(KERNEL_DS);
69808 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69809 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69810 set_fs(old_fs);
69811 if (result < 0)
69812 goto out_kfree;
69813 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69814 }
69815
69816 set_fs(KERNEL_DS);
69817 - result = vfs_write(file, buffer, str - buffer, &pos);
69818 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69819 set_fs(old_fs);
69820 if (result < 0)
69821 goto out_kfree;
69822 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69823 int i;
69824
69825 set_fs(KERNEL_DS);
69826 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69827 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69828 set_fs(old_fs);
69829 if (result < 0)
69830 goto out;
69831 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69832 __le16 dnaddr;
69833
69834 set_fs(KERNEL_DS);
69835 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69836 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69837 set_fs(old_fs);
69838 if (result < 0)
69839 goto out;
69840 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69841 le16_to_cpu(dnaddr) & 0x3ff);
69842
69843 set_fs(KERNEL_DS);
69844 - result = vfs_write(file, buf, len, &pos);
69845 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69846 set_fs(old_fs);
69847 if (result < 0)
69848 goto out;
69849 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69850 index e660464..c8b9e67 100644
69851 --- a/kernel/taskstats.c
69852 +++ b/kernel/taskstats.c
69853 @@ -27,9 +27,12 @@
69854 #include <linux/cgroup.h>
69855 #include <linux/fs.h>
69856 #include <linux/file.h>
69857 +#include <linux/grsecurity.h>
69858 #include <net/genetlink.h>
69859 #include <linux/atomic.h>
69860
69861 +extern int gr_is_taskstats_denied(int pid);
69862 +
69863 /*
69864 * Maximum length of a cpumask that can be specified in
69865 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69866 @@ -556,6 +559,9 @@ err:
69867
69868 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69869 {
69870 + if (gr_is_taskstats_denied(current->pid))
69871 + return -EACCES;
69872 +
69873 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69874 return cmd_attr_register_cpumask(info);
69875 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69876 diff --git a/kernel/time.c b/kernel/time.c
69877 index ba744cf..267b7c5 100644
69878 --- a/kernel/time.c
69879 +++ b/kernel/time.c
69880 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69881 return error;
69882
69883 if (tz) {
69884 + /* we log in do_settimeofday called below, so don't log twice
69885 + */
69886 + if (!tv)
69887 + gr_log_timechange();
69888 +
69889 sys_tz = *tz;
69890 update_vsyscall_tz();
69891 if (firsttime) {
69892 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69893 index aa27d39..34d221c 100644
69894 --- a/kernel/time/alarmtimer.c
69895 +++ b/kernel/time/alarmtimer.c
69896 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69897 struct platform_device *pdev;
69898 int error = 0;
69899 int i;
69900 - struct k_clock alarm_clock = {
69901 + static struct k_clock alarm_clock = {
69902 .clock_getres = alarm_clock_getres,
69903 .clock_get = alarm_clock_get,
69904 .timer_create = alarm_timer_create,
69905 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69906 index f113755..ec24223 100644
69907 --- a/kernel/time/tick-broadcast.c
69908 +++ b/kernel/time/tick-broadcast.c
69909 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69910 * then clear the broadcast bit.
69911 */
69912 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69913 - int cpu = smp_processor_id();
69914 + cpu = smp_processor_id();
69915
69916 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69917 tick_broadcast_clear_oneshot(cpu);
69918 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69919 index 3447cfa..291806b 100644
69920 --- a/kernel/time/timekeeping.c
69921 +++ b/kernel/time/timekeeping.c
69922 @@ -14,6 +14,7 @@
69923 #include <linux/init.h>
69924 #include <linux/mm.h>
69925 #include <linux/sched.h>
69926 +#include <linux/grsecurity.h>
69927 #include <linux/syscore_ops.h>
69928 #include <linux/clocksource.h>
69929 #include <linux/jiffies.h>
69930 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
69931 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69932 return -EINVAL;
69933
69934 + gr_log_timechange();
69935 +
69936 write_seqlock_irqsave(&timekeeper.lock, flags);
69937
69938 timekeeping_forward_now();
69939 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69940 index 3258455..f35227d 100644
69941 --- a/kernel/time/timer_list.c
69942 +++ b/kernel/time/timer_list.c
69943 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69944
69945 static void print_name_offset(struct seq_file *m, void *sym)
69946 {
69947 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69948 + SEQ_printf(m, "<%p>", NULL);
69949 +#else
69950 char symname[KSYM_NAME_LEN];
69951
69952 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69953 SEQ_printf(m, "<%pK>", sym);
69954 else
69955 SEQ_printf(m, "%s", symname);
69956 +#endif
69957 }
69958
69959 static void
69960 @@ -112,7 +116,11 @@ next_one:
69961 static void
69962 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69963 {
69964 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69965 + SEQ_printf(m, " .base: %p\n", NULL);
69966 +#else
69967 SEQ_printf(m, " .base: %pK\n", base);
69968 +#endif
69969 SEQ_printf(m, " .index: %d\n",
69970 base->index);
69971 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69972 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69973 {
69974 struct proc_dir_entry *pe;
69975
69976 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69977 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69978 +#else
69979 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69980 +#endif
69981 if (!pe)
69982 return -ENOMEM;
69983 return 0;
69984 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69985 index 0b537f2..9e71eca 100644
69986 --- a/kernel/time/timer_stats.c
69987 +++ b/kernel/time/timer_stats.c
69988 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69989 static unsigned long nr_entries;
69990 static struct entry entries[MAX_ENTRIES];
69991
69992 -static atomic_t overflow_count;
69993 +static atomic_unchecked_t overflow_count;
69994
69995 /*
69996 * The entries are in a hash-table, for fast lookup:
69997 @@ -140,7 +140,7 @@ static void reset_entries(void)
69998 nr_entries = 0;
69999 memset(entries, 0, sizeof(entries));
70000 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70001 - atomic_set(&overflow_count, 0);
70002 + atomic_set_unchecked(&overflow_count, 0);
70003 }
70004
70005 static struct entry *alloc_entry(void)
70006 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70007 if (likely(entry))
70008 entry->count++;
70009 else
70010 - atomic_inc(&overflow_count);
70011 + atomic_inc_unchecked(&overflow_count);
70012
70013 out_unlock:
70014 raw_spin_unlock_irqrestore(lock, flags);
70015 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70016
70017 static void print_name_offset(struct seq_file *m, unsigned long addr)
70018 {
70019 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70020 + seq_printf(m, "<%p>", NULL);
70021 +#else
70022 char symname[KSYM_NAME_LEN];
70023
70024 if (lookup_symbol_name(addr, symname) < 0)
70025 seq_printf(m, "<%p>", (void *)addr);
70026 else
70027 seq_printf(m, "%s", symname);
70028 +#endif
70029 }
70030
70031 static int tstats_show(struct seq_file *m, void *v)
70032 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70033
70034 seq_puts(m, "Timer Stats Version: v0.2\n");
70035 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70036 - if (atomic_read(&overflow_count))
70037 + if (atomic_read_unchecked(&overflow_count))
70038 seq_printf(m, "Overflow: %d entries\n",
70039 - atomic_read(&overflow_count));
70040 + atomic_read_unchecked(&overflow_count));
70041
70042 for (i = 0; i < nr_entries; i++) {
70043 entry = entries + i;
70044 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70045 {
70046 struct proc_dir_entry *pe;
70047
70048 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70049 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70050 +#else
70051 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70052 +#endif
70053 if (!pe)
70054 return -ENOMEM;
70055 return 0;
70056 diff --git a/kernel/timer.c b/kernel/timer.c
70057 index 6ec7e7e..cbc448b 100644
70058 --- a/kernel/timer.c
70059 +++ b/kernel/timer.c
70060 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70061 /*
70062 * This function runs timers and the timer-tq in bottom half context.
70063 */
70064 -static void run_timer_softirq(struct softirq_action *h)
70065 +static void run_timer_softirq(void)
70066 {
70067 struct tvec_base *base = __this_cpu_read(tvec_bases);
70068
70069 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70070 index c0bd030..62a1927 100644
70071 --- a/kernel/trace/blktrace.c
70072 +++ b/kernel/trace/blktrace.c
70073 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70074 struct blk_trace *bt = filp->private_data;
70075 char buf[16];
70076
70077 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70078 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70079
70080 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70081 }
70082 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70083 return 1;
70084
70085 bt = buf->chan->private_data;
70086 - atomic_inc(&bt->dropped);
70087 + atomic_inc_unchecked(&bt->dropped);
70088 return 0;
70089 }
70090
70091 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70092
70093 bt->dir = dir;
70094 bt->dev = dev;
70095 - atomic_set(&bt->dropped, 0);
70096 + atomic_set_unchecked(&bt->dropped, 0);
70097
70098 ret = -EIO;
70099 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70100 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70101 index a008663..d363254 100644
70102 --- a/kernel/trace/ftrace.c
70103 +++ b/kernel/trace/ftrace.c
70104 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70105 if (unlikely(ftrace_disabled))
70106 return 0;
70107
70108 + ret = ftrace_arch_code_modify_prepare();
70109 + FTRACE_WARN_ON(ret);
70110 + if (ret)
70111 + return 0;
70112 +
70113 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70114 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70115 if (ret) {
70116 ftrace_bug(ret, ip);
70117 - return 0;
70118 }
70119 - return 1;
70120 + return ret ? 0 : 1;
70121 }
70122
70123 /*
70124 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70125
70126 int
70127 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70128 - void *data)
70129 + void *data)
70130 {
70131 struct ftrace_func_probe *entry;
70132 struct ftrace_page *pg;
70133 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70134 index a7fa070..403bc8d 100644
70135 --- a/kernel/trace/trace.c
70136 +++ b/kernel/trace/trace.c
70137 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70138 };
70139 #endif
70140
70141 -static struct dentry *d_tracer;
70142 -
70143 struct dentry *tracing_init_dentry(void)
70144 {
70145 + static struct dentry *d_tracer;
70146 static int once;
70147
70148 if (d_tracer)
70149 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70150 return d_tracer;
70151 }
70152
70153 -static struct dentry *d_percpu;
70154 -
70155 struct dentry *tracing_dentry_percpu(void)
70156 {
70157 + static struct dentry *d_percpu;
70158 static int once;
70159 struct dentry *d_tracer;
70160
70161 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70162 index 29111da..d190fe2 100644
70163 --- a/kernel/trace/trace_events.c
70164 +++ b/kernel/trace/trace_events.c
70165 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70166 struct ftrace_module_file_ops {
70167 struct list_head list;
70168 struct module *mod;
70169 - struct file_operations id;
70170 - struct file_operations enable;
70171 - struct file_operations format;
70172 - struct file_operations filter;
70173 };
70174
70175 static struct ftrace_module_file_ops *
70176 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70177
70178 file_ops->mod = mod;
70179
70180 - file_ops->id = ftrace_event_id_fops;
70181 - file_ops->id.owner = mod;
70182 -
70183 - file_ops->enable = ftrace_enable_fops;
70184 - file_ops->enable.owner = mod;
70185 -
70186 - file_ops->filter = ftrace_event_filter_fops;
70187 - file_ops->filter.owner = mod;
70188 -
70189 - file_ops->format = ftrace_event_format_fops;
70190 - file_ops->format.owner = mod;
70191 + pax_open_kernel();
70192 + *(void **)&mod->trace_id.owner = mod;
70193 + *(void **)&mod->trace_enable.owner = mod;
70194 + *(void **)&mod->trace_filter.owner = mod;
70195 + *(void **)&mod->trace_format.owner = mod;
70196 + pax_close_kernel();
70197
70198 list_add(&file_ops->list, &ftrace_module_file_list);
70199
70200 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70201
70202 for_each_event(call, start, end) {
70203 __trace_add_event_call(*call, mod,
70204 - &file_ops->id, &file_ops->enable,
70205 - &file_ops->filter, &file_ops->format);
70206 + &mod->trace_id, &mod->trace_enable,
70207 + &mod->trace_filter, &mod->trace_format);
70208 }
70209 }
70210
70211 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70212 index fd3c8aa..5f324a6 100644
70213 --- a/kernel/trace/trace_mmiotrace.c
70214 +++ b/kernel/trace/trace_mmiotrace.c
70215 @@ -24,7 +24,7 @@ struct header_iter {
70216 static struct trace_array *mmio_trace_array;
70217 static bool overrun_detected;
70218 static unsigned long prev_overruns;
70219 -static atomic_t dropped_count;
70220 +static atomic_unchecked_t dropped_count;
70221
70222 static void mmio_reset_data(struct trace_array *tr)
70223 {
70224 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70225
70226 static unsigned long count_overruns(struct trace_iterator *iter)
70227 {
70228 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70229 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70230 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70231
70232 if (over > prev_overruns)
70233 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70234 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70235 sizeof(*entry), 0, pc);
70236 if (!event) {
70237 - atomic_inc(&dropped_count);
70238 + atomic_inc_unchecked(&dropped_count);
70239 return;
70240 }
70241 entry = ring_buffer_event_data(event);
70242 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70243 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70244 sizeof(*entry), 0, pc);
70245 if (!event) {
70246 - atomic_inc(&dropped_count);
70247 + atomic_inc_unchecked(&dropped_count);
70248 return;
70249 }
70250 entry = ring_buffer_event_data(event);
70251 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70252 index df611a0..10d8b32 100644
70253 --- a/kernel/trace/trace_output.c
70254 +++ b/kernel/trace/trace_output.c
70255 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70256
70257 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70258 if (!IS_ERR(p)) {
70259 - p = mangle_path(s->buffer + s->len, p, "\n");
70260 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70261 if (p) {
70262 s->len = p - s->buffer;
70263 return 1;
70264 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70265 index d4545f4..a9010a1 100644
70266 --- a/kernel/trace/trace_stack.c
70267 +++ b/kernel/trace/trace_stack.c
70268 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70269 return;
70270
70271 /* we do not handle interrupt stacks yet */
70272 - if (!object_is_on_stack(&this_size))
70273 + if (!object_starts_on_stack(&this_size))
70274 return;
70275
70276 local_irq_save(flags);
70277 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70278 index ff5bdee..3eaeba6 100644
70279 --- a/lib/Kconfig.debug
70280 +++ b/lib/Kconfig.debug
70281 @@ -1165,6 +1165,7 @@ config LATENCYTOP
70282 depends on DEBUG_KERNEL
70283 depends on STACKTRACE_SUPPORT
70284 depends on PROC_FS
70285 + depends on !GRKERNSEC_HIDESYM
70286 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70287 select KALLSYMS
70288 select KALLSYMS_ALL
70289 diff --git a/lib/bitmap.c b/lib/bitmap.c
70290 index 06fdfa1..97c5c7d 100644
70291 --- a/lib/bitmap.c
70292 +++ b/lib/bitmap.c
70293 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70294 {
70295 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70296 u32 chunk;
70297 - const char __user __force *ubuf = (const char __user __force *)buf;
70298 + const char __user *ubuf = (const char __force_user *)buf;
70299
70300 bitmap_zero(maskp, nmaskbits);
70301
70302 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70303 {
70304 if (!access_ok(VERIFY_READ, ubuf, ulen))
70305 return -EFAULT;
70306 - return __bitmap_parse((const char __force *)ubuf,
70307 + return __bitmap_parse((const char __force_kernel *)ubuf,
70308 ulen, 1, maskp, nmaskbits);
70309
70310 }
70311 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70312 {
70313 unsigned a, b;
70314 int c, old_c, totaldigits;
70315 - const char __user __force *ubuf = (const char __user __force *)buf;
70316 + const char __user *ubuf = (const char __force_user *)buf;
70317 int exp_digit, in_range;
70318
70319 totaldigits = c = 0;
70320 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70321 {
70322 if (!access_ok(VERIFY_READ, ubuf, ulen))
70323 return -EFAULT;
70324 - return __bitmap_parselist((const char __force *)ubuf,
70325 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70326 ulen, 1, maskp, nmaskbits);
70327 }
70328 EXPORT_SYMBOL(bitmap_parselist_user);
70329 diff --git a/lib/bug.c b/lib/bug.c
70330 index a28c141..2bd3d95 100644
70331 --- a/lib/bug.c
70332 +++ b/lib/bug.c
70333 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70334 return BUG_TRAP_TYPE_NONE;
70335
70336 bug = find_bug(bugaddr);
70337 + if (!bug)
70338 + return BUG_TRAP_TYPE_NONE;
70339
70340 file = NULL;
70341 line = 0;
70342 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70343 index d11808c..dc2d6f8 100644
70344 --- a/lib/debugobjects.c
70345 +++ b/lib/debugobjects.c
70346 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70347 if (limit > 4)
70348 return;
70349
70350 - is_on_stack = object_is_on_stack(addr);
70351 + is_on_stack = object_starts_on_stack(addr);
70352 if (is_on_stack == onstack)
70353 return;
70354
70355 diff --git a/lib/devres.c b/lib/devres.c
70356 index 80b9c76..9e32279 100644
70357 --- a/lib/devres.c
70358 +++ b/lib/devres.c
70359 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70360 void devm_iounmap(struct device *dev, void __iomem *addr)
70361 {
70362 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70363 - (void *)addr));
70364 + (void __force *)addr));
70365 iounmap(addr);
70366 }
70367 EXPORT_SYMBOL(devm_iounmap);
70368 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70369 {
70370 ioport_unmap(addr);
70371 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70372 - devm_ioport_map_match, (void *)addr));
70373 + devm_ioport_map_match, (void __force *)addr));
70374 }
70375 EXPORT_SYMBOL(devm_ioport_unmap);
70376
70377 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70378 index 66ce414..6f0a0dd 100644
70379 --- a/lib/dma-debug.c
70380 +++ b/lib/dma-debug.c
70381 @@ -924,7 +924,7 @@ out:
70382
70383 static void check_for_stack(struct device *dev, void *addr)
70384 {
70385 - if (object_is_on_stack(addr))
70386 + if (object_starts_on_stack(addr))
70387 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70388 "stack [addr=%p]\n", addr);
70389 }
70390 diff --git a/lib/extable.c b/lib/extable.c
70391 index 4cac81e..4d66cfc 100644
70392 --- a/lib/extable.c
70393 +++ b/lib/extable.c
70394 @@ -13,6 +13,7 @@
70395 #include <linux/init.h>
70396 #include <linux/sort.h>
70397 #include <asm/uaccess.h>
70398 +#include <asm/pgtable.h>
70399
70400 #ifndef ARCH_HAS_SORT_EXTABLE
70401 /*
70402 diff --git a/lib/inflate.c b/lib/inflate.c
70403 index 013a761..c28f3fc 100644
70404 --- a/lib/inflate.c
70405 +++ b/lib/inflate.c
70406 @@ -269,7 +269,7 @@ static void free(void *where)
70407 malloc_ptr = free_mem_ptr;
70408 }
70409 #else
70410 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70411 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70412 #define free(a) kfree(a)
70413 #endif
70414
70415 diff --git a/lib/ioremap.c b/lib/ioremap.c
70416 index 0c9216c..863bd89 100644
70417 --- a/lib/ioremap.c
70418 +++ b/lib/ioremap.c
70419 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70420 unsigned long next;
70421
70422 phys_addr -= addr;
70423 - pmd = pmd_alloc(&init_mm, pud, addr);
70424 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70425 if (!pmd)
70426 return -ENOMEM;
70427 do {
70428 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70429 unsigned long next;
70430
70431 phys_addr -= addr;
70432 - pud = pud_alloc(&init_mm, pgd, addr);
70433 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70434 if (!pud)
70435 return -ENOMEM;
70436 do {
70437 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70438 index bd2bea9..6b3c95e 100644
70439 --- a/lib/is_single_threaded.c
70440 +++ b/lib/is_single_threaded.c
70441 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70442 struct task_struct *p, *t;
70443 bool ret;
70444
70445 + if (!mm)
70446 + return true;
70447 +
70448 if (atomic_read(&task->signal->live) != 1)
70449 return false;
70450
70451 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70452 index e796429..6e38f9f 100644
70453 --- a/lib/radix-tree.c
70454 +++ b/lib/radix-tree.c
70455 @@ -92,7 +92,7 @@ struct radix_tree_preload {
70456 int nr;
70457 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70458 };
70459 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70460 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70461
70462 static inline void *ptr_to_indirect(void *ptr)
70463 {
70464 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70465 index c3f36d41..5c5aeb5 100644
70466 --- a/lib/vsprintf.c
70467 +++ b/lib/vsprintf.c
70468 @@ -16,6 +16,9 @@
70469 * - scnprintf and vscnprintf
70470 */
70471
70472 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70473 +#define __INCLUDED_BY_HIDESYM 1
70474 +#endif
70475 #include <stdarg.h>
70476 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70477 #include <linux/types.h>
70478 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70479 char sym[KSYM_SYMBOL_LEN];
70480 if (ext == 'B')
70481 sprint_backtrace(sym, value);
70482 - else if (ext != 'f' && ext != 's')
70483 + else if (ext != 'f' && ext != 's' && ext != 'a')
70484 sprint_symbol(sym, value);
70485 else
70486 sprint_symbol_no_offset(sym, value);
70487 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70488 return number(buf, end, *(const netdev_features_t *)addr, spec);
70489 }
70490
70491 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70492 +int kptr_restrict __read_mostly = 2;
70493 +#else
70494 int kptr_restrict __read_mostly;
70495 +#endif
70496
70497 /*
70498 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70499 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70500 * - 'S' For symbolic direct pointers with offset
70501 * - 's' For symbolic direct pointers without offset
70502 * - 'B' For backtraced symbolic direct pointers with offset
70503 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70504 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70505 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70506 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70507 * - 'M' For a 6-byte MAC address, it prints the address in the
70508 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70509
70510 if (!ptr && *fmt != 'K') {
70511 /*
70512 - * Print (null) with the same width as a pointer so it makes
70513 + * Print (nil) with the same width as a pointer so it makes
70514 * tabular output look nice.
70515 */
70516 if (spec.field_width == -1)
70517 spec.field_width = default_width;
70518 - return string(buf, end, "(null)", spec);
70519 + return string(buf, end, "(nil)", spec);
70520 }
70521
70522 switch (*fmt) {
70523 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70524 /* Fallthrough */
70525 case 'S':
70526 case 's':
70527 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70528 + break;
70529 +#else
70530 + return symbol_string(buf, end, ptr, spec, *fmt);
70531 +#endif
70532 + case 'A':
70533 + case 'a':
70534 case 'B':
70535 return symbol_string(buf, end, ptr, spec, *fmt);
70536 case 'R':
70537 @@ -1025,12 +1041,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70538 va_end(va);
70539 return buf;
70540 }
70541 + case 'P':
70542 + break;
70543 case 'K':
70544 /*
70545 * %pK cannot be used in IRQ context because its test
70546 * for CAP_SYSLOG would be meaningless.
70547 */
70548 - if (in_irq() || in_serving_softirq() || in_nmi()) {
70549 + if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70550 + in_nmi())) {
70551 if (spec.field_width == -1)
70552 spec.field_width = default_width;
70553 return string(buf, end, "pK-error", spec);
70554 @@ -1047,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70555 }
70556 break;
70557 }
70558 +
70559 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70560 + /* 'P' = approved pointers to copy to userland,
70561 + as in the /proc/kallsyms case, as we make it display nothing
70562 + for non-root users, and the real contents for root users
70563 + Also ignore 'K' pointers, since we force their NULLing for non-root users
70564 + above
70565 + */
70566 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70567 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70568 + dump_stack();
70569 + ptr = NULL;
70570 + }
70571 +#endif
70572 +
70573 spec.flags |= SMALL;
70574 if (spec.field_width == -1) {
70575 spec.field_width = default_width;
70576 @@ -1758,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70577 typeof(type) value; \
70578 if (sizeof(type) == 8) { \
70579 args = PTR_ALIGN(args, sizeof(u32)); \
70580 - *(u32 *)&value = *(u32 *)args; \
70581 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70582 + *(u32 *)&value = *(const u32 *)args; \
70583 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70584 } else { \
70585 args = PTR_ALIGN(args, sizeof(type)); \
70586 - value = *(typeof(type) *)args; \
70587 + value = *(const typeof(type) *)args; \
70588 } \
70589 args += sizeof(type); \
70590 value; \
70591 @@ -1825,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70592 case FORMAT_TYPE_STR: {
70593 const char *str_arg = args;
70594 args += strlen(str_arg) + 1;
70595 - str = string(str, end, (char *)str_arg, spec);
70596 + str = string(str, end, str_arg, spec);
70597 break;
70598 }
70599
70600 diff --git a/localversion-grsec b/localversion-grsec
70601 new file mode 100644
70602 index 0000000..7cd6065
70603 --- /dev/null
70604 +++ b/localversion-grsec
70605 @@ -0,0 +1 @@
70606 +-grsec
70607 diff --git a/mm/Kconfig b/mm/Kconfig
70608 index 82fed4e..979e814 100644
70609 --- a/mm/Kconfig
70610 +++ b/mm/Kconfig
70611 @@ -247,10 +247,10 @@ config KSM
70612 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70613
70614 config DEFAULT_MMAP_MIN_ADDR
70615 - int "Low address space to protect from user allocation"
70616 + int "Low address space to protect from user allocation"
70617 depends on MMU
70618 - default 4096
70619 - help
70620 + default 65536
70621 + help
70622 This is the portion of low virtual memory which should be protected
70623 from userspace allocation. Keeping a user from writing to low pages
70624 can help reduce the impact of kernel NULL pointer bugs.
70625 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70626
70627 config HWPOISON_INJECT
70628 tristate "HWPoison pages injector"
70629 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70630 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70631 select PROC_PAGE_MONITOR
70632
70633 config NOMMU_INITIAL_TRIM_EXCESS
70634 diff --git a/mm/filemap.c b/mm/filemap.c
70635 index a4a5260..6151dc5 100644
70636 --- a/mm/filemap.c
70637 +++ b/mm/filemap.c
70638 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70639 struct address_space *mapping = file->f_mapping;
70640
70641 if (!mapping->a_ops->readpage)
70642 - return -ENOEXEC;
70643 + return -ENODEV;
70644 file_accessed(file);
70645 vma->vm_ops = &generic_file_vm_ops;
70646 vma->vm_flags |= VM_CAN_NONLINEAR;
70647 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70648 *pos = i_size_read(inode);
70649
70650 if (limit != RLIM_INFINITY) {
70651 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70652 if (*pos >= limit) {
70653 send_sig(SIGXFSZ, current, 0);
70654 return -EFBIG;
70655 diff --git a/mm/fremap.c b/mm/fremap.c
70656 index 9ed4fd4..c42648d 100644
70657 --- a/mm/fremap.c
70658 +++ b/mm/fremap.c
70659 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70660 retry:
70661 vma = find_vma(mm, start);
70662
70663 +#ifdef CONFIG_PAX_SEGMEXEC
70664 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70665 + goto out;
70666 +#endif
70667 +
70668 /*
70669 * Make sure the vma is shared, that it supports prefaulting,
70670 * and that the remapped range is valid and fully within
70671 diff --git a/mm/highmem.c b/mm/highmem.c
70672 index 57d82c6..e9e0552 100644
70673 --- a/mm/highmem.c
70674 +++ b/mm/highmem.c
70675 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70676 * So no dangers, even with speculative execution.
70677 */
70678 page = pte_page(pkmap_page_table[i]);
70679 + pax_open_kernel();
70680 pte_clear(&init_mm, (unsigned long)page_address(page),
70681 &pkmap_page_table[i]);
70682 -
70683 + pax_close_kernel();
70684 set_page_address(page, NULL);
70685 need_flush = 1;
70686 }
70687 @@ -186,9 +187,11 @@ start:
70688 }
70689 }
70690 vaddr = PKMAP_ADDR(last_pkmap_nr);
70691 +
70692 + pax_open_kernel();
70693 set_pte_at(&init_mm, vaddr,
70694 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70695 -
70696 + pax_close_kernel();
70697 pkmap_count[last_pkmap_nr] = 1;
70698 set_page_address(page, (void *)vaddr);
70699
70700 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70701 index 57c4b93..24b8f59 100644
70702 --- a/mm/huge_memory.c
70703 +++ b/mm/huge_memory.c
70704 @@ -735,7 +735,7 @@ out:
70705 * run pte_offset_map on the pmd, if an huge pmd could
70706 * materialize from under us from a different thread.
70707 */
70708 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70709 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70710 return VM_FAULT_OOM;
70711 /* if an huge pmd materialized from under us just retry later */
70712 if (unlikely(pmd_trans_huge(*pmd)))
70713 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70714 index e198831..38d524f 100644
70715 --- a/mm/hugetlb.c
70716 +++ b/mm/hugetlb.c
70717 @@ -2447,6 +2447,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70718 return 1;
70719 }
70720
70721 +#ifdef CONFIG_PAX_SEGMEXEC
70722 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70723 +{
70724 + struct mm_struct *mm = vma->vm_mm;
70725 + struct vm_area_struct *vma_m;
70726 + unsigned long address_m;
70727 + pte_t *ptep_m;
70728 +
70729 + vma_m = pax_find_mirror_vma(vma);
70730 + if (!vma_m)
70731 + return;
70732 +
70733 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70734 + address_m = address + SEGMEXEC_TASK_SIZE;
70735 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70736 + get_page(page_m);
70737 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70738 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70739 +}
70740 +#endif
70741 +
70742 /*
70743 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70744 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70745 @@ -2559,6 +2580,11 @@ retry_avoidcopy:
70746 make_huge_pte(vma, new_page, 1));
70747 page_remove_rmap(old_page);
70748 hugepage_add_new_anon_rmap(new_page, vma, address);
70749 +
70750 +#ifdef CONFIG_PAX_SEGMEXEC
70751 + pax_mirror_huge_pte(vma, address, new_page);
70752 +#endif
70753 +
70754 /* Make the old page be freed below */
70755 new_page = old_page;
70756 mmu_notifier_invalidate_range_end(mm,
70757 @@ -2713,6 +2739,10 @@ retry:
70758 && (vma->vm_flags & VM_SHARED)));
70759 set_huge_pte_at(mm, address, ptep, new_pte);
70760
70761 +#ifdef CONFIG_PAX_SEGMEXEC
70762 + pax_mirror_huge_pte(vma, address, page);
70763 +#endif
70764 +
70765 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70766 /* Optimization, do the COW without a second fault */
70767 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70768 @@ -2742,6 +2772,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70769 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70770 struct hstate *h = hstate_vma(vma);
70771
70772 +#ifdef CONFIG_PAX_SEGMEXEC
70773 + struct vm_area_struct *vma_m;
70774 +#endif
70775 +
70776 address &= huge_page_mask(h);
70777
70778 ptep = huge_pte_offset(mm, address);
70779 @@ -2755,6 +2789,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70780 VM_FAULT_SET_HINDEX(h - hstates);
70781 }
70782
70783 +#ifdef CONFIG_PAX_SEGMEXEC
70784 + vma_m = pax_find_mirror_vma(vma);
70785 + if (vma_m) {
70786 + unsigned long address_m;
70787 +
70788 + if (vma->vm_start > vma_m->vm_start) {
70789 + address_m = address;
70790 + address -= SEGMEXEC_TASK_SIZE;
70791 + vma = vma_m;
70792 + h = hstate_vma(vma);
70793 + } else
70794 + address_m = address + SEGMEXEC_TASK_SIZE;
70795 +
70796 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70797 + return VM_FAULT_OOM;
70798 + address_m &= HPAGE_MASK;
70799 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70800 + }
70801 +#endif
70802 +
70803 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70804 if (!ptep)
70805 return VM_FAULT_OOM;
70806 diff --git a/mm/internal.h b/mm/internal.h
70807 index 2ba87fb..7f451e2 100644
70808 --- a/mm/internal.h
70809 +++ b/mm/internal.h
70810 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70811 * in mm/page_alloc.c
70812 */
70813 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70814 +extern void free_compound_page(struct page *page);
70815 extern void prep_compound_page(struct page *page, unsigned long order);
70816 #ifdef CONFIG_MEMORY_FAILURE
70817 extern bool is_free_buddy_page(struct page *page);
70818 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70819 index 45eb621..6ccd8ea 100644
70820 --- a/mm/kmemleak.c
70821 +++ b/mm/kmemleak.c
70822 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70823
70824 for (i = 0; i < object->trace_len; i++) {
70825 void *ptr = (void *)object->trace[i];
70826 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70827 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70828 }
70829 }
70830
70831 diff --git a/mm/maccess.c b/mm/maccess.c
70832 index d53adf9..03a24bf 100644
70833 --- a/mm/maccess.c
70834 +++ b/mm/maccess.c
70835 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70836 set_fs(KERNEL_DS);
70837 pagefault_disable();
70838 ret = __copy_from_user_inatomic(dst,
70839 - (__force const void __user *)src, size);
70840 + (const void __force_user *)src, size);
70841 pagefault_enable();
70842 set_fs(old_fs);
70843
70844 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70845
70846 set_fs(KERNEL_DS);
70847 pagefault_disable();
70848 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70849 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70850 pagefault_enable();
70851 set_fs(old_fs);
70852
70853 diff --git a/mm/madvise.c b/mm/madvise.c
70854 index 14d260f..b2a80fd 100644
70855 --- a/mm/madvise.c
70856 +++ b/mm/madvise.c
70857 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70858 pgoff_t pgoff;
70859 unsigned long new_flags = vma->vm_flags;
70860
70861 +#ifdef CONFIG_PAX_SEGMEXEC
70862 + struct vm_area_struct *vma_m;
70863 +#endif
70864 +
70865 switch (behavior) {
70866 case MADV_NORMAL:
70867 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70868 @@ -119,6 +123,13 @@ success:
70869 /*
70870 * vm_flags is protected by the mmap_sem held in write mode.
70871 */
70872 +
70873 +#ifdef CONFIG_PAX_SEGMEXEC
70874 + vma_m = pax_find_mirror_vma(vma);
70875 + if (vma_m)
70876 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70877 +#endif
70878 +
70879 vma->vm_flags = new_flags;
70880
70881 out:
70882 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70883 struct vm_area_struct ** prev,
70884 unsigned long start, unsigned long end)
70885 {
70886 +
70887 +#ifdef CONFIG_PAX_SEGMEXEC
70888 + struct vm_area_struct *vma_m;
70889 +#endif
70890 +
70891 *prev = vma;
70892 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70893 return -EINVAL;
70894 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70895 zap_page_range(vma, start, end - start, &details);
70896 } else
70897 zap_page_range(vma, start, end - start, NULL);
70898 +
70899 +#ifdef CONFIG_PAX_SEGMEXEC
70900 + vma_m = pax_find_mirror_vma(vma);
70901 + if (vma_m) {
70902 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70903 + struct zap_details details = {
70904 + .nonlinear_vma = vma_m,
70905 + .last_index = ULONG_MAX,
70906 + };
70907 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70908 + } else
70909 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70910 + }
70911 +#endif
70912 +
70913 return 0;
70914 }
70915
70916 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70917 if (end < start)
70918 goto out;
70919
70920 +#ifdef CONFIG_PAX_SEGMEXEC
70921 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70922 + if (end > SEGMEXEC_TASK_SIZE)
70923 + goto out;
70924 + } else
70925 +#endif
70926 +
70927 + if (end > TASK_SIZE)
70928 + goto out;
70929 +
70930 error = 0;
70931 if (end == start)
70932 goto out;
70933 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70934 index ab1e714..415de01 100644
70935 --- a/mm/memory-failure.c
70936 +++ b/mm/memory-failure.c
70937 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70938
70939 int sysctl_memory_failure_recovery __read_mostly = 1;
70940
70941 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70942 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70943
70944 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70945
70946 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
70947 pfn, t->comm, t->pid);
70948 si.si_signo = SIGBUS;
70949 si.si_errno = 0;
70950 - si.si_addr = (void *)addr;
70951 + si.si_addr = (void __user *)addr;
70952 #ifdef __ARCH_SI_TRAPNO
70953 si.si_trapno = trapno;
70954 #endif
70955 @@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70956 }
70957
70958 nr_pages = 1 << compound_trans_order(hpage);
70959 - atomic_long_add(nr_pages, &mce_bad_pages);
70960 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70961
70962 /*
70963 * We need/can do nothing about count=0 pages.
70964 @@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70965 if (!PageHWPoison(hpage)
70966 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70967 || (p != hpage && TestSetPageHWPoison(hpage))) {
70968 - atomic_long_sub(nr_pages, &mce_bad_pages);
70969 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70970 return 0;
70971 }
70972 set_page_hwpoison_huge_page(hpage);
70973 @@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70974 }
70975 if (hwpoison_filter(p)) {
70976 if (TestClearPageHWPoison(p))
70977 - atomic_long_sub(nr_pages, &mce_bad_pages);
70978 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70979 unlock_page(hpage);
70980 put_page(hpage);
70981 return 0;
70982 @@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
70983 return 0;
70984 }
70985 if (TestClearPageHWPoison(p))
70986 - atomic_long_sub(nr_pages, &mce_bad_pages);
70987 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70988 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70989 return 0;
70990 }
70991 @@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
70992 */
70993 if (TestClearPageHWPoison(page)) {
70994 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70995 - atomic_long_sub(nr_pages, &mce_bad_pages);
70996 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70997 freeit = 1;
70998 if (PageHuge(page))
70999 clear_page_hwpoison_huge_page(page);
71000 @@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71001 }
71002 done:
71003 if (!PageHWPoison(hpage))
71004 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71005 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71006 set_page_hwpoison_huge_page(hpage);
71007 dequeue_hwpoisoned_huge_page(hpage);
71008 /* keep elevated page count for bad page */
71009 @@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
71010 return ret;
71011
71012 done:
71013 - atomic_long_add(1, &mce_bad_pages);
71014 + atomic_long_add_unchecked(1, &mce_bad_pages);
71015 SetPageHWPoison(page);
71016 /* keep elevated page count for bad page */
71017 return ret;
71018 diff --git a/mm/memory.c b/mm/memory.c
71019 index 2466d12..08be4f6 100644
71020 --- a/mm/memory.c
71021 +++ b/mm/memory.c
71022 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71023 return;
71024
71025 pmd = pmd_offset(pud, start);
71026 +
71027 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71028 pud_clear(pud);
71029 pmd_free_tlb(tlb, pmd, start);
71030 +#endif
71031 +
71032 }
71033
71034 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71035 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71036 if (end - 1 > ceiling - 1)
71037 return;
71038
71039 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71040 pud = pud_offset(pgd, start);
71041 pgd_clear(pgd);
71042 pud_free_tlb(tlb, pud, start);
71043 +#endif
71044 +
71045 }
71046
71047 /*
71048 @@ -1602,12 +1609,6 @@ no_page_table:
71049 return page;
71050 }
71051
71052 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71053 -{
71054 - return stack_guard_page_start(vma, addr) ||
71055 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71056 -}
71057 -
71058 /**
71059 * __get_user_pages() - pin user pages in memory
71060 * @tsk: task_struct of target task
71061 @@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71062 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71063 i = 0;
71064
71065 - do {
71066 + while (nr_pages) {
71067 struct vm_area_struct *vma;
71068
71069 - vma = find_extend_vma(mm, start);
71070 + vma = find_vma(mm, start);
71071 if (!vma && in_gate_area(mm, start)) {
71072 unsigned long pg = start & PAGE_MASK;
71073 pgd_t *pgd;
71074 @@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71075 goto next_page;
71076 }
71077
71078 - if (!vma ||
71079 + if (!vma || start < vma->vm_start ||
71080 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71081 !(vm_flags & vma->vm_flags))
71082 return i ? : -EFAULT;
71083 @@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71084 int ret;
71085 unsigned int fault_flags = 0;
71086
71087 - /* For mlock, just skip the stack guard page. */
71088 - if (foll_flags & FOLL_MLOCK) {
71089 - if (stack_guard_page(vma, start))
71090 - goto next_page;
71091 - }
71092 if (foll_flags & FOLL_WRITE)
71093 fault_flags |= FAULT_FLAG_WRITE;
71094 if (nonblocking)
71095 @@ -1836,7 +1832,7 @@ next_page:
71096 start += PAGE_SIZE;
71097 nr_pages--;
71098 } while (nr_pages && start < vma->vm_end);
71099 - } while (nr_pages);
71100 + }
71101 return i;
71102 }
71103 EXPORT_SYMBOL(__get_user_pages);
71104 @@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71105 page_add_file_rmap(page);
71106 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71107
71108 +#ifdef CONFIG_PAX_SEGMEXEC
71109 + pax_mirror_file_pte(vma, addr, page, ptl);
71110 +#endif
71111 +
71112 retval = 0;
71113 pte_unmap_unlock(pte, ptl);
71114 return retval;
71115 @@ -2077,10 +2077,22 @@ out:
71116 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71117 struct page *page)
71118 {
71119 +
71120 +#ifdef CONFIG_PAX_SEGMEXEC
71121 + struct vm_area_struct *vma_m;
71122 +#endif
71123 +
71124 if (addr < vma->vm_start || addr >= vma->vm_end)
71125 return -EFAULT;
71126 if (!page_count(page))
71127 return -EINVAL;
71128 +
71129 +#ifdef CONFIG_PAX_SEGMEXEC
71130 + vma_m = pax_find_mirror_vma(vma);
71131 + if (vma_m)
71132 + vma_m->vm_flags |= VM_INSERTPAGE;
71133 +#endif
71134 +
71135 vma->vm_flags |= VM_INSERTPAGE;
71136 return insert_page(vma, addr, page, vma->vm_page_prot);
71137 }
71138 @@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71139 unsigned long pfn)
71140 {
71141 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71142 + BUG_ON(vma->vm_mirror);
71143
71144 if (addr < vma->vm_start || addr >= vma->vm_end)
71145 return -EFAULT;
71146 @@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71147
71148 BUG_ON(pud_huge(*pud));
71149
71150 - pmd = pmd_alloc(mm, pud, addr);
71151 + pmd = (mm == &init_mm) ?
71152 + pmd_alloc_kernel(mm, pud, addr) :
71153 + pmd_alloc(mm, pud, addr);
71154 if (!pmd)
71155 return -ENOMEM;
71156 do {
71157 @@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71158 unsigned long next;
71159 int err;
71160
71161 - pud = pud_alloc(mm, pgd, addr);
71162 + pud = (mm == &init_mm) ?
71163 + pud_alloc_kernel(mm, pgd, addr) :
71164 + pud_alloc(mm, pgd, addr);
71165 if (!pud)
71166 return -ENOMEM;
71167 do {
71168 @@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71169 copy_user_highpage(dst, src, va, vma);
71170 }
71171
71172 +#ifdef CONFIG_PAX_SEGMEXEC
71173 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71174 +{
71175 + struct mm_struct *mm = vma->vm_mm;
71176 + spinlock_t *ptl;
71177 + pte_t *pte, entry;
71178 +
71179 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71180 + entry = *pte;
71181 + if (!pte_present(entry)) {
71182 + if (!pte_none(entry)) {
71183 + BUG_ON(pte_file(entry));
71184 + free_swap_and_cache(pte_to_swp_entry(entry));
71185 + pte_clear_not_present_full(mm, address, pte, 0);
71186 + }
71187 + } else {
71188 + struct page *page;
71189 +
71190 + flush_cache_page(vma, address, pte_pfn(entry));
71191 + entry = ptep_clear_flush(vma, address, pte);
71192 + BUG_ON(pte_dirty(entry));
71193 + page = vm_normal_page(vma, address, entry);
71194 + if (page) {
71195 + update_hiwater_rss(mm);
71196 + if (PageAnon(page))
71197 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71198 + else
71199 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71200 + page_remove_rmap(page);
71201 + page_cache_release(page);
71202 + }
71203 + }
71204 + pte_unmap_unlock(pte, ptl);
71205 +}
71206 +
71207 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71208 + *
71209 + * the ptl of the lower mapped page is held on entry and is not released on exit
71210 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71211 + */
71212 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71213 +{
71214 + struct mm_struct *mm = vma->vm_mm;
71215 + unsigned long address_m;
71216 + spinlock_t *ptl_m;
71217 + struct vm_area_struct *vma_m;
71218 + pmd_t *pmd_m;
71219 + pte_t *pte_m, entry_m;
71220 +
71221 + BUG_ON(!page_m || !PageAnon(page_m));
71222 +
71223 + vma_m = pax_find_mirror_vma(vma);
71224 + if (!vma_m)
71225 + return;
71226 +
71227 + BUG_ON(!PageLocked(page_m));
71228 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71229 + address_m = address + SEGMEXEC_TASK_SIZE;
71230 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71231 + pte_m = pte_offset_map(pmd_m, address_m);
71232 + ptl_m = pte_lockptr(mm, pmd_m);
71233 + if (ptl != ptl_m) {
71234 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71235 + if (!pte_none(*pte_m))
71236 + goto out;
71237 + }
71238 +
71239 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71240 + page_cache_get(page_m);
71241 + page_add_anon_rmap(page_m, vma_m, address_m);
71242 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71243 + set_pte_at(mm, address_m, pte_m, entry_m);
71244 + update_mmu_cache(vma_m, address_m, entry_m);
71245 +out:
71246 + if (ptl != ptl_m)
71247 + spin_unlock(ptl_m);
71248 + pte_unmap(pte_m);
71249 + unlock_page(page_m);
71250 +}
71251 +
71252 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71253 +{
71254 + struct mm_struct *mm = vma->vm_mm;
71255 + unsigned long address_m;
71256 + spinlock_t *ptl_m;
71257 + struct vm_area_struct *vma_m;
71258 + pmd_t *pmd_m;
71259 + pte_t *pte_m, entry_m;
71260 +
71261 + BUG_ON(!page_m || PageAnon(page_m));
71262 +
71263 + vma_m = pax_find_mirror_vma(vma);
71264 + if (!vma_m)
71265 + return;
71266 +
71267 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71268 + address_m = address + SEGMEXEC_TASK_SIZE;
71269 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71270 + pte_m = pte_offset_map(pmd_m, address_m);
71271 + ptl_m = pte_lockptr(mm, pmd_m);
71272 + if (ptl != ptl_m) {
71273 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71274 + if (!pte_none(*pte_m))
71275 + goto out;
71276 + }
71277 +
71278 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71279 + page_cache_get(page_m);
71280 + page_add_file_rmap(page_m);
71281 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71282 + set_pte_at(mm, address_m, pte_m, entry_m);
71283 + update_mmu_cache(vma_m, address_m, entry_m);
71284 +out:
71285 + if (ptl != ptl_m)
71286 + spin_unlock(ptl_m);
71287 + pte_unmap(pte_m);
71288 +}
71289 +
71290 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71291 +{
71292 + struct mm_struct *mm = vma->vm_mm;
71293 + unsigned long address_m;
71294 + spinlock_t *ptl_m;
71295 + struct vm_area_struct *vma_m;
71296 + pmd_t *pmd_m;
71297 + pte_t *pte_m, entry_m;
71298 +
71299 + vma_m = pax_find_mirror_vma(vma);
71300 + if (!vma_m)
71301 + return;
71302 +
71303 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71304 + address_m = address + SEGMEXEC_TASK_SIZE;
71305 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71306 + pte_m = pte_offset_map(pmd_m, address_m);
71307 + ptl_m = pte_lockptr(mm, pmd_m);
71308 + if (ptl != ptl_m) {
71309 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71310 + if (!pte_none(*pte_m))
71311 + goto out;
71312 + }
71313 +
71314 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71315 + set_pte_at(mm, address_m, pte_m, entry_m);
71316 +out:
71317 + if (ptl != ptl_m)
71318 + spin_unlock(ptl_m);
71319 + pte_unmap(pte_m);
71320 +}
71321 +
71322 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71323 +{
71324 + struct page *page_m;
71325 + pte_t entry;
71326 +
71327 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71328 + goto out;
71329 +
71330 + entry = *pte;
71331 + page_m = vm_normal_page(vma, address, entry);
71332 + if (!page_m)
71333 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71334 + else if (PageAnon(page_m)) {
71335 + if (pax_find_mirror_vma(vma)) {
71336 + pte_unmap_unlock(pte, ptl);
71337 + lock_page(page_m);
71338 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71339 + if (pte_same(entry, *pte))
71340 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71341 + else
71342 + unlock_page(page_m);
71343 + }
71344 + } else
71345 + pax_mirror_file_pte(vma, address, page_m, ptl);
71346 +
71347 +out:
71348 + pte_unmap_unlock(pte, ptl);
71349 +}
71350 +#endif
71351 +
71352 /*
71353 * This routine handles present pages, when users try to write
71354 * to a shared page. It is done by copying the page to a new address
71355 @@ -2692,6 +2889,12 @@ gotten:
71356 */
71357 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71358 if (likely(pte_same(*page_table, orig_pte))) {
71359 +
71360 +#ifdef CONFIG_PAX_SEGMEXEC
71361 + if (pax_find_mirror_vma(vma))
71362 + BUG_ON(!trylock_page(new_page));
71363 +#endif
71364 +
71365 if (old_page) {
71366 if (!PageAnon(old_page)) {
71367 dec_mm_counter_fast(mm, MM_FILEPAGES);
71368 @@ -2743,6 +2946,10 @@ gotten:
71369 page_remove_rmap(old_page);
71370 }
71371
71372 +#ifdef CONFIG_PAX_SEGMEXEC
71373 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71374 +#endif
71375 +
71376 /* Free the old page.. */
71377 new_page = old_page;
71378 ret |= VM_FAULT_WRITE;
71379 @@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71380 swap_free(entry);
71381 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71382 try_to_free_swap(page);
71383 +
71384 +#ifdef CONFIG_PAX_SEGMEXEC
71385 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71386 +#endif
71387 +
71388 unlock_page(page);
71389 if (swapcache) {
71390 /*
71391 @@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71392
71393 /* No need to invalidate - it was non-present before */
71394 update_mmu_cache(vma, address, page_table);
71395 +
71396 +#ifdef CONFIG_PAX_SEGMEXEC
71397 + pax_mirror_anon_pte(vma, address, page, ptl);
71398 +#endif
71399 +
71400 unlock:
71401 pte_unmap_unlock(page_table, ptl);
71402 out:
71403 @@ -3064,40 +3281,6 @@ out_release:
71404 }
71405
71406 /*
71407 - * This is like a special single-page "expand_{down|up}wards()",
71408 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71409 - * doesn't hit another vma.
71410 - */
71411 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71412 -{
71413 - address &= PAGE_MASK;
71414 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71415 - struct vm_area_struct *prev = vma->vm_prev;
71416 -
71417 - /*
71418 - * Is there a mapping abutting this one below?
71419 - *
71420 - * That's only ok if it's the same stack mapping
71421 - * that has gotten split..
71422 - */
71423 - if (prev && prev->vm_end == address)
71424 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71425 -
71426 - expand_downwards(vma, address - PAGE_SIZE);
71427 - }
71428 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71429 - struct vm_area_struct *next = vma->vm_next;
71430 -
71431 - /* As VM_GROWSDOWN but s/below/above/ */
71432 - if (next && next->vm_start == address + PAGE_SIZE)
71433 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71434 -
71435 - expand_upwards(vma, address + PAGE_SIZE);
71436 - }
71437 - return 0;
71438 -}
71439 -
71440 -/*
71441 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71442 * but allow concurrent faults), and pte mapped but not yet locked.
71443 * We return with mmap_sem still held, but pte unmapped and unlocked.
71444 @@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71445 unsigned long address, pte_t *page_table, pmd_t *pmd,
71446 unsigned int flags)
71447 {
71448 - struct page *page;
71449 + struct page *page = NULL;
71450 spinlock_t *ptl;
71451 pte_t entry;
71452
71453 - pte_unmap(page_table);
71454 -
71455 - /* Check if we need to add a guard page to the stack */
71456 - if (check_stack_guard_page(vma, address) < 0)
71457 - return VM_FAULT_SIGBUS;
71458 -
71459 - /* Use the zero-page for reads */
71460 if (!(flags & FAULT_FLAG_WRITE)) {
71461 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71462 vma->vm_page_prot));
71463 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71464 + ptl = pte_lockptr(mm, pmd);
71465 + spin_lock(ptl);
71466 if (!pte_none(*page_table))
71467 goto unlock;
71468 goto setpte;
71469 }
71470
71471 /* Allocate our own private page. */
71472 + pte_unmap(page_table);
71473 +
71474 if (unlikely(anon_vma_prepare(vma)))
71475 goto oom;
71476 page = alloc_zeroed_user_highpage_movable(vma, address);
71477 @@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71478 if (!pte_none(*page_table))
71479 goto release;
71480
71481 +#ifdef CONFIG_PAX_SEGMEXEC
71482 + if (pax_find_mirror_vma(vma))
71483 + BUG_ON(!trylock_page(page));
71484 +#endif
71485 +
71486 inc_mm_counter_fast(mm, MM_ANONPAGES);
71487 page_add_new_anon_rmap(page, vma, address);
71488 setpte:
71489 @@ -3152,6 +3336,12 @@ setpte:
71490
71491 /* No need to invalidate - it was non-present before */
71492 update_mmu_cache(vma, address, page_table);
71493 +
71494 +#ifdef CONFIG_PAX_SEGMEXEC
71495 + if (page)
71496 + pax_mirror_anon_pte(vma, address, page, ptl);
71497 +#endif
71498 +
71499 unlock:
71500 pte_unmap_unlock(page_table, ptl);
71501 return 0;
71502 @@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71503 */
71504 /* Only go through if we didn't race with anybody else... */
71505 if (likely(pte_same(*page_table, orig_pte))) {
71506 +
71507 +#ifdef CONFIG_PAX_SEGMEXEC
71508 + if (anon && pax_find_mirror_vma(vma))
71509 + BUG_ON(!trylock_page(page));
71510 +#endif
71511 +
71512 flush_icache_page(vma, page);
71513 entry = mk_pte(page, vma->vm_page_prot);
71514 if (flags & FAULT_FLAG_WRITE)
71515 @@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71516
71517 /* no need to invalidate: a not-present page won't be cached */
71518 update_mmu_cache(vma, address, page_table);
71519 +
71520 +#ifdef CONFIG_PAX_SEGMEXEC
71521 + if (anon)
71522 + pax_mirror_anon_pte(vma, address, page, ptl);
71523 + else
71524 + pax_mirror_file_pte(vma, address, page, ptl);
71525 +#endif
71526 +
71527 } else {
71528 if (cow_page)
71529 mem_cgroup_uncharge_page(cow_page);
71530 @@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71531 if (flags & FAULT_FLAG_WRITE)
71532 flush_tlb_fix_spurious_fault(vma, address);
71533 }
71534 +
71535 +#ifdef CONFIG_PAX_SEGMEXEC
71536 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71537 + return 0;
71538 +#endif
71539 +
71540 unlock:
71541 pte_unmap_unlock(pte, ptl);
71542 return 0;
71543 @@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71544 pmd_t *pmd;
71545 pte_t *pte;
71546
71547 +#ifdef CONFIG_PAX_SEGMEXEC
71548 + struct vm_area_struct *vma_m;
71549 +#endif
71550 +
71551 __set_current_state(TASK_RUNNING);
71552
71553 count_vm_event(PGFAULT);
71554 @@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71555 if (unlikely(is_vm_hugetlb_page(vma)))
71556 return hugetlb_fault(mm, vma, address, flags);
71557
71558 +#ifdef CONFIG_PAX_SEGMEXEC
71559 + vma_m = pax_find_mirror_vma(vma);
71560 + if (vma_m) {
71561 + unsigned long address_m;
71562 + pgd_t *pgd_m;
71563 + pud_t *pud_m;
71564 + pmd_t *pmd_m;
71565 +
71566 + if (vma->vm_start > vma_m->vm_start) {
71567 + address_m = address;
71568 + address -= SEGMEXEC_TASK_SIZE;
71569 + vma = vma_m;
71570 + } else
71571 + address_m = address + SEGMEXEC_TASK_SIZE;
71572 +
71573 + pgd_m = pgd_offset(mm, address_m);
71574 + pud_m = pud_alloc(mm, pgd_m, address_m);
71575 + if (!pud_m)
71576 + return VM_FAULT_OOM;
71577 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71578 + if (!pmd_m)
71579 + return VM_FAULT_OOM;
71580 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71581 + return VM_FAULT_OOM;
71582 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71583 + }
71584 +#endif
71585 +
71586 retry:
71587 pgd = pgd_offset(mm, address);
71588 pud = pud_alloc(mm, pgd, address);
71589 @@ -3535,7 +3777,7 @@ retry:
71590 * run pte_offset_map on the pmd, if an huge pmd could
71591 * materialize from under us from a different thread.
71592 */
71593 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71594 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71595 return VM_FAULT_OOM;
71596 /* if an huge pmd materialized from under us just retry later */
71597 if (unlikely(pmd_trans_huge(*pmd)))
71598 @@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71599 spin_unlock(&mm->page_table_lock);
71600 return 0;
71601 }
71602 +
71603 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71604 +{
71605 + pud_t *new = pud_alloc_one(mm, address);
71606 + if (!new)
71607 + return -ENOMEM;
71608 +
71609 + smp_wmb(); /* See comment in __pte_alloc */
71610 +
71611 + spin_lock(&mm->page_table_lock);
71612 + if (pgd_present(*pgd)) /* Another has populated it */
71613 + pud_free(mm, new);
71614 + else
71615 + pgd_populate_kernel(mm, pgd, new);
71616 + spin_unlock(&mm->page_table_lock);
71617 + return 0;
71618 +}
71619 #endif /* __PAGETABLE_PUD_FOLDED */
71620
71621 #ifndef __PAGETABLE_PMD_FOLDED
71622 @@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71623 spin_unlock(&mm->page_table_lock);
71624 return 0;
71625 }
71626 +
71627 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71628 +{
71629 + pmd_t *new = pmd_alloc_one(mm, address);
71630 + if (!new)
71631 + return -ENOMEM;
71632 +
71633 + smp_wmb(); /* See comment in __pte_alloc */
71634 +
71635 + spin_lock(&mm->page_table_lock);
71636 +#ifndef __ARCH_HAS_4LEVEL_HACK
71637 + if (pud_present(*pud)) /* Another has populated it */
71638 + pmd_free(mm, new);
71639 + else
71640 + pud_populate_kernel(mm, pud, new);
71641 +#else
71642 + if (pgd_present(*pud)) /* Another has populated it */
71643 + pmd_free(mm, new);
71644 + else
71645 + pgd_populate_kernel(mm, pud, new);
71646 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71647 + spin_unlock(&mm->page_table_lock);
71648 + return 0;
71649 +}
71650 #endif /* __PAGETABLE_PMD_FOLDED */
71651
71652 int make_pages_present(unsigned long addr, unsigned long end)
71653 @@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71654 gate_vma.vm_start = FIXADDR_USER_START;
71655 gate_vma.vm_end = FIXADDR_USER_END;
71656 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71657 - gate_vma.vm_page_prot = __P101;
71658 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71659
71660 return 0;
71661 }
71662 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71663 index 1d771e4..f9a6808 100644
71664 --- a/mm/mempolicy.c
71665 +++ b/mm/mempolicy.c
71666 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71667 unsigned long vmstart;
71668 unsigned long vmend;
71669
71670 +#ifdef CONFIG_PAX_SEGMEXEC
71671 + struct vm_area_struct *vma_m;
71672 +#endif
71673 +
71674 vma = find_vma(mm, start);
71675 if (!vma || vma->vm_start > start)
71676 return -EFAULT;
71677 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71678 if (err)
71679 goto out;
71680 }
71681 +
71682 +#ifdef CONFIG_PAX_SEGMEXEC
71683 + vma_m = pax_find_mirror_vma(vma);
71684 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71685 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71686 + if (err)
71687 + goto out;
71688 + }
71689 +#endif
71690 +
71691 }
71692
71693 out:
71694 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71695
71696 if (end < start)
71697 return -EINVAL;
71698 +
71699 +#ifdef CONFIG_PAX_SEGMEXEC
71700 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71701 + if (end > SEGMEXEC_TASK_SIZE)
71702 + return -EINVAL;
71703 + } else
71704 +#endif
71705 +
71706 + if (end > TASK_SIZE)
71707 + return -EINVAL;
71708 +
71709 if (end == start)
71710 return 0;
71711
71712 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71713 */
71714 tcred = __task_cred(task);
71715 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71716 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71717 - !capable(CAP_SYS_NICE)) {
71718 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71719 rcu_read_unlock();
71720 err = -EPERM;
71721 goto out_put;
71722 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71723 goto out;
71724 }
71725
71726 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71727 + if (mm != current->mm &&
71728 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71729 + mmput(mm);
71730 + err = -EPERM;
71731 + goto out;
71732 + }
71733 +#endif
71734 +
71735 err = do_migrate_pages(mm, old, new,
71736 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71737
71738 diff --git a/mm/mlock.c b/mm/mlock.c
71739 index ef726e8..cd7f1ec 100644
71740 --- a/mm/mlock.c
71741 +++ b/mm/mlock.c
71742 @@ -13,6 +13,7 @@
71743 #include <linux/pagemap.h>
71744 #include <linux/mempolicy.h>
71745 #include <linux/syscalls.h>
71746 +#include <linux/security.h>
71747 #include <linux/sched.h>
71748 #include <linux/export.h>
71749 #include <linux/rmap.h>
71750 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71751 {
71752 unsigned long nstart, end, tmp;
71753 struct vm_area_struct * vma, * prev;
71754 - int error;
71755 + int error = 0;
71756
71757 VM_BUG_ON(start & ~PAGE_MASK);
71758 VM_BUG_ON(len != PAGE_ALIGN(len));
71759 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71760 return -EINVAL;
71761 if (end == start)
71762 return 0;
71763 + if (end > TASK_SIZE)
71764 + return -EINVAL;
71765 +
71766 vma = find_vma(current->mm, start);
71767 if (!vma || vma->vm_start > start)
71768 return -ENOMEM;
71769 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71770 for (nstart = start ; ; ) {
71771 vm_flags_t newflags;
71772
71773 +#ifdef CONFIG_PAX_SEGMEXEC
71774 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71775 + break;
71776 +#endif
71777 +
71778 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71779
71780 newflags = vma->vm_flags | VM_LOCKED;
71781 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71782 lock_limit >>= PAGE_SHIFT;
71783
71784 /* check against resource limits */
71785 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71786 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71787 error = do_mlock(start, len, 1);
71788 up_write(&current->mm->mmap_sem);
71789 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71790 static int do_mlockall(int flags)
71791 {
71792 struct vm_area_struct * vma, * prev = NULL;
71793 - unsigned int def_flags = 0;
71794
71795 if (flags & MCL_FUTURE)
71796 - def_flags = VM_LOCKED;
71797 - current->mm->def_flags = def_flags;
71798 + current->mm->def_flags |= VM_LOCKED;
71799 + else
71800 + current->mm->def_flags &= ~VM_LOCKED;
71801 if (flags == MCL_FUTURE)
71802 goto out;
71803
71804 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71805 vm_flags_t newflags;
71806
71807 +#ifdef CONFIG_PAX_SEGMEXEC
71808 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71809 + break;
71810 +#endif
71811 +
71812 + BUG_ON(vma->vm_end > TASK_SIZE);
71813 newflags = vma->vm_flags | VM_LOCKED;
71814 if (!(flags & MCL_CURRENT))
71815 newflags &= ~VM_LOCKED;
71816 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71817 lock_limit >>= PAGE_SHIFT;
71818
71819 ret = -ENOMEM;
71820 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71821 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71822 capable(CAP_IPC_LOCK))
71823 ret = do_mlockall(flags);
71824 diff --git a/mm/mmap.c b/mm/mmap.c
71825 index 3edfcdf..4a27ae9 100644
71826 --- a/mm/mmap.c
71827 +++ b/mm/mmap.c
71828 @@ -47,6 +47,16 @@
71829 #define arch_rebalance_pgtables(addr, len) (addr)
71830 #endif
71831
71832 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71833 +{
71834 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71835 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71836 + up_read(&mm->mmap_sem);
71837 + BUG();
71838 + }
71839 +#endif
71840 +}
71841 +
71842 static void unmap_region(struct mm_struct *mm,
71843 struct vm_area_struct *vma, struct vm_area_struct *prev,
71844 unsigned long start, unsigned long end);
71845 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71846 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71847 *
71848 */
71849 -pgprot_t protection_map[16] = {
71850 +pgprot_t protection_map[16] __read_only = {
71851 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71852 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71853 };
71854
71855 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71856 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71857 {
71858 - return __pgprot(pgprot_val(protection_map[vm_flags &
71859 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71860 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71861 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71862 +
71863 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71864 + if (!(__supported_pte_mask & _PAGE_NX) &&
71865 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71866 + (vm_flags & (VM_READ | VM_WRITE)))
71867 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71868 +#endif
71869 +
71870 + return prot;
71871 }
71872 EXPORT_SYMBOL(vm_get_page_prot);
71873
71874 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71875 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71876 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71877 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71878 /*
71879 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71880 * other variables. It can be updated by several CPUs frequently.
71881 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71882 struct vm_area_struct *next = vma->vm_next;
71883
71884 might_sleep();
71885 + BUG_ON(vma->vm_mirror);
71886 if (vma->vm_ops && vma->vm_ops->close)
71887 vma->vm_ops->close(vma);
71888 if (vma->vm_file) {
71889 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71890 * not page aligned -Ram Gupta
71891 */
71892 rlim = rlimit(RLIMIT_DATA);
71893 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71894 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71895 (mm->end_data - mm->start_data) > rlim)
71896 goto out;
71897 @@ -708,6 +730,12 @@ static int
71898 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71899 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71900 {
71901 +
71902 +#ifdef CONFIG_PAX_SEGMEXEC
71903 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71904 + return 0;
71905 +#endif
71906 +
71907 if (is_mergeable_vma(vma, file, vm_flags) &&
71908 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71909 if (vma->vm_pgoff == vm_pgoff)
71910 @@ -727,6 +755,12 @@ static int
71911 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71912 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71913 {
71914 +
71915 +#ifdef CONFIG_PAX_SEGMEXEC
71916 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71917 + return 0;
71918 +#endif
71919 +
71920 if (is_mergeable_vma(vma, file, vm_flags) &&
71921 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71922 pgoff_t vm_pglen;
71923 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71924 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71925 struct vm_area_struct *prev, unsigned long addr,
71926 unsigned long end, unsigned long vm_flags,
71927 - struct anon_vma *anon_vma, struct file *file,
71928 + struct anon_vma *anon_vma, struct file *file,
71929 pgoff_t pgoff, struct mempolicy *policy)
71930 {
71931 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71932 struct vm_area_struct *area, *next;
71933 int err;
71934
71935 +#ifdef CONFIG_PAX_SEGMEXEC
71936 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71937 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71938 +
71939 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71940 +#endif
71941 +
71942 /*
71943 * We later require that vma->vm_flags == vm_flags,
71944 * so this tests vma->vm_flags & VM_SPECIAL, too.
71945 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71946 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71947 next = next->vm_next;
71948
71949 +#ifdef CONFIG_PAX_SEGMEXEC
71950 + if (prev)
71951 + prev_m = pax_find_mirror_vma(prev);
71952 + if (area)
71953 + area_m = pax_find_mirror_vma(area);
71954 + if (next)
71955 + next_m = pax_find_mirror_vma(next);
71956 +#endif
71957 +
71958 /*
71959 * Can it merge with the predecessor?
71960 */
71961 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71962 /* cases 1, 6 */
71963 err = vma_adjust(prev, prev->vm_start,
71964 next->vm_end, prev->vm_pgoff, NULL);
71965 - } else /* cases 2, 5, 7 */
71966 +
71967 +#ifdef CONFIG_PAX_SEGMEXEC
71968 + if (!err && prev_m)
71969 + err = vma_adjust(prev_m, prev_m->vm_start,
71970 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71971 +#endif
71972 +
71973 + } else { /* cases 2, 5, 7 */
71974 err = vma_adjust(prev, prev->vm_start,
71975 end, prev->vm_pgoff, NULL);
71976 +
71977 +#ifdef CONFIG_PAX_SEGMEXEC
71978 + if (!err && prev_m)
71979 + err = vma_adjust(prev_m, prev_m->vm_start,
71980 + end_m, prev_m->vm_pgoff, NULL);
71981 +#endif
71982 +
71983 + }
71984 if (err)
71985 return NULL;
71986 khugepaged_enter_vma_merge(prev);
71987 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71988 mpol_equal(policy, vma_policy(next)) &&
71989 can_vma_merge_before(next, vm_flags,
71990 anon_vma, file, pgoff+pglen)) {
71991 - if (prev && addr < prev->vm_end) /* case 4 */
71992 + if (prev && addr < prev->vm_end) { /* case 4 */
71993 err = vma_adjust(prev, prev->vm_start,
71994 addr, prev->vm_pgoff, NULL);
71995 - else /* cases 3, 8 */
71996 +
71997 +#ifdef CONFIG_PAX_SEGMEXEC
71998 + if (!err && prev_m)
71999 + err = vma_adjust(prev_m, prev_m->vm_start,
72000 + addr_m, prev_m->vm_pgoff, NULL);
72001 +#endif
72002 +
72003 + } else { /* cases 3, 8 */
72004 err = vma_adjust(area, addr, next->vm_end,
72005 next->vm_pgoff - pglen, NULL);
72006 +
72007 +#ifdef CONFIG_PAX_SEGMEXEC
72008 + if (!err && area_m)
72009 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72010 + next_m->vm_pgoff - pglen, NULL);
72011 +#endif
72012 +
72013 + }
72014 if (err)
72015 return NULL;
72016 khugepaged_enter_vma_merge(area);
72017 @@ -940,14 +1020,11 @@ none:
72018 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72019 struct file *file, long pages)
72020 {
72021 - const unsigned long stack_flags
72022 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72023 -
72024 if (file) {
72025 mm->shared_vm += pages;
72026 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72027 mm->exec_vm += pages;
72028 - } else if (flags & stack_flags)
72029 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72030 mm->stack_vm += pages;
72031 if (flags & (VM_RESERVED|VM_IO))
72032 mm->reserved_vm += pages;
72033 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72034 * (the exception is when the underlying filesystem is noexec
72035 * mounted, in which case we dont add PROT_EXEC.)
72036 */
72037 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72038 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72039 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72040 prot |= PROT_EXEC;
72041
72042 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72043 /* Obtain the address to map to. we verify (or select) it and ensure
72044 * that it represents a valid section of the address space.
72045 */
72046 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72047 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72048 if (addr & ~PAGE_MASK)
72049 return addr;
72050
72051 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72052 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72053 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72054
72055 +#ifdef CONFIG_PAX_MPROTECT
72056 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72057 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72058 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72059 + gr_log_rwxmmap(file);
72060 +
72061 +#ifdef CONFIG_PAX_EMUPLT
72062 + vm_flags &= ~VM_EXEC;
72063 +#else
72064 + return -EPERM;
72065 +#endif
72066 +
72067 + }
72068 +
72069 + if (!(vm_flags & VM_EXEC))
72070 + vm_flags &= ~VM_MAYEXEC;
72071 +#else
72072 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72073 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72074 +#endif
72075 + else
72076 + vm_flags &= ~VM_MAYWRITE;
72077 + }
72078 +#endif
72079 +
72080 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72081 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72082 + vm_flags &= ~VM_PAGEEXEC;
72083 +#endif
72084 +
72085 if (flags & MAP_LOCKED)
72086 if (!can_do_mlock())
72087 return -EPERM;
72088 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72089 locked += mm->locked_vm;
72090 lock_limit = rlimit(RLIMIT_MEMLOCK);
72091 lock_limit >>= PAGE_SHIFT;
72092 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72093 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72094 return -EAGAIN;
72095 }
72096 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72097 }
72098 }
72099
72100 + if (!gr_acl_handle_mmap(file, prot))
72101 + return -EACCES;
72102 +
72103 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72104 }
72105
72106 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72107 vm_flags_t vm_flags = vma->vm_flags;
72108
72109 /* If it was private or non-writable, the write bit is already clear */
72110 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72111 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72112 return 0;
72113
72114 /* The backer wishes to know when pages are first written to? */
72115 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72116 unsigned long charged = 0;
72117 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72118
72119 +#ifdef CONFIG_PAX_SEGMEXEC
72120 + struct vm_area_struct *vma_m = NULL;
72121 +#endif
72122 +
72123 + /*
72124 + * mm->mmap_sem is required to protect against another thread
72125 + * changing the mappings in case we sleep.
72126 + */
72127 + verify_mm_writelocked(mm);
72128 +
72129 /* Clear old maps */
72130 error = -ENOMEM;
72131 -munmap_back:
72132 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72133 if (vma && vma->vm_start < addr + len) {
72134 if (do_munmap(mm, addr, len))
72135 return -ENOMEM;
72136 - goto munmap_back;
72137 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72138 + BUG_ON(vma && vma->vm_start < addr + len);
72139 }
72140
72141 /* Check against address space limit. */
72142 @@ -1280,6 +1401,16 @@ munmap_back:
72143 goto unacct_error;
72144 }
72145
72146 +#ifdef CONFIG_PAX_SEGMEXEC
72147 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72148 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72149 + if (!vma_m) {
72150 + error = -ENOMEM;
72151 + goto free_vma;
72152 + }
72153 + }
72154 +#endif
72155 +
72156 vma->vm_mm = mm;
72157 vma->vm_start = addr;
72158 vma->vm_end = addr + len;
72159 @@ -1304,6 +1435,19 @@ munmap_back:
72160 error = file->f_op->mmap(file, vma);
72161 if (error)
72162 goto unmap_and_free_vma;
72163 +
72164 +#ifdef CONFIG_PAX_SEGMEXEC
72165 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72166 + added_exe_file_vma(mm);
72167 +#endif
72168 +
72169 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72170 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72171 + vma->vm_flags |= VM_PAGEEXEC;
72172 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72173 + }
72174 +#endif
72175 +
72176 if (vm_flags & VM_EXECUTABLE)
72177 added_exe_file_vma(mm);
72178
72179 @@ -1341,6 +1485,11 @@ munmap_back:
72180 vma_link(mm, vma, prev, rb_link, rb_parent);
72181 file = vma->vm_file;
72182
72183 +#ifdef CONFIG_PAX_SEGMEXEC
72184 + if (vma_m)
72185 + BUG_ON(pax_mirror_vma(vma_m, vma));
72186 +#endif
72187 +
72188 /* Once vma denies write, undo our temporary denial count */
72189 if (correct_wcount)
72190 atomic_inc(&inode->i_writecount);
72191 @@ -1349,6 +1498,7 @@ out:
72192
72193 mm->total_vm += len >> PAGE_SHIFT;
72194 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72195 + track_exec_limit(mm, addr, addr + len, vm_flags);
72196 if (vm_flags & VM_LOCKED) {
72197 if (!mlock_vma_pages_range(vma, addr, addr + len))
72198 mm->locked_vm += (len >> PAGE_SHIFT);
72199 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72200 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72201 charged = 0;
72202 free_vma:
72203 +
72204 +#ifdef CONFIG_PAX_SEGMEXEC
72205 + if (vma_m)
72206 + kmem_cache_free(vm_area_cachep, vma_m);
72207 +#endif
72208 +
72209 kmem_cache_free(vm_area_cachep, vma);
72210 unacct_error:
72211 if (charged)
72212 @@ -1378,6 +1534,44 @@ unacct_error:
72213 return error;
72214 }
72215
72216 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72217 +{
72218 + if (!vma) {
72219 +#ifdef CONFIG_STACK_GROWSUP
72220 + if (addr > sysctl_heap_stack_gap)
72221 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72222 + else
72223 + vma = find_vma(current->mm, 0);
72224 + if (vma && (vma->vm_flags & VM_GROWSUP))
72225 + return false;
72226 +#endif
72227 + return true;
72228 + }
72229 +
72230 + if (addr + len > vma->vm_start)
72231 + return false;
72232 +
72233 + if (vma->vm_flags & VM_GROWSDOWN)
72234 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72235 +#ifdef CONFIG_STACK_GROWSUP
72236 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72237 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72238 +#endif
72239 +
72240 + return true;
72241 +}
72242 +
72243 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72244 +{
72245 + if (vma->vm_start < len)
72246 + return -ENOMEM;
72247 + if (!(vma->vm_flags & VM_GROWSDOWN))
72248 + return vma->vm_start - len;
72249 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72250 + return vma->vm_start - len - sysctl_heap_stack_gap;
72251 + return -ENOMEM;
72252 +}
72253 +
72254 /* Get an address range which is currently unmapped.
72255 * For shmat() with addr=0.
72256 *
72257 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72258 if (flags & MAP_FIXED)
72259 return addr;
72260
72261 +#ifdef CONFIG_PAX_RANDMMAP
72262 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72263 +#endif
72264 +
72265 if (addr) {
72266 addr = PAGE_ALIGN(addr);
72267 - vma = find_vma(mm, addr);
72268 - if (TASK_SIZE - len >= addr &&
72269 - (!vma || addr + len <= vma->vm_start))
72270 - return addr;
72271 + if (TASK_SIZE - len >= addr) {
72272 + vma = find_vma(mm, addr);
72273 + if (check_heap_stack_gap(vma, addr, len))
72274 + return addr;
72275 + }
72276 }
72277 if (len > mm->cached_hole_size) {
72278 - start_addr = addr = mm->free_area_cache;
72279 + start_addr = addr = mm->free_area_cache;
72280 } else {
72281 - start_addr = addr = TASK_UNMAPPED_BASE;
72282 - mm->cached_hole_size = 0;
72283 + start_addr = addr = mm->mmap_base;
72284 + mm->cached_hole_size = 0;
72285 }
72286
72287 full_search:
72288 @@ -1426,34 +1625,40 @@ full_search:
72289 * Start a new search - just in case we missed
72290 * some holes.
72291 */
72292 - if (start_addr != TASK_UNMAPPED_BASE) {
72293 - addr = TASK_UNMAPPED_BASE;
72294 - start_addr = addr;
72295 + if (start_addr != mm->mmap_base) {
72296 + start_addr = addr = mm->mmap_base;
72297 mm->cached_hole_size = 0;
72298 goto full_search;
72299 }
72300 return -ENOMEM;
72301 }
72302 - if (!vma || addr + len <= vma->vm_start) {
72303 - /*
72304 - * Remember the place where we stopped the search:
72305 - */
72306 - mm->free_area_cache = addr + len;
72307 - return addr;
72308 - }
72309 + if (check_heap_stack_gap(vma, addr, len))
72310 + break;
72311 if (addr + mm->cached_hole_size < vma->vm_start)
72312 mm->cached_hole_size = vma->vm_start - addr;
72313 addr = vma->vm_end;
72314 }
72315 +
72316 + /*
72317 + * Remember the place where we stopped the search:
72318 + */
72319 + mm->free_area_cache = addr + len;
72320 + return addr;
72321 }
72322 #endif
72323
72324 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72325 {
72326 +
72327 +#ifdef CONFIG_PAX_SEGMEXEC
72328 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72329 + return;
72330 +#endif
72331 +
72332 /*
72333 * Is this a new hole at the lowest possible address?
72334 */
72335 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72336 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72337 mm->free_area_cache = addr;
72338 }
72339
72340 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72341 {
72342 struct vm_area_struct *vma;
72343 struct mm_struct *mm = current->mm;
72344 - unsigned long addr = addr0, start_addr;
72345 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72346
72347 /* requested length too big for entire address space */
72348 if (len > TASK_SIZE)
72349 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72350 if (flags & MAP_FIXED)
72351 return addr;
72352
72353 +#ifdef CONFIG_PAX_RANDMMAP
72354 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72355 +#endif
72356 +
72357 /* requesting a specific address */
72358 if (addr) {
72359 addr = PAGE_ALIGN(addr);
72360 - vma = find_vma(mm, addr);
72361 - if (TASK_SIZE - len >= addr &&
72362 - (!vma || addr + len <= vma->vm_start))
72363 - return addr;
72364 + if (TASK_SIZE - len >= addr) {
72365 + vma = find_vma(mm, addr);
72366 + if (check_heap_stack_gap(vma, addr, len))
72367 + return addr;
72368 + }
72369 }
72370
72371 /* check if free_area_cache is useful for us */
72372 @@ -1508,7 +1718,7 @@ try_again:
72373 * return with success:
72374 */
72375 vma = find_vma(mm, addr);
72376 - if (!vma || addr+len <= vma->vm_start)
72377 + if (check_heap_stack_gap(vma, addr, len))
72378 /* remember the address as a hint for next time */
72379 return (mm->free_area_cache = addr);
72380
72381 @@ -1517,8 +1727,8 @@ try_again:
72382 mm->cached_hole_size = vma->vm_start - addr;
72383
72384 /* try just below the current vma->vm_start */
72385 - addr = vma->vm_start-len;
72386 - } while (len < vma->vm_start);
72387 + addr = skip_heap_stack_gap(vma, len);
72388 + } while (!IS_ERR_VALUE(addr));
72389
72390 fail:
72391 /*
72392 @@ -1541,13 +1751,21 @@ fail:
72393 * can happen with large stack limits and large mmap()
72394 * allocations.
72395 */
72396 + mm->mmap_base = TASK_UNMAPPED_BASE;
72397 +
72398 +#ifdef CONFIG_PAX_RANDMMAP
72399 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72400 + mm->mmap_base += mm->delta_mmap;
72401 +#endif
72402 +
72403 + mm->free_area_cache = mm->mmap_base;
72404 mm->cached_hole_size = ~0UL;
72405 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72406 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72407 /*
72408 * Restore the topdown base:
72409 */
72410 - mm->free_area_cache = mm->mmap_base;
72411 + mm->mmap_base = base;
72412 + mm->free_area_cache = base;
72413 mm->cached_hole_size = ~0UL;
72414
72415 return addr;
72416 @@ -1556,6 +1774,12 @@ fail:
72417
72418 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72419 {
72420 +
72421 +#ifdef CONFIG_PAX_SEGMEXEC
72422 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72423 + return;
72424 +#endif
72425 +
72426 /*
72427 * Is this a new hole at the highest possible address?
72428 */
72429 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72430 mm->free_area_cache = addr;
72431
72432 /* dont allow allocations above current base */
72433 - if (mm->free_area_cache > mm->mmap_base)
72434 + if (mm->free_area_cache > mm->mmap_base) {
72435 mm->free_area_cache = mm->mmap_base;
72436 + mm->cached_hole_size = ~0UL;
72437 + }
72438 }
72439
72440 unsigned long
72441 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72442 return vma;
72443 }
72444
72445 +#ifdef CONFIG_PAX_SEGMEXEC
72446 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72447 +{
72448 + struct vm_area_struct *vma_m;
72449 +
72450 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72451 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72452 + BUG_ON(vma->vm_mirror);
72453 + return NULL;
72454 + }
72455 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72456 + vma_m = vma->vm_mirror;
72457 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72458 + BUG_ON(vma->vm_file != vma_m->vm_file);
72459 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72460 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72461 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72462 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72463 + return vma_m;
72464 +}
72465 +#endif
72466 +
72467 /*
72468 * Verify that the stack growth is acceptable and
72469 * update accounting. This is shared with both the
72470 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72471 return -ENOMEM;
72472
72473 /* Stack limit test */
72474 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72475 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72476 return -ENOMEM;
72477
72478 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72479 locked = mm->locked_vm + grow;
72480 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72481 limit >>= PAGE_SHIFT;
72482 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72483 if (locked > limit && !capable(CAP_IPC_LOCK))
72484 return -ENOMEM;
72485 }
72486 @@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72487 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72488 * vma is the last one with address > vma->vm_end. Have to extend vma.
72489 */
72490 +#ifndef CONFIG_IA64
72491 +static
72492 +#endif
72493 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72494 {
72495 int error;
72496 + bool locknext;
72497
72498 if (!(vma->vm_flags & VM_GROWSUP))
72499 return -EFAULT;
72500
72501 + /* Also guard against wrapping around to address 0. */
72502 + if (address < PAGE_ALIGN(address+1))
72503 + address = PAGE_ALIGN(address+1);
72504 + else
72505 + return -ENOMEM;
72506 +
72507 /*
72508 * We must make sure the anon_vma is allocated
72509 * so that the anon_vma locking is not a noop.
72510 */
72511 if (unlikely(anon_vma_prepare(vma)))
72512 return -ENOMEM;
72513 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72514 + if (locknext && anon_vma_prepare(vma->vm_next))
72515 + return -ENOMEM;
72516 vma_lock_anon_vma(vma);
72517 + if (locknext)
72518 + vma_lock_anon_vma(vma->vm_next);
72519
72520 /*
72521 * vma->vm_start/vm_end cannot change under us because the caller
72522 * is required to hold the mmap_sem in read mode. We need the
72523 - * anon_vma lock to serialize against concurrent expand_stacks.
72524 - * Also guard against wrapping around to address 0.
72525 + * anon_vma locks to serialize against concurrent expand_stacks
72526 + * and expand_upwards.
72527 */
72528 - if (address < PAGE_ALIGN(address+4))
72529 - address = PAGE_ALIGN(address+4);
72530 - else {
72531 - vma_unlock_anon_vma(vma);
72532 - return -ENOMEM;
72533 - }
72534 error = 0;
72535
72536 /* Somebody else might have raced and expanded it already */
72537 - if (address > vma->vm_end) {
72538 + 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)
72539 + error = -ENOMEM;
72540 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72541 unsigned long size, grow;
72542
72543 size = address - vma->vm_start;
72544 @@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72545 }
72546 }
72547 }
72548 + if (locknext)
72549 + vma_unlock_anon_vma(vma->vm_next);
72550 vma_unlock_anon_vma(vma);
72551 khugepaged_enter_vma_merge(vma);
72552 return error;
72553 @@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72554 unsigned long address)
72555 {
72556 int error;
72557 + bool lockprev = false;
72558 + struct vm_area_struct *prev;
72559
72560 /*
72561 * We must make sure the anon_vma is allocated
72562 @@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72563 if (error)
72564 return error;
72565
72566 + prev = vma->vm_prev;
72567 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72568 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72569 +#endif
72570 + if (lockprev && anon_vma_prepare(prev))
72571 + return -ENOMEM;
72572 + if (lockprev)
72573 + vma_lock_anon_vma(prev);
72574 +
72575 vma_lock_anon_vma(vma);
72576
72577 /*
72578 @@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72579 */
72580
72581 /* Somebody else might have raced and expanded it already */
72582 - if (address < vma->vm_start) {
72583 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72584 + error = -ENOMEM;
72585 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72586 unsigned long size, grow;
72587
72588 +#ifdef CONFIG_PAX_SEGMEXEC
72589 + struct vm_area_struct *vma_m;
72590 +
72591 + vma_m = pax_find_mirror_vma(vma);
72592 +#endif
72593 +
72594 size = vma->vm_end - address;
72595 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72596
72597 @@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72598 if (!error) {
72599 vma->vm_start = address;
72600 vma->vm_pgoff -= grow;
72601 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72602 +
72603 +#ifdef CONFIG_PAX_SEGMEXEC
72604 + if (vma_m) {
72605 + vma_m->vm_start -= grow << PAGE_SHIFT;
72606 + vma_m->vm_pgoff -= grow;
72607 + }
72608 +#endif
72609 +
72610 perf_event_mmap(vma);
72611 }
72612 }
72613 }
72614 vma_unlock_anon_vma(vma);
72615 + if (lockprev)
72616 + vma_unlock_anon_vma(prev);
72617 khugepaged_enter_vma_merge(vma);
72618 return error;
72619 }
72620 @@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72621 do {
72622 long nrpages = vma_pages(vma);
72623
72624 +#ifdef CONFIG_PAX_SEGMEXEC
72625 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72626 + vma = remove_vma(vma);
72627 + continue;
72628 + }
72629 +#endif
72630 +
72631 if (vma->vm_flags & VM_ACCOUNT)
72632 nr_accounted += nrpages;
72633 mm->total_vm -= nrpages;
72634 @@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72635 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72636 vma->vm_prev = NULL;
72637 do {
72638 +
72639 +#ifdef CONFIG_PAX_SEGMEXEC
72640 + if (vma->vm_mirror) {
72641 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72642 + vma->vm_mirror->vm_mirror = NULL;
72643 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72644 + vma->vm_mirror = NULL;
72645 + }
72646 +#endif
72647 +
72648 rb_erase(&vma->vm_rb, &mm->mm_rb);
72649 mm->map_count--;
72650 tail_vma = vma;
72651 @@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72652 struct vm_area_struct *new;
72653 int err = -ENOMEM;
72654
72655 +#ifdef CONFIG_PAX_SEGMEXEC
72656 + struct vm_area_struct *vma_m, *new_m = NULL;
72657 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72658 +#endif
72659 +
72660 if (is_vm_hugetlb_page(vma) && (addr &
72661 ~(huge_page_mask(hstate_vma(vma)))))
72662 return -EINVAL;
72663
72664 +#ifdef CONFIG_PAX_SEGMEXEC
72665 + vma_m = pax_find_mirror_vma(vma);
72666 +#endif
72667 +
72668 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72669 if (!new)
72670 goto out_err;
72671
72672 +#ifdef CONFIG_PAX_SEGMEXEC
72673 + if (vma_m) {
72674 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72675 + if (!new_m) {
72676 + kmem_cache_free(vm_area_cachep, new);
72677 + goto out_err;
72678 + }
72679 + }
72680 +#endif
72681 +
72682 /* most fields are the same, copy all, and then fixup */
72683 *new = *vma;
72684
72685 @@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72686 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72687 }
72688
72689 +#ifdef CONFIG_PAX_SEGMEXEC
72690 + if (vma_m) {
72691 + *new_m = *vma_m;
72692 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72693 + new_m->vm_mirror = new;
72694 + new->vm_mirror = new_m;
72695 +
72696 + if (new_below)
72697 + new_m->vm_end = addr_m;
72698 + else {
72699 + new_m->vm_start = addr_m;
72700 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72701 + }
72702 + }
72703 +#endif
72704 +
72705 pol = mpol_dup(vma_policy(vma));
72706 if (IS_ERR(pol)) {
72707 err = PTR_ERR(pol);
72708 @@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72709 else
72710 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72711
72712 +#ifdef CONFIG_PAX_SEGMEXEC
72713 + if (!err && vma_m) {
72714 + if (anon_vma_clone(new_m, vma_m))
72715 + goto out_free_mpol;
72716 +
72717 + mpol_get(pol);
72718 + vma_set_policy(new_m, pol);
72719 +
72720 + if (new_m->vm_file) {
72721 + get_file(new_m->vm_file);
72722 + if (vma_m->vm_flags & VM_EXECUTABLE)
72723 + added_exe_file_vma(mm);
72724 + }
72725 +
72726 + if (new_m->vm_ops && new_m->vm_ops->open)
72727 + new_m->vm_ops->open(new_m);
72728 +
72729 + if (new_below)
72730 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72731 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72732 + else
72733 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72734 +
72735 + if (err) {
72736 + if (new_m->vm_ops && new_m->vm_ops->close)
72737 + new_m->vm_ops->close(new_m);
72738 + if (new_m->vm_file) {
72739 + if (vma_m->vm_flags & VM_EXECUTABLE)
72740 + removed_exe_file_vma(mm);
72741 + fput(new_m->vm_file);
72742 + }
72743 + mpol_put(pol);
72744 + }
72745 + }
72746 +#endif
72747 +
72748 /* Success. */
72749 if (!err)
72750 return 0;
72751 @@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72752 removed_exe_file_vma(mm);
72753 fput(new->vm_file);
72754 }
72755 - unlink_anon_vmas(new);
72756 out_free_mpol:
72757 mpol_put(pol);
72758 out_free_vma:
72759 +
72760 +#ifdef CONFIG_PAX_SEGMEXEC
72761 + if (new_m) {
72762 + unlink_anon_vmas(new_m);
72763 + kmem_cache_free(vm_area_cachep, new_m);
72764 + }
72765 +#endif
72766 +
72767 + unlink_anon_vmas(new);
72768 kmem_cache_free(vm_area_cachep, new);
72769 out_err:
72770 return err;
72771 @@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72772 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72773 unsigned long addr, int new_below)
72774 {
72775 +
72776 +#ifdef CONFIG_PAX_SEGMEXEC
72777 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72778 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72779 + if (mm->map_count >= sysctl_max_map_count-1)
72780 + return -ENOMEM;
72781 + } else
72782 +#endif
72783 +
72784 if (mm->map_count >= sysctl_max_map_count)
72785 return -ENOMEM;
72786
72787 @@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72788 * work. This now handles partial unmappings.
72789 * Jeremy Fitzhardinge <jeremy@goop.org>
72790 */
72791 +#ifdef CONFIG_PAX_SEGMEXEC
72792 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72793 {
72794 + int ret = __do_munmap(mm, start, len);
72795 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72796 + return ret;
72797 +
72798 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72799 +}
72800 +
72801 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72802 +#else
72803 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72804 +#endif
72805 +{
72806 unsigned long end;
72807 struct vm_area_struct *vma, *prev, *last;
72808
72809 + /*
72810 + * mm->mmap_sem is required to protect against another thread
72811 + * changing the mappings in case we sleep.
72812 + */
72813 + verify_mm_writelocked(mm);
72814 +
72815 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72816 return -EINVAL;
72817
72818 @@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72819 /* Fix up all other VM information */
72820 remove_vma_list(mm, vma);
72821
72822 + track_exec_limit(mm, start, end, 0UL);
72823 +
72824 return 0;
72825 }
72826
72827 @@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72828 int ret;
72829 struct mm_struct *mm = current->mm;
72830
72831 +
72832 +#ifdef CONFIG_PAX_SEGMEXEC
72833 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72834 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72835 + return -EINVAL;
72836 +#endif
72837 +
72838 down_write(&mm->mmap_sem);
72839 ret = do_munmap(mm, start, len);
72840 up_write(&mm->mmap_sem);
72841 @@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72842 return vm_munmap(addr, len);
72843 }
72844
72845 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72846 -{
72847 -#ifdef CONFIG_DEBUG_VM
72848 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72849 - WARN_ON(1);
72850 - up_read(&mm->mmap_sem);
72851 - }
72852 -#endif
72853 -}
72854 -
72855 /*
72856 * this is really a simplified "do_mmap". it only handles
72857 * anonymous maps. eventually we may be able to do some
72858 @@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72859 struct rb_node ** rb_link, * rb_parent;
72860 pgoff_t pgoff = addr >> PAGE_SHIFT;
72861 int error;
72862 + unsigned long charged;
72863
72864 len = PAGE_ALIGN(len);
72865 if (!len)
72866 @@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72867
72868 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72869
72870 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72871 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72872 + flags &= ~VM_EXEC;
72873 +
72874 +#ifdef CONFIG_PAX_MPROTECT
72875 + if (mm->pax_flags & MF_PAX_MPROTECT)
72876 + flags &= ~VM_MAYEXEC;
72877 +#endif
72878 +
72879 + }
72880 +#endif
72881 +
72882 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72883 if (error & ~PAGE_MASK)
72884 return error;
72885
72886 + charged = len >> PAGE_SHIFT;
72887 +
72888 /*
72889 * mlock MCL_FUTURE?
72890 */
72891 if (mm->def_flags & VM_LOCKED) {
72892 unsigned long locked, lock_limit;
72893 - locked = len >> PAGE_SHIFT;
72894 + locked = charged;
72895 locked += mm->locked_vm;
72896 lock_limit = rlimit(RLIMIT_MEMLOCK);
72897 lock_limit >>= PAGE_SHIFT;
72898 @@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72899 /*
72900 * Clear old maps. this also does some error checking for us
72901 */
72902 - munmap_back:
72903 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72904 if (vma && vma->vm_start < addr + len) {
72905 if (do_munmap(mm, addr, len))
72906 return -ENOMEM;
72907 - goto munmap_back;
72908 - }
72909 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72910 + BUG_ON(vma && vma->vm_start < addr + len);
72911 + }
72912
72913 /* Check against address space limits *after* clearing old maps... */
72914 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72915 + if (!may_expand_vm(mm, charged))
72916 return -ENOMEM;
72917
72918 if (mm->map_count > sysctl_max_map_count)
72919 return -ENOMEM;
72920
72921 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72922 + if (security_vm_enough_memory_mm(mm, charged))
72923 return -ENOMEM;
72924
72925 /* Can we just expand an old private anonymous mapping? */
72926 @@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72927 */
72928 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72929 if (!vma) {
72930 - vm_unacct_memory(len >> PAGE_SHIFT);
72931 + vm_unacct_memory(charged);
72932 return -ENOMEM;
72933 }
72934
72935 @@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72936 vma_link(mm, vma, prev, rb_link, rb_parent);
72937 out:
72938 perf_event_mmap(vma);
72939 - mm->total_vm += len >> PAGE_SHIFT;
72940 + mm->total_vm += charged;
72941 if (flags & VM_LOCKED) {
72942 if (!mlock_vma_pages_range(vma, addr, addr + len))
72943 - mm->locked_vm += (len >> PAGE_SHIFT);
72944 + mm->locked_vm += charged;
72945 }
72946 + track_exec_limit(mm, addr, addr + len, flags);
72947 return addr;
72948 }
72949
72950 @@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
72951 while (vma) {
72952 if (vma->vm_flags & VM_ACCOUNT)
72953 nr_accounted += vma_pages(vma);
72954 + vma->vm_mirror = NULL;
72955 vma = remove_vma(vma);
72956 }
72957 vm_unacct_memory(nr_accounted);
72958 @@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72959 struct vm_area_struct * __vma, * prev;
72960 struct rb_node ** rb_link, * rb_parent;
72961
72962 +#ifdef CONFIG_PAX_SEGMEXEC
72963 + struct vm_area_struct *vma_m = NULL;
72964 +#endif
72965 +
72966 + if (security_mmap_addr(vma->vm_start))
72967 + return -EPERM;
72968 +
72969 /*
72970 * The vm_pgoff of a purely anonymous vma should be irrelevant
72971 * until its first write fault, when page's anon_vma and index
72972 @@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72973 if (vma->vm_file && uprobe_mmap(vma))
72974 return -EINVAL;
72975
72976 +#ifdef CONFIG_PAX_SEGMEXEC
72977 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72978 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72979 + if (!vma_m)
72980 + return -ENOMEM;
72981 + }
72982 +#endif
72983 +
72984 vma_link(mm, vma, prev, rb_link, rb_parent);
72985 +
72986 +#ifdef CONFIG_PAX_SEGMEXEC
72987 + if (vma_m)
72988 + BUG_ON(pax_mirror_vma(vma_m, vma));
72989 +#endif
72990 +
72991 return 0;
72992 }
72993
72994 @@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72995 struct mempolicy *pol;
72996 bool faulted_in_anon_vma = true;
72997
72998 + BUG_ON(vma->vm_mirror);
72999 +
73000 /*
73001 * If anonymous vma has not yet been faulted, update new pgoff
73002 * to match new location, to increase its chance of merging.
73003 @@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73004 return NULL;
73005 }
73006
73007 +#ifdef CONFIG_PAX_SEGMEXEC
73008 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73009 +{
73010 + struct vm_area_struct *prev_m;
73011 + struct rb_node **rb_link_m, *rb_parent_m;
73012 + struct mempolicy *pol_m;
73013 +
73014 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73015 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73016 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73017 + *vma_m = *vma;
73018 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73019 + if (anon_vma_clone(vma_m, vma))
73020 + return -ENOMEM;
73021 + pol_m = vma_policy(vma_m);
73022 + mpol_get(pol_m);
73023 + vma_set_policy(vma_m, pol_m);
73024 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73025 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73026 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73027 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73028 + if (vma_m->vm_file)
73029 + get_file(vma_m->vm_file);
73030 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73031 + vma_m->vm_ops->open(vma_m);
73032 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73033 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73034 + vma_m->vm_mirror = vma;
73035 + vma->vm_mirror = vma_m;
73036 + return 0;
73037 +}
73038 +#endif
73039 +
73040 /*
73041 * Return true if the calling process may expand its vm space by the passed
73042 * number of pages
73043 @@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73044
73045 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73046
73047 +#ifdef CONFIG_PAX_RANDMMAP
73048 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73049 + cur -= mm->brk_gap;
73050 +#endif
73051 +
73052 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73053 if (cur + npages > lim)
73054 return 0;
73055 return 1;
73056 @@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73057 vma->vm_start = addr;
73058 vma->vm_end = addr + len;
73059
73060 +#ifdef CONFIG_PAX_MPROTECT
73061 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73062 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73063 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73064 + return -EPERM;
73065 + if (!(vm_flags & VM_EXEC))
73066 + vm_flags &= ~VM_MAYEXEC;
73067 +#else
73068 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73069 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73070 +#endif
73071 + else
73072 + vm_flags &= ~VM_MAYWRITE;
73073 + }
73074 +#endif
73075 +
73076 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73077 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73078
73079 diff --git a/mm/mprotect.c b/mm/mprotect.c
73080 index a409926..8b32e6d 100644
73081 --- a/mm/mprotect.c
73082 +++ b/mm/mprotect.c
73083 @@ -23,10 +23,17 @@
73084 #include <linux/mmu_notifier.h>
73085 #include <linux/migrate.h>
73086 #include <linux/perf_event.h>
73087 +
73088 +#ifdef CONFIG_PAX_MPROTECT
73089 +#include <linux/elf.h>
73090 +#include <linux/binfmts.h>
73091 +#endif
73092 +
73093 #include <asm/uaccess.h>
73094 #include <asm/pgtable.h>
73095 #include <asm/cacheflush.h>
73096 #include <asm/tlbflush.h>
73097 +#include <asm/mmu_context.h>
73098
73099 #ifndef pgprot_modify
73100 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73101 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73102 flush_tlb_range(vma, start, end);
73103 }
73104
73105 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73106 +/* called while holding the mmap semaphor for writing except stack expansion */
73107 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73108 +{
73109 + unsigned long oldlimit, newlimit = 0UL;
73110 +
73111 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73112 + return;
73113 +
73114 + spin_lock(&mm->page_table_lock);
73115 + oldlimit = mm->context.user_cs_limit;
73116 + if ((prot & VM_EXEC) && oldlimit < end)
73117 + /* USER_CS limit moved up */
73118 + newlimit = end;
73119 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73120 + /* USER_CS limit moved down */
73121 + newlimit = start;
73122 +
73123 + if (newlimit) {
73124 + mm->context.user_cs_limit = newlimit;
73125 +
73126 +#ifdef CONFIG_SMP
73127 + wmb();
73128 + cpus_clear(mm->context.cpu_user_cs_mask);
73129 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73130 +#endif
73131 +
73132 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73133 + }
73134 + spin_unlock(&mm->page_table_lock);
73135 + if (newlimit == end) {
73136 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73137 +
73138 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73139 + if (is_vm_hugetlb_page(vma))
73140 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73141 + else
73142 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73143 + }
73144 +}
73145 +#endif
73146 +
73147 int
73148 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73149 unsigned long start, unsigned long end, unsigned long newflags)
73150 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73151 int error;
73152 int dirty_accountable = 0;
73153
73154 +#ifdef CONFIG_PAX_SEGMEXEC
73155 + struct vm_area_struct *vma_m = NULL;
73156 + unsigned long start_m, end_m;
73157 +
73158 + start_m = start + SEGMEXEC_TASK_SIZE;
73159 + end_m = end + SEGMEXEC_TASK_SIZE;
73160 +#endif
73161 +
73162 if (newflags == oldflags) {
73163 *pprev = vma;
73164 return 0;
73165 }
73166
73167 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73168 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73169 +
73170 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73171 + return -ENOMEM;
73172 +
73173 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73174 + return -ENOMEM;
73175 + }
73176 +
73177 /*
73178 * If we make a private mapping writable we increase our commit;
73179 * but (without finer accounting) cannot reduce our commit if we
73180 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73181 }
73182 }
73183
73184 +#ifdef CONFIG_PAX_SEGMEXEC
73185 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73186 + if (start != vma->vm_start) {
73187 + error = split_vma(mm, vma, start, 1);
73188 + if (error)
73189 + goto fail;
73190 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73191 + *pprev = (*pprev)->vm_next;
73192 + }
73193 +
73194 + if (end != vma->vm_end) {
73195 + error = split_vma(mm, vma, end, 0);
73196 + if (error)
73197 + goto fail;
73198 + }
73199 +
73200 + if (pax_find_mirror_vma(vma)) {
73201 + error = __do_munmap(mm, start_m, end_m - start_m);
73202 + if (error)
73203 + goto fail;
73204 + } else {
73205 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73206 + if (!vma_m) {
73207 + error = -ENOMEM;
73208 + goto fail;
73209 + }
73210 + vma->vm_flags = newflags;
73211 + error = pax_mirror_vma(vma_m, vma);
73212 + if (error) {
73213 + vma->vm_flags = oldflags;
73214 + goto fail;
73215 + }
73216 + }
73217 + }
73218 +#endif
73219 +
73220 /*
73221 * First try to merge with previous and/or next vma.
73222 */
73223 @@ -204,9 +307,21 @@ success:
73224 * vm_flags and vm_page_prot are protected by the mmap_sem
73225 * held in write mode.
73226 */
73227 +
73228 +#ifdef CONFIG_PAX_SEGMEXEC
73229 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73230 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73231 +#endif
73232 +
73233 vma->vm_flags = newflags;
73234 +
73235 +#ifdef CONFIG_PAX_MPROTECT
73236 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73237 + mm->binfmt->handle_mprotect(vma, newflags);
73238 +#endif
73239 +
73240 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73241 - vm_get_page_prot(newflags));
73242 + vm_get_page_prot(vma->vm_flags));
73243
73244 if (vma_wants_writenotify(vma)) {
73245 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73246 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73247 end = start + len;
73248 if (end <= start)
73249 return -ENOMEM;
73250 +
73251 +#ifdef CONFIG_PAX_SEGMEXEC
73252 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73253 + if (end > SEGMEXEC_TASK_SIZE)
73254 + return -EINVAL;
73255 + } else
73256 +#endif
73257 +
73258 + if (end > TASK_SIZE)
73259 + return -EINVAL;
73260 +
73261 if (!arch_validate_prot(prot))
73262 return -EINVAL;
73263
73264 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73265 /*
73266 * Does the application expect PROT_READ to imply PROT_EXEC:
73267 */
73268 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73269 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73270 prot |= PROT_EXEC;
73271
73272 vm_flags = calc_vm_prot_bits(prot);
73273 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73274 if (start > vma->vm_start)
73275 prev = vma;
73276
73277 +#ifdef CONFIG_PAX_MPROTECT
73278 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73279 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73280 +#endif
73281 +
73282 for (nstart = start ; ; ) {
73283 unsigned long newflags;
73284
73285 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73286
73287 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73288 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73289 + if (prot & (PROT_WRITE | PROT_EXEC))
73290 + gr_log_rwxmprotect(vma->vm_file);
73291 +
73292 + error = -EACCES;
73293 + goto out;
73294 + }
73295 +
73296 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73297 error = -EACCES;
73298 goto out;
73299 }
73300 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73301 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73302 if (error)
73303 goto out;
73304 +
73305 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73306 +
73307 nstart = tmp;
73308
73309 if (nstart < prev->vm_end)
73310 diff --git a/mm/mremap.c b/mm/mremap.c
73311 index 21fed20..6822658 100644
73312 --- a/mm/mremap.c
73313 +++ b/mm/mremap.c
73314 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73315 continue;
73316 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73317 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73318 +
73319 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73320 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73321 + pte = pte_exprotect(pte);
73322 +#endif
73323 +
73324 set_pte_at(mm, new_addr, new_pte, pte);
73325 }
73326
73327 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73328 if (is_vm_hugetlb_page(vma))
73329 goto Einval;
73330
73331 +#ifdef CONFIG_PAX_SEGMEXEC
73332 + if (pax_find_mirror_vma(vma))
73333 + goto Einval;
73334 +#endif
73335 +
73336 /* We can't remap across vm area boundaries */
73337 if (old_len > vma->vm_end - addr)
73338 goto Efault;
73339 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73340 unsigned long ret = -EINVAL;
73341 unsigned long charged = 0;
73342 unsigned long map_flags;
73343 + unsigned long pax_task_size = TASK_SIZE;
73344
73345 if (new_addr & ~PAGE_MASK)
73346 goto out;
73347
73348 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73349 +#ifdef CONFIG_PAX_SEGMEXEC
73350 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73351 + pax_task_size = SEGMEXEC_TASK_SIZE;
73352 +#endif
73353 +
73354 + pax_task_size -= PAGE_SIZE;
73355 +
73356 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73357 goto out;
73358
73359 /* Check if the location we're moving into overlaps the
73360 * old location at all, and fail if it does.
73361 */
73362 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73363 - goto out;
73364 -
73365 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73366 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73367 goto out;
73368
73369 ret = do_munmap(mm, new_addr, new_len);
73370 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73371 struct vm_area_struct *vma;
73372 unsigned long ret = -EINVAL;
73373 unsigned long charged = 0;
73374 + unsigned long pax_task_size = TASK_SIZE;
73375
73376 down_write(&current->mm->mmap_sem);
73377
73378 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73379 if (!new_len)
73380 goto out;
73381
73382 +#ifdef CONFIG_PAX_SEGMEXEC
73383 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73384 + pax_task_size = SEGMEXEC_TASK_SIZE;
73385 +#endif
73386 +
73387 + pax_task_size -= PAGE_SIZE;
73388 +
73389 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73390 + old_len > pax_task_size || addr > pax_task_size-old_len)
73391 + goto out;
73392 +
73393 if (flags & MREMAP_FIXED) {
73394 if (flags & MREMAP_MAYMOVE)
73395 ret = mremap_to(addr, old_len, new_addr, new_len);
73396 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73397 addr + new_len);
73398 }
73399 ret = addr;
73400 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73401 goto out;
73402 }
73403 }
73404 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73405 goto out;
73406 }
73407
73408 + map_flags = vma->vm_flags;
73409 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73410 + if (!(ret & ~PAGE_MASK)) {
73411 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73412 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73413 + }
73414 }
73415 out:
73416 if (ret & ~PAGE_MASK)
73417 diff --git a/mm/nommu.c b/mm/nommu.c
73418 index d4b0c10..ed421b5 100644
73419 --- a/mm/nommu.c
73420 +++ b/mm/nommu.c
73421 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73422 int sysctl_overcommit_ratio = 50; /* default is 50% */
73423 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73424 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73425 -int heap_stack_gap = 0;
73426
73427 atomic_long_t mmap_pages_allocated;
73428
73429 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73430 EXPORT_SYMBOL(find_vma);
73431
73432 /*
73433 - * find a VMA
73434 - * - we don't extend stack VMAs under NOMMU conditions
73435 - */
73436 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73437 -{
73438 - return find_vma(mm, addr);
73439 -}
73440 -
73441 -/*
73442 * expand a stack to a given address
73443 * - not supported under NOMMU conditions
73444 */
73445 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73446
73447 /* most fields are the same, copy all, and then fixup */
73448 *new = *vma;
73449 + INIT_LIST_HEAD(&new->anon_vma_chain);
73450 *region = *vma->vm_region;
73451 new->vm_region = region;
73452
73453 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73454 index 4a4f921..eaa5e3a 100644
73455 --- a/mm/page_alloc.c
73456 +++ b/mm/page_alloc.c
73457 @@ -336,7 +336,7 @@ out:
73458 * This usage means that zero-order pages may not be compound.
73459 */
73460
73461 -static void free_compound_page(struct page *page)
73462 +void free_compound_page(struct page *page)
73463 {
73464 __free_pages_ok(page, compound_order(page));
73465 }
73466 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73467 int i;
73468 int bad = 0;
73469
73470 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73471 + unsigned long index = 1UL << order;
73472 +#endif
73473 +
73474 trace_mm_page_free(page, order);
73475 kmemcheck_free_shadow(page, order);
73476
73477 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73478 debug_check_no_obj_freed(page_address(page),
73479 PAGE_SIZE << order);
73480 }
73481 +
73482 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73483 + for (; index; --index)
73484 + sanitize_highpage(page + index - 1);
73485 +#endif
73486 +
73487 arch_free_page(page, order);
73488 kernel_map_pages(page, 1 << order, 0);
73489
73490 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73491 arch_alloc_page(page, order);
73492 kernel_map_pages(page, 1 << order, 1);
73493
73494 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73495 if (gfp_flags & __GFP_ZERO)
73496 prep_zero_page(page, order, gfp_flags);
73497 +#endif
73498
73499 if (order && (gfp_flags & __GFP_COMP))
73500 prep_compound_page(page, order);
73501 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73502 unsigned long pfn;
73503
73504 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73505 +#ifdef CONFIG_X86_32
73506 + /* boot failures in VMware 8 on 32bit vanilla since
73507 + this change */
73508 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73509 +#else
73510 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73511 +#endif
73512 return 1;
73513 }
73514 return 0;
73515 diff --git a/mm/percpu.c b/mm/percpu.c
73516 index bb4be74..a43ea85 100644
73517 --- a/mm/percpu.c
73518 +++ b/mm/percpu.c
73519 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73520 static unsigned int pcpu_high_unit_cpu __read_mostly;
73521
73522 /* the address of the first chunk which starts with the kernel static area */
73523 -void *pcpu_base_addr __read_mostly;
73524 +void *pcpu_base_addr __read_only;
73525 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73526
73527 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73528 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73529 index 926b466..b23df53 100644
73530 --- a/mm/process_vm_access.c
73531 +++ b/mm/process_vm_access.c
73532 @@ -13,6 +13,7 @@
73533 #include <linux/uio.h>
73534 #include <linux/sched.h>
73535 #include <linux/highmem.h>
73536 +#include <linux/security.h>
73537 #include <linux/ptrace.h>
73538 #include <linux/slab.h>
73539 #include <linux/syscalls.h>
73540 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73541 size_t iov_l_curr_offset = 0;
73542 ssize_t iov_len;
73543
73544 + return -ENOSYS; // PaX: until properly audited
73545 +
73546 /*
73547 * Work out how many pages of struct pages we're going to need
73548 * when eventually calling get_user_pages
73549 */
73550 for (i = 0; i < riovcnt; i++) {
73551 iov_len = rvec[i].iov_len;
73552 - if (iov_len > 0) {
73553 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73554 - + iov_len)
73555 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73556 - / PAGE_SIZE + 1;
73557 - nr_pages = max(nr_pages, nr_pages_iov);
73558 - }
73559 + if (iov_len <= 0)
73560 + continue;
73561 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73562 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73563 + nr_pages = max(nr_pages, nr_pages_iov);
73564 }
73565
73566 if (nr_pages == 0)
73567 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73568 goto free_proc_pages;
73569 }
73570
73571 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73572 + rc = -EPERM;
73573 + goto put_task_struct;
73574 + }
73575 +
73576 mm = mm_access(task, PTRACE_MODE_ATTACH);
73577 if (!mm || IS_ERR(mm)) {
73578 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73579 diff --git a/mm/rmap.c b/mm/rmap.c
73580 index 0f3b7cd..c5652b6 100644
73581 --- a/mm/rmap.c
73582 +++ b/mm/rmap.c
73583 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73584 struct anon_vma *anon_vma = vma->anon_vma;
73585 struct anon_vma_chain *avc;
73586
73587 +#ifdef CONFIG_PAX_SEGMEXEC
73588 + struct anon_vma_chain *avc_m = NULL;
73589 +#endif
73590 +
73591 might_sleep();
73592 if (unlikely(!anon_vma)) {
73593 struct mm_struct *mm = vma->vm_mm;
73594 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73595 if (!avc)
73596 goto out_enomem;
73597
73598 +#ifdef CONFIG_PAX_SEGMEXEC
73599 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73600 + if (!avc_m)
73601 + goto out_enomem_free_avc;
73602 +#endif
73603 +
73604 anon_vma = find_mergeable_anon_vma(vma);
73605 allocated = NULL;
73606 if (!anon_vma) {
73607 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73608 /* page_table_lock to protect against threads */
73609 spin_lock(&mm->page_table_lock);
73610 if (likely(!vma->anon_vma)) {
73611 +
73612 +#ifdef CONFIG_PAX_SEGMEXEC
73613 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73614 +
73615 + if (vma_m) {
73616 + BUG_ON(vma_m->anon_vma);
73617 + vma_m->anon_vma = anon_vma;
73618 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
73619 + avc_m = NULL;
73620 + }
73621 +#endif
73622 +
73623 vma->anon_vma = anon_vma;
73624 anon_vma_chain_link(vma, avc, anon_vma);
73625 allocated = NULL;
73626 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73627
73628 if (unlikely(allocated))
73629 put_anon_vma(allocated);
73630 +
73631 +#ifdef CONFIG_PAX_SEGMEXEC
73632 + if (unlikely(avc_m))
73633 + anon_vma_chain_free(avc_m);
73634 +#endif
73635 +
73636 if (unlikely(avc))
73637 anon_vma_chain_free(avc);
73638 }
73639 return 0;
73640
73641 out_enomem_free_avc:
73642 +
73643 +#ifdef CONFIG_PAX_SEGMEXEC
73644 + if (avc_m)
73645 + anon_vma_chain_free(avc_m);
73646 +#endif
73647 +
73648 anon_vma_chain_free(avc);
73649 out_enomem:
73650 return -ENOMEM;
73651 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73652 * Attach the anon_vmas from src to dst.
73653 * Returns 0 on success, -ENOMEM on failure.
73654 */
73655 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73656 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73657 {
73658 struct anon_vma_chain *avc, *pavc;
73659 struct anon_vma *root = NULL;
73660 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73661 * the corresponding VMA in the parent process is attached to.
73662 * Returns 0 on success, non-zero on failure.
73663 */
73664 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73665 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73666 {
73667 struct anon_vma_chain *avc;
73668 struct anon_vma *anon_vma;
73669 diff --git a/mm/shmem.c b/mm/shmem.c
73670 index bd10636..5c16d49 100644
73671 --- a/mm/shmem.c
73672 +++ b/mm/shmem.c
73673 @@ -31,7 +31,7 @@
73674 #include <linux/export.h>
73675 #include <linux/swap.h>
73676
73677 -static struct vfsmount *shm_mnt;
73678 +struct vfsmount *shm_mnt;
73679
73680 #ifdef CONFIG_SHMEM
73681 /*
73682 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73683 #define BOGO_DIRENT_SIZE 20
73684
73685 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73686 -#define SHORT_SYMLINK_LEN 128
73687 +#define SHORT_SYMLINK_LEN 64
73688
73689 struct shmem_xattr {
73690 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73691 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73692 int err = -ENOMEM;
73693
73694 /* Round up to L1_CACHE_BYTES to resist false sharing */
73695 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73696 - L1_CACHE_BYTES), GFP_KERNEL);
73697 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73698 if (!sbinfo)
73699 return -ENOMEM;
73700
73701 diff --git a/mm/slab.c b/mm/slab.c
73702 index e901a36..ca479fc 100644
73703 --- a/mm/slab.c
73704 +++ b/mm/slab.c
73705 @@ -153,7 +153,7 @@
73706
73707 /* Legal flag mask for kmem_cache_create(). */
73708 #if DEBUG
73709 -# define CREATE_MASK (SLAB_RED_ZONE | \
73710 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73711 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73712 SLAB_CACHE_DMA | \
73713 SLAB_STORE_USER | \
73714 @@ -161,7 +161,7 @@
73715 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73716 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73717 #else
73718 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73719 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73720 SLAB_CACHE_DMA | \
73721 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73722 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73723 @@ -290,7 +290,7 @@ struct kmem_list3 {
73724 * Need this for bootstrapping a per node allocator.
73725 */
73726 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73727 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73728 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73729 #define CACHE_CACHE 0
73730 #define SIZE_AC MAX_NUMNODES
73731 #define SIZE_L3 (2 * MAX_NUMNODES)
73732 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73733 if ((x)->max_freeable < i) \
73734 (x)->max_freeable = i; \
73735 } while (0)
73736 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73737 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73738 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73739 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73740 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73741 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73742 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73743 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73744 #else
73745 #define STATS_INC_ACTIVE(x) do { } while (0)
73746 #define STATS_DEC_ACTIVE(x) do { } while (0)
73747 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73748 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73749 */
73750 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73751 - const struct slab *slab, void *obj)
73752 + const struct slab *slab, const void *obj)
73753 {
73754 u32 offset = (obj - slab->s_mem);
73755 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73756 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73757 struct cache_names {
73758 char *name;
73759 char *name_dma;
73760 + char *name_usercopy;
73761 };
73762
73763 static struct cache_names __initdata cache_names[] = {
73764 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73765 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73766 #include <linux/kmalloc_sizes.h>
73767 - {NULL,}
73768 + {NULL}
73769 #undef CACHE
73770 };
73771
73772 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73773 if (unlikely(gfpflags & GFP_DMA))
73774 return csizep->cs_dmacachep;
73775 #endif
73776 +
73777 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73778 + if (unlikely(gfpflags & GFP_USERCOPY))
73779 + return csizep->cs_usercopycachep;
73780 +#endif
73781 +
73782 return csizep->cs_cachep;
73783 }
73784
73785 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73786 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73787 sizes[INDEX_AC].cs_size,
73788 ARCH_KMALLOC_MINALIGN,
73789 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73790 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73791 NULL);
73792
73793 if (INDEX_AC != INDEX_L3) {
73794 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73795 kmem_cache_create(names[INDEX_L3].name,
73796 sizes[INDEX_L3].cs_size,
73797 ARCH_KMALLOC_MINALIGN,
73798 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73799 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73800 NULL);
73801 }
73802
73803 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73804 sizes->cs_cachep = kmem_cache_create(names->name,
73805 sizes->cs_size,
73806 ARCH_KMALLOC_MINALIGN,
73807 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73808 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73809 NULL);
73810 }
73811 #ifdef CONFIG_ZONE_DMA
73812 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73813 SLAB_PANIC,
73814 NULL);
73815 #endif
73816 +
73817 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73818 + sizes->cs_usercopycachep = kmem_cache_create(
73819 + names->name_usercopy,
73820 + sizes->cs_size,
73821 + ARCH_KMALLOC_MINALIGN,
73822 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73823 + NULL);
73824 +#endif
73825 +
73826 sizes++;
73827 names++;
73828 }
73829 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73830 }
73831 /* cpu stats */
73832 {
73833 - unsigned long allochit = atomic_read(&cachep->allochit);
73834 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73835 - unsigned long freehit = atomic_read(&cachep->freehit);
73836 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73837 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73838 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73839 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73840 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73841
73842 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73843 allochit, allocmiss, freehit, freemiss);
73844 @@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73845 {
73846 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73847 #ifdef CONFIG_DEBUG_SLAB_LEAK
73848 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73849 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73850 #endif
73851 return 0;
73852 }
73853 module_init(slab_proc_init);
73854 #endif
73855
73856 +bool is_usercopy_object(const void *ptr)
73857 +{
73858 + struct page *page;
73859 + struct kmem_cache *cachep;
73860 +
73861 + if (ZERO_OR_NULL_PTR(ptr))
73862 + return false;
73863 +
73864 + if (!virt_addr_valid(ptr))
73865 + return false;
73866 +
73867 + page = virt_to_head_page(ptr);
73868 +
73869 + if (!PageSlab(page))
73870 + return false;
73871 +
73872 + cachep = page_get_cache(page);
73873 + return cachep->flags & SLAB_USERCOPY;
73874 +}
73875 +
73876 +#ifdef CONFIG_PAX_USERCOPY
73877 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73878 +{
73879 + struct page *page;
73880 + struct kmem_cache *cachep;
73881 + struct slab *slabp;
73882 + unsigned int objnr;
73883 + unsigned long offset;
73884 +
73885 + if (ZERO_OR_NULL_PTR(ptr))
73886 + return "<null>";
73887 +
73888 + if (!virt_addr_valid(ptr))
73889 + return NULL;
73890 +
73891 + page = virt_to_head_page(ptr);
73892 +
73893 + if (!PageSlab(page))
73894 + return NULL;
73895 +
73896 + cachep = page_get_cache(page);
73897 + if (!(cachep->flags & SLAB_USERCOPY))
73898 + return cachep->name;
73899 +
73900 + slabp = page_get_slab(page);
73901 + objnr = obj_to_index(cachep, slabp, ptr);
73902 + BUG_ON(objnr >= cachep->num);
73903 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73904 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73905 + return NULL;
73906 +
73907 + return cachep->name;
73908 +}
73909 +#endif
73910 +
73911 /**
73912 * ksize - get the actual amount of memory allocated for a given object
73913 * @objp: Pointer to the object
73914 diff --git a/mm/slob.c b/mm/slob.c
73915 index 8105be4..3c15e57 100644
73916 --- a/mm/slob.c
73917 +++ b/mm/slob.c
73918 @@ -29,7 +29,7 @@
73919 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73920 * alloc_pages() directly, allocating compound pages so the page order
73921 * does not have to be separately tracked, and also stores the exact
73922 - * allocation size in page->private so that it can be used to accurately
73923 + * allocation size in slob_page->size so that it can be used to accurately
73924 * provide ksize(). These objects are detected in kfree() because slob_page()
73925 * is false for them.
73926 *
73927 @@ -58,6 +58,7 @@
73928 */
73929
73930 #include <linux/kernel.h>
73931 +#include <linux/sched.h>
73932 #include <linux/slab.h>
73933 #include <linux/mm.h>
73934 #include <linux/swap.h> /* struct reclaim_state */
73935 @@ -102,7 +103,8 @@ struct slob_page {
73936 unsigned long flags; /* mandatory */
73937 atomic_t _count; /* mandatory */
73938 slobidx_t units; /* free units left in page */
73939 - unsigned long pad[2];
73940 + unsigned long pad[1];
73941 + unsigned long size; /* size when >=PAGE_SIZE */
73942 slob_t *free; /* first free slob_t in page */
73943 struct list_head list; /* linked list of free pages */
73944 };
73945 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73946 */
73947 static inline int is_slob_page(struct slob_page *sp)
73948 {
73949 - return PageSlab((struct page *)sp);
73950 + return PageSlab((struct page *)sp) && !sp->size;
73951 }
73952
73953 static inline void set_slob_page(struct slob_page *sp)
73954 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73955
73956 static inline struct slob_page *slob_page(const void *addr)
73957 {
73958 - return (struct slob_page *)virt_to_page(addr);
73959 + return (struct slob_page *)virt_to_head_page(addr);
73960 }
73961
73962 /*
73963 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73964 /*
73965 * Return the size of a slob block.
73966 */
73967 -static slobidx_t slob_units(slob_t *s)
73968 +static slobidx_t slob_units(const slob_t *s)
73969 {
73970 if (s->units > 0)
73971 return s->units;
73972 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73973 /*
73974 * Return the next free slob block pointer after this one.
73975 */
73976 -static slob_t *slob_next(slob_t *s)
73977 +static slob_t *slob_next(const slob_t *s)
73978 {
73979 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73980 slobidx_t next;
73981 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73982 /*
73983 * Returns true if s is the last free block in its page.
73984 */
73985 -static int slob_last(slob_t *s)
73986 +static int slob_last(const slob_t *s)
73987 {
73988 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73989 }
73990 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73991 if (!page)
73992 return NULL;
73993
73994 + set_slob_page(page);
73995 return page_address(page);
73996 }
73997
73998 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73999 if (!b)
74000 return NULL;
74001 sp = slob_page(b);
74002 - set_slob_page(sp);
74003
74004 spin_lock_irqsave(&slob_lock, flags);
74005 sp->units = SLOB_UNITS(PAGE_SIZE);
74006 sp->free = b;
74007 + sp->size = 0;
74008 INIT_LIST_HEAD(&sp->list);
74009 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74010 set_slob_page_free(sp, slob_list);
74011 @@ -476,10 +479,9 @@ out:
74012 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74013 */
74014
74015 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74016 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74017 {
74018 - unsigned int *m;
74019 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74020 + slob_t *m;
74021 void *ret;
74022
74023 gfp &= gfp_allowed_mask;
74024 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74025
74026 if (!m)
74027 return NULL;
74028 - *m = size;
74029 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74030 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74031 + m[0].units = size;
74032 + m[1].units = align;
74033 ret = (void *)m + align;
74034
74035 trace_kmalloc_node(_RET_IP_, ret,
74036 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74037 gfp |= __GFP_COMP;
74038 ret = slob_new_pages(gfp, order, node);
74039 if (ret) {
74040 - struct page *page;
74041 - page = virt_to_page(ret);
74042 - page->private = size;
74043 + struct slob_page *sp;
74044 + sp = slob_page(ret);
74045 + sp->size = size;
74046 }
74047
74048 trace_kmalloc_node(_RET_IP_, ret,
74049 size, PAGE_SIZE << order, gfp, node);
74050 }
74051
74052 - kmemleak_alloc(ret, size, 1, gfp);
74053 + return ret;
74054 +}
74055 +
74056 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74057 +{
74058 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74059 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74060 +
74061 + if (!ZERO_OR_NULL_PTR(ret))
74062 + kmemleak_alloc(ret, size, 1, gfp);
74063 return ret;
74064 }
74065 EXPORT_SYMBOL(__kmalloc_node);
74066 @@ -533,13 +547,83 @@ void kfree(const void *block)
74067 sp = slob_page(block);
74068 if (is_slob_page(sp)) {
74069 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74070 - unsigned int *m = (unsigned int *)(block - align);
74071 - slob_free(m, *m + align);
74072 - } else
74073 + slob_t *m = (slob_t *)(block - align);
74074 + slob_free(m, m[0].units + align);
74075 + } else {
74076 + clear_slob_page(sp);
74077 + free_slob_page(sp);
74078 + sp->size = 0;
74079 put_page(&sp->page);
74080 + }
74081 }
74082 EXPORT_SYMBOL(kfree);
74083
74084 +bool is_usercopy_object(const void *ptr)
74085 +{
74086 + return false;
74087 +}
74088 +
74089 +#ifdef CONFIG_PAX_USERCOPY
74090 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74091 +{
74092 + struct slob_page *sp;
74093 + const slob_t *free;
74094 + const void *base;
74095 + unsigned long flags;
74096 +
74097 + if (ZERO_OR_NULL_PTR(ptr))
74098 + return "<null>";
74099 +
74100 + if (!virt_addr_valid(ptr))
74101 + return NULL;
74102 +
74103 + sp = slob_page(ptr);
74104 + if (!PageSlab((struct page *)sp))
74105 + return NULL;
74106 +
74107 + if (sp->size) {
74108 + base = page_address(&sp->page);
74109 + if (base <= ptr && n <= sp->size - (ptr - base))
74110 + return NULL;
74111 + return "<slob>";
74112 + }
74113 +
74114 + /* some tricky double walking to find the chunk */
74115 + spin_lock_irqsave(&slob_lock, flags);
74116 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74117 + free = sp->free;
74118 +
74119 + while (!slob_last(free) && (void *)free <= ptr) {
74120 + base = free + slob_units(free);
74121 + free = slob_next(free);
74122 + }
74123 +
74124 + while (base < (void *)free) {
74125 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74126 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74127 + int offset;
74128 +
74129 + if (ptr < base + align)
74130 + break;
74131 +
74132 + offset = ptr - base - align;
74133 + if (offset >= m) {
74134 + base += size;
74135 + continue;
74136 + }
74137 +
74138 + if (n > m - offset)
74139 + break;
74140 +
74141 + spin_unlock_irqrestore(&slob_lock, flags);
74142 + return NULL;
74143 + }
74144 +
74145 + spin_unlock_irqrestore(&slob_lock, flags);
74146 + return "<slob>";
74147 +}
74148 +#endif
74149 +
74150 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74151 size_t ksize(const void *block)
74152 {
74153 @@ -552,10 +636,10 @@ size_t ksize(const void *block)
74154 sp = slob_page(block);
74155 if (is_slob_page(sp)) {
74156 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74157 - unsigned int *m = (unsigned int *)(block - align);
74158 - return SLOB_UNITS(*m) * SLOB_UNIT;
74159 + slob_t *m = (slob_t *)(block - align);
74160 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74161 } else
74162 - return sp->page.private;
74163 + return sp->size;
74164 }
74165 EXPORT_SYMBOL(ksize);
74166
74167 @@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74168 {
74169 struct kmem_cache *c;
74170
74171 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74172 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74173 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74174 +#else
74175 c = slob_alloc(sizeof(struct kmem_cache),
74176 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74177 +#endif
74178
74179 if (c) {
74180 c->name = name;
74181 @@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74182
74183 lockdep_trace_alloc(flags);
74184
74185 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74186 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74187 +#else
74188 if (c->size < PAGE_SIZE) {
74189 b = slob_alloc(c->size, flags, c->align, node);
74190 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74191 SLOB_UNITS(c->size) * SLOB_UNIT,
74192 flags, node);
74193 } else {
74194 + struct slob_page *sp;
74195 +
74196 b = slob_new_pages(flags, get_order(c->size), node);
74197 + sp = slob_page(b);
74198 + sp->size = c->size;
74199 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74200 PAGE_SIZE << get_order(c->size),
74201 flags, node);
74202 }
74203 +#endif
74204
74205 if (c->ctor)
74206 c->ctor(b);
74207 @@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74208
74209 static void __kmem_cache_free(void *b, int size)
74210 {
74211 - if (size < PAGE_SIZE)
74212 + struct slob_page *sp = slob_page(b);
74213 +
74214 + if (is_slob_page(sp))
74215 slob_free(b, size);
74216 - else
74217 + else {
74218 + clear_slob_page(sp);
74219 + free_slob_page(sp);
74220 + sp->size = 0;
74221 slob_free_pages(b, get_order(size));
74222 + }
74223 }
74224
74225 static void kmem_rcu_free(struct rcu_head *head)
74226 @@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74227
74228 void kmem_cache_free(struct kmem_cache *c, void *b)
74229 {
74230 + int size = c->size;
74231 +
74232 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74233 + if (size + c->align < PAGE_SIZE) {
74234 + size += c->align;
74235 + b -= c->align;
74236 + }
74237 +#endif
74238 +
74239 kmemleak_free_recursive(b, c->flags);
74240 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74241 struct slob_rcu *slob_rcu;
74242 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74243 - slob_rcu->size = c->size;
74244 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74245 + slob_rcu->size = size;
74246 call_rcu(&slob_rcu->head, kmem_rcu_free);
74247 } else {
74248 - __kmem_cache_free(b, c->size);
74249 + __kmem_cache_free(b, size);
74250 }
74251
74252 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74253 + trace_kfree(_RET_IP_, b);
74254 +#else
74255 trace_kmem_cache_free(_RET_IP_, b);
74256 +#endif
74257 +
74258 }
74259 EXPORT_SYMBOL(kmem_cache_free);
74260
74261 diff --git a/mm/slub.c b/mm/slub.c
74262 index 8c691fa..ff23a85 100644
74263 --- a/mm/slub.c
74264 +++ b/mm/slub.c
74265 @@ -209,7 +209,7 @@ struct track {
74266
74267 enum track_item { TRACK_ALLOC, TRACK_FREE };
74268
74269 -#ifdef CONFIG_SYSFS
74270 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74271 static int sysfs_slab_add(struct kmem_cache *);
74272 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74273 static void sysfs_slab_remove(struct kmem_cache *);
74274 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74275 if (!t->addr)
74276 return;
74277
74278 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74279 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74280 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74281 #ifdef CONFIG_STACKTRACE
74282 {
74283 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74284
74285 page = virt_to_head_page(x);
74286
74287 + BUG_ON(!PageSlab(page));
74288 +
74289 slab_free(s, page, x, _RET_IP_);
74290
74291 trace_kmem_cache_free(_RET_IP_, x);
74292 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
74293 * Merge control. If this is set then no merging of slab caches will occur.
74294 * (Could be removed. This was introduced to pacify the merge skeptics.)
74295 */
74296 -static int slub_nomerge;
74297 +static int slub_nomerge = 1;
74298
74299 /*
74300 * Calculate the order of allocation given an slab object size.
74301 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74302 else
74303 s->cpu_partial = 30;
74304
74305 - s->refcount = 1;
74306 + atomic_set(&s->refcount, 1);
74307 #ifdef CONFIG_NUMA
74308 s->remote_node_defrag_ratio = 1000;
74309 #endif
74310 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74311 void kmem_cache_destroy(struct kmem_cache *s)
74312 {
74313 down_write(&slub_lock);
74314 - s->refcount--;
74315 - if (!s->refcount) {
74316 + if (atomic_dec_and_test(&s->refcount)) {
74317 list_del(&s->list);
74318 up_write(&slub_lock);
74319 if (kmem_cache_close(s)) {
74320 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74321 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74322 #endif
74323
74324 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74325 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74326 +#endif
74327 +
74328 static int __init setup_slub_min_order(char *str)
74329 {
74330 get_option(&str, &slub_min_order);
74331 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74332 return kmalloc_dma_caches[index];
74333
74334 #endif
74335 +
74336 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74337 + if (flags & SLAB_USERCOPY)
74338 + return kmalloc_usercopy_caches[index];
74339 +
74340 +#endif
74341 +
74342 return kmalloc_caches[index];
74343 }
74344
74345 @@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74346 EXPORT_SYMBOL(__kmalloc_node);
74347 #endif
74348
74349 +bool is_usercopy_object(const void *ptr)
74350 +{
74351 + struct page *page;
74352 + struct kmem_cache *s;
74353 +
74354 + if (ZERO_OR_NULL_PTR(ptr))
74355 + return false;
74356 +
74357 + if (!virt_addr_valid(ptr))
74358 + return false;
74359 +
74360 + page = virt_to_head_page(ptr);
74361 +
74362 + if (!PageSlab(page))
74363 + return false;
74364 +
74365 + s = page->slab;
74366 + return s->flags & SLAB_USERCOPY;
74367 +}
74368 +
74369 +#ifdef CONFIG_PAX_USERCOPY
74370 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74371 +{
74372 + struct page *page;
74373 + struct kmem_cache *s;
74374 + unsigned long offset;
74375 +
74376 + if (ZERO_OR_NULL_PTR(ptr))
74377 + return "<null>";
74378 +
74379 + if (!virt_addr_valid(ptr))
74380 + return NULL;
74381 +
74382 + page = virt_to_head_page(ptr);
74383 +
74384 + if (!PageSlab(page))
74385 + return NULL;
74386 +
74387 + s = page->slab;
74388 + if (!(s->flags & SLAB_USERCOPY))
74389 + return s->name;
74390 +
74391 + offset = (ptr - page_address(page)) % s->size;
74392 + if (offset <= s->objsize && n <= s->objsize - offset)
74393 + return NULL;
74394 +
74395 + return s->name;
74396 +}
74397 +#endif
74398 +
74399 size_t ksize(const void *object)
74400 {
74401 struct page *page;
74402 @@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74403 int node;
74404
74405 list_add(&s->list, &slab_caches);
74406 - s->refcount = -1;
74407 + atomic_set(&s->refcount, -1);
74408
74409 for_each_node_state(node, N_NORMAL_MEMORY) {
74410 struct kmem_cache_node *n = get_node(s, node);
74411 @@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74412
74413 /* Caches that are not of the two-to-the-power-of size */
74414 if (KMALLOC_MIN_SIZE <= 32) {
74415 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74416 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74417 caches++;
74418 }
74419
74420 if (KMALLOC_MIN_SIZE <= 64) {
74421 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74422 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74423 caches++;
74424 }
74425
74426 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74427 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74428 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74429 caches++;
74430 }
74431
74432 @@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74433 }
74434 }
74435 #endif
74436 +
74437 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74438 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74439 + struct kmem_cache *s = kmalloc_caches[i];
74440 +
74441 + if (s && s->size) {
74442 + char *name = kasprintf(GFP_NOWAIT,
74443 + "usercopy-kmalloc-%d", s->objsize);
74444 +
74445 + BUG_ON(!name);
74446 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74447 + s->objsize, SLAB_USERCOPY);
74448 + }
74449 + }
74450 +#endif
74451 +
74452 printk(KERN_INFO
74453 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74454 " CPUs=%d, Nodes=%d\n",
74455 @@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74456 /*
74457 * We may have set a slab to be unmergeable during bootstrap.
74458 */
74459 - if (s->refcount < 0)
74460 + if (atomic_read(&s->refcount) < 0)
74461 return 1;
74462
74463 return 0;
74464 @@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74465 down_write(&slub_lock);
74466 s = find_mergeable(size, align, flags, name, ctor);
74467 if (s) {
74468 - s->refcount++;
74469 + atomic_inc(&s->refcount);
74470 /*
74471 * Adjust the object sizes so that we clear
74472 * the complete object on kzalloc.
74473 @@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74474 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74475
74476 if (sysfs_slab_alias(s, name)) {
74477 - s->refcount--;
74478 + atomic_dec(&s->refcount);
74479 goto err;
74480 }
74481 up_write(&slub_lock);
74482 @@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74483 }
74484 #endif
74485
74486 -#ifdef CONFIG_SYSFS
74487 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74488 static int count_inuse(struct page *page)
74489 {
74490 return page->inuse;
74491 @@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74492 validate_slab_cache(kmalloc_caches[9]);
74493 }
74494 #else
74495 -#ifdef CONFIG_SYSFS
74496 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74497 static void resiliency_test(void) {};
74498 #endif
74499 #endif
74500
74501 -#ifdef CONFIG_SYSFS
74502 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74503 enum slab_stat_type {
74504 SL_ALL, /* All slabs */
74505 SL_PARTIAL, /* Only partially allocated slabs */
74506 @@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74507
74508 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74509 {
74510 - return sprintf(buf, "%d\n", s->refcount - 1);
74511 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74512 }
74513 SLAB_ATTR_RO(aliases);
74514
74515 @@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74516 return name;
74517 }
74518
74519 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74520 static int sysfs_slab_add(struct kmem_cache *s)
74521 {
74522 int err;
74523 @@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74524 kobject_del(&s->kobj);
74525 kobject_put(&s->kobj);
74526 }
74527 +#endif
74528
74529 /*
74530 * Need to buffer aliases during bootup until sysfs becomes
74531 @@ -5355,6 +5435,7 @@ struct saved_alias {
74532
74533 static struct saved_alias *alias_list;
74534
74535 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74536 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74537 {
74538 struct saved_alias *al;
74539 @@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74540 alias_list = al;
74541 return 0;
74542 }
74543 +#endif
74544
74545 static int __init slab_sysfs_init(void)
74546 {
74547 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74548 index 1b7e22a..3fcd4f3 100644
74549 --- a/mm/sparse-vmemmap.c
74550 +++ b/mm/sparse-vmemmap.c
74551 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74552 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74553 if (!p)
74554 return NULL;
74555 - pud_populate(&init_mm, pud, p);
74556 + pud_populate_kernel(&init_mm, pud, p);
74557 }
74558 return pud;
74559 }
74560 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74561 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74562 if (!p)
74563 return NULL;
74564 - pgd_populate(&init_mm, pgd, p);
74565 + pgd_populate_kernel(&init_mm, pgd, p);
74566 }
74567 return pgd;
74568 }
74569 diff --git a/mm/swap.c b/mm/swap.c
74570 index 4e7e2ec..0c57830 100644
74571 --- a/mm/swap.c
74572 +++ b/mm/swap.c
74573 @@ -30,6 +30,7 @@
74574 #include <linux/backing-dev.h>
74575 #include <linux/memcontrol.h>
74576 #include <linux/gfp.h>
74577 +#include <linux/hugetlb.h>
74578
74579 #include "internal.h"
74580
74581 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74582
74583 __page_cache_release(page);
74584 dtor = get_compound_page_dtor(page);
74585 + if (!PageHuge(page))
74586 + BUG_ON(dtor != free_compound_page);
74587 (*dtor)(page);
74588 }
74589
74590 diff --git a/mm/swapfile.c b/mm/swapfile.c
74591 index 71373d0..11fa7d9 100644
74592 --- a/mm/swapfile.c
74593 +++ b/mm/swapfile.c
74594 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74595
74596 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74597 /* Activity counter to indicate that a swapon or swapoff has occurred */
74598 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74599 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74600
74601 static inline unsigned char swap_count(unsigned char ent)
74602 {
74603 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74604 }
74605 filp_close(swap_file, NULL);
74606 err = 0;
74607 - atomic_inc(&proc_poll_event);
74608 + atomic_inc_unchecked(&proc_poll_event);
74609 wake_up_interruptible(&proc_poll_wait);
74610
74611 out_dput:
74612 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74613
74614 poll_wait(file, &proc_poll_wait, wait);
74615
74616 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74617 - seq->poll_event = atomic_read(&proc_poll_event);
74618 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74619 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74620 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74621 }
74622
74623 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74624 return ret;
74625
74626 seq = file->private_data;
74627 - seq->poll_event = atomic_read(&proc_poll_event);
74628 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74629 return 0;
74630 }
74631
74632 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74633 (frontswap_map) ? "FS" : "");
74634
74635 mutex_unlock(&swapon_mutex);
74636 - atomic_inc(&proc_poll_event);
74637 + atomic_inc_unchecked(&proc_poll_event);
74638 wake_up_interruptible(&proc_poll_wait);
74639
74640 if (S_ISREG(inode->i_mode))
74641 diff --git a/mm/util.c b/mm/util.c
74642 index 8c7265a..c96d884 100644
74643 --- a/mm/util.c
74644 +++ b/mm/util.c
74645 @@ -285,6 +285,12 @@ done:
74646 void arch_pick_mmap_layout(struct mm_struct *mm)
74647 {
74648 mm->mmap_base = TASK_UNMAPPED_BASE;
74649 +
74650 +#ifdef CONFIG_PAX_RANDMMAP
74651 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74652 + mm->mmap_base += mm->delta_mmap;
74653 +#endif
74654 +
74655 mm->get_unmapped_area = arch_get_unmapped_area;
74656 mm->unmap_area = arch_unmap_area;
74657 }
74658 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74659 index 2aad499..2e608e8 100644
74660 --- a/mm/vmalloc.c
74661 +++ b/mm/vmalloc.c
74662 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74663
74664 pte = pte_offset_kernel(pmd, addr);
74665 do {
74666 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74667 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74668 +
74669 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74670 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74671 + BUG_ON(!pte_exec(*pte));
74672 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74673 + continue;
74674 + }
74675 +#endif
74676 +
74677 + {
74678 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74679 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74680 + }
74681 } while (pte++, addr += PAGE_SIZE, addr != end);
74682 }
74683
74684 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74685 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74686 {
74687 pte_t *pte;
74688 + int ret = -ENOMEM;
74689
74690 /*
74691 * nr is a running index into the array which helps higher level
74692 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74693 pte = pte_alloc_kernel(pmd, addr);
74694 if (!pte)
74695 return -ENOMEM;
74696 +
74697 + pax_open_kernel();
74698 do {
74699 struct page *page = pages[*nr];
74700
74701 - if (WARN_ON(!pte_none(*pte)))
74702 - return -EBUSY;
74703 - if (WARN_ON(!page))
74704 - return -ENOMEM;
74705 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74706 + if (pgprot_val(prot) & _PAGE_NX)
74707 +#endif
74708 +
74709 + if (WARN_ON(!pte_none(*pte))) {
74710 + ret = -EBUSY;
74711 + goto out;
74712 + }
74713 + if (WARN_ON(!page)) {
74714 + ret = -ENOMEM;
74715 + goto out;
74716 + }
74717 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74718 (*nr)++;
74719 } while (pte++, addr += PAGE_SIZE, addr != end);
74720 - return 0;
74721 + ret = 0;
74722 +out:
74723 + pax_close_kernel();
74724 + return ret;
74725 }
74726
74727 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74728 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74729 pmd_t *pmd;
74730 unsigned long next;
74731
74732 - pmd = pmd_alloc(&init_mm, pud, addr);
74733 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74734 if (!pmd)
74735 return -ENOMEM;
74736 do {
74737 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74738 pud_t *pud;
74739 unsigned long next;
74740
74741 - pud = pud_alloc(&init_mm, pgd, addr);
74742 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74743 if (!pud)
74744 return -ENOMEM;
74745 do {
74746 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74747 * and fall back on vmalloc() if that fails. Others
74748 * just put it in the vmalloc space.
74749 */
74750 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74751 +#ifdef CONFIG_MODULES
74752 +#ifdef MODULES_VADDR
74753 unsigned long addr = (unsigned long)x;
74754 if (addr >= MODULES_VADDR && addr < MODULES_END)
74755 return 1;
74756 #endif
74757 +
74758 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74759 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74760 + return 1;
74761 +#endif
74762 +
74763 +#endif
74764 +
74765 return is_vmalloc_addr(x);
74766 }
74767
74768 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74769
74770 if (!pgd_none(*pgd)) {
74771 pud_t *pud = pud_offset(pgd, addr);
74772 +#ifdef CONFIG_X86
74773 + if (!pud_large(*pud))
74774 +#endif
74775 if (!pud_none(*pud)) {
74776 pmd_t *pmd = pmd_offset(pud, addr);
74777 +#ifdef CONFIG_X86
74778 + if (!pmd_large(*pmd))
74779 +#endif
74780 if (!pmd_none(*pmd)) {
74781 pte_t *ptep, pte;
74782
74783 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74784 static struct vmap_area *alloc_vmap_area(unsigned long size,
74785 unsigned long align,
74786 unsigned long vstart, unsigned long vend,
74787 + int node, gfp_t gfp_mask) __size_overflow(1);
74788 +static struct vmap_area *alloc_vmap_area(unsigned long size,
74789 + unsigned long align,
74790 + unsigned long vstart, unsigned long vend,
74791 int node, gfp_t gfp_mask)
74792 {
74793 struct vmap_area *va;
74794 @@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74795 struct vm_struct *area;
74796
74797 BUG_ON(in_interrupt());
74798 +
74799 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74800 + if (flags & VM_KERNEXEC) {
74801 + if (start != VMALLOC_START || end != VMALLOC_END)
74802 + return NULL;
74803 + start = (unsigned long)MODULES_EXEC_VADDR;
74804 + end = (unsigned long)MODULES_EXEC_END;
74805 + }
74806 +#endif
74807 +
74808 if (flags & VM_IOREMAP) {
74809 int bit = fls(size);
74810
74811 @@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
74812 if (count > totalram_pages)
74813 return NULL;
74814
74815 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74816 + if (!(pgprot_val(prot) & _PAGE_NX))
74817 + flags |= VM_KERNEXEC;
74818 +#endif
74819 +
74820 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74821 __builtin_return_address(0));
74822 if (!area)
74823 @@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74824 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74825 goto fail;
74826
74827 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74828 + if (!(pgprot_val(prot) & _PAGE_NX))
74829 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74830 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74831 + else
74832 +#endif
74833 +
74834 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74835 start, end, node, gfp_mask, caller);
74836 if (!area)
74837 @@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
74838 * For tight control over page level allocator and protection flags
74839 * use __vmalloc() instead.
74840 */
74841 -
74842 void *vmalloc_exec(unsigned long size)
74843 {
74844 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74845 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74846 -1, __builtin_return_address(0));
74847 }
74848
74849 @@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74850 unsigned long uaddr = vma->vm_start;
74851 unsigned long usize = vma->vm_end - vma->vm_start;
74852
74853 + BUG_ON(vma->vm_mirror);
74854 +
74855 if ((PAGE_SIZE-1) & (unsigned long)addr)
74856 return -EINVAL;
74857
74858 diff --git a/mm/vmstat.c b/mm/vmstat.c
74859 index 1bbbbd9..ff35669 100644
74860 --- a/mm/vmstat.c
74861 +++ b/mm/vmstat.c
74862 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74863 *
74864 * vm_stat contains the global counters
74865 */
74866 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74867 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74868 EXPORT_SYMBOL(vm_stat);
74869
74870 #ifdef CONFIG_SMP
74871 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74872 v = p->vm_stat_diff[i];
74873 p->vm_stat_diff[i] = 0;
74874 local_irq_restore(flags);
74875 - atomic_long_add(v, &zone->vm_stat[i]);
74876 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74877 global_diff[i] += v;
74878 #ifdef CONFIG_NUMA
74879 /* 3 seconds idle till flush */
74880 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74881
74882 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74883 if (global_diff[i])
74884 - atomic_long_add(global_diff[i], &vm_stat[i]);
74885 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74886 }
74887
74888 #endif
74889 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
74890 start_cpu_timer(cpu);
74891 #endif
74892 #ifdef CONFIG_PROC_FS
74893 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74894 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74895 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74896 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74897 + {
74898 + mode_t gr_mode = S_IRUGO;
74899 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74900 + gr_mode = S_IRUSR;
74901 +#endif
74902 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74903 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74904 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74905 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74906 +#else
74907 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74908 +#endif
74909 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74910 + }
74911 #endif
74912 return 0;
74913 }
74914 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74915 index 9096bcb..43ed7bb 100644
74916 --- a/net/8021q/vlan.c
74917 +++ b/net/8021q/vlan.c
74918 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74919 err = -EPERM;
74920 if (!capable(CAP_NET_ADMIN))
74921 break;
74922 - if ((args.u.name_type >= 0) &&
74923 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74924 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74925 struct vlan_net *vn;
74926
74927 vn = net_generic(net, vlan_net_id);
74928 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74929 index 6449bae..8c1f454 100644
74930 --- a/net/9p/trans_fd.c
74931 +++ b/net/9p/trans_fd.c
74932 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74933 oldfs = get_fs();
74934 set_fs(get_ds());
74935 /* The cast to a user pointer is valid due to the set_fs() */
74936 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74937 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74938 set_fs(oldfs);
74939
74940 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74941 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74942 index 876fbe8..8bbea9f 100644
74943 --- a/net/atm/atm_misc.c
74944 +++ b/net/atm/atm_misc.c
74945 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74946 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74947 return 1;
74948 atm_return(vcc, truesize);
74949 - atomic_inc(&vcc->stats->rx_drop);
74950 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74951 return 0;
74952 }
74953 EXPORT_SYMBOL(atm_charge);
74954 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74955 }
74956 }
74957 atm_return(vcc, guess);
74958 - atomic_inc(&vcc->stats->rx_drop);
74959 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74960 return NULL;
74961 }
74962 EXPORT_SYMBOL(atm_alloc_charge);
74963 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74964
74965 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74966 {
74967 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74968 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74969 __SONET_ITEMS
74970 #undef __HANDLE_ITEM
74971 }
74972 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74973
74974 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74975 {
74976 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74977 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74978 __SONET_ITEMS
74979 #undef __HANDLE_ITEM
74980 }
74981 diff --git a/net/atm/lec.h b/net/atm/lec.h
74982 index a86aff9..3a0d6f6 100644
74983 --- a/net/atm/lec.h
74984 +++ b/net/atm/lec.h
74985 @@ -48,7 +48,7 @@ struct lane2_ops {
74986 const u8 *tlvs, u32 sizeoftlvs);
74987 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74988 const u8 *tlvs, u32 sizeoftlvs);
74989 -};
74990 +} __no_const;
74991
74992 /*
74993 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74994 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74995 index 0919a88..a23d54e 100644
74996 --- a/net/atm/mpc.h
74997 +++ b/net/atm/mpc.h
74998 @@ -33,7 +33,7 @@ struct mpoa_client {
74999 struct mpc_parameters parameters; /* parameters for this client */
75000
75001 const struct net_device_ops *old_ops;
75002 - struct net_device_ops new_ops;
75003 + net_device_ops_no_const new_ops;
75004 };
75005
75006
75007 diff --git a/net/atm/proc.c b/net/atm/proc.c
75008 index 0d020de..011c7bb 100644
75009 --- a/net/atm/proc.c
75010 +++ b/net/atm/proc.c
75011 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75012 const struct k_atm_aal_stats *stats)
75013 {
75014 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75015 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75016 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75017 - atomic_read(&stats->rx_drop));
75018 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75019 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75020 + atomic_read_unchecked(&stats->rx_drop));
75021 }
75022
75023 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75024 diff --git a/net/atm/resources.c b/net/atm/resources.c
75025 index 23f45ce..c748f1a 100644
75026 --- a/net/atm/resources.c
75027 +++ b/net/atm/resources.c
75028 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75029 static void copy_aal_stats(struct k_atm_aal_stats *from,
75030 struct atm_aal_stats *to)
75031 {
75032 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75033 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75034 __AAL_STAT_ITEMS
75035 #undef __HANDLE_ITEM
75036 }
75037 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75038 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75039 struct atm_aal_stats *to)
75040 {
75041 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75042 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75043 __AAL_STAT_ITEMS
75044 #undef __HANDLE_ITEM
75045 }
75046 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75047 index dc53798..dc66333 100644
75048 --- a/net/batman-adv/bat_iv_ogm.c
75049 +++ b/net/batman-adv/bat_iv_ogm.c
75050 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75051
75052 /* randomize initial seqno to avoid collision */
75053 get_random_bytes(&random_seqno, sizeof(random_seqno));
75054 - atomic_set(&hard_iface->seqno, random_seqno);
75055 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75056
75057 hard_iface->packet_len = BATMAN_OGM_HLEN;
75058 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75059 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75060
75061 /* change sequence number to network order */
75062 batman_ogm_packet->seqno =
75063 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75064 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75065
75066 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75067 batman_ogm_packet->tt_crc = htons((uint16_t)
75068 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75069 else
75070 batman_ogm_packet->gw_flags = NO_FLAGS;
75071
75072 - atomic_inc(&hard_iface->seqno);
75073 + atomic_inc_unchecked(&hard_iface->seqno);
75074
75075 slide_own_bcast_window(hard_iface);
75076 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75077 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75078 return;
75079
75080 /* could be changed by schedule_own_packet() */
75081 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75082 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75083
75084 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75085
75086 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75087 index dc334fa..766a01a 100644
75088 --- a/net/batman-adv/hard-interface.c
75089 +++ b/net/batman-adv/hard-interface.c
75090 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75091 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75092 dev_add_pack(&hard_iface->batman_adv_ptype);
75093
75094 - atomic_set(&hard_iface->frag_seqno, 1);
75095 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75096 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75097 hard_iface->net_dev->name);
75098
75099 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75100 * This can't be called via a bat_priv callback because
75101 * we have no bat_priv yet.
75102 */
75103 - atomic_set(&hard_iface->seqno, 1);
75104 + atomic_set_unchecked(&hard_iface->seqno, 1);
75105 hard_iface->packet_buff = NULL;
75106
75107 return hard_iface;
75108 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75109 index a0ec0e4..7beb587 100644
75110 --- a/net/batman-adv/soft-interface.c
75111 +++ b/net/batman-adv/soft-interface.c
75112 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75113
75114 /* set broadcast sequence number */
75115 bcast_packet->seqno =
75116 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75117 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75118
75119 add_bcast_packet_to_list(bat_priv, skb, 1);
75120
75121 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75122 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75123
75124 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75125 - atomic_set(&bat_priv->bcast_seqno, 1);
75126 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75127 atomic_set(&bat_priv->ttvn, 0);
75128 atomic_set(&bat_priv->tt_local_changes, 0);
75129 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75130 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75131 index 61308e8..2e142b2 100644
75132 --- a/net/batman-adv/types.h
75133 +++ b/net/batman-adv/types.h
75134 @@ -38,8 +38,8 @@ struct hard_iface {
75135 int16_t if_num;
75136 char if_status;
75137 struct net_device *net_dev;
75138 - atomic_t seqno;
75139 - atomic_t frag_seqno;
75140 + atomic_unchecked_t seqno;
75141 + atomic_unchecked_t frag_seqno;
75142 unsigned char *packet_buff;
75143 int packet_len;
75144 struct kobject *hardif_obj;
75145 @@ -163,7 +163,7 @@ struct bat_priv {
75146 atomic_t orig_interval; /* uint */
75147 atomic_t hop_penalty; /* uint */
75148 atomic_t log_level; /* uint */
75149 - atomic_t bcast_seqno;
75150 + atomic_unchecked_t bcast_seqno;
75151 atomic_t bcast_queue_left;
75152 atomic_t batman_queue_left;
75153 atomic_t ttvn; /* translation table version number */
75154 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75155 index 74175c2..32f8901 100644
75156 --- a/net/batman-adv/unicast.c
75157 +++ b/net/batman-adv/unicast.c
75158 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75159 frag1->flags = UNI_FRAG_HEAD | large_tail;
75160 frag2->flags = large_tail;
75161
75162 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75163 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75164 frag1->seqno = htons(seqno - 1);
75165 frag2->seqno = htons(seqno);
75166
75167 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75168 index 4554e80..b778671 100644
75169 --- a/net/bluetooth/l2cap_core.c
75170 +++ b/net/bluetooth/l2cap_core.c
75171 @@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75172 break;
75173
75174 case L2CAP_CONF_RFC:
75175 - if (olen == sizeof(rfc))
75176 - memcpy(&rfc, (void *)val, olen);
75177 + if (olen != sizeof(rfc))
75178 + break;
75179 +
75180 + memcpy(&rfc, (void *)val, olen);
75181
75182 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75183 rfc.mode != chan->mode)
75184 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75185 index d1820ff..d414b0e 100644
75186 --- a/net/bluetooth/rfcomm/tty.c
75187 +++ b/net/bluetooth/rfcomm/tty.c
75188 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75189 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75190
75191 spin_lock_irqsave(&dev->port.lock, flags);
75192 - if (dev->port.count > 0) {
75193 + if (atomic_read(&dev->port.count) > 0) {
75194 spin_unlock_irqrestore(&dev->port.lock, flags);
75195 return;
75196 }
75197 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75198 return -ENODEV;
75199
75200 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75201 - dev->channel, dev->port.count);
75202 + dev->channel, atomic_read(&dev->port.count));
75203
75204 spin_lock_irqsave(&dev->port.lock, flags);
75205 - if (++dev->port.count > 1) {
75206 + if (atomic_inc_return(&dev->port.count) > 1) {
75207 spin_unlock_irqrestore(&dev->port.lock, flags);
75208 return 0;
75209 }
75210 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75211 return;
75212
75213 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75214 - dev->port.count);
75215 + atomic_read(&dev->port.count));
75216
75217 spin_lock_irqsave(&dev->port.lock, flags);
75218 - if (!--dev->port.count) {
75219 + if (!atomic_dec_return(&dev->port.count)) {
75220 spin_unlock_irqrestore(&dev->port.lock, flags);
75221 if (dev->tty_dev->parent)
75222 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75223 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75224 index 5fe2ff3..10968b5 100644
75225 --- a/net/bridge/netfilter/ebtables.c
75226 +++ b/net/bridge/netfilter/ebtables.c
75227 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75228 tmp.valid_hooks = t->table->valid_hooks;
75229 }
75230 mutex_unlock(&ebt_mutex);
75231 - if (copy_to_user(user, &tmp, *len) != 0){
75232 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75233 BUGPRINT("c2u Didn't work\n");
75234 ret = -EFAULT;
75235 break;
75236 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75237 index 047cd0e..461fd28 100644
75238 --- a/net/caif/cfctrl.c
75239 +++ b/net/caif/cfctrl.c
75240 @@ -10,6 +10,7 @@
75241 #include <linux/spinlock.h>
75242 #include <linux/slab.h>
75243 #include <linux/pkt_sched.h>
75244 +#include <linux/sched.h>
75245 #include <net/caif/caif_layer.h>
75246 #include <net/caif/cfpkt.h>
75247 #include <net/caif/cfctrl.h>
75248 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75249 memset(&dev_info, 0, sizeof(dev_info));
75250 dev_info.id = 0xff;
75251 cfsrvl_init(&this->serv, 0, &dev_info, false);
75252 - atomic_set(&this->req_seq_no, 1);
75253 - atomic_set(&this->rsp_seq_no, 1);
75254 + atomic_set_unchecked(&this->req_seq_no, 1);
75255 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75256 this->serv.layer.receive = cfctrl_recv;
75257 sprintf(this->serv.layer.name, "ctrl");
75258 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75259 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75260 struct cfctrl_request_info *req)
75261 {
75262 spin_lock_bh(&ctrl->info_list_lock);
75263 - atomic_inc(&ctrl->req_seq_no);
75264 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75265 + atomic_inc_unchecked(&ctrl->req_seq_no);
75266 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75267 list_add_tail(&req->list, &ctrl->list);
75268 spin_unlock_bh(&ctrl->info_list_lock);
75269 }
75270 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75271 if (p != first)
75272 pr_warn("Requests are not received in order\n");
75273
75274 - atomic_set(&ctrl->rsp_seq_no,
75275 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75276 p->sequence_no);
75277 list_del(&p->list);
75278 goto out;
75279 diff --git a/net/can/gw.c b/net/can/gw.c
75280 index b41acf2..3affb3a 100644
75281 --- a/net/can/gw.c
75282 +++ b/net/can/gw.c
75283 @@ -96,7 +96,7 @@ struct cf_mod {
75284 struct {
75285 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75286 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75287 - } csumfunc;
75288 + } __no_const csumfunc;
75289 };
75290
75291
75292 diff --git a/net/compat.c b/net/compat.c
75293 index 1b96281..a7e6c91 100644
75294 --- a/net/compat.c
75295 +++ b/net/compat.c
75296 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75297 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75298 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75299 return -EFAULT;
75300 - kmsg->msg_name = compat_ptr(tmp1);
75301 - kmsg->msg_iov = compat_ptr(tmp2);
75302 - kmsg->msg_control = compat_ptr(tmp3);
75303 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75304 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75305 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75306 return 0;
75307 }
75308
75309 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75310
75311 if (kern_msg->msg_namelen) {
75312 if (mode == VERIFY_READ) {
75313 - int err = move_addr_to_kernel(kern_msg->msg_name,
75314 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75315 kern_msg->msg_namelen,
75316 kern_address);
75317 if (err < 0)
75318 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75319 kern_msg->msg_name = NULL;
75320
75321 tot_len = iov_from_user_compat_to_kern(kern_iov,
75322 - (struct compat_iovec __user *)kern_msg->msg_iov,
75323 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75324 kern_msg->msg_iovlen);
75325 if (tot_len >= 0)
75326 kern_msg->msg_iov = kern_iov;
75327 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75328
75329 #define CMSG_COMPAT_FIRSTHDR(msg) \
75330 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75331 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75332 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75333 (struct compat_cmsghdr __user *)NULL)
75334
75335 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75336 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75337 (ucmlen) <= (unsigned long) \
75338 ((mhdr)->msg_controllen - \
75339 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75340 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75341
75342 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75343 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75344 {
75345 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75346 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75347 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75348 msg->msg_controllen)
75349 return NULL;
75350 return (struct compat_cmsghdr __user *)ptr;
75351 @@ -219,7 +219,7 @@ Efault:
75352
75353 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75354 {
75355 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75356 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75357 struct compat_cmsghdr cmhdr;
75358 int cmlen;
75359
75360 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75361
75362 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75363 {
75364 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75365 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75366 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75367 int fdnum = scm->fp->count;
75368 struct file **fp = scm->fp->fp;
75369 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75370 return -EFAULT;
75371 old_fs = get_fs();
75372 set_fs(KERNEL_DS);
75373 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75374 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75375 set_fs(old_fs);
75376
75377 return err;
75378 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75379 len = sizeof(ktime);
75380 old_fs = get_fs();
75381 set_fs(KERNEL_DS);
75382 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75383 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75384 set_fs(old_fs);
75385
75386 if (!err) {
75387 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75388 case MCAST_JOIN_GROUP:
75389 case MCAST_LEAVE_GROUP:
75390 {
75391 - struct compat_group_req __user *gr32 = (void *)optval;
75392 + struct compat_group_req __user *gr32 = (void __user *)optval;
75393 struct group_req __user *kgr =
75394 compat_alloc_user_space(sizeof(struct group_req));
75395 u32 interface;
75396 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75397 case MCAST_BLOCK_SOURCE:
75398 case MCAST_UNBLOCK_SOURCE:
75399 {
75400 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75401 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75402 struct group_source_req __user *kgsr = compat_alloc_user_space(
75403 sizeof(struct group_source_req));
75404 u32 interface;
75405 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75406 }
75407 case MCAST_MSFILTER:
75408 {
75409 - struct compat_group_filter __user *gf32 = (void *)optval;
75410 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75411 struct group_filter __user *kgf;
75412 u32 interface, fmode, numsrc;
75413
75414 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75415 char __user *optval, int __user *optlen,
75416 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75417 {
75418 - struct compat_group_filter __user *gf32 = (void *)optval;
75419 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75420 struct group_filter __user *kgf;
75421 int __user *koptlen;
75422 u32 interface, fmode, numsrc;
75423 diff --git a/net/core/datagram.c b/net/core/datagram.c
75424 index ae6acf6..d5c8f66 100644
75425 --- a/net/core/datagram.c
75426 +++ b/net/core/datagram.c
75427 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75428 }
75429
75430 kfree_skb(skb);
75431 - atomic_inc(&sk->sk_drops);
75432 + atomic_inc_unchecked(&sk->sk_drops);
75433 sk_mem_reclaim_partial(sk);
75434
75435 return err;
75436 diff --git a/net/core/dev.c b/net/core/dev.c
75437 index 1cb0d8a..0427dd9 100644
75438 --- a/net/core/dev.c
75439 +++ b/net/core/dev.c
75440 @@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75441 if (no_module && capable(CAP_NET_ADMIN))
75442 no_module = request_module("netdev-%s", name);
75443 if (no_module && capable(CAP_SYS_MODULE)) {
75444 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75445 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75446 +#else
75447 if (!request_module("%s", name))
75448 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75449 name);
75450 +#endif
75451 }
75452 }
75453 EXPORT_SYMBOL(dev_load);
75454 @@ -1601,7 +1605,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75455 {
75456 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75457 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75458 - atomic_long_inc(&dev->rx_dropped);
75459 + atomic_long_inc_unchecked(&dev->rx_dropped);
75460 kfree_skb(skb);
75461 return NET_RX_DROP;
75462 }
75463 @@ -1611,7 +1615,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75464 nf_reset(skb);
75465
75466 if (unlikely(!is_skb_forwardable(dev, skb))) {
75467 - atomic_long_inc(&dev->rx_dropped);
75468 + atomic_long_inc_unchecked(&dev->rx_dropped);
75469 kfree_skb(skb);
75470 return NET_RX_DROP;
75471 }
75472 @@ -2040,7 +2044,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75473
75474 struct dev_gso_cb {
75475 void (*destructor)(struct sk_buff *skb);
75476 -};
75477 +} __no_const;
75478
75479 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75480
75481 @@ -2875,7 +2879,7 @@ enqueue:
75482
75483 local_irq_restore(flags);
75484
75485 - atomic_long_inc(&skb->dev->rx_dropped);
75486 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75487 kfree_skb(skb);
75488 return NET_RX_DROP;
75489 }
75490 @@ -2947,7 +2951,7 @@ int netif_rx_ni(struct sk_buff *skb)
75491 }
75492 EXPORT_SYMBOL(netif_rx_ni);
75493
75494 -static void net_tx_action(struct softirq_action *h)
75495 +static void net_tx_action(void)
75496 {
75497 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75498
75499 @@ -3234,7 +3238,7 @@ ncls:
75500 if (pt_prev) {
75501 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75502 } else {
75503 - atomic_long_inc(&skb->dev->rx_dropped);
75504 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75505 kfree_skb(skb);
75506 /* Jamal, now you will not able to escape explaining
75507 * me how you were going to use this. :-)
75508 @@ -3799,7 +3803,7 @@ void netif_napi_del(struct napi_struct *napi)
75509 }
75510 EXPORT_SYMBOL(netif_napi_del);
75511
75512 -static void net_rx_action(struct softirq_action *h)
75513 +static void net_rx_action(void)
75514 {
75515 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75516 unsigned long time_limit = jiffies + 2;
75517 @@ -4269,8 +4273,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75518 else
75519 seq_printf(seq, "%04x", ntohs(pt->type));
75520
75521 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75522 + seq_printf(seq, " %-8s %p\n",
75523 + pt->dev ? pt->dev->name : "", NULL);
75524 +#else
75525 seq_printf(seq, " %-8s %pF\n",
75526 pt->dev ? pt->dev->name : "", pt->func);
75527 +#endif
75528 }
75529
75530 return 0;
75531 @@ -5820,7 +5829,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75532 } else {
75533 netdev_stats_to_stats64(storage, &dev->stats);
75534 }
75535 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75536 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75537 return storage;
75538 }
75539 EXPORT_SYMBOL(dev_get_stats);
75540 diff --git a/net/core/flow.c b/net/core/flow.c
75541 index e318c7e..168b1d0 100644
75542 --- a/net/core/flow.c
75543 +++ b/net/core/flow.c
75544 @@ -61,7 +61,7 @@ struct flow_cache {
75545 struct timer_list rnd_timer;
75546 };
75547
75548 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75549 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75550 EXPORT_SYMBOL(flow_cache_genid);
75551 static struct flow_cache flow_cache_global;
75552 static struct kmem_cache *flow_cachep __read_mostly;
75553 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75554
75555 static int flow_entry_valid(struct flow_cache_entry *fle)
75556 {
75557 - if (atomic_read(&flow_cache_genid) != fle->genid)
75558 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75559 return 0;
75560 if (fle->object && !fle->object->ops->check(fle->object))
75561 return 0;
75562 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75563 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75564 fcp->hash_count++;
75565 }
75566 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75567 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75568 flo = fle->object;
75569 if (!flo)
75570 goto ret_object;
75571 @@ -280,7 +280,7 @@ nocache:
75572 }
75573 flo = resolver(net, key, family, dir, flo, ctx);
75574 if (fle) {
75575 - fle->genid = atomic_read(&flow_cache_genid);
75576 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75577 if (!IS_ERR(flo))
75578 fle->object = flo;
75579 else
75580 diff --git a/net/core/iovec.c b/net/core/iovec.c
75581 index 7e7aeb0..2a998cb 100644
75582 --- a/net/core/iovec.c
75583 +++ b/net/core/iovec.c
75584 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75585 if (m->msg_namelen) {
75586 if (mode == VERIFY_READ) {
75587 void __user *namep;
75588 - namep = (void __user __force *) m->msg_name;
75589 + namep = (void __force_user *) m->msg_name;
75590 err = move_addr_to_kernel(namep, m->msg_namelen,
75591 address);
75592 if (err < 0)
75593 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75594 }
75595
75596 size = m->msg_iovlen * sizeof(struct iovec);
75597 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75598 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75599 return -EFAULT;
75600
75601 m->msg_iov = iov;
75602 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75603 index 21318d1..7f105e4 100644
75604 --- a/net/core/rtnetlink.c
75605 +++ b/net/core/rtnetlink.c
75606 @@ -58,7 +58,7 @@ struct rtnl_link {
75607 rtnl_doit_func doit;
75608 rtnl_dumpit_func dumpit;
75609 rtnl_calcit_func calcit;
75610 -};
75611 +} __no_const;
75612
75613 static DEFINE_MUTEX(rtnl_mutex);
75614
75615 diff --git a/net/core/scm.c b/net/core/scm.c
75616 index 611c5ef..88f6d6d 100644
75617 --- a/net/core/scm.c
75618 +++ b/net/core/scm.c
75619 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75620 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75621 {
75622 struct cmsghdr __user *cm
75623 - = (__force struct cmsghdr __user *)msg->msg_control;
75624 + = (struct cmsghdr __force_user *)msg->msg_control;
75625 struct cmsghdr cmhdr;
75626 int cmlen = CMSG_LEN(len);
75627 int err;
75628 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75629 err = -EFAULT;
75630 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75631 goto out;
75632 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75633 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75634 goto out;
75635 cmlen = CMSG_SPACE(len);
75636 if (msg->msg_controllen < cmlen)
75637 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75638 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75639 {
75640 struct cmsghdr __user *cm
75641 - = (__force struct cmsghdr __user*)msg->msg_control;
75642 + = (struct cmsghdr __force_user *)msg->msg_control;
75643
75644 int fdmax = 0;
75645 int fdnum = scm->fp->count;
75646 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75647 if (fdnum < fdmax)
75648 fdmax = fdnum;
75649
75650 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75651 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75652 i++, cmfptr++)
75653 {
75654 int new_fd;
75655 diff --git a/net/core/sock.c b/net/core/sock.c
75656 index 9e5b71f..66dec30 100644
75657 --- a/net/core/sock.c
75658 +++ b/net/core/sock.c
75659 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75660 struct sk_buff_head *list = &sk->sk_receive_queue;
75661
75662 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75663 - atomic_inc(&sk->sk_drops);
75664 + atomic_inc_unchecked(&sk->sk_drops);
75665 trace_sock_rcvqueue_full(sk, skb);
75666 return -ENOMEM;
75667 }
75668 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75669 return err;
75670
75671 if (!sk_rmem_schedule(sk, skb->truesize)) {
75672 - atomic_inc(&sk->sk_drops);
75673 + atomic_inc_unchecked(&sk->sk_drops);
75674 return -ENOBUFS;
75675 }
75676
75677 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75678 skb_dst_force(skb);
75679
75680 spin_lock_irqsave(&list->lock, flags);
75681 - skb->dropcount = atomic_read(&sk->sk_drops);
75682 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75683 __skb_queue_tail(list, skb);
75684 spin_unlock_irqrestore(&list->lock, flags);
75685
75686 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75687 skb->dev = NULL;
75688
75689 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75690 - atomic_inc(&sk->sk_drops);
75691 + atomic_inc_unchecked(&sk->sk_drops);
75692 goto discard_and_relse;
75693 }
75694 if (nested)
75695 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75696 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75697 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75698 bh_unlock_sock(sk);
75699 - atomic_inc(&sk->sk_drops);
75700 + atomic_inc_unchecked(&sk->sk_drops);
75701 goto discard_and_relse;
75702 }
75703
75704 @@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75705 if (len > sizeof(peercred))
75706 len = sizeof(peercred);
75707 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75708 - if (copy_to_user(optval, &peercred, len))
75709 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75710 return -EFAULT;
75711 goto lenout;
75712 }
75713 @@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75714 return -ENOTCONN;
75715 if (lv < len)
75716 return -EINVAL;
75717 - if (copy_to_user(optval, address, len))
75718 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75719 return -EFAULT;
75720 goto lenout;
75721 }
75722 @@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75723
75724 if (len > lv)
75725 len = lv;
75726 - if (copy_to_user(optval, &v, len))
75727 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75728 return -EFAULT;
75729 lenout:
75730 if (put_user(len, optlen))
75731 @@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75732 */
75733 smp_wmb();
75734 atomic_set(&sk->sk_refcnt, 1);
75735 - atomic_set(&sk->sk_drops, 0);
75736 + atomic_set_unchecked(&sk->sk_drops, 0);
75737 }
75738 EXPORT_SYMBOL(sock_init_data);
75739
75740 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75741 index 5fd1467..8b70900 100644
75742 --- a/net/core/sock_diag.c
75743 +++ b/net/core/sock_diag.c
75744 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75745
75746 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75747 {
75748 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75749 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75750 cookie[1] != INET_DIAG_NOCOOKIE) &&
75751 ((u32)(unsigned long)sk != cookie[0] ||
75752 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75753 return -ESTALE;
75754 else
75755 +#endif
75756 return 0;
75757 }
75758 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75759
75760 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75761 {
75762 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75763 + cookie[0] = 0;
75764 + cookie[1] = 0;
75765 +#else
75766 cookie[0] = (u32)(unsigned long)sk;
75767 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75768 +#endif
75769 }
75770 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75771
75772 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75773 index a55eecc..dd8428c 100644
75774 --- a/net/decnet/sysctl_net_decnet.c
75775 +++ b/net/decnet/sysctl_net_decnet.c
75776 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75777
75778 if (len > *lenp) len = *lenp;
75779
75780 - if (copy_to_user(buffer, addr, len))
75781 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75782 return -EFAULT;
75783
75784 *lenp = len;
75785 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75786
75787 if (len > *lenp) len = *lenp;
75788
75789 - if (copy_to_user(buffer, devname, len))
75790 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75791 return -EFAULT;
75792
75793 *lenp = len;
75794 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75795 index 3854411..2201a94 100644
75796 --- a/net/ipv4/fib_frontend.c
75797 +++ b/net/ipv4/fib_frontend.c
75798 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75799 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75800 fib_sync_up(dev);
75801 #endif
75802 - atomic_inc(&net->ipv4.dev_addr_genid);
75803 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75804 rt_cache_flush(dev_net(dev), -1);
75805 break;
75806 case NETDEV_DOWN:
75807 fib_del_ifaddr(ifa, NULL);
75808 - atomic_inc(&net->ipv4.dev_addr_genid);
75809 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75810 if (ifa->ifa_dev->ifa_list == NULL) {
75811 /* Last address was deleted from this interface.
75812 * Disable IP.
75813 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75814 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75815 fib_sync_up(dev);
75816 #endif
75817 - atomic_inc(&net->ipv4.dev_addr_genid);
75818 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75819 rt_cache_flush(dev_net(dev), -1);
75820 break;
75821 case NETDEV_DOWN:
75822 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75823 index e5b7182..570a90e 100644
75824 --- a/net/ipv4/fib_semantics.c
75825 +++ b/net/ipv4/fib_semantics.c
75826 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75827 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75828 nh->nh_gw,
75829 nh->nh_parent->fib_scope);
75830 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75831 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75832
75833 return nh->nh_saddr;
75834 }
75835 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75836 index 7880af9..70f92a3 100644
75837 --- a/net/ipv4/inet_hashtables.c
75838 +++ b/net/ipv4/inet_hashtables.c
75839 @@ -18,12 +18,15 @@
75840 #include <linux/sched.h>
75841 #include <linux/slab.h>
75842 #include <linux/wait.h>
75843 +#include <linux/security.h>
75844
75845 #include <net/inet_connection_sock.h>
75846 #include <net/inet_hashtables.h>
75847 #include <net/secure_seq.h>
75848 #include <net/ip.h>
75849
75850 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75851 +
75852 /*
75853 * Allocate and initialize a new local port bind bucket.
75854 * The bindhash mutex for snum's hash chain must be held here.
75855 @@ -530,6 +533,8 @@ ok:
75856 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75857 spin_unlock(&head->lock);
75858
75859 + gr_update_task_in_ip_table(current, inet_sk(sk));
75860 +
75861 if (tw) {
75862 inet_twsk_deschedule(tw, death_row);
75863 while (twrefcnt) {
75864 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75865 index dfba343..c827d50 100644
75866 --- a/net/ipv4/inetpeer.c
75867 +++ b/net/ipv4/inetpeer.c
75868 @@ -487,8 +487,8 @@ relookup:
75869 if (p) {
75870 p->daddr = *daddr;
75871 atomic_set(&p->refcnt, 1);
75872 - atomic_set(&p->rid, 0);
75873 - atomic_set(&p->ip_id_count,
75874 + atomic_set_unchecked(&p->rid, 0);
75875 + atomic_set_unchecked(&p->ip_id_count,
75876 (daddr->family == AF_INET) ?
75877 secure_ip_id(daddr->addr.a4) :
75878 secure_ipv6_id(daddr->addr.a6));
75879 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75880 index 9dbd3dd..0c59fb2 100644
75881 --- a/net/ipv4/ip_fragment.c
75882 +++ b/net/ipv4/ip_fragment.c
75883 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75884 return 0;
75885
75886 start = qp->rid;
75887 - end = atomic_inc_return(&peer->rid);
75888 + end = atomic_inc_return_unchecked(&peer->rid);
75889 qp->rid = end;
75890
75891 rc = qp->q.fragments && (end - start) > max;
75892 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75893 index 0d11f23..2bb3f64 100644
75894 --- a/net/ipv4/ip_sockglue.c
75895 +++ b/net/ipv4/ip_sockglue.c
75896 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75897 len = min_t(unsigned int, len, opt->optlen);
75898 if (put_user(len, optlen))
75899 return -EFAULT;
75900 - if (copy_to_user(optval, opt->__data, len))
75901 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75902 + copy_to_user(optval, opt->__data, len))
75903 return -EFAULT;
75904 return 0;
75905 }
75906 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75907 if (sk->sk_type != SOCK_STREAM)
75908 return -ENOPROTOOPT;
75909
75910 - msg.msg_control = optval;
75911 + msg.msg_control = (void __force_kernel *)optval;
75912 msg.msg_controllen = len;
75913 msg.msg_flags = flags;
75914
75915 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75916 index 67e8a6b..386764d 100644
75917 --- a/net/ipv4/ipconfig.c
75918 +++ b/net/ipv4/ipconfig.c
75919 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75920
75921 mm_segment_t oldfs = get_fs();
75922 set_fs(get_ds());
75923 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75924 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75925 set_fs(oldfs);
75926 return res;
75927 }
75928 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75929
75930 mm_segment_t oldfs = get_fs();
75931 set_fs(get_ds());
75932 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75933 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75934 set_fs(oldfs);
75935 return res;
75936 }
75937 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75938
75939 mm_segment_t oldfs = get_fs();
75940 set_fs(get_ds());
75941 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75942 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75943 set_fs(oldfs);
75944 return res;
75945 }
75946 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75947 index 2c00e8b..45b3bdd 100644
75948 --- a/net/ipv4/ping.c
75949 +++ b/net/ipv4/ping.c
75950 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75951 sk_rmem_alloc_get(sp),
75952 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75953 atomic_read(&sp->sk_refcnt), sp,
75954 - atomic_read(&sp->sk_drops), len);
75955 + atomic_read_unchecked(&sp->sk_drops), len);
75956 }
75957
75958 static int ping_seq_show(struct seq_file *seq, void *v)
75959 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75960 index 4032b81..625143c 100644
75961 --- a/net/ipv4/raw.c
75962 +++ b/net/ipv4/raw.c
75963 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
75964 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75965 {
75966 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75967 - atomic_inc(&sk->sk_drops);
75968 + atomic_inc_unchecked(&sk->sk_drops);
75969 kfree_skb(skb);
75970 return NET_RX_DROP;
75971 }
75972 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
75973
75974 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75975 {
75976 + struct icmp_filter filter;
75977 +
75978 if (optlen > sizeof(struct icmp_filter))
75979 optlen = sizeof(struct icmp_filter);
75980 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75981 + if (copy_from_user(&filter, optval, optlen))
75982 return -EFAULT;
75983 + raw_sk(sk)->filter = filter;
75984 return 0;
75985 }
75986
75987 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75988 {
75989 int len, ret = -EFAULT;
75990 + struct icmp_filter filter;
75991
75992 if (get_user(len, optlen))
75993 goto out;
75994 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75995 if (len > sizeof(struct icmp_filter))
75996 len = sizeof(struct icmp_filter);
75997 ret = -EFAULT;
75998 - if (put_user(len, optlen) ||
75999 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76000 + filter = raw_sk(sk)->filter;
76001 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76002 goto out;
76003 ret = 0;
76004 out: return ret;
76005 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76006 sk_wmem_alloc_get(sp),
76007 sk_rmem_alloc_get(sp),
76008 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76009 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76010 + atomic_read(&sp->sk_refcnt),
76011 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76012 + NULL,
76013 +#else
76014 + sp,
76015 +#endif
76016 + atomic_read_unchecked(&sp->sk_drops));
76017 }
76018
76019 static int raw_seq_show(struct seq_file *seq, void *v)
76020 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76021 index 98b30d0..cfa3cf7 100644
76022 --- a/net/ipv4/route.c
76023 +++ b/net/ipv4/route.c
76024 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76025
76026 static inline int rt_genid(struct net *net)
76027 {
76028 - return atomic_read(&net->ipv4.rt_genid);
76029 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76030 }
76031
76032 #ifdef CONFIG_PROC_FS
76033 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76034 unsigned char shuffle;
76035
76036 get_random_bytes(&shuffle, sizeof(shuffle));
76037 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76038 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76039 inetpeer_invalidate_tree(AF_INET);
76040 }
76041
76042 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76043 error = rt->dst.error;
76044 if (peer) {
76045 inet_peer_refcheck(rt->peer);
76046 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76047 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76048 if (peer->tcp_ts_stamp) {
76049 ts = peer->tcp_ts;
76050 tsage = get_seconds() - peer->tcp_ts_stamp;
76051 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76052 index c8d28c4..e40f75a 100644
76053 --- a/net/ipv4/tcp_ipv4.c
76054 +++ b/net/ipv4/tcp_ipv4.c
76055 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76056 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76057
76058
76059 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76060 +extern int grsec_enable_blackhole;
76061 +#endif
76062 +
76063 #ifdef CONFIG_TCP_MD5SIG
76064 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76065 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76066 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76067 return 0;
76068
76069 reset:
76070 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76071 + if (!grsec_enable_blackhole)
76072 +#endif
76073 tcp_v4_send_reset(rsk, skb);
76074 discard:
76075 kfree_skb(skb);
76076 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76077 TCP_SKB_CB(skb)->sacked = 0;
76078
76079 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76080 - if (!sk)
76081 + if (!sk) {
76082 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76083 + ret = 1;
76084 +#endif
76085 goto no_tcp_socket;
76086 -
76087 + }
76088 process:
76089 - if (sk->sk_state == TCP_TIME_WAIT)
76090 + if (sk->sk_state == TCP_TIME_WAIT) {
76091 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76092 + ret = 2;
76093 +#endif
76094 goto do_time_wait;
76095 + }
76096
76097 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76098 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76099 @@ -1774,6 +1788,10 @@ no_tcp_socket:
76100 bad_packet:
76101 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76102 } else {
76103 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76104 + if (!grsec_enable_blackhole || (ret == 1 &&
76105 + (skb->dev->flags & IFF_LOOPBACK)))
76106 +#endif
76107 tcp_v4_send_reset(NULL, skb);
76108 }
76109
76110 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76111 0, /* non standard timer */
76112 0, /* open_requests have no inode */
76113 atomic_read(&sk->sk_refcnt),
76114 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76115 + NULL,
76116 +#else
76117 req,
76118 +#endif
76119 len);
76120 }
76121
76122 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76123 sock_i_uid(sk),
76124 icsk->icsk_probes_out,
76125 sock_i_ino(sk),
76126 - atomic_read(&sk->sk_refcnt), sk,
76127 + atomic_read(&sk->sk_refcnt),
76128 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76129 + NULL,
76130 +#else
76131 + sk,
76132 +#endif
76133 jiffies_to_clock_t(icsk->icsk_rto),
76134 jiffies_to_clock_t(icsk->icsk_ack.ato),
76135 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76136 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76137 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76138 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76139 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76140 - atomic_read(&tw->tw_refcnt), tw, len);
76141 + atomic_read(&tw->tw_refcnt),
76142 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76143 + NULL,
76144 +#else
76145 + tw,
76146 +#endif
76147 + len);
76148 }
76149
76150 #define TMPSZ 150
76151 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76152 index b85d9fe..4b0eed9 100644
76153 --- a/net/ipv4/tcp_minisocks.c
76154 +++ b/net/ipv4/tcp_minisocks.c
76155 @@ -27,6 +27,10 @@
76156 #include <net/inet_common.h>
76157 #include <net/xfrm.h>
76158
76159 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76160 +extern int grsec_enable_blackhole;
76161 +#endif
76162 +
76163 int sysctl_tcp_syncookies __read_mostly = 1;
76164 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76165
76166 @@ -754,6 +758,10 @@ listen_overflow:
76167
76168 embryonic_reset:
76169 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76170 +
76171 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76172 + if (!grsec_enable_blackhole)
76173 +#endif
76174 if (!(flg & TCP_FLAG_RST))
76175 req->rsk_ops->send_reset(sk, skb);
76176
76177 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76178 index 4526fe6..1a34e43 100644
76179 --- a/net/ipv4/tcp_probe.c
76180 +++ b/net/ipv4/tcp_probe.c
76181 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76182 if (cnt + width >= len)
76183 break;
76184
76185 - if (copy_to_user(buf + cnt, tbuf, width))
76186 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76187 return -EFAULT;
76188 cnt += width;
76189 }
76190 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76191 index e911e6c..d0a9356 100644
76192 --- a/net/ipv4/tcp_timer.c
76193 +++ b/net/ipv4/tcp_timer.c
76194 @@ -22,6 +22,10 @@
76195 #include <linux/gfp.h>
76196 #include <net/tcp.h>
76197
76198 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76199 +extern int grsec_lastack_retries;
76200 +#endif
76201 +
76202 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76203 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76204 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76205 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76206 }
76207 }
76208
76209 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76210 + if ((sk->sk_state == TCP_LAST_ACK) &&
76211 + (grsec_lastack_retries > 0) &&
76212 + (grsec_lastack_retries < retry_until))
76213 + retry_until = grsec_lastack_retries;
76214 +#endif
76215 +
76216 if (retransmits_timed_out(sk, retry_until,
76217 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76218 /* Has it gone just too far? */
76219 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76220 index eaca736..60488ae 100644
76221 --- a/net/ipv4/udp.c
76222 +++ b/net/ipv4/udp.c
76223 @@ -87,6 +87,7 @@
76224 #include <linux/types.h>
76225 #include <linux/fcntl.h>
76226 #include <linux/module.h>
76227 +#include <linux/security.h>
76228 #include <linux/socket.h>
76229 #include <linux/sockios.h>
76230 #include <linux/igmp.h>
76231 @@ -110,6 +111,10 @@
76232 #include <linux/static_key.h>
76233 #include "udp_impl.h"
76234
76235 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76236 +extern int grsec_enable_blackhole;
76237 +#endif
76238 +
76239 struct udp_table udp_table __read_mostly;
76240 EXPORT_SYMBOL(udp_table);
76241
76242 @@ -568,6 +573,9 @@ found:
76243 return s;
76244 }
76245
76246 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76247 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76248 +
76249 /*
76250 * This routine is called by the ICMP module when it gets some
76251 * sort of error condition. If err < 0 then the socket should
76252 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76253 dport = usin->sin_port;
76254 if (dport == 0)
76255 return -EINVAL;
76256 +
76257 + err = gr_search_udp_sendmsg(sk, usin);
76258 + if (err)
76259 + return err;
76260 } else {
76261 if (sk->sk_state != TCP_ESTABLISHED)
76262 return -EDESTADDRREQ;
76263 +
76264 + err = gr_search_udp_sendmsg(sk, NULL);
76265 + if (err)
76266 + return err;
76267 +
76268 daddr = inet->inet_daddr;
76269 dport = inet->inet_dport;
76270 /* Open fast path for connected socket.
76271 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76272 udp_lib_checksum_complete(skb)) {
76273 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76274 IS_UDPLITE(sk));
76275 - atomic_inc(&sk->sk_drops);
76276 + atomic_inc_unchecked(&sk->sk_drops);
76277 __skb_unlink(skb, rcvq);
76278 __skb_queue_tail(&list_kill, skb);
76279 }
76280 @@ -1189,6 +1206,10 @@ try_again:
76281 if (!skb)
76282 goto out;
76283
76284 + err = gr_search_udp_recvmsg(sk, skb);
76285 + if (err)
76286 + goto out_free;
76287 +
76288 ulen = skb->len - sizeof(struct udphdr);
76289 copied = len;
76290 if (copied > ulen)
76291 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76292
76293 drop:
76294 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76295 - atomic_inc(&sk->sk_drops);
76296 + atomic_inc_unchecked(&sk->sk_drops);
76297 kfree_skb(skb);
76298 return -1;
76299 }
76300 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76301 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76302
76303 if (!skb1) {
76304 - atomic_inc(&sk->sk_drops);
76305 + atomic_inc_unchecked(&sk->sk_drops);
76306 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76307 IS_UDPLITE(sk));
76308 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76309 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76310 goto csum_error;
76311
76312 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76313 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76314 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76315 +#endif
76316 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76317
76318 /*
76319 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76320 sk_wmem_alloc_get(sp),
76321 sk_rmem_alloc_get(sp),
76322 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76323 - atomic_read(&sp->sk_refcnt), sp,
76324 - atomic_read(&sp->sk_drops), len);
76325 + atomic_read(&sp->sk_refcnt),
76326 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76327 + NULL,
76328 +#else
76329 + sp,
76330 +#endif
76331 + atomic_read_unchecked(&sp->sk_drops), len);
76332 }
76333
76334 int udp4_seq_show(struct seq_file *seq, void *v)
76335 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76336 index 8f6411c..5767579 100644
76337 --- a/net/ipv6/addrconf.c
76338 +++ b/net/ipv6/addrconf.c
76339 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76340 p.iph.ihl = 5;
76341 p.iph.protocol = IPPROTO_IPV6;
76342 p.iph.ttl = 64;
76343 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76344 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76345
76346 if (ops->ndo_do_ioctl) {
76347 mm_segment_t oldfs = get_fs();
76348 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76349 index e6cee52..cf47476 100644
76350 --- a/net/ipv6/inet6_connection_sock.c
76351 +++ b/net/ipv6/inet6_connection_sock.c
76352 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76353 #ifdef CONFIG_XFRM
76354 {
76355 struct rt6_info *rt = (struct rt6_info *)dst;
76356 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76357 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76358 }
76359 #endif
76360 }
76361 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76362 #ifdef CONFIG_XFRM
76363 if (dst) {
76364 struct rt6_info *rt = (struct rt6_info *)dst;
76365 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76366 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76367 __sk_dst_reset(sk);
76368 dst = NULL;
76369 }
76370 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76371 index ba6d13d..6899122 100644
76372 --- a/net/ipv6/ipv6_sockglue.c
76373 +++ b/net/ipv6/ipv6_sockglue.c
76374 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76375 if (sk->sk_type != SOCK_STREAM)
76376 return -ENOPROTOOPT;
76377
76378 - msg.msg_control = optval;
76379 + msg.msg_control = (void __force_kernel *)optval;
76380 msg.msg_controllen = len;
76381 msg.msg_flags = flags;
76382
76383 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76384 index 93d6983..8e54c4d 100644
76385 --- a/net/ipv6/raw.c
76386 +++ b/net/ipv6/raw.c
76387 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76388 {
76389 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76390 skb_checksum_complete(skb)) {
76391 - atomic_inc(&sk->sk_drops);
76392 + atomic_inc_unchecked(&sk->sk_drops);
76393 kfree_skb(skb);
76394 return NET_RX_DROP;
76395 }
76396 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76397 struct raw6_sock *rp = raw6_sk(sk);
76398
76399 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76400 - atomic_inc(&sk->sk_drops);
76401 + atomic_inc_unchecked(&sk->sk_drops);
76402 kfree_skb(skb);
76403 return NET_RX_DROP;
76404 }
76405 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76406
76407 if (inet->hdrincl) {
76408 if (skb_checksum_complete(skb)) {
76409 - atomic_inc(&sk->sk_drops);
76410 + atomic_inc_unchecked(&sk->sk_drops);
76411 kfree_skb(skb);
76412 return NET_RX_DROP;
76413 }
76414 @@ -602,7 +602,7 @@ out:
76415 return err;
76416 }
76417
76418 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76419 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76420 struct flowi6 *fl6, struct dst_entry **dstp,
76421 unsigned int flags)
76422 {
76423 @@ -914,12 +914,15 @@ do_confirm:
76424 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76425 char __user *optval, int optlen)
76426 {
76427 + struct icmp6_filter filter;
76428 +
76429 switch (optname) {
76430 case ICMPV6_FILTER:
76431 if (optlen > sizeof(struct icmp6_filter))
76432 optlen = sizeof(struct icmp6_filter);
76433 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76434 + if (copy_from_user(&filter, optval, optlen))
76435 return -EFAULT;
76436 + raw6_sk(sk)->filter = filter;
76437 return 0;
76438 default:
76439 return -ENOPROTOOPT;
76440 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76441 char __user *optval, int __user *optlen)
76442 {
76443 int len;
76444 + struct icmp6_filter filter;
76445
76446 switch (optname) {
76447 case ICMPV6_FILTER:
76448 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76449 len = sizeof(struct icmp6_filter);
76450 if (put_user(len, optlen))
76451 return -EFAULT;
76452 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76453 + filter = raw6_sk(sk)->filter;
76454 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76455 return -EFAULT;
76456 return 0;
76457 default:
76458 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76459 0, 0L, 0,
76460 sock_i_uid(sp), 0,
76461 sock_i_ino(sp),
76462 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76463 + atomic_read(&sp->sk_refcnt),
76464 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76465 + NULL,
76466 +#else
76467 + sp,
76468 +#endif
76469 + atomic_read_unchecked(&sp->sk_drops));
76470 }
76471
76472 static int raw6_seq_show(struct seq_file *seq, void *v)
76473 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76474 index 9df64a5..39875da 100644
76475 --- a/net/ipv6/tcp_ipv6.c
76476 +++ b/net/ipv6/tcp_ipv6.c
76477 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76478 }
76479 #endif
76480
76481 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76482 +extern int grsec_enable_blackhole;
76483 +#endif
76484 +
76485 static void tcp_v6_hash(struct sock *sk)
76486 {
76487 if (sk->sk_state != TCP_CLOSE) {
76488 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76489 return 0;
76490
76491 reset:
76492 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76493 + if (!grsec_enable_blackhole)
76494 +#endif
76495 tcp_v6_send_reset(sk, skb);
76496 discard:
76497 if (opt_skb)
76498 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76499 TCP_SKB_CB(skb)->sacked = 0;
76500
76501 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76502 - if (!sk)
76503 + if (!sk) {
76504 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76505 + ret = 1;
76506 +#endif
76507 goto no_tcp_socket;
76508 + }
76509
76510 process:
76511 - if (sk->sk_state == TCP_TIME_WAIT)
76512 + if (sk->sk_state == TCP_TIME_WAIT) {
76513 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76514 + ret = 2;
76515 +#endif
76516 goto do_time_wait;
76517 + }
76518
76519 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76520 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76521 @@ -1679,6 +1694,10 @@ no_tcp_socket:
76522 bad_packet:
76523 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76524 } else {
76525 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76526 + if (!grsec_enable_blackhole || (ret == 1 &&
76527 + (skb->dev->flags & IFF_LOOPBACK)))
76528 +#endif
76529 tcp_v6_send_reset(NULL, skb);
76530 }
76531
76532 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76533 uid,
76534 0, /* non standard timer */
76535 0, /* open_requests have no inode */
76536 - 0, req);
76537 + 0,
76538 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76539 + NULL
76540 +#else
76541 + req
76542 +#endif
76543 + );
76544 }
76545
76546 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76547 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76548 sock_i_uid(sp),
76549 icsk->icsk_probes_out,
76550 sock_i_ino(sp),
76551 - atomic_read(&sp->sk_refcnt), sp,
76552 + atomic_read(&sp->sk_refcnt),
76553 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76554 + NULL,
76555 +#else
76556 + sp,
76557 +#endif
76558 jiffies_to_clock_t(icsk->icsk_rto),
76559 jiffies_to_clock_t(icsk->icsk_ack.ato),
76560 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76561 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76562 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76563 tw->tw_substate, 0, 0,
76564 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76565 - atomic_read(&tw->tw_refcnt), tw);
76566 + atomic_read(&tw->tw_refcnt),
76567 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76568 + NULL
76569 +#else
76570 + tw
76571 +#endif
76572 + );
76573 }
76574
76575 static int tcp6_seq_show(struct seq_file *seq, void *v)
76576 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76577 index f05099f..ea613f0 100644
76578 --- a/net/ipv6/udp.c
76579 +++ b/net/ipv6/udp.c
76580 @@ -50,6 +50,10 @@
76581 #include <linux/seq_file.h>
76582 #include "udp_impl.h"
76583
76584 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76585 +extern int grsec_enable_blackhole;
76586 +#endif
76587 +
76588 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76589 {
76590 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76591 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76592 return rc;
76593 drop:
76594 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76595 - atomic_inc(&sk->sk_drops);
76596 + atomic_inc_unchecked(&sk->sk_drops);
76597 kfree_skb(skb);
76598 return -1;
76599 }
76600 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76601 if (likely(skb1 == NULL))
76602 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76603 if (!skb1) {
76604 - atomic_inc(&sk->sk_drops);
76605 + atomic_inc_unchecked(&sk->sk_drops);
76606 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76607 IS_UDPLITE(sk));
76608 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76609 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76610 goto discard;
76611
76612 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76613 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76614 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76615 +#endif
76616 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76617
76618 kfree_skb(skb);
76619 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76620 0, 0L, 0,
76621 sock_i_uid(sp), 0,
76622 sock_i_ino(sp),
76623 - atomic_read(&sp->sk_refcnt), sp,
76624 - atomic_read(&sp->sk_drops));
76625 + atomic_read(&sp->sk_refcnt),
76626 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76627 + NULL,
76628 +#else
76629 + sp,
76630 +#endif
76631 + atomic_read_unchecked(&sp->sk_drops));
76632 }
76633
76634 int udp6_seq_show(struct seq_file *seq, void *v)
76635 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76636 index 6b9d5a0..4dffaf1 100644
76637 --- a/net/irda/ircomm/ircomm_tty.c
76638 +++ b/net/irda/ircomm/ircomm_tty.c
76639 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76640 add_wait_queue(&self->open_wait, &wait);
76641
76642 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76643 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76644 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76645
76646 /* As far as I can see, we protect open_count - Jean II */
76647 spin_lock_irqsave(&self->spinlock, flags);
76648 if (!tty_hung_up_p(filp)) {
76649 extra_count = 1;
76650 - self->open_count--;
76651 + local_dec(&self->open_count);
76652 }
76653 spin_unlock_irqrestore(&self->spinlock, flags);
76654 - self->blocked_open++;
76655 + local_inc(&self->blocked_open);
76656
76657 while (1) {
76658 if (tty->termios->c_cflag & CBAUD) {
76659 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76660 }
76661
76662 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76663 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76664 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76665
76666 schedule();
76667 }
76668 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76669 if (extra_count) {
76670 /* ++ is not atomic, so this should be protected - Jean II */
76671 spin_lock_irqsave(&self->spinlock, flags);
76672 - self->open_count++;
76673 + local_inc(&self->open_count);
76674 spin_unlock_irqrestore(&self->spinlock, flags);
76675 }
76676 - self->blocked_open--;
76677 + local_dec(&self->blocked_open);
76678
76679 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76680 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76681 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76682
76683 if (!retval)
76684 self->flags |= ASYNC_NORMAL_ACTIVE;
76685 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76686 }
76687 /* ++ is not atomic, so this should be protected - Jean II */
76688 spin_lock_irqsave(&self->spinlock, flags);
76689 - self->open_count++;
76690 + local_inc(&self->open_count);
76691
76692 tty->driver_data = self;
76693 self->tty = tty;
76694 spin_unlock_irqrestore(&self->spinlock, flags);
76695
76696 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76697 - self->line, self->open_count);
76698 + self->line, local_read(&self->open_count));
76699
76700 /* Not really used by us, but lets do it anyway */
76701 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76702 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76703 return;
76704 }
76705
76706 - if ((tty->count == 1) && (self->open_count != 1)) {
76707 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76708 /*
76709 * Uh, oh. tty->count is 1, which means that the tty
76710 * structure will be freed. state->count should always
76711 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76712 */
76713 IRDA_DEBUG(0, "%s(), bad serial port count; "
76714 "tty->count is 1, state->count is %d\n", __func__ ,
76715 - self->open_count);
76716 - self->open_count = 1;
76717 + local_read(&self->open_count));
76718 + local_set(&self->open_count, 1);
76719 }
76720
76721 - if (--self->open_count < 0) {
76722 + if (local_dec_return(&self->open_count) < 0) {
76723 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76724 - __func__, self->line, self->open_count);
76725 - self->open_count = 0;
76726 + __func__, self->line, local_read(&self->open_count));
76727 + local_set(&self->open_count, 0);
76728 }
76729 - if (self->open_count) {
76730 + if (local_read(&self->open_count)) {
76731 spin_unlock_irqrestore(&self->spinlock, flags);
76732
76733 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76734 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76735 tty->closing = 0;
76736 self->tty = NULL;
76737
76738 - if (self->blocked_open) {
76739 + if (local_read(&self->blocked_open)) {
76740 if (self->close_delay)
76741 schedule_timeout_interruptible(self->close_delay);
76742 wake_up_interruptible(&self->open_wait);
76743 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76744 spin_lock_irqsave(&self->spinlock, flags);
76745 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76746 self->tty = NULL;
76747 - self->open_count = 0;
76748 + local_set(&self->open_count, 0);
76749 spin_unlock_irqrestore(&self->spinlock, flags);
76750
76751 wake_up_interruptible(&self->open_wait);
76752 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76753 seq_putc(m, '\n');
76754
76755 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76756 - seq_printf(m, "Open count: %d\n", self->open_count);
76757 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76758 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76759 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76760
76761 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76762 index cd6f7a9..e63fe89 100644
76763 --- a/net/iucv/af_iucv.c
76764 +++ b/net/iucv/af_iucv.c
76765 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76766
76767 write_lock_bh(&iucv_sk_list.lock);
76768
76769 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76770 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76771 while (__iucv_get_sock_by_name(name)) {
76772 sprintf(name, "%08x",
76773 - atomic_inc_return(&iucv_sk_list.autobind_name));
76774 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76775 }
76776
76777 write_unlock_bh(&iucv_sk_list.lock);
76778 diff --git a/net/key/af_key.c b/net/key/af_key.c
76779 index 34e4185..8823368 100644
76780 --- a/net/key/af_key.c
76781 +++ b/net/key/af_key.c
76782 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76783 static u32 get_acqseq(void)
76784 {
76785 u32 res;
76786 - static atomic_t acqseq;
76787 + static atomic_unchecked_t acqseq;
76788
76789 do {
76790 - res = atomic_inc_return(&acqseq);
76791 + res = atomic_inc_return_unchecked(&acqseq);
76792 } while (!res);
76793 return res;
76794 }
76795 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76796 index 3f3cd50..d2cf249 100644
76797 --- a/net/mac80211/ieee80211_i.h
76798 +++ b/net/mac80211/ieee80211_i.h
76799 @@ -28,6 +28,7 @@
76800 #include <net/ieee80211_radiotap.h>
76801 #include <net/cfg80211.h>
76802 #include <net/mac80211.h>
76803 +#include <asm/local.h>
76804 #include "key.h"
76805 #include "sta_info.h"
76806
76807 @@ -863,7 +864,7 @@ struct ieee80211_local {
76808 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76809 spinlock_t queue_stop_reason_lock;
76810
76811 - int open_count;
76812 + local_t open_count;
76813 int monitors, cooked_mntrs;
76814 /* number of interfaces with corresponding FIF_ flags */
76815 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76816 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76817 index 8664111..1d6a065 100644
76818 --- a/net/mac80211/iface.c
76819 +++ b/net/mac80211/iface.c
76820 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76821 break;
76822 }
76823
76824 - if (local->open_count == 0) {
76825 + if (local_read(&local->open_count) == 0) {
76826 res = drv_start(local);
76827 if (res)
76828 goto err_del_bss;
76829 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76830 break;
76831 }
76832
76833 - if (local->monitors == 0 && local->open_count == 0) {
76834 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
76835 res = ieee80211_add_virtual_monitor(local);
76836 if (res)
76837 goto err_stop;
76838 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76839 mutex_unlock(&local->mtx);
76840
76841 if (coming_up)
76842 - local->open_count++;
76843 + local_inc(&local->open_count);
76844
76845 if (hw_reconf_flags)
76846 ieee80211_hw_config(local, hw_reconf_flags);
76847 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76848 err_del_interface:
76849 drv_remove_interface(local, sdata);
76850 err_stop:
76851 - if (!local->open_count)
76852 + if (!local_read(&local->open_count))
76853 drv_stop(local);
76854 err_del_bss:
76855 sdata->bss = NULL;
76856 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76857 }
76858
76859 if (going_down)
76860 - local->open_count--;
76861 + local_dec(&local->open_count);
76862
76863 switch (sdata->vif.type) {
76864 case NL80211_IFTYPE_AP_VLAN:
76865 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76866
76867 ieee80211_recalc_ps(local, -1);
76868
76869 - if (local->open_count == 0) {
76870 + if (local_read(&local->open_count) == 0) {
76871 if (local->ops->napi_poll)
76872 napi_disable(&local->napi);
76873 ieee80211_clear_tx_pending(local);
76874 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76875 }
76876 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
76877
76878 - if (local->monitors == local->open_count && local->monitors > 0)
76879 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
76880 ieee80211_add_virtual_monitor(local);
76881 }
76882
76883 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76884 index f5548e9..474a15f 100644
76885 --- a/net/mac80211/main.c
76886 +++ b/net/mac80211/main.c
76887 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76888 local->hw.conf.power_level = power;
76889 }
76890
76891 - if (changed && local->open_count) {
76892 + if (changed && local_read(&local->open_count)) {
76893 ret = drv_config(local, changed);
76894 /*
76895 * Goal:
76896 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76897 index af1c4e2..24dbbe3 100644
76898 --- a/net/mac80211/pm.c
76899 +++ b/net/mac80211/pm.c
76900 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76901 struct ieee80211_sub_if_data *sdata;
76902 struct sta_info *sta;
76903
76904 - if (!local->open_count)
76905 + if (!local_read(&local->open_count))
76906 goto suspend;
76907
76908 ieee80211_scan_cancel(local);
76909 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76910 cancel_work_sync(&local->dynamic_ps_enable_work);
76911 del_timer_sync(&local->dynamic_ps_timer);
76912
76913 - local->wowlan = wowlan && local->open_count;
76914 + local->wowlan = wowlan && local_read(&local->open_count);
76915 if (local->wowlan) {
76916 int err = drv_suspend(local, wowlan);
76917 if (err < 0) {
76918 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76919 drv_remove_interface(local, sdata);
76920
76921 /* stop hardware - this must stop RX */
76922 - if (local->open_count)
76923 + if (local_read(&local->open_count))
76924 ieee80211_stop_device(local);
76925
76926 suspend:
76927 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76928 index 3313c11..bec9f17 100644
76929 --- a/net/mac80211/rate.c
76930 +++ b/net/mac80211/rate.c
76931 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76932
76933 ASSERT_RTNL();
76934
76935 - if (local->open_count)
76936 + if (local_read(&local->open_count))
76937 return -EBUSY;
76938
76939 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76940 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76941 index c97a065..ff61928 100644
76942 --- a/net/mac80211/rc80211_pid_debugfs.c
76943 +++ b/net/mac80211/rc80211_pid_debugfs.c
76944 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76945
76946 spin_unlock_irqrestore(&events->lock, status);
76947
76948 - if (copy_to_user(buf, pb, p))
76949 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76950 return -EFAULT;
76951
76952 return p;
76953 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76954 index 8dd4712..19594fa 100644
76955 --- a/net/mac80211/util.c
76956 +++ b/net/mac80211/util.c
76957 @@ -1216,7 +1216,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76958 }
76959 #endif
76960 /* everything else happens only if HW was up & running */
76961 - if (!local->open_count)
76962 + if (!local_read(&local->open_count))
76963 goto wake_up;
76964
76965 /*
76966 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76967 index 209c1ed..39484dc 100644
76968 --- a/net/netfilter/Kconfig
76969 +++ b/net/netfilter/Kconfig
76970 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
76971
76972 To compile it as a module, choose M here. If unsure, say N.
76973
76974 +config NETFILTER_XT_MATCH_GRADM
76975 + tristate '"gradm" match support'
76976 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76977 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76978 + ---help---
76979 + The gradm match allows to match on grsecurity RBAC being enabled.
76980 + It is useful when iptables rules are applied early on bootup to
76981 + prevent connections to the machine (except from a trusted host)
76982 + while the RBAC system is disabled.
76983 +
76984 config NETFILTER_XT_MATCH_HASHLIMIT
76985 tristate '"hashlimit" match support'
76986 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76987 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76988 index 4e7960c..89e48d4 100644
76989 --- a/net/netfilter/Makefile
76990 +++ b/net/netfilter/Makefile
76991 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76992 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76993 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76994 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76995 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76996 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76997 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76998 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76999 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77000 index 1548df9..98ad9b4 100644
77001 --- a/net/netfilter/ipvs/ip_vs_conn.c
77002 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77003 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77004 /* Increase the refcnt counter of the dest */
77005 atomic_inc(&dest->refcnt);
77006
77007 - conn_flags = atomic_read(&dest->conn_flags);
77008 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77009 if (cp->protocol != IPPROTO_UDP)
77010 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77011 flags = cp->flags;
77012 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77013 atomic_set(&cp->refcnt, 1);
77014
77015 atomic_set(&cp->n_control, 0);
77016 - atomic_set(&cp->in_pkts, 0);
77017 + atomic_set_unchecked(&cp->in_pkts, 0);
77018
77019 atomic_inc(&ipvs->conn_count);
77020 if (flags & IP_VS_CONN_F_NO_CPORT)
77021 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77022
77023 /* Don't drop the entry if its number of incoming packets is not
77024 located in [0, 8] */
77025 - i = atomic_read(&cp->in_pkts);
77026 + i = atomic_read_unchecked(&cp->in_pkts);
77027 if (i > 8 || i < 0) return 0;
77028
77029 if (!todrop_rate[i]) return 0;
77030 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77031 index a54b018c..07e0120 100644
77032 --- a/net/netfilter/ipvs/ip_vs_core.c
77033 +++ b/net/netfilter/ipvs/ip_vs_core.c
77034 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77035 ret = cp->packet_xmit(skb, cp, pd->pp);
77036 /* do not touch skb anymore */
77037
77038 - atomic_inc(&cp->in_pkts);
77039 + atomic_inc_unchecked(&cp->in_pkts);
77040 ip_vs_conn_put(cp);
77041 return ret;
77042 }
77043 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77044 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77045 pkts = sysctl_sync_threshold(ipvs);
77046 else
77047 - pkts = atomic_add_return(1, &cp->in_pkts);
77048 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77049
77050 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77051 ip_vs_sync_conn(net, cp, pkts);
77052 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77053 index 84444dd..86adaa0 100644
77054 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77055 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77056 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77057 ip_vs_rs_hash(ipvs, dest);
77058 write_unlock_bh(&ipvs->rs_lock);
77059 }
77060 - atomic_set(&dest->conn_flags, conn_flags);
77061 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77062
77063 /* bind the service */
77064 if (!dest->svc) {
77065 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77066 " %-7s %-6d %-10d %-10d\n",
77067 &dest->addr.in6,
77068 ntohs(dest->port),
77069 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77070 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77071 atomic_read(&dest->weight),
77072 atomic_read(&dest->activeconns),
77073 atomic_read(&dest->inactconns));
77074 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77075 "%-7s %-6d %-10d %-10d\n",
77076 ntohl(dest->addr.ip),
77077 ntohs(dest->port),
77078 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77079 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77080 atomic_read(&dest->weight),
77081 atomic_read(&dest->activeconns),
77082 atomic_read(&dest->inactconns));
77083 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77084
77085 entry.addr = dest->addr.ip;
77086 entry.port = dest->port;
77087 - entry.conn_flags = atomic_read(&dest->conn_flags);
77088 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77089 entry.weight = atomic_read(&dest->weight);
77090 entry.u_threshold = dest->u_threshold;
77091 entry.l_threshold = dest->l_threshold;
77092 @@ -3089,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77093 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77094 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77095 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77096 - (atomic_read(&dest->conn_flags) &
77097 + (atomic_read_unchecked(&dest->conn_flags) &
77098 IP_VS_CONN_F_FWD_MASK)) ||
77099 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77100 atomic_read(&dest->weight)) ||
77101 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77102 index effa10c..9058928 100644
77103 --- a/net/netfilter/ipvs/ip_vs_sync.c
77104 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77105 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77106 cp = cp->control;
77107 if (cp) {
77108 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77109 - pkts = atomic_add_return(1, &cp->in_pkts);
77110 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77111 else
77112 pkts = sysctl_sync_threshold(ipvs);
77113 ip_vs_sync_conn(net, cp->control, pkts);
77114 @@ -758,7 +758,7 @@ control:
77115 if (!cp)
77116 return;
77117 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77118 - pkts = atomic_add_return(1, &cp->in_pkts);
77119 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77120 else
77121 pkts = sysctl_sync_threshold(ipvs);
77122 goto sloop;
77123 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77124
77125 if (opt)
77126 memcpy(&cp->in_seq, opt, sizeof(*opt));
77127 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77128 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77129 cp->state = state;
77130 cp->old_state = cp->state;
77131 /*
77132 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77133 index 7fd66de..e6fb361 100644
77134 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77135 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77136 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77137 else
77138 rc = NF_ACCEPT;
77139 /* do not touch skb anymore */
77140 - atomic_inc(&cp->in_pkts);
77141 + atomic_inc_unchecked(&cp->in_pkts);
77142 goto out;
77143 }
77144
77145 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77146 else
77147 rc = NF_ACCEPT;
77148 /* do not touch skb anymore */
77149 - atomic_inc(&cp->in_pkts);
77150 + atomic_inc_unchecked(&cp->in_pkts);
77151 goto out;
77152 }
77153
77154 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77155 index ac3af97..c134c21 100644
77156 --- a/net/netfilter/nf_conntrack_core.c
77157 +++ b/net/netfilter/nf_conntrack_core.c
77158 @@ -1530,6 +1530,10 @@ err_proto:
77159 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77160 #define DYING_NULLS_VAL ((1<<30)+1)
77161
77162 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77163 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77164 +#endif
77165 +
77166 static int nf_conntrack_init_net(struct net *net)
77167 {
77168 int ret;
77169 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77170 goto err_stat;
77171 }
77172
77173 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77174 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77175 +#else
77176 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77177 +#endif
77178 if (!net->ct.slabname) {
77179 ret = -ENOMEM;
77180 goto err_slabname;
77181 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77182 index 3c3cfc0..7a6ea1a 100644
77183 --- a/net/netfilter/nfnetlink_log.c
77184 +++ b/net/netfilter/nfnetlink_log.c
77185 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77186 };
77187
77188 static DEFINE_SPINLOCK(instances_lock);
77189 -static atomic_t global_seq;
77190 +static atomic_unchecked_t global_seq;
77191
77192 #define INSTANCE_BUCKETS 16
77193 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77194 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77195 /* global sequence number */
77196 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77197 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77198 - htonl(atomic_inc_return(&global_seq))))
77199 + htonl(atomic_inc_return_unchecked(&global_seq))))
77200 goto nla_put_failure;
77201
77202 if (data_len) {
77203 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77204 new file mode 100644
77205 index 0000000..6905327
77206 --- /dev/null
77207 +++ b/net/netfilter/xt_gradm.c
77208 @@ -0,0 +1,51 @@
77209 +/*
77210 + * gradm match for netfilter
77211 + * Copyright © Zbigniew Krzystolik, 2010
77212 + *
77213 + * This program is free software; you can redistribute it and/or modify
77214 + * it under the terms of the GNU General Public License; either version
77215 + * 2 or 3 as published by the Free Software Foundation.
77216 + */
77217 +#include <linux/module.h>
77218 +#include <linux/moduleparam.h>
77219 +#include <linux/skbuff.h>
77220 +#include <linux/netfilter/x_tables.h>
77221 +#include <linux/grsecurity.h>
77222 +#include <linux/netfilter/xt_gradm.h>
77223 +
77224 +static bool
77225 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77226 +{
77227 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77228 + bool retval = false;
77229 + if (gr_acl_is_enabled())
77230 + retval = true;
77231 + return retval ^ info->invflags;
77232 +}
77233 +
77234 +static struct xt_match gradm_mt_reg __read_mostly = {
77235 + .name = "gradm",
77236 + .revision = 0,
77237 + .family = NFPROTO_UNSPEC,
77238 + .match = gradm_mt,
77239 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77240 + .me = THIS_MODULE,
77241 +};
77242 +
77243 +static int __init gradm_mt_init(void)
77244 +{
77245 + return xt_register_match(&gradm_mt_reg);
77246 +}
77247 +
77248 +static void __exit gradm_mt_exit(void)
77249 +{
77250 + xt_unregister_match(&gradm_mt_reg);
77251 +}
77252 +
77253 +module_init(gradm_mt_init);
77254 +module_exit(gradm_mt_exit);
77255 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77256 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77257 +MODULE_LICENSE("GPL");
77258 +MODULE_ALIAS("ipt_gradm");
77259 +MODULE_ALIAS("ip6t_gradm");
77260 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77261 index 4fe4fb4..87a89e5 100644
77262 --- a/net/netfilter/xt_statistic.c
77263 +++ b/net/netfilter/xt_statistic.c
77264 @@ -19,7 +19,7 @@
77265 #include <linux/module.h>
77266
77267 struct xt_statistic_priv {
77268 - atomic_t count;
77269 + atomic_unchecked_t count;
77270 } ____cacheline_aligned_in_smp;
77271
77272 MODULE_LICENSE("GPL");
77273 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77274 break;
77275 case XT_STATISTIC_MODE_NTH:
77276 do {
77277 - oval = atomic_read(&info->master->count);
77278 + oval = atomic_read_unchecked(&info->master->count);
77279 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77280 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77281 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77282 if (nval == 0)
77283 ret = !ret;
77284 break;
77285 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77286 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77287 if (info->master == NULL)
77288 return -ENOMEM;
77289 - atomic_set(&info->master->count, info->u.nth.count);
77290 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77291
77292 return 0;
77293 }
77294 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77295 index b3025a6..d63a537 100644
77296 --- a/net/netlink/af_netlink.c
77297 +++ b/net/netlink/af_netlink.c
77298 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
77299 sk->sk_error_report(sk);
77300 }
77301 }
77302 - atomic_inc(&sk->sk_drops);
77303 + atomic_inc_unchecked(&sk->sk_drops);
77304 }
77305
77306 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77307 @@ -2022,7 +2022,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77308 sk_wmem_alloc_get(s),
77309 nlk->cb,
77310 atomic_read(&s->sk_refcnt),
77311 - atomic_read(&s->sk_drops),
77312 + atomic_read_unchecked(&s->sk_drops),
77313 sock_i_ino(s)
77314 );
77315
77316 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77317 index 06592d8..64860f6 100644
77318 --- a/net/netrom/af_netrom.c
77319 +++ b/net/netrom/af_netrom.c
77320 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77321 struct sock *sk = sock->sk;
77322 struct nr_sock *nr = nr_sk(sk);
77323
77324 + memset(sax, 0, sizeof(*sax));
77325 lock_sock(sk);
77326 if (peer != 0) {
77327 if (sk->sk_state != TCP_ESTABLISHED) {
77328 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77329 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77330 } else {
77331 sax->fsa_ax25.sax25_family = AF_NETROM;
77332 - sax->fsa_ax25.sax25_ndigis = 0;
77333 sax->fsa_ax25.sax25_call = nr->source_addr;
77334 *uaddr_len = sizeof(struct sockaddr_ax25);
77335 }
77336 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77337 index 0f66174..2f50376 100644
77338 --- a/net/packet/af_packet.c
77339 +++ b/net/packet/af_packet.c
77340 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77341
77342 spin_lock(&sk->sk_receive_queue.lock);
77343 po->stats.tp_packets++;
77344 - skb->dropcount = atomic_read(&sk->sk_drops);
77345 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77346 __skb_queue_tail(&sk->sk_receive_queue, skb);
77347 spin_unlock(&sk->sk_receive_queue.lock);
77348 sk->sk_data_ready(sk, skb->len);
77349 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77350 drop_n_acct:
77351 spin_lock(&sk->sk_receive_queue.lock);
77352 po->stats.tp_drops++;
77353 - atomic_inc(&sk->sk_drops);
77354 + atomic_inc_unchecked(&sk->sk_drops);
77355 spin_unlock(&sk->sk_receive_queue.lock);
77356
77357 drop_n_restore:
77358 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77359 case PACKET_HDRLEN:
77360 if (len > sizeof(int))
77361 len = sizeof(int);
77362 - if (copy_from_user(&val, optval, len))
77363 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77364 return -EFAULT;
77365 switch (val) {
77366 case TPACKET_V1:
77367 @@ -3314,7 +3314,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77368 len = lv;
77369 if (put_user(len, optlen))
77370 return -EFAULT;
77371 - if (copy_to_user(optval, data, len))
77372 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77373 return -EFAULT;
77374 return 0;
77375 }
77376 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77377 index 5a940db..f0b9c12 100644
77378 --- a/net/phonet/af_phonet.c
77379 +++ b/net/phonet/af_phonet.c
77380 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77381 {
77382 struct phonet_protocol *pp;
77383
77384 - if (protocol >= PHONET_NPROTO)
77385 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77386 return NULL;
77387
77388 rcu_read_lock();
77389 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77390 {
77391 int err = 0;
77392
77393 - if (protocol >= PHONET_NPROTO)
77394 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77395 return -EINVAL;
77396
77397 err = proto_register(pp->prot, 1);
77398 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77399 index 576f22c..bc7a71b 100644
77400 --- a/net/phonet/pep.c
77401 +++ b/net/phonet/pep.c
77402 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77403
77404 case PNS_PEP_CTRL_REQ:
77405 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77406 - atomic_inc(&sk->sk_drops);
77407 + atomic_inc_unchecked(&sk->sk_drops);
77408 break;
77409 }
77410 __skb_pull(skb, 4);
77411 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77412 }
77413
77414 if (pn->rx_credits == 0) {
77415 - atomic_inc(&sk->sk_drops);
77416 + atomic_inc_unchecked(&sk->sk_drops);
77417 err = -ENOBUFS;
77418 break;
77419 }
77420 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77421 }
77422
77423 if (pn->rx_credits == 0) {
77424 - atomic_inc(&sk->sk_drops);
77425 + atomic_inc_unchecked(&sk->sk_drops);
77426 err = NET_RX_DROP;
77427 break;
77428 }
77429 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77430 index 0acc943..c727611 100644
77431 --- a/net/phonet/socket.c
77432 +++ b/net/phonet/socket.c
77433 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77434 pn->resource, sk->sk_state,
77435 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77436 sock_i_uid(sk), sock_i_ino(sk),
77437 - atomic_read(&sk->sk_refcnt), sk,
77438 - atomic_read(&sk->sk_drops), &len);
77439 + atomic_read(&sk->sk_refcnt),
77440 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77441 + NULL,
77442 +#else
77443 + sk,
77444 +#endif
77445 + atomic_read_unchecked(&sk->sk_drops), &len);
77446 }
77447 seq_printf(seq, "%*s\n", 127 - len, "");
77448 return 0;
77449 diff --git a/net/rds/cong.c b/net/rds/cong.c
77450 index e5b65ac..f3b6fb7 100644
77451 --- a/net/rds/cong.c
77452 +++ b/net/rds/cong.c
77453 @@ -78,7 +78,7 @@
77454 * finds that the saved generation number is smaller than the global generation
77455 * number, it wakes up the process.
77456 */
77457 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77458 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77459
77460 /*
77461 * Congestion monitoring
77462 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77463 rdsdebug("waking map %p for %pI4\n",
77464 map, &map->m_addr);
77465 rds_stats_inc(s_cong_update_received);
77466 - atomic_inc(&rds_cong_generation);
77467 + atomic_inc_unchecked(&rds_cong_generation);
77468 if (waitqueue_active(&map->m_waitq))
77469 wake_up(&map->m_waitq);
77470 if (waitqueue_active(&rds_poll_waitq))
77471 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77472
77473 int rds_cong_updated_since(unsigned long *recent)
77474 {
77475 - unsigned long gen = atomic_read(&rds_cong_generation);
77476 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77477
77478 if (likely(*recent == gen))
77479 return 0;
77480 diff --git a/net/rds/ib.h b/net/rds/ib.h
77481 index 8d2b3d5..227ec5b 100644
77482 --- a/net/rds/ib.h
77483 +++ b/net/rds/ib.h
77484 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77485 /* sending acks */
77486 unsigned long i_ack_flags;
77487 #ifdef KERNEL_HAS_ATOMIC64
77488 - atomic64_t i_ack_next; /* next ACK to send */
77489 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77490 #else
77491 spinlock_t i_ack_lock; /* protect i_ack_next */
77492 u64 i_ack_next; /* next ACK to send */
77493 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77494 index a1e1162..265e129 100644
77495 --- a/net/rds/ib_cm.c
77496 +++ b/net/rds/ib_cm.c
77497 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77498 /* Clear the ACK state */
77499 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77500 #ifdef KERNEL_HAS_ATOMIC64
77501 - atomic64_set(&ic->i_ack_next, 0);
77502 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77503 #else
77504 ic->i_ack_next = 0;
77505 #endif
77506 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77507 index 8d19491..05a3e65 100644
77508 --- a/net/rds/ib_recv.c
77509 +++ b/net/rds/ib_recv.c
77510 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77511 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77512 int ack_required)
77513 {
77514 - atomic64_set(&ic->i_ack_next, seq);
77515 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77516 if (ack_required) {
77517 smp_mb__before_clear_bit();
77518 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77519 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77520 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77521 smp_mb__after_clear_bit();
77522
77523 - return atomic64_read(&ic->i_ack_next);
77524 + return atomic64_read_unchecked(&ic->i_ack_next);
77525 }
77526 #endif
77527
77528 diff --git a/net/rds/iw.h b/net/rds/iw.h
77529 index 04ce3b1..48119a6 100644
77530 --- a/net/rds/iw.h
77531 +++ b/net/rds/iw.h
77532 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77533 /* sending acks */
77534 unsigned long i_ack_flags;
77535 #ifdef KERNEL_HAS_ATOMIC64
77536 - atomic64_t i_ack_next; /* next ACK to send */
77537 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77538 #else
77539 spinlock_t i_ack_lock; /* protect i_ack_next */
77540 u64 i_ack_next; /* next ACK to send */
77541 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77542 index a91e1db..cf3053f 100644
77543 --- a/net/rds/iw_cm.c
77544 +++ b/net/rds/iw_cm.c
77545 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77546 /* Clear the ACK state */
77547 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77548 #ifdef KERNEL_HAS_ATOMIC64
77549 - atomic64_set(&ic->i_ack_next, 0);
77550 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77551 #else
77552 ic->i_ack_next = 0;
77553 #endif
77554 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77555 index 4503335..db566b4 100644
77556 --- a/net/rds/iw_recv.c
77557 +++ b/net/rds/iw_recv.c
77558 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77559 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77560 int ack_required)
77561 {
77562 - atomic64_set(&ic->i_ack_next, seq);
77563 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77564 if (ack_required) {
77565 smp_mb__before_clear_bit();
77566 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77567 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77568 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77569 smp_mb__after_clear_bit();
77570
77571 - return atomic64_read(&ic->i_ack_next);
77572 + return atomic64_read_unchecked(&ic->i_ack_next);
77573 }
77574 #endif
77575
77576 diff --git a/net/rds/recv.c b/net/rds/recv.c
77577 index 5c6e9f1..9f0f17c 100644
77578 --- a/net/rds/recv.c
77579 +++ b/net/rds/recv.c
77580 @@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77581
77582 rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
77583
77584 + msg->msg_namelen = 0;
77585 +
77586 if (msg_flags & MSG_OOB)
77587 goto out;
77588
77589 @@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77590 sin->sin_port = inc->i_hdr.h_sport;
77591 sin->sin_addr.s_addr = inc->i_saddr;
77592 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
77593 + msg->msg_namelen = sizeof(*sin);
77594 }
77595 break;
77596 }
77597 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77598 index edac9ef..16bcb98 100644
77599 --- a/net/rds/tcp.c
77600 +++ b/net/rds/tcp.c
77601 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77602 int val = 1;
77603
77604 set_fs(KERNEL_DS);
77605 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77606 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77607 sizeof(val));
77608 set_fs(oldfs);
77609 }
77610 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77611 index 1b4fd68..2234175 100644
77612 --- a/net/rds/tcp_send.c
77613 +++ b/net/rds/tcp_send.c
77614 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77615
77616 oldfs = get_fs();
77617 set_fs(KERNEL_DS);
77618 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77619 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77620 sizeof(val));
77621 set_fs(oldfs);
77622 }
77623 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77624 index 05996d0..5a1dfe0 100644
77625 --- a/net/rxrpc/af_rxrpc.c
77626 +++ b/net/rxrpc/af_rxrpc.c
77627 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77628 __be32 rxrpc_epoch;
77629
77630 /* current debugging ID */
77631 -atomic_t rxrpc_debug_id;
77632 +atomic_unchecked_t rxrpc_debug_id;
77633
77634 /* count of skbs currently in use */
77635 atomic_t rxrpc_n_skbs;
77636 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77637 index e4d9cbc..b229649 100644
77638 --- a/net/rxrpc/ar-ack.c
77639 +++ b/net/rxrpc/ar-ack.c
77640 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77641
77642 _enter("{%d,%d,%d,%d},",
77643 call->acks_hard, call->acks_unacked,
77644 - atomic_read(&call->sequence),
77645 + atomic_read_unchecked(&call->sequence),
77646 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77647
77648 stop = 0;
77649 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77650
77651 /* each Tx packet has a new serial number */
77652 sp->hdr.serial =
77653 - htonl(atomic_inc_return(&call->conn->serial));
77654 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77655
77656 hdr = (struct rxrpc_header *) txb->head;
77657 hdr->serial = sp->hdr.serial;
77658 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77659 */
77660 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77661 {
77662 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77663 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77664 }
77665
77666 /*
77667 @@ -629,7 +629,7 @@ process_further:
77668
77669 latest = ntohl(sp->hdr.serial);
77670 hard = ntohl(ack.firstPacket);
77671 - tx = atomic_read(&call->sequence);
77672 + tx = atomic_read_unchecked(&call->sequence);
77673
77674 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77675 latest,
77676 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77677 goto maybe_reschedule;
77678
77679 send_ACK_with_skew:
77680 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77681 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77682 ntohl(ack.serial));
77683 send_ACK:
77684 mtu = call->conn->trans->peer->if_mtu;
77685 @@ -1173,7 +1173,7 @@ send_ACK:
77686 ackinfo.rxMTU = htonl(5692);
77687 ackinfo.jumbo_max = htonl(4);
77688
77689 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77690 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77691 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77692 ntohl(hdr.serial),
77693 ntohs(ack.maxSkew),
77694 @@ -1191,7 +1191,7 @@ send_ACK:
77695 send_message:
77696 _debug("send message");
77697
77698 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77699 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77700 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77701 send_message_2:
77702
77703 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77704 index a3bbb36..3341fb9 100644
77705 --- a/net/rxrpc/ar-call.c
77706 +++ b/net/rxrpc/ar-call.c
77707 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77708 spin_lock_init(&call->lock);
77709 rwlock_init(&call->state_lock);
77710 atomic_set(&call->usage, 1);
77711 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77712 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77713 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77714
77715 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77716 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77717 index 4106ca9..a338d7a 100644
77718 --- a/net/rxrpc/ar-connection.c
77719 +++ b/net/rxrpc/ar-connection.c
77720 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77721 rwlock_init(&conn->lock);
77722 spin_lock_init(&conn->state_lock);
77723 atomic_set(&conn->usage, 1);
77724 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77725 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77726 conn->avail_calls = RXRPC_MAXCALLS;
77727 conn->size_align = 4;
77728 conn->header_size = sizeof(struct rxrpc_header);
77729 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77730 index e7ed43a..6afa140 100644
77731 --- a/net/rxrpc/ar-connevent.c
77732 +++ b/net/rxrpc/ar-connevent.c
77733 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77734
77735 len = iov[0].iov_len + iov[1].iov_len;
77736
77737 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77738 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77739 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77740
77741 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77742 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77743 index 529572f..c758ca7 100644
77744 --- a/net/rxrpc/ar-input.c
77745 +++ b/net/rxrpc/ar-input.c
77746 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77747 /* track the latest serial number on this connection for ACK packet
77748 * information */
77749 serial = ntohl(sp->hdr.serial);
77750 - hi_serial = atomic_read(&call->conn->hi_serial);
77751 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77752 while (serial > hi_serial)
77753 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77754 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77755 serial);
77756
77757 /* request ACK generation for any ACK or DATA packet that requests
77758 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77759 index a693aca..81e7293 100644
77760 --- a/net/rxrpc/ar-internal.h
77761 +++ b/net/rxrpc/ar-internal.h
77762 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77763 int error; /* error code for local abort */
77764 int debug_id; /* debug ID for printks */
77765 unsigned int call_counter; /* call ID counter */
77766 - atomic_t serial; /* packet serial number counter */
77767 - atomic_t hi_serial; /* highest serial number received */
77768 + atomic_unchecked_t serial; /* packet serial number counter */
77769 + atomic_unchecked_t hi_serial; /* highest serial number received */
77770 u8 avail_calls; /* number of calls available */
77771 u8 size_align; /* data size alignment (for security) */
77772 u8 header_size; /* rxrpc + security header size */
77773 @@ -346,7 +346,7 @@ struct rxrpc_call {
77774 spinlock_t lock;
77775 rwlock_t state_lock; /* lock for state transition */
77776 atomic_t usage;
77777 - atomic_t sequence; /* Tx data packet sequence counter */
77778 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77779 u32 abort_code; /* local/remote abort code */
77780 enum { /* current state of call */
77781 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77782 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77783 */
77784 extern atomic_t rxrpc_n_skbs;
77785 extern __be32 rxrpc_epoch;
77786 -extern atomic_t rxrpc_debug_id;
77787 +extern atomic_unchecked_t rxrpc_debug_id;
77788 extern struct workqueue_struct *rxrpc_workqueue;
77789
77790 /*
77791 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77792 index 87f7135..74d3703 100644
77793 --- a/net/rxrpc/ar-local.c
77794 +++ b/net/rxrpc/ar-local.c
77795 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77796 spin_lock_init(&local->lock);
77797 rwlock_init(&local->services_lock);
77798 atomic_set(&local->usage, 1);
77799 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77800 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77801 memcpy(&local->srx, srx, sizeof(*srx));
77802 }
77803
77804 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77805 index 16ae887..d24f12b 100644
77806 --- a/net/rxrpc/ar-output.c
77807 +++ b/net/rxrpc/ar-output.c
77808 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77809 sp->hdr.cid = call->cid;
77810 sp->hdr.callNumber = call->call_id;
77811 sp->hdr.seq =
77812 - htonl(atomic_inc_return(&call->sequence));
77813 + htonl(atomic_inc_return_unchecked(&call->sequence));
77814 sp->hdr.serial =
77815 - htonl(atomic_inc_return(&conn->serial));
77816 + htonl(atomic_inc_return_unchecked(&conn->serial));
77817 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77818 sp->hdr.userStatus = 0;
77819 sp->hdr.securityIndex = conn->security_ix;
77820 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77821 index bebaa43..2644591 100644
77822 --- a/net/rxrpc/ar-peer.c
77823 +++ b/net/rxrpc/ar-peer.c
77824 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77825 INIT_LIST_HEAD(&peer->error_targets);
77826 spin_lock_init(&peer->lock);
77827 atomic_set(&peer->usage, 1);
77828 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77829 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77830 memcpy(&peer->srx, srx, sizeof(*srx));
77831
77832 rxrpc_assess_MTU_size(peer);
77833 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77834 index 38047f7..9f48511 100644
77835 --- a/net/rxrpc/ar-proc.c
77836 +++ b/net/rxrpc/ar-proc.c
77837 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77838 atomic_read(&conn->usage),
77839 rxrpc_conn_states[conn->state],
77840 key_serial(conn->key),
77841 - atomic_read(&conn->serial),
77842 - atomic_read(&conn->hi_serial));
77843 + atomic_read_unchecked(&conn->serial),
77844 + atomic_read_unchecked(&conn->hi_serial));
77845
77846 return 0;
77847 }
77848 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77849 index 92df566..87ec1bf 100644
77850 --- a/net/rxrpc/ar-transport.c
77851 +++ b/net/rxrpc/ar-transport.c
77852 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77853 spin_lock_init(&trans->client_lock);
77854 rwlock_init(&trans->conn_lock);
77855 atomic_set(&trans->usage, 1);
77856 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77857 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77858
77859 if (peer->srx.transport.family == AF_INET) {
77860 switch (peer->srx.transport_type) {
77861 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77862 index f226709..0e735a8 100644
77863 --- a/net/rxrpc/rxkad.c
77864 +++ b/net/rxrpc/rxkad.c
77865 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77866
77867 len = iov[0].iov_len + iov[1].iov_len;
77868
77869 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77870 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77871 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77872
77873 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77874 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77875
77876 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77877
77878 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77879 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77880 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77881
77882 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77883 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77884 index 1e2eee8..ce3967e 100644
77885 --- a/net/sctp/proc.c
77886 +++ b/net/sctp/proc.c
77887 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77888 seq_printf(seq,
77889 "%8pK %8pK %-3d %-3d %-2d %-4d "
77890 "%4d %8d %8d %7d %5lu %-5d %5d ",
77891 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77892 + assoc, sk,
77893 + sctp_sk(sk)->type, sk->sk_state,
77894 assoc->state, hash,
77895 assoc->assoc_id,
77896 assoc->sndbuf_used,
77897 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77898 index 31c7bfc..bc380ae 100644
77899 --- a/net/sctp/socket.c
77900 +++ b/net/sctp/socket.c
77901 @@ -4577,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77902 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77903 if (space_left < addrlen)
77904 return -ENOMEM;
77905 - if (copy_to_user(to, &temp, addrlen))
77906 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77907 return -EFAULT;
77908 to += addrlen;
77909 cnt++;
77910 diff --git a/net/socket.c b/net/socket.c
77911 index 6e0ccc0..e3387a27 100644
77912 --- a/net/socket.c
77913 +++ b/net/socket.c
77914 @@ -88,6 +88,7 @@
77915 #include <linux/nsproxy.h>
77916 #include <linux/magic.h>
77917 #include <linux/slab.h>
77918 +#include <linux/in.h>
77919
77920 #include <asm/uaccess.h>
77921 #include <asm/unistd.h>
77922 @@ -105,6 +106,8 @@
77923 #include <linux/sockios.h>
77924 #include <linux/atalk.h>
77925
77926 +#include <linux/grsock.h>
77927 +
77928 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77929 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77930 unsigned long nr_segs, loff_t pos);
77931 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77932 &sockfs_dentry_operations, SOCKFS_MAGIC);
77933 }
77934
77935 -static struct vfsmount *sock_mnt __read_mostly;
77936 +struct vfsmount *sock_mnt __read_mostly;
77937
77938 static struct file_system_type sock_fs_type = {
77939 .name = "sockfs",
77940 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77941 return -EAFNOSUPPORT;
77942 if (type < 0 || type >= SOCK_MAX)
77943 return -EINVAL;
77944 + if (protocol < 0)
77945 + return -EINVAL;
77946
77947 /* Compatibility.
77948
77949 @@ -1338,6 +1343,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77950 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77951 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77952
77953 + if(!gr_search_socket(family, type, protocol)) {
77954 + retval = -EACCES;
77955 + goto out;
77956 + }
77957 +
77958 + if (gr_handle_sock_all(family, type, protocol)) {
77959 + retval = -EACCES;
77960 + goto out;
77961 + }
77962 +
77963 retval = sock_create(family, type, protocol, &sock);
77964 if (retval < 0)
77965 goto out;
77966 @@ -1450,6 +1465,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77967 if (sock) {
77968 err = move_addr_to_kernel(umyaddr, addrlen, &address);
77969 if (err >= 0) {
77970 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77971 + err = -EACCES;
77972 + goto error;
77973 + }
77974 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77975 + if (err)
77976 + goto error;
77977 +
77978 err = security_socket_bind(sock,
77979 (struct sockaddr *)&address,
77980 addrlen);
77981 @@ -1458,6 +1481,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77982 (struct sockaddr *)
77983 &address, addrlen);
77984 }
77985 +error:
77986 fput_light(sock->file, fput_needed);
77987 }
77988 return err;
77989 @@ -1481,10 +1505,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77990 if ((unsigned int)backlog > somaxconn)
77991 backlog = somaxconn;
77992
77993 + if (gr_handle_sock_server_other(sock->sk)) {
77994 + err = -EPERM;
77995 + goto error;
77996 + }
77997 +
77998 + err = gr_search_listen(sock);
77999 + if (err)
78000 + goto error;
78001 +
78002 err = security_socket_listen(sock, backlog);
78003 if (!err)
78004 err = sock->ops->listen(sock, backlog);
78005
78006 +error:
78007 fput_light(sock->file, fput_needed);
78008 }
78009 return err;
78010 @@ -1528,6 +1562,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78011 newsock->type = sock->type;
78012 newsock->ops = sock->ops;
78013
78014 + if (gr_handle_sock_server_other(sock->sk)) {
78015 + err = -EPERM;
78016 + sock_release(newsock);
78017 + goto out_put;
78018 + }
78019 +
78020 + err = gr_search_accept(sock);
78021 + if (err) {
78022 + sock_release(newsock);
78023 + goto out_put;
78024 + }
78025 +
78026 /*
78027 * We don't need try_module_get here, as the listening socket (sock)
78028 * has the protocol module (sock->ops->owner) held.
78029 @@ -1566,6 +1612,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78030 fd_install(newfd, newfile);
78031 err = newfd;
78032
78033 + gr_attach_curr_ip(newsock->sk);
78034 +
78035 out_put:
78036 fput_light(sock->file, fput_needed);
78037 out:
78038 @@ -1598,6 +1646,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78039 int, addrlen)
78040 {
78041 struct socket *sock;
78042 + struct sockaddr *sck;
78043 struct sockaddr_storage address;
78044 int err, fput_needed;
78045
78046 @@ -1608,6 +1657,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78047 if (err < 0)
78048 goto out_put;
78049
78050 + sck = (struct sockaddr *)&address;
78051 +
78052 + if (gr_handle_sock_client(sck)) {
78053 + err = -EACCES;
78054 + goto out_put;
78055 + }
78056 +
78057 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78058 + if (err)
78059 + goto out_put;
78060 +
78061 err =
78062 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78063 if (err)
78064 @@ -1962,7 +2022,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78065 * checking falls down on this.
78066 */
78067 if (copy_from_user(ctl_buf,
78068 - (void __user __force *)msg_sys->msg_control,
78069 + (void __force_user *)msg_sys->msg_control,
78070 ctl_len))
78071 goto out_freectl;
78072 msg_sys->msg_control = ctl_buf;
78073 @@ -2130,7 +2190,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78074 * kernel msghdr to use the kernel address space)
78075 */
78076
78077 - uaddr = (__force void __user *)msg_sys->msg_name;
78078 + uaddr = (void __force_user *)msg_sys->msg_name;
78079 uaddr_len = COMPAT_NAMELEN(msg);
78080 if (MSG_CMSG_COMPAT & flags) {
78081 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
78082 @@ -2758,7 +2818,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78083 }
78084
78085 ifr = compat_alloc_user_space(buf_size);
78086 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78087 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78088
78089 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78090 return -EFAULT;
78091 @@ -2782,12 +2842,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78092 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78093
78094 if (copy_in_user(rxnfc, compat_rxnfc,
78095 - (void *)(&rxnfc->fs.m_ext + 1) -
78096 - (void *)rxnfc) ||
78097 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78098 + (void __user *)rxnfc) ||
78099 copy_in_user(&rxnfc->fs.ring_cookie,
78100 &compat_rxnfc->fs.ring_cookie,
78101 - (void *)(&rxnfc->fs.location + 1) -
78102 - (void *)&rxnfc->fs.ring_cookie) ||
78103 + (void __user *)(&rxnfc->fs.location + 1) -
78104 + (void __user *)&rxnfc->fs.ring_cookie) ||
78105 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78106 sizeof(rxnfc->rule_cnt)))
78107 return -EFAULT;
78108 @@ -2799,12 +2859,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78109
78110 if (convert_out) {
78111 if (copy_in_user(compat_rxnfc, rxnfc,
78112 - (const void *)(&rxnfc->fs.m_ext + 1) -
78113 - (const void *)rxnfc) ||
78114 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78115 + (const void __user *)rxnfc) ||
78116 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78117 &rxnfc->fs.ring_cookie,
78118 - (const void *)(&rxnfc->fs.location + 1) -
78119 - (const void *)&rxnfc->fs.ring_cookie) ||
78120 + (const void __user *)(&rxnfc->fs.location + 1) -
78121 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78122 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78123 sizeof(rxnfc->rule_cnt)))
78124 return -EFAULT;
78125 @@ -2874,7 +2934,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78126 old_fs = get_fs();
78127 set_fs(KERNEL_DS);
78128 err = dev_ioctl(net, cmd,
78129 - (struct ifreq __user __force *) &kifr);
78130 + (struct ifreq __force_user *) &kifr);
78131 set_fs(old_fs);
78132
78133 return err;
78134 @@ -2983,7 +3043,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78135
78136 old_fs = get_fs();
78137 set_fs(KERNEL_DS);
78138 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78139 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78140 set_fs(old_fs);
78141
78142 if (cmd == SIOCGIFMAP && !err) {
78143 @@ -3088,7 +3148,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78144 ret |= __get_user(rtdev, &(ur4->rt_dev));
78145 if (rtdev) {
78146 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78147 - r4.rt_dev = (char __user __force *)devname;
78148 + r4.rt_dev = (char __force_user *)devname;
78149 devname[15] = 0;
78150 } else
78151 r4.rt_dev = NULL;
78152 @@ -3314,8 +3374,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78153 int __user *uoptlen;
78154 int err;
78155
78156 - uoptval = (char __user __force *) optval;
78157 - uoptlen = (int __user __force *) optlen;
78158 + uoptval = (char __force_user *) optval;
78159 + uoptlen = (int __force_user *) optlen;
78160
78161 set_fs(KERNEL_DS);
78162 if (level == SOL_SOCKET)
78163 @@ -3335,7 +3395,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78164 char __user *uoptval;
78165 int err;
78166
78167 - uoptval = (char __user __force *) optval;
78168 + uoptval = (char __force_user *) optval;
78169
78170 set_fs(KERNEL_DS);
78171 if (level == SOL_SOCKET)
78172 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78173 index 994cfea..5343b6b 100644
78174 --- a/net/sunrpc/sched.c
78175 +++ b/net/sunrpc/sched.c
78176 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
78177 #ifdef RPC_DEBUG
78178 static void rpc_task_set_debuginfo(struct rpc_task *task)
78179 {
78180 - static atomic_t rpc_pid;
78181 + static atomic_unchecked_t rpc_pid;
78182
78183 - task->tk_pid = atomic_inc_return(&rpc_pid);
78184 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78185 }
78186 #else
78187 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78188 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78189 index 8343737..677025e 100644
78190 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78191 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78192 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78193 static unsigned int min_max_inline = 4096;
78194 static unsigned int max_max_inline = 65536;
78195
78196 -atomic_t rdma_stat_recv;
78197 -atomic_t rdma_stat_read;
78198 -atomic_t rdma_stat_write;
78199 -atomic_t rdma_stat_sq_starve;
78200 -atomic_t rdma_stat_rq_starve;
78201 -atomic_t rdma_stat_rq_poll;
78202 -atomic_t rdma_stat_rq_prod;
78203 -atomic_t rdma_stat_sq_poll;
78204 -atomic_t rdma_stat_sq_prod;
78205 +atomic_unchecked_t rdma_stat_recv;
78206 +atomic_unchecked_t rdma_stat_read;
78207 +atomic_unchecked_t rdma_stat_write;
78208 +atomic_unchecked_t rdma_stat_sq_starve;
78209 +atomic_unchecked_t rdma_stat_rq_starve;
78210 +atomic_unchecked_t rdma_stat_rq_poll;
78211 +atomic_unchecked_t rdma_stat_rq_prod;
78212 +atomic_unchecked_t rdma_stat_sq_poll;
78213 +atomic_unchecked_t rdma_stat_sq_prod;
78214
78215 /* Temporary NFS request map and context caches */
78216 struct kmem_cache *svc_rdma_map_cachep;
78217 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
78218 len -= *ppos;
78219 if (len > *lenp)
78220 len = *lenp;
78221 - if (len && copy_to_user(buffer, str_buf, len))
78222 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78223 return -EFAULT;
78224 *lenp = len;
78225 *ppos += len;
78226 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
78227 {
78228 .procname = "rdma_stat_read",
78229 .data = &rdma_stat_read,
78230 - .maxlen = sizeof(atomic_t),
78231 + .maxlen = sizeof(atomic_unchecked_t),
78232 .mode = 0644,
78233 .proc_handler = read_reset_stat,
78234 },
78235 {
78236 .procname = "rdma_stat_recv",
78237 .data = &rdma_stat_recv,
78238 - .maxlen = sizeof(atomic_t),
78239 + .maxlen = sizeof(atomic_unchecked_t),
78240 .mode = 0644,
78241 .proc_handler = read_reset_stat,
78242 },
78243 {
78244 .procname = "rdma_stat_write",
78245 .data = &rdma_stat_write,
78246 - .maxlen = sizeof(atomic_t),
78247 + .maxlen = sizeof(atomic_unchecked_t),
78248 .mode = 0644,
78249 .proc_handler = read_reset_stat,
78250 },
78251 {
78252 .procname = "rdma_stat_sq_starve",
78253 .data = &rdma_stat_sq_starve,
78254 - .maxlen = sizeof(atomic_t),
78255 + .maxlen = sizeof(atomic_unchecked_t),
78256 .mode = 0644,
78257 .proc_handler = read_reset_stat,
78258 },
78259 {
78260 .procname = "rdma_stat_rq_starve",
78261 .data = &rdma_stat_rq_starve,
78262 - .maxlen = sizeof(atomic_t),
78263 + .maxlen = sizeof(atomic_unchecked_t),
78264 .mode = 0644,
78265 .proc_handler = read_reset_stat,
78266 },
78267 {
78268 .procname = "rdma_stat_rq_poll",
78269 .data = &rdma_stat_rq_poll,
78270 - .maxlen = sizeof(atomic_t),
78271 + .maxlen = sizeof(atomic_unchecked_t),
78272 .mode = 0644,
78273 .proc_handler = read_reset_stat,
78274 },
78275 {
78276 .procname = "rdma_stat_rq_prod",
78277 .data = &rdma_stat_rq_prod,
78278 - .maxlen = sizeof(atomic_t),
78279 + .maxlen = sizeof(atomic_unchecked_t),
78280 .mode = 0644,
78281 .proc_handler = read_reset_stat,
78282 },
78283 {
78284 .procname = "rdma_stat_sq_poll",
78285 .data = &rdma_stat_sq_poll,
78286 - .maxlen = sizeof(atomic_t),
78287 + .maxlen = sizeof(atomic_unchecked_t),
78288 .mode = 0644,
78289 .proc_handler = read_reset_stat,
78290 },
78291 {
78292 .procname = "rdma_stat_sq_prod",
78293 .data = &rdma_stat_sq_prod,
78294 - .maxlen = sizeof(atomic_t),
78295 + .maxlen = sizeof(atomic_unchecked_t),
78296 .mode = 0644,
78297 .proc_handler = read_reset_stat,
78298 },
78299 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78300 index 41cb63b..c4a1489 100644
78301 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78302 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78303 @@ -501,7 +501,7 @@ next_sge:
78304 svc_rdma_put_context(ctxt, 0);
78305 goto out;
78306 }
78307 - atomic_inc(&rdma_stat_read);
78308 + atomic_inc_unchecked(&rdma_stat_read);
78309
78310 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78311 chl_map->ch[ch_no].count -= read_wr.num_sge;
78312 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78313 dto_q);
78314 list_del_init(&ctxt->dto_q);
78315 } else {
78316 - atomic_inc(&rdma_stat_rq_starve);
78317 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78318 clear_bit(XPT_DATA, &xprt->xpt_flags);
78319 ctxt = NULL;
78320 }
78321 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78322 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78323 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78324 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78325 - atomic_inc(&rdma_stat_recv);
78326 + atomic_inc_unchecked(&rdma_stat_recv);
78327
78328 /* Build up the XDR from the receive buffers. */
78329 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78330 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78331 index 42eb7ba..c887c45 100644
78332 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78333 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78334 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78335 write_wr.wr.rdma.remote_addr = to;
78336
78337 /* Post It */
78338 - atomic_inc(&rdma_stat_write);
78339 + atomic_inc_unchecked(&rdma_stat_write);
78340 if (svc_rdma_send(xprt, &write_wr))
78341 goto err;
78342 return 0;
78343 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78344 index 73b428b..5f3f8f3 100644
78345 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78346 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78347 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78348 return;
78349
78350 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78351 - atomic_inc(&rdma_stat_rq_poll);
78352 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78353
78354 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78355 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78356 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78357 }
78358
78359 if (ctxt)
78360 - atomic_inc(&rdma_stat_rq_prod);
78361 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78362
78363 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78364 /*
78365 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78366 return;
78367
78368 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78369 - atomic_inc(&rdma_stat_sq_poll);
78370 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78371 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78372 if (wc.status != IB_WC_SUCCESS)
78373 /* Close the transport */
78374 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78375 }
78376
78377 if (ctxt)
78378 - atomic_inc(&rdma_stat_sq_prod);
78379 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78380 }
78381
78382 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78383 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78384 spin_lock_bh(&xprt->sc_lock);
78385 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78386 spin_unlock_bh(&xprt->sc_lock);
78387 - atomic_inc(&rdma_stat_sq_starve);
78388 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78389
78390 /* See if we can opportunistically reap SQ WR to make room */
78391 sq_cq_reap(xprt);
78392 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78393 index e3a6e37..be2ea77 100644
78394 --- a/net/sysctl_net.c
78395 +++ b/net/sysctl_net.c
78396 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78397 struct ctl_table *table)
78398 {
78399 /* Allow network administrator to have same access as root. */
78400 - if (capable(CAP_NET_ADMIN)) {
78401 + if (capable_nolog(CAP_NET_ADMIN)) {
78402 int mode = (table->mode >> 6) & 7;
78403 return (mode << 6) | (mode << 3) | mode;
78404 }
78405 diff --git a/net/tipc/link.c b/net/tipc/link.c
78406 index 7a614f4..b14dbd2 100644
78407 --- a/net/tipc/link.c
78408 +++ b/net/tipc/link.c
78409 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78410 struct tipc_msg fragm_hdr;
78411 struct sk_buff *buf, *buf_chain, *prev;
78412 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78413 - const unchar *sect_crs;
78414 + const unchar __user *sect_crs;
78415 int curr_sect;
78416 u32 fragm_no;
78417
78418 @@ -1205,7 +1205,7 @@ again:
78419
78420 if (!sect_rest) {
78421 sect_rest = msg_sect[++curr_sect].iov_len;
78422 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78423 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78424 }
78425
78426 if (sect_rest < fragm_rest)
78427 @@ -1224,7 +1224,7 @@ error:
78428 }
78429 } else
78430 skb_copy_to_linear_data_offset(buf, fragm_crs,
78431 - sect_crs, sz);
78432 + (const void __force_kernel *)sect_crs, sz);
78433 sect_crs += sz;
78434 sect_rest -= sz;
78435 fragm_crs += sz;
78436 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78437 index deea0d2..fa13bd7 100644
78438 --- a/net/tipc/msg.c
78439 +++ b/net/tipc/msg.c
78440 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78441 msg_sect[cnt].iov_len);
78442 else
78443 skb_copy_to_linear_data_offset(*buf, pos,
78444 - msg_sect[cnt].iov_base,
78445 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78446 msg_sect[cnt].iov_len);
78447 pos += msg_sect[cnt].iov_len;
78448 }
78449 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78450 index f976e9cd..560d055 100644
78451 --- a/net/tipc/subscr.c
78452 +++ b/net/tipc/subscr.c
78453 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78454 {
78455 struct iovec msg_sect;
78456
78457 - msg_sect.iov_base = (void *)&sub->evt;
78458 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78459 msg_sect.iov_len = sizeof(struct tipc_event);
78460
78461 sub->evt.event = htohl(event, sub->swap);
78462 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78463 index 641f2e4..a63f5e1 100644
78464 --- a/net/unix/af_unix.c
78465 +++ b/net/unix/af_unix.c
78466 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
78467 err = -ECONNREFUSED;
78468 if (!S_ISSOCK(inode->i_mode))
78469 goto put_fail;
78470 +
78471 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78472 + err = -EACCES;
78473 + goto put_fail;
78474 + }
78475 +
78476 u = unix_find_socket_byinode(inode);
78477 if (!u)
78478 goto put_fail;
78479 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
78480 if (u) {
78481 struct dentry *dentry;
78482 dentry = unix_sk(u)->path.dentry;
78483 +
78484 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78485 + err = -EPERM;
78486 + sock_put(u);
78487 + goto fail;
78488 + }
78489 +
78490 if (dentry)
78491 touch_atime(&unix_sk(u)->path);
78492 } else
78493 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78494 err = security_path_mknod(&path, dentry, mode, 0);
78495 if (err)
78496 goto out_mknod_drop_write;
78497 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78498 + err = -EACCES;
78499 + goto out_mknod_drop_write;
78500 + }
78501 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78502 out_mknod_drop_write:
78503 mnt_drop_write(path.mnt);
78504 if (err)
78505 goto out_mknod_dput;
78506 +
78507 + gr_handle_create(dentry, path.mnt);
78508 +
78509 mutex_unlock(&path.dentry->d_inode->i_mutex);
78510 dput(path.dentry);
78511 path.dentry = dentry;
78512 diff --git a/net/wireless/core.h b/net/wireless/core.h
78513 index 8523f38..79f6091 100644
78514 --- a/net/wireless/core.h
78515 +++ b/net/wireless/core.h
78516 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78517 struct mutex mtx;
78518
78519 /* rfkill support */
78520 - struct rfkill_ops rfkill_ops;
78521 + rfkill_ops_no_const rfkill_ops;
78522 struct rfkill *rfkill;
78523 struct work_struct rfkill_sync;
78524
78525 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78526 index b0eb7aa..7d73e82 100644
78527 --- a/net/wireless/wext-core.c
78528 +++ b/net/wireless/wext-core.c
78529 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78530 */
78531
78532 /* Support for very large requests */
78533 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78534 - (user_length > descr->max_tokens)) {
78535 + if (user_length > descr->max_tokens) {
78536 /* Allow userspace to GET more than max so
78537 * we can support any size GET requests.
78538 * There is still a limit : -ENOMEM.
78539 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78540 }
78541 }
78542
78543 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78544 - /*
78545 - * If this is a GET, but not NOMAX, it means that the extra
78546 - * data is not bounded by userspace, but by max_tokens. Thus
78547 - * set the length to max_tokens. This matches the extra data
78548 - * allocation.
78549 - * The driver should fill it with the number of tokens it
78550 - * provided, and it may check iwp->length rather than having
78551 - * knowledge of max_tokens. If the driver doesn't change the
78552 - * iwp->length, this ioctl just copies back max_token tokens
78553 - * filled with zeroes. Hopefully the driver isn't claiming
78554 - * them to be valid data.
78555 - */
78556 - iwp->length = descr->max_tokens;
78557 - }
78558 -
78559 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78560
78561 iwp->length += essid_compat;
78562 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78563 index ccfbd32..9b61cf9f 100644
78564 --- a/net/xfrm/xfrm_policy.c
78565 +++ b/net/xfrm/xfrm_policy.c
78566 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78567 {
78568 policy->walk.dead = 1;
78569
78570 - atomic_inc(&policy->genid);
78571 + atomic_inc_unchecked(&policy->genid);
78572
78573 if (del_timer(&policy->timer))
78574 xfrm_pol_put(policy);
78575 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78576 hlist_add_head(&policy->bydst, chain);
78577 xfrm_pol_hold(policy);
78578 net->xfrm.policy_count[dir]++;
78579 - atomic_inc(&flow_cache_genid);
78580 + atomic_inc_unchecked(&flow_cache_genid);
78581 if (delpol)
78582 __xfrm_policy_unlink(delpol, dir);
78583 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78584 @@ -1532,7 +1532,7 @@ free_dst:
78585 goto out;
78586 }
78587
78588 -static int inline
78589 +static inline int
78590 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78591 {
78592 if (!*target) {
78593 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78594 return 0;
78595 }
78596
78597 -static int inline
78598 +static inline int
78599 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78600 {
78601 #ifdef CONFIG_XFRM_SUB_POLICY
78602 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78603 #endif
78604 }
78605
78606 -static int inline
78607 +static inline int
78608 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78609 {
78610 #ifdef CONFIG_XFRM_SUB_POLICY
78611 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78612
78613 xdst->num_pols = num_pols;
78614 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78615 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78616 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78617
78618 return xdst;
78619 }
78620 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78621 if (xdst->xfrm_genid != dst->xfrm->genid)
78622 return 0;
78623 if (xdst->num_pols > 0 &&
78624 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78625 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78626 return 0;
78627
78628 mtu = dst_mtu(dst->child);
78629 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78630 sizeof(pol->xfrm_vec[i].saddr));
78631 pol->xfrm_vec[i].encap_family = mp->new_family;
78632 /* flush bundles */
78633 - atomic_inc(&pol->genid);
78634 + atomic_inc_unchecked(&pol->genid);
78635 }
78636 }
78637
78638 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78639 index ff1720d..ed8475e 100644
78640 --- a/scripts/Makefile.build
78641 +++ b/scripts/Makefile.build
78642 @@ -111,7 +111,7 @@ endif
78643 endif
78644
78645 # Do not include host rules unless needed
78646 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78647 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
78648 include scripts/Makefile.host
78649 endif
78650
78651 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78652 index 686cb0d..9d653bf 100644
78653 --- a/scripts/Makefile.clean
78654 +++ b/scripts/Makefile.clean
78655 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78656 __clean-files := $(extra-y) $(always) \
78657 $(targets) $(clean-files) \
78658 $(host-progs) \
78659 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78660 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78661 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78662
78663 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78664
78665 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78666 index 1ac414f..38575f7 100644
78667 --- a/scripts/Makefile.host
78668 +++ b/scripts/Makefile.host
78669 @@ -31,6 +31,8 @@
78670 # Note: Shared libraries consisting of C++ files are not supported
78671
78672 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78673 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78674 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
78675
78676 # C code
78677 # Executables compiled from a single .c file
78678 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78679 # Shared libaries (only .c supported)
78680 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78681 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78682 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78683 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
78684 # Remove .so files from "xxx-objs"
78685 host-cobjs := $(filter-out %.so,$(host-cobjs))
78686 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
78687
78688 -#Object (.o) files used by the shared libaries
78689 +# Object (.o) files used by the shared libaries
78690 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
78691 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
78692
78693 # output directory for programs/.o files
78694 # hostprogs-y := tools/build may have been specified. Retrieve directory
78695 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
78696 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
78697 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
78698 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
78699 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
78700 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
78701 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
78702 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
78703
78704 obj-dirs += $(host-objdirs)
78705 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
78706 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
78707 $(call if_changed_dep,host-cshobjs)
78708
78709 +# Compile .c file, create position independent .o file
78710 +# host-cxxshobjs -> .o
78711 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
78712 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
78713 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
78714 + $(call if_changed_dep,host-cxxshobjs)
78715 +
78716 # Link a shared library, based on position independent .o files
78717 # *.o -> .so shared library (host-cshlib)
78718 quiet_cmd_host-cshlib = HOSTLLD -shared $@
78719 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
78720 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
78721 $(call if_changed,host-cshlib)
78722
78723 +# Link a shared library, based on position independent .o files
78724 +# *.o -> .so shared library (host-cxxshlib)
78725 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
78726 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
78727 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
78728 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
78729 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
78730 + $(call if_changed,host-cxxshlib)
78731 +
78732 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
78733 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
78734 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
78735
78736 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78737 index cb1f50c..cef2a7c 100644
78738 --- a/scripts/basic/fixdep.c
78739 +++ b/scripts/basic/fixdep.c
78740 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78741 /*
78742 * Lookup a value in the configuration string.
78743 */
78744 -static int is_defined_config(const char *name, int len, unsigned int hash)
78745 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78746 {
78747 struct item *aux;
78748
78749 @@ -211,10 +211,10 @@ static void clear_config(void)
78750 /*
78751 * Record the use of a CONFIG_* word.
78752 */
78753 -static void use_config(const char *m, int slen)
78754 +static void use_config(const char *m, unsigned int slen)
78755 {
78756 unsigned int hash = strhash(m, slen);
78757 - int c, i;
78758 + unsigned int c, i;
78759
78760 if (is_defined_config(m, slen, hash))
78761 return;
78762 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78763
78764 static void parse_config_file(const char *map, size_t len)
78765 {
78766 - const int *end = (const int *) (map + len);
78767 + const unsigned int *end = (const unsigned int *) (map + len);
78768 /* start at +1, so that p can never be < map */
78769 - const int *m = (const int *) map + 1;
78770 + const unsigned int *m = (const unsigned int *) map + 1;
78771 const char *p, *q;
78772
78773 for (; m < end; m++) {
78774 @@ -406,7 +406,7 @@ static void print_deps(void)
78775 static void traps(void)
78776 {
78777 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78778 - int *p = (int *)test;
78779 + unsigned int *p = (unsigned int *)test;
78780
78781 if (*p != INT_CONF) {
78782 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78783 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78784 new file mode 100644
78785 index 0000000..008ac1a
78786 --- /dev/null
78787 +++ b/scripts/gcc-plugin.sh
78788 @@ -0,0 +1,17 @@
78789 +#!/bin/bash
78790 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
78791 +#include "gcc-plugin.h"
78792 +#include "tree.h"
78793 +#include "tm.h"
78794 +#include "rtl.h"
78795 +#ifdef ENABLE_BUILD_WITH_CXX
78796 +#warning $2
78797 +#else
78798 +#warning $1
78799 +#endif
78800 +EOF`
78801 +if [ $? -eq 0 ]
78802 +then
78803 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
78804 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
78805 +fi
78806 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78807 index 5759751..b170367 100644
78808 --- a/scripts/mod/file2alias.c
78809 +++ b/scripts/mod/file2alias.c
78810 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78811 unsigned long size, unsigned long id_size,
78812 void *symval)
78813 {
78814 - int i;
78815 + unsigned int i;
78816
78817 if (size % id_size || size < id_size) {
78818 if (cross_build != 0)
78819 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78820 /* USB is special because the bcdDevice can be matched against a numeric range */
78821 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78822 static void do_usb_entry(struct usb_device_id *id,
78823 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78824 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78825 unsigned char range_lo, unsigned char range_hi,
78826 unsigned char max, struct module *mod)
78827 {
78828 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78829 {
78830 unsigned int devlo, devhi;
78831 unsigned char chi, clo, max;
78832 - int ndigits;
78833 + unsigned int ndigits;
78834
78835 id->match_flags = TO_NATIVE(id->match_flags);
78836 id->idVendor = TO_NATIVE(id->idVendor);
78837 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78838 for (i = 0; i < count; i++) {
78839 const char *id = (char *)devs[i].id;
78840 char acpi_id[sizeof(devs[0].id)];
78841 - int j;
78842 + unsigned int j;
78843
78844 buf_printf(&mod->dev_table_buf,
78845 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78846 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78847
78848 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78849 const char *id = (char *)card->devs[j].id;
78850 - int i2, j2;
78851 + unsigned int i2, j2;
78852 int dup = 0;
78853
78854 if (!id[0])
78855 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78856 /* add an individual alias for every device entry */
78857 if (!dup) {
78858 char acpi_id[sizeof(card->devs[0].id)];
78859 - int k;
78860 + unsigned int k;
78861
78862 buf_printf(&mod->dev_table_buf,
78863 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78864 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78865 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78866 char *alias)
78867 {
78868 - int i, j;
78869 + unsigned int i, j;
78870
78871 sprintf(alias, "dmi*");
78872
78873 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78874 index 0f84bb3..2d42035 100644
78875 --- a/scripts/mod/modpost.c
78876 +++ b/scripts/mod/modpost.c
78877 @@ -925,6 +925,7 @@ enum mismatch {
78878 ANY_INIT_TO_ANY_EXIT,
78879 ANY_EXIT_TO_ANY_INIT,
78880 EXPORT_TO_INIT_EXIT,
78881 + DATA_TO_TEXT
78882 };
78883
78884 struct sectioncheck {
78885 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
78886 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78887 .mismatch = EXPORT_TO_INIT_EXIT,
78888 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78889 +},
78890 +/* Do not reference code from writable data */
78891 +{
78892 + .fromsec = { DATA_SECTIONS, NULL },
78893 + .tosec = { TEXT_SECTIONS, NULL },
78894 + .mismatch = DATA_TO_TEXT
78895 }
78896 };
78897
78898 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78899 continue;
78900 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78901 continue;
78902 - if (sym->st_value == addr)
78903 - return sym;
78904 /* Find a symbol nearby - addr are maybe negative */
78905 d = sym->st_value - addr;
78906 + if (d == 0)
78907 + return sym;
78908 if (d < 0)
78909 d = addr - sym->st_value;
78910 if (d < distance) {
78911 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
78912 tosym, prl_to, prl_to, tosym);
78913 free(prl_to);
78914 break;
78915 + case DATA_TO_TEXT:
78916 +#if 0
78917 + fprintf(stderr,
78918 + "The %s %s:%s references\n"
78919 + "the %s %s:%s%s\n",
78920 + from, fromsec, fromsym, to, tosec, tosym, to_p);
78921 +#endif
78922 + break;
78923 }
78924 fprintf(stderr, "\n");
78925 }
78926 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78927 static void check_sec_ref(struct module *mod, const char *modname,
78928 struct elf_info *elf)
78929 {
78930 - int i;
78931 + unsigned int i;
78932 Elf_Shdr *sechdrs = elf->sechdrs;
78933
78934 /* Walk through all sections */
78935 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78936 va_end(ap);
78937 }
78938
78939 -void buf_write(struct buffer *buf, const char *s, int len)
78940 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78941 {
78942 if (buf->size - buf->pos < len) {
78943 buf->size += len + SZ;
78944 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78945 if (fstat(fileno(file), &st) < 0)
78946 goto close_write;
78947
78948 - if (st.st_size != b->pos)
78949 + if (st.st_size != (off_t)b->pos)
78950 goto close_write;
78951
78952 tmp = NOFAIL(malloc(b->pos));
78953 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78954 index 51207e4..f7d603d 100644
78955 --- a/scripts/mod/modpost.h
78956 +++ b/scripts/mod/modpost.h
78957 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78958
78959 struct buffer {
78960 char *p;
78961 - int pos;
78962 - int size;
78963 + unsigned int pos;
78964 + unsigned int size;
78965 };
78966
78967 void __attribute__((format(printf, 2, 3)))
78968 buf_printf(struct buffer *buf, const char *fmt, ...);
78969
78970 void
78971 -buf_write(struct buffer *buf, const char *s, int len);
78972 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78973
78974 struct module {
78975 struct module *next;
78976 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78977 index 9dfcd6d..099068e 100644
78978 --- a/scripts/mod/sumversion.c
78979 +++ b/scripts/mod/sumversion.c
78980 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78981 goto out;
78982 }
78983
78984 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78985 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78986 warn("writing sum in %s failed: %s\n",
78987 filename, strerror(errno));
78988 goto out;
78989 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78990 index 5c11312..72742b5 100644
78991 --- a/scripts/pnmtologo.c
78992 +++ b/scripts/pnmtologo.c
78993 @@ -237,14 +237,14 @@ static void write_header(void)
78994 fprintf(out, " * Linux logo %s\n", logoname);
78995 fputs(" */\n\n", out);
78996 fputs("#include <linux/linux_logo.h>\n\n", out);
78997 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78998 + fprintf(out, "static unsigned char %s_data[] = {\n",
78999 logoname);
79000 }
79001
79002 static void write_footer(void)
79003 {
79004 fputs("\n};\n\n", out);
79005 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79006 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79007 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79008 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79009 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79010 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79011 fputs("\n};\n\n", out);
79012
79013 /* write logo clut */
79014 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79015 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79016 logoname);
79017 write_hex_cnt = 0;
79018 for (i = 0; i < logo_clutsize; i++) {
79019 diff --git a/security/Kconfig b/security/Kconfig
79020 index e9c6ac7..4349785 100644
79021 --- a/security/Kconfig
79022 +++ b/security/Kconfig
79023 @@ -4,6 +4,876 @@
79024
79025 menu "Security options"
79026
79027 +menu "Grsecurity"
79028 +
79029 + config ARCH_TRACK_EXEC_LIMIT
79030 + bool
79031 +
79032 + config PAX_KERNEXEC_PLUGIN
79033 + bool
79034 +
79035 + config PAX_PER_CPU_PGD
79036 + bool
79037 +
79038 + config TASK_SIZE_MAX_SHIFT
79039 + int
79040 + depends on X86_64
79041 + default 47 if !PAX_PER_CPU_PGD
79042 + default 42 if PAX_PER_CPU_PGD
79043 +
79044 + config PAX_ENABLE_PAE
79045 + bool
79046 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79047 +
79048 + config PAX_USERCOPY_SLABS
79049 + bool
79050 +
79051 +config GRKERNSEC
79052 + bool "Grsecurity"
79053 + select CRYPTO
79054 + select CRYPTO_SHA256
79055 + select PROC_FS
79056 + select STOP_MACHINE
79057 + help
79058 + If you say Y here, you will be able to configure many features
79059 + that will enhance the security of your system. It is highly
79060 + recommended that you say Y here and read through the help
79061 + for each option so that you fully understand the features and
79062 + can evaluate their usefulness for your machine.
79063 +
79064 +choice
79065 + prompt "Configuration Method"
79066 + depends on GRKERNSEC
79067 + default GRKERNSEC_CONFIG_CUSTOM
79068 + help
79069 +
79070 +config GRKERNSEC_CONFIG_AUTO
79071 + bool "Automatic"
79072 + help
79073 + If you choose this configuration method, you'll be able to answer a small
79074 + number of simple questions about how you plan to use this kernel.
79075 + The settings of grsecurity and PaX will be automatically configured for
79076 + the highest commonly-used settings within the provided constraints.
79077 +
79078 + If you require additional configuration, custom changes can still be made
79079 + from the "custom configuration" menu.
79080 +
79081 +config GRKERNSEC_CONFIG_CUSTOM
79082 + bool "Custom"
79083 + help
79084 + If you choose this configuration method, you'll be able to configure all
79085 + grsecurity and PaX settings manually. Via this method, no options are
79086 + automatically enabled.
79087 +
79088 +endchoice
79089 +
79090 +choice
79091 + prompt "Usage Type"
79092 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79093 + default GRKERNSEC_CONFIG_SERVER
79094 + help
79095 +
79096 +config GRKERNSEC_CONFIG_SERVER
79097 + bool "Server"
79098 + help
79099 + Choose this option if you plan to use this kernel on a server.
79100 +
79101 +config GRKERNSEC_CONFIG_DESKTOP
79102 + bool "Desktop"
79103 + help
79104 + Choose this option if you plan to use this kernel on a desktop.
79105 +
79106 +endchoice
79107 +
79108 +choice
79109 + prompt "Virtualization Type"
79110 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
79111 + default GRKERNSEC_CONFIG_VIRT_NONE
79112 + help
79113 +
79114 +config GRKERNSEC_CONFIG_VIRT_NONE
79115 + bool "None"
79116 + help
79117 + Choose this option if this kernel will be run on bare metal.
79118 +
79119 +config GRKERNSEC_CONFIG_VIRT_GUEST
79120 + bool "Guest"
79121 + help
79122 + Choose this option if this kernel will be run as a VM guest.
79123 +
79124 +config GRKERNSEC_CONFIG_VIRT_HOST
79125 + bool "Host"
79126 + help
79127 + Choose this option if this kernel will be run as a VM host.
79128 +
79129 +endchoice
79130 +
79131 +choice
79132 + prompt "Virtualization Hardware"
79133 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79134 + help
79135 +
79136 +config GRKERNSEC_CONFIG_VIRT_EPT
79137 + bool "EPT/RVI Processor Support"
79138 + depends on X86
79139 + help
79140 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
79141 + hardware virtualization. This allows for additional kernel hardening protections
79142 + to operate without additional performance impact.
79143 +
79144 + To see if your Intel processor supports EPT, see:
79145 + http://ark.intel.com/Products/VirtualizationTechnology
79146 + (Most Core i3/5/7 support EPT)
79147 +
79148 + To see if your AMD processor supports RVI, see:
79149 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
79150 +
79151 +config GRKERNSEC_CONFIG_VIRT_SOFT
79152 + bool "First-gen/No Hardware Virtualization"
79153 + help
79154 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
79155 + support hardware virtualization or doesn't support the EPT/RVI extensions.
79156 +
79157 +endchoice
79158 +
79159 +choice
79160 + prompt "Virtualization Software"
79161 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79162 + help
79163 +
79164 +config GRKERNSEC_CONFIG_VIRT_XEN
79165 + bool "Xen"
79166 + help
79167 + Choose this option if this kernel is running as a Xen guest or host.
79168 +
79169 +config GRKERNSEC_CONFIG_VIRT_VMWARE
79170 + bool "VMWare"
79171 + help
79172 + Choose this option if this kernel is running as a VMWare guest or host.
79173 +
79174 +config GRKERNSEC_CONFIG_VIRT_KVM
79175 + bool "KVM"
79176 + help
79177 + Choose this option if this kernel is running as a KVM guest or host.
79178 +
79179 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
79180 + bool "VirtualBox"
79181 + help
79182 + Choose this option if this kernel is running as a VirtualBox guest or host.
79183 +
79184 +endchoice
79185 +
79186 +choice
79187 + prompt "Required Priorities"
79188 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79189 + default GRKERNSEC_CONFIG_PRIORITY_PERF
79190 + help
79191 +
79192 +config GRKERNSEC_CONFIG_PRIORITY_PERF
79193 + bool "Performance"
79194 + help
79195 + Choose this option if performance is of highest priority for this deployment
79196 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
79197 + and freed memory sanitizing will be disabled.
79198 +
79199 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
79200 + bool "Security"
79201 + help
79202 + Choose this option if security is of highest priority for this deployment of
79203 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
79204 + be enabled for this kernel. In a worst-case scenario, these features can
79205 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
79206 +
79207 +endchoice
79208 +
79209 +menu "Default Special Groups"
79210 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79211 +
79212 +config GRKERNSEC_PROC_GID
79213 + int "GID exempted from /proc restrictions"
79214 + default 1001
79215 + help
79216 + Setting this GID determines which group will be exempted from
79217 + grsecurity's /proc restrictions, allowing users of the specified
79218 + group to view network statistics and the existence of other users'
79219 + processes on the system.
79220 +
79221 +config GRKERNSEC_TPE_GID
79222 + int "GID for untrusted users"
79223 + depends on GRKERNSEC_CONFIG_SERVER
79224 + default 1005
79225 + help
79226 + Setting this GID determines which group untrusted users should
79227 + be added to. These users will be placed under grsecurity's Trusted Path
79228 + Execution mechanism, preventing them from executing their own binaries.
79229 + The users will only be able to execute binaries in directories owned and
79230 + writable only by the root user.
79231 +
79232 +config GRKERNSEC_SYMLINKOWN_GID
79233 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
79234 + depends on GRKERNSEC_CONFIG_SERVER
79235 + default 1006
79236 + help
79237 + Setting this GID determines what group kernel-enforced
79238 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
79239 + is enabled, a sysctl option with name "symlinkown_gid" is created.
79240 +
79241 +
79242 +endmenu
79243 +
79244 +menu "Customize Configuration"
79245 +depends on GRKERNSEC
79246 +
79247 +menu "PaX"
79248 +
79249 +config PAX
79250 + bool "Enable various PaX features"
79251 + default y if GRKERNSEC_CONFIG_AUTO
79252 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79253 + help
79254 + This allows you to enable various PaX features. PaX adds
79255 + intrusion prevention mechanisms to the kernel that reduce
79256 + the risks posed by exploitable memory corruption bugs.
79257 +
79258 +menu "PaX Control"
79259 + depends on PAX
79260 +
79261 +config PAX_SOFTMODE
79262 + bool 'Support soft mode'
79263 + help
79264 + Enabling this option will allow you to run PaX in soft mode, that
79265 + is, PaX features will not be enforced by default, only on executables
79266 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79267 + support as they are the only way to mark executables for soft mode use.
79268 +
79269 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79270 + line option on boot. Furthermore you can control various PaX features
79271 + at runtime via the entries in /proc/sys/kernel/pax.
79272 +
79273 +config PAX_EI_PAX
79274 + bool 'Use legacy ELF header marking'
79275 + default y if GRKERNSEC_CONFIG_AUTO
79276 + help
79277 + Enabling this option will allow you to control PaX features on
79278 + a per executable basis via the 'chpax' utility available at
79279 + http://pax.grsecurity.net/. The control flags will be read from
79280 + an otherwise reserved part of the ELF header. This marking has
79281 + numerous drawbacks (no support for soft-mode, toolchain does not
79282 + know about the non-standard use of the ELF header) therefore it
79283 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79284 + support.
79285 +
79286 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79287 + support as well, they will override the legacy EI_PAX marks.
79288 +
79289 + If you enable none of the marking options then all applications
79290 + will run with PaX enabled on them by default.
79291 +
79292 +config PAX_PT_PAX_FLAGS
79293 + bool 'Use ELF program header marking'
79294 + default y if GRKERNSEC_CONFIG_AUTO
79295 + help
79296 + Enabling this option will allow you to control PaX features on
79297 + a per executable basis via the 'paxctl' utility available at
79298 + http://pax.grsecurity.net/. The control flags will be read from
79299 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79300 + has the benefits of supporting both soft mode and being fully
79301 + integrated into the toolchain (the binutils patch is available
79302 + from http://pax.grsecurity.net).
79303 +
79304 + Note that if you enable the legacy EI_PAX marking support as well,
79305 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79306 +
79307 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79308 + must make sure that the marks are the same if a binary has both marks.
79309 +
79310 + If you enable none of the marking options then all applications
79311 + will run with PaX enabled on them by default.
79312 +
79313 +config PAX_XATTR_PAX_FLAGS
79314 + bool 'Use filesystem extended attributes marking'
79315 + default y if GRKERNSEC_CONFIG_AUTO
79316 + select CIFS_XATTR if CIFS
79317 + select EXT2_FS_XATTR if EXT2_FS
79318 + select EXT3_FS_XATTR if EXT3_FS
79319 + select EXT4_FS_XATTR if EXT4_FS
79320 + select JFFS2_FS_XATTR if JFFS2_FS
79321 + select REISERFS_FS_XATTR if REISERFS_FS
79322 + select SQUASHFS_XATTR if SQUASHFS
79323 + select TMPFS_XATTR if TMPFS
79324 + select UBIFS_FS_XATTR if UBIFS_FS
79325 + help
79326 + Enabling this option will allow you to control PaX features on
79327 + a per executable basis via the 'setfattr' utility. The control
79328 + flags will be read from the user.pax.flags extended attribute of
79329 + the file. This marking has the benefit of supporting binary-only
79330 + applications that self-check themselves (e.g., skype) and would
79331 + not tolerate chpax/paxctl changes. The main drawback is that
79332 + extended attributes are not supported by some filesystems (e.g.,
79333 + isofs, udf, vfat) so copying files through such filesystems will
79334 + lose the extended attributes and these PaX markings.
79335 +
79336 + Note that if you enable the legacy EI_PAX marking support as well,
79337 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79338 +
79339 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79340 + must make sure that the marks are the same if a binary has both marks.
79341 +
79342 + If you enable none of the marking options then all applications
79343 + will run with PaX enabled on them by default.
79344 +
79345 +choice
79346 + prompt 'MAC system integration'
79347 + default PAX_HAVE_ACL_FLAGS
79348 + help
79349 + Mandatory Access Control systems have the option of controlling
79350 + PaX flags on a per executable basis, choose the method supported
79351 + by your particular system.
79352 +
79353 + - "none": if your MAC system does not interact with PaX,
79354 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79355 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79356 +
79357 + NOTE: this option is for developers/integrators only.
79358 +
79359 + config PAX_NO_ACL_FLAGS
79360 + bool 'none'
79361 +
79362 + config PAX_HAVE_ACL_FLAGS
79363 + bool 'direct'
79364 +
79365 + config PAX_HOOK_ACL_FLAGS
79366 + bool 'hook'
79367 +endchoice
79368 +
79369 +endmenu
79370 +
79371 +menu "Non-executable pages"
79372 + depends on PAX
79373 +
79374 +config PAX_NOEXEC
79375 + bool "Enforce non-executable pages"
79376 + default y if GRKERNSEC_CONFIG_AUTO
79377 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79378 + help
79379 + By design some architectures do not allow for protecting memory
79380 + pages against execution or even if they do, Linux does not make
79381 + use of this feature. In practice this means that if a page is
79382 + readable (such as the stack or heap) it is also executable.
79383 +
79384 + There is a well known exploit technique that makes use of this
79385 + fact and a common programming mistake where an attacker can
79386 + introduce code of his choice somewhere in the attacked program's
79387 + memory (typically the stack or the heap) and then execute it.
79388 +
79389 + If the attacked program was running with different (typically
79390 + higher) privileges than that of the attacker, then he can elevate
79391 + his own privilege level (e.g. get a root shell, write to files for
79392 + which he does not have write access to, etc).
79393 +
79394 + Enabling this option will let you choose from various features
79395 + that prevent the injection and execution of 'foreign' code in
79396 + a program.
79397 +
79398 + This will also break programs that rely on the old behaviour and
79399 + expect that dynamically allocated memory via the malloc() family
79400 + of functions is executable (which it is not). Notable examples
79401 + are the XFree86 4.x server, the java runtime and wine.
79402 +
79403 +config PAX_PAGEEXEC
79404 + bool "Paging based non-executable pages"
79405 + default y if GRKERNSEC_CONFIG_AUTO
79406 + 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)
79407 + select S390_SWITCH_AMODE if S390
79408 + select S390_EXEC_PROTECT if S390
79409 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79410 + help
79411 + This implementation is based on the paging feature of the CPU.
79412 + On i386 without hardware non-executable bit support there is a
79413 + variable but usually low performance impact, however on Intel's
79414 + P4 core based CPUs it is very high so you should not enable this
79415 + for kernels meant to be used on such CPUs.
79416 +
79417 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79418 + with hardware non-executable bit support there is no performance
79419 + impact, on ppc the impact is negligible.
79420 +
79421 + Note that several architectures require various emulations due to
79422 + badly designed userland ABIs, this will cause a performance impact
79423 + but will disappear as soon as userland is fixed. For example, ppc
79424 + userland MUST have been built with secure-plt by a recent toolchain.
79425 +
79426 +config PAX_SEGMEXEC
79427 + bool "Segmentation based non-executable pages"
79428 + default y if GRKERNSEC_CONFIG_AUTO
79429 + depends on PAX_NOEXEC && X86_32
79430 + help
79431 + This implementation is based on the segmentation feature of the
79432 + CPU and has a very small performance impact, however applications
79433 + will be limited to a 1.5 GB address space instead of the normal
79434 + 3 GB.
79435 +
79436 +config PAX_EMUTRAMP
79437 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79438 + default y if PARISC
79439 + help
79440 + There are some programs and libraries that for one reason or
79441 + another attempt to execute special small code snippets from
79442 + non-executable memory pages. Most notable examples are the
79443 + signal handler return code generated by the kernel itself and
79444 + the GCC trampolines.
79445 +
79446 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79447 + such programs will no longer work under your kernel.
79448 +
79449 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79450 + utilities to enable trampoline emulation for the affected programs
79451 + yet still have the protection provided by the non-executable pages.
79452 +
79453 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79454 + your system will not even boot.
79455 +
79456 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79457 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79458 + for the affected files.
79459 +
79460 + NOTE: enabling this feature *may* open up a loophole in the
79461 + protection provided by non-executable pages that an attacker
79462 + could abuse. Therefore the best solution is to not have any
79463 + files on your system that would require this option. This can
79464 + be achieved by not using libc5 (which relies on the kernel
79465 + signal handler return code) and not using or rewriting programs
79466 + that make use of the nested function implementation of GCC.
79467 + Skilled users can just fix GCC itself so that it implements
79468 + nested function calls in a way that does not interfere with PaX.
79469 +
79470 +config PAX_EMUSIGRT
79471 + bool "Automatically emulate sigreturn trampolines"
79472 + depends on PAX_EMUTRAMP && PARISC
79473 + default y
79474 + help
79475 + Enabling this option will have the kernel automatically detect
79476 + and emulate signal return trampolines executing on the stack
79477 + that would otherwise lead to task termination.
79478 +
79479 + This solution is intended as a temporary one for users with
79480 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79481 + Modula-3 runtime, etc) or executables linked to such, basically
79482 + everything that does not specify its own SA_RESTORER function in
79483 + normal executable memory like glibc 2.1+ does.
79484 +
79485 + On parisc you MUST enable this option, otherwise your system will
79486 + not even boot.
79487 +
79488 + NOTE: this feature cannot be disabled on a per executable basis
79489 + and since it *does* open up a loophole in the protection provided
79490 + by non-executable pages, the best solution is to not have any
79491 + files on your system that would require this option.
79492 +
79493 +config PAX_MPROTECT
79494 + bool "Restrict mprotect()"
79495 + default y if GRKERNSEC_CONFIG_AUTO
79496 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79497 + help
79498 + Enabling this option will prevent programs from
79499 + - changing the executable status of memory pages that were
79500 + not originally created as executable,
79501 + - making read-only executable pages writable again,
79502 + - creating executable pages from anonymous memory,
79503 + - making read-only-after-relocations (RELRO) data pages writable again.
79504 +
79505 + You should say Y here to complete the protection provided by
79506 + the enforcement of non-executable pages.
79507 +
79508 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79509 + this feature on a per file basis.
79510 +
79511 +config PAX_MPROTECT_COMPAT
79512 + bool "Use legacy/compat protection demoting (read help)"
79513 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79514 + depends on PAX_MPROTECT
79515 + help
79516 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79517 + by sending the proper error code to the application. For some broken
79518 + userland, this can cause problems with Python or other applications. The
79519 + current implementation however allows for applications like clamav to
79520 + detect if JIT compilation/execution is allowed and to fall back gracefully
79521 + to an interpreter-based mode if it does not. While we encourage everyone
79522 + to use the current implementation as-is and push upstream to fix broken
79523 + userland (note that the RWX logging option can assist with this), in some
79524 + environments this may not be possible. Having to disable MPROTECT
79525 + completely on certain binaries reduces the security benefit of PaX,
79526 + so this option is provided for those environments to revert to the old
79527 + behavior.
79528 +
79529 +config PAX_ELFRELOCS
79530 + bool "Allow ELF text relocations (read help)"
79531 + depends on PAX_MPROTECT
79532 + default n
79533 + help
79534 + Non-executable pages and mprotect() restrictions are effective
79535 + in preventing the introduction of new executable code into an
79536 + attacked task's address space. There remain only two venues
79537 + for this kind of attack: if the attacker can execute already
79538 + existing code in the attacked task then he can either have it
79539 + create and mmap() a file containing his code or have it mmap()
79540 + an already existing ELF library that does not have position
79541 + independent code in it and use mprotect() on it to make it
79542 + writable and copy his code there. While protecting against
79543 + the former approach is beyond PaX, the latter can be prevented
79544 + by having only PIC ELF libraries on one's system (which do not
79545 + need to relocate their code). If you are sure this is your case,
79546 + as is the case with all modern Linux distributions, then leave
79547 + this option disabled. You should say 'n' here.
79548 +
79549 +config PAX_ETEXECRELOCS
79550 + bool "Allow ELF ET_EXEC text relocations"
79551 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79552 + select PAX_ELFRELOCS
79553 + default y
79554 + help
79555 + On some architectures there are incorrectly created applications
79556 + that require text relocations and would not work without enabling
79557 + this option. If you are an alpha, ia64 or parisc user, you should
79558 + enable this option and disable it once you have made sure that
79559 + none of your applications need it.
79560 +
79561 +config PAX_EMUPLT
79562 + bool "Automatically emulate ELF PLT"
79563 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79564 + default y
79565 + help
79566 + Enabling this option will have the kernel automatically detect
79567 + and emulate the Procedure Linkage Table entries in ELF files.
79568 + On some architectures such entries are in writable memory, and
79569 + become non-executable leading to task termination. Therefore
79570 + it is mandatory that you enable this option on alpha, parisc,
79571 + sparc and sparc64, otherwise your system would not even boot.
79572 +
79573 + NOTE: this feature *does* open up a loophole in the protection
79574 + provided by the non-executable pages, therefore the proper
79575 + solution is to modify the toolchain to produce a PLT that does
79576 + not need to be writable.
79577 +
79578 +config PAX_DLRESOLVE
79579 + bool 'Emulate old glibc resolver stub'
79580 + depends on PAX_EMUPLT && SPARC
79581 + default n
79582 + help
79583 + This option is needed if userland has an old glibc (before 2.4)
79584 + that puts a 'save' instruction into the runtime generated resolver
79585 + stub that needs special emulation.
79586 +
79587 +config PAX_KERNEXEC
79588 + bool "Enforce non-executable kernel pages"
79589 + 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))
79590 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79591 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79592 + select PAX_KERNEXEC_PLUGIN if X86_64
79593 + help
79594 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79595 + that is, enabling this option will make it harder to inject
79596 + and execute 'foreign' code in kernel memory itself.
79597 +
79598 + Note that on x86_64 kernels there is a known regression when
79599 + this feature and KVM/VMX are both enabled in the host kernel.
79600 +
79601 +choice
79602 + prompt "Return Address Instrumentation Method"
79603 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79604 + depends on PAX_KERNEXEC_PLUGIN
79605 + help
79606 + Select the method used to instrument function pointer dereferences.
79607 + Note that binary modules cannot be instrumented by this approach.
79608 +
79609 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79610 + bool "bts"
79611 + help
79612 + This method is compatible with binary only modules but has
79613 + a higher runtime overhead.
79614 +
79615 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79616 + bool "or"
79617 + depends on !PARAVIRT
79618 + help
79619 + This method is incompatible with binary only modules but has
79620 + a lower runtime overhead.
79621 +endchoice
79622 +
79623 +config PAX_KERNEXEC_PLUGIN_METHOD
79624 + string
79625 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79626 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79627 + default ""
79628 +
79629 +config PAX_KERNEXEC_MODULE_TEXT
79630 + int "Minimum amount of memory reserved for module code"
79631 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
79632 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79633 + depends on PAX_KERNEXEC && X86_32 && MODULES
79634 + help
79635 + Due to implementation details the kernel must reserve a fixed
79636 + amount of memory for module code at compile time that cannot be
79637 + changed at runtime. Here you can specify the minimum amount
79638 + in MB that will be reserved. Due to the same implementation
79639 + details this size will always be rounded up to the next 2/4 MB
79640 + boundary (depends on PAE) so the actually available memory for
79641 + module code will usually be more than this minimum.
79642 +
79643 + The default 4 MB should be enough for most users but if you have
79644 + an excessive number of modules (e.g., most distribution configs
79645 + compile many drivers as modules) or use huge modules such as
79646 + nvidia's kernel driver, you will need to adjust this amount.
79647 + A good rule of thumb is to look at your currently loaded kernel
79648 + modules and add up their sizes.
79649 +
79650 +endmenu
79651 +
79652 +menu "Address Space Layout Randomization"
79653 + depends on PAX
79654 +
79655 +config PAX_ASLR
79656 + bool "Address Space Layout Randomization"
79657 + default y if GRKERNSEC_CONFIG_AUTO
79658 + help
79659 + Many if not most exploit techniques rely on the knowledge of
79660 + certain addresses in the attacked program. The following options
79661 + will allow the kernel to apply a certain amount of randomization
79662 + to specific parts of the program thereby forcing an attacker to
79663 + guess them in most cases. Any failed guess will most likely crash
79664 + the attacked program which allows the kernel to detect such attempts
79665 + and react on them. PaX itself provides no reaction mechanisms,
79666 + instead it is strongly encouraged that you make use of Nergal's
79667 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79668 + (http://www.grsecurity.net/) built-in crash detection features or
79669 + develop one yourself.
79670 +
79671 + By saying Y here you can choose to randomize the following areas:
79672 + - top of the task's kernel stack
79673 + - top of the task's userland stack
79674 + - base address for mmap() requests that do not specify one
79675 + (this includes all libraries)
79676 + - base address of the main executable
79677 +
79678 + It is strongly recommended to say Y here as address space layout
79679 + randomization has negligible impact on performance yet it provides
79680 + a very effective protection.
79681 +
79682 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79683 + this feature on a per file basis.
79684 +
79685 +config PAX_RANDKSTACK
79686 + bool "Randomize kernel stack base"
79687 + default y if GRKERNSEC_CONFIG_AUTO
79688 + depends on X86_TSC && X86
79689 + help
79690 + By saying Y here the kernel will randomize every task's kernel
79691 + stack on every system call. This will not only force an attacker
79692 + to guess it but also prevent him from making use of possible
79693 + leaked information about it.
79694 +
79695 + Since the kernel stack is a rather scarce resource, randomization
79696 + may cause unexpected stack overflows, therefore you should very
79697 + carefully test your system. Note that once enabled in the kernel
79698 + configuration, this feature cannot be disabled on a per file basis.
79699 +
79700 +config PAX_RANDUSTACK
79701 + bool "Randomize user stack base"
79702 + default y if GRKERNSEC_CONFIG_AUTO
79703 + depends on PAX_ASLR
79704 + help
79705 + By saying Y here the kernel will randomize every task's userland
79706 + stack. The randomization is done in two steps where the second
79707 + one may apply a big amount of shift to the top of the stack and
79708 + cause problems for programs that want to use lots of memory (more
79709 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79710 + For this reason the second step can be controlled by 'chpax' or
79711 + 'paxctl' on a per file basis.
79712 +
79713 +config PAX_RANDMMAP
79714 + bool "Randomize mmap() base"
79715 + default y if GRKERNSEC_CONFIG_AUTO
79716 + depends on PAX_ASLR
79717 + help
79718 + By saying Y here the kernel will use a randomized base address for
79719 + mmap() requests that do not specify one themselves. As a result
79720 + all dynamically loaded libraries will appear at random addresses
79721 + and therefore be harder to exploit by a technique where an attacker
79722 + attempts to execute library code for his purposes (e.g. spawn a
79723 + shell from an exploited program that is running at an elevated
79724 + privilege level).
79725 +
79726 + Furthermore, if a program is relinked as a dynamic ELF file, its
79727 + base address will be randomized as well, completing the full
79728 + randomization of the address space layout. Attacking such programs
79729 + becomes a guess game. You can find an example of doing this at
79730 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79731 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79732 +
79733 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79734 + feature on a per file basis.
79735 +
79736 +endmenu
79737 +
79738 +menu "Miscellaneous hardening features"
79739 +
79740 +config PAX_MEMORY_SANITIZE
79741 + bool "Sanitize all freed memory"
79742 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79743 + depends on !HIBERNATION
79744 + help
79745 + By saying Y here the kernel will erase memory pages as soon as they
79746 + are freed. This in turn reduces the lifetime of data stored in the
79747 + pages, making it less likely that sensitive information such as
79748 + passwords, cryptographic secrets, etc stay in memory for too long.
79749 +
79750 + This is especially useful for programs whose runtime is short, long
79751 + lived processes and the kernel itself benefit from this as long as
79752 + they operate on whole memory pages and ensure timely freeing of pages
79753 + that may hold sensitive information.
79754 +
79755 + The tradeoff is performance impact, on a single CPU system kernel
79756 + compilation sees a 3% slowdown, other systems and workloads may vary
79757 + and you are advised to test this feature on your expected workload
79758 + before deploying it.
79759 +
79760 + Note that this feature does not protect data stored in live pages,
79761 + e.g., process memory swapped to disk may stay there for a long time.
79762 +
79763 +config PAX_MEMORY_STACKLEAK
79764 + bool "Sanitize kernel stack"
79765 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79766 + depends on X86
79767 + help
79768 + By saying Y here the kernel will erase the kernel stack before it
79769 + returns from a system call. This in turn reduces the information
79770 + that a kernel stack leak bug can reveal.
79771 +
79772 + Note that such a bug can still leak information that was put on
79773 + the stack by the current system call (the one eventually triggering
79774 + the bug) but traces of earlier system calls on the kernel stack
79775 + cannot leak anymore.
79776 +
79777 + The tradeoff is performance impact: on a single CPU system kernel
79778 + compilation sees a 1% slowdown, other systems and workloads may vary
79779 + and you are advised to test this feature on your expected workload
79780 + before deploying it.
79781 +
79782 + Note: full support for this feature requires gcc with plugin support
79783 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79784 + versions means that functions with large enough stack frames may
79785 + leave uninitialized memory behind that may be exposed to a later
79786 + syscall leaking the stack.
79787 +
79788 +config PAX_MEMORY_UDEREF
79789 + bool "Prevent invalid userland pointer dereference"
79790 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
79791 + depends on X86 && !UML_X86 && !XEN
79792 + select PAX_PER_CPU_PGD if X86_64
79793 + help
79794 + By saying Y here the kernel will be prevented from dereferencing
79795 + userland pointers in contexts where the kernel expects only kernel
79796 + pointers. This is both a useful runtime debugging feature and a
79797 + security measure that prevents exploiting a class of kernel bugs.
79798 +
79799 + The tradeoff is that some virtualization solutions may experience
79800 + a huge slowdown and therefore you should not enable this feature
79801 + for kernels meant to run in such environments. Whether a given VM
79802 + solution is affected or not is best determined by simply trying it
79803 + out, the performance impact will be obvious right on boot as this
79804 + mechanism engages from very early on. A good rule of thumb is that
79805 + VMs running on CPUs without hardware virtualization support (i.e.,
79806 + the majority of IA-32 CPUs) will likely experience the slowdown.
79807 +
79808 +config PAX_REFCOUNT
79809 + bool "Prevent various kernel object reference counter overflows"
79810 + default y if GRKERNSEC_CONFIG_AUTO
79811 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79812 + help
79813 + By saying Y here the kernel will detect and prevent overflowing
79814 + various (but not all) kinds of object reference counters. Such
79815 + overflows can normally occur due to bugs only and are often, if
79816 + not always, exploitable.
79817 +
79818 + The tradeoff is that data structures protected by an overflowed
79819 + refcount will never be freed and therefore will leak memory. Note
79820 + that this leak also happens even without this protection but in
79821 + that case the overflow can eventually trigger the freeing of the
79822 + data structure while it is still being used elsewhere, resulting
79823 + in the exploitable situation that this feature prevents.
79824 +
79825 + Since this has a negligible performance impact, you should enable
79826 + this feature.
79827 +
79828 +config PAX_USERCOPY
79829 + bool "Harden heap object copies between kernel and userland"
79830 + default y if GRKERNSEC_CONFIG_AUTO
79831 + depends on X86 || PPC || SPARC || ARM
79832 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79833 + select PAX_USERCOPY_SLABS
79834 + help
79835 + By saying Y here the kernel will enforce the size of heap objects
79836 + when they are copied in either direction between the kernel and
79837 + userland, even if only a part of the heap object is copied.
79838 +
79839 + Specifically, this checking prevents information leaking from the
79840 + kernel heap during kernel to userland copies (if the kernel heap
79841 + object is otherwise fully initialized) and prevents kernel heap
79842 + overflows during userland to kernel copies.
79843 +
79844 + Note that the current implementation provides the strictest bounds
79845 + checks for the SLUB allocator.
79846 +
79847 + Enabling this option also enables per-slab cache protection against
79848 + data in a given cache being copied into/out of via userland
79849 + accessors. Though the whitelist of regions will be reduced over
79850 + time, it notably protects important data structures like task structs.
79851 +
79852 + If frame pointers are enabled on x86, this option will also restrict
79853 + copies into and out of the kernel stack to local variables within a
79854 + single frame.
79855 +
79856 + Since this has a negligible performance impact, you should enable
79857 + this feature.
79858 +
79859 +config PAX_SIZE_OVERFLOW
79860 + bool "Prevent various integer overflows in function size parameters"
79861 + default y if GRKERNSEC_CONFIG_AUTO
79862 + depends on X86
79863 + help
79864 + By saying Y here the kernel recomputes expressions of function
79865 + arguments marked by a size_overflow attribute with double integer
79866 + precision (DImode/TImode for 32/64 bit integer types).
79867 +
79868 + The recomputed argument is checked against INT_MAX and an event
79869 + is logged on overflow and the triggering process is killed.
79870 +
79871 + Homepage:
79872 + http://www.grsecurity.net/~ephox/overflow_plugin/
79873 +
79874 +config PAX_LATENT_ENTROPY
79875 + bool "Generate some entropy during boot"
79876 + default y if GRKERNSEC_CONFIG_AUTO
79877 + help
79878 + By saying Y here the kernel will instrument early boot code to
79879 + extract some entropy from both original and artificially created
79880 + program state. This will help especially embedded systems where
79881 + there is little 'natural' source of entropy normally. The cost
79882 + is some slowdown of the boot process.
79883 +
79884 + Note that entropy extracted this way is not cryptographically
79885 + secure!
79886 +
79887 +endmenu
79888 +
79889 +endmenu
79890 +
79891 +source grsecurity/Kconfig
79892 +
79893 +endmenu
79894 +
79895 +endmenu
79896 +
79897 source security/keys/Kconfig
79898
79899 config SECURITY_DMESG_RESTRICT
79900 @@ -103,7 +973,7 @@ config INTEL_TXT
79901 config LSM_MMAP_MIN_ADDR
79902 int "Low address space for LSM to protect from user allocation"
79903 depends on SECURITY && SECURITY_SELINUX
79904 - default 32768 if ARM
79905 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79906 default 65536
79907 help
79908 This is the portion of low virtual memory which should be protected
79909 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79910 index 8ea39aa..8569ac5 100644
79911 --- a/security/apparmor/lsm.c
79912 +++ b/security/apparmor/lsm.c
79913 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79914 return error;
79915 }
79916
79917 -static struct security_operations apparmor_ops = {
79918 +static struct security_operations apparmor_ops __read_only = {
79919 .name = "apparmor",
79920
79921 .ptrace_access_check = apparmor_ptrace_access_check,
79922 diff --git a/security/commoncap.c b/security/commoncap.c
79923 index 6dbae46..f534748 100644
79924 --- a/security/commoncap.c
79925 +++ b/security/commoncap.c
79926 @@ -583,6 +583,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79927 const struct cred *cred = current_cred();
79928 kuid_t root_uid = make_kuid(cred->user_ns, 0);
79929
79930 + if (gr_acl_enable_at_secure())
79931 + return 1;
79932 +
79933 if (!uid_eq(cred->uid, root_uid)) {
79934 if (bprm->cap_effective)
79935 return 1;
79936 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79937 index 3ccf7ac..d73ad64 100644
79938 --- a/security/integrity/ima/ima.h
79939 +++ b/security/integrity/ima/ima.h
79940 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79941 extern spinlock_t ima_queue_lock;
79942
79943 struct ima_h_table {
79944 - atomic_long_t len; /* number of stored measurements in the list */
79945 - atomic_long_t violations;
79946 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79947 + atomic_long_unchecked_t violations;
79948 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79949 };
79950 extern struct ima_h_table ima_htable;
79951 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79952 index 88a2788..581ab92 100644
79953 --- a/security/integrity/ima/ima_api.c
79954 +++ b/security/integrity/ima/ima_api.c
79955 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79956 int result;
79957
79958 /* can overflow, only indicator */
79959 - atomic_long_inc(&ima_htable.violations);
79960 + atomic_long_inc_unchecked(&ima_htable.violations);
79961
79962 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79963 if (!entry) {
79964 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79965 index e1aa2b4..52027bf 100644
79966 --- a/security/integrity/ima/ima_fs.c
79967 +++ b/security/integrity/ima/ima_fs.c
79968 @@ -28,12 +28,12 @@
79969 static int valid_policy = 1;
79970 #define TMPBUFLEN 12
79971 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79972 - loff_t *ppos, atomic_long_t *val)
79973 + loff_t *ppos, atomic_long_unchecked_t *val)
79974 {
79975 char tmpbuf[TMPBUFLEN];
79976 ssize_t len;
79977
79978 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79979 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79980 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79981 }
79982
79983 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79984 index 55a6271..ad829c3 100644
79985 --- a/security/integrity/ima/ima_queue.c
79986 +++ b/security/integrity/ima/ima_queue.c
79987 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79988 INIT_LIST_HEAD(&qe->later);
79989 list_add_tail_rcu(&qe->later, &ima_measurements);
79990
79991 - atomic_long_inc(&ima_htable.len);
79992 + atomic_long_inc_unchecked(&ima_htable.len);
79993 key = ima_hash_key(entry->digest);
79994 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79995 return 0;
79996 diff --git a/security/keys/compat.c b/security/keys/compat.c
79997 index c92d42b..341e7ea 100644
79998 --- a/security/keys/compat.c
79999 +++ b/security/keys/compat.c
80000 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80001 if (ret == 0)
80002 goto no_payload_free;
80003
80004 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80005 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80006
80007 if (iov != iovstack)
80008 kfree(iov);
80009 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80010 index 0f5b3f0..b8d47c1 100644
80011 --- a/security/keys/keyctl.c
80012 +++ b/security/keys/keyctl.c
80013 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80014 /*
80015 * Copy the iovec data from userspace
80016 */
80017 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80018 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80019 unsigned ioc)
80020 {
80021 for (; ioc > 0; ioc--) {
80022 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80023 * If successful, 0 will be returned.
80024 */
80025 long keyctl_instantiate_key_common(key_serial_t id,
80026 - const struct iovec *payload_iov,
80027 + const struct iovec __user *payload_iov,
80028 unsigned ioc,
80029 size_t plen,
80030 key_serial_t ringid)
80031 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
80032 [0].iov_len = plen
80033 };
80034
80035 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80036 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80037 }
80038
80039 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80040 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80041 if (ret == 0)
80042 goto no_payload_free;
80043
80044 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80045 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80046
80047 if (iov != iovstack)
80048 kfree(iov);
80049 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80050 index 7445875..262834f 100644
80051 --- a/security/keys/keyring.c
80052 +++ b/security/keys/keyring.c
80053 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
80054 ret = -EFAULT;
80055
80056 for (loop = 0; loop < klist->nkeys; loop++) {
80057 + key_serial_t serial;
80058 key = rcu_deref_link_locked(klist, loop,
80059 keyring);
80060 + serial = key->serial;
80061
80062 tmp = sizeof(key_serial_t);
80063 if (tmp > buflen)
80064 tmp = buflen;
80065
80066 - if (copy_to_user(buffer,
80067 - &key->serial,
80068 - tmp) != 0)
80069 + if (copy_to_user(buffer, &serial, tmp))
80070 goto error;
80071
80072 buflen -= tmp;
80073 diff --git a/security/min_addr.c b/security/min_addr.c
80074 index f728728..6457a0c 100644
80075 --- a/security/min_addr.c
80076 +++ b/security/min_addr.c
80077 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80078 */
80079 static void update_mmap_min_addr(void)
80080 {
80081 +#ifndef SPARC
80082 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80083 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80084 mmap_min_addr = dac_mmap_min_addr;
80085 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80086 #else
80087 mmap_min_addr = dac_mmap_min_addr;
80088 #endif
80089 +#endif
80090 }
80091
80092 /*
80093 diff --git a/security/security.c b/security/security.c
80094 index 860aeb3..45765c0 100644
80095 --- a/security/security.c
80096 +++ b/security/security.c
80097 @@ -20,6 +20,7 @@
80098 #include <linux/ima.h>
80099 #include <linux/evm.h>
80100 #include <linux/fsnotify.h>
80101 +#include <linux/mm.h>
80102 #include <linux/mman.h>
80103 #include <linux/mount.h>
80104 #include <linux/personality.h>
80105 @@ -32,8 +33,8 @@
80106 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80107 CONFIG_DEFAULT_SECURITY;
80108
80109 -static struct security_operations *security_ops;
80110 -static struct security_operations default_security_ops = {
80111 +static struct security_operations *security_ops __read_only;
80112 +static struct security_operations default_security_ops __read_only = {
80113 .name = "default",
80114 };
80115
80116 @@ -74,7 +75,9 @@ int __init security_init(void)
80117
80118 void reset_security_ops(void)
80119 {
80120 + pax_open_kernel();
80121 security_ops = &default_security_ops;
80122 + pax_close_kernel();
80123 }
80124
80125 /* Save user chosen LSM */
80126 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80127 index ffd8900..0b1751b 100644
80128 --- a/security/selinux/hooks.c
80129 +++ b/security/selinux/hooks.c
80130 @@ -95,8 +95,6 @@
80131
80132 #define NUM_SEL_MNT_OPTS 5
80133
80134 -extern struct security_operations *security_ops;
80135 -
80136 /* SECMARK reference count */
80137 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80138
80139 @@ -2792,11 +2790,16 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
80140
80141 /* We strip a nul only if it is at the end, otherwise the
80142 * context contains a nul and we should audit that */
80143 - str = value;
80144 - if (str[size - 1] == '\0')
80145 - audit_size = size - 1;
80146 - else
80147 - audit_size = size;
80148 + if (value) {
80149 + str = value;
80150 + if (str[size - 1] == '\0')
80151 + audit_size = size - 1;
80152 + else
80153 + audit_size = size;
80154 + } else {
80155 + str = "";
80156 + audit_size = 0;
80157 + }
80158 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
80159 audit_log_format(ab, "op=setxattr invalid_context=");
80160 audit_log_n_untrustedstring(ab, value, audit_size);
80161 @@ -5506,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80162
80163 #endif
80164
80165 -static struct security_operations selinux_ops = {
80166 +static struct security_operations selinux_ops __read_only = {
80167 .name = "selinux",
80168
80169 .ptrace_access_check = selinux_ptrace_access_check,
80170 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80171 index c220f31..89fab3f 100644
80172 --- a/security/selinux/include/xfrm.h
80173 +++ b/security/selinux/include/xfrm.h
80174 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80175
80176 static inline void selinux_xfrm_notify_policyload(void)
80177 {
80178 - atomic_inc(&flow_cache_genid);
80179 + atomic_inc_unchecked(&flow_cache_genid);
80180 }
80181 #else
80182 static inline int selinux_xfrm_enabled(void)
80183 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80184 index ee0bb57..57fcd43 100644
80185 --- a/security/smack/smack_lsm.c
80186 +++ b/security/smack/smack_lsm.c
80187 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80188 return 0;
80189 }
80190
80191 -struct security_operations smack_ops = {
80192 +struct security_operations smack_ops __read_only = {
80193 .name = "smack",
80194
80195 .ptrace_access_check = smack_ptrace_access_check,
80196 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80197 index c2d04a5..e6a1aeb 100644
80198 --- a/security/tomoyo/tomoyo.c
80199 +++ b/security/tomoyo/tomoyo.c
80200 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80201 * tomoyo_security_ops is a "struct security_operations" which is used for
80202 * registering TOMOYO.
80203 */
80204 -static struct security_operations tomoyo_security_ops = {
80205 +static struct security_operations tomoyo_security_ops __read_only = {
80206 .name = "tomoyo",
80207 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80208 .cred_prepare = tomoyo_cred_prepare,
80209 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
80210 index 51d6709..1f3dbe2 100644
80211 --- a/security/yama/Kconfig
80212 +++ b/security/yama/Kconfig
80213 @@ -1,6 +1,6 @@
80214 config SECURITY_YAMA
80215 bool "Yama support"
80216 - depends on SECURITY
80217 + depends on SECURITY && !GRKERNSEC
80218 select SECURITYFS
80219 select SECURITY_PATH
80220 default n
80221 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80222 index 270790d..c67dfcb 100644
80223 --- a/sound/aoa/codecs/onyx.c
80224 +++ b/sound/aoa/codecs/onyx.c
80225 @@ -54,7 +54,7 @@ struct onyx {
80226 spdif_locked:1,
80227 analog_locked:1,
80228 original_mute:2;
80229 - int open_count;
80230 + local_t open_count;
80231 struct codec_info *codec_info;
80232
80233 /* mutex serializes concurrent access to the device
80234 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80235 struct onyx *onyx = cii->codec_data;
80236
80237 mutex_lock(&onyx->mutex);
80238 - onyx->open_count++;
80239 + local_inc(&onyx->open_count);
80240 mutex_unlock(&onyx->mutex);
80241
80242 return 0;
80243 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80244 struct onyx *onyx = cii->codec_data;
80245
80246 mutex_lock(&onyx->mutex);
80247 - onyx->open_count--;
80248 - if (!onyx->open_count)
80249 + if (local_dec_and_test(&onyx->open_count))
80250 onyx->spdif_locked = onyx->analog_locked = 0;
80251 mutex_unlock(&onyx->mutex);
80252
80253 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80254 index ffd2025..df062c9 100644
80255 --- a/sound/aoa/codecs/onyx.h
80256 +++ b/sound/aoa/codecs/onyx.h
80257 @@ -11,6 +11,7 @@
80258 #include <linux/i2c.h>
80259 #include <asm/pmac_low_i2c.h>
80260 #include <asm/prom.h>
80261 +#include <asm/local.h>
80262
80263 /* PCM3052 register definitions */
80264
80265 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80266 index 08fde00..0bf641a 100644
80267 --- a/sound/core/oss/pcm_oss.c
80268 +++ b/sound/core/oss/pcm_oss.c
80269 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80270 if (in_kernel) {
80271 mm_segment_t fs;
80272 fs = snd_enter_user();
80273 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80274 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80275 snd_leave_user(fs);
80276 } else {
80277 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80278 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80279 }
80280 if (ret != -EPIPE && ret != -ESTRPIPE)
80281 break;
80282 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80283 if (in_kernel) {
80284 mm_segment_t fs;
80285 fs = snd_enter_user();
80286 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80287 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80288 snd_leave_user(fs);
80289 } else {
80290 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80291 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80292 }
80293 if (ret == -EPIPE) {
80294 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80295 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80296 struct snd_pcm_plugin_channel *channels;
80297 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80298 if (!in_kernel) {
80299 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80300 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80301 return -EFAULT;
80302 buf = runtime->oss.buffer;
80303 }
80304 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80305 }
80306 } else {
80307 tmp = snd_pcm_oss_write2(substream,
80308 - (const char __force *)buf,
80309 + (const char __force_kernel *)buf,
80310 runtime->oss.period_bytes, 0);
80311 if (tmp <= 0)
80312 goto err;
80313 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80314 struct snd_pcm_runtime *runtime = substream->runtime;
80315 snd_pcm_sframes_t frames, frames1;
80316 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80317 - char __user *final_dst = (char __force __user *)buf;
80318 + char __user *final_dst = (char __force_user *)buf;
80319 if (runtime->oss.plugin_first) {
80320 struct snd_pcm_plugin_channel *channels;
80321 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80322 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80323 xfer += tmp;
80324 runtime->oss.buffer_used -= tmp;
80325 } else {
80326 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80327 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80328 runtime->oss.period_bytes, 0);
80329 if (tmp <= 0)
80330 goto err;
80331 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80332 size1);
80333 size1 /= runtime->channels; /* frames */
80334 fs = snd_enter_user();
80335 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80336 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80337 snd_leave_user(fs);
80338 }
80339 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80340 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80341 index 91cdf94..4085161 100644
80342 --- a/sound/core/pcm_compat.c
80343 +++ b/sound/core/pcm_compat.c
80344 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80345 int err;
80346
80347 fs = snd_enter_user();
80348 - err = snd_pcm_delay(substream, &delay);
80349 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80350 snd_leave_user(fs);
80351 if (err < 0)
80352 return err;
80353 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80354 index 53b5ada..2db94c8 100644
80355 --- a/sound/core/pcm_native.c
80356 +++ b/sound/core/pcm_native.c
80357 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80358 switch (substream->stream) {
80359 case SNDRV_PCM_STREAM_PLAYBACK:
80360 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80361 - (void __user *)arg);
80362 + (void __force_user *)arg);
80363 break;
80364 case SNDRV_PCM_STREAM_CAPTURE:
80365 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80366 - (void __user *)arg);
80367 + (void __force_user *)arg);
80368 break;
80369 default:
80370 result = -EINVAL;
80371 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80372 index 5cf8d65..912a79c 100644
80373 --- a/sound/core/seq/seq_device.c
80374 +++ b/sound/core/seq/seq_device.c
80375 @@ -64,7 +64,7 @@ struct ops_list {
80376 int argsize; /* argument size */
80377
80378 /* operators */
80379 - struct snd_seq_dev_ops ops;
80380 + struct snd_seq_dev_ops *ops;
80381
80382 /* registred devices */
80383 struct list_head dev_list; /* list of devices */
80384 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80385
80386 mutex_lock(&ops->reg_mutex);
80387 /* copy driver operators */
80388 - ops->ops = *entry;
80389 + ops->ops = entry;
80390 ops->driver |= DRIVER_LOADED;
80391 ops->argsize = argsize;
80392
80393 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80394 dev->name, ops->id, ops->argsize, dev->argsize);
80395 return -EINVAL;
80396 }
80397 - if (ops->ops.init_device(dev) >= 0) {
80398 + if (ops->ops->init_device(dev) >= 0) {
80399 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80400 ops->num_init_devices++;
80401 } else {
80402 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80403 dev->name, ops->id, ops->argsize, dev->argsize);
80404 return -EINVAL;
80405 }
80406 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80407 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80408 dev->status = SNDRV_SEQ_DEVICE_FREE;
80409 dev->driver_data = NULL;
80410 ops->num_init_devices--;
80411 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80412 index 621e60e..f4543f5 100644
80413 --- a/sound/drivers/mts64.c
80414 +++ b/sound/drivers/mts64.c
80415 @@ -29,6 +29,7 @@
80416 #include <sound/initval.h>
80417 #include <sound/rawmidi.h>
80418 #include <sound/control.h>
80419 +#include <asm/local.h>
80420
80421 #define CARD_NAME "Miditerminal 4140"
80422 #define DRIVER_NAME "MTS64"
80423 @@ -67,7 +68,7 @@ struct mts64 {
80424 struct pardevice *pardev;
80425 int pardev_claimed;
80426
80427 - int open_count;
80428 + local_t open_count;
80429 int current_midi_output_port;
80430 int current_midi_input_port;
80431 u8 mode[MTS64_NUM_INPUT_PORTS];
80432 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80433 {
80434 struct mts64 *mts = substream->rmidi->private_data;
80435
80436 - if (mts->open_count == 0) {
80437 + if (local_read(&mts->open_count) == 0) {
80438 /* We don't need a spinlock here, because this is just called
80439 if the device has not been opened before.
80440 So there aren't any IRQs from the device */
80441 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80442
80443 msleep(50);
80444 }
80445 - ++(mts->open_count);
80446 + local_inc(&mts->open_count);
80447
80448 return 0;
80449 }
80450 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80451 struct mts64 *mts = substream->rmidi->private_data;
80452 unsigned long flags;
80453
80454 - --(mts->open_count);
80455 - if (mts->open_count == 0) {
80456 + if (local_dec_return(&mts->open_count) == 0) {
80457 /* We need the spinlock_irqsave here because we can still
80458 have IRQs at this point */
80459 spin_lock_irqsave(&mts->lock, flags);
80460 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80461
80462 msleep(500);
80463
80464 - } else if (mts->open_count < 0)
80465 - mts->open_count = 0;
80466 + } else if (local_read(&mts->open_count) < 0)
80467 + local_set(&mts->open_count, 0);
80468
80469 return 0;
80470 }
80471 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80472 index b953fb4..1999c01 100644
80473 --- a/sound/drivers/opl4/opl4_lib.c
80474 +++ b/sound/drivers/opl4/opl4_lib.c
80475 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80476 MODULE_DESCRIPTION("OPL4 driver");
80477 MODULE_LICENSE("GPL");
80478
80479 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80480 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80481 {
80482 int timeout = 10;
80483 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80484 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80485 index 3e32bd3..46fc152 100644
80486 --- a/sound/drivers/portman2x4.c
80487 +++ b/sound/drivers/portman2x4.c
80488 @@ -48,6 +48,7 @@
80489 #include <sound/initval.h>
80490 #include <sound/rawmidi.h>
80491 #include <sound/control.h>
80492 +#include <asm/local.h>
80493
80494 #define CARD_NAME "Portman 2x4"
80495 #define DRIVER_NAME "portman"
80496 @@ -85,7 +86,7 @@ struct portman {
80497 struct pardevice *pardev;
80498 int pardev_claimed;
80499
80500 - int open_count;
80501 + local_t open_count;
80502 int mode[PORTMAN_NUM_INPUT_PORTS];
80503 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80504 };
80505 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80506 index ea995af..f1bfa37 100644
80507 --- a/sound/firewire/amdtp.c
80508 +++ b/sound/firewire/amdtp.c
80509 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80510 ptr = s->pcm_buffer_pointer + data_blocks;
80511 if (ptr >= pcm->runtime->buffer_size)
80512 ptr -= pcm->runtime->buffer_size;
80513 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80514 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80515
80516 s->pcm_period_pointer += data_blocks;
80517 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80518 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
80519 */
80520 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80521 {
80522 - ACCESS_ONCE(s->source_node_id_field) =
80523 + ACCESS_ONCE_RW(s->source_node_id_field) =
80524 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80525 }
80526 EXPORT_SYMBOL(amdtp_out_stream_update);
80527 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80528 index b680c5e..061b7a0 100644
80529 --- a/sound/firewire/amdtp.h
80530 +++ b/sound/firewire/amdtp.h
80531 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
80532 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80533 struct snd_pcm_substream *pcm)
80534 {
80535 - ACCESS_ONCE(s->pcm) = pcm;
80536 + ACCESS_ONCE_RW(s->pcm) = pcm;
80537 }
80538
80539 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
80540 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80541 index d428ffe..751ef78 100644
80542 --- a/sound/firewire/isight.c
80543 +++ b/sound/firewire/isight.c
80544 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80545 ptr += count;
80546 if (ptr >= runtime->buffer_size)
80547 ptr -= runtime->buffer_size;
80548 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80549 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80550
80551 isight->period_counter += count;
80552 if (isight->period_counter >= runtime->period_size) {
80553 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80554 if (err < 0)
80555 return err;
80556
80557 - ACCESS_ONCE(isight->pcm_active) = true;
80558 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80559
80560 return 0;
80561 }
80562 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80563 {
80564 struct isight *isight = substream->private_data;
80565
80566 - ACCESS_ONCE(isight->pcm_active) = false;
80567 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80568
80569 mutex_lock(&isight->mutex);
80570 isight_stop_streaming(isight);
80571 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80572
80573 switch (cmd) {
80574 case SNDRV_PCM_TRIGGER_START:
80575 - ACCESS_ONCE(isight->pcm_running) = true;
80576 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80577 break;
80578 case SNDRV_PCM_TRIGGER_STOP:
80579 - ACCESS_ONCE(isight->pcm_running) = false;
80580 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80581 break;
80582 default:
80583 return -EINVAL;
80584 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80585 index 7bd5e33..1fcab12 100644
80586 --- a/sound/isa/cmi8330.c
80587 +++ b/sound/isa/cmi8330.c
80588 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80589
80590 struct snd_pcm *pcm;
80591 struct snd_cmi8330_stream {
80592 - struct snd_pcm_ops ops;
80593 + snd_pcm_ops_no_const ops;
80594 snd_pcm_open_callback_t open;
80595 void *private_data; /* sb or wss */
80596 } streams[2];
80597 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80598 index 733b014..56ce96f 100644
80599 --- a/sound/oss/sb_audio.c
80600 +++ b/sound/oss/sb_audio.c
80601 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80602 buf16 = (signed short *)(localbuf + localoffs);
80603 while (c)
80604 {
80605 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80606 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80607 if (copy_from_user(lbuf8,
80608 userbuf+useroffs + p,
80609 locallen))
80610 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80611 index 09d4648..cf234c7 100644
80612 --- a/sound/oss/swarm_cs4297a.c
80613 +++ b/sound/oss/swarm_cs4297a.c
80614 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80615 {
80616 struct cs4297a_state *s;
80617 u32 pwr, id;
80618 - mm_segment_t fs;
80619 int rval;
80620 #ifndef CONFIG_BCM_CS4297A_CSWARM
80621 u64 cfg;
80622 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80623 if (!rval) {
80624 char *sb1250_duart_present;
80625
80626 +#if 0
80627 + mm_segment_t fs;
80628 fs = get_fs();
80629 set_fs(KERNEL_DS);
80630 -#if 0
80631 val = SOUND_MASK_LINE;
80632 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80633 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80634 val = initvol[i].vol;
80635 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80636 }
80637 + set_fs(fs);
80638 // cs4297a_write_ac97(s, 0x18, 0x0808);
80639 #else
80640 // cs4297a_write_ac97(s, 0x5e, 0x180);
80641 cs4297a_write_ac97(s, 0x02, 0x0808);
80642 cs4297a_write_ac97(s, 0x18, 0x0808);
80643 #endif
80644 - set_fs(fs);
80645
80646 list_add(&s->list, &cs4297a_devs);
80647
80648 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80649 index 2fdaadb..7df8fc6 100644
80650 --- a/sound/pci/hda/hda_codec.h
80651 +++ b/sound/pci/hda/hda_codec.h
80652 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80653 /* notify power-up/down from codec to controller */
80654 void (*pm_notify)(struct hda_bus *bus);
80655 #endif
80656 -};
80657 +} __no_const;
80658
80659 /* template to pass to the bus constructor */
80660 struct hda_bus_template {
80661 @@ -711,6 +711,7 @@ struct hda_codec_ops {
80662 #endif
80663 void (*reboot_notify)(struct hda_codec *codec);
80664 };
80665 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80666
80667 /* record for amp information cache */
80668 struct hda_cache_head {
80669 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
80670 struct snd_pcm_substream *substream);
80671 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80672 struct snd_pcm_substream *substream);
80673 -};
80674 +} __no_const;
80675
80676 /* PCM information for each substream */
80677 struct hda_pcm_stream {
80678 @@ -799,7 +800,7 @@ struct hda_codec {
80679 const char *modelname; /* model name for preset */
80680
80681 /* set by patch */
80682 - struct hda_codec_ops patch_ops;
80683 + hda_codec_ops_no_const patch_ops;
80684
80685 /* PCM to create, set by patch_ops.build_pcms callback */
80686 unsigned int num_pcms;
80687 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80688 index 0da778a..bc38b84 100644
80689 --- a/sound/pci/ice1712/ice1712.h
80690 +++ b/sound/pci/ice1712/ice1712.h
80691 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80692 unsigned int mask_flags; /* total mask bits */
80693 struct snd_akm4xxx_ops {
80694 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80695 - } ops;
80696 + } __no_const ops;
80697 };
80698
80699 struct snd_ice1712_spdif {
80700 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80701 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80702 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80703 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80704 - } ops;
80705 + } __no_const ops;
80706 };
80707
80708
80709 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80710 index a8159b81..5f006a5 100644
80711 --- a/sound/pci/ymfpci/ymfpci_main.c
80712 +++ b/sound/pci/ymfpci/ymfpci_main.c
80713 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80714 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80715 break;
80716 }
80717 - if (atomic_read(&chip->interrupt_sleep_count)) {
80718 - atomic_set(&chip->interrupt_sleep_count, 0);
80719 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80720 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80721 wake_up(&chip->interrupt_sleep);
80722 }
80723 __end:
80724 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80725 continue;
80726 init_waitqueue_entry(&wait, current);
80727 add_wait_queue(&chip->interrupt_sleep, &wait);
80728 - atomic_inc(&chip->interrupt_sleep_count);
80729 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80730 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80731 remove_wait_queue(&chip->interrupt_sleep, &wait);
80732 }
80733 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80734 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80735 spin_unlock(&chip->reg_lock);
80736
80737 - if (atomic_read(&chip->interrupt_sleep_count)) {
80738 - atomic_set(&chip->interrupt_sleep_count, 0);
80739 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80740 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80741 wake_up(&chip->interrupt_sleep);
80742 }
80743 }
80744 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80745 spin_lock_init(&chip->reg_lock);
80746 spin_lock_init(&chip->voice_lock);
80747 init_waitqueue_head(&chip->interrupt_sleep);
80748 - atomic_set(&chip->interrupt_sleep_count, 0);
80749 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80750 chip->card = card;
80751 chip->pci = pci;
80752 chip->irq = -1;
80753 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
80754 new file mode 100644
80755 index 0000000..50f2f2f
80756 --- /dev/null
80757 +++ b/tools/gcc/.gitignore
80758 @@ -0,0 +1 @@
80759 +size_overflow_hash.h
80760 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80761 new file mode 100644
80762 index 0000000..1d09b7e
80763 --- /dev/null
80764 +++ b/tools/gcc/Makefile
80765 @@ -0,0 +1,43 @@
80766 +#CC := gcc
80767 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80768 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80769 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80770 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80771 +
80772 +ifeq ($(PLUGINCC),$(HOSTCC))
80773 +HOSTLIBS := hostlibs
80774 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80775 +else
80776 +HOSTLIBS := hostcxxlibs
80777 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
80778 +endif
80779 +
80780 +$(HOSTLIBS)-y := constify_plugin.so
80781 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80782 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80783 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80784 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80785 +$(HOSTLIBS)-y += colorize_plugin.so
80786 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80787 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
80788 +
80789 +always := $($(HOSTLIBS)-y)
80790 +
80791 +constify_plugin-objs := constify_plugin.o
80792 +stackleak_plugin-objs := stackleak_plugin.o
80793 +kallocstat_plugin-objs := kallocstat_plugin.o
80794 +kernexec_plugin-objs := kernexec_plugin.o
80795 +checker_plugin-objs := checker_plugin.o
80796 +colorize_plugin-objs := colorize_plugin.o
80797 +size_overflow_plugin-objs := size_overflow_plugin.o
80798 +latent_entropy_plugin-objs := latent_entropy_plugin.o
80799 +
80800 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
80801 +
80802 +quiet_cmd_build_size_overflow_hash = GENHASH $@
80803 + cmd_build_size_overflow_hash = \
80804 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
80805 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
80806 + $(call if_changed,build_size_overflow_hash)
80807 +
80808 +targets += size_overflow_hash.h
80809 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80810 new file mode 100644
80811 index 0000000..d41b5af
80812 --- /dev/null
80813 +++ b/tools/gcc/checker_plugin.c
80814 @@ -0,0 +1,171 @@
80815 +/*
80816 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80817 + * Licensed under the GPL v2
80818 + *
80819 + * Note: the choice of the license means that the compilation process is
80820 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80821 + * but for the kernel it doesn't matter since it doesn't link against
80822 + * any of the gcc libraries
80823 + *
80824 + * gcc plugin to implement various sparse (source code checker) features
80825 + *
80826 + * TODO:
80827 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80828 + *
80829 + * BUGS:
80830 + * - none known
80831 + */
80832 +#include "gcc-plugin.h"
80833 +#include "config.h"
80834 +#include "system.h"
80835 +#include "coretypes.h"
80836 +#include "tree.h"
80837 +#include "tree-pass.h"
80838 +#include "flags.h"
80839 +#include "intl.h"
80840 +#include "toplev.h"
80841 +#include "plugin.h"
80842 +//#include "expr.h" where are you...
80843 +#include "diagnostic.h"
80844 +#include "plugin-version.h"
80845 +#include "tm.h"
80846 +#include "function.h"
80847 +#include "basic-block.h"
80848 +#include "gimple.h"
80849 +#include "rtl.h"
80850 +#include "emit-rtl.h"
80851 +#include "tree-flow.h"
80852 +#include "target.h"
80853 +
80854 +extern void c_register_addr_space (const char *str, addr_space_t as);
80855 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80856 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80857 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80858 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80859 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80860 +
80861 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80862 +extern rtx emit_move_insn(rtx x, rtx y);
80863 +
80864 +int plugin_is_GPL_compatible;
80865 +
80866 +static struct plugin_info checker_plugin_info = {
80867 + .version = "201111150100",
80868 +};
80869 +
80870 +#define ADDR_SPACE_KERNEL 0
80871 +#define ADDR_SPACE_FORCE_KERNEL 1
80872 +#define ADDR_SPACE_USER 2
80873 +#define ADDR_SPACE_FORCE_USER 3
80874 +#define ADDR_SPACE_IOMEM 0
80875 +#define ADDR_SPACE_FORCE_IOMEM 0
80876 +#define ADDR_SPACE_PERCPU 0
80877 +#define ADDR_SPACE_FORCE_PERCPU 0
80878 +#define ADDR_SPACE_RCU 0
80879 +#define ADDR_SPACE_FORCE_RCU 0
80880 +
80881 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80882 +{
80883 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80884 +}
80885 +
80886 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80887 +{
80888 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80889 +}
80890 +
80891 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80892 +{
80893 + return default_addr_space_valid_pointer_mode(mode, as);
80894 +}
80895 +
80896 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80897 +{
80898 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80899 +}
80900 +
80901 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80902 +{
80903 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80904 +}
80905 +
80906 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80907 +{
80908 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80909 + return true;
80910 +
80911 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80912 + return true;
80913 +
80914 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80915 + return true;
80916 +
80917 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80918 + return true;
80919 +
80920 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80921 + return true;
80922 +
80923 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80924 + return true;
80925 +
80926 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80927 + return true;
80928 +
80929 + return subset == superset;
80930 +}
80931 +
80932 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80933 +{
80934 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80935 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80936 +
80937 + return op;
80938 +}
80939 +
80940 +static void register_checker_address_spaces(void *event_data, void *data)
80941 +{
80942 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80943 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80944 + c_register_addr_space("__user", ADDR_SPACE_USER);
80945 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80946 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80947 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80948 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80949 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80950 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80951 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80952 +
80953 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80954 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80955 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80956 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80957 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80958 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80959 + targetm.addr_space.convert = checker_addr_space_convert;
80960 +}
80961 +
80962 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80963 +{
80964 + const char * const plugin_name = plugin_info->base_name;
80965 + const int argc = plugin_info->argc;
80966 + const struct plugin_argument * const argv = plugin_info->argv;
80967 + int i;
80968 +
80969 + if (!plugin_default_version_check(version, &gcc_version)) {
80970 + error(G_("incompatible gcc/plugin versions"));
80971 + return 1;
80972 + }
80973 +
80974 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80975 +
80976 + for (i = 0; i < argc; ++i)
80977 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80978 +
80979 + if (TARGET_64BIT == 0)
80980 + return 0;
80981 +
80982 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80983 +
80984 + return 0;
80985 +}
80986 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80987 new file mode 100644
80988 index 0000000..846aeb0
80989 --- /dev/null
80990 +++ b/tools/gcc/colorize_plugin.c
80991 @@ -0,0 +1,148 @@
80992 +/*
80993 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80994 + * Licensed under the GPL v2
80995 + *
80996 + * Note: the choice of the license means that the compilation process is
80997 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80998 + * but for the kernel it doesn't matter since it doesn't link against
80999 + * any of the gcc libraries
81000 + *
81001 + * gcc plugin to colorize diagnostic output
81002 + *
81003 + */
81004 +
81005 +#include "gcc-plugin.h"
81006 +#include "config.h"
81007 +#include "system.h"
81008 +#include "coretypes.h"
81009 +#include "tree.h"
81010 +#include "tree-pass.h"
81011 +#include "flags.h"
81012 +#include "intl.h"
81013 +#include "toplev.h"
81014 +#include "plugin.h"
81015 +#include "diagnostic.h"
81016 +#include "plugin-version.h"
81017 +#include "tm.h"
81018 +
81019 +int plugin_is_GPL_compatible;
81020 +
81021 +static struct plugin_info colorize_plugin_info = {
81022 + .version = "201203092200",
81023 + .help = NULL,
81024 +};
81025 +
81026 +#define GREEN "\033[32m\033[2m"
81027 +#define LIGHTGREEN "\033[32m\033[1m"
81028 +#define YELLOW "\033[33m\033[2m"
81029 +#define LIGHTYELLOW "\033[33m\033[1m"
81030 +#define RED "\033[31m\033[2m"
81031 +#define LIGHTRED "\033[31m\033[1m"
81032 +#define BLUE "\033[34m\033[2m"
81033 +#define LIGHTBLUE "\033[34m\033[1m"
81034 +#define BRIGHT "\033[m\033[1m"
81035 +#define NORMAL "\033[m"
81036 +
81037 +static diagnostic_starter_fn old_starter;
81038 +static diagnostic_finalizer_fn old_finalizer;
81039 +
81040 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81041 +{
81042 + const char *color;
81043 + char *newprefix;
81044 +
81045 + switch (diagnostic->kind) {
81046 + case DK_NOTE:
81047 + color = LIGHTBLUE;
81048 + break;
81049 +
81050 + case DK_PEDWARN:
81051 + case DK_WARNING:
81052 + color = LIGHTYELLOW;
81053 + break;
81054 +
81055 + case DK_ERROR:
81056 + case DK_FATAL:
81057 + case DK_ICE:
81058 + case DK_PERMERROR:
81059 + case DK_SORRY:
81060 + color = LIGHTRED;
81061 + break;
81062 +
81063 + default:
81064 + color = NORMAL;
81065 + }
81066 +
81067 + old_starter(context, diagnostic);
81068 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81069 + return;
81070 + pp_destroy_prefix(context->printer);
81071 + pp_set_prefix(context->printer, newprefix);
81072 +}
81073 +
81074 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81075 +{
81076 + old_finalizer(context, diagnostic);
81077 +}
81078 +
81079 +static void colorize_arm(void)
81080 +{
81081 + old_starter = diagnostic_starter(global_dc);
81082 + old_finalizer = diagnostic_finalizer(global_dc);
81083 +
81084 + diagnostic_starter(global_dc) = start_colorize;
81085 + diagnostic_finalizer(global_dc) = finalize_colorize;
81086 +}
81087 +
81088 +static unsigned int execute_colorize_rearm(void)
81089 +{
81090 + if (diagnostic_starter(global_dc) == start_colorize)
81091 + return 0;
81092 +
81093 + colorize_arm();
81094 + return 0;
81095 +}
81096 +
81097 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81098 + .pass = {
81099 + .type = SIMPLE_IPA_PASS,
81100 + .name = "colorize_rearm",
81101 + .gate = NULL,
81102 + .execute = execute_colorize_rearm,
81103 + .sub = NULL,
81104 + .next = NULL,
81105 + .static_pass_number = 0,
81106 + .tv_id = TV_NONE,
81107 + .properties_required = 0,
81108 + .properties_provided = 0,
81109 + .properties_destroyed = 0,
81110 + .todo_flags_start = 0,
81111 + .todo_flags_finish = 0
81112 + }
81113 +};
81114 +
81115 +static void colorize_start_unit(void *gcc_data, void *user_data)
81116 +{
81117 + colorize_arm();
81118 +}
81119 +
81120 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81121 +{
81122 + const char * const plugin_name = plugin_info->base_name;
81123 + struct register_pass_info colorize_rearm_pass_info = {
81124 + .pass = &pass_ipa_colorize_rearm.pass,
81125 + .reference_pass_name = "*free_lang_data",
81126 + .ref_pass_instance_number = 1,
81127 + .pos_op = PASS_POS_INSERT_AFTER
81128 + };
81129 +
81130 + if (!plugin_default_version_check(version, &gcc_version)) {
81131 + error(G_("incompatible gcc/plugin versions"));
81132 + return 1;
81133 + }
81134 +
81135 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81136 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81137 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81138 + return 0;
81139 +}
81140 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81141 new file mode 100644
81142 index 0000000..048d4ff
81143 --- /dev/null
81144 +++ b/tools/gcc/constify_plugin.c
81145 @@ -0,0 +1,328 @@
81146 +/*
81147 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81148 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81149 + * Licensed under the GPL v2, or (at your option) v3
81150 + *
81151 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81152 + *
81153 + * Homepage:
81154 + * http://www.grsecurity.net/~ephox/const_plugin/
81155 + *
81156 + * Usage:
81157 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81158 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81159 + */
81160 +
81161 +#include "gcc-plugin.h"
81162 +#include "config.h"
81163 +#include "system.h"
81164 +#include "coretypes.h"
81165 +#include "tree.h"
81166 +#include "tree-pass.h"
81167 +#include "flags.h"
81168 +#include "intl.h"
81169 +#include "toplev.h"
81170 +#include "plugin.h"
81171 +#include "diagnostic.h"
81172 +#include "plugin-version.h"
81173 +#include "tm.h"
81174 +#include "function.h"
81175 +#include "basic-block.h"
81176 +#include "gimple.h"
81177 +#include "rtl.h"
81178 +#include "emit-rtl.h"
81179 +#include "tree-flow.h"
81180 +
81181 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81182 +
81183 +int plugin_is_GPL_compatible;
81184 +
81185 +static struct plugin_info const_plugin_info = {
81186 + .version = "201205300030",
81187 + .help = "no-constify\tturn off constification\n",
81188 +};
81189 +
81190 +static void deconstify_tree(tree node);
81191 +
81192 +static void deconstify_type(tree type)
81193 +{
81194 + tree field;
81195 +
81196 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
81197 + tree type = TREE_TYPE(field);
81198 +
81199 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81200 + continue;
81201 + if (!TYPE_READONLY(type))
81202 + continue;
81203 +
81204 + deconstify_tree(field);
81205 + }
81206 + TYPE_READONLY(type) = 0;
81207 + C_TYPE_FIELDS_READONLY(type) = 0;
81208 +}
81209 +
81210 +static void deconstify_tree(tree node)
81211 +{
81212 + tree old_type, new_type, field;
81213 +
81214 + old_type = TREE_TYPE(node);
81215 +
81216 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
81217 +
81218 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81219 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81220 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81221 + DECL_FIELD_CONTEXT(field) = new_type;
81222 +
81223 + deconstify_type(new_type);
81224 +
81225 + TREE_READONLY(node) = 0;
81226 + TREE_TYPE(node) = new_type;
81227 +}
81228 +
81229 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81230 +{
81231 + tree type;
81232 +
81233 + *no_add_attrs = true;
81234 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81235 + error("%qE attribute does not apply to functions", name);
81236 + return NULL_TREE;
81237 + }
81238 +
81239 + if (TREE_CODE(*node) == VAR_DECL) {
81240 + error("%qE attribute does not apply to variables", name);
81241 + return NULL_TREE;
81242 + }
81243 +
81244 + if (TYPE_P(*node)) {
81245 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81246 + *no_add_attrs = false;
81247 + else
81248 + error("%qE attribute applies to struct and union types only", name);
81249 + return NULL_TREE;
81250 + }
81251 +
81252 + type = TREE_TYPE(*node);
81253 +
81254 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81255 + error("%qE attribute applies to struct and union types only", name);
81256 + return NULL_TREE;
81257 + }
81258 +
81259 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81260 + error("%qE attribute is already applied to the type", name);
81261 + return NULL_TREE;
81262 + }
81263 +
81264 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81265 + error("%qE attribute used on type that is not constified", name);
81266 + return NULL_TREE;
81267 + }
81268 +
81269 + if (TREE_CODE(*node) == TYPE_DECL) {
81270 + deconstify_tree(*node);
81271 + return NULL_TREE;
81272 + }
81273 +
81274 + return NULL_TREE;
81275 +}
81276 +
81277 +static void constify_type(tree type)
81278 +{
81279 + TYPE_READONLY(type) = 1;
81280 + C_TYPE_FIELDS_READONLY(type) = 1;
81281 +}
81282 +
81283 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81284 +{
81285 + *no_add_attrs = true;
81286 + if (!TYPE_P(*node)) {
81287 + error("%qE attribute applies to types only", name);
81288 + return NULL_TREE;
81289 + }
81290 +
81291 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81292 + error("%qE attribute applies to struct and union types only", name);
81293 + return NULL_TREE;
81294 + }
81295 +
81296 + *no_add_attrs = false;
81297 + constify_type(*node);
81298 + return NULL_TREE;
81299 +}
81300 +
81301 +static struct attribute_spec no_const_attr = {
81302 + .name = "no_const",
81303 + .min_length = 0,
81304 + .max_length = 0,
81305 + .decl_required = false,
81306 + .type_required = false,
81307 + .function_type_required = false,
81308 + .handler = handle_no_const_attribute,
81309 +#if BUILDING_GCC_VERSION >= 4007
81310 + .affects_type_identity = true
81311 +#endif
81312 +};
81313 +
81314 +static struct attribute_spec do_const_attr = {
81315 + .name = "do_const",
81316 + .min_length = 0,
81317 + .max_length = 0,
81318 + .decl_required = false,
81319 + .type_required = false,
81320 + .function_type_required = false,
81321 + .handler = handle_do_const_attribute,
81322 +#if BUILDING_GCC_VERSION >= 4007
81323 + .affects_type_identity = true
81324 +#endif
81325 +};
81326 +
81327 +static void register_attributes(void *event_data, void *data)
81328 +{
81329 + register_attribute(&no_const_attr);
81330 + register_attribute(&do_const_attr);
81331 +}
81332 +
81333 +static bool is_fptr(tree field)
81334 +{
81335 + tree ptr = TREE_TYPE(field);
81336 +
81337 + if (TREE_CODE(ptr) != POINTER_TYPE)
81338 + return false;
81339 +
81340 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81341 +}
81342 +
81343 +static bool walk_struct(tree node)
81344 +{
81345 + tree field;
81346 +
81347 + if (TYPE_FIELDS(node) == NULL_TREE)
81348 + return false;
81349 +
81350 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
81351 + gcc_assert(!TYPE_READONLY(node));
81352 + deconstify_type(node);
81353 + return false;
81354 + }
81355 +
81356 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81357 + tree type = TREE_TYPE(field);
81358 + enum tree_code code = TREE_CODE(type);
81359 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81360 + if (!(walk_struct(type)))
81361 + return false;
81362 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81363 + return false;
81364 + }
81365 + return true;
81366 +}
81367 +
81368 +static void finish_type(void *event_data, void *data)
81369 +{
81370 + tree type = (tree)event_data;
81371 +
81372 + if (type == NULL_TREE)
81373 + return;
81374 +
81375 + if (TYPE_READONLY(type))
81376 + return;
81377 +
81378 + if (walk_struct(type))
81379 + constify_type(type);
81380 +}
81381 +
81382 +static unsigned int check_local_variables(void);
81383 +
81384 +struct gimple_opt_pass pass_local_variable = {
81385 + {
81386 + .type = GIMPLE_PASS,
81387 + .name = "check_local_variables",
81388 + .gate = NULL,
81389 + .execute = check_local_variables,
81390 + .sub = NULL,
81391 + .next = NULL,
81392 + .static_pass_number = 0,
81393 + .tv_id = TV_NONE,
81394 + .properties_required = 0,
81395 + .properties_provided = 0,
81396 + .properties_destroyed = 0,
81397 + .todo_flags_start = 0,
81398 + .todo_flags_finish = 0
81399 + }
81400 +};
81401 +
81402 +static unsigned int check_local_variables(void)
81403 +{
81404 + tree var;
81405 + referenced_var_iterator rvi;
81406 +
81407 +#if BUILDING_GCC_VERSION == 4005
81408 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81409 +#else
81410 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81411 +#endif
81412 + tree type = TREE_TYPE(var);
81413 +
81414 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81415 + continue;
81416 +
81417 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81418 + continue;
81419 +
81420 + if (!TYPE_READONLY(type))
81421 + continue;
81422 +
81423 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81424 +// continue;
81425 +
81426 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81427 +// continue;
81428 +
81429 + if (walk_struct(type)) {
81430 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
81431 + return 1;
81432 + }
81433 + }
81434 + return 0;
81435 +}
81436 +
81437 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81438 +{
81439 + const char * const plugin_name = plugin_info->base_name;
81440 + const int argc = plugin_info->argc;
81441 + const struct plugin_argument * const argv = plugin_info->argv;
81442 + int i;
81443 + bool constify = true;
81444 +
81445 + struct register_pass_info local_variable_pass_info = {
81446 + .pass = &pass_local_variable.pass,
81447 + .reference_pass_name = "*referenced_vars",
81448 + .ref_pass_instance_number = 1,
81449 + .pos_op = PASS_POS_INSERT_AFTER
81450 + };
81451 +
81452 + if (!plugin_default_version_check(version, &gcc_version)) {
81453 + error(G_("incompatible gcc/plugin versions"));
81454 + return 1;
81455 + }
81456 +
81457 + for (i = 0; i < argc; ++i) {
81458 + if (!(strcmp(argv[i].key, "no-constify"))) {
81459 + constify = false;
81460 + continue;
81461 + }
81462 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81463 + }
81464 +
81465 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81466 + if (constify) {
81467 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81468 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81469 + }
81470 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81471 +
81472 + return 0;
81473 +}
81474 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
81475 new file mode 100644
81476 index 0000000..a0fe8b2
81477 --- /dev/null
81478 +++ b/tools/gcc/generate_size_overflow_hash.sh
81479 @@ -0,0 +1,94 @@
81480 +#!/bin/bash
81481 +
81482 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
81483 +
81484 +header1="size_overflow_hash.h"
81485 +database="size_overflow_hash.data"
81486 +n=65536
81487 +
81488 +usage() {
81489 +cat <<EOF
81490 +usage: $0 options
81491 +OPTIONS:
81492 + -h|--help help
81493 + -o header file
81494 + -d database file
81495 + -n hash array size
81496 +EOF
81497 + return 0
81498 +}
81499 +
81500 +while true
81501 +do
81502 + case "$1" in
81503 + -h|--help) usage && exit 0;;
81504 + -n) n=$2; shift 2;;
81505 + -o) header1="$2"; shift 2;;
81506 + -d) database="$2"; shift 2;;
81507 + --) shift 1; break ;;
81508 + *) break ;;
81509 + esac
81510 +done
81511 +
81512 +create_defines() {
81513 + for i in `seq 1 10`
81514 + do
81515 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
81516 + done
81517 + echo >> "$header1"
81518 +}
81519 +
81520 +create_structs () {
81521 + rm -f "$header1"
81522 +
81523 + create_defines
81524 +
81525 + cat "$database" | while read data
81526 + do
81527 + data_array=($data)
81528 + struct_hash_name="${data_array[0]}"
81529 + funcn="${data_array[1]}"
81530 + params="${data_array[2]}"
81531 + next="${data_array[5]}"
81532 +
81533 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
81534 +
81535 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
81536 + echo -en "\t.param\t= " >> "$header1"
81537 + line=
81538 + for param_num in ${params//-/ };
81539 + do
81540 + line="${line}PARAM"$param_num"|"
81541 + done
81542 +
81543 + echo -e "${line%?},\n};\n" >> "$header1"
81544 + done
81545 +}
81546 +
81547 +create_headers () {
81548 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
81549 +}
81550 +
81551 +create_array_elements () {
81552 + index=0
81553 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
81554 + do
81555 + data_array=($data)
81556 + i="${data_array[3]}"
81557 + hash="${data_array[4]}"
81558 + while [[ $index -lt $i ]]
81559 + do
81560 + echo -e "\t["$index"]\t= NULL," >> "$header1"
81561 + index=$(($index + 1))
81562 + done
81563 + index=$(($index + 1))
81564 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
81565 + done
81566 + echo '};' >> $header1
81567 +}
81568 +
81569 +create_structs
81570 +create_headers
81571 +create_array_elements
81572 +
81573 +exit 0
81574 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81575 new file mode 100644
81576 index 0000000..a86e422
81577 --- /dev/null
81578 +++ b/tools/gcc/kallocstat_plugin.c
81579 @@ -0,0 +1,167 @@
81580 +/*
81581 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81582 + * Licensed under the GPL v2
81583 + *
81584 + * Note: the choice of the license means that the compilation process is
81585 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81586 + * but for the kernel it doesn't matter since it doesn't link against
81587 + * any of the gcc libraries
81588 + *
81589 + * gcc plugin to find the distribution of k*alloc sizes
81590 + *
81591 + * TODO:
81592 + *
81593 + * BUGS:
81594 + * - none known
81595 + */
81596 +#include "gcc-plugin.h"
81597 +#include "config.h"
81598 +#include "system.h"
81599 +#include "coretypes.h"
81600 +#include "tree.h"
81601 +#include "tree-pass.h"
81602 +#include "flags.h"
81603 +#include "intl.h"
81604 +#include "toplev.h"
81605 +#include "plugin.h"
81606 +//#include "expr.h" where are you...
81607 +#include "diagnostic.h"
81608 +#include "plugin-version.h"
81609 +#include "tm.h"
81610 +#include "function.h"
81611 +#include "basic-block.h"
81612 +#include "gimple.h"
81613 +#include "rtl.h"
81614 +#include "emit-rtl.h"
81615 +
81616 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81617 +
81618 +int plugin_is_GPL_compatible;
81619 +
81620 +static const char * const kalloc_functions[] = {
81621 + "__kmalloc",
81622 + "kmalloc",
81623 + "kmalloc_large",
81624 + "kmalloc_node",
81625 + "kmalloc_order",
81626 + "kmalloc_order_trace",
81627 + "kmalloc_slab",
81628 + "kzalloc",
81629 + "kzalloc_node",
81630 +};
81631 +
81632 +static struct plugin_info kallocstat_plugin_info = {
81633 + .version = "201111150100",
81634 +};
81635 +
81636 +static unsigned int execute_kallocstat(void);
81637 +
81638 +static struct gimple_opt_pass kallocstat_pass = {
81639 + .pass = {
81640 + .type = GIMPLE_PASS,
81641 + .name = "kallocstat",
81642 + .gate = NULL,
81643 + .execute = execute_kallocstat,
81644 + .sub = NULL,
81645 + .next = NULL,
81646 + .static_pass_number = 0,
81647 + .tv_id = TV_NONE,
81648 + .properties_required = 0,
81649 + .properties_provided = 0,
81650 + .properties_destroyed = 0,
81651 + .todo_flags_start = 0,
81652 + .todo_flags_finish = 0
81653 + }
81654 +};
81655 +
81656 +static bool is_kalloc(const char *fnname)
81657 +{
81658 + size_t i;
81659 +
81660 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81661 + if (!strcmp(fnname, kalloc_functions[i]))
81662 + return true;
81663 + return false;
81664 +}
81665 +
81666 +static unsigned int execute_kallocstat(void)
81667 +{
81668 + basic_block bb;
81669 +
81670 + // 1. loop through BBs and GIMPLE statements
81671 + FOR_EACH_BB(bb) {
81672 + gimple_stmt_iterator gsi;
81673 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81674 + // gimple match:
81675 + tree fndecl, size;
81676 + gimple call_stmt;
81677 + const char *fnname;
81678 +
81679 + // is it a call
81680 + call_stmt = gsi_stmt(gsi);
81681 + if (!is_gimple_call(call_stmt))
81682 + continue;
81683 + fndecl = gimple_call_fndecl(call_stmt);
81684 + if (fndecl == NULL_TREE)
81685 + continue;
81686 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81687 + continue;
81688 +
81689 + // is it a call to k*alloc
81690 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81691 + if (!is_kalloc(fnname))
81692 + continue;
81693 +
81694 + // is the size arg the result of a simple const assignment
81695 + size = gimple_call_arg(call_stmt, 0);
81696 + while (true) {
81697 + gimple def_stmt;
81698 + expanded_location xloc;
81699 + size_t size_val;
81700 +
81701 + if (TREE_CODE(size) != SSA_NAME)
81702 + break;
81703 + def_stmt = SSA_NAME_DEF_STMT(size);
81704 + if (!def_stmt || !is_gimple_assign(def_stmt))
81705 + break;
81706 + if (gimple_num_ops(def_stmt) != 2)
81707 + break;
81708 + size = gimple_assign_rhs1(def_stmt);
81709 + if (!TREE_CONSTANT(size))
81710 + continue;
81711 + xloc = expand_location(gimple_location(def_stmt));
81712 + if (!xloc.file)
81713 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81714 + size_val = TREE_INT_CST_LOW(size);
81715 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81716 + break;
81717 + }
81718 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81719 +//debug_tree(gimple_call_fn(call_stmt));
81720 +//print_node(stderr, "pax", fndecl, 4);
81721 + }
81722 + }
81723 +
81724 + return 0;
81725 +}
81726 +
81727 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81728 +{
81729 + const char * const plugin_name = plugin_info->base_name;
81730 + struct register_pass_info kallocstat_pass_info = {
81731 + .pass = &kallocstat_pass.pass,
81732 + .reference_pass_name = "ssa",
81733 + .ref_pass_instance_number = 1,
81734 + .pos_op = PASS_POS_INSERT_AFTER
81735 + };
81736 +
81737 + if (!plugin_default_version_check(version, &gcc_version)) {
81738 + error(G_("incompatible gcc/plugin versions"));
81739 + return 1;
81740 + }
81741 +
81742 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81743 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81744 +
81745 + return 0;
81746 +}
81747 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81748 new file mode 100644
81749 index 0000000..98011fa
81750 --- /dev/null
81751 +++ b/tools/gcc/kernexec_plugin.c
81752 @@ -0,0 +1,427 @@
81753 +/*
81754 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81755 + * Licensed under the GPL v2
81756 + *
81757 + * Note: the choice of the license means that the compilation process is
81758 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81759 + * but for the kernel it doesn't matter since it doesn't link against
81760 + * any of the gcc libraries
81761 + *
81762 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81763 + *
81764 + * TODO:
81765 + *
81766 + * BUGS:
81767 + * - none known
81768 + */
81769 +#include "gcc-plugin.h"
81770 +#include "config.h"
81771 +#include "system.h"
81772 +#include "coretypes.h"
81773 +#include "tree.h"
81774 +#include "tree-pass.h"
81775 +#include "flags.h"
81776 +#include "intl.h"
81777 +#include "toplev.h"
81778 +#include "plugin.h"
81779 +//#include "expr.h" where are you...
81780 +#include "diagnostic.h"
81781 +#include "plugin-version.h"
81782 +#include "tm.h"
81783 +#include "function.h"
81784 +#include "basic-block.h"
81785 +#include "gimple.h"
81786 +#include "rtl.h"
81787 +#include "emit-rtl.h"
81788 +#include "tree-flow.h"
81789 +
81790 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81791 +extern rtx emit_move_insn(rtx x, rtx y);
81792 +
81793 +int plugin_is_GPL_compatible;
81794 +
81795 +static struct plugin_info kernexec_plugin_info = {
81796 + .version = "201111291120",
81797 + .help = "method=[bts|or]\tinstrumentation method\n"
81798 +};
81799 +
81800 +static unsigned int execute_kernexec_reload(void);
81801 +static unsigned int execute_kernexec_fptr(void);
81802 +static unsigned int execute_kernexec_retaddr(void);
81803 +static bool kernexec_cmodel_check(void);
81804 +
81805 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81806 +static void (*kernexec_instrument_retaddr)(rtx);
81807 +
81808 +static struct gimple_opt_pass kernexec_reload_pass = {
81809 + .pass = {
81810 + .type = GIMPLE_PASS,
81811 + .name = "kernexec_reload",
81812 + .gate = kernexec_cmodel_check,
81813 + .execute = execute_kernexec_reload,
81814 + .sub = NULL,
81815 + .next = NULL,
81816 + .static_pass_number = 0,
81817 + .tv_id = TV_NONE,
81818 + .properties_required = 0,
81819 + .properties_provided = 0,
81820 + .properties_destroyed = 0,
81821 + .todo_flags_start = 0,
81822 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81823 + }
81824 +};
81825 +
81826 +static struct gimple_opt_pass kernexec_fptr_pass = {
81827 + .pass = {
81828 + .type = GIMPLE_PASS,
81829 + .name = "kernexec_fptr",
81830 + .gate = kernexec_cmodel_check,
81831 + .execute = execute_kernexec_fptr,
81832 + .sub = NULL,
81833 + .next = NULL,
81834 + .static_pass_number = 0,
81835 + .tv_id = TV_NONE,
81836 + .properties_required = 0,
81837 + .properties_provided = 0,
81838 + .properties_destroyed = 0,
81839 + .todo_flags_start = 0,
81840 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81841 + }
81842 +};
81843 +
81844 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81845 + .pass = {
81846 + .type = RTL_PASS,
81847 + .name = "kernexec_retaddr",
81848 + .gate = kernexec_cmodel_check,
81849 + .execute = execute_kernexec_retaddr,
81850 + .sub = NULL,
81851 + .next = NULL,
81852 + .static_pass_number = 0,
81853 + .tv_id = TV_NONE,
81854 + .properties_required = 0,
81855 + .properties_provided = 0,
81856 + .properties_destroyed = 0,
81857 + .todo_flags_start = 0,
81858 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81859 + }
81860 +};
81861 +
81862 +static bool kernexec_cmodel_check(void)
81863 +{
81864 + tree section;
81865 +
81866 + if (ix86_cmodel != CM_KERNEL)
81867 + return false;
81868 +
81869 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81870 + if (!section || !TREE_VALUE(section))
81871 + return true;
81872 +
81873 + section = TREE_VALUE(TREE_VALUE(section));
81874 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81875 + return true;
81876 +
81877 + return false;
81878 +}
81879 +
81880 +/*
81881 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81882 + */
81883 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81884 +{
81885 + gimple asm_movabs_stmt;
81886 +
81887 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81888 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81889 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81890 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81891 + update_stmt(asm_movabs_stmt);
81892 +}
81893 +
81894 +/*
81895 + * find all asm() stmts that clobber r10 and add a reload of r10
81896 + */
81897 +static unsigned int execute_kernexec_reload(void)
81898 +{
81899 + basic_block bb;
81900 +
81901 + // 1. loop through BBs and GIMPLE statements
81902 + FOR_EACH_BB(bb) {
81903 + gimple_stmt_iterator gsi;
81904 +
81905 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81906 + // gimple match: __asm__ ("" : : : "r10");
81907 + gimple asm_stmt;
81908 + size_t nclobbers;
81909 +
81910 + // is it an asm ...
81911 + asm_stmt = gsi_stmt(gsi);
81912 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81913 + continue;
81914 +
81915 + // ... clobbering r10
81916 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81917 + while (nclobbers--) {
81918 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81919 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81920 + continue;
81921 + kernexec_reload_fptr_mask(&gsi);
81922 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81923 + break;
81924 + }
81925 + }
81926 + }
81927 +
81928 + return 0;
81929 +}
81930 +
81931 +/*
81932 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81933 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81934 + */
81935 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81936 +{
81937 + gimple assign_intptr, assign_new_fptr, call_stmt;
81938 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81939 +
81940 + call_stmt = gsi_stmt(*gsi);
81941 + old_fptr = gimple_call_fn(call_stmt);
81942 +
81943 + // create temporary unsigned long variable used for bitops and cast fptr to it
81944 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81945 + add_referenced_var(intptr);
81946 + mark_sym_for_renaming(intptr);
81947 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81948 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81949 + update_stmt(assign_intptr);
81950 +
81951 + // apply logical or to temporary unsigned long and bitmask
81952 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81953 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81954 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81955 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81956 + update_stmt(assign_intptr);
81957 +
81958 + // cast temporary unsigned long back to a temporary fptr variable
81959 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81960 + add_referenced_var(new_fptr);
81961 + mark_sym_for_renaming(new_fptr);
81962 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81963 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81964 + update_stmt(assign_new_fptr);
81965 +
81966 + // replace call stmt fn with the new fptr
81967 + gimple_call_set_fn(call_stmt, new_fptr);
81968 + update_stmt(call_stmt);
81969 +}
81970 +
81971 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81972 +{
81973 + gimple asm_or_stmt, call_stmt;
81974 + tree old_fptr, new_fptr, input, output;
81975 + VEC(tree, gc) *inputs = NULL;
81976 + VEC(tree, gc) *outputs = NULL;
81977 +
81978 + call_stmt = gsi_stmt(*gsi);
81979 + old_fptr = gimple_call_fn(call_stmt);
81980 +
81981 + // create temporary fptr variable
81982 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81983 + add_referenced_var(new_fptr);
81984 + mark_sym_for_renaming(new_fptr);
81985 +
81986 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81987 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81988 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81989 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81990 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81991 + VEC_safe_push(tree, gc, inputs, input);
81992 + VEC_safe_push(tree, gc, outputs, output);
81993 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81994 + gimple_asm_set_volatile(asm_or_stmt, true);
81995 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81996 + update_stmt(asm_or_stmt);
81997 +
81998 + // replace call stmt fn with the new fptr
81999 + gimple_call_set_fn(call_stmt, new_fptr);
82000 + update_stmt(call_stmt);
82001 +}
82002 +
82003 +/*
82004 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82005 + */
82006 +static unsigned int execute_kernexec_fptr(void)
82007 +{
82008 + basic_block bb;
82009 +
82010 + // 1. loop through BBs and GIMPLE statements
82011 + FOR_EACH_BB(bb) {
82012 + gimple_stmt_iterator gsi;
82013 +
82014 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82015 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82016 + tree fn;
82017 + gimple call_stmt;
82018 +
82019 + // is it a call ...
82020 + call_stmt = gsi_stmt(gsi);
82021 + if (!is_gimple_call(call_stmt))
82022 + continue;
82023 + fn = gimple_call_fn(call_stmt);
82024 + if (TREE_CODE(fn) == ADDR_EXPR)
82025 + continue;
82026 + if (TREE_CODE(fn) != SSA_NAME)
82027 + gcc_unreachable();
82028 +
82029 + // ... through a function pointer
82030 + fn = SSA_NAME_VAR(fn);
82031 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82032 + continue;
82033 + fn = TREE_TYPE(fn);
82034 + if (TREE_CODE(fn) != POINTER_TYPE)
82035 + continue;
82036 + fn = TREE_TYPE(fn);
82037 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82038 + continue;
82039 +
82040 + kernexec_instrument_fptr(&gsi);
82041 +
82042 +//debug_tree(gimple_call_fn(call_stmt));
82043 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82044 + }
82045 + }
82046 +
82047 + return 0;
82048 +}
82049 +
82050 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82051 +static void kernexec_instrument_retaddr_bts(rtx insn)
82052 +{
82053 + rtx btsq;
82054 + rtvec argvec, constraintvec, labelvec;
82055 + int line;
82056 +
82057 + // create asm volatile("btsq $63,(%%rsp)":::)
82058 + argvec = rtvec_alloc(0);
82059 + constraintvec = rtvec_alloc(0);
82060 + labelvec = rtvec_alloc(0);
82061 + line = expand_location(RTL_LOCATION(insn)).line;
82062 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82063 + MEM_VOLATILE_P(btsq) = 1;
82064 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82065 + emit_insn_before(btsq, insn);
82066 +}
82067 +
82068 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82069 +static void kernexec_instrument_retaddr_or(rtx insn)
82070 +{
82071 + rtx orq;
82072 + rtvec argvec, constraintvec, labelvec;
82073 + int line;
82074 +
82075 + // create asm volatile("orq %%r10,(%%rsp)":::)
82076 + argvec = rtvec_alloc(0);
82077 + constraintvec = rtvec_alloc(0);
82078 + labelvec = rtvec_alloc(0);
82079 + line = expand_location(RTL_LOCATION(insn)).line;
82080 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82081 + MEM_VOLATILE_P(orq) = 1;
82082 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82083 + emit_insn_before(orq, insn);
82084 +}
82085 +
82086 +/*
82087 + * find all asm level function returns and forcibly set the highest bit of the return address
82088 + */
82089 +static unsigned int execute_kernexec_retaddr(void)
82090 +{
82091 + rtx insn;
82092 +
82093 + // 1. find function returns
82094 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82095 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82096 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82097 + rtx body;
82098 +
82099 + // is it a retn
82100 + if (!JUMP_P(insn))
82101 + continue;
82102 + body = PATTERN(insn);
82103 + if (GET_CODE(body) == PARALLEL)
82104 + body = XVECEXP(body, 0, 0);
82105 + if (GET_CODE(body) != RETURN)
82106 + continue;
82107 + kernexec_instrument_retaddr(insn);
82108 + }
82109 +
82110 +// print_simple_rtl(stderr, get_insns());
82111 +// print_rtl(stderr, get_insns());
82112 +
82113 + return 0;
82114 +}
82115 +
82116 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82117 +{
82118 + const char * const plugin_name = plugin_info->base_name;
82119 + const int argc = plugin_info->argc;
82120 + const struct plugin_argument * const argv = plugin_info->argv;
82121 + int i;
82122 + struct register_pass_info kernexec_reload_pass_info = {
82123 + .pass = &kernexec_reload_pass.pass,
82124 + .reference_pass_name = "ssa",
82125 + .ref_pass_instance_number = 1,
82126 + .pos_op = PASS_POS_INSERT_AFTER
82127 + };
82128 + struct register_pass_info kernexec_fptr_pass_info = {
82129 + .pass = &kernexec_fptr_pass.pass,
82130 + .reference_pass_name = "ssa",
82131 + .ref_pass_instance_number = 1,
82132 + .pos_op = PASS_POS_INSERT_AFTER
82133 + };
82134 + struct register_pass_info kernexec_retaddr_pass_info = {
82135 + .pass = &kernexec_retaddr_pass.pass,
82136 + .reference_pass_name = "pro_and_epilogue",
82137 + .ref_pass_instance_number = 1,
82138 + .pos_op = PASS_POS_INSERT_AFTER
82139 + };
82140 +
82141 + if (!plugin_default_version_check(version, &gcc_version)) {
82142 + error(G_("incompatible gcc/plugin versions"));
82143 + return 1;
82144 + }
82145 +
82146 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82147 +
82148 + if (TARGET_64BIT == 0)
82149 + return 0;
82150 +
82151 + for (i = 0; i < argc; ++i) {
82152 + if (!strcmp(argv[i].key, "method")) {
82153 + if (!argv[i].value) {
82154 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82155 + continue;
82156 + }
82157 + if (!strcmp(argv[i].value, "bts")) {
82158 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82159 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82160 + } else if (!strcmp(argv[i].value, "or")) {
82161 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82162 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82163 + fix_register("r10", 1, 1);
82164 + } else
82165 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82166 + continue;
82167 + }
82168 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82169 + }
82170 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82171 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82172 +
82173 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82174 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82175 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82176 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82177 +
82178 + return 0;
82179 +}
82180 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
82181 new file mode 100644
82182 index 0000000..b8008f7
82183 --- /dev/null
82184 +++ b/tools/gcc/latent_entropy_plugin.c
82185 @@ -0,0 +1,295 @@
82186 +/*
82187 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
82188 + * Licensed under the GPL v2
82189 + *
82190 + * Note: the choice of the license means that the compilation process is
82191 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82192 + * but for the kernel it doesn't matter since it doesn't link against
82193 + * any of the gcc libraries
82194 + *
82195 + * gcc plugin to help generate a little bit of entropy from program state,
82196 + * used during boot in the kernel
82197 + *
82198 + * TODO:
82199 + * - add ipa pass to identify not explicitly marked candidate functions
82200 + * - mix in more program state (function arguments/return values, loop variables, etc)
82201 + * - more instrumentation control via attribute parameters
82202 + *
82203 + * BUGS:
82204 + * - LTO needs -flto-partition=none for now
82205 + */
82206 +#include "gcc-plugin.h"
82207 +#include "config.h"
82208 +#include "system.h"
82209 +#include "coretypes.h"
82210 +#include "tree.h"
82211 +#include "tree-pass.h"
82212 +#include "flags.h"
82213 +#include "intl.h"
82214 +#include "toplev.h"
82215 +#include "plugin.h"
82216 +//#include "expr.h" where are you...
82217 +#include "diagnostic.h"
82218 +#include "plugin-version.h"
82219 +#include "tm.h"
82220 +#include "function.h"
82221 +#include "basic-block.h"
82222 +#include "gimple.h"
82223 +#include "rtl.h"
82224 +#include "emit-rtl.h"
82225 +#include "tree-flow.h"
82226 +
82227 +int plugin_is_GPL_compatible;
82228 +
82229 +static tree latent_entropy_decl;
82230 +
82231 +static struct plugin_info latent_entropy_plugin_info = {
82232 + .version = "201207271820",
82233 + .help = NULL
82234 +};
82235 +
82236 +static unsigned int execute_latent_entropy(void);
82237 +static bool gate_latent_entropy(void);
82238 +
82239 +static struct gimple_opt_pass latent_entropy_pass = {
82240 + .pass = {
82241 + .type = GIMPLE_PASS,
82242 + .name = "latent_entropy",
82243 + .gate = gate_latent_entropy,
82244 + .execute = execute_latent_entropy,
82245 + .sub = NULL,
82246 + .next = NULL,
82247 + .static_pass_number = 0,
82248 + .tv_id = TV_NONE,
82249 + .properties_required = PROP_gimple_leh | PROP_cfg,
82250 + .properties_provided = 0,
82251 + .properties_destroyed = 0,
82252 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82253 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82254 + }
82255 +};
82256 +
82257 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82258 +{
82259 + if (TREE_CODE(*node) != FUNCTION_DECL) {
82260 + *no_add_attrs = true;
82261 + error("%qE attribute only applies to functions", name);
82262 + }
82263 + return NULL_TREE;
82264 +}
82265 +
82266 +static struct attribute_spec latent_entropy_attr = {
82267 + .name = "latent_entropy",
82268 + .min_length = 0,
82269 + .max_length = 0,
82270 + .decl_required = true,
82271 + .type_required = false,
82272 + .function_type_required = false,
82273 + .handler = handle_latent_entropy_attribute,
82274 +#if BUILDING_GCC_VERSION >= 4007
82275 + .affects_type_identity = false
82276 +#endif
82277 +};
82278 +
82279 +static void register_attributes(void *event_data, void *data)
82280 +{
82281 + register_attribute(&latent_entropy_attr);
82282 +}
82283 +
82284 +static bool gate_latent_entropy(void)
82285 +{
82286 + tree latent_entropy_attr;
82287 +
82288 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
82289 + return latent_entropy_attr != NULL_TREE;
82290 +}
82291 +
82292 +static unsigned HOST_WIDE_INT seed;
82293 +static unsigned HOST_WIDE_INT get_random_const(void)
82294 +{
82295 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
82296 + return seed;
82297 +}
82298 +
82299 +static enum tree_code get_op(tree *rhs)
82300 +{
82301 + static enum tree_code op;
82302 + unsigned HOST_WIDE_INT random_const;
82303 +
82304 + random_const = get_random_const();
82305 +
82306 + switch (op) {
82307 + case BIT_XOR_EXPR:
82308 + op = PLUS_EXPR;
82309 + break;
82310 +
82311 + case PLUS_EXPR:
82312 + if (rhs) {
82313 + op = LROTATE_EXPR;
82314 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
82315 + break;
82316 + }
82317 +
82318 + case LROTATE_EXPR:
82319 + default:
82320 + op = BIT_XOR_EXPR;
82321 + break;
82322 + }
82323 + if (rhs)
82324 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
82325 + return op;
82326 +}
82327 +
82328 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
82329 +{
82330 + gimple_stmt_iterator gsi;
82331 + gimple assign;
82332 + tree addxorrol, rhs;
82333 + enum tree_code op;
82334 +
82335 + op = get_op(&rhs);
82336 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
82337 + assign = gimple_build_assign(local_entropy, addxorrol);
82338 + find_referenced_vars_in(assign);
82339 +//debug_bb(bb);
82340 + gsi = gsi_after_labels(bb);
82341 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
82342 + update_stmt(assign);
82343 +}
82344 +
82345 +static void perturb_latent_entropy(basic_block bb, tree rhs)
82346 +{
82347 + gimple_stmt_iterator gsi;
82348 + gimple assign;
82349 + tree addxorrol, temp;
82350 +
82351 + // 1. create temporary copy of latent_entropy
82352 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
82353 + add_referenced_var(temp);
82354 + mark_sym_for_renaming(temp);
82355 +
82356 + // 2. read...
82357 + assign = gimple_build_assign(temp, latent_entropy_decl);
82358 + find_referenced_vars_in(assign);
82359 + gsi = gsi_after_labels(bb);
82360 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82361 + update_stmt(assign);
82362 +
82363 + // 3. ...modify...
82364 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
82365 + assign = gimple_build_assign(temp, addxorrol);
82366 + find_referenced_vars_in(assign);
82367 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82368 + update_stmt(assign);
82369 +
82370 + // 4. ...write latent_entropy
82371 + assign = gimple_build_assign(latent_entropy_decl, temp);
82372 + find_referenced_vars_in(assign);
82373 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82374 + update_stmt(assign);
82375 +}
82376 +
82377 +static unsigned int execute_latent_entropy(void)
82378 +{
82379 + basic_block bb;
82380 + gimple assign;
82381 + gimple_stmt_iterator gsi;
82382 + tree local_entropy;
82383 +
82384 + if (!latent_entropy_decl) {
82385 + struct varpool_node *node;
82386 +
82387 + for (node = varpool_nodes; node; node = node->next) {
82388 + tree var = node->decl;
82389 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
82390 + continue;
82391 + latent_entropy_decl = var;
82392 +// debug_tree(var);
82393 + break;
82394 + }
82395 + if (!latent_entropy_decl) {
82396 +// debug_tree(current_function_decl);
82397 + return 0;
82398 + }
82399 + }
82400 +
82401 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
82402 +
82403 + // 1. create local entropy variable
82404 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
82405 + add_referenced_var(local_entropy);
82406 + mark_sym_for_renaming(local_entropy);
82407 +
82408 + // 2. initialize local entropy variable
82409 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
82410 + if (dom_info_available_p(CDI_DOMINATORS))
82411 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
82412 + gsi = gsi_start_bb(bb);
82413 +
82414 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
82415 +// gimple_set_location(assign, loc);
82416 + find_referenced_vars_in(assign);
82417 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82418 + update_stmt(assign);
82419 + bb = bb->next_bb;
82420 +
82421 + // 3. instrument each BB with an operation on the local entropy variable
82422 + while (bb != EXIT_BLOCK_PTR) {
82423 + perturb_local_entropy(bb, local_entropy);
82424 + bb = bb->next_bb;
82425 + };
82426 +
82427 + // 4. mix local entropy into the global entropy variable
82428 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
82429 + return 0;
82430 +}
82431 +
82432 +static void start_unit_callback(void *gcc_data, void *user_data)
82433 +{
82434 +#if BUILDING_GCC_VERSION >= 4007
82435 + seed = get_random_seed(false);
82436 +#else
82437 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
82438 + seed *= seed;
82439 +#endif
82440 +
82441 + if (in_lto_p)
82442 + return;
82443 +
82444 + // extern u64 latent_entropy
82445 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
82446 +
82447 + TREE_STATIC(latent_entropy_decl) = 1;
82448 + TREE_PUBLIC(latent_entropy_decl) = 1;
82449 + TREE_USED(latent_entropy_decl) = 1;
82450 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
82451 + DECL_EXTERNAL(latent_entropy_decl) = 1;
82452 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
82453 + DECL_INITIAL(latent_entropy_decl) = NULL;
82454 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
82455 +// varpool_finalize_decl(latent_entropy_decl);
82456 +// varpool_mark_needed_node(latent_entropy_decl);
82457 +}
82458 +
82459 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82460 +{
82461 + const char * const plugin_name = plugin_info->base_name;
82462 + struct register_pass_info latent_entropy_pass_info = {
82463 + .pass = &latent_entropy_pass.pass,
82464 + .reference_pass_name = "optimized",
82465 + .ref_pass_instance_number = 1,
82466 + .pos_op = PASS_POS_INSERT_BEFORE
82467 + };
82468 +
82469 + if (!plugin_default_version_check(version, &gcc_version)) {
82470 + error(G_("incompatible gcc/plugin versions"));
82471 + return 1;
82472 + }
82473 +
82474 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
82475 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
82476 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
82477 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82478 +
82479 + return 0;
82480 +}
82481 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
82482 new file mode 100644
82483 index 0000000..daaa86c
82484 --- /dev/null
82485 +++ b/tools/gcc/size_overflow_hash.data
82486 @@ -0,0 +1,2486 @@
82487 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
82488 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
82489 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
82490 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
82491 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
82492 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
82493 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
82494 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
82495 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
82496 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
82497 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
82498 +_000013_hash kmemdup 2 64015 _000013_hash NULL
82499 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
82500 +_000015_hash memdup_user 2 59590 _000015_hash NULL
82501 +_000016_hash module_alloc 1 63630 _000016_hash NULL
82502 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
82503 +_000018_hash read_kcore 3 63488 _000018_hash NULL
82504 +_000019_hash read_ldt 2 47570 _000019_hash NULL
82505 +_000020_hash read_zero 3 19366 _000020_hash NULL
82506 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
82507 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
82508 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
82509 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
82510 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
82511 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
82512 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
82513 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
82514 +_000029_hash adu_write 3 30487 _000029_hash NULL
82515 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
82516 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
82517 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
82518 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
82519 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
82520 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
82521 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
82522 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
82523 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
82524 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
82525 +_000041_hash alloc_context 1 3194 _000041_hash NULL
82526 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
82527 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
82528 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
82529 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
82530 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
82531 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
82532 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
82533 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
82534 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
82535 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
82536 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
82537 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
82538 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
82539 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
82540 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
82541 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
82542 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
82543 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
82544 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
82545 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
82546 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
82547 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
82548 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
82549 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
82550 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
82551 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
82552 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
82553 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
82554 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
82555 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
82556 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
82557 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
82558 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
82559 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
82560 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
82561 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
82562 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
82563 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
82564 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
82565 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
82566 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
82567 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
82568 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
82569 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
82570 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
82571 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
82572 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
82573 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
82574 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
82575 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
82576 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
82577 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
82578 +_000096_hash capi_write 3 35104 _000096_hash NULL
82579 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
82580 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
82581 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
82582 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
82583 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
82584 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
82585 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
82586 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
82587 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
82588 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
82589 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
82590 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
82591 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
82592 +_000111_hash change_xattr 5 61390 _000111_hash NULL
82593 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
82594 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
82595 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
82596 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
82597 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
82598 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
82599 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
82600 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
82601 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
82602 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
82603 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
82604 +_000123_hash cmm_write 3 2896 _000123_hash NULL
82605 +_000124_hash cm_write 3 36858 _000124_hash NULL
82606 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
82607 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
82608 +_000127_hash command_file_write 3 31318 _000127_hash NULL
82609 +_000128_hash command_write 3 58841 _000128_hash NULL
82610 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
82611 +_000130_hash concat_writev 3 21451 _000130_hash NULL
82612 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
82613 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
82614 +_000133_hash copy_items 6 50140 _000133_hash NULL
82615 +_000134_hash copy_macs 4 45534 _000134_hash NULL
82616 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
82617 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
82618 +_000137_hash cosa_write 3 1774 _000137_hash NULL
82619 +_000138_hash create_entry 2 33479 _000138_hash NULL
82620 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
82621 +_000141_hash create_xattr 5 54106 _000141_hash NULL
82622 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
82623 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
82624 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
82625 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
82626 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
82627 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
82628 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
82629 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
82630 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
82631 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
82632 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
82633 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
82634 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
82635 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
82636 +_000158_hash dev_config 3 8506 _000158_hash NULL
82637 +_000159_hash device_write 3 45156 _000159_hash NULL
82638 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
82639 +_000161_hash devres_alloc 2 551 _000161_hash NULL
82640 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
82641 +_000163_hash direct_entry 3 38836 _000163_hash NULL
82642 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
82643 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
82644 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
82645 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
82646 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
82647 +_000169_hash dm_read 3 15674 _000169_hash NULL
82648 +_000170_hash dm_write 3 2513 _000170_hash NULL
82649 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
82650 +_000172_hash dns_query 3 9676 _000172_hash NULL
82651 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
82652 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
82653 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
82654 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
82655 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
82656 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
82657 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
82658 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
82659 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
82660 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
82661 +_000183_hash dsp_write 2 46218 _000183_hash NULL
82662 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
82663 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
82664 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
82665 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
82666 +_000188_hash dvb_play 3 50814 _000188_hash NULL
82667 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
82668 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
82669 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
82670 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
82671 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
82672 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
82673 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
82674 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
82675 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
82676 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
82677 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
82678 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
82679 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
82680 +_000202_hash ep_read 3 58813 _000202_hash NULL
82681 +_000203_hash ep_write 3 59008 _000203_hash NULL
82682 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
82683 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
82684 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
82685 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
82686 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
82687 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
82688 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
82689 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
82690 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
82691 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
82692 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
82693 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
82694 +_000216_hash fl_create 5 56435 _000216_hash NULL
82695 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
82696 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
82697 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
82698 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
82699 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
82700 +_000222_hash get_arg 3 5694 _000222_hash NULL
82701 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
82702 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
82703 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
82704 +_000226_hash get_registers 3 26187 _000226_hash NULL
82705 +_000227_hash get_scq 2 10897 _000227_hash NULL
82706 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
82707 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
82708 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
82709 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
82710 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
82711 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
82712 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
82713 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
82714 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
82715 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
82716 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
82717 +_000239_hash handle_request 9 10024 _000239_hash NULL
82718 +_000240_hash hash_new 1 62224 _000240_hash NULL
82719 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
82720 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
82721 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
82722 +_000244_hash heap_init 2 49617 _000244_hash NULL
82723 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
82724 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
82725 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
82726 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
82727 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
82728 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
82729 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
82730 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
82731 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
82732 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
82733 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
82734 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
82735 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
82736 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
82737 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
82738 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
82739 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
82740 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
82741 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
82742 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
82743 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
82744 +_000266_hash ieee80211_build_probe_req 7 27660 _000266_hash NULL
82745 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
82746 +_000268_hash if_write 3 51756 _000268_hash NULL
82747 +_000269_hash ilo_write 3 64378 _000269_hash NULL
82748 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
82749 +_000271_hash init_data_container 1 60709 _000271_hash NULL
82750 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
82751 +_000273_hash insert_dent 7 65034 _000273_hash NULL
82752 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
82753 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
82754 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
82755 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
82756 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
82757 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
82758 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
82759 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
82760 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
82761 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
82762 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
82763 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
82764 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
82765 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
82766 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
82767 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
82768 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
82769 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
82770 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
82771 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
82772 +_000294_hash isdn_read 3 50021 _000294_hash NULL
82773 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
82774 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
82775 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
82776 +_000298_hash iso_callback 3 43208 _000298_hash NULL
82777 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
82778 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
82779 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
82780 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
82781 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
82782 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
82783 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
82784 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
82785 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
82786 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
82787 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
82788 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
82789 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
82790 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
82791 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
82792 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
82793 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
82794 +_000319_hash kone_receive 4 4690 _000319_hash NULL
82795 +_000320_hash kone_send 4 63435 _000320_hash NULL
82796 +_000321_hash krealloc 2 14908 _000321_hash NULL
82797 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
82798 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
82799 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
82800 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
82801 +_000326_hash kzalloc 1 54740 _000326_hash NULL
82802 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
82803 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
82804 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
82805 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
82806 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
82807 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
82808 +_000333_hash __lgread 4 31668 _000333_hash NULL
82809 +_000334_hash libipw_alloc_txb 1 27579 _000334_hash NULL
82810 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
82811 +_000336_hash listxattr 3 12769 _000336_hash NULL
82812 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
82813 +_000338_hash load_msg 2 95 _000338_hash NULL
82814 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
82815 +_000340_hash lp_write 3 9511 _000340_hash NULL
82816 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
82817 +_000342_hash mce_write 3 26201 _000342_hash NULL
82818 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
82819 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
82820 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
82821 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
82822 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
82823 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
82824 +_000350_hash mem_rw 3 22085 _000350_hash NULL
82825 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
82826 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
82827 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
82828 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
82829 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
82830 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
82831 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
82832 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
82833 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
82834 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
82835 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
82836 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
82837 +_000363_hash mtdchar_write 3 56831 _000363_hash NULL
82838 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
82839 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
82840 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
82841 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
82842 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
82843 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
82844 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
82845 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
82846 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
82847 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
82848 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
82849 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
82850 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
82851 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
82852 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
82853 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
82854 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
82855 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
82856 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
82857 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
82858 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
82859 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
82860 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
82861 +_000391_hash nvram_write 3 3894 _000391_hash NULL
82862 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
82863 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
82864 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
82865 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
82866 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
82867 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
82868 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
82869 +_000399_hash opticon_write 4 60775 _000399_hash NULL
82870 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
82871 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
82872 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
82873 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
82874 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
82875 +_000405_hash parse_command 2 37079 _000405_hash NULL
82876 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
82877 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
82878 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
82879 +_000409_hash pg_write 3 40766 _000409_hash NULL
82880 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
82881 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
82882 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
82883 +_000413_hash pkt_add 3 39897 _000413_hash NULL
82884 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
82885 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
82886 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
82887 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
82888 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
82889 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
82890 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
82891 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
82892 +_000422_hash ppp_write 3 34034 _000422_hash NULL
82893 +_000423_hash pp_read 3 33210 _000423_hash NULL
82894 +_000424_hash pp_write 3 39554 _000424_hash NULL
82895 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
82896 +_000426_hash printer_write 3 60276 _000426_hash NULL
82897 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
82898 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
82899 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
82900 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
82901 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
82902 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
82903 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
82904 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
82905 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
82906 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
82907 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
82908 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
82909 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
82910 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
82911 +_000442_hash pt_write 3 40159 _000442_hash NULL
82912 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
82913 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
82914 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
82915 +_000446_hash r3964_write 4 57662 _000446_hash NULL
82916 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
82917 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
82918 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
82919 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
82920 +_000451_hash rbd_add 3 16366 _000451_hash NULL
82921 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
82922 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
82923 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
82924 +_000455_hash read 3 9397 _000455_hash NULL
82925 +_000456_hash read_buf 2 20469 _000456_hash NULL
82926 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
82927 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
82928 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
82929 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
82930 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
82931 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
82932 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
82933 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
82934 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
82935 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
82936 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
82937 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
82938 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
82939 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
82940 +_000471_hash revalidate 2 19043 _000471_hash NULL
82941 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
82942 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
82943 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
82944 +_000475_hash rngapi_reset 3 34366 _000475_hash NULL
82945 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
82946 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
82947 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
82948 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
82949 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
82950 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
82951 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
82952 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
82953 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
82954 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
82955 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
82956 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
82957 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
82958 +_000489_hash savemem 3 58129 _000489_hash NULL
82959 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
82960 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
82961 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
82962 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
82963 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
82964 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
82965 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
82966 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
82967 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
82968 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
82969 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
82970 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
82971 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
82972 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
82973 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
82974 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
82975 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
82976 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
82977 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
82978 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
82979 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
82980 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
82981 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
82982 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
82983 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
82984 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
82985 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
82986 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
82987 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
82988 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
82989 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
82990 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
82991 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
82992 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
82993 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
82994 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
82995 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
82996 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
82997 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
82998 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
82999 +_000532_hash set_registers 3 53582 _000532_hash NULL
83000 +_000533_hash setsockopt 5 54539 _000533_hash NULL
83001 +_000534_hash setup_req 3 5848 _000534_hash NULL
83002 +_000535_hash setup_window 7 59178 _000535_hash NULL
83003 +_000536_hash setxattr 4 37006 _000536_hash NULL
83004 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
83005 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
83006 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
83007 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
83008 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
83009 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
83010 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
83011 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
83012 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
83013 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
83014 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
83015 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
83016 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
83017 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
83018 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
83019 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
83020 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
83021 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
83022 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
83023 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
83024 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
83025 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
83026 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
83027 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
83028 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
83029 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
83030 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
83031 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
83032 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
83033 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
83034 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
83035 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
83036 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
83037 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
83038 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
83039 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
83040 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
83041 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
83042 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
83043 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
83044 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
83045 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
83046 +_000581_hash spidev_write 3 44510 _000581_hash NULL
83047 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
83048 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
83049 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
83050 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
83051 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
83052 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
83053 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
83054 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
83055 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
83056 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
83057 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
83058 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
83059 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
83060 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
83061 +_000597_hash tower_write 3 8580 _000597_hash NULL
83062 +_000598_hash tpm_write 3 50798 _000598_hash NULL
83063 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
83064 +_000600_hash trusted_update 3 12664 _000600_hash NULL
83065 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
83066 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
83067 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
83068 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
83069 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
83070 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
83071 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
83072 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
83073 +_000609_hash uea_request 4 47613 _000609_hash NULL
83074 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
83075 +_000611_hash uio_write 3 43202 _000611_hash NULL
83076 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
83077 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
83078 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
83079 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
83080 +_000616_hash usblp_write 3 23178 _000616_hash NULL
83081 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
83082 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
83083 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
83084 +_000621_hash user_update 3 41332 _000621_hash NULL
83085 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
83086 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
83087 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
83088 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
83089 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
83090 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
83091 +_000629_hash vcs_write 3 3910 _000629_hash NULL
83092 +_000630_hash vfd_write 3 14717 _000630_hash NULL
83093 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
83094 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
83095 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
83096 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
83097 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
83098 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
83099 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
83100 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
83101 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
83102 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
83103 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
83104 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
83105 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
83106 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
83107 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
83108 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
83109 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
83110 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
83111 +_000651_hash wdm_write 3 53735 _000651_hash NULL
83112 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
83113 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
83114 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
83115 +_000655_hash write 3 62671 _000655_hash NULL
83116 +_000656_hash write_flush 3 50803 _000656_hash NULL
83117 +_000657_hash write_rio 3 54837 _000657_hash NULL
83118 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
83119 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
83120 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
83121 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
83122 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
83123 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
83124 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
83125 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
83126 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
83127 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
83128 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
83129 +_000669_hash zoran_write 3 22404 _000669_hash NULL
83130 +_000671_hash acpi_ex_allocate_name_string 2 7685 _000671_hash NULL
83131 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
83132 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
83133 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
83134 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
83135 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
83136 +_000677_hash add_res_range 4 21310 _000677_hash NULL
83137 +_000678_hash addtgt 3 54703 _000678_hash NULL
83138 +_000679_hash add_uuid 4 49831 _000679_hash NULL
83139 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
83140 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
83141 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
83142 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
83143 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
83144 +_000685_hash alloc_async 1 14208 _000685_hash NULL
83145 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
83146 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
83147 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
83148 +_000689_hash alloc_context 1 41283 _000689_hash NULL
83149 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
83150 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
83151 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
83152 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
83153 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
83154 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
83155 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
83156 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
83157 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
83158 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
83159 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
83160 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
83161 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
83162 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
83163 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
83164 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
83165 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
83166 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
83167 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
83168 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
83169 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
83170 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
83171 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
83172 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
83173 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
83174 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
83175 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
83176 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
83177 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
83178 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
83179 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
83180 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
83181 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
83182 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
83183 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
83184 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
83185 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
83186 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
83187 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
83188 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
83189 +_000736_hash ati_create_gatt_pages 1 4722 _000736_hash NULL
83190 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
83191 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
83192 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
83193 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
83194 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
83195 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
83196 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
83197 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
83198 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
83199 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
83200 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
83201 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
83202 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
83203 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
83204 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
83205 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
83206 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
83207 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
83208 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
83209 +_000759_hash ca_extend 2 64541 _000759_hash NULL
83210 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
83211 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
83212 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
83213 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
83214 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
83215 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
83216 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
83217 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
83218 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
83219 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
83220 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
83221 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
83222 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
83223 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
83224 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
83225 +_000778_hash cifs_writedata_alloc 1 32880 _000778_hash NULL
83226 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
83227 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
83228 +_000781_hash construct_key 3 11329 _000781_hash NULL
83229 +_000782_hash context_alloc 3 24645 _000782_hash NULL
83230 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
83231 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
83232 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
83233 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
83234 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
83235 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
83236 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
83237 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
83238 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
83239 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
83240 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
83241 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
83242 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
83243 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
83244 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
83245 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
83246 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
83247 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
83248 +_000805_hash depth_write 3 3021 _000805_hash NULL
83249 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
83250 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
83251 +_000808_hash dev_write 3 7708 _000808_hash NULL
83252 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
83253 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
83254 +_000811_hash disconnect 4 32521 _000811_hash NULL
83255 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
83256 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
83257 +_000815_hash do_dccp_setsockopt 5 54377 _000815_hash NULL
83258 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
83259 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
83260 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
83261 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
83262 +_000820_hash do_sync 1 9604 _000820_hash NULL
83263 +_000821_hash dup_array 3 33551 _000821_hash NULL
83264 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
83265 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
83266 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
83267 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
83268 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
83269 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
83270 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
83271 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
83272 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
83273 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
83274 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
83275 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
83276 +_000834_hash enable_write 3 30456 _000834_hash NULL
83277 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
83278 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
83279 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
83280 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
83281 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
83282 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
83283 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
83284 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
83285 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
83286 +_000844_hash fillonedir 3 41746 _000844_hash NULL
83287 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
83288 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
83289 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
83290 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
83291 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
83292 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
83293 +_000851_hash get_entry 4 16003 _000851_hash NULL
83294 +_000852_hash get_free_de 2 33714 _000852_hash NULL
83295 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
83296 +_000854_hash getxattr 4 24398 _000854_hash NULL
83297 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
83298 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
83299 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
83300 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
83301 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
83302 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
83303 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
83304 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
83305 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
83306 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
83307 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
83308 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
83309 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
83310 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
83311 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
83312 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
83313 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
83314 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
83315 +_000876_hash ieee80211_send_probe_req 6 6924 _000876_hash NULL
83316 +_000877_hash if_writecmd 2 815 _000877_hash NULL
83317 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
83318 +_000880_hash init_ipath 1 48187 _000880_hash NULL
83319 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
83320 +_000883_hash init_q 4 132 _000883_hash NULL
83321 +_000884_hash init_state 2 60165 _000884_hash NULL
83322 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
83323 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
83324 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
83325 +_000888_hash interfaces 2 38859 _000888_hash NULL
83326 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
83327 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
83328 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
83329 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
83330 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
83331 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
83332 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
83333 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
83334 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
83335 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
83336 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
83337 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
83338 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
83339 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
83340 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
83341 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
83342 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
83343 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
83344 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
83345 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
83346 +_000911_hash isdn_write 3 45863 _000911_hash NULL
83347 +_000912_hash isku_receive 4 54130 _000912_hash NULL
83348 +_000913_hash isku_send 4 41542 _000913_hash NULL
83349 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
83350 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
83351 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
83352 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
83353 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
83354 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
83355 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
83356 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
83357 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
83358 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
83359 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
83360 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
83361 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
83362 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
83363 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
83364 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
83365 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
83366 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
83367 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
83368 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
83369 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
83370 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
83371 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
83372 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
83373 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
83374 +_000940_hash kvm_write_guest_page 5 63555 _000940_hash NULL
83375 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
83376 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
83377 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
83378 +_000945_hash lc_create 3 48662 _000945_hash NULL
83379 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
83380 +_000947_hash linear_conf 2 23485 _000947_hash NULL
83381 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
83382 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
83383 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
83384 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
83385 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
83386 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
83387 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
83388 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
83389 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
83390 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
83391 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
83392 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
83393 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
83394 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
83395 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
83396 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
83397 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
83398 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
83399 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
83400 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
83401 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
83402 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
83403 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
83404 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
83405 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
83406 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
83407 +_000977_hash new_dir 3 31919 _000977_hash NULL
83408 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
83409 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
83410 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
83411 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
83412 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
83413 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
83414 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
83415 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
83416 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
83417 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
83418 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
83419 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
83420 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
83421 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
83422 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
83423 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
83424 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
83425 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
83426 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
83427 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
83428 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
83429 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
83430 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
83431 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
83432 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
83433 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
83434 +_001008_hash osst_write 3 31581 _001008_hash NULL
83435 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
83436 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
83437 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
83438 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
83439 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
83440 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
83441 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
83442 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
83443 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
83444 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
83445 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
83446 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
83447 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
83448 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
83449 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
83450 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
83451 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
83452 +_001030_hash play_iframe 3 8219 _001030_hash NULL
83453 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
83454 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
83455 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
83456 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
83457 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
83458 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
83459 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
83460 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
83461 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
83462 +_001042_hash proc_write 3 51003 _001042_hash NULL
83463 +_001043_hash profile_load 3 58267 _001043_hash NULL
83464 +_001044_hash profile_remove 3 8556 _001044_hash NULL
83465 +_001045_hash profile_replace 3 14652 _001045_hash NULL
83466 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
83467 +_001047_hash pyra_send 4 12061 _001047_hash NULL
83468 +_001048_hash qc_capture 3 19298 _001048_hash NULL
83469 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
83470 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
83471 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
83472 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
83473 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
83474 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
83475 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
83476 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
83477 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
83478 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
83479 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
83480 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
83481 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
83482 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
83483 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
83484 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
83485 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
83486 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
83487 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
83488 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
83489 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
83490 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
83491 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
83492 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
83493 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
83494 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
83495 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
83496 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
83497 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
83498 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
83499 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
83500 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
83501 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
83502 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
83503 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
83504 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
83505 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
83506 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
83507 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
83508 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
83509 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
83510 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
83511 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
83512 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
83513 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
83514 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
83515 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
83516 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
83517 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
83518 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
83519 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
83520 +_001102_hash set_connectable 4 56458 _001102_hash NULL
83521 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
83522 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
83523 +_001105_hash setkey 3 14987 _001105_hash NULL
83524 +_001106_hash set_le 4 30581 _001106_hash NULL
83525 +_001107_hash set_link_security 4 4502 _001107_hash NULL
83526 +_001108_hash set_local_name 4 55757 _001108_hash NULL
83527 +_001109_hash set_powered 4 12129 _001109_hash NULL
83528 +_001110_hash set_ssp 4 62411 _001110_hash NULL
83529 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
83530 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
83531 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
83532 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
83533 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
83534 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
83535 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
83536 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
83537 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
83538 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
83539 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
83540 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
83541 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
83542 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
83543 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
83544 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
83545 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
83546 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
83547 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
83548 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
83549 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
83550 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
83551 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
83552 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
83553 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
83554 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
83555 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
83556 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
83557 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
83558 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
83559 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
83560 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
83561 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
83562 +_001148_hash sound_write 3 5102 _001148_hash NULL
83563 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
83564 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
83565 +_001151_hash spidev_message 3 5518 _001151_hash NULL
83566 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
83567 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
83568 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
83569 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
83570 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
83571 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
83572 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
83573 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
83574 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
83575 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
83576 +_001163_hash st_write 3 16874 _001163_hash NULL
83577 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
83578 +_001165_hash symtab_init 2 61050 _001165_hash NULL
83579 +_001166_hash sys_bind 3 10799 _001166_hash NULL
83580 +_001167_hash sys_connect 3 15291 _001167_hash NULL
83581 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
83582 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
83583 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
83584 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
83585 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
83586 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
83587 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
83588 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
83589 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
83590 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
83591 +_001178_hash sys_semop 3 39457 _001178_hash NULL
83592 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
83593 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
83594 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
83595 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
83596 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
83597 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
83598 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
83599 +_001186_hash timeout_write 3 50991 _001186_hash NULL
83600 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
83601 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
83602 +_001189_hash tm6000_read_write_usb 7 50774 _001189_hash NULL
83603 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
83604 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
83605 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
83606 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
83607 +_001195_hash ts_write 3 64336 _001195_hash NULL
83608 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
83609 +_001197_hash tty_write 3 5494 _001197_hash NULL
83610 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
83611 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
83612 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
83613 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
83614 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
83615 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
83616 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
83617 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
83618 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
83619 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
83620 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
83621 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
83622 +_001211_hash uvc_alloc_entity 3 20836 _001211_hash NULL
83623 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
83624 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
83625 +_001214_hash vb2_read 3 42703 _001214_hash NULL
83626 +_001215_hash vb2_write 3 31948 _001215_hash NULL
83627 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
83628 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
83629 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
83630 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
83631 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
83632 +_001223_hash vmalloc 1 15464 _001223_hash NULL
83633 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
83634 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
83635 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
83636 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
83637 +_001228_hash vzalloc 1 47421 _001228_hash NULL
83638 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
83639 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
83640 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
83641 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
83642 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
83643 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
83644 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
83645 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
83646 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
83647 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
83648 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
83649 +_001240_hash xfs_dir_cilookup_result 3 64288 _001240_hash NULL
83650 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
83651 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
83652 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
83653 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
83654 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
83655 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
83656 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
83657 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
83658 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
83659 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
83660 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
83661 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
83662 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
83663 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
83664 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
83665 +_001256_hash add_child 4 45201 _001256_hash NULL
83666 +_001257_hash add_port 2 54941 _001257_hash NULL
83667 +_001258_hash adu_read 3 24177 _001258_hash NULL
83668 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
83669 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
83670 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
83671 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
83672 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
83673 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
83674 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
83675 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
83676 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
83677 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
83678 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
83679 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
83680 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
83681 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
83682 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
83683 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
83684 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
83685 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
83686 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
83687 +_001280_hash async_setkey 3 35521 _001280_hash NULL
83688 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
83689 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
83690 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
83691 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
83692 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
83693 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
83694 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
83695 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
83696 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
83697 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
83698 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
83699 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
83700 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
83701 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
83702 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
83703 +_001298_hash bm_init 2 13529 _001298_hash NULL
83704 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
83705 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
83706 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
83707 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
83708 +_001303_hash cache_read 3 24790 _001303_hash NULL
83709 +_001304_hash cache_write 3 13589 _001304_hash NULL
83710 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
83711 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
83712 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
83713 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
83714 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
83715 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
83716 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
83717 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
83718 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
83719 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
83720 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
83721 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
83722 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
83723 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
83724 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
83725 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
83726 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
83727 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
83728 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
83729 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
83730 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
83731 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
83732 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
83733 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
83734 +_001331_hash dev_read 3 56369 _001331_hash NULL
83735 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
83736 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
83737 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
83738 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
83739 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
83740 +_001338_hash do_readlink 2 43518 _001338_hash NULL
83741 +_001339_hash __do_replace 5 37227 _001339_hash NULL
83742 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
83743 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
83744 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
83745 +_001343_hash dump_midi 3 51040 _001343_hash NULL
83746 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
83747 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
83748 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5 4303 _001346_hash NULL
83749 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
83750 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
83751 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
83752 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
83753 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
83754 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
83755 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
83756 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
83757 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
83758 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
83759 +_001358_hash filldir 3 55137 _001358_hash NULL
83760 +_001359_hash filldir64 3 46469 _001359_hash NULL
83761 +_001360_hash fops_read 3 40672 _001360_hash NULL
83762 +_001361_hash from_buffer 3 18625 _001361_hash NULL
83763 +_001362_hash fsm_init 2 16134 _001362_hash NULL
83764 +_001363_hash get_subdir 3 62581 _001363_hash NULL
83765 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
83766 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
83767 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
83768 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
83769 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
83770 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
83771 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
83772 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
83773 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
83774 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
83775 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
83776 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
83777 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
83778 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
83779 +_001379_hash ilo_read 3 32531 _001379_hash NULL
83780 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
83781 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
83782 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
83783 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
83784 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
83785 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
83786 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
83787 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
83788 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
83789 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
83790 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
83791 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
83792 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
83793 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
83794 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
83795 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
83796 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
83797 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
83798 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
83799 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
83800 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
83801 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
83802 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
83803 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
83804 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
83805 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
83806 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
83807 +_001412_hash keyring_read 3 13438 _001412_hash NULL
83808 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
83809 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
83810 +_001415_hash kmp_init 2 41373 _001415_hash NULL
83811 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
83812 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
83813 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
83814 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
83815 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
83816 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
83817 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
83818 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
83819 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
83820 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
83821 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
83822 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
83823 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
83824 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
83825 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
83826 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
83827 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
83828 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
83829 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
83830 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
83831 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
83832 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
83833 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
83834 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
83835 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
83836 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
83837 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
83838 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
83839 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
83840 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
83841 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
83842 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
83843 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
83844 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
83845 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
83846 +_001454_hash override_release 2 52032 _001454_hash NULL
83847 +_001455_hash packet_snd 3 13634 _001455_hash NULL
83848 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
83849 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
83850 +_001458_hash pg_read 3 17276 _001458_hash NULL
83851 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
83852 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
83853 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
83854 +_001462_hash pms_capture 4 27142 _001462_hash NULL
83855 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
83856 +_001464_hash printer_read 3 54851 _001464_hash NULL
83857 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
83858 +_001466_hash pt_read 3 49136 _001466_hash NULL
83859 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
83860 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
83861 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
83862 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
83863 +_001471_hash qcam_read 3 13977 _001471_hash NULL
83864 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
83865 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
83866 +_001474_hash read_flush 3 43851 _001474_hash NULL
83867 +_001475_hash read_profile 3 27859 _001475_hash NULL
83868 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
83869 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
83870 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
83871 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
83872 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
83873 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
83874 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
83875 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
83876 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
83877 +_001486_hash roccat_read 3 41093 _001486_hash NULL
83878 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
83879 +_001488_hash scsi_register 2 49094 _001488_hash NULL
83880 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
83881 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
83882 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
83883 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
83884 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
83885 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
83886 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
83887 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
83888 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
83889 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
83890 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
83891 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
83892 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
83893 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
83894 +_001503_hash set_arg 3 42824 _001503_hash NULL
83895 +_001504_hash sg_read 3 25799 _001504_hash NULL
83896 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
83897 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
83898 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
83899 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
83900 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
83901 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
83902 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
83903 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
83904 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
83905 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
83906 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
83907 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
83908 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
83909 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
83910 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
83911 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
83912 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
83913 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
83914 +_001525_hash store_msg 3 56417 _001525_hash NULL
83915 +_001526_hash str_to_user 2 11411 _001526_hash NULL
83916 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
83917 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
83918 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
83919 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
83920 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
83921 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
83922 +_001533_hash sys_process_vm_readv 3-5 19090 _001533_hash NULL
83923 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
83924 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
83925 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
83926 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
83927 +_001540_hash team_options_register 3 20091 _001540_hash NULL
83928 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
83929 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
83930 +_001543_hash tipc_send 4 51238 _001543_hash NULL
83931 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
83932 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
83933 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
83934 +_001547_hash tnode_new 3 44757 _001547_hash NULL
83935 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
83936 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
83937 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
83938 +_001551_hash tpm_read 3 50344 _001551_hash NULL
83939 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
83940 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
83941 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
83942 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
83943 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
83944 +_001558_hash uio_read 3 49300 _001558_hash NULL
83945 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
83946 +_001560_hash unlink1 3 63059 _001560_hash NULL
83947 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
83948 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
83949 +_001564_hash usblp_read 3 57342 _001564_hash NULL
83950 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
83951 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
83952 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
83953 +_001568_hash user_read 3 51881 _001568_hash NULL
83954 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
83955 +_001570_hash vcs_read 3 8017 _001570_hash NULL
83956 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
83957 +_001572_hash venus_create 4 20555 _001572_hash NULL
83958 +_001573_hash venus_link 5 32165 _001573_hash NULL
83959 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
83960 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
83961 +_001576_hash venus_remove 4 59781 _001576_hash NULL
83962 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
83963 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
83964 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
83965 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
83966 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
83967 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
83968 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
83969 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
83970 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
83971 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
83972 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
83973 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
83974 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
83975 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
83976 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
83977 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
83978 +_001596_hash wdm_read 3 6549 _001596_hash NULL
83979 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
83980 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
83981 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
83982 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
83983 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
83984 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
83985 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
83986 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
83987 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
83988 +_001606_hash xz_dec_lzma2_create 2 36353 _001606_hash NULL
83989 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
83990 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
83991 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
83992 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
83993 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
83994 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
83995 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
83996 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
83997 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
83998 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
83999 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
84000 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
84001 +_001619_hash __alloc_bootmem_low 1 43423 _001619_hash NULL
84002 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
84003 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
84004 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
84005 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
84006 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
84007 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
84008 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
84009 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
84010 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
84011 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
84012 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
84013 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
84014 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
84015 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
84016 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
84017 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
84018 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
84019 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
84020 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
84021 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
84022 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
84023 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
84024 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
84025 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
84026 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
84027 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
84028 +_001648_hash blk_queue_init_tags 2 44355 _001648_hash NULL
84029 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
84030 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
84031 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
84032 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
84033 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
84034 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
84035 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
84036 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
84037 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
84038 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
84039 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
84040 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
84041 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
84042 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
84043 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
84044 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
84045 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
84046 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
84047 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
84048 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
84049 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
84050 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
84051 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
84052 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
84053 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
84054 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
84055 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
84056 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
84057 +_001677_hash create_subvol 4 2347 _001677_hash NULL
84058 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
84059 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
84060 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
84061 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
84062 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
84063 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
84064 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
84065 +_001687_hash debug_output 3 18575 _001687_hash NULL
84066 +_001688_hash debug_read 3 19322 _001688_hash NULL
84067 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
84068 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
84069 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
84070 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
84071 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
84072 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
84073 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
84074 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
84075 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
84076 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
84077 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
84078 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
84079 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
84080 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
84081 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
84082 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
84083 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
84084 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
84085 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
84086 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
84087 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
84088 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
84089 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
84090 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
84091 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
84092 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
84093 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
84094 +_001716_hash filter_read 3 61692 _001716_hash NULL
84095 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
84096 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
84097 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
84098 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
84099 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
84100 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
84101 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
84102 +_001724_hash ht40allow_map_read 3 55209 _001724_hash NULL
84103 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
84104 +_001726_hash hysdn_conf_read 3 42324 _001726_hash NULL
84105 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
84106 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
84107 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
84108 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
84109 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
84110 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
84111 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
84112 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
84113 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
84114 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
84115 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
84116 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
84117 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
84118 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
84119 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
84120 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
84121 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
84122 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
84123 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
84124 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
84125 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
84126 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
84127 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
84128 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
84129 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
84130 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
84131 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
84132 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
84133 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
84134 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
84135 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
84136 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
84137 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
84138 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
84139 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
84140 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
84141 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
84142 +_001765_hash ipw_write 3 59807 _001765_hash NULL
84143 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
84144 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
84145 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
84146 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
84147 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
84148 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
84149 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
84150 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
84151 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
84152 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
84153 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
84154 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
84155 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
84156 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
84157 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
84158 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
84159 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
84160 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
84161 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
84162 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
84163 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
84164 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
84165 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
84166 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
84167 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
84168 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
84169 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
84170 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
84171 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
84172 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
84173 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
84174 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
84175 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
84176 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
84177 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
84178 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
84179 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
84180 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
84181 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
84182 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
84183 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
84184 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
84185 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _001808_hash NULL
84186 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
84187 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
84188 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
84189 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
84190 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
84191 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
84192 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
84193 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
84194 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
84195 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
84196 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
84197 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
84198 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
84199 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
84200 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
84201 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
84202 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
84203 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
84204 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
84205 +_001828_hash key_key_read 3 3241 _001828_hash NULL
84206 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
84207 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
84208 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
84209 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
84210 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
84211 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
84212 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
84213 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
84214 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
84215 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
84216 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
84217 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
84218 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
84219 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
84220 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
84221 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
84222 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
84223 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
84224 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
84225 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
84226 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
84227 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
84228 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
84229 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
84230 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
84231 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
84232 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
84233 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
84234 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
84235 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
84236 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
84237 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
84238 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
84239 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
84240 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
84241 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
84242 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
84243 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
84244 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
84245 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
84246 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
84247 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
84248 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
84249 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
84250 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
84251 +_001876_hash nfsd_vfs_read 6 62605 _001876_hash NULL
84252 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
84253 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
84254 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
84255 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
84256 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
84257 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
84258 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
84259 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
84260 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
84261 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
84262 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
84263 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
84264 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
84265 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
84266 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
84267 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
84268 +_001893_hash page_readlink 3 23346 _001893_hash NULL
84269 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
84270 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
84271 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
84272 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
84273 +_001898_hash pms_read 3 53873 _001898_hash NULL
84274 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
84275 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
84276 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
84277 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
84278 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
84279 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
84280 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
84281 +_001906_hash proc_read 3 43614 _001906_hash NULL
84282 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
84283 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
84284 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
84285 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
84286 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
84287 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
84288 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
84289 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
84290 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
84291 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
84292 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
84293 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
84294 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
84295 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
84296 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
84297 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
84298 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
84299 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
84300 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
84301 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
84302 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
84303 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
84304 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
84305 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
84306 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
84307 +_001932_hash queues_read 3 24877 _001932_hash NULL
84308 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
84309 +_001934_hash rcname_read 3 25919 _001934_hash NULL
84310 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
84311 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
84312 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
84313 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
84314 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
84315 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
84316 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
84317 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
84318 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
84319 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
84320 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
84321 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
84322 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
84323 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
84324 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
84325 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
84326 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
84327 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
84328 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
84329 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
84330 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
84331 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
84332 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
84333 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
84334 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
84335 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
84336 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
84337 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
84338 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
84339 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
84340 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
84341 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
84342 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
84343 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
84344 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
84345 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
84346 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
84347 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
84348 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
84349 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
84350 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
84351 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
84352 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
84353 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
84354 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
84355 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
84356 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
84357 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
84358 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
84359 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
84360 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
84361 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
84362 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
84363 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
84364 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _001989_hash NULL
84365 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
84366 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
84367 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
84368 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
84369 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
84370 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
84371 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
84372 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
84373 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
84374 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
84375 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
84376 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
84377 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
84378 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
84379 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
84380 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
84381 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
84382 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
84383 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
84384 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
84385 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
84386 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
84387 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
84388 +_002014_hash send_msg 4 37323 _002014_hash NULL
84389 +_002015_hash send_packet 4 52960 _002015_hash NULL
84390 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
84391 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
84392 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
84393 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
84394 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
84395 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
84396 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
84397 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
84398 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
84399 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
84400 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
84401 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
84402 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
84403 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
84404 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
84405 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
84406 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
84407 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
84408 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
84409 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
84410 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
84411 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
84412 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
84413 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
84414 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
84415 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
84416 +_002045_hash st_read 3 51251 _002045_hash NULL
84417 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
84418 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
84419 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
84420 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
84421 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
84422 +_002051_hash sys_readv 3 50664 _002051_hash NULL
84423 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
84424 +_002053_hash sys_writev 3 28384 _002053_hash NULL
84425 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
84426 +_002055_hash ts_read 3 44687 _002055_hash NULL
84427 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
84428 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
84429 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
84430 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
84431 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
84432 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
84433 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
84434 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
84435 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
84436 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
84437 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
84438 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
84439 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
84440 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
84441 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
84442 +_002074_hash waiters_read 3 40902 _002074_hash NULL
84443 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
84444 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
84445 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
84446 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
84447 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
84448 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
84449 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
84450 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
84451 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
84452 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
84453 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
84454 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
84455 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
84456 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
84457 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
84458 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
84459 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
84460 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
84461 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
84462 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
84463 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
84464 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
84465 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
84466 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
84467 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
84468 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
84469 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
84470 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
84471 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
84472 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
84473 +_002106_hash cx18_read 3 23699 _002106_hash NULL
84474 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
84475 +_002108_hash depth_read 3 31112 _002108_hash NULL
84476 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
84477 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
84478 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
84479 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
84480 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
84481 +_002115_hash enable_read 3 2117 _002115_hash NULL
84482 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
84483 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
84484 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
84485 +_002119_hash frequency_read 3 64031 _002119_hash NULL
84486 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
84487 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
84488 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
84489 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
84490 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
84491 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
84492 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
84493 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
84494 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
84495 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
84496 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
84497 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
84498 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
84499 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
84500 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
84501 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
84502 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
84503 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
84504 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
84505 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
84506 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
84507 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
84508 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
84509 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
84510 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
84511 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
84512 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
84513 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
84514 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
84515 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
84516 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
84517 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
84518 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
84519 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
84520 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
84521 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
84522 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
84523 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002157_hash NULL
84524 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
84525 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
84526 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
84527 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
84528 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
84529 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
84530 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
84531 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
84532 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
84533 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
84534 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
84535 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
84536 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
84537 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
84538 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
84539 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
84540 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
84541 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
84542 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
84543 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
84544 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
84545 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
84546 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
84547 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
84548 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
84549 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
84550 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
84551 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
84552 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
84553 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
84554 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
84555 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
84556 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
84557 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
84558 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
84559 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
84560 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
84561 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
84562 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
84563 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
84564 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
84565 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
84566 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
84567 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
84568 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
84569 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
84570 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
84571 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
84572 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
84573 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
84574 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
84575 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
84576 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
84577 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
84578 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
84579 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
84580 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
84581 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
84582 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
84583 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
84584 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
84585 +_002220_hash power_read 3 15939 _002220_hash NULL
84586 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
84587 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
84588 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
84589 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
84590 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
84591 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
84592 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
84593 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
84594 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
84595 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
84596 +_002231_hash read_tree_block 3 841 _002231_hash NULL
84597 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
84598 +_002234_hash recv_msg 4 48709 _002234_hash NULL
84599 +_002235_hash recv_stream 4 30138 _002235_hash NULL
84600 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
84601 +_002237_hash request_key_async 4 6990 _002237_hash NULL
84602 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
84603 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
84604 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
84605 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
84606 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
84607 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
84608 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
84609 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
84610 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
84611 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
84612 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
84613 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
84614 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
84615 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
84616 +_002252_hash send_stream 4 3397 _002252_hash NULL
84617 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
84618 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
84619 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
84620 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
84621 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
84622 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
84623 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
84624 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
84625 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
84626 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
84627 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
84628 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
84629 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
84630 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
84631 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
84632 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
84633 +_002270_hash timeout_read 3 47915 _002270_hash NULL
84634 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
84635 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
84636 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
84637 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
84638 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
84639 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
84640 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
84641 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
84642 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
84643 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
84644 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
84645 +_002283_hash user_power_read 3 39414 _002283_hash NULL
84646 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
84647 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
84648 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
84649 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
84650 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
84651 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
84652 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
84653 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
84654 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
84655 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
84656 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
84657 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
84658 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
84659 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
84660 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
84661 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
84662 +_002300_hash spi_execute 5 28736 _002300_hash NULL
84663 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
84664 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
84665 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
84666 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
84667 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
84668 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
84669 +_002308_hash write_leb 5 36957 _002308_hash NULL
84670 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
84671 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
84672 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
84673 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
84674 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
84675 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
84676 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
84677 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
84678 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
84679 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
84680 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
84681 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
84682 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
84683 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
84684 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
84685 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
84686 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
84687 +_002329_hash recover_head 3 17904 _002329_hash NULL
84688 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
84689 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
84690 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
84691 +_002334_hash amthi_read 4 45831 _002334_hash NULL
84692 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
84693 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
84694 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
84695 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
84696 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
84697 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
84698 +_002341_hash card_send_command 3 40757 _002341_hash NULL
84699 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
84700 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
84701 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
84702 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
84703 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
84704 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
84705 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
84706 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
84707 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
84708 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
84709 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
84710 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
84711 +_002354_hash fir16_create 3 5574 _002354_hash NULL
84712 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
84713 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
84714 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
84715 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
84716 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
84717 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
84718 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
84719 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
84720 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
84721 +_002365_hash keymap_store 4 45406 _002365_hash NULL
84722 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
84723 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
84724 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
84725 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
84726 +_002370_hash lirc_write 3 20604 _002370_hash NULL
84727 +_002371_hash _malloc 1 54077 _002371_hash NULL
84728 +_002372_hash mei_read 3 6507 _002372_hash NULL
84729 +_002373_hash mei_write 3 4005 _002373_hash NULL
84730 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
84731 +_002375_hash msg_set 3 51725 _002375_hash NULL
84732 +_002376_hash newpart 6 47485 _002376_hash NULL
84733 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
84734 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
84735 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
84736 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
84737 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
84738 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
84739 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
84740 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
84741 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
84742 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
84743 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
84744 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
84745 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
84746 +_002393_hash sep_read 3 17161 _002393_hash NULL
84747 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
84748 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
84749 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
84750 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
84751 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
84752 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
84753 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
84754 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
84755 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
84756 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
84757 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
84758 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
84759 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
84760 +_002411_hash mempool_create 1 29437 _002411_hash NULL
84761 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
84762 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
84763 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
84764 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
84765 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
84766 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
84767 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
84768 +_002419_hash add_partition 2 55588 _002419_hash NULL
84769 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
84770 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
84771 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
84772 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
84773 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
84774 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
84775 +_002427_hash bioset_create 1 5580 _002427_hash NULL
84776 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
84777 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
84778 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
84779 +_002431_hash prison_create 1 43623 _002431_hash NULL
84780 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
84781 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
84782 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
84783 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
84784 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
84785 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
84786 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
84787 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
84788 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
84789 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
84790 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
84791 +_002443_hash comedi_read 3 13199 _002443_hash NULL
84792 +_002444_hash comedi_write 3 47926 _002444_hash NULL
84793 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
84794 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
84795 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
84796 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
84797 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
84798 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
84799 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
84800 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
84801 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
84802 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
84803 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
84804 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
84805 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
84806 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
84807 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
84808 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
84809 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
84810 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
84811 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
84812 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
84813 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
84814 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
84815 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
84816 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
84817 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
84818 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
84819 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
84820 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
84821 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
84822 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
84823 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
84824 +_002476_hash flash_read 3 57843 _002476_hash NULL
84825 +_002477_hash flash_write 3 62354 _002477_hash NULL
84826 +_002478_hash gather_array 3 56641 _002478_hash NULL
84827 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
84828 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
84829 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
84830 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
84831 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
84832 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
84833 +_002486_hash ieee80211_alloc_txb 1 52477 _002486_hash NULL
84834 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
84835 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
84836 +_002489_hash init_cdev 1 8274 _002489_hash NULL
84837 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
84838 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
84839 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
84840 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
84841 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
84842 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
84843 +_002496_hash options_write 3 47243 _002496_hash NULL
84844 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
84845 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
84846 +_002499_hash portnames_read 3 41958 _002499_hash NULL
84847 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
84848 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
84849 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
84850 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
84851 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
84852 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
84853 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
84854 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
84855 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
84856 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
84857 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
84858 +_002511_hash queue_reply 3 22416 _002511_hash NULL
84859 +_002512_hash Realloc 2 34961 _002512_hash NULL
84860 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
84861 +_002514_hash rtllib_alloc_txb 1 21687 _002514_hash NULL
84862 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
84863 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
84864 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
84865 +_002518_hash split 2 11691 _002518_hash NULL
84866 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
84867 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
84868 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
84869 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
84870 +_002523_hash tunables_read 3 36385 _002523_hash NULL
84871 +_002524_hash tunables_write 3 59563 _002524_hash NULL
84872 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
84873 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
84874 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
84875 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
84876 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
84877 +_002530_hash xsd_read 3 15653 _002530_hash NULL
84878 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
84879 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _002532_hash NULL
84880 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
84881 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
84882 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
84883 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
84884 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
84885 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
84886 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
84887 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
84888 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
84889 +_002546_hash compat_readv 3 30273 _002546_hash NULL
84890 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
84891 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
84892 +_002551_hash compat_writev 3 60063 _002551_hash NULL
84893 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
84894 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
84895 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
84896 +_002555_hash xd_rw 4 49020 _002555_hash NULL
84897 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
84898 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
84899 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
84900 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
84901 +_002560_hash ms_rw 4 17220 _002560_hash NULL
84902 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
84903 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
84904 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
84905 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
84906 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
84907 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
84908 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
84909 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
84910 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
84911 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
84912 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
84913 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
84914 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
84915 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
84916 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
84917 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
84918 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
84919 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
84920 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
84921 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
84922 +_002584_hash fb_read 3 33506 _002584_hash NULL
84923 +_002585_hash fb_write 3 46924 _002585_hash NULL
84924 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
84925 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
84926 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
84927 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
84928 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
84929 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
84930 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
84931 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
84932 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
84933 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
84934 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
84935 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
84936 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
84937 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
84938 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
84939 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
84940 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
84941 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
84942 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
84943 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
84944 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
84945 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
84946 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
84947 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
84948 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
84949 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
84950 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
84951 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
84952 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
84953 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
84954 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
84955 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
84956 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
84957 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
84958 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
84959 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
84960 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
84961 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
84962 +_002626_hash create_table 2 16213 _002626_hash NULL
84963 +_002627_hash mem_read 3 57631 _002627_hash NULL
84964 +_002628_hash mem_write 3 22232 _002628_hash NULL
84965 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
84966 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
84967 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
84968 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
84969 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
84970 +_002634_hash acl_alloc 1 35979 _002634_hash NULL
84971 +_002635_hash acl_alloc_stack_init 1 60630 _002635_hash NULL
84972 +_002636_hash acl_alloc_num 1-2 60778 _002636_hash NULL
84973 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84974 new file mode 100644
84975 index 0000000..cc96254
84976 --- /dev/null
84977 +++ b/tools/gcc/size_overflow_plugin.c
84978 @@ -0,0 +1,1204 @@
84979 +/*
84980 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84981 + * Licensed under the GPL v2, or (at your option) v3
84982 + *
84983 + * Homepage:
84984 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84985 + *
84986 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84987 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84988 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
84989 + *
84990 + * Usage:
84991 + * $ 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
84992 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84993 + */
84994 +
84995 +#include "gcc-plugin.h"
84996 +#include "config.h"
84997 +#include "system.h"
84998 +#include "coretypes.h"
84999 +#include "tree.h"
85000 +#include "tree-pass.h"
85001 +#include "intl.h"
85002 +#include "plugin-version.h"
85003 +#include "tm.h"
85004 +#include "toplev.h"
85005 +#include "function.h"
85006 +#include "tree-flow.h"
85007 +#include "plugin.h"
85008 +#include "gimple.h"
85009 +#include "c-common.h"
85010 +#include "diagnostic.h"
85011 +#include "cfgloop.h"
85012 +
85013 +struct size_overflow_hash {
85014 + struct size_overflow_hash *next;
85015 + const char *name;
85016 + unsigned int param;
85017 +};
85018 +
85019 +#include "size_overflow_hash.h"
85020 +
85021 +#define __unused __attribute__((__unused__))
85022 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
85023 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
85024 +#define BEFORE_STMT true
85025 +#define AFTER_STMT false
85026 +#define CREATE_NEW_VAR NULL_TREE
85027 +#define CODES_LIMIT 32
85028 +#define MAX_PARAM 10
85029 +
85030 +#if BUILDING_GCC_VERSION == 4005
85031 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
85032 +#endif
85033 +
85034 +int plugin_is_GPL_compatible;
85035 +void debug_gimple_stmt(gimple gs);
85036 +
85037 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
85038 +static tree signed_size_overflow_type;
85039 +static tree unsigned_size_overflow_type;
85040 +static tree report_size_overflow_decl;
85041 +static tree const_char_ptr_type_node;
85042 +static unsigned int handle_function(void);
85043 +
85044 +static struct plugin_info size_overflow_plugin_info = {
85045 + .version = "20120618beta",
85046 + .help = "no-size-overflow\tturn off size overflow checking\n",
85047 +};
85048 +
85049 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
85050 +{
85051 + unsigned int arg_count = type_num_arguments(*node);
85052 +
85053 + for (; args; args = TREE_CHAIN(args)) {
85054 + tree position = TREE_VALUE(args);
85055 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
85056 + error("handle_size_overflow_attribute: overflow parameter outside range.");
85057 + *no_add_attrs = true;
85058 + }
85059 + }
85060 + return NULL_TREE;
85061 +}
85062 +
85063 +static struct attribute_spec no_size_overflow_attr = {
85064 + .name = "size_overflow",
85065 + .min_length = 1,
85066 + .max_length = -1,
85067 + .decl_required = false,
85068 + .type_required = true,
85069 + .function_type_required = true,
85070 + .handler = handle_size_overflow_attribute,
85071 +#if BUILDING_GCC_VERSION >= 4007
85072 + .affects_type_identity = false
85073 +#endif
85074 +};
85075 +
85076 +static void register_attributes(void __unused *event_data, void __unused *data)
85077 +{
85078 + register_attribute(&no_size_overflow_attr);
85079 +}
85080 +
85081 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
85082 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
85083 +{
85084 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
85085 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
85086 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
85087 +
85088 + const unsigned int m = 0x57559429;
85089 + const unsigned int n = 0x5052acdb;
85090 + const unsigned int *key4 = (const unsigned int *)key;
85091 + unsigned int h = len;
85092 + unsigned int k = len + seed + n;
85093 + unsigned long long p;
85094 +
85095 + while (len >= 8) {
85096 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
85097 + len -= 8;
85098 + }
85099 + if (len >= 4) {
85100 + cwmixb(key4[0]) key4 += 1;
85101 + len -= 4;
85102 + }
85103 + if (len)
85104 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
85105 + cwmixb(h ^ (k + n));
85106 + return k ^ h;
85107 +
85108 +#undef cwfold
85109 +#undef cwmixa
85110 +#undef cwmixb
85111 +}
85112 +
85113 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
85114 +{
85115 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
85116 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
85117 + return fn ^ codes;
85118 +}
85119 +
85120 +static inline tree get_original_function_decl(tree fndecl)
85121 +{
85122 + if (DECL_ABSTRACT_ORIGIN(fndecl))
85123 + return DECL_ABSTRACT_ORIGIN(fndecl);
85124 + return fndecl;
85125 +}
85126 +
85127 +static inline gimple get_def_stmt(tree node)
85128 +{
85129 + gcc_assert(TREE_CODE(node) == SSA_NAME);
85130 + return SSA_NAME_DEF_STMT(node);
85131 +}
85132 +
85133 +static unsigned char get_tree_code(tree type)
85134 +{
85135 + switch (TREE_CODE(type)) {
85136 + case ARRAY_TYPE:
85137 + return 0;
85138 + case BOOLEAN_TYPE:
85139 + return 1;
85140 + case ENUMERAL_TYPE:
85141 + return 2;
85142 + case FUNCTION_TYPE:
85143 + return 3;
85144 + case INTEGER_TYPE:
85145 + return 4;
85146 + case POINTER_TYPE:
85147 + return 5;
85148 + case RECORD_TYPE:
85149 + return 6;
85150 + case UNION_TYPE:
85151 + return 7;
85152 + case VOID_TYPE:
85153 + return 8;
85154 + case REAL_TYPE:
85155 + return 9;
85156 + case VECTOR_TYPE:
85157 + return 10;
85158 + case REFERENCE_TYPE:
85159 + return 11;
85160 + default:
85161 + debug_tree(type);
85162 + gcc_unreachable();
85163 + }
85164 +}
85165 +
85166 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
85167 +{
85168 + gcc_assert(type != NULL_TREE);
85169 +
85170 + while (type && len < CODES_LIMIT) {
85171 + tree_codes[len] = get_tree_code(type);
85172 + len++;
85173 + type = TREE_TYPE(type);
85174 + }
85175 + return len;
85176 +}
85177 +
85178 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
85179 +{
85180 + tree arg, result, type = TREE_TYPE(fndecl);
85181 + enum tree_code code = TREE_CODE(type);
85182 + size_t len = 0;
85183 +
85184 + gcc_assert(code == FUNCTION_TYPE);
85185 +
85186 + arg = TYPE_ARG_TYPES(type);
85187 + // skip builtins __builtin_constant_p
85188 + if (!arg && DECL_BUILT_IN(fndecl))
85189 + return 0;
85190 + gcc_assert(arg != NULL_TREE);
85191 +
85192 + if (TREE_CODE_CLASS(code) == tcc_type)
85193 + result = type;
85194 + else
85195 + result = DECL_RESULT(fndecl);
85196 +
85197 + gcc_assert(result != NULL_TREE);
85198 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
85199 +
85200 + while (arg && len < CODES_LIMIT) {
85201 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
85202 + arg = TREE_CHAIN(arg);
85203 + }
85204 +
85205 + gcc_assert(len != 0);
85206 + return len;
85207 +}
85208 +
85209 +static struct size_overflow_hash *get_function_hash(tree fndecl)
85210 +{
85211 + unsigned int hash;
85212 + struct size_overflow_hash *entry;
85213 + unsigned char tree_codes[CODES_LIMIT];
85214 + size_t len;
85215 + const char *func_name = NAME(fndecl);
85216 +
85217 + len = get_function_decl(fndecl, tree_codes);
85218 + if (len == 0)
85219 + return NULL;
85220 +
85221 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
85222 +
85223 + entry = size_overflow_hash[hash];
85224 + while (entry) {
85225 + if (!strcmp(entry->name, func_name))
85226 + return entry;
85227 + entry = entry->next;
85228 + }
85229 +
85230 + return NULL;
85231 +}
85232 +
85233 +static void check_arg_type(tree var)
85234 +{
85235 + tree type = TREE_TYPE(var);
85236 + enum tree_code code = TREE_CODE(type);
85237 +
85238 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
85239 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
85240 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
85241 +}
85242 +
85243 +static int find_arg_number(tree arg, tree func)
85244 +{
85245 + tree var;
85246 + bool match = false;
85247 + unsigned int argnum = 1;
85248 +
85249 + if (TREE_CODE(arg) == SSA_NAME)
85250 + arg = SSA_NAME_VAR(arg);
85251 +
85252 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
85253 + if (strcmp(NAME(arg), NAME(var))) {
85254 + argnum++;
85255 + continue;
85256 + }
85257 + check_arg_type(var);
85258 +
85259 + match = true;
85260 + break;
85261 + }
85262 + if (!match) {
85263 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
85264 + return 0;
85265 + }
85266 + return argnum;
85267 +}
85268 +
85269 +static void print_missing_msg(tree func, unsigned int argnum)
85270 +{
85271 + unsigned int new_hash;
85272 + size_t len;
85273 + unsigned char tree_codes[CODES_LIMIT];
85274 + location_t loc = DECL_SOURCE_LOCATION(func);
85275 + const char *curfunc = NAME(func);
85276 +
85277 + len = get_function_decl(func, tree_codes);
85278 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
85279 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
85280 +}
85281 +
85282 +static void check_missing_attribute(tree arg)
85283 +{
85284 + tree type, func = get_original_function_decl(current_function_decl);
85285 + unsigned int argnum;
85286 + struct size_overflow_hash *hash;
85287 +
85288 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
85289 +
85290 + type = TREE_TYPE(arg);
85291 + // skip function pointers
85292 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
85293 + return;
85294 +
85295 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
85296 + return;
85297 +
85298 + argnum = find_arg_number(arg, func);
85299 + if (argnum == 0)
85300 + return;
85301 +
85302 + hash = get_function_hash(func);
85303 + if (!hash || !(hash->param & (1U << argnum)))
85304 + print_missing_msg(func, argnum);
85305 +}
85306 +
85307 +static tree create_new_var(tree type)
85308 +{
85309 + tree new_var = create_tmp_var(type, "cicus");
85310 +
85311 + add_referenced_var(new_var);
85312 + mark_sym_for_renaming(new_var);
85313 + return new_var;
85314 +}
85315 +
85316 +static bool is_bool(tree node)
85317 +{
85318 + tree type;
85319 +
85320 + if (node == NULL_TREE)
85321 + return false;
85322 +
85323 + type = TREE_TYPE(node);
85324 + if (!INTEGRAL_TYPE_P(type))
85325 + return false;
85326 + if (TREE_CODE(type) == BOOLEAN_TYPE)
85327 + return true;
85328 + if (TYPE_PRECISION(type) == 1)
85329 + return true;
85330 + return false;
85331 +}
85332 +
85333 +static tree cast_a_tree(tree type, tree var)
85334 +{
85335 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
85336 + gcc_assert(fold_convertible_p(type, var));
85337 +
85338 + return fold_convert(type, var);
85339 +}
85340 +
85341 +static tree signed_cast(tree var)
85342 +{
85343 + return cast_a_tree(signed_size_overflow_type, var);
85344 +}
85345 +
85346 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
85347 +{
85348 + gimple assign;
85349 +
85350 + if (new_var == CREATE_NEW_VAR)
85351 + new_var = create_new_var(type);
85352 +
85353 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
85354 + gimple_set_location(assign, loc);
85355 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
85356 +
85357 + return assign;
85358 +}
85359 +
85360 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
85361 +{
85362 + tree oldstmt_rhs1;
85363 + enum tree_code code;
85364 + gimple stmt;
85365 + gimple_stmt_iterator gsi;
85366 +
85367 + if (!*potentionally_overflowed)
85368 + return NULL_TREE;
85369 +
85370 + if (rhs1 == NULL_TREE) {
85371 + debug_gimple_stmt(oldstmt);
85372 + error("create_assign: rhs1 is NULL_TREE");
85373 + gcc_unreachable();
85374 + }
85375 +
85376 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
85377 + code = TREE_CODE(oldstmt_rhs1);
85378 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
85379 + check_missing_attribute(oldstmt_rhs1);
85380 +
85381 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
85382 + gsi = gsi_for_stmt(oldstmt);
85383 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
85384 + basic_block next_bb, cur_bb;
85385 + edge e;
85386 +
85387 + gcc_assert(before == false);
85388 + gcc_assert(stmt_can_throw_internal(oldstmt));
85389 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
85390 + gcc_assert(!gsi_end_p(gsi));
85391 +
85392 + cur_bb = gimple_bb(oldstmt);
85393 + next_bb = cur_bb->next_bb;
85394 + e = find_edge(cur_bb, next_bb);
85395 + gcc_assert(e != NULL);
85396 + gcc_assert(e->flags & EDGE_FALLTHRU);
85397 +
85398 + gsi = gsi_after_labels(next_bb);
85399 + gcc_assert(!gsi_end_p(gsi));
85400 + before = true;
85401 + }
85402 + if (before)
85403 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
85404 + else
85405 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
85406 + update_stmt(stmt);
85407 + pointer_set_insert(visited, oldstmt);
85408 + return gimple_get_lhs(stmt);
85409 +}
85410 +
85411 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
85412 +{
85413 + tree new_var, lhs = gimple_get_lhs(oldstmt);
85414 + gimple stmt;
85415 + gimple_stmt_iterator gsi;
85416 +
85417 + if (!*potentionally_overflowed)
85418 + return NULL_TREE;
85419 +
85420 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
85421 + rhs1 = gimple_assign_rhs1(oldstmt);
85422 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
85423 + }
85424 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
85425 + rhs2 = gimple_assign_rhs2(oldstmt);
85426 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
85427 + }
85428 +
85429 + stmt = gimple_copy(oldstmt);
85430 + gimple_set_location(stmt, gimple_location(oldstmt));
85431 +
85432 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
85433 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
85434 +
85435 + if (is_bool(lhs))
85436 + new_var = SSA_NAME_VAR(lhs);
85437 + else
85438 + new_var = create_new_var(signed_size_overflow_type);
85439 + new_var = make_ssa_name(new_var, stmt);
85440 + gimple_set_lhs(stmt, new_var);
85441 +
85442 + if (rhs1 != NULL_TREE) {
85443 + if (!gimple_assign_cast_p(oldstmt))
85444 + rhs1 = signed_cast(rhs1);
85445 + gimple_assign_set_rhs1(stmt, rhs1);
85446 + }
85447 +
85448 + if (rhs2 != NULL_TREE)
85449 + gimple_assign_set_rhs2(stmt, rhs2);
85450 +#if BUILDING_GCC_VERSION >= 4007
85451 + if (rhs3 != NULL_TREE)
85452 + gimple_assign_set_rhs3(stmt, rhs3);
85453 +#endif
85454 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
85455 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
85456 +
85457 + gsi = gsi_for_stmt(oldstmt);
85458 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
85459 + update_stmt(stmt);
85460 + pointer_set_insert(visited, oldstmt);
85461 + return gimple_get_lhs(stmt);
85462 +}
85463 +
85464 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
85465 +{
85466 + basic_block bb;
85467 + gimple phi;
85468 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
85469 +
85470 + bb = gsi_bb(gsi);
85471 +
85472 + phi = create_phi_node(var, bb);
85473 + gsi = gsi_last(phi_nodes(bb));
85474 + gsi_remove(&gsi, false);
85475 +
85476 + gsi = gsi_for_stmt(oldstmt);
85477 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
85478 + gimple_set_bb(phi, bb);
85479 + return phi;
85480 +}
85481 +
85482 +static basic_block create_a_first_bb(void)
85483 +{
85484 + basic_block first_bb;
85485 +
85486 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85487 + if (dom_info_available_p(CDI_DOMINATORS))
85488 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
85489 + return first_bb;
85490 +}
85491 +
85492 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
85493 +{
85494 + basic_block bb;
85495 + gimple newstmt, def_stmt;
85496 + gimple_stmt_iterator gsi;
85497 +
85498 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
85499 + if (TREE_CODE(arg) == SSA_NAME) {
85500 + def_stmt = get_def_stmt(arg);
85501 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
85502 + gsi = gsi_for_stmt(def_stmt);
85503 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
85504 + return newstmt;
85505 + }
85506 + }
85507 +
85508 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
85509 + if (bb->index == 0)
85510 + bb = create_a_first_bb();
85511 + gsi = gsi_after_labels(bb);
85512 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
85513 + return newstmt;
85514 +}
85515 +
85516 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
85517 +{
85518 + gimple newstmt;
85519 + gimple_stmt_iterator gsi;
85520 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
85521 + gimple def_newstmt = get_def_stmt(new_rhs);
85522 +
85523 + gsi_insert = gsi_insert_after;
85524 + gsi = gsi_for_stmt(def_newstmt);
85525 +
85526 + switch (gimple_code(get_def_stmt(arg))) {
85527 + case GIMPLE_PHI:
85528 + newstmt = gimple_build_assign(new_var, new_rhs);
85529 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
85530 + gsi_insert = gsi_insert_before;
85531 + break;
85532 + case GIMPLE_ASM:
85533 + case GIMPLE_CALL:
85534 + newstmt = gimple_build_assign(new_var, new_rhs);
85535 + break;
85536 + case GIMPLE_ASSIGN:
85537 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
85538 + break;
85539 + default:
85540 + /* unknown gimple_code (handle_build_new_phi_arg) */
85541 + gcc_unreachable();
85542 + }
85543 +
85544 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
85545 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
85546 + update_stmt(newstmt);
85547 + return newstmt;
85548 +}
85549 +
85550 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
85551 +{
85552 + gimple newstmt;
85553 + tree new_rhs;
85554 +
85555 + new_rhs = expand(visited, potentionally_overflowed, arg);
85556 +
85557 + if (new_rhs == NULL_TREE)
85558 + return NULL_TREE;
85559 +
85560 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85561 + return gimple_get_lhs(newstmt);
85562 +}
85563 +
85564 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
85565 +{
85566 + gimple phi;
85567 + tree new_var = create_new_var(signed_size_overflow_type);
85568 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85569 +
85570 + pointer_set_insert(visited, oldstmt);
85571 + phi = overflow_create_phi_node(oldstmt, new_var);
85572 + for (i = 0; i < n; i++) {
85573 + tree arg, lhs;
85574 +
85575 + arg = gimple_phi_arg_def(oldstmt, i);
85576 + if (is_gimple_constant(arg))
85577 + arg = signed_cast(arg);
85578 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85579 + if (lhs == NULL_TREE)
85580 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85581 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85582 + }
85583 +
85584 + update_stmt(phi);
85585 + return gimple_phi_result(phi);
85586 +}
85587 +
85588 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85589 +{
85590 + gimple def_stmt = get_def_stmt(var);
85591 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85592 +
85593 + *potentionally_overflowed = true;
85594 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85595 + if (new_rhs1 == NULL_TREE) {
85596 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85597 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85598 + else
85599 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85600 + }
85601 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85602 +}
85603 +
85604 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85605 +{
85606 + gimple def_stmt = get_def_stmt(var);
85607 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85608 +
85609 + if (is_gimple_constant(rhs1))
85610 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast(rhs1), NULL_TREE, NULL_TREE);
85611 +
85612 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
85613 + switch (TREE_CODE(rhs1)) {
85614 + case SSA_NAME:
85615 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85616 +
85617 + case ARRAY_REF:
85618 + case BIT_FIELD_REF:
85619 + case ADDR_EXPR:
85620 + case COMPONENT_REF:
85621 + case INDIRECT_REF:
85622 +#if BUILDING_GCC_VERSION >= 4006
85623 + case MEM_REF:
85624 +#endif
85625 + case PARM_DECL:
85626 + case TARGET_MEM_REF:
85627 + case VAR_DECL:
85628 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85629 +
85630 + default:
85631 + debug_gimple_stmt(def_stmt);
85632 + debug_tree(rhs1);
85633 + gcc_unreachable();
85634 + }
85635 +}
85636 +
85637 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85638 +{
85639 + gimple cond_stmt;
85640 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85641 +
85642 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85643 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85644 + update_stmt(cond_stmt);
85645 +}
85646 +
85647 +static tree create_string_param(tree string)
85648 +{
85649 + tree i_type, a_type;
85650 + int length = TREE_STRING_LENGTH(string);
85651 +
85652 + gcc_assert(length > 0);
85653 +
85654 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
85655 + a_type = build_array_type(char_type_node, i_type);
85656 +
85657 + TREE_TYPE(string) = a_type;
85658 + TREE_CONSTANT(string) = 1;
85659 + TREE_READONLY(string) = 1;
85660 +
85661 + return build1(ADDR_EXPR, ptr_type_node, string);
85662 +}
85663 +
85664 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85665 +{
85666 + gimple func_stmt, def_stmt;
85667 + tree current_func, loc_file, loc_line;
85668 + expanded_location xloc;
85669 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85670 +
85671 + def_stmt = get_def_stmt(arg);
85672 + xloc = expand_location(gimple_location(def_stmt));
85673 +
85674 + if (!gimple_has_location(def_stmt)) {
85675 + xloc = expand_location(gimple_location(stmt));
85676 + if (!gimple_has_location(stmt))
85677 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85678 + }
85679 +
85680 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85681 +
85682 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
85683 + loc_file = create_string_param(loc_file);
85684 +
85685 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
85686 + current_func = create_string_param(current_func);
85687 +
85688 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85689 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85690 +
85691 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85692 +}
85693 +
85694 +static void __unused print_the_code_insertions(gimple stmt)
85695 +{
85696 + location_t loc = gimple_location(stmt);
85697 +
85698 + inform(loc, "Integer size_overflow check applied here.");
85699 +}
85700 +
85701 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85702 +{
85703 + basic_block cond_bb, join_bb, bb_true;
85704 + edge e;
85705 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85706 +
85707 + cond_bb = gimple_bb(stmt);
85708 + gsi_prev(&gsi);
85709 + if (gsi_end_p(gsi))
85710 + e = split_block_after_labels(cond_bb);
85711 + else
85712 + e = split_block(cond_bb, gsi_stmt(gsi));
85713 + cond_bb = e->src;
85714 + join_bb = e->dest;
85715 + e->flags = EDGE_FALSE_VALUE;
85716 + e->probability = REG_BR_PROB_BASE;
85717 +
85718 + bb_true = create_empty_bb(cond_bb);
85719 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85720 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85721 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85722 +
85723 + if (dom_info_available_p(CDI_DOMINATORS)) {
85724 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85725 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85726 + }
85727 +
85728 + if (current_loops != NULL) {
85729 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85730 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85731 + }
85732 +
85733 + insert_cond(cond_bb, arg, cond_code, type_value);
85734 + insert_cond_result(bb_true, stmt, arg);
85735 +
85736 +// print_the_code_insertions(stmt);
85737 +}
85738 +
85739 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85740 +{
85741 + gimple ucast_stmt;
85742 + gimple_stmt_iterator gsi;
85743 + location_t loc = gimple_location(stmt);
85744 +
85745 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85746 + gsi = gsi_for_stmt(stmt);
85747 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85748 + return ucast_stmt;
85749 +}
85750 +
85751 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85752 +{
85753 + tree type_max, type_min, rhs_type = TREE_TYPE(rhs);
85754 + gimple ucast_stmt;
85755 +
85756 + if (!*potentionally_overflowed)
85757 + return;
85758 +
85759 + if (TYPE_UNSIGNED(rhs_type)) {
85760 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85761 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85762 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85763 + } else {
85764 + type_max = signed_cast(TYPE_MAX_VALUE(rhs_type));
85765 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85766 +
85767 + type_min = signed_cast(TYPE_MIN_VALUE(rhs_type));
85768 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85769 + }
85770 +}
85771 +
85772 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
85773 +{
85774 + gimple assign;
85775 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85776 + tree origtype = TREE_TYPE(orig_rhs);
85777 +
85778 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85779 +
85780 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85781 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85782 + update_stmt(assign);
85783 + return gimple_get_lhs(assign);
85784 +}
85785 +
85786 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var, tree orig_rhs, tree var_rhs, tree new_rhs1, tree new_rhs2, void (*gimple_assign_set_rhs)(gimple, tree))
85787 +{
85788 + tree new_rhs;
85789 +
85790 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85791 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85792 +
85793 + if (var_rhs == NULL_TREE)
85794 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85795 +
85796 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
85797 + gimple_assign_set_rhs(def_stmt, new_rhs);
85798 + update_stmt(def_stmt);
85799 +
85800 + check_size_overflow(def_stmt, var_rhs, orig_rhs, potentionally_overflowed);
85801 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85802 +}
85803 +
85804 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85805 +{
85806 + tree rhs1, rhs2;
85807 + gimple def_stmt = get_def_stmt(var);
85808 + tree new_rhs1 = NULL_TREE;
85809 + tree new_rhs2 = NULL_TREE;
85810 +
85811 + rhs1 = gimple_assign_rhs1(def_stmt);
85812 + rhs2 = gimple_assign_rhs2(def_stmt);
85813 +
85814 + /* no DImode/TImode division in the 32/64 bit kernel */
85815 + switch (gimple_assign_rhs_code(def_stmt)) {
85816 + case RDIV_EXPR:
85817 + case TRUNC_DIV_EXPR:
85818 + case CEIL_DIV_EXPR:
85819 + case FLOOR_DIV_EXPR:
85820 + case ROUND_DIV_EXPR:
85821 + case TRUNC_MOD_EXPR:
85822 + case CEIL_MOD_EXPR:
85823 + case FLOOR_MOD_EXPR:
85824 + case ROUND_MOD_EXPR:
85825 + case EXACT_DIV_EXPR:
85826 + case POINTER_PLUS_EXPR:
85827 + case BIT_AND_EXPR:
85828 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85829 + default:
85830 + break;
85831 + }
85832 +
85833 + *potentionally_overflowed = true;
85834 +
85835 + if (TREE_CODE(rhs1) == SSA_NAME)
85836 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85837 + if (TREE_CODE(rhs2) == SSA_NAME)
85838 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85839 +
85840 + if (is_gimple_constant(rhs2))
85841 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, new_rhs1, signed_cast(rhs2), &gimple_assign_set_rhs1);
85842 +
85843 + if (is_gimple_constant(rhs1))
85844 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, new_rhs2, signed_cast(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85845 +
85846 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85847 +}
85848 +
85849 +#if BUILDING_GCC_VERSION >= 4007
85850 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85851 +{
85852 + if (is_gimple_constant(rhs))
85853 + return signed_cast(rhs);
85854 + if (TREE_CODE(rhs) != SSA_NAME)
85855 + return NULL_TREE;
85856 + return expand(visited, potentionally_overflowed, rhs);
85857 +}
85858 +
85859 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85860 +{
85861 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85862 + gimple def_stmt = get_def_stmt(var);
85863 +
85864 + *potentionally_overflowed = true;
85865 +
85866 + rhs1 = gimple_assign_rhs1(def_stmt);
85867 + rhs2 = gimple_assign_rhs2(def_stmt);
85868 + rhs3 = gimple_assign_rhs3(def_stmt);
85869 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85870 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85871 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85872 +
85873 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85874 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85875 + error("handle_ternary_ops: unknown rhs");
85876 + gcc_unreachable();
85877 +}
85878 +#endif
85879 +
85880 +static void set_size_overflow_type(tree node)
85881 +{
85882 + switch (TYPE_MODE(TREE_TYPE(node))) {
85883 + case SImode:
85884 + signed_size_overflow_type = intDI_type_node;
85885 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85886 + break;
85887 + case DImode:
85888 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85889 + signed_size_overflow_type = intDI_type_node;
85890 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85891 + } else {
85892 + signed_size_overflow_type = intTI_type_node;
85893 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85894 + }
85895 + break;
85896 + default:
85897 + error("set_size_overflow_type: unsupported gcc configuration.");
85898 + gcc_unreachable();
85899 + }
85900 +}
85901 +
85902 +static tree expand_visited(gimple def_stmt)
85903 +{
85904 + gimple tmp;
85905 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85906 +
85907 + gsi_next(&gsi);
85908 + tmp = gsi_stmt(gsi);
85909 + switch (gimple_code(tmp)) {
85910 + case GIMPLE_ASSIGN:
85911 + return gimple_get_lhs(tmp);
85912 + case GIMPLE_PHI:
85913 + return gimple_phi_result(tmp);
85914 + case GIMPLE_CALL:
85915 + return gimple_call_lhs(tmp);
85916 + default:
85917 + return NULL_TREE;
85918 + }
85919 +}
85920 +
85921 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85922 +{
85923 + gimple def_stmt;
85924 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85925 +
85926 + if (is_gimple_constant(var))
85927 + return NULL_TREE;
85928 +
85929 + if (TREE_CODE(var) == ADDR_EXPR)
85930 + return NULL_TREE;
85931 +
85932 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
85933 + if (code != INTEGER_TYPE)
85934 + return NULL_TREE;
85935 +
85936 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85937 + check_missing_attribute(var);
85938 + return NULL_TREE;
85939 + }
85940 +
85941 + def_stmt = get_def_stmt(var);
85942 +
85943 + if (!def_stmt)
85944 + return NULL_TREE;
85945 +
85946 + if (pointer_set_contains(visited, def_stmt))
85947 + return expand_visited(def_stmt);
85948 +
85949 + switch (gimple_code(def_stmt)) {
85950 + case GIMPLE_NOP:
85951 + check_missing_attribute(var);
85952 + return NULL_TREE;
85953 + case GIMPLE_PHI:
85954 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85955 + case GIMPLE_CALL:
85956 + case GIMPLE_ASM:
85957 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85958 + case GIMPLE_ASSIGN:
85959 + switch (gimple_num_ops(def_stmt)) {
85960 + case 2:
85961 + return handle_unary_ops(visited, potentionally_overflowed, var);
85962 + case 3:
85963 + return handle_binary_ops(visited, potentionally_overflowed, var);
85964 +#if BUILDING_GCC_VERSION >= 4007
85965 + case 4:
85966 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85967 +#endif
85968 + }
85969 + default:
85970 + debug_gimple_stmt(def_stmt);
85971 + error("expand: unknown gimple code");
85972 + gcc_unreachable();
85973 + }
85974 +}
85975 +
85976 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85977 +{
85978 + gimple assign;
85979 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85980 + tree origtype = TREE_TYPE(origarg);
85981 +
85982 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85983 +
85984 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85985 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85986 + update_stmt(assign);
85987 +
85988 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85989 + update_stmt(stmt);
85990 +}
85991 +
85992 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85993 +{
85994 + const char *origid;
85995 + tree arg, origarg;
85996 +
85997 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85998 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85999 + return gimple_call_arg(stmt, argnum);
86000 + }
86001 +
86002 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
86003 + while (origarg && argnum) {
86004 + argnum--;
86005 + origarg = TREE_CHAIN(origarg);
86006 + }
86007 +
86008 + gcc_assert(argnum == 0);
86009 +
86010 + gcc_assert(origarg != NULL_TREE);
86011 + origid = NAME(origarg);
86012 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
86013 + if (!strcmp(origid, NAME(arg)))
86014 + return arg;
86015 + }
86016 + return NULL_TREE;
86017 +}
86018 +
86019 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
86020 +{
86021 + struct pointer_set_t *visited;
86022 + tree arg, newarg;
86023 + bool potentionally_overflowed;
86024 +
86025 + arg = get_function_arg(argnum, stmt, fndecl);
86026 + if (arg == NULL_TREE)
86027 + return;
86028 +
86029 + if (is_gimple_constant(arg))
86030 + return;
86031 + if (TREE_CODE(arg) != SSA_NAME)
86032 + return;
86033 +
86034 + check_arg_type(arg);
86035 +
86036 + set_size_overflow_type(arg);
86037 +
86038 + visited = pointer_set_create();
86039 + potentionally_overflowed = false;
86040 + newarg = expand(visited, &potentionally_overflowed, arg);
86041 + pointer_set_destroy(visited);
86042 +
86043 + if (newarg == NULL_TREE || !potentionally_overflowed)
86044 + return;
86045 +
86046 + change_function_arg(stmt, arg, argnum, newarg);
86047 +
86048 + check_size_overflow(stmt, newarg, arg, &potentionally_overflowed);
86049 +}
86050 +
86051 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
86052 +{
86053 + tree p = TREE_VALUE(attr);
86054 + do {
86055 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
86056 + p = TREE_CHAIN(p);
86057 + } while (p);
86058 +}
86059 +
86060 +static void handle_function_by_hash(gimple stmt, tree fndecl)
86061 +{
86062 + tree orig_fndecl;
86063 + unsigned int num;
86064 + struct size_overflow_hash *hash;
86065 +
86066 + orig_fndecl = get_original_function_decl(fndecl);
86067 + hash = get_function_hash(orig_fndecl);
86068 + if (!hash)
86069 + return;
86070 +
86071 + for (num = 1; num <= MAX_PARAM; num++)
86072 + if (hash->param & (1U << num))
86073 + handle_function_arg(stmt, fndecl, num - 1);
86074 +}
86075 +
86076 +static unsigned int handle_function(void)
86077 +{
86078 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
86079 + int saved_last_basic_block = last_basic_block;
86080 +
86081 + do {
86082 + gimple_stmt_iterator gsi;
86083 + basic_block next = bb->next_bb;
86084 +
86085 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86086 + tree fndecl, attr;
86087 + gimple stmt = gsi_stmt(gsi);
86088 +
86089 + if (!(is_gimple_call(stmt)))
86090 + continue;
86091 + fndecl = gimple_call_fndecl(stmt);
86092 + if (fndecl == NULL_TREE)
86093 + continue;
86094 + if (gimple_call_num_args(stmt) == 0)
86095 + continue;
86096 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
86097 + if (!attr || !TREE_VALUE(attr))
86098 + handle_function_by_hash(stmt, fndecl);
86099 + else
86100 + handle_function_by_attribute(stmt, attr, fndecl);
86101 + gsi = gsi_for_stmt(stmt);
86102 + }
86103 + bb = next;
86104 + } while (bb && bb->index <= saved_last_basic_block);
86105 + return 0;
86106 +}
86107 +
86108 +static struct gimple_opt_pass size_overflow_pass = {
86109 + .pass = {
86110 + .type = GIMPLE_PASS,
86111 + .name = "size_overflow",
86112 + .gate = NULL,
86113 + .execute = handle_function,
86114 + .sub = NULL,
86115 + .next = NULL,
86116 + .static_pass_number = 0,
86117 + .tv_id = TV_NONE,
86118 + .properties_required = PROP_cfg | PROP_referenced_vars,
86119 + .properties_provided = 0,
86120 + .properties_destroyed = 0,
86121 + .todo_flags_start = 0,
86122 + .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
86123 + }
86124 +};
86125 +
86126 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
86127 +{
86128 + tree fntype;
86129 +
86130 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
86131 +
86132 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
86133 + fntype = build_function_type_list(void_type_node,
86134 + const_char_ptr_type_node,
86135 + unsigned_type_node,
86136 + const_char_ptr_type_node,
86137 + NULL_TREE);
86138 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
86139 +
86140 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
86141 + TREE_PUBLIC(report_size_overflow_decl) = 1;
86142 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
86143 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
86144 +}
86145 +
86146 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86147 +{
86148 + int i;
86149 + const char * const plugin_name = plugin_info->base_name;
86150 + const int argc = plugin_info->argc;
86151 + const struct plugin_argument * const argv = plugin_info->argv;
86152 + bool enable = true;
86153 +
86154 + struct register_pass_info size_overflow_pass_info = {
86155 + .pass = &size_overflow_pass.pass,
86156 + .reference_pass_name = "ssa",
86157 + .ref_pass_instance_number = 1,
86158 + .pos_op = PASS_POS_INSERT_AFTER
86159 + };
86160 +
86161 + if (!plugin_default_version_check(version, &gcc_version)) {
86162 + error(G_("incompatible gcc/plugin versions"));
86163 + return 1;
86164 + }
86165 +
86166 + for (i = 0; i < argc; ++i) {
86167 + if (!strcmp(argv[i].key, "no-size-overflow")) {
86168 + enable = false;
86169 + continue;
86170 + }
86171 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86172 + }
86173 +
86174 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
86175 + if (enable) {
86176 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86177 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
86178 + }
86179 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86180 +
86181 + return 0;
86182 +}
86183 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
86184 new file mode 100644
86185 index 0000000..38d2014
86186 --- /dev/null
86187 +++ b/tools/gcc/stackleak_plugin.c
86188 @@ -0,0 +1,313 @@
86189 +/*
86190 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86191 + * Licensed under the GPL v2
86192 + *
86193 + * Note: the choice of the license means that the compilation process is
86194 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86195 + * but for the kernel it doesn't matter since it doesn't link against
86196 + * any of the gcc libraries
86197 + *
86198 + * gcc plugin to help implement various PaX features
86199 + *
86200 + * - track lowest stack pointer
86201 + *
86202 + * TODO:
86203 + * - initialize all local variables
86204 + *
86205 + * BUGS:
86206 + * - none known
86207 + */
86208 +#include "gcc-plugin.h"
86209 +#include "config.h"
86210 +#include "system.h"
86211 +#include "coretypes.h"
86212 +#include "tree.h"
86213 +#include "tree-pass.h"
86214 +#include "flags.h"
86215 +#include "intl.h"
86216 +#include "toplev.h"
86217 +#include "plugin.h"
86218 +//#include "expr.h" where are you...
86219 +#include "diagnostic.h"
86220 +#include "plugin-version.h"
86221 +#include "tm.h"
86222 +#include "function.h"
86223 +#include "basic-block.h"
86224 +#include "gimple.h"
86225 +#include "rtl.h"
86226 +#include "emit-rtl.h"
86227 +
86228 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86229 +
86230 +int plugin_is_GPL_compatible;
86231 +
86232 +static int track_frame_size = -1;
86233 +static const char track_function[] = "pax_track_stack";
86234 +static const char check_function[] = "pax_check_alloca";
86235 +static bool init_locals;
86236 +
86237 +static struct plugin_info stackleak_plugin_info = {
86238 + .version = "201203140940",
86239 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
86240 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
86241 +};
86242 +
86243 +static bool gate_stackleak_track_stack(void);
86244 +static unsigned int execute_stackleak_tree_instrument(void);
86245 +static unsigned int execute_stackleak_final(void);
86246 +
86247 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
86248 + .pass = {
86249 + .type = GIMPLE_PASS,
86250 + .name = "stackleak_tree_instrument",
86251 + .gate = gate_stackleak_track_stack,
86252 + .execute = execute_stackleak_tree_instrument,
86253 + .sub = NULL,
86254 + .next = NULL,
86255 + .static_pass_number = 0,
86256 + .tv_id = TV_NONE,
86257 + .properties_required = PROP_gimple_leh | PROP_cfg,
86258 + .properties_provided = 0,
86259 + .properties_destroyed = 0,
86260 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86261 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86262 + }
86263 +};
86264 +
86265 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
86266 + .pass = {
86267 + .type = RTL_PASS,
86268 + .name = "stackleak_final",
86269 + .gate = gate_stackleak_track_stack,
86270 + .execute = execute_stackleak_final,
86271 + .sub = NULL,
86272 + .next = NULL,
86273 + .static_pass_number = 0,
86274 + .tv_id = TV_NONE,
86275 + .properties_required = 0,
86276 + .properties_provided = 0,
86277 + .properties_destroyed = 0,
86278 + .todo_flags_start = 0,
86279 + .todo_flags_finish = TODO_dump_func
86280 + }
86281 +};
86282 +
86283 +static bool gate_stackleak_track_stack(void)
86284 +{
86285 + return track_frame_size >= 0;
86286 +}
86287 +
86288 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
86289 +{
86290 + gimple check_alloca;
86291 + tree fntype, fndecl, alloca_size;
86292 +
86293 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
86294 + fndecl = build_fn_decl(check_function, fntype);
86295 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86296 +
86297 + // insert call to void pax_check_alloca(unsigned long size)
86298 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
86299 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
86300 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
86301 +}
86302 +
86303 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
86304 +{
86305 + gimple track_stack;
86306 + tree fntype, fndecl;
86307 +
86308 + fntype = build_function_type_list(void_type_node, NULL_TREE);
86309 + fndecl = build_fn_decl(track_function, fntype);
86310 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86311 +
86312 + // insert call to void pax_track_stack(void)
86313 + track_stack = gimple_build_call(fndecl, 0);
86314 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
86315 +}
86316 +
86317 +#if BUILDING_GCC_VERSION == 4005
86318 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
86319 +{
86320 + tree fndecl;
86321 +
86322 + if (!is_gimple_call(stmt))
86323 + return false;
86324 + fndecl = gimple_call_fndecl(stmt);
86325 + if (!fndecl)
86326 + return false;
86327 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
86328 + return false;
86329 +// print_node(stderr, "pax", fndecl, 4);
86330 + return DECL_FUNCTION_CODE(fndecl) == code;
86331 +}
86332 +#endif
86333 +
86334 +static bool is_alloca(gimple stmt)
86335 +{
86336 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
86337 + return true;
86338 +
86339 +#if BUILDING_GCC_VERSION >= 4007
86340 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
86341 + return true;
86342 +#endif
86343 +
86344 + return false;
86345 +}
86346 +
86347 +static unsigned int execute_stackleak_tree_instrument(void)
86348 +{
86349 + basic_block bb, entry_bb;
86350 + bool prologue_instrumented = false, is_leaf = true;
86351 +
86352 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
86353 +
86354 + // 1. loop through BBs and GIMPLE statements
86355 + FOR_EACH_BB(bb) {
86356 + gimple_stmt_iterator gsi;
86357 +
86358 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86359 + gimple stmt;
86360 +
86361 + stmt = gsi_stmt(gsi);
86362 +
86363 + if (is_gimple_call(stmt))
86364 + is_leaf = false;
86365 +
86366 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
86367 + if (!is_alloca(stmt))
86368 + continue;
86369 +
86370 + // 2. insert stack overflow check before each __builtin_alloca call
86371 + stackleak_check_alloca(&gsi);
86372 +
86373 + // 3. insert track call after each __builtin_alloca call
86374 + stackleak_add_instrumentation(&gsi);
86375 + if (bb == entry_bb)
86376 + prologue_instrumented = true;
86377 + }
86378 + }
86379 +
86380 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
86381 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
86382 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
86383 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
86384 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
86385 + return 0;
86386 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
86387 + return 0;
86388 +
86389 + // 4. insert track call at the beginning
86390 + if (!prologue_instrumented) {
86391 + gimple_stmt_iterator gsi;
86392 +
86393 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86394 + if (dom_info_available_p(CDI_DOMINATORS))
86395 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86396 + gsi = gsi_start_bb(bb);
86397 + stackleak_add_instrumentation(&gsi);
86398 + }
86399 +
86400 + return 0;
86401 +}
86402 +
86403 +static unsigned int execute_stackleak_final(void)
86404 +{
86405 + rtx insn;
86406 +
86407 + if (cfun->calls_alloca)
86408 + return 0;
86409 +
86410 + // keep calls only if function frame is big enough
86411 + if (get_frame_size() >= track_frame_size)
86412 + return 0;
86413 +
86414 + // 1. find pax_track_stack calls
86415 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86416 + // 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))
86417 + rtx body;
86418 +
86419 + if (!CALL_P(insn))
86420 + continue;
86421 + body = PATTERN(insn);
86422 + if (GET_CODE(body) != CALL)
86423 + continue;
86424 + body = XEXP(body, 0);
86425 + if (GET_CODE(body) != MEM)
86426 + continue;
86427 + body = XEXP(body, 0);
86428 + if (GET_CODE(body) != SYMBOL_REF)
86429 + continue;
86430 + if (strcmp(XSTR(body, 0), track_function))
86431 + continue;
86432 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86433 + // 2. delete call
86434 + insn = delete_insn_and_edges(insn);
86435 +#if BUILDING_GCC_VERSION >= 4007
86436 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86437 + insn = delete_insn_and_edges(insn);
86438 +#endif
86439 + }
86440 +
86441 +// print_simple_rtl(stderr, get_insns());
86442 +// print_rtl(stderr, get_insns());
86443 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86444 +
86445 + return 0;
86446 +}
86447 +
86448 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86449 +{
86450 + const char * const plugin_name = plugin_info->base_name;
86451 + const int argc = plugin_info->argc;
86452 + const struct plugin_argument * const argv = plugin_info->argv;
86453 + int i;
86454 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86455 + .pass = &stackleak_tree_instrument_pass.pass,
86456 +// .reference_pass_name = "tree_profile",
86457 + .reference_pass_name = "optimized",
86458 + .ref_pass_instance_number = 1,
86459 + .pos_op = PASS_POS_INSERT_BEFORE
86460 + };
86461 + struct register_pass_info stackleak_final_pass_info = {
86462 + .pass = &stackleak_final_rtl_opt_pass.pass,
86463 + .reference_pass_name = "final",
86464 + .ref_pass_instance_number = 1,
86465 + .pos_op = PASS_POS_INSERT_BEFORE
86466 + };
86467 +
86468 + if (!plugin_default_version_check(version, &gcc_version)) {
86469 + error(G_("incompatible gcc/plugin versions"));
86470 + return 1;
86471 + }
86472 +
86473 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86474 +
86475 + for (i = 0; i < argc; ++i) {
86476 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86477 + if (!argv[i].value) {
86478 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86479 + continue;
86480 + }
86481 + track_frame_size = atoi(argv[i].value);
86482 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86483 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86484 + continue;
86485 + }
86486 + if (!strcmp(argv[i].key, "initialize-locals")) {
86487 + if (argv[i].value) {
86488 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86489 + continue;
86490 + }
86491 + init_locals = true;
86492 + continue;
86493 + }
86494 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86495 + }
86496 +
86497 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86498 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86499 +
86500 + return 0;
86501 +}
86502 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
86503 index 6789d78..4afd019 100644
86504 --- a/tools/perf/util/include/asm/alternative-asm.h
86505 +++ b/tools/perf/util/include/asm/alternative-asm.h
86506 @@ -5,4 +5,7 @@
86507
86508 #define altinstruction_entry #
86509
86510 + .macro pax_force_retaddr rip=0, reload=0
86511 + .endm
86512 +
86513 #endif
86514 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86515 index af0f22f..9a7d479 100644
86516 --- a/usr/gen_init_cpio.c
86517 +++ b/usr/gen_init_cpio.c
86518 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
86519 int retval;
86520 int rc = -1;
86521 int namesize;
86522 - int i;
86523 + unsigned int i;
86524
86525 mode |= S_IFREG;
86526
86527 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
86528 *env_var = *expanded = '\0';
86529 strncat(env_var, start + 2, end - start - 2);
86530 strncat(expanded, new_location, start - new_location);
86531 - strncat(expanded, getenv(env_var), PATH_MAX);
86532 - strncat(expanded, end + 1, PATH_MAX);
86533 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86534 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86535 strncpy(new_location, expanded, PATH_MAX);
86536 + new_location[PATH_MAX] = 0;
86537 } else
86538 break;
86539 }
86540 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86541 index 44ee712..7da730b 100644
86542 --- a/virt/kvm/kvm_main.c
86543 +++ b/virt/kvm/kvm_main.c
86544 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86545
86546 static cpumask_var_t cpus_hardware_enabled;
86547 static int kvm_usage_count = 0;
86548 -static atomic_t hardware_enable_failed;
86549 +static atomic_unchecked_t hardware_enable_failed;
86550
86551 struct kmem_cache *kvm_vcpu_cache;
86552 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86553 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
86554
86555 if (r) {
86556 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86557 - atomic_inc(&hardware_enable_failed);
86558 + atomic_inc_unchecked(&hardware_enable_failed);
86559 printk(KERN_INFO "kvm: enabling virtualization on "
86560 "CPU%d failed\n", cpu);
86561 }
86562 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
86563
86564 kvm_usage_count++;
86565 if (kvm_usage_count == 1) {
86566 - atomic_set(&hardware_enable_failed, 0);
86567 + atomic_set_unchecked(&hardware_enable_failed, 0);
86568 on_each_cpu(hardware_enable_nolock, NULL, 1);
86569
86570 - if (atomic_read(&hardware_enable_failed)) {
86571 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86572 hardware_disable_all_nolock();
86573 r = -EBUSY;
86574 }
86575 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86576 kvm_arch_vcpu_put(vcpu);
86577 }
86578
86579 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86580 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86581 struct module *module)
86582 {
86583 int r;
86584 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86585 if (!vcpu_align)
86586 vcpu_align = __alignof__(struct kvm_vcpu);
86587 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86588 - 0, NULL);
86589 + SLAB_USERCOPY, NULL);
86590 if (!kvm_vcpu_cache) {
86591 r = -ENOMEM;
86592 goto out_free_3;
86593 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86594 if (r)
86595 goto out_free;
86596
86597 - kvm_chardev_ops.owner = module;
86598 - kvm_vm_fops.owner = module;
86599 - kvm_vcpu_fops.owner = module;
86600 + pax_open_kernel();
86601 + *(void **)&kvm_chardev_ops.owner = module;
86602 + *(void **)&kvm_vm_fops.owner = module;
86603 + *(void **)&kvm_vcpu_fops.owner = module;
86604 + pax_close_kernel();
86605
86606 r = misc_register(&kvm_dev);
86607 if (r) {